View previous topic :: View next topic |
Author |
Message |
christyleomin
Joined: 08 Apr 2011 Posts: 155
|
Posted: Thu Mar 06, 2014 7:24 am Post subject: FORTRAN writing to back storage file |
|
|
Can anyone help me to understand what is a back storage file in FORTRAN to which I write statements with unit 3 like
my_number may eb some integer/real
I am trying to underatns an old piece of code that has such statements |
|
Back to top |
|
 |
christyleomin
Joined: 08 Apr 2011 Posts: 155
|
Posted: Thu Mar 06, 2014 7:29 am Post subject: |
|
|
Also: I do not find where the file is opened. |
|
Back to top |
|
 |
christyleomin
Joined: 08 Apr 2011 Posts: 155
|
Posted: Thu Mar 06, 2014 8:45 am Post subject: |
|
|
My question is where is this getting written into? |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Thu Mar 06, 2014 8:52 am Post subject: |
|
|
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 |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Thu Mar 06, 2014 8:54 am Post subject: |
|
|
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. |
|
Back to top |
|
 |
christyleomin
Joined: 08 Apr 2011 Posts: 155
|
Posted: Thu Mar 06, 2014 9:10 am Post subject: |
|
|
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 :
Code: | 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? |
|
Back to top |
|
 |
IanLambley
Joined: 17 Dec 2006 Posts: 506 Location: Sunderland
|
Posted: Thu Mar 06, 2014 1:56 pm Post subject: |
|
|
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. |
|
Back to top |
|
 |
|