Lisa
Lisa

Reputation: 1

Write error in Fortran

I am struggling to read from one input text file into a new text file using the Fortran compiler in Visual Studio 10. My input file is in gslib format (attached)

program main  

! Unit numbers:  

      lisa = 4  
      lfke = 9  

! Writing input data to file Lisa  

      open(unit=lisa,file='fake.dat',status='OLD',err=80)  
      open(unit=lfke,file='dlfke',status='NEW', err=80)  
      read(lisa,*,err=80)  
      read(lisa,*,err=80) line  
      write(9,*) line    
      close(unit=lisa)  
      close(unit=lfke)           
      80   stop 'ERROR in test file!'  
      end

Upvotes: 0

Views: 1693

Answers (1)

M. S. B.
M. S. B.

Reputation: 29401

This program is always going to produce the error message "ERROR in test file", whether or not there is an error. After executing line the close statements, it will next execute line 80 with the stop statement. You will probably find it easier, as your develop your program, to remove the err=80 tests in each IO statement. Then if there is an IO error, the program will automatically terminate and produce a specific message about the program. These err=branches are useful if you want to have your program handle the error, but with this implementation its hiding what the IO error was since all IO errors produce the same message.

Upvotes: 3

Related Questions