RE: Reading and writing Binary Restart or Output files with Fortran

From: Joshua D. Moore (
Date: Fri Apr 18 2008 - 19:25:55 CDT

Dear Leandro and List,

I saw your post on the list from 2006
I was wondering if you found a solution to this? I am also having the same
problem, and it seems to stem from the fact that the binary file was written
as a "stream" with fwrite in C. Fortran 90 doesn't have an option to read a
"stream" only "sequential" or "direct" access. Fortran 95 does I think but
I haven't gotten it to work yet with a proper compiler.

I really was hoping I could write this with Fortran 77 or 90 but it seems so
far I cannot.

I thought it was interesting you were able to read until atom 2241. I was
only able to read until atom 617 I think. Maybe this is because my machine
is only 32 bit or something.

Here is my code if interested (doesn't work unless you decrease it to 617
from totatoms*3). Also this won't work when using a do loop or a call
statement to a subroutine (I tried). I saw another post about the
difference in access between the dcd format and the binary restart and
output files. It seems the output and restart files are access="stream" but
the dcd files are access="sequential" (in fortran)

program read_binvel
implicit none
character*80 binvelfilename
integer j
integer mxatoms
integer*4 totatoms
real(8) V(mxatoms*3)
read(*,*) binvelfilename

read(*,*) totatoms



read(8) (V(j),j=1,totatoms*3)
write(*,*) (V(j),j=1,totatoms*3)

end program

I also thought that the total atoms (number) was written at the beginning in
Output.C when writing a binary file (seems to be), but for some reason I
don't see this number at the beginning. I could use the ASCII format but
this only gives 3 decimal places (I actually want to use this for

I actually want to write a namdbin file from my own code, but if I can't
read one then there is no hope in writing one :(

Thanks in advance for any advice (and also the list).


Joshua Moore

This archive was generated by hypermail 2.1.6 : Wed Feb 29 2012 - 15:49:24 CST