我有一个fortran程序,必须在其中打开二进制输出文件。通常一个指定。
RECL=num
但是对于我的特定情况,使用该选项打开的文件不起作用。有效的是
RECORDTYPE=stream
我通常不接受第二种选择的gfortran。使用RECL选项,程序可以运行,但是数据不可用。英特尔编译器可以。英特尔不再提供免费的编译器,我失去了曾经拥有的免费英特尔编译器。
如果有任何建议使用gfortran编写流,或者如果有人可以备份其编译器文件夹,请将其放在google驱动器上并给我链接(希望这不是滥用),我将不胜感激。 我在Ubuntu 18.04上工作。
我在下面粘贴我使用的示例程序以及要写入二进制文件的数据。
Program stndat
implicit none
integer :: iflag=0,itime=0
integer :: nlev,ihrold,nflag,icount
integer :: ihr !,iwx,delta,cld,vis
integer,dimension(1:3) :: today,now
Real :: lat,lon,iu,iv,itemp,idp,ipress
CHARACTER(len=3) :: stnid
character(len=8) :: date
character(len=10) :: time
character(len=5) :: zone
character(len=8) :: year,inst*10,hour*2
!
integer,dimension(1:8) :: values
! using keyword arguments
call date_and_time(date,time,zone,values)
!
open(1,file='tmp.txt')
write(1,'(1x,a8,2x,a10)') date,time
Program stndat
implicit none
integer :: iflag=0,itime=0
integer :: nlev,ihrold,nflag,icount
integer :: ihr !,iwx,delta,cld,vis
integer,dimension(1:3) :: today,now
Real :: lat,lon,iu,iv,itemp,idp,ipress
CHARACTER(len=3) :: stnid
character(len=8) :: date
character(len=10) :: time
character(len=5) :: zone
character(len=8) :: year,inst*10,hour*2
!
integer,dimension(1:8) :: values
! using keyword arguments
call date_and_time(date,time,zone,values)
!
open(1,file='tmp.txt')
write(1,'(1x,a8,2x,a10)') date,time
rewind(1)
read(1,'(1x,a8,2x,a10)') year,inst
close(1,status='delete')
iflag=0
itime=0
icount=1
hour = time(:2)
hour = '09'
! Open up I/O Files
Open(unit=11,file='../../Output/synop4grads.txt',status='old')
Open(unit=12,file='../../Output/Obs_out.bin',form='unformatted',recordtype='stream',status='unknown')
10 continue
! Read in the line of code
read(11,'(1x,a3,2x,f5.2,2x,f6.2,2x,i2,8(2x,f5.1))',END=40) stnid,lon,lat,ihr,iu,iv,itemp,idp,ipress
IF (iflag.EQ.0) THEN
iflag=1
ihrold=ihr
ENDIF
!
! Check to see if this is an old time group. If so, write a terminator
IF (ihrold.NE.ihr) THEN
nlev=0
write(12)stnid,lat,lon,ihr,nlev,nflag
ENDIF
! Now make ihrold equal to the current ihr
ihrold=ihr
!
! Now we can go ahead and write the report
! First, define some variables to be used in the header
itime=0.
nlev=1
nflag=1
write(12) stnid,lat,lon,ihr,nlev,nflag
!
! read in the following: itemp,idp,ipress,iu,iv,iwx,ic,icl
write(12) iu,iv,itemp,idp,ipress
! When its done writing one report, instruct the program
! to read-in the next line
go to 10
!
! When there are no more lines to read-in, the program
! goes to 40
40 continue
nlev=0
!
write(12)stnid,lat,lon,ihr,nlev,nflag
close(11)
close(12)
end
数据
403 29.08 -9.80 01 -0.5 -3.0 24.0 16.5 496.0
441 24.43 -11.75 01 -99.0 -99.0 18.5 16.8 533.0
461 28.85 -11.10 01 -1.4 -9.9 26.0 17.7 485.0
475 31.12 -10.21 01 -1.0 -9.9 24.4 14.0 509.0
476 31.25 -10.10 01 -0.7 -6.0 24.0 14.5 -99.0
477 31.43 -11.90 01 -1.7 -49.0 -9.9 0.0 500.0