Note that there are some explanatory texts on larger screens.

plurals
  1. POWrite and read access=stream files in fortran
    primarykey
    data
    text
    <p>I have a shell script from which I pass a binary file to a fortran program such that </p> <pre><code>Mth=$1 loop=1 it=1 while test $it -le 12 do Mth=`expr $Mth + $loop` file="DataFile"$Mth".bin" ./fort_exe ${Yr} ${nt} ${it} # Increment loop it=`expr $it + 1` done </code></pre> <p>This script is used to pass 12 files within a do loop to the fortran program. In the fortran program, I read the binary file passed from the shell script and I am trying to write a 2nd file which would compile in a single file all the data that was read from the consecutive files e.g.</p> <pre><code> !Open binary file passed from shell script open(1,file='Datafile'//TRIM{Mth)//.bin',action='read',form='unformatted',access='direct', &amp; recl=4*x*y, status='old') ! Open write file for t 1. The status is different in t 1 and t &gt; 1 so I open it twice: I guess there is a more elegant way to do this... open(2,file='Newfile.bin',action='write',form='unformatted', &amp; access='stream', position='append', status='replace') irec = 0 do t = 1, nt ! Read input file irec = irec + 1 read(1,rec=irec) val(:,:) ! write output file irecW= irec + (imonth-1)*nt if ( t .eq. 1) write(2,pos=irecW) val(:,:) ! Close file after t = 1, update the status to old and reopen. if ( t .eq. 2) then close (2) open(2,file='Newfile.bin',action='write',form='unformatted', &amp; access='stream', position='append',status='old') endif if ( t .ge. 2) write(2,pos=irecW) val(:,:) enddo </code></pre> <p>I can read the binary data from the first file no problem but when I try and read from another program the binary data from the file that I wrote in the first program such that </p> <pre><code> open(1,file='Newfile.bin',action='read',form='unformatted', &amp; access='stream', status='old') irec=0 do t = 1, nt ! Read input file irec = irec + 1 read(1,pos=irec) val(:,:) write(*,*) val(:,:) enddo </code></pre> <p>val(:,:) is nothing but a list of zeros. This is the first time I use access=stream which I believe is the only way I can use position='append'. I have tried compiling with gfortran and ifort but I do not get any error messages. </p> <p>Does anyone have any idea why this is happening?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload