int get_tpr_version(const char *infile) { char buf[STRLEN]; gmx_bool bDouble; int precision,fver; t_fileio *fio; fio = open_tpx(infile,"r"); gmx_fio_checktype(fio); precision = sizeof(real); gmx_fio_do_string(fio,buf); if (strncmp(buf,"VERSION",7)) gmx_fatal(FARGS,"Can not read file %s,\n" " this file is from a Gromacs version which is older than 2.0\n" " Make a new one with grompp or use a gro or pdb file, if possible", gmx_fio_getname(fio)); gmx_fio_do_int(fio,precision); bDouble = (precision == sizeof(double)); if ((precision != sizeof(float)) && !bDouble) gmx_fatal(FARGS,"Unknown precision in file %s: real is %d bytes " "instead of %d or %d", gmx_fio_getname(fio),precision,sizeof(float),sizeof(double)); gmx_fio_setprecision(fio,bDouble); fprintf(stderr,"Reading file %s, %s (%s precision)\n", gmx_fio_getname(fio),buf,bDouble ? "double" : "single"); gmx_fio_do_int(fio,fver); close_tpx(fio); return fver; }
static gmx_bool do_trnheader(t_fileio *fio, gmx_bool bRead, t_trnheader *sh, gmx_bool *bOK) { int magic = GROMACS_MAGIC; static gmx_bool bFirst = TRUE; char buf[256]; *bOK = TRUE; gmx_fio_checktype(fio); if (!gmx_fio_do_int(fio, magic) || magic != GROMACS_MAGIC) { return FALSE; } if (bRead) { *bOK = *bOK && gmx_fio_do_string(fio, buf); if (bFirst) { fprintf(stderr, "trn version: %s ", buf); } } else { sprintf(buf, "GMX_trn_file"); *bOK = *bOK && gmx_fio_do_string(fio, buf); } *bOK = *bOK && gmx_fio_do_int(fio, sh->ir_size); *bOK = *bOK && gmx_fio_do_int(fio, sh->e_size); *bOK = *bOK && gmx_fio_do_int(fio, sh->box_size); *bOK = *bOK && gmx_fio_do_int(fio, sh->vir_size); *bOK = *bOK && gmx_fio_do_int(fio, sh->pres_size); *bOK = *bOK && gmx_fio_do_int(fio, sh->top_size); *bOK = *bOK && gmx_fio_do_int(fio, sh->sym_size); *bOK = *bOK && gmx_fio_do_int(fio, sh->x_size); *bOK = *bOK && gmx_fio_do_int(fio, sh->v_size); *bOK = *bOK && gmx_fio_do_int(fio, sh->f_size); *bOK = *bOK && gmx_fio_do_int(fio, sh->natoms); if (!*bOK) { return *bOK; } sh->bDouble = (nFloatSize(sh) == sizeof(double)); gmx_fio_setprecision(fio, sh->bDouble); if (bRead && bFirst) { fprintf(stderr, "(%s precision)\n", sh->bDouble ? "double" : "single"); bFirst = FALSE; } *bOK = *bOK && gmx_fio_do_int(fio, sh->step); *bOK = *bOK && gmx_fio_do_int(fio, sh->nre); *bOK = *bOK && gmx_fio_do_real(fio, sh->t); *bOK = *bOK && gmx_fio_do_real(fio, sh->lambda); return *bOK; }
static bool do_trnheader(int fp,bool bRead,t_trnheader *sh, bool *bOK) { const int magic=GROMACS_MAGIC; const char *version = "GMX_trn_file"; static bool bFirst=TRUE; char buf[256]; *bOK=TRUE; gmx_fio_select(fp); if (!do_int(magic)) return FALSE; if (bRead) { *bOK = *bOK && do_string(buf); if (bFirst) fprintf(stderr,"trn version: %s ",buf); } else *bOK = *bOK && do_string(version); *bOK = *bOK && do_int(sh->ir_size); *bOK = *bOK && do_int(sh->e_size); *bOK = *bOK && do_int(sh->box_size); *bOK = *bOK && do_int(sh->vir_size); *bOK = *bOK && do_int(sh->pres_size); *bOK = *bOK && do_int(sh->top_size); *bOK = *bOK && do_int(sh->sym_size); *bOK = *bOK && do_int(sh->x_size); *bOK = *bOK && do_int(sh->v_size); *bOK = *bOK && do_int(sh->f_size); *bOK = *bOK && do_int(sh->natoms); if (!*bOK) return *bOK; sh->bDouble = (nFloatSize(sh) == sizeof(double)); gmx_fio_setprecision(fp,sh->bDouble); if (bRead && bFirst) { fprintf(stderr,"(%s precision)\n",sh->bDouble ? "double" : "single"); bFirst = FALSE; } *bOK = *bOK && do_int(sh->step); *bOK = *bOK && do_int(sh->nre); *bOK = *bOK && do_real(sh->t); *bOK = *bOK && do_real(sh->lambda); return *bOK; }
int open_enx(char *fn,char *mode) { int fp,nre,i; char **nm=NULL; t_enxframe *fr; bool bDum=TRUE; /* Energy files should always be opened as binary files, * but that is checked in gmx_fio_open. */ if (mode[0]=='r') { fp=gmx_fio_open(fn,mode); gmx_fio_select(fp); gmx_fio_setprecision(fp,FALSE); do_enxnms(fp,&nre,&nm); snew(fr,1); do_eheader(fp,fr,&bDum); /* Now check whether this file is in single precision */ if (((fr->e_size && (fr->nre == nre) && (nre*4*sizeof(float) == fr->e_size)) || (fr->d_size && (fr->ndisre*sizeof(float)*2+sizeof(int) == fr->d_size)))){ fprintf(stderr,"Opened %s as single precision energy file\n",fn); for(i=0; (i<nre); i++) sfree(nm[i]); sfree(nm); } else { gmx_fio_rewind(fp); gmx_fio_select(fp); gmx_fio_setprecision(fp,TRUE); do_enxnms(fp,&nre,&nm); do_eheader(fp,fr,&bDum); if (((fr->e_size && (fr->nre == nre) && (nre*4*sizeof(double) == fr->e_size)) || (fr->d_size && (fr->ndisre*sizeof(double)*2+sizeof(int) == fr->d_size)))) fprintf(stderr,"Opened %s as double precision energy file\n",fn); else { if (empty_file(fn)) fatal_error(0,"File %s is empty",fn); else fatal_error(0,"Energy file %s not recognized, maybe different CPU?", fn); } for(i=0; (i<nre); i++) sfree(nm[i]); sfree(nm); } free_enxframe(fr); sfree(fr); gmx_fio_rewind(fp); } else fp = gmx_fio_open(fn,mode); framenr=0; return fp; }
ener_file_t open_enx(const char *fn,const char *mode) { int nre,i; gmx_enxnm_t *nms=NULL; int file_version=-1; t_enxframe *fr; gmx_bool bWrongPrecision,bOK=TRUE; struct ener_file *ef; snew(ef,1); if (mode[0]=='r') { ef->fio=gmx_fio_open(fn,mode); gmx_fio_checktype(ef->fio); gmx_fio_setprecision(ef->fio,FALSE); do_enxnms(ef,&nre,&nms); snew(fr,1); do_eheader(ef,&file_version,fr,nre,&bWrongPrecision,&bOK); if(!bOK) { gmx_file("Cannot read energy file header. Corrupt file?"); } /* Now check whether this file is in single precision */ if (!bWrongPrecision && ((fr->e_size && (fr->nre == nre) && (nre*4*(long int)sizeof(float) == fr->e_size)) ) ) { fprintf(stderr,"Opened %s as single precision energy file\n",fn); free_enxnms(nre,nms); } else { gmx_fio_rewind(ef->fio); gmx_fio_checktype(ef->fio); gmx_fio_setprecision(ef->fio,TRUE); do_enxnms(ef,&nre,&nms); do_eheader(ef,&file_version,fr,nre,&bWrongPrecision,&bOK); if(!bOK) { gmx_file("Cannot write energy file header; maybe you are out of quota?"); } if (((fr->e_size && (fr->nre == nre) && (nre*4*(long int)sizeof(double) == fr->e_size)) )) fprintf(stderr,"Opened %s as double precision energy file\n", fn); else { if (empty_file(fn)) gmx_fatal(FARGS,"File %s is empty",fn); else gmx_fatal(FARGS,"Energy file %s not recognized, maybe different CPU?", fn); } free_enxnms(nre,nms); } free_enxframe(fr); sfree(fr); gmx_fio_rewind(ef->fio); } else ef->fio = gmx_fio_open(fn,mode); ef->framenr=0; ef->frametime=0; return ef; }
int open_enx(const char *fn,const char *mode) { int fp,nre,i; gmx_enxnm_t *nms=NULL; int file_version=-1; t_enxframe *fr; bool bDum=TRUE; if (mode[0]=='r') { fp=gmx_fio_open(fn,mode); gmx_fio_select(fp); gmx_fio_setprecision(fp,FALSE); do_enxnms(fp,&nre,&nms); snew(fr,1); do_eheader(fp,&file_version,fr,TRUE,&bDum); if(!bDum) { gmx_file("Cannot read energy file header. Corrupt file?"); } /* Now check whether this file is in single precision */ if (((fr->e_size && (fr->nre == nre) && (nre*4*sizeof(float) == fr->e_size)) || (fr->d_size && (fr->ndisre*sizeof(float)*2+sizeof(int) == fr->d_size)))){ fprintf(stderr,"Opened %s as single precision energy file\n",fn); free_enxnms(nre,nms); } else { gmx_fio_rewind(fp); gmx_fio_select(fp); gmx_fio_setprecision(fp,TRUE); do_enxnms(fp,&nre,&nms); do_eheader(fp,&file_version,fr,TRUE,&bDum); if(!bDum) { gmx_file("Cannot write energy file header; maybe you are out of quota?"); } if (((fr->e_size && (fr->nre == nre) && (nre*4*sizeof(double) == fr->e_size)) || (fr->d_size && (fr->ndisre*sizeof(double)*2+sizeof(int) == fr->d_size)))) fprintf(stderr,"Opened %s as double precision energy file\n",fn); else { if (empty_file(fn)) gmx_fatal(FARGS,"File %s is empty",fn); else gmx_fatal(FARGS,"Energy file %s not recognized, maybe different CPU?", fn); } free_enxnms(nre,nms); } free_enxframe(fr); sfree(fr); gmx_fio_rewind(fp); } else fp = gmx_fio_open(fn,mode); framenr=0; frametime=0; return fp; }