forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem WRITE

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Helen



Joined: 15 Mar 2018
Posts: 9

PostPosted: Thu Mar 15, 2018 4:59 pm    Post subject: Problem WRITE Reply with quote

Doing fortran at Uni this year and using the marvellous PLATO to edit,compile, build and run my programs on a windows 10 laptop.

Most things going swimmingly fine with one exception: I can’t work out how to write to a file, so I was hoping for some advice.

Previously with other platforms, I just have to say write (100,*) ‘hello world’ and this writes nicely to the fort.100 file.

But this doesn’t work for me on PLATO so I need some guidance!

I've read help docs and I'm currently trying:

Code:
OPEN (UNIT=10,FILE='test.out')
!I've never needed to use OPEN before but I thought I'd try it!
WRITE(10) 'Volume = ',a


I'm getting the error at runtime "File access and properties are incomplete."

Any assistance greatly appreciated!

Helen
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 934

PostPosted: Thu Mar 15, 2018 7:15 pm    Post subject: Reply with quote

Unlike some other compilers, FTN95 does not open a file with a name such as FORTnn if I/O is attempted to unit-nn without a previous OPEN statement having been executed for the file. Does the file "test.out" already exist in the working directory?

If you wish to create a new file, add the clause STATUS='NEW' to the OPEN statement. If you are going to run your program several times, and you do not mind overwriting the file, should it already exist, you may use the STATUS='REPLACE' clause instead. See https://silverfrost.com/ftn95-help/inout/open.aspx .

By the way, please note that Plato is merely an IDE from which the FTN95 compiler, SLINK linker and SDBG debugger can be managed. Other IDEs such as MS Visual Studio can be used with the same development tools.


Last edited by mecej4 on Sun Apr 01, 2018 9:03 pm; edited 2 times in total
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 861

PostPosted: Thu Mar 15, 2018 9:53 pm    Post subject: Reply with quote

I didn't know this mecej4 ..... and it isn't clearly stated either in the documentation that you link to above, I don't think (unless I missed some subtelty, or more likely just missed something altogether)

Maybe the

Quote:
STATUS=<string>
<string> is a character expression which, when trailing spaces are removed, gives the value OLD, NEW, REPLACE, SCRATCH or UNKNOWN.


in the documentation needs to have something like the following appended to it ? ....

Quote:
If OPENing an output file then STATUS = NEW is obligatory


and maybe it should also be reflected in the first example given at the top of that documentation page which gives an example exactly like the one attempted by Helen, albeit for an input file.

This point is also worthy of being added to any section(s) of the documentation concerning conversion of programs from other compilers which , if I understand correctly, allow opening of ouput files without the STATUS = NEW present.

I presume that the FORTRAN standard is clear on this point ?[/quote]
_________________
"This is the triumph of folly.
The machine, which knows no rest, ought to remain a tool,
... but instead becomes our master and will swallow up our life and soul"
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 934

PostPosted: Thu Mar 15, 2018 10:32 pm    Post subject: Reply with quote

The standard leaves out the meanings of many I/O statement keywords as "implementation dependent".

If STATUS='NEW' is used, the I/O system will create the file on the first successful run of the program. A subsequent run will fail because the file already exists, unless the user remembers to delete the file before the second, etc., runs. This is where STATUS='REPLACE' comes in handy. If the output file does not exist, 'REPLACE' is equivalent to 'NEW'. For an existing file, 'REPLACE' causes the file to be deleted and then created.

After a file has been opened for writing with 'NEW' or 'REPLACE', the status of the file changes to 'OLD'.
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 177
Location: Glasgow, Scotland.

PostPosted: Thu Mar 15, 2018 11:47 pm    Post subject: Reply with quote

Interesting post which puzzled me as I've never came across this issue before and I don't always use STATUS.

I would use this code instead.

Code:
a = 1.0
OPEN (UNIT=10,FILE='test.out') 
WRITE(10,*) 'Volume = ',a
end
Back to top
View user's profile Send private message Visit poster's website
mecej4



Joined: 31 Oct 2006
Posts: 934

PostPosted: Fri Mar 16, 2018 12:32 am    Post subject: Reply with quote

According to the standard, if the STATUS= clause is omitted, it defaults to STATUS='UNKNOWN', and the status is processor dependent.

What this implies is that if you use OPEN with no STATUS= clause, some compilers may cause the OPEN to fail. If things are working and you don't switch compilers, your code will continue to work as before.
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 861

PostPosted: Fri Mar 16, 2018 4:22 am    Post subject: Reply with quote

Ken, is that code you posted what you meant because it appears to be exactly the same as Helen's code ! (barring the initialisation of 'a' that is ) ?
_________________
"This is the triumph of folly.
The machine, which knows no rest, ought to remain a tool,
... but instead becomes our master and will swallow up our life and soul"
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 1968
Location: Sydney

PostPosted: Fri Mar 16, 2018 6:49 am    Post subject: Re: Reply with quote

John-Silver wrote:
Ken, is that code you posted what you meant because it appears to be exactly the same as Helen's code ! (barring the initialisation of 'a' that is ) ?


No, Helen had "WRITE(10) ..." while Ken had "WRITE(10,*) ..."

Helen's write statement was wrong as it implied an unformatted binary write, while Ken's was a formatted write to a text file.

Helen,
FTN95 requires that you must open a file, before you can use it.
Some other compilers will open a default named file, if you don't provide a name. (Not sure what they do about FORM= etc)
I think it was previously the case that some compilers provided an automatic name to temporary files (STATUS='SCRATCH') but past compilers I have used have required a file-name to be provided with an OPEN statement.

The safest way is to specify:
Open (UNIT=.., FILE=.., STATUS=.., FORM=.., IOSTAT=..)

FORM='FORMATTED' is the default, so if you specify alternatives (UNFORMATTED), then you also need to provide further options.

I think the documentation for OPEN is the part of the language manual that I refer to most often. It copes with many different possible uses of files.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 934

PostPosted: Fri Mar 16, 2018 12:01 pm    Post subject: Reply with quote

John, I did not put a literal interpretation on the two lines of code in the original post. Without a format specifier in the WRITE statement, the code shown would have failed with any compiler for the following reasons.

"WRITE(10)" implies an unformatted file connection, whereas the standard says "If this specifier is omitted, the default value is UNFORMATTED if the file is being connected for direct access, and the default value is FORMATTED if the file is being connected for sequential access."

It would be useful for Helen to post the actual code that generated the error message that she posted, along with details such as the compiler version, options in effect, etc.
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 177
Location: Glasgow, Scotland.

PostPosted: Fri Mar 16, 2018 9:44 pm    Post subject: Re: Reply with quote

mecej4 wrote:
According to the standard, if the STATUS= clause is omitted, it defaults to STATUS='UNKNOWN', and the status is processor dependent.

What this implies is that if you use OPEN with no STATUS= clause, some compilers may cause the OPEN to fail. If things are working and you don't switch compilers, your code will continue to work as before.


Thanks Mecej, it's been a very long time since I used another compiler and now that I've got to grips with Clearwin+ I have no plans to change. But I have made a note of this for future reference.
Back to top
View user's profile Send private message Visit poster's website
Helen



Joined: 15 Mar 2018
Posts: 9

PostPosted: Wed Mar 21, 2018 12:10 pm    Post subject: thank you, all! Reply with quote

Thank you all so much for helping me out with my novice question! Your help has solved the problem and I'm writing with glee now! Have a great week!
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 1864
Location: South Pole, Antarctica

PostPosted: Wed Mar 21, 2018 1:10 pm    Post subject: Re: Problem WRITE Reply with quote

Helen wrote:

I'm getting the error at runtime "File access and properties are incomplete."
Any assistance greatly appreciated!


1) I wrote about this here many times. That was good example of Fortran punishing itself and losing market share by such cryptic error messages.

2) It might be worth to synchronize FTN95 with most other compilers which allow WRITE and READ without even OPENing any files. Fortran strict, complex and confusing rules for input/output often punish novices so much that they never use Fortran again.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 934

PostPosted: Sun Apr 01, 2018 3:39 pm    Post subject: Reply with quote

Dan, I think that you are rather severe on the compiler here. Helen did not post the source code, so we do not know what the compiler told her when she compiled and linked it.

I ran into a similar situation ten days later, where the code contained the equivalent of
Code:
program tst
implicit none
integer i,j,k
!
open(2,file='fort.2',status='replace',form='formatted')
do i=1,10
   print *, 'i = ',i
   j=i*i
   k=i*i*i
   write(2)i,j,k     ! *** ERROR ***: unformatted I/O on formatted file connection
end do
close(2)
end program tst

The compiler said:
Code:
0005) open(2,file='fort.2',status='replace',form='formatted')
WARNING - Opening unit 2 may affect the operation of output to the default unit '*' - are you sure you want to do this?
0012) close(2)
WARNING - Closing unit 2 may affect the operation of output to the default unit '*' - are you sure you want to do this?
    NO ERRORS, 2 WARNINGS  [<TST> FTN95 v8.10.0]
Creating executable: tstw.EXE

Running the program gave
Code:
Run-time Error
 *** Error   90, File access and properties are incompatible

We can suggest more clear wording for the error message, but we should not fault the run time error message after we have ignored the compile time warnings.

In the actual application, the OPEN and WRITE statements contained LUT as the file unit number; the OPEN and WRITE occurred in separate source files, so the compiler could not have known that LUT = 2, and did not issue any warnings.


Last edited by mecej4 on Sun Apr 01, 2018 4:03 pm; edited 2 times in total
Back to top
View user's profile Send private message
Helen



Joined: 15 Mar 2018
Posts: 9

PostPosted: Sun Apr 01, 2018 3:45 pm    Post subject: just a word Reply with quote

i am a novice so i can quite understand why i fell at the first hurdle, but I found your forum and being here is so great of you!
I was using Simply Fortran (just found it first) at first until I had to pay what was too much for me and on that program you don't have to to open the file first... you can just write. However it is swings and roundabouts (probably) as I never worked out how to write to a "specific" filename in that program... it always seemed that it had to be a number 100,101 etc. I'm probably still very ignorant, but I just wanted to add my novice experience! Happy Easter!
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 934

PostPosted: Sun Apr 01, 2018 4:13 pm    Post subject: Re: just a word Reply with quote

Helen wrote:
i am a novice so i can quite understand why i fell at the first hurdle, but I found your forum and being here is so great of you!
I was using Simply Fortran (just found it first) at first until I had to pay what was too much for me and on that program you don't have to to open the file first... you can just write. However it is swings and roundabouts (probably) as I never worked out how to write to a "specific" filename in that program... it always seemed that it had to be a number 100,101 etc. I'm probably still very ignorant, but I just wanted to add my novice experience! Happy Easter!

Helen, we are all ignorant in one way or another, but we are here to help one another, and this forum is very effective at that! FTN95 is a great compiler for use when learning Fortran. Your questions on using the compiler and Fortran programming are welcome.

I think that the other Fortran compiler that you used allowed you to use unit numbers (such as 100, 101, ..) for I/O without naming and OPENing the corresponding files, but that is a non-standard extension. I should be very surprised if that compiler did not accept OPEN -- if it did not, that compiler would be flouting the Fortran standard.

Apt quotation: ‘Good judgment comes from experience, and experience — well, that comes from poor judgment!'
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group