void close_enx(int fp) { if(gmx_fio_close(fp) != 0) { gmx_file("Cannot close energy file; it might be corrupt, or maybe you are out of quota?"); } }
void close_enx(ener_file_t ef) { if(gmx_fio_close(ef->fio) != 0) { gmx_file("Cannot close energy file; it might be corrupt, or maybe you are out of quota?"); } }
void close_trj(t_trxstatus *status) { gmx_fio_close(status->fio); /* The memory in status->xframe is lost here, * but the read_first_x/read_next_x functions are deprecated anyhow. * read_first_frame/read_next_frame and close_trx should be used. */ sfree(status); }
void close_trx(t_trxstatus *status) { gmx_tng_close(&status->tng); if (status->fio) { gmx_fio_close(status->fio); } sfree(status); }
void close_enx(ener_file_t ef) { if (ef == NULL) { // Nothing to do return; } if (gmx_fio_close(ef->fio) != 0) { gmx_file("Cannot close energy file; it might be corrupt, or maybe you are out of disk space?"); } }
void close_trx(t_trxstatus *status) { if (status == nullptr) { return; } gmx_tng_close(&status->tng); if (status->fio) { gmx_fio_close(status->fio); } sfree(status); }
void close_trj(t_trxstatus *status) { if (status == nullptr) { return; } gmx_tng_close(&status->tng); if (status->fio) { gmx_fio_close(status->fio); } /* The memory in status->xframe is lost here, * but the read_first_x/read_next_x functions are deprecated anyhow. * read_first_frame/read_next_frame and close_trx should be used. */ sfree(status); }
int gmx_fio_fclose(FILE *fp) { int i,rc,found; found = 0; rc = -1; for(i=0; i<nFIO && !found; i++) { if(fp == FIO[i].fp) { rc = gmx_fio_close(i); found=1; } } return rc; }
void close_trx(t_trxstatus *status) { if (status == nullptr) { return; } gmx_tng_close(&status->tng); if (status->fio) { gmx_fio_close(status->fio); } sfree(status->persistent_line); #if GMX_USE_PLUGINS sfree(status->vmdplugin); #endif /* The memory in status->xframe is lost here, * but the read_first_x/read_next_x functions are deprecated anyhow. * read_first_frame/read_next_frame and close_trx should be used. */ sfree(status); }
void close_xtc(t_fileio *fio) { gmx_fio_close(fio); }
int read_first_frame(const output_env_t oenv,t_trxstatus **status, const char *fn,t_trxframe *fr,int flags) { t_fileio *fio; gmx_bool bFirst,bOK; int dummy=0; clear_trxframe(fr,TRUE); fr->flags = flags; bFirst = TRUE; snew((*status), 1); status_init( *status ); (*status)->nxframe=1; initcount(*status); fio = (*status)->fio =gmx_fio_open(fn,"r"); switch (gmx_fio_getftp(fio)) { case efTRJ: case efTRR: break; case efCPT: read_checkpoint_trxframe(fio,fr); bFirst = FALSE; break; case efG96: /* Can not rewind a compressed file, so open it twice */ read_g96_conf(gmx_fio_getfp(fio),fn,fr); gmx_fio_close(fio); clear_trxframe(fr,FALSE); if (flags & (TRX_READ_X | TRX_NEED_X)) snew(fr->x,fr->natoms); if (flags & (TRX_READ_V | TRX_NEED_V)) snew(fr->v,fr->natoms); fio = (*status)->fio =gmx_fio_open(fn,"r"); break; case efG87: fr->natoms=xyz_first_x(*status, gmx_fio_getfp(fio),oenv,&fr->time, &fr->x,fr->box); if (fr->natoms) { fr->bTime = TRUE; fr->bX = TRUE; fr->bBox = TRUE; printcount(*status,oenv,fr->time,FALSE); } bFirst = FALSE; break; case efXTC: if (read_first_xtc(fio,&fr->natoms,&fr->step,&fr->time,fr->box,&fr->x, &fr->prec,&bOK) == 0) { if (bOK) { gmx_fatal(FARGS,"No XTC!\n"); } else { fr->not_ok = DATA_NOT_OK; } } if (fr->not_ok) { fr->natoms = 0; printincomp(*status,fr); } else { fr->bPrec = (fr->prec > 0); fr->bStep = TRUE; fr->bTime = TRUE; fr->bX = TRUE; fr->bBox = TRUE; printcount(*status,oenv,fr->time,FALSE); } bFirst = FALSE; break; case efPDB: pdb_first_x(*status, gmx_fio_getfp(fio),fr); if (fr->natoms) printcount(*status,oenv,fr->time,FALSE); bFirst = FALSE; break; case efGRO: if (gro_first_x_or_v(gmx_fio_getfp(fio),fr)) printcount(*status,oenv,fr->time,FALSE); bFirst = FALSE; break; default: #ifdef GMX_DLOPEN gmx_fio_fp_close(fio); /*only close the file without removing FIO entry*/ if (!read_first_vmd_frame(&dummy,fn,fr,flags)) { gmx_fatal(FARGS,"Not supported in read_first_frame: %s",fn); } #else gmx_fatal(FARGS,"Not supported in read_first_frame: %s",fn); #endif break; } /* Return FALSE if we read a frame that's past the set ending time. */ if (!bFirst && (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) > 0)) { fr->t0 = fr->time; return FALSE; } if (bFirst || (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) < 0)) /* Read a frame when no frame was read or the first was skipped */ if (!read_next_frame(oenv,*status,fr)) return FALSE; fr->t0 = fr->time; return (fr->natoms > 0); }
void gmx_mtxio_write(char * filename, int nrow, int ncol, real * full_matrix, gmx_sparsematrix_t * sparse_matrix) { int fd; XDR * xd; int i,j,prec; bool bDum = TRUE; bool bRead = FALSE; size_t sz; if(full_matrix!=NULL && sparse_matrix!=NULL) { gmx_fatal(FARGS,"Both full AND sparse matrix specified to gmx_mtxio_write().\n"); } fd = gmx_fio_open(filename,"w"); gmx_fio_select(fd); xd = gmx_fio_getxdr(fd); /* Write magic number */ i = GMX_MTXIO_MAGIC_NUMBER; do_int(i); /* Write generating Gromacs version */ do_string(GromacsVersion()); /* Write 1 for double, 0 for single precision */ if(sizeof(real)==sizeof(double)) prec = 1; else prec = 0; do_int(prec); do_int(nrow); do_int(ncol); if(full_matrix!=NULL) { /* Full matrix storage format */ i = GMX_MTXIO_FULL_MATRIX; do_int(i); sz = nrow*ncol; ndo_real(full_matrix,sz,bDum); } else { /* Sparse storage */ i = GMX_MTXIO_SPARSE_MATRIX; do_int(i); do_int(sparse_matrix->compressed_symmetric); do_int(sparse_matrix->nrow); if(sparse_matrix->nrow != nrow) { gmx_fatal(FARGS,"Internal inconsistency in sparse matrix.\n"); } ndo_int(sparse_matrix->ndata,sparse_matrix->nrow,bDum); for(i=0; i<sparse_matrix->nrow; i++) { for(j=0; j<sparse_matrix->ndata[i]; j++) { do_int(sparse_matrix->data[i][j].col); do_real(sparse_matrix->data[i][j].value); } } } gmx_fio_close(fd); }
void gmx_mtxio_read (char * filename, int * nrow, int * ncol, real ** full_matrix, gmx_sparsematrix_t ** sparse_matrix) { int fd; XDR * xd; int i,j,prec; bool bDum = TRUE; bool bRead = TRUE; char gmxver[256]; size_t sz; fd = gmx_fio_open(filename,"r"); gmx_fio_select(fd); xd = gmx_fio_getxdr(fd); /* Read and check magic number */ i = GMX_MTXIO_MAGIC_NUMBER; do_int(i); if(i!=GMX_MTXIO_MAGIC_NUMBER) { gmx_fatal(FARGS, "No matrix data found in file. Note that the Hessian matrix format changed\n" "in Gromacs 3.3 to enable portable files and sparse matrix storage.\n"); } /* Read generating Gromacs version */ do_string(gmxver); /* Write 1 for double, 0 for single precision */ if(sizeof(real)==sizeof(double)) prec = 1; else prec = 0; do_int(prec); fprintf(stderr,"Reading %s precision matrix generated by Gromacs %s\n", (prec == 1) ? "double" : "single",gmxver); do_int(i); *nrow=i; do_int(i); *ncol=i; do_int(i); if(i==GMX_MTXIO_FULL_MATRIX) { printf("Full matrix storage format, nrow=%d, ncols=%d\n",*nrow,*ncol); sz = (*nrow) * (*ncol); snew((*full_matrix),sz); ndo_real((*full_matrix),sz,bDum); } else { /* Sparse storage */ printf("Sparse matrix storage format, nrow=%d, ncols=%d\n",*nrow,*ncol); snew((*sparse_matrix),1); do_int((*sparse_matrix)->compressed_symmetric); do_int((*sparse_matrix)->nrow); if((*sparse_matrix)->nrow != *nrow) { gmx_fatal(FARGS,"Internal inconsistency in sparse matrix.\n"); } snew((*sparse_matrix)->ndata,(*sparse_matrix)->nrow); snew((*sparse_matrix)->nalloc,(*sparse_matrix)->nrow); snew((*sparse_matrix)->data,(*sparse_matrix)->nrow); ndo_int((*sparse_matrix)->ndata,(*sparse_matrix)->nrow,bDum); for(i=0; i<(*sparse_matrix)->nrow; i++) { (*sparse_matrix)->nalloc[i] = (*sparse_matrix)->ndata[i] + 10; snew(((*sparse_matrix)->data[i]),(*sparse_matrix)->nalloc[i]); for(j=0; j<(*sparse_matrix)->ndata[i]; j++) { do_int((*sparse_matrix)->data[i][j].col); do_real((*sparse_matrix)->data[i][j].value); } } } gmx_fio_close(fd); }
void close_trn(int fp) { gmx_fio_close(fp); }
void close_enx(int fp) { gmx_fio_close(fp); }
void gmx_trr_close(t_fileio *fio) { gmx_fio_close(fio); }
void gmx_mtxio_write(const char * filename, int nrow, int ncol, real * full_matrix, gmx_sparsematrix_t * sparse_matrix) { t_fileio *fio; int i, j, prec; size_t sz; if (full_matrix != nullptr && sparse_matrix != nullptr) { gmx_fatal(FARGS, "Both full AND sparse matrix specified to gmx_mtxio_write().\n"); } fio = gmx_fio_open(filename, "w"); /* Write magic number */ i = GMX_MTXIO_MAGIC_NUMBER; gmx_fio_do_int(fio, i); /* Write generating Gromacs version */ gmx_fio_write_string(fio, gmx_version()); /* Write 1 for double, 0 for single precision */ if (sizeof(real) == sizeof(double)) { prec = 1; } else { prec = 0; } gmx_fio_do_int(fio, prec); gmx_fio_do_int(fio, nrow); gmx_fio_do_int(fio, ncol); if (full_matrix != nullptr) { /* Full matrix storage format */ i = GMX_MTXIO_FULL_MATRIX; gmx_fio_do_int(fio, i); sz = nrow*ncol; gmx_fio_ndo_real(fio, full_matrix, sz); } else { /* Sparse storage */ i = GMX_MTXIO_SPARSE_MATRIX; gmx_fio_do_int(fio, i); gmx_fio_do_gmx_bool(fio, sparse_matrix->compressed_symmetric); gmx_fio_do_int(fio, sparse_matrix->nrow); if (sparse_matrix->nrow != nrow) { gmx_fatal(FARGS, "Internal inconsistency in sparse matrix.\n"); } gmx_fio_ndo_int(fio, sparse_matrix->ndata, sparse_matrix->nrow); for (i = 0; i < sparse_matrix->nrow; i++) { for (j = 0; j < sparse_matrix->ndata[i]; j++) { gmx_fio_do_int(fio, sparse_matrix->data[i][j].col); gmx_fio_do_real(fio, sparse_matrix->data[i][j].value); } } } gmx_fio_close(fio); }
void close_trn(t_fileio *fio) { gmx_fio_close(fio); }
void close_trx(t_trxstatus *status) { gmx_fio_close(status->fio); sfree(status); }
int read_first_frame(const output_env_t oenv, t_trxstatus **status, const char *fn, t_trxframe *fr, int flags) { t_fileio *fio; gmx_bool bFirst, bOK; int dummy = 0; clear_trxframe(fr, TRUE); fr->flags = flags; bFirst = TRUE; snew((*status), 1); status_init( *status ); (*status)->nxframe = 1; initcount(*status); fio = (*status)->fio = gmx_fio_open(fn, "r"); switch (gmx_fio_getftp(fio)) { case efTRJ: case efTRR: break; case efCPT: read_checkpoint_trxframe(fio, fr); bFirst = FALSE; break; case efG96: /* Can not rewind a compressed file, so open it twice */ if (!(*status)->persistent_line) { /* allocate the persistent line */ snew((*status)->persistent_line, STRLEN+1); } read_g96_conf(gmx_fio_getfp(fio), fn, fr, (*status)->persistent_line); gmx_fio_close(fio); clear_trxframe(fr, FALSE); if (flags & (TRX_READ_X | TRX_NEED_X)) { snew(fr->x, fr->natoms); } if (flags & (TRX_READ_V | TRX_NEED_V)) { snew(fr->v, fr->natoms); } fio = (*status)->fio = gmx_fio_open(fn, "r"); break; case efG87: fr->natoms = xyz_first_x(*status, gmx_fio_getfp(fio), oenv, &fr->time, &fr->x, fr->box); if (fr->natoms) { fr->bTime = TRUE; fr->bX = TRUE; fr->bBox = TRUE; printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efXTC: if (read_first_xtc(fio, &fr->natoms, &fr->step, &fr->time, fr->box, &fr->x, &fr->prec, &bOK) == 0) { if (bOK) { gmx_fatal(FARGS, "No XTC!\n"); } else { fr->not_ok = DATA_NOT_OK; } } if (fr->not_ok) { fr->natoms = 0; printincomp(*status, fr); } else { fr->bPrec = (fr->prec > 0); fr->bStep = TRUE; fr->bTime = TRUE; fr->bX = TRUE; fr->bBox = TRUE; printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efPDB: pdb_first_x(*status, gmx_fio_getfp(fio), fr); if (fr->natoms) { printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efGRO: if (gro_first_x_or_v(gmx_fio_getfp(fio), fr)) { printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; default: #ifdef GMX_USE_PLUGINS fprintf(stderr, "The file format of %s is not a known trajectory format to GROMACS.\n" "Please make sure that the file is a trajectory!\n" "GROMACS will now assume it to be a trajectory and will try to open it using the VMD plug-ins.\n" "This will only work in case the VMD plugins are found and it is a trajectory format supported by VMD.\n", fn); gmx_fio_fp_close(fio); /*only close the file without removing FIO entry*/ if (!read_first_vmd_frame(fn, fr)) { gmx_fatal(FARGS, "Not supported in read_first_frame: %s", fn); } #else gmx_fatal(FARGS, "Not supported in read_first_frame: %s. Please make sure that the file is a trajectory.\n" "GROMACS is not compiled with plug-in support. Thus it cannot read non-GROMACS trajectory formats using the VMD plug-ins.\n" "Please compile with plug-in support if you want to read non-GROMACS trajectory formats.\n", fn); #endif break; } /* Return FALSE if we read a frame that's past the set ending time. */ if (!bFirst && (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) > 0)) { fr->t0 = fr->time; return FALSE; } if (bFirst || (!(fr->flags & TRX_DONT_SKIP) && check_times(fr->time) < 0)) { /* Read a frame when no frame was read or the first was skipped */ if (!read_next_frame(oenv, *status, fr)) { return FALSE; } } fr->t0 = fr->time; return (fr->natoms > 0); }
bool read_first_frame(const gmx_output_env_t *oenv, t_trxstatus **status, const char *fn, t_trxframe *fr, int flags) { t_fileio *fio = nullptr; gmx_bool bFirst, bOK; int ftp = fn2ftp(fn); clear_trxframe(fr, TRUE); bFirst = TRUE; snew((*status), 1); status_init( *status ); initcount(*status); (*status)->flags = flags; if (efTNG == ftp) { /* Special treatment for TNG files */ gmx_tng_open(fn, 'r', &(*status)->tng); } else { fio = (*status)->fio = gmx_fio_open(fn, "r"); } switch (ftp) { case efTRR: break; case efCPT: read_checkpoint_trxframe(fio, fr); bFirst = FALSE; break; case efG96: { /* Can not rewind a compressed file, so open it twice */ if (!(*status)->persistent_line) { /* allocate the persistent line */ snew((*status)->persistent_line, STRLEN+1); } t_symtab *symtab = nullptr; read_g96_conf(gmx_fio_getfp(fio), fn, nullptr, fr, symtab, (*status)->persistent_line); gmx_fio_close(fio); clear_trxframe(fr, FALSE); if (flags & (TRX_READ_X | TRX_NEED_X)) { snew(fr->x, fr->natoms); } if (flags & (TRX_READ_V | TRX_NEED_V)) { snew(fr->v, fr->natoms); } (*status)->fio = gmx_fio_open(fn, "r"); break; } case efXTC: if (read_first_xtc(fio, &fr->natoms, &fr->step, &fr->time, fr->box, &fr->x, &fr->prec, &bOK) == 0) { GMX_RELEASE_ASSERT(!bOK, "Inconsistent results - OK status from read_first_xtc, but 0 atom coords read"); fr->not_ok = DATA_NOT_OK; } if (fr->not_ok) { fr->natoms = 0; printincomp(*status, fr); } else { fr->bPrec = (fr->prec > 0); fr->bStep = TRUE; fr->bTime = TRUE; fr->bX = TRUE; fr->bBox = TRUE; printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efTNG: fr->step = -1; if (!gmx_read_next_tng_frame((*status)->tng, fr, nullptr, 0)) { fr->not_ok = DATA_NOT_OK; fr->natoms = 0; printincomp(*status, fr); } else { printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efPDB: pdb_first_x(*status, gmx_fio_getfp(fio), fr); if (fr->natoms) { printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; case efGRO: if (gro_first_x_or_v(gmx_fio_getfp(fio), fr)) { printcount(*status, oenv, fr->time, FALSE); } bFirst = FALSE; break; default: #if GMX_USE_PLUGINS fprintf(stderr, "The file format of %s is not a known trajectory format to GROMACS.\n" "Please make sure that the file is a trajectory!\n" "GROMACS will now assume it to be a trajectory and will try to open it using the VMD plug-ins.\n" "This will only work in case the VMD plugins are found and it is a trajectory format supported by VMD.\n", fn); gmx_fio_fp_close(fio); /*only close the file without removing FIO entry*/ if (!read_first_vmd_frame(fn, &(*status)->vmdplugin, fr)) { gmx_fatal(FARGS, "Not supported in read_first_frame: %s", fn); } #else gmx_fatal(FARGS, "Not supported in read_first_frame: %s. Please make sure that the file is a trajectory.\n" "GROMACS is not compiled with plug-in support. Thus it cannot read non-GROMACS trajectory formats using the VMD plug-ins.\n" "Please compile with plug-in support if you want to read non-GROMACS trajectory formats.\n", fn); #endif break; } (*status)->tf = fr->time; /* Return FALSE if we read a frame that's past the set ending time. */ if (!bFirst && (!(flags & TRX_DONT_SKIP) && check_times(fr->time) > 0)) { (*status)->t0 = fr->time; return FALSE; } if (bFirst || (!(flags & TRX_DONT_SKIP) && check_times(fr->time) < 0)) { /* Read a frame when no frame was read or the first was skipped */ if (!read_next_frame(oenv, *status, fr)) { return FALSE; } } (*status)->t0 = fr->time; /* We need the number of atoms for random-access XTC searching, even when * we don't have access to the actual frame data. */ (*status)->natoms = fr->natoms; return (fr->natoms > 0); }
void close_xtc(int fp) { gmx_fio_close(fp); }