From: V.Ovchinnikov (ovchinnv_at_MIT.EDU)
Date: Sat Apr 19 2008 - 10:40:46 CDT
Hi, Josh,
I don't know whether you're aware of the `record' structure of fortran
unformatted files. Essentially, fortran expects that every line of data
acquired in a read statement be bracketed by two 4-byte (8-byte on 64bit
ststems) integers that tell you the number of bytes the line of data, or
the record has (i.e. the record length). For example, if you were to
write
integer*4 i
open(1,name='trash', form='unformatted')
read(1) i
the corresponding file should contain twelve bytes corresponding to the
integers:
1 4 1
There are some compilers that extend the fortran standard and implement
a `binary' file form; for example, I know that absoft fortran used to
have this.
Another solution would be to write a read function in c and link your
fortran code against it.
Hope this was useful,
Victor
On Fri, 2008-04-18 at 20:25 -0400, Joshua D. Moore wrote:
> Dear Leandro and List,
>
> I saw your post on the list from 2006
>
> http://www.ks.uiuc.edu/Research/namd/mailing_list/namd-l/3287.html
>
> 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
> parameter(mxatoms=5000)
> integer*4 totatoms
> real(8) V(mxatoms*3)
> write(*,*) 'NAME OF BINARY VELOCITY FILE'
> read(*,*) binvelfilename
>
> write(*,*) 'ENTER TOTAL NUMBER OF ATOMS'
>
> read(*,*) totatoms
>
> open(unit=8,file=binvelfilename,form="unformatted",status="old",access="sequential",recl=4,pad="yes")
>
> !open(unit=8,file=binvelfilename,form="unformatted",access="stream")
>
> read(8) (V(j),j=1,totatoms*3)
> write(*,*) (V(j),j=1,totatoms*3)
>
> close(8)
> 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 velocities).
>
> 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).
>
> Best.
>
> Joshua Moore
>
>
This archive was generated by hypermail 2.1.6 : Tue Oct 07 2008 - 19:18:27 CDT