From 4bd00f0d606ba94e0e61994c087369ee125297b2 Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Mon, 20 Jul 2015 12:35:31 +0300 Subject: [PATCH] Rename trnio routines - Rename all routines from trnio.h to gmx_trr_*, and replace trn with trr also in the implementation. Use more comprehensible names than read_htrn(). - Fix one missing gmx_trr_close() in eigio.c. - Get rid of contrib/anaf.c, which was some cut-down version of gmx dump. Change-Id: Id4ea14e83ce14089bbdf0e672f15531cf0f22e61 --- src/contrib/anaf.c | 166 -------------------------- src/gromacs/fileio/mdoutf.cpp | 14 +-- src/gromacs/fileio/trrio.cpp | 95 +++++++-------- src/gromacs/fileio/trrio.h | 99 +++++++-------- src/gromacs/fileio/trxio.cpp | 16 +-- src/gromacs/gmxana/eigio.c | 35 +++--- src/gromacs/gmxana/eigio.h | 6 +- src/gromacs/gmxana/gmx_angle.c | 14 +-- src/gromacs/gmxana/gmx_trjconv.c | 18 +-- src/gromacs/gmxpreprocess/readrot.cpp | 18 +-- src/gromacs/tools/convert_tpr.cpp | 10 +- src/gromacs/tools/dump.cpp | 60 +++++----- 12 files changed, 192 insertions(+), 359 deletions(-) delete mode 100644 src/contrib/anaf.c diff --git a/src/contrib/anaf.c b/src/contrib/anaf.c deleted file mode 100644 index df4d1f8681..0000000000 --- a/src/contrib/anaf.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * - * This source code is part of - * - * G R O M A C S - * - * GROningen MAchine for Chemical Simulations - * - * VERSION 3.3.99_development_20071104 - * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others. - * Copyright (c) 1991-2000, University of Groningen, The Netherlands. - * Copyright (c) 2001-2006, The GROMACS development team, - * check out http://www.gromacs.org for more information. - - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * If you want to redistribute modifications, please consider that - * scientific software is very special. Version control is crucial - - * bugs must be traceable. We will be happy to consider code for - * inclusion in the official distribution, but derived work must not - * be called official GROMACS. Details are found in the README & COPYING - * files - if they are missing, get the official version at www.gromacs.org. - * - * To help us fund GROMACS development, we humbly ask that you cite - * the papers on the package - you can find them in the top README file. - * - * For more info, check our website at http://www.gromacs.org - * - * And Hey: - * Groningen Machine for Chemical Simulation - */ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include "macros.h" -#include "gromacs/utility/futil.h" -#include "gromacs/commandline/pargs.h" -#include "copyrite.h" -#include "txtdump.h" -#include "gromacs/utility/fatalerror.h" -#include "gromacs/fileio/xtcio.h" -#include "gromacs/fileio/enxio.h" -#include "gromacs/utility/smalloc.h" -#include "gromacs/fileio/gmxfio.h" -#include "gromacs/fileio/tpxio.h" -#include "gromacs/fileio/trrio.h" -#include "txtdump.h" -#include "gromacs/math/vec.h" - -static char *nm[5] = { "OW", "HW1", "HW2", "DW", "SW" }; - -static void list_trn(char *fn) -{ - static real mass[5] = { 15.9994, 1.008, 1.008, 0.0, 0.0 }; - int i,j=0,m,fpread,fpwrite,nframe; - rvec *x,*v,*f,fmol[2],xcm[2],torque[j],dx; - real mmm,len; - matrix box; - t_trnheader trn; - gmx_bool bOK; - - printf("Going to open %s\n",fn); - fpread = open_trn(fn,"r"); - fpwrite = open_tpx(NULL,"w"); - - mmm=mass[0]+2*mass[1]; - for(i=0; (i<5); i++) - mass[i] /= mmm; - - nframe = 0; - while (fread_trnheader(fpread,&trn,&bOK)) { - snew(x,trn.natoms); - snew(v,trn.natoms); - snew(f,trn.natoms); - if (fread_htrn(fpread,&trn, - trn.box_size ? box : NULL, - trn.x_size ? x : NULL, - trn.v_size ? v : NULL, - trn.f_size ? f : NULL)) { - - if (trn.x_size && trn.f_size) { - printf("There are %d atoms\n",trn.natoms); - for(j=0; (j<2); j++) { - clear_rvec(xcm[j]); - clear_rvec(fmol[j]); - clear_rvec(torque[j]); - for(i=5*j; (i<5*j+5); i++) { - rvec_inc(fmol[j],f[i]); - for(m=0; (mfp_trn = open_trn(filename, filemode); + of->fp_trn = gmx_trr_open(filename, filemode); break; case efTNG: gmx_tng_open(filename, filemode[0], &of->tng); @@ -315,11 +315,11 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr, { if (of->fp_trn) { - fwrite_trn(of->fp_trn, step, t, state_local->lambda[efptFEP], - state_local->box, top_global->natoms, - (mdof_flags & MDOF_X) ? state_global->x : NULL, - (mdof_flags & MDOF_V) ? global_v : NULL, - (mdof_flags & MDOF_F) ? f_global : NULL); + gmx_trr_write_frame(of->fp_trn, step, t, state_local->lambda[efptFEP], + state_local->box, top_global->natoms, + (mdof_flags & MDOF_X) ? state_global->x : NULL, + (mdof_flags & MDOF_V) ? global_v : NULL, + (mdof_flags & MDOF_F) ? f_global : NULL); if (gmx_fio_flush(of->fp_trn) != 0) { gmx_file("Cannot write trajectory; maybe you are out of disk space?"); @@ -405,7 +405,7 @@ void done_mdoutf(gmx_mdoutf_t of) } if (of->fp_trn) { - close_trn(of->fp_trn); + gmx_trr_close(of->fp_trn); } if (of->fp_dhdl != NULL) { diff --git a/src/gromacs/fileio/trrio.cpp b/src/gromacs/fileio/trrio.cpp index 9951fba746..f3e16b1f4d 100644 --- a/src/gromacs/fileio/trrio.cpp +++ b/src/gromacs/fileio/trrio.cpp @@ -51,7 +51,7 @@ #define BUFSIZE 128 #define GROMACS_MAGIC 1993 -static int nFloatSize(t_trnheader *sh) +static int nFloatSize(gmx_trr_header_t *sh) { int nflsize = 0; @@ -73,7 +73,7 @@ static int nFloatSize(t_trnheader *sh) } else { - gmx_file("Can not determine precision of trn file"); + gmx_file("Can not determine precision of trr file"); } if (((nflsize != sizeof(float)) && (nflsize != sizeof(double)))) @@ -84,7 +84,8 @@ static int nFloatSize(t_trnheader *sh) return nflsize; } -static gmx_bool do_trnheader(t_fileio *fio, gmx_bool bRead, t_trnheader *sh, gmx_bool *bOK) +static gmx_bool +do_trr_frame_header(t_fileio *fio, bool bRead, gmx_trr_header_t *sh, gmx_bool *bOK) { int magic = GROMACS_MAGIC; static gmx_bool bFirst = TRUE; @@ -102,7 +103,7 @@ static gmx_bool do_trnheader(t_fileio *fio, gmx_bool bRead, t_trnheader *sh, gmx *bOK = *bOK && gmx_fio_do_string(fio, buf); if (bFirst) { - fprintf(stderr, "trn version: %s ", buf); + fprintf(stderr, "trr version: %s ", buf); } } else @@ -143,8 +144,9 @@ static gmx_bool do_trnheader(t_fileio *fio, gmx_bool bRead, t_trnheader *sh, gmx return *bOK; } -static gmx_bool do_htrn(t_fileio *fio, t_trnheader *sh, - rvec *box, rvec *x, rvec *v, rvec *f) +static gmx_bool +do_trr_frame_data(t_fileio *fio, gmx_trr_header_t *sh, + rvec *box, rvec *x, rvec *v, rvec *f) { matrix pv; gmx_bool bOK; @@ -178,11 +180,12 @@ static gmx_bool do_htrn(t_fileio *fio, t_trnheader *sh, return bOK; } -static gmx_bool do_trn(t_fileio *fio, gmx_bool bRead, int *step, real *t, real *lambda, - rvec *box, int *natoms, rvec *x, rvec *v, rvec *f) +static gmx_bool +do_trr_frame(t_fileio *fio, bool bRead, int *step, real *t, real *lambda, + rvec *box, int *natoms, rvec *x, rvec *v, rvec *f) { - t_trnheader *sh; - gmx_bool bOK; + gmx_trr_header_t *sh; + gmx_bool bOK; snew(sh, 1); if (!bRead) @@ -197,7 +200,7 @@ static gmx_bool do_trn(t_fileio *fio, gmx_bool bRead, int *step, real *t, real * sh->t = *t; sh->lambda = *lambda; } - if (!do_trnheader(fio, bRead, sh, &bOK)) + if (!do_trr_frame_header(fio, bRead, sh, &bOK)) { return FALSE; } @@ -209,22 +212,22 @@ static gmx_bool do_trn(t_fileio *fio, gmx_bool bRead, int *step, real *t, real * *lambda = sh->lambda; if (sh->ir_size) { - gmx_file("inputrec in trn file"); + gmx_file("inputrec in trr file"); } if (sh->e_size) { - gmx_file("energies in trn file"); + gmx_file("energies in trr file"); } if (sh->top_size) { - gmx_file("topology in trn file"); + gmx_file("topology in trr file"); } if (sh->sym_size) { - gmx_file("symbol table in trn file"); + gmx_file("symbol table in trr file"); } } - bOK = do_htrn(fio, sh, box, x, v, f); + bOK = do_trr_frame_data(fio, sh, box, x, v, f); sfree(sh); @@ -237,72 +240,66 @@ static gmx_bool do_trn(t_fileio *fio, gmx_bool bRead, int *step, real *t, real * * ************************************************************/ -void read_trnheader(const char *fn, t_trnheader *trn) +void gmx_trr_read_single_header(const char *fn, gmx_trr_header_t *header) { - t_fileio *fio; + t_fileio *fio = gmx_trr_open(fn, "r"); gmx_bool bOK; - - fio = open_trn(fn, "r"); - if (!do_trnheader(fio, TRUE, trn, &bOK)) + if (!do_trr_frame_header(fio, true, header, &bOK)) { gmx_fatal(FARGS, "Empty file %s", fn); } - close_trn(fio); + gmx_trr_close(fio); } -gmx_bool fread_trnheader(t_fileio *fio, t_trnheader *trn, gmx_bool *bOK) +gmx_bool gmx_trr_read_frame_header(t_fileio *fio, gmx_trr_header_t *header, gmx_bool *bOK) { - return do_trnheader(fio, TRUE, trn, bOK); + return do_trr_frame_header(fio, true, header, bOK); } -void write_trn(const char *fn, int step, real t, real lambda, - rvec *box, int natoms, rvec *x, rvec *v, rvec *f) +void gmx_trr_write_single_frame(const char *fn, int step, real t, real lambda, + rvec *box, int natoms, rvec *x, rvec *v, rvec *f) { - t_fileio *fio; - - fio = open_trn(fn, "w"); - do_trn(fio, FALSE, &step, &t, &lambda, box, &natoms, x, v, f); - close_trn(fio); + t_fileio *fio = gmx_trr_open(fn, "w"); + do_trr_frame(fio, false, &step, &t, &lambda, box, &natoms, x, v, f); + gmx_trr_close(fio); } -void read_trn(const char *fn, int *step, real *t, real *lambda, - rvec *box, int *natoms, rvec *x, rvec *v, rvec *f) +void gmx_trr_read_single_frame(const char *fn, int *step, real *t, real *lambda, + rvec *box, int *natoms, rvec *x, rvec *v, rvec *f) { - t_fileio *fio; - - fio = open_trn(fn, "r"); - (void) do_trn(fio, TRUE, step, t, lambda, box, natoms, x, v, f); - close_trn(fio); + t_fileio *fio = gmx_trr_open(fn, "r"); + do_trr_frame(fio, true, step, t, lambda, box, natoms, x, v, f); + gmx_trr_close(fio); } -void fwrite_trn(t_fileio *fio, int step, real t, real lambda, - rvec *box, int natoms, rvec *x, rvec *v, rvec *f) +void gmx_trr_write_frame(t_fileio *fio, int step, real t, real lambda, + rvec *box, int natoms, rvec *x, rvec *v, rvec *f) { - if (do_trn(fio, FALSE, &step, &t, &lambda, box, &natoms, x, v, f) == FALSE) + if (!do_trr_frame(fio, false, &step, &t, &lambda, box, &natoms, x, v, f)) { gmx_file("Cannot write trajectory frame; maybe you are out of disk space?"); } } -gmx_bool fread_trn(t_fileio *fio, int *step, real *t, real *lambda, - rvec *box, int *natoms, rvec *x, rvec *v, rvec *f) +gmx_bool gmx_trr_read_frame(t_fileio *fio, int *step, real *t, real *lambda, + rvec *box, int *natoms, rvec *x, rvec *v, rvec *f) { - return do_trn(fio, TRUE, step, t, lambda, box, natoms, x, v, f); + return do_trr_frame(fio, true, step, t, lambda, box, natoms, x, v, f); } -gmx_bool fread_htrn(t_fileio *fio, t_trnheader *trn, rvec *box, rvec *x, rvec *v, - rvec *f) +gmx_bool gmx_trr_read_frame_data(t_fileio *fio, gmx_trr_header_t *header, + rvec *box, rvec *x, rvec *v, rvec *f) { - return do_htrn(fio, trn, box, x, v, f); + return do_trr_frame_data(fio, header, box, x, v, f); } -t_fileio *open_trn(const char *fn, const char *mode) +t_fileio *gmx_trr_open(const char *fn, const char *mode) { return gmx_fio_open(fn, mode); } -void close_trn(t_fileio *fio) +void gmx_trr_close(t_fileio *fio) { gmx_fio_close(fio); } diff --git a/src/gromacs/fileio/trrio.h b/src/gromacs/fileio/trrio.h index cb45bb6c19..3f280576c0 100644 --- a/src/gromacs/fileio/trrio.h +++ b/src/gromacs/fileio/trrio.h @@ -51,7 +51,7 @@ * * The routines in the corresponding c-file trrio.cpp * are based on the lower level routines in gmxfio.cpp - * The file handle returned from open_trn + * The file handle returned from gmx_trr_open() * can also be used with the routines in gmxfio.h * **************************************************************/ @@ -62,71 +62,72 @@ extern "C" { struct t_fileio; -typedef struct /* This struct describes the order and the */ - /* sizes of the structs in a trjfile, sizes are given in bytes. */ +/* This struct describes the order and the */ +/* sizes of the structs in a trr file, sizes are given in bytes. */ +typedef struct gmx_trr_header_t { - gmx_bool bDouble; /* Double precision? */ - int ir_size; /* Backward compatibility */ - int e_size; /* Backward compatibility */ - int box_size; /* Non zero if a box is present */ - int vir_size; /* Backward compatibility */ - int pres_size; /* Backward compatibility */ - int top_size; /* Backward compatibility */ - int sym_size; /* Backward compatibility */ - int x_size; /* Non zero if coordinates are present */ - int v_size; /* Non zero if velocities are present */ - int f_size; /* Non zero if forces are present */ - - int natoms; /* The total number of atoms */ - int step; /* Current step number */ - int nre; /* Backward compatibility */ - real t; /* Current time */ - real lambda; /* Current value of lambda */ - int fep_state; /* Current value of alchemical state */ -} t_trnheader; - -struct t_fileio *open_trn(const char *fn, const char *mode); -/* Open a trr / trr file */ - -void close_trn(struct t_fileio *fio); + gmx_bool bDouble; /* Double precision? */ + int ir_size; /* Backward compatibility */ + int e_size; /* Backward compatibility */ + int box_size; /* Non zero if a box is present */ + int vir_size; /* Backward compatibility */ + int pres_size; /* Backward compatibility */ + int top_size; /* Backward compatibility */ + int sym_size; /* Backward compatibility */ + int x_size; /* Non zero if coordinates are present */ + int v_size; /* Non zero if velocities are present */ + int f_size; /* Non zero if forces are present */ + + int natoms; /* The total number of atoms */ + int step; /* Current step number */ + int nre; /* Backward compatibility */ + real t; /* Current time */ + real lambda; /* Current value of lambda */ + int fep_state; /* Current value of alchemical state */ +} gmx_trr_header_t; + +struct t_fileio *gmx_trr_open(const char *fn, const char *mode); +/* Open a trr file */ + +void gmx_trr_close(struct t_fileio *fio); /* Close it */ -gmx_bool fread_trnheader(struct t_fileio *fio, t_trnheader *trn, gmx_bool *bOK); -/* Read the header of a trn file. Return FALSE if there is no frame. +gmx_bool gmx_trr_read_frame_header(struct t_fileio *fio, gmx_trr_header_t *header, gmx_bool *bOK); +/* Read the header of a trr file. Return FALSE if there is no frame. * bOK will be FALSE when the header is incomplete. */ -void read_trnheader(const char *fn, t_trnheader *header); -/* Read the header of a trn file from fn, and close the file afterwards. - */ - -void fwrite_trn(struct t_fileio *fio, int step, real t, real lambda, - rvec *box, int natoms, rvec *x, rvec *v, rvec *f); -/* Write a trn frame to file fp, box, x, v, f may be NULL */ - -gmx_bool fread_htrn(struct t_fileio *fio, t_trnheader *sh, - rvec *box, rvec *x, rvec *v, rvec *f); +gmx_bool gmx_trr_read_frame_data(struct t_fileio *fio, gmx_trr_header_t *sh, + rvec *box, rvec *x, rvec *v, rvec *f); /* Extern read a frame except the header (that should be pre-read, - * using routine read_trnheader, see above) from a trn file. + * using routine gmx_trr_read_frame_header(), see above) from a trr file. * Return FALSE on error */ -gmx_bool fread_trn(struct t_fileio *fio, int *step, real *t, real *lambda, - rvec *box, int *natoms, rvec *x, rvec *v, rvec *f); -/* Read a trn frame, including the header from fp. box, x, v, f may +gmx_bool gmx_trr_read_frame(struct t_fileio *fio, int *step, real *t, real *lambda, + rvec *box, int *natoms, rvec *x, rvec *v, rvec *f); +/* Read a trr frame, including the header from fp. box, x, v, f may * be NULL, in which case the data will be skipped over. * return FALSE on error */ -void write_trn(const char *fn, int step, real t, real lambda, - rvec *box, int natoms, rvec *x, rvec *v, rvec *f); -/* Write a single trn frame to file fn, which is closed afterwards */ +void gmx_trr_write_frame(struct t_fileio *fio, int step, real t, real lambda, + rvec *box, int natoms, rvec *x, rvec *v, rvec *f); +/* Write a trr frame to file fp, box, x, v, f may be NULL */ -void read_trn(const char *fn, int *step, real *t, real *lambda, - rvec *box, int *natoms, rvec *x, rvec *v, rvec *f); -/* Read a single trn frame from file fn, which is closed afterwards +void gmx_trr_read_single_header(const char *fn, gmx_trr_header_t *header); +/* Read the header of a trr file from fn, and close the file afterwards. */ +void gmx_trr_read_single_frame(const char *fn, int *step, real *t, real *lambda, + rvec *box, int *natoms, rvec *x, rvec *v, rvec *f); +/* Read a single trr frame from file fn, which is closed afterwards + */ + +void gmx_trr_write_single_frame(const char *fn, int step, real t, real lambda, + rvec *box, int natoms, rvec *x, rvec *v, rvec *f); +/* Write a single trr frame to file fn, which is closed afterwards */ + #ifdef __cplusplus } #endif diff --git a/src/gromacs/fileio/trxio.cpp b/src/gromacs/fileio/trxio.cpp index 50bd6d5e32..ab386090eb 100644 --- a/src/gromacs/fileio/trxio.cpp +++ b/src/gromacs/fileio/trxio.cpp @@ -397,8 +397,8 @@ int write_trxframe_indexed(t_trxstatus *status, t_trxframe *fr, int nind, write_xtc(status->fio, nind, fr->step, fr->time, fr->box, xout, prec); break; case efTRR: - fwrite_trn(status->fio, nframes_read(status), - fr->time, fr->step, fr->box, nind, xout, vout, fout); + gmx_trr_write_frame(status->fio, nframes_read(status), + fr->time, fr->step, fr->box, nind, xout, vout, fout); break; case efGRO: case efPDB: @@ -549,8 +549,8 @@ int write_trxframe(t_trxstatus *status, t_trxframe *fr, gmx_conect gc) write_xtc(status->fio, fr->natoms, fr->step, fr->time, fr->box, fr->x, prec); break; case efTRR: - fwrite_trn(status->fio, fr->step, fr->time, fr->lambda, fr->box, fr->natoms, - fr->bX ? fr->x : NULL, fr->bV ? fr->v : NULL, fr->bF ? fr->f : NULL); + gmx_trr_write_frame(status->fio, fr->step, fr->time, fr->lambda, fr->box, fr->natoms, + fr->bX ? fr->x : NULL, fr->bV ? fr->v : NULL, fr->bF ? fr->f : NULL); break; case efGRO: case efPDB: @@ -636,12 +636,12 @@ t_trxstatus *open_trx(const char *outfile, const char *filemode) static gmx_bool gmx_next_frame(t_trxstatus *status, t_trxframe *fr) { - t_trnheader sh; - gmx_bool bOK, bRet; + gmx_trr_header_t sh; + gmx_bool bOK, bRet; bRet = FALSE; - if (fread_trnheader(status->fio, &sh, &bOK)) + if (gmx_trr_read_frame_header(status->fio, &sh, &bOK)) { fr->bDouble = sh.bDouble; fr->natoms = sh.natoms; @@ -677,7 +677,7 @@ static gmx_bool gmx_next_frame(t_trxstatus *status, t_trxframe *fr) } fr->bF = sh.f_size > 0; } - if (fread_htrn(status->fio, &sh, fr->box, fr->x, fr->v, fr->f)) + if (gmx_trr_read_frame_data(status->fio, &sh, fr->box, fr->x, fr->v, fr->f)) { bRet = TRUE; } diff --git a/src/gromacs/gmxana/eigio.c b/src/gromacs/gmxana/eigio.c index 1d421e51f5..97daf30f4b 100644 --- a/src/gromacs/gmxana/eigio.c +++ b/src/gromacs/gmxana/eigio.c @@ -50,7 +50,7 @@ void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit, int *nvec, int **eignr, rvec ***eigvec, real **eigval) { - t_trnheader head; + gmx_trr_header_t head; int i, snew_size; struct t_fileio *status; rvec *x; @@ -60,11 +60,11 @@ void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit, *bDMR = FALSE; /* read (reference (t=-1) and) average (t=0) structure */ - status = open_trn(file, "r"); - fread_trnheader(status, &head, &bOK); + status = gmx_trr_open(file, "r"); + gmx_trr_read_frame_header(status, &head, &bOK); *natoms = head.natoms; snew(*xav, *natoms); - fread_htrn(status, &head, box, *xav, NULL, NULL); + gmx_trr_read_frame_data(status, &head, box, *xav, NULL, NULL); if ((head.t >= -1.1) && (head.t <= -0.9)) { @@ -85,8 +85,8 @@ void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit, sfree(*xref); *xref = NULL; } - fread_trnheader(status, &head, &bOK); - fread_htrn(status, &head, box, *xav, NULL, NULL); + gmx_trr_read_frame_header(status, &head, &bOK); + gmx_trr_read_frame_data(status, &head, box, *xav, NULL, NULL); } else { @@ -115,9 +115,9 @@ void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit, snew(*eigvec, snew_size); *nvec = 0; - while (fread_trnheader(status, &head, &bOK)) + while (gmx_trr_read_frame_header(status, &head, &bOK)) { - fread_htrn(status, &head, box, x, NULL, NULL); + gmx_trr_read_frame_data(status, &head, box, x, NULL, NULL); if (*nvec >= snew_size) { snew_size += 10; @@ -136,16 +136,17 @@ void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit, (*nvec)++; } sfree(x); + gmx_trr_close(status); fprintf(stderr, "Read %d eigenvectors (for %d atoms)\n\n", *nvec, *natoms); } -void write_eigenvectors(const char *trnname, int natoms, real mat[], +void write_eigenvectors(const char *trrname, int natoms, real mat[], gmx_bool bReverse, int begin, int end, int WriteXref, rvec *xref, gmx_bool bDMR, rvec xav[], gmx_bool bDMA, real eigval[]) { - struct t_fileio *trnout; + struct t_fileio *trrout; int ndim, i, j, d, vec; matrix zerobox; rvec *x; @@ -157,22 +158,22 @@ void write_eigenvectors(const char *trnname, int natoms, real mat[], fprintf (stderr, "\nWriting %saverage structure & eigenvectors %d--%d to %s\n", (WriteXref == eWXR_YES) ? "reference, " : "", - begin, end, trnname); + begin, end, trrname); - trnout = open_trn(trnname, "w"); + trrout = gmx_trr_open(trrname, "w"); if (WriteXref == eWXR_YES) { /* misuse lambda: 0/1 mass weighted fit no/yes */ - fwrite_trn(trnout, -1, -1, bDMR ? 1.0 : 0.0, zerobox, natoms, xref, NULL, NULL); + gmx_trr_write_frame(trrout, -1, -1, bDMR ? 1.0 : 0.0, zerobox, natoms, xref, NULL, NULL); } else if (WriteXref == eWXR_NOFIT) { /* misuse lambda: -1 no fit */ - fwrite_trn(trnout, -1, -1, -1.0, zerobox, natoms, x, NULL, NULL); + gmx_trr_write_frame(trrout, -1, -1, -1.0, zerobox, natoms, x, NULL, NULL); } /* misuse lambda: 0/1 mass weighted analysis no/yes */ - fwrite_trn(trnout, 0, 0, bDMA ? 1.0 : 0.0, zerobox, natoms, xav, NULL, NULL); + gmx_trr_write_frame(trrout, 0, 0, bDMA ? 1.0 : 0.0, zerobox, natoms, xav, NULL, NULL); for (i = 0; i <= (end-begin); i++) { @@ -195,9 +196,9 @@ void write_eigenvectors(const char *trnname, int natoms, real mat[], } /* Store the eigenvalue in the time field */ - fwrite_trn(trnout, begin+i, eigval[vec], 0, zerobox, natoms, x, NULL, NULL); + gmx_trr_write_frame(trrout, begin+i, eigval[vec], 0, zerobox, natoms, x, NULL, NULL); } - close_trn(trnout); + gmx_trr_close(trrout); sfree(x); } diff --git a/src/gromacs/gmxana/eigio.h b/src/gromacs/gmxana/eigio.h index b254923bb6..7b2638e16d 100644 --- a/src/gromacs/gmxana/eigio.h +++ b/src/gromacs/gmxana/eigio.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -56,11 +56,11 @@ extern void read_eigenvectors(const char *file, int *natoms, gmx_bool *bFit, /* xav is the average/minimum structure is written (t=0). */ /* bDMA indicates mass weighted analysis/eigenvectors. */ -extern void write_eigenvectors(const char *trnname, int natoms, real mat[], +extern void write_eigenvectors(const char *trrname, int natoms, real mat[], gmx_bool bReverse, int begin, int end, int WriteXref, rvec *xref, gmx_bool bDMR, rvec xav[], gmx_bool bDMA, real *eigval); -/* Write eigenvectors in mat to a TRN file. */ +/* Write eigenvectors in mat to a TRR file. */ /* The reference structure is written (t=-1) when WriteXref=eWXR_YES. */ /* When WriteXref==eWXR_NOFIT a zero frame is written (t=-1), */ /* with lambda=-1. */ diff --git a/src/gromacs/gmxana/gmx_angle.c b/src/gromacs/gmxana/gmx_angle.c index 67208e0f89..a12593a7b1 100644 --- a/src/gromacs/gmxana/gmx_angle.c +++ b/src/gromacs/gmxana/gmx_angle.c @@ -56,11 +56,11 @@ #include "gromacs/utility/futil.h" #include "gromacs/utility/smalloc.h" -static void dump_dih_trn(int nframes, int nangles, real **dih, const char *fn, +static void dump_dih_trr(int nframes, int nangles, real **dih, const char *fn, real *time) { int i, j, k, l, m, na; - struct t_fileio *trn; + struct t_fileio *fio; rvec *x; matrix box = {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}; @@ -76,7 +76,7 @@ static void dump_dih_trn(int nframes, int nangles, real **dih, const char *fn, printf("There are %d dihedrals. Will fill %d atom positions with cos/sin\n", nangles, na); snew(x, na); - trn = open_trn(fn, "w"); + fio = gmx_trr_open(fn, "w"); for (i = 0; (i < nframes); i++) { k = l = 0; @@ -93,9 +93,9 @@ static void dump_dih_trn(int nframes, int nangles, real **dih, const char *fn, } } } - fwrite_trn(trn, i, time[i], 0, box, na, x, NULL, NULL); + gmx_trr_write_frame(fio, i, time[i], 0, box, na, x, NULL, NULL); } - close_trn(trn); + gmx_trr_close(fio); sfree(x); } @@ -209,7 +209,7 @@ int gmx_g_angle(int argc, char *argv[]) { if (mult != 4) { - gmx_fatal(FARGS, "Can not combine angles with trn dump"); + gmx_fatal(FARGS, "Can not combine angles with trr dump"); } else { @@ -309,7 +309,7 @@ int gmx_g_angle(int argc, char *argv[]) } if (opt2bSet("-or", NFILE, fnm)) { - dump_dih_trn(nframes, nangles, dih, opt2fn("-or", NFILE, fnm), time); + dump_dih_trr(nframes, nangles, dih, opt2fn("-or", NFILE, fnm), time); } if (bFrac) diff --git a/src/gromacs/gmxana/gmx_trjconv.c b/src/gromacs/gmxana/gmx_trjconv.c index f0e64ed790..213eae951b 100644 --- a/src/gromacs/gmxana/gmx_trjconv.c +++ b/src/gromacs/gmxana/gmx_trjconv.c @@ -463,7 +463,7 @@ static void mk_filenm(char *base, const char *ext, int ndigit, int file_nr, strcat(out_file, ext); } -void check_trn(const char *fn) +void check_trr(const char *fn) { if (fn2ftp(fn) != efTRR) { @@ -476,7 +476,7 @@ void do_trunc(const char *fn, real t0) t_fileio *in; FILE *fp; gmx_bool bStop, bOK; - t_trnheader sh; + gmx_trr_header_t sh; gmx_off_t fpos; char yesno[256]; int j; @@ -488,23 +488,23 @@ void do_trunc(const char *fn, real t0) } /* Check whether this is a .trr file */ - check_trn(fn); + check_trr(fn); - in = open_trn(fn, "r"); + in = gmx_trr_open(fn, "r"); fp = gmx_fio_getfp(in); if (fp == NULL) { fprintf(stderr, "Sorry, can not trunc %s, truncation of this filetype is not supported\n", fn); - close_trn(in); + gmx_trr_close(in); } else { j = 0; fpos = gmx_fio_ftell(in); bStop = FALSE; - while (!bStop && fread_trnheader(in, &sh, &bOK)) + while (!bStop && gmx_trr_read_frame_header(in, &sh, &bOK)) { - fread_htrn(in, &sh, NULL, NULL, NULL, NULL); + gmx_trr_read_frame_data(in, &sh, NULL, NULL, NULL, NULL); fpos = gmx_ftell(fp); t = sh.t; if (t >= t0) @@ -525,7 +525,7 @@ void do_trunc(const char *fn, real t0) if (strcmp(yesno, "YES") == 0) { fprintf(stderr, "Once again, I'm gonna DO this...\n"); - close_trn(in); + gmx_trr_close(in); if (0 != gmx_truncate(fn, fpos)) { gmx_fatal(FARGS, "Error truncating file %s", fn); @@ -539,7 +539,7 @@ void do_trunc(const char *fn, real t0) else { fprintf(stderr, "Already at end of file (t=%g)...\n", t); - close_trn(in); + gmx_trr_close(in); } } } diff --git a/src/gromacs/gmxpreprocess/readrot.cpp b/src/gromacs/gmxpreprocess/readrot.cpp index 4615d2faf3..f663e95303 100644 --- a/src/gromacs/gmxpreprocess/readrot.cpp +++ b/src/gromacs/gmxpreprocess/readrot.cpp @@ -239,12 +239,12 @@ extern void set_reference_positions( t_rot *rot, rvec *x, matrix box, const char *fn, gmx_bool bSet, warninp_t wi) { - int g, i, ii; - t_rotgrp *rotg; - t_trnheader header; /* Header information of reference file */ - char base[STRLEN], extension[STRLEN], reffile[STRLEN]; - char *extpos; - rvec f_box[3]; /* Box from reference file */ + int g, i, ii; + t_rotgrp *rotg; + gmx_trr_header_t header; /* Header information of reference file */ + char base[STRLEN], extension[STRLEN], reffile[STRLEN]; + char *extpos; + rvec f_box[3]; /* Box from reference file */ /* Base name and extension of the reference file: */ @@ -276,13 +276,13 @@ extern void set_reference_positions( if (gmx_fexist(reffile)) { fprintf(stderr, " Reading them from %s.\n", reffile); - read_trnheader(reffile, &header); + gmx_trr_read_single_header(reffile, &header); if (rotg->nat != header.natoms) { gmx_fatal(FARGS, "Number of atoms in file %s (%d) does not match the number of atoms in rotation group (%d)!\n", reffile, header.natoms, rotg->nat); } - read_trn(reffile, &header.step, &header.t, &header.lambda, f_box, &header.natoms, rotg->x_ref, NULL, NULL); + gmx_trr_read_single_frame(reffile, &header.step, &header.t, &header.lambda, f_box, &header.natoms, rotg->x_ref, NULL, NULL); /* Check whether the box is unchanged and output a warning if not: */ check_box_unchanged(f_box, box, reffile, wi); @@ -295,7 +295,7 @@ extern void set_reference_positions( ii = rotg->ind[i]; copy_rvec(x[ii], rotg->x_ref[i]); } - write_trn(reffile, g, 0.0, 0.0, box, rotg->nat, rotg->x_ref, NULL, NULL); + gmx_trr_write_single_frame(reffile, g, 0.0, 0.0, box, rotg->nat, rotg->x_ref, NULL, NULL); } } } diff --git a/src/gromacs/tools/convert_tpr.cpp b/src/gromacs/tools/convert_tpr.cpp index a222ef578f..01c772c9c2 100644 --- a/src/gromacs/tools/convert_tpr.cpp +++ b/src/gromacs/tools/convert_tpr.cpp @@ -352,7 +352,7 @@ int gmx_convert_tpr(int argc, char *argv[]) const char *top_fn, *frame_fn; struct t_fileio *fp; ener_file_t fp_ener = NULL; - t_trnheader head; + gmx_trr_header_t head; int i; gmx_int64_t nsteps_req, run_step, frame; double run_t, state_t; @@ -489,7 +489,7 @@ int gmx_convert_tpr(int argc, char *argv[]) "\nREADING COORDS, VELS AND BOX FROM TRAJECTORY %s...\n\n", frame_fn); - fp = open_trn(frame_fn, "r"); + fp = gmx_trr_open(frame_fn, "r"); if (bScanEner) { fp_ener = open_enx(ftp2fn(efEDR, NFILE, fnm), "r"); @@ -505,7 +505,7 @@ int gmx_convert_tpr(int argc, char *argv[]) frame = 0; while (bFrame) { - bFrame = fread_trnheader(fp, &head, &bOK); + bFrame = gmx_trr_read_frame_header(fp, &head, &bOK); if (bOK && frame == 0) { if (mtop.natoms != head.natoms) @@ -520,7 +520,7 @@ int gmx_convert_tpr(int argc, char *argv[]) bFrame = bFrame && bOK; if (bFrame) { - bOK = fread_htrn(fp, &head, newbox, newx, newv, NULL); + bOK = gmx_trr_read_frame_data(fp, &head, newbox, newx, newv, NULL); } bFrame = bFrame && bOK; bUse = FALSE; @@ -572,7 +572,7 @@ int gmx_convert_tpr(int argc, char *argv[]) free_enxframe(fr_ener); free_enxnms(nre, enm); } - close_trn(fp); + gmx_trr_close(fp); fprintf(stderr, "\n"); if (!bOK) diff --git a/src/gromacs/tools/dump.cpp b/src/gromacs/tools/dump.cpp index 65a028ced8..305abf88f6 100644 --- a/src/gromacs/tools/dump.cpp +++ b/src/gromacs/tools/dump.cpp @@ -203,57 +203,57 @@ static void list_top(const char *fn) } } -static void list_trn(const char *fn) +static void list_trr(const char *fn) { - t_fileio *fpread; - int nframe, indent; - char buf[256]; - rvec *x, *v, *f; - matrix box; - t_trnheader trn; - gmx_bool bOK; + t_fileio *fpread; + int nframe, indent; + char buf[256]; + rvec *x, *v, *f; + matrix box; + gmx_trr_header_t trrheader; + gmx_bool bOK; - fpread = open_trn(fn, "r"); + fpread = gmx_trr_open(fn, "r"); nframe = 0; - while (fread_trnheader(fpread, &trn, &bOK)) + while (gmx_trr_read_frame_header(fpread, &trrheader, &bOK)) { - snew(x, trn.natoms); - snew(v, trn.natoms); - snew(f, trn.natoms); - if (fread_htrn(fpread, &trn, - trn.box_size ? box : NULL, - trn.x_size ? x : NULL, - trn.v_size ? v : NULL, - trn.f_size ? f : NULL)) + snew(x, trrheader.natoms); + snew(v, trrheader.natoms); + snew(f, trrheader.natoms); + if (gmx_trr_read_frame_data(fpread, &trrheader, + trrheader.box_size ? box : NULL, + trrheader.x_size ? x : NULL, + trrheader.v_size ? v : NULL, + trrheader.f_size ? f : NULL)) { sprintf(buf, "%s frame %d", fn, nframe); indent = 0; indent = pr_title(stdout, indent, buf); pr_indent(stdout, indent); fprintf(stdout, "natoms=%10d step=%10d time=%12.7e lambda=%10g\n", - trn.natoms, trn.step, trn.t, trn.lambda); - if (trn.box_size) + trrheader.natoms, trrheader.step, trrheader.t, trrheader.lambda); + if (trrheader.box_size) { pr_rvecs(stdout, indent, "box", box, DIM); } - if (trn.x_size) + if (trrheader.x_size) { - pr_rvecs(stdout, indent, "x", x, trn.natoms); + pr_rvecs(stdout, indent, "x", x, trrheader.natoms); } - if (trn.v_size) + if (trrheader.v_size) { - pr_rvecs(stdout, indent, "v", v, trn.natoms); + pr_rvecs(stdout, indent, "v", v, trrheader.natoms); } - if (trn.f_size) + if (trrheader.f_size) { - pr_rvecs(stdout, indent, "f", f, trn.natoms); + pr_rvecs(stdout, indent, "f", f, trrheader.natoms); } } else { fprintf(stderr, "\nWARNING: Incomplete frame: nr %d, t=%g\n", - nframe, trn.t); + nframe, trrheader.t); } sfree(x); @@ -264,9 +264,9 @@ static void list_trn(const char *fn) if (!bOK) { fprintf(stderr, "\nWARNING: Incomplete frame header: nr %d, t=%g\n", - nframe, trn.t); + nframe, trrheader.t); } - close_trn(fpread); + gmx_trr_close(fpread); } void list_xtc(const char *fn) @@ -405,7 +405,7 @@ void list_trx(const char *fn) list_xtc(fn); break; case efTRR: - list_trn(fn); + list_trr(fn); break; case efTNG: list_tng(fn); -- 2.22.0