Exemplo n.º 1
0
static void edr_nms(int fp,int *nre,char ***nms)
{
  XDR  *xdr;
  bool bRead = gmx_fio_getread(fp);
  int  i;
  char **NM;

  xdr = gmx_fio_getxdr(fp);

  NM=*nms;
  
  if (!xdr_int(xdr,nre)) {
	  if(!bRead)
		  gmx_file("Cannot write energy names to file; maybe you are out of quota?");
    *nre=0;
    return;
  }
  if (*nre == -55555) {
    /* In the 4.1 edr format the first entry is the magic number */
    gmx_fatal(FARGS,"You are trying to read an edr file of GROMACS version 4.1 or later with GROMACS version 4.0");
  }
  if (NM == NULL) {
    snew(NM,*nre);
  }
  for(i=0; i<*nre; i++) {
    if (bRead && NM[i]) {
      sfree(NM[i]);
      NM[i] = NULL;
    }
	  if(!xdr_string(xdr,&(NM[i]),STRLEN))
		  gmx_file("Cannot write energy names to file; maybe you are out of quota?");
  }
  *nms=NM;
}
Exemplo n.º 2
0
static void edr_nms(int fp,int *nre,char ***nms)
{
  XDR  *xdr;
  bool bRead = gmx_fio_getread(fp);
  int  i;
  char **NM;

  xdr = gmx_fio_getxdr(fp);

  NM=*nms;
  
  if (!xdr_int(xdr,nre)) {
    *nre=0;
    return;
  }
  if (NM == NULL) {
    snew(NM,*nre);
  }
  for(i=0; i<*nre; i++) {
    if (bRead && NM[i]) {
      sfree(NM[i]);
      NM[i] = NULL;
    }
    xdr_string(xdr,&(NM[i]),STRLEN);
  }
  *nms=NM;
}
Exemplo n.º 3
0
static bool do_eheader(int fp,t_enxframe *fr,bool *bOK)
{
  int  block,i,dum=0;
  bool bRead = gmx_fio_getread(fp);
  int  tempfix_nr=0;

  *bOK=TRUE;
  if (!do_real(fr->t))
  {
      return FALSE;
  }
  if (!do_int (fr->step)    ||
      !do_int (fr->nre)     ||
      !do_int (fr->ndisre)  || 
      !do_int (fr->nblock))
  {
	  *bOK = FALSE;
  }

  if (*bOK && bRead && fr->nblock>70) 
  {
    /* Temporary fix for intermediate file version, only used by B. Hess */
    tempfix_nr = fr->nblock;
    fr->nblock = 1;
  }
	
  if (*bOK && bRead && fr->nblock>fr->nr_alloc)
  {
    srenew(fr->nr,fr->nblock);
    srenew(fr->b_alloc,fr->nblock);
    srenew(fr->block,fr->nblock);
    for(i=fr->nr_alloc; i<fr->nblock; i++) {
      fr->block[i]   = NULL;
      fr->b_alloc[i] = 0;
    }
    fr->nr_alloc = fr->nblock;
  }
  if (tempfix_nr)
    fr->nr[0] = tempfix_nr;
  else 
  {
    for(block=0; block<fr->nblock && *bOK; block++)
		if (!do_int (fr->nr[block])) 
			*bOK = FALSE;
  }
	
  if(*bOK)
  {
	  if (!do_int (fr->e_size)   ||
		  !do_int (fr->d_size)   ||
		  !do_int (dum))
	  {
		  *bOK = FALSE;
	  }
  }
	
  return *bOK;
}
Exemplo n.º 4
0
void do_enxnms(ener_file_t ef,int *nre,gmx_enxnm_t **nms)
{
    int  magic=-55555;
    XDR  *xdr;
    gmx_bool bRead = gmx_fio_getread(ef->fio);
    int  file_version;
    int  i;
   
    gmx_fio_checktype(ef->fio); 

    xdr = gmx_fio_getxdr(ef->fio);
    
    if (!xdr_int(xdr,&magic))
    {
        if(!bRead)
        {
            gmx_file("Cannot write energy names to file; maybe you are out of quota?");
        }
        *nre=0;
        return;
    }
    if (magic > 0)
    {
        /* Assume this is an old edr format */
        file_version = 1;
        *nre = magic;
        ef->eo.bOldFileOpen = TRUE;
        ef->eo.bReadFirstStep = FALSE;
        srenew(ef->eo.ener_prev,*nre);
    }
    else
    {
        ef->eo.bOldFileOpen=FALSE;

        if (magic != -55555)
        {
            gmx_fatal(FARGS,"Energy names magic number mismatch, this is not a GROMACS edr file");
        }
        file_version = enx_version;
        xdr_int(xdr,&file_version);
        if (file_version > enx_version)
        {
            gmx_fatal(FARGS,"reading tpx file (%s) version %d with version %d program",gmx_fio_getname(ef->fio),file_version,enx_version);
        }
        xdr_int(xdr,nre);
    }
    if (file_version != enx_version)
    {
        fprintf(stderr,"Note: enx file_version %d, software version %d\n",
                file_version,enx_version);
    }

    edr_strings(xdr,bRead,file_version,*nre,nms);
}
Exemplo n.º 5
0
void do_enxnms(int fp,int *nre,char ***nms)
{
  bool bRead;
  
  bRead = gmx_fio_getread(fp);
  if (gmx_fio_getftp(fp) == efEDR) {
    gmx_fio_select(fp);
    edr_nms(fp,nre,nms);
  }
  else if (bRead)
    rd_ener_nms(gmx_fio_getfp(fp),nre,nms);
  else
    wr_ener_nms(gmx_fio_getfp(fp),*nre,*nms);
}
Exemplo n.º 6
0
bool do_enx(int fp,t_enxframe *fr)
{
  int       i,block;
  bool      bRead,bOK,bOK1,bSane;
  real      tmp1,tmp2;

  bOK = TRUE;
  bRead = gmx_fio_getread(fp);
  if (!bRead) {  
    fr->e_size = fr->nre*sizeof(fr->ener[0].e)*4;
    fr->d_size = fr->ndisre*(sizeof(fr->rav[0]) + 
			   sizeof(fr->rt[0]));
  }
  gmx_fio_select(fp);

  if (!do_eheader(fp,fr,&bOK)) {
    if (bRead) {
	fprintf(stderr,"\rLast frame read %d                          ",framenr-1);
	if (!bOK)
	  fprintf(stderr,"\nWARNING: Incomplete frame: nr %6d time %8.3f\n",
		  framenr,fr->t);
    }
    return FALSE;
  }
  if (bRead) {
    if ( ( framenr<10 ) || ( framenr%10 == 0) ) 
      fprintf(stderr,"\rReading frame %6d time %8.3f           ",framenr,fr->t);
    framenr++;
  }
  /* Check sanity of this header */
  bSane = (fr->nre > 0 || fr->ndisre > 0);
  for(block=0; block<fr->nblock; block++)
    bSane = bSane || (fr->nr[block] > 0);
  if (!((fr->step >= 0) && bSane)) {
    fprintf(stderr,"\nWARNING: there may be something wrong with energy file %s\n",
	    gmx_fio_getname(fp));
    fprintf(stderr,"Found: step=%d, nre=%d, ndisre=%d, nblock=%d, time=%g.\n"
	    "Trying to skip frame expect a crash though\n",
	    fr->step,fr->nre,fr->ndisre,fr->nblock,fr->t);
  }
  if (bRead && fr->nre>fr->e_alloc) {
    srenew(fr->ener,fr->nre);
    fr->e_alloc = fr->nre;
  }
  for(i=0; i<fr->nre; i++) {
    bOK = bOK && do_real(fr->ener[i].e);
    
    tmp1 = fr->ener[i].eav;
    if((tmp1/(fr->step+1))<GMX_REAL_EPS)
      tmp1=0;
    bOK = bOK && do_real(tmp1);
    fr->ener[i].eav = tmp1;
    
    /* This is to save only in single precision (unless compiled in DP) */
    tmp2 = fr->ener[i].esum;
    bOK = bOK && do_real(tmp2);
    fr->ener[i].esum = tmp2;
    
    bOK = bOK && do_real(fr->ener[i].e2sum);
  }
  if (fr->ndisre) {
    if (bRead && fr->ndisre>fr->d_alloc) {
      srenew(fr->rav,fr->ndisre);
      srenew(fr->rt,fr->ndisre);
      fr->d_alloc = fr->ndisre;
    }
    ndo_real(fr->rav,fr->ndisre,bOK1);
    bOK = bOK && bOK1;
    ndo_real(fr->rt,fr->ndisre,bOK1);
    bOK = bOK && bOK1;
  }
  for(block=0; block<fr->nblock; block++) {
    if (bRead && fr->nr[block]>fr->b_alloc[block]) {
      srenew(fr->block[block],fr->nr[block]);
      fr->b_alloc[block] = fr->nr[block];
    }
    ndo_real(fr->block[block],fr->nr[block],bOK1);
    bOK = bOK && bOK1;
  }
  if (!bOK) {
    if (bRead) {
      fprintf(stderr,"\nLast frame read %d                               ",
	      framenr-1);
      fprintf(stderr,"\nWARNING: Incomplete frame: nr %6d time %8.3f     \n",
	      framenr,fr->t);
    } else 
      fatal_error(-1,"could not write energies");
    return FALSE; 
  }
  
  return TRUE;
}
Exemplo n.º 7
0
gmx_bool do_enx(ener_file_t ef,t_enxframe *fr)
{
    int       file_version=-1;
    int       i,b;
    gmx_bool      bRead,bOK,bOK1,bSane;
    real      tmp1,tmp2,rdum;
    char      buf[22];
    /*int       d_size;*/
    
    bOK = TRUE;
    bRead = gmx_fio_getread(ef->fio);
    if (!bRead)
    {  
        fr->e_size = fr->nre*sizeof(fr->ener[0].e)*4;
        /*d_size = fr->ndisre*(sizeof(real)*2);*/
    }
    gmx_fio_checktype(ef->fio);

    if (!do_eheader(ef,&file_version,fr,-1,NULL,&bOK))
    {
        if (bRead)
        {
            fprintf(stderr,"\rLast energy frame read %d time %8.3f         ",
                    ef->framenr-1,ef->frametime);
            if (!bOK)
            {
                fprintf(stderr,
                        "\nWARNING: Incomplete energy frame: nr %d time %8.3f\n",
                        ef->framenr,fr->t);
            }
        }
        else
        {
            gmx_file("Cannot write energy file header; maybe you are out of quota?");
        }
        return FALSE;
    }
    if (bRead)
    {
        if ((ef->framenr <   20 || ef->framenr %   10 == 0) &&
            (ef->framenr <  200 || ef->framenr %  100 == 0) &&
            (ef->framenr < 2000 || ef->framenr % 1000 == 0))
        {
            fprintf(stderr,"\rReading energy frame %6d time %8.3f         ",
                    ef->framenr,fr->t);
        }
        ef->framenr++;
        ef->frametime = fr->t;
    }
    /* Check sanity of this header */
    bSane = fr->nre > 0 ;
    for(b=0; b<fr->nblock; b++)
    {
        bSane = bSane || (fr->block[b].nsub > 0);
    }
    if (!((fr->step >= 0) && bSane))
    {
        fprintf(stderr,"\nWARNING: there may be something wrong with energy file %s\n",
                gmx_fio_getname(ef->fio));
        fprintf(stderr,"Found: step=%s, nre=%d, nblock=%d, time=%g.\n"
                "Trying to skip frame expect a crash though\n",
                gmx_step_str(fr->step,buf),fr->nre,fr->nblock,fr->t);
    }
    if (bRead && fr->nre > fr->e_alloc)
    {
        srenew(fr->ener,fr->nre);
        for(i=fr->e_alloc; (i<fr->nre); i++)
        {
            fr->ener[i].e    = 0;
            fr->ener[i].eav  = 0;
            fr->ener[i].esum = 0;
        }
        fr->e_alloc = fr->nre;
    }
    
    for(i=0; i<fr->nre; i++)
    {
        bOK = bOK && gmx_fio_do_real(ef->fio, fr->ener[i].e);
        
        /* Do not store sums of length 1,
         * since this does not add information.
         */
        if (file_version == 1 ||
            (bRead && fr->nsum > 0) || fr->nsum > 1)
        {
            tmp1 = fr->ener[i].eav;
            bOK = bOK && gmx_fio_do_real(ef->fio, tmp1);
            if (bRead)
                fr->ener[i].eav = tmp1;
            
            /* This is to save only in single precision (unless compiled in DP) */
            tmp2 = fr->ener[i].esum;
            bOK = bOK && gmx_fio_do_real(ef->fio, tmp2);
            if (bRead)
                fr->ener[i].esum = tmp2;
            
            if (file_version == 1)
            {
                /* Old, unused real */
                rdum = 0;
                bOK = bOK && gmx_fio_do_real(ef->fio, rdum);
            }
        }
    }
    
    /* Here we can not check for file_version==1, since one could have
     * continued an old format simulation with a new one with mdrun -append.
     */
    if (bRead && ef->eo.bOldFileOpen)
    {
        /* Convert old full simulation sums to sums between energy frames */
        convert_full_sums(&(ef->eo),fr);
    }
    /* read the blocks */
    for(b=0; b<fr->nblock; b++)
    {
        /* now read the subblocks. */
        int nsub=fr->block[b].nsub; /* shortcut */
        int i;

        for(i=0;i<nsub;i++)
        {
            t_enxsubblock *sub=&(fr->block[b].sub[i]); /* shortcut */

            if (bRead)
            {
                enxsubblock_alloc(sub);
            }

            /* read/write data */
            bOK1=TRUE;
            switch (sub->type)
            {
                case xdr_datatype_float:
                    bOK1=gmx_fio_ndo_float(ef->fio, sub->fval, sub->nr); 
                    break;
                case xdr_datatype_double:
                    bOK1=gmx_fio_ndo_double(ef->fio, sub->dval, sub->nr); 
                    break;
                case xdr_datatype_int:
                    bOK1=gmx_fio_ndo_int(ef->fio, sub->ival, sub->nr);
                    break;
                case xdr_datatype_large_int:
                    bOK1=gmx_fio_ndo_gmx_large_int(ef->fio, sub->lval, sub->nr);
                    break;
                case xdr_datatype_char:
                    bOK1=gmx_fio_ndo_uchar(ef->fio, sub->cval, sub->nr);
                    break;
                case xdr_datatype_string:
                    bOK1=gmx_fio_ndo_string(ef->fio, sub->sval, sub->nr);
                    break;
                default:
                    gmx_incons("Reading unknown block data type: this file is corrupted or from the future");
            }
            bOK = bOK && bOK1;
        }
    }
    
    if(!bRead)
    {
        if( gmx_fio_flush(ef->fio) != 0)
        {
            gmx_file("Cannot write energy file; maybe you are out of quota?");
        }
    }
    
    if (!bOK)
    {
        if (bRead)
        {
            fprintf(stderr,"\nLast energy frame read %d",
                    ef->framenr-1);
            fprintf(stderr,"\nWARNING: Incomplete energy frame: nr %d time %8.3f\n",
                    ef->framenr,fr->t);
        }
        else
        {
            gmx_fatal(FARGS,"could not write energies");
        }
        return FALSE; 
    }
    
    return TRUE;
}
Exemplo n.º 8
0
static gmx_bool do_eheader(ener_file_t ef,int *file_version,t_enxframe *fr,
                       int nre_test,gmx_bool *bWrongPrecision,gmx_bool *bOK)
{
    int  magic=-7777777;
    real first_real_to_check;
    int  b,i,zero=0,dum=0;
    gmx_bool bRead = gmx_fio_getread(ef->fio);
    int  tempfix_nr=0;
    int  ndisre=0;
    int  startb=0;
#ifndef GMX_DOUBLE
    xdr_datatype dtreal=xdr_datatype_float; 
#else
    xdr_datatype dtreal=xdr_datatype_double; 
#endif
    
    if (nre_test >= 0)
    {
        *bWrongPrecision = FALSE;
    }

    *bOK=TRUE;
    /* The original energy frame started with a real,
     * so we have to use a real for compatibility.
     * This is VERY DIRTY code, since do_eheader can be called
     * with the wrong precision set and then we could read r > -1e10,
     * while actually the intention was r < -1e10.
     * When nre_test >= 0, do_eheader should therefore terminate
     * before the number of i/o calls starts depending on what has been read
     * (which is the case for for instance the block sizes for variable
     * number of blocks, where this number is read before).
     */
    first_real_to_check = -2e10;
    if (!gmx_fio_do_real(ef->fio, first_real_to_check))
    {
        return FALSE;
    }
    if (first_real_to_check > -1e10)
    {
        /* Assume we are reading an old format */
        *file_version = 1;
        fr->t = first_real_to_check;
        if (!gmx_fio_do_int(ef->fio, dum))   *bOK = FALSE;
        fr->step = dum;
    }
    else
    {
        if (!gmx_fio_do_int(ef->fio, magic))       *bOK = FALSE;
        if (magic != -7777777)
        {
            enx_warning("Energy header magic number mismatch, this is not a GROMACS edr file");
            *bOK=FALSE;
            return FALSE;
        }
        *file_version = enx_version;
        if (!gmx_fio_do_int(ef->fio, *file_version)) *bOK = FALSE;
        if (*bOK && *file_version > enx_version)
        {
            gmx_fatal(FARGS,"reading tpx file (%s) version %d with version %d program",gmx_fio_getname(ef->fio),file_version,enx_version);
        }
        if (!gmx_fio_do_double(ef->fio, fr->t))       *bOK = FALSE;
        if (!gmx_fio_do_gmx_large_int(ef->fio, fr->step)) *bOK = FALSE;
        if (!bRead && fr->nsum == 1) {
            /* Do not store sums of length 1,
             * since this does not add information.
             */
            if (!gmx_fio_do_int(ef->fio, zero))      *bOK = FALSE;
        } else {
            if (!gmx_fio_do_int(ef->fio, fr->nsum))  *bOK = FALSE;
        }
        if (*file_version >= 3)
        {
            if (!gmx_fio_do_gmx_large_int(ef->fio, fr->nsteps)) *bOK = FALSE;
        }
        else
        {
            fr->nsteps = max(1,fr->nsum);
        }
        if (*file_version >= 5)
        {
            if (!gmx_fio_do_double(ef->fio, fr->dt)) *bOK = FALSE;
        }
        else
        {
            fr->dt = 0;
        }
    }
    if (!gmx_fio_do_int(ef->fio, fr->nre))     *bOK = FALSE;
    if (*file_version < 4)
    {
        if (!gmx_fio_do_int(ef->fio, ndisre))  *bOK = FALSE;
    }
    else
    {
        /* now reserved for possible future use */
        if (!gmx_fio_do_int(ef->fio, dum))  *bOK = FALSE;
    }

    if (!gmx_fio_do_int(ef->fio, fr->nblock))  *bOK = FALSE;
    if (fr->nblock < 0) *bOK=FALSE;

    if (ndisre!=0)
    {
        if (*file_version >= 4)
        {
            enx_warning("Distance restraint blocks in old style in new style file");
            *bOK=FALSE;
            return FALSE;
        }
        fr->nblock+=1;
    }


    /* Frames could have nre=0, so we can not rely only on the fr->nre check */
    if (bRead && nre_test >= 0 &&
        ((fr->nre > 0 && fr->nre != nre_test) ||
         fr->nre < 0 || ndisre < 0 || fr->nblock < 0))
    {
        *bWrongPrecision = TRUE;
        return *bOK;
    }

    /* we now know what these should be, or we've already bailed out because
       of wrong precision */
    if ( *file_version==1 && (fr->t < 0 || fr->t > 1e20 || fr->step < 0 ) )
    {
        enx_warning("edr file with negative step number or unreasonable time (and without version number).");
        *bOK=FALSE;
        return FALSE;
    }


    if (*bOK && bRead)
    {
        add_blocks_enxframe(fr, fr->nblock);
    }

    startb=0;
    if (ndisre>0)
    {
        /* sub[0] is the instantaneous data, sub[1] is time averaged */
        add_subblocks_enxblock(&(fr->block[0]), 2);
        fr->block[0].id=enxDISRE;
        fr->block[0].sub[0].nr=ndisre;
        fr->block[0].sub[1].nr=ndisre;
        fr->block[0].sub[0].type=dtreal;
        fr->block[0].sub[1].type=dtreal;
        startb++;
    }

    /* read block header info */
    for(b=startb; b<fr->nblock; b++)
    {
        if (*file_version<4)
        {
            /* blocks in old version files always have 1 subblock that 
               consists of reals. */
            int nrint;

            if (bRead)
            {
                add_subblocks_enxblock(&(fr->block[b]), 1);
            }
            else
            {
                if (fr->block[b].nsub != 1)
                {
                    gmx_incons("Writing an old version .edr file with too many subblocks");
                }
                if (fr->block[b].sub[0].type != dtreal)
                {
                    gmx_incons("Writing an old version .edr file the wrong subblock type");
                }
            }
            nrint = fr->block[b].sub[0].nr;
            
            if (!gmx_fio_do_int(ef->fio, nrint))
            {
                *bOK = FALSE;
            }
            fr->block[b].id          = b - startb;
            fr->block[b].sub[0].nr   = nrint;
            fr->block[b].sub[0].type = dtreal;
        }
        else
        {
            int i;
            /* in the new version files, the block header only contains
               the ID and the number of subblocks */
            int nsub=fr->block[b].nsub;
            *bOK = *bOK && gmx_fio_do_int(ef->fio, fr->block[b].id);
            *bOK = *bOK && gmx_fio_do_int(ef->fio, nsub);

            fr->block[b].nsub=nsub;
            if (bRead)
                add_subblocks_enxblock(&(fr->block[b]), nsub);

            /* read/write type & size for each subblock */
            for(i=0;i<nsub;i++)
            {
                t_enxsubblock *sub=&(fr->block[b].sub[i]); /* shortcut */
                int typenr=sub->type;

                *bOK=*bOK && gmx_fio_do_int(ef->fio, typenr);
                *bOK=*bOK && gmx_fio_do_int(ef->fio, sub->nr);

                sub->type = (xdr_datatype)typenr;
            }
        }
    }
    if (!gmx_fio_do_int(ef->fio, fr->e_size))  *bOK = FALSE;

    /* now reserved for possible future use */
    if (!gmx_fio_do_int(ef->fio, dum))  *bOK = FALSE;

    /* Do a dummy int to keep the format compatible with the old code */
    if (!gmx_fio_do_int(ef->fio, dum))         *bOK = FALSE;
    
    if (*bOK && *file_version == 1 && nre_test < 0)
    {
#if 0
        if (fp >= ener_old_nalloc)
        {
            gmx_incons("Problem with reading old format energy files");
        }
#endif
        
        if (!ef->eo.bReadFirstStep)
        {
            ef->eo.bReadFirstStep = TRUE;
            ef->eo.first_step     = fr->step;
            ef->eo.step_prev      = fr->step;
            ef->eo.nsum_prev      = 0;
        }
        
        fr->nsum   = fr->step - ef->eo.first_step + 1;
        fr->nsteps = fr->step - ef->eo.step_prev;
        fr->dt     = 0;
    }
	
    return *bOK;
}
Exemplo n.º 9
0
bool do_enx(int fp,t_enxframe *fr)
{
    int       file_version=-1;
    int       i,block;
    bool      bRead,bOK,bOK1,bSane;
    real      tmp1,tmp2,rdum;
    char      buf[22];
    
    bOK = TRUE;
    bRead = gmx_fio_getread(fp);
    if (!bRead)
    {  
        fr->e_size = fr->nre*sizeof(fr->ener[0].e)*4;
        fr->d_size = fr->ndisre*(sizeof(fr->disre_rm3tav[0]) + 
                                 sizeof(fr->disre_rt[0]));
    }
    gmx_fio_select(fp);
    
    if (!do_eheader(fp,&file_version,fr,FALSE,&bOK))
    {
        if (bRead)
        {
            fprintf(stderr,"\rLast energy frame read %d time %8.3f           ",
                    framenr-1,frametime);
            if (!bOK)
            {
                fprintf(stderr,
                        "\nWARNING: Incomplete energy frame: nr %d time %8.3f\n",
                        framenr,fr->t);
            }
        }
        else
        {
            gmx_file("Cannot write energy file header; maybe you are out of quota?");
        }
        return FALSE;
    }
    if (bRead)
    {
        if ((framenr <   20 || framenr %   10 == 0) &&
            (framenr <  200 || framenr %  100 == 0) &&
            (framenr < 2000 || framenr % 1000 == 0))
        {
            fprintf(stderr,"\rReading energy frame %6d time %8.3f           ",
                    framenr,fr->t);
        }
        framenr++;
        frametime = fr->t;
    }
    /* Check sanity of this header */
    bSane = (fr->nre > 0 || fr->ndisre > 0);
    for(block=0; block<fr->nblock; block++)
    {
        bSane = bSane || (fr->nr[block] > 0);
    }
    if (!((fr->step >= 0) && bSane))
    {
        fprintf(stderr,"\nWARNING: there may be something wrong with energy file %s\n",
                gmx_fio_getname(fp));
        fprintf(stderr,"Found: step=%s, nre=%d, ndisre=%d, nblock=%d, time=%g.\n"
                "Trying to skip frame expect a crash though\n",
                gmx_step_str(fr->step,buf),fr->nre,fr->ndisre,fr->nblock,fr->t);
    }
    if (bRead && fr->nre > fr->e_alloc)
    {
        srenew(fr->ener,fr->nre);
        for(i=fr->e_alloc; (i<fr->nre); i++)
        {
            fr->ener[i].e    = 0;
            fr->ener[i].eav  = 0;
            fr->ener[i].esum = 0;
        }
        fr->e_alloc = fr->nre;
    }
    
    for(i=0; i<fr->nre; i++)
    {
        bOK = bOK && do_real(fr->ener[i].e);
        
        /* Do not store sums of length 1,
         * since this does not add information.
         */
        if (file_version == 1 ||
            (bRead && fr->nsum > 0) || fr->nsum > 1)
        {
            tmp1 = fr->ener[i].eav;
            bOK = bOK && do_real(tmp1);
            if (bRead)
                fr->ener[i].eav = tmp1;
            
            /* This is to save only in single precision (unless compiled in DP) */
            tmp2 = fr->ener[i].esum;
            bOK = bOK && do_real(tmp2);
            if (bRead)
                fr->ener[i].esum = tmp2;
            
            if (file_version == 1)
            {
                /* Old, unused real */
                rdum = 0;
                bOK = bOK && do_real(rdum);
            }
        }
    }
    
    /* Here we can not check for file_version==1, since one could have
     * continued an old format simulation with a new one with mdrun -append.
     */
    if (bRead && fp < ener_old_nalloc && ener_old[fp].bOldFileOpen)
    {
        /* Convert old full simulation sums to sums between energy frames */
        convert_full_sums(&ener_old[fp],fr);
    }
    
    if (fr->ndisre)
    {
        if (bRead && fr->ndisre>fr->d_alloc)
        {
            srenew(fr->disre_rm3tav,fr->ndisre);
            srenew(fr->disre_rt,fr->ndisre);
            fr->d_alloc = fr->ndisre;
        }
        ndo_real(fr->disre_rm3tav,fr->ndisre,bOK1);
        bOK = bOK && bOK1;
        ndo_real(fr->disre_rt,fr->ndisre,bOK1);
        bOK = bOK && bOK1;
    }
    for(block=0; block<fr->nblock; block++)
    {
        if (bRead && fr->nr[block]>fr->b_alloc[block])
        {
            srenew(fr->block[block],fr->nr[block]);
            fr->b_alloc[block] = fr->nr[block];
        }
        ndo_real(fr->block[block],fr->nr[block],bOK1);
        bOK = bOK && bOK1;
    }
    
    if(!bRead)
    {
        if( gmx_fio_flush(fp) != 0)
        {
            gmx_file("Cannot write energy file; maybe you are out of quota?");
        }
    }
    
    if (!bOK)
    {
        if (bRead)
        {
            fprintf(stderr,"\nLast energy frame read %d",
                    framenr-1);
            fprintf(stderr,"\nWARNING: Incomplete energy frame: nr %d time %8.3f\n",
                    framenr,fr->t);
        }
        else
        {
            gmx_fatal(FARGS,"could not write energies");
        }
        return FALSE; 
    }
    
    return TRUE;
}
Exemplo n.º 10
0
static bool do_eheader(int fp,int *file_version,t_enxframe *fr,bool bTest,
                       bool *bOK)
{
    int  magic=-7777777;
    real r;
    int  block,i,zero=0,dum=0;
    bool bRead = gmx_fio_getread(fp);
    int  tempfix_nr=0;
    
    *bOK=TRUE;
    /* The original energy frame started with a real,
     * so we have to use a real for compatibility.
     */
    r = -2e10;
    if (!do_real(r))           return FALSE;
    if (r > -1e10)
    {
        /* Assume we are reading an old format */
        *file_version = 1;
        fr->t = r;
        if (!do_int(dum))   *bOK = FALSE;
        fr->step = dum;
    }
    else
    {
        if (!do_int (magic))       *bOK = FALSE;
        if (magic != -7777777)
        {
            gmx_fatal(FARGS,"Energy header magic number mismatch, this is not a GROMACS edr file");
        }
        *file_version = enx_version;
        if (!do_int (*file_version)) *bOK = FALSE;
        if (*bOK && *file_version > enx_version)
        {
            gmx_fatal(FARGS,"reading tpx file (%s) version %d with version %d program",gmx_fio_getname(fp),file_version,enx_version);
        }
        if (!do_double(fr->t))       *bOK = FALSE;
        if (!do_gmx_step_t(fr->step)) *bOK = FALSE;
        if (!bRead && fr->nsum == 1) {
            /* Do not store sums of length 1,
             * since this does not add information.
             */
            if (!do_int (zero))      *bOK = FALSE;
        } else {
            if (!do_int (fr->nsum))  *bOK = FALSE;
        }
        if (*file_version >= 3)
        {
            do_gmx_step_t(fr->nsteps);
        }
        else
        {
            fr->nsteps = max(1,fr->nsum);
        }
    }
    if (!do_int (fr->nre))     *bOK = FALSE;
    if (!do_int (fr->ndisre))  *bOK = FALSE;
    if (!do_int (fr->nblock))  *bOK = FALSE;
	
    if (*bOK && bRead && fr->nblock>fr->nr_alloc)
    {
        srenew(fr->nr,fr->nblock);
        srenew(fr->b_alloc,fr->nblock);
        srenew(fr->block,fr->nblock);
        for(i=fr->nr_alloc; i<fr->nblock; i++) {
            fr->block[i]   = NULL;
            fr->b_alloc[i] = 0;
        }
        fr->nr_alloc = fr->nblock;
    }
    for(block=0; block<fr->nblock; block++)
    {
        if (!do_int (fr->nr[block])) 
        {
            *bOK = FALSE;
        }
    }
    if (!do_int (fr->e_size))  *bOK = FALSE;
    if (!do_int (fr->d_size))  *bOK = FALSE;
    /* Do a dummy int to keep the format compatible with the old code */
    if (!do_int (dum))         *bOK = FALSE;
    
    
    if (*bOK && *file_version == 1 && !bTest)
    {
        if (fp >= ener_old_nalloc)
        {
            gmx_incons("Problem with reading old format energy files");
        }
        
        if (!ener_old[fp].bReadFirstStep)
        {
            ener_old[fp].bReadFirstStep = TRUE;
            ener_old[fp].first_step     = fr->step;
            ener_old[fp].nsum_prev      = 0;
        }
        
        fr->nsum = fr->step - ener_old[fp].first_step + 1;
        fr->nsteps = fr->nsum;
    }
	
    return *bOK;
}
Exemplo n.º 11
0
void do_enxnms(int fp,int *nre,gmx_enxnm_t **nms)
{
    int  magic=-55555;
    XDR  *xdr;
    bool bRead = gmx_fio_getread(fp);
    int  file_version;
    int  i;
    
    gmx_fio_select(fp);

    xdr = gmx_fio_getxdr(fp);
    
    if (!xdr_int(xdr,&magic))
    {
        if(!bRead)
        {
            gmx_file("Cannot write energy names to file; maybe you are out of quota?");
        }
        *nre=0;
        return;
    }
    if (magic > 0)
    {
        /* Assume this is an old edr format */
        file_version = 1;
        *nre = magic;

        if (fp >= ener_old_nalloc)
        {
            srenew(ener_old,fp + 1);
            for(i=ener_old_nalloc; i<fp+1; i++) {
                ener_old[i].bOldFileOpen = FALSE;
                ener_old[i].ener_prev = NULL;
            }
            ener_old_nalloc = fp + 1;
        }
        ener_old[fp].bOldFileOpen = TRUE;
        ener_old[fp].bReadFirstStep = FALSE;
        srenew(ener_old[fp].ener_prev,*nre);
    }
    else
    {
        if (fp < ener_old_nalloc)
        {
             ener_old[fp].bOldFileOpen = FALSE;
        }

        if (magic != -55555)
        {
            gmx_fatal(FARGS,"Energy names magic number mismatch, this is not a GROMACS edr file");
        }
        file_version = enx_version;
        xdr_int(xdr,&file_version);
        if (file_version > enx_version)
        {
            gmx_fatal(FARGS,"reading tpx file (%s) version %d with version %d program",gmx_fio_getname(fp),file_version,enx_version);
        }
        xdr_int(xdr,nre);
    }
    if (file_version != enx_version)
    {
        fprintf(stderr,"Note: enx file_version %d, software version %d\n",
                file_version,enx_version);
    }

    edr_strings(xdr,bRead,file_version,*nre,nms);
}