PDA

View Full Version : Reading and writing sequential files


Zar
11-11-2009, 07:48 AM
Could somebody help me to insert some lines to this fortran code so that it can read and write binary data to ascii in a sequence of files (e.g. c_002.bip_c1.bin, c_005.bip_c1.bin, c_006.bip_c1.bin) rather than manually modifying the reading and writing file every time the code runs?Below is the code:

implicit none
integer lat, lon, irec,x,y
real*4 bmap(180,90)
parameter(irec=180*90*4)
open(21,file=
& 'c_015.bip_c1.bin',
& access='direct',
& form='unformatted',
& recl=irec,status='old',err=999)
read(21,rec=1,err=999)
& ((bmap(lon,lat),lon=1,180),lat=1,90)
close(21)
open(31,file= 'c_015.bip_c1.txt',form='formatted')
do 123 y=1,90
write(31,30) (bmap(x,y),x=1,180)
30 Format(180F12.6)
123 continue
999 continue
stop
End

mecej4
12-12-2009, 10:04 PM
Use internal writes to create the sequence of file names. For example,

character*12 fname
data fname/'c_000.bip_c1'/
do i=2,7
write(fname(5:),'(I1)')i
!
open(21,file=fname // '.bin',access=....
read(21,rec=....
close(21)
!
open(31,file=fname // '.txt',form=....
write(31,30)...
close(31)