×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Fortran runtime error: End of file while reading data from unformatted file

Fortran runtime error: End of file while reading data from unformatted file

Fortran runtime error: End of file while reading data from unformatted file

(OP)
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?

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,
     &   iproj,cm,bl,rot,xrotcen,yrotcen)
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
      end

      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,
    &   iproj,cm,bl,rot,xrotcen,yrotcen
      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 
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?

RE: Fortran runtime error: End of file while reading data from unformatted file

maybe it would be helpful if you post how the file looks like

RE: Fortran runtime error: End of file while reading data from unformatted file

Well, for starters, if what you have posted reflects exactly your source code...line 94 has the '&' in the wrong column; it needs to be in column 6

RE: Fortran runtime error: End of file while reading data from unformatted file

Quote:

...needs to be in column 6

Use to be a STOP on the KEYPUNCH punch master drum Hollerith card for FORTRAN code, if I’m not mistaken. Recall punching up a master while M.M. O’Hare ranted.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close