Silverfrost Forums

Welcome to our forums

FORTRAN writing to back storage file

6 Mar 2014 6:24 #13790

Can anyone help me to understand what is a back storage file in FORTRAN to which I write statements with unit 3 like

write(3) my_number

my_number may eb some integer/real

I am trying to underatns an old piece of code that has such statements

6 Mar 2014 6:29 #13791

Also: I do not find where the file is opened.

6 Mar 2014 7:45 #13793

My question is where is this getting written into?

6 Mar 2014 7:52 #13794

There must be a file opened on unit 3 that is an unformatted file. Some compilers will open a default named file, other compilers will give an error that the file is not opened. Is it your program, or are you just providing a subroutine ? You might not see the code that opens the file.

John

6 Mar 2014 7:54 #13795

With FTN95 you get a run time error...

Error 94, in file ... Unit has neither been OPENed nor preconnected.

If you don't get this error report then I guess there must be an OPEN statement somewhere in your code.

6 Mar 2014 8:10 #13797

I'm not getting a runtime error. I will be trying with FTN 95 only next week.

All this old code needs to work with FTN 95 finally

I have a 2011 version of FORTRAN intel compiler and it works with that.

Is it compiler dependent?

Also, I noticed that the data is read correctly :

integer rn,a,b
         
         integer itype, w, h
     
      
       mbck=3
       rn=1
       a=4 
       b=7 
        
        

      write(mbck) rn,a,b
     
      rewind mbck
      read(mbck) itype, w, h
      close(mbck)

I see that there is a file named fort3 at the location my project folder structure exists.

But the characters written inside the are unreadable (I opened the file in wordpad) the characters appear like below



Is this a binary file?

6 Mar 2014 12:56 #13800

The good old DEC VAX Fortran compiler used to automatically open a file if there was no explicit OPEN statement, i.e. FORT003.DAT in that case. This was a 'get-around' for old code derived from batch machines where the OPEN statement within the Fortran language did not exist and the files were assigned as part of the batch commands.

Paul is right, you should insert an OPEN statement at the appropriate point, and probably a CLOSE statement as well.

Yes the data is binary with record length information at the start and end of each record. The length information is compiler dependent and has been discussed at length in this forum. Do not expect an unformatted file from another compiler to be readable.

Please login to reply.