Hi Tsjerk,<div>Thanks, but I don&#39;t really want to use a python script, I am doing this from some c/c++ code. I think I figured out a way to do it, but I haven&#39;t tested it yet:</div><div><br></div><div>i)    open the file</div>
<div>ii)   do a read_first_xtc</div><div>iii)  then get the file pointer positon from ftellg, which should be the length of the frame in bytes;</div><div>iv)  place the file pointer at the end of the file with an fseek, then get the length with an ftellg</div>
<div>v)   Divide the total length by the length of a frame and obtain the number of written frames.</div><div><br></div><div>I am only wondering what to do when the length in bytes of the file is too large for a long int!<br>
<br><div class="gmail_quote">On 4 June 2012 16:11, Tsjerk Wassenaar <span dir="ltr">&lt;<a href="mailto:tsjerkw@gmail.com" target="_blank">tsjerkw@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hey Paolo,<br>
<br>
I think I posted a script for extracting a last frame before, but if I<br>
can&#39;t even find it myself... Here it is:<br>
<br>
#!/usr/bin/env python<br>
<br>
from struct import unpack<br>
import sys<br>
<br>
def i(x): return sum([ord(x[j])&lt;&lt;(24-j*8) for j in range(4)])<br>
<br>
f = open(sys.argv[1])<br>
tag = f.read(8)                   # Tag: magic number and number of atoms<br>
n = 92 + i(f.read(84)[-4:])       # Size of frame in bytes<br>
<br>
f.seek(-5*n/4, 2)                 # This should contain a complete frame<br>
frame = f.read()                  # Read the remaining part in<br>
frame = frame[frame.index(tag):]  # Find the tag<br>
<br>
# Open the output file<br>
if len(sys.argv) &gt; 2:<br>
    o = sys.argv[2]<br>
else:<br>
    o = sys.argv[1][:-4]+&quot;-last.xtc&quot;<br>
open(o,&quot;w&quot;).write(frame)<br>
<br>
###<br>
<br>
Hope it helps. Cheers,<br>
<br>
Tsjerk<br>
<div><div class="h5">On Mon, Jun 4, 2012 at 12:59 PM, Paolo Franz &lt;<a href="mailto:paolo.franz@gmail.com">paolo.franz@gmail.com</a>&gt; wrote:<br>
&gt; Hello everybody!<br>
&gt;<br>
&gt; I am wondering how I can figure out the number of frames contained in an<br>
&gt; .xtc file. Indeed, I need to read a particular frame of a trajectory and I<br>
&gt; thought that the function<br>
&gt; xtc_seek_frame(FILE * , int *, int *)<br>
&gt; would return 0 if the frame was there and 1 when it was not. Instead, if I<br>
&gt; call it with a frame outside the boundaries it seems to go into an infinite<br>
&gt; loop. What I am doing wrong? Is there a way to read the last frame of an<br>
&gt; .xtc file?<br>
&gt;<br>
&gt; Sincerely<br>
&gt; Paolo<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div>&gt; --<br>
&gt; gmx-developers mailing list<br>
&gt; <a href="mailto:gmx-developers@gromacs.org">gmx-developers@gromacs.org</a><br>
&gt; <a href="http://lists.gromacs.org/mailman/listinfo/gmx-developers" target="_blank">http://lists.gromacs.org/mailman/listinfo/gmx-developers</a><br>
&gt; Please don&#39;t post (un)subscribe requests to the list. Use the<br>
&gt; www interface or send it to <a href="mailto:gmx-developers-request@gromacs.org">gmx-developers-request@gromacs.org</a>.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Tsjerk A. Wassenaar, Ph.D.<br>
<br>
post-doctoral researcher<br>
Molecular Dynamics Group<br>
* Groningen Institute for Biomolecular Research and Biotechnology<br>
* Zernike Institute for Advanced Materials<br>
University of Groningen<br>
The Netherlands<br>
--<br>
gmx-developers mailing list<br>
<a href="mailto:gmx-developers@gromacs.org">gmx-developers@gromacs.org</a><br>
<a href="http://lists.gromacs.org/mailman/listinfo/gmx-developers" target="_blank">http://lists.gromacs.org/mailman/listinfo/gmx-developers</a><br>
Please don&#39;t post (un)subscribe requests to the list. Use the<br>
www interface or send it to <a href="mailto:gmx-developers-request@gromacs.org">gmx-developers-request@gromacs.org</a>.<br>
</font></span></blockquote></div><br></div>