mathseeker
Programmer
I have a fortran 77 code to convert USGS .grd file format to some different (.add) format. But whenever I run the code I am getting fortran runtime error. I am very new to fortran language. Can someone help me with solving this issue?
the error is
At line 94 of file sgf2add.f (unit = 11, file = 'CBA_master_usgs_unix.grd')
Fortran runtime error: End of file
Error termination. Backtrace:
#0 0x7f76b865816a in ???
#1 0x7f76b8658d55 in ???
#2 0x7f76b865951d in ???
#3 0x7f76b87cf7e3 in ???
#4 0x7f76b87d012f in ???
#5 0x7f76b87d01f5 in ???
#6 0x7f76b87d2a57 in ???
#7 0x564cb9982ea2 in rdhead1_
at /home/sreenidhi/MEM/Data_usgs/sgf2add.f:94
#8 0x564cb9983808 in MAIN__
at /home/sreenidhi/MEM/Data_usgs/sgf2add.f:37
#9 0x564cb9983eaf in main
at /home/sreenidhi/MEM/Data_usgs/sgf2add.f:84
I have highlighted the lines 94 (blue) 37(orange) and 84(green). I think this is very simple question but I am not able to resolve the problem. Can someone help me resolving this issue?
Code:
c program to convert USGS standard grid format to format suitable for use
c in elastic thickness estimation algorithms.
implicit none
integer i,id0,ilon0,ilat0,iproj,j,nargs,nc,ncol,nr,nrow,nz
character filin*50,filout*50,id*56,pgm*8
real*4 bl,cm,del,dx,dy,ewtd,mnln,mxln,mnlt,mxlt,nstd,rot,theta,xo,
& xrotcen,yo,yrotcen,zrow(5000)
real*8 drow(5000)
integer IOstatus
integer iargc
nargs=iargc()
if(nargs.ne.2)then
write(6,*)"usage: prog infile outfile"
call exit(-1)
else
call getarg(1,filin)
call getarg(2,filout)
endif
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cc Substitute form='formatted' if your original data format is ascii c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
open(11,file=filin,form='unformatted')
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
rewind(11)
open(12,file=filout,form='unformatted')
rewind(12)
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cc Substitute a header read statement for your format here.... c
read(11) id,pgm,ncol,nrow,nz,xo,dx,yo,dy,
& iproj,cm,bl,rot,xrotcen,yrotcen
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
call rdhead1(11,id,pgm,ncol,nrow,nz,xo,dx,yo,dy,
[highlight #FCAF3E] & iproj,cm,bl,rot,xrotcen,yrotcen)[/highlight]
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
print*,'Is this a gravity (0) or topography (1) file?'
read(5,*)id0
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cc ilon0,ilat0 are the integer central meridian, base latitude of c
cc the map projection c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
ilon0=nint(cm)
ilat0=nint(bl)
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cc del is the grid spacing in km; theta is orientation in c
cc deg +ccw from N c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
del=dx
theta=rot
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cc nc is the number of columns (EW); nr is # rows (NS) c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
nc=ncol
nr=nrow
ewtd=float(nc-1)*del
nstd=float(nr-1)*del
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cc These are dummy values not used by the program. c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
mnln=0.
mxln=1.
mnlt=0.
mxlt=1.
write(12)id0,ilon0,ilat0,dble(del),dble(theta)
write(12)nc,nr,dble(ewtd),dble(nstd)
write(12)dble(mnln),dble(mxln),dble(mnlt),dble(mxlt)
do j=1,nr
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cc Substitute read statements from your own file format here.
read(11,IOstat=IOstatus)(zrow(i),i=1,nc)
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
call row_read(11,ncol,zrow)
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
do i=1,nc
drow(i)=dble(zrow(i))
enddo
write(12)(drow(i),i=1,nc)
enddo
[highlight #8AE234] end
[/highlight]
subroutine rdhead1 (unit,id,pgm,ncol,nrow,nz,xo,dx,yo,dy,
& iproj,cm,bl,rot,xrotcen,yrotcen)
character id*56, pgm*8
integer unit
c..... Try to read header with projection and rotation information.
read(unit,err=10) id,pgm,ncol,nrow,nz,xo,dx,yo,dy,
[highlight #729FCF] & iproj,cm,bl,rot,xrotcen,yrotcen
[/highlight] return
c..... If error, try to read header with just projection information.
10 rewind unit
read(unit,err=20) id,pgm,ncol,nrow,nz,xo,dx,yo,dy,iproj,cm,bl
return
c..... If error, try to read header with no added information
20 rewind unit
read(unit) id,pgm,ncol,nrow,nz,xo,dx,yo,dy
iproj=99
cm=0.0
bl=0.0
return
end
subroutine row_read(iunit,ncol,zrow)
dimension zrow(ncol)
read(iunit, IOstat=IOstatus) dum,zrow
return
end
At line 94 of file sgf2add.f (unit = 11, file = 'CBA_master_usgs_unix.grd')
Fortran runtime error: End of file
Error termination. Backtrace:
#0 0x7f76b865816a in ???
#1 0x7f76b8658d55 in ???
#2 0x7f76b865951d in ???
#3 0x7f76b87cf7e3 in ???
#4 0x7f76b87d012f in ???
#5 0x7f76b87d01f5 in ???
#6 0x7f76b87d2a57 in ???
#7 0x564cb9982ea2 in rdhead1_
at /home/sreenidhi/MEM/Data_usgs/sgf2add.f:94
#8 0x564cb9983808 in MAIN__
at /home/sreenidhi/MEM/Data_usgs/sgf2add.f:37
#9 0x564cb9983eaf in main
at /home/sreenidhi/MEM/Data_usgs/sgf2add.f:84
I have highlighted the lines 94 (blue) 37(orange) and 84(green). I think this is very simple question but I am not able to resolve the problem. Can someone help me resolving this issue?