[gmx-users] Length of .xtc file in frames for C-Code

Mirco Wahab mirco.wahab at chemie.tu-freiberg.de
Fri Apr 4 00:36:15 CEST 2014


On 03.04.2014 16:10, GtrAngus wrote:
> I have a question to all the people who are familiar with C-code. How can I
> read in the total number of frames in my *.xtc file? Especially when I do
> the analysis somewhere in the middle?
> E.g: I have a file with 100.000 frames. When I start the programm with
> ./program -f traj.xtc
> then I want somewhere in my code something like:
> int totalnumerbofframesyouareanalyzing = 100.000
>
> When I do the same with:
> ./program -f traj.xtc -b 20.000
> then I want in my code:
> int totalnumerbofframesyouareanalyzing = 80.000

It's not entirely clear what you want.

a) Do you *already know* the number of frames in traj.xtc and
don't know how to create a C program for manually reading of the xtc?

b) do you *want to know* the number of frames in order to
use that number in your program which, aside from the number,
already works?

If b), the number of frames can be extracted through trjconv
simply by reading "over the end". trjconv will issue a warning
which contains this number.
Something like (one command, one line,
read trjconv stderr through perl one-liner in a shell):

$> trjconv -dump 9e9 -o x 2>&1 | perl -lne 'print "int 
n_last=$1;\ndouble t_last=$2;" if /Last\D+(\d+)\D+(\d+)/'

Applied on a simulation directory here, it prints:

   int n_last=1000;
   double t_last=100000;

which could be "patched" into C source code ;-)


M.



More information about the gromacs.org_gmx-users mailing list