replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Write(*,*) and Print * Statements
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 

Write(*,*) and Print * Statements

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



Joined: 10 Feb 2014
Posts: 8
Location: Chicago, Illinois USA

PostPosted: Sun Feb 16, 2014 7:55 pm    Post subject: Write(*,*) and Print * Statements Reply with quote

Does Silverfrost FTN95 allow statements such as

print *, ' This is a test '

and

write(*, 100)
100 format(1x,' This is a test')


Sometimes print * and write (*, ) works and sometimes I get the following error at run time:

*** Error 94, Unit has neither been OPENed nor preconnected

Also I cannot find where print * and write (*, ) are documented in Silverfrost FTN95 documentation.

(I am porting over code from a compiler where the above statements are valid.)

Thanks to anybody that helps with this.
_________________
Regards,
Bob
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Mon Feb 17, 2014 3:03 am    Post subject: Reply with quote

You should not get the error report you have identified for the code examples you have provided.
I typically use write (*,*) 'This is a test'

where you would probably get the error report is when you have:
write (1,*) 'This is a test'
or
write (6,*) 'This is a test'
In these cases, the code was written where fortran unit 1 or 6 defaulted to standard output. Salford Fortran defaults unit 1, although 5 and 6 also work. This might not be the case with other compilers. The following example demonstrates what works with FTN95.
Code:
    integer*4 lu, iostat
!
    do lu = 1,10
      write (lu,*, iostat=iostat) 'successful test for unit',lu
      if (iostat /= 0) write (*,*) 'ERROR : unsuccessful test for unit',lu
    end do
    write (lu,*) 'error example for unit',lu
!
end
Back to top
View user's profile Send private message
Magliola



Joined: 10 Feb 2014
Posts: 8
Location: Chicago, Illinois USA

PostPosted: Mon Feb 17, 2014 5:54 am    Post subject: Reply with quote

John,
Thank you for the help and post. I ran your bit of code and I get the following:

successful test for unit 1
successful test for unit 2
ERROR : unsuccessful test for unit 3
ERROR : unsuccessful test for unit 4
successful test for unit 5
successful test for unit 6
ERROR : unsuccessful test for unit 7
ERROR : unsuccessful test for unit 8
ERROR : unsuccessful test for unit 9
ERROR : unsuccessful test for unit 10

It looks like units 1, 2, 5 and 6 all default to output to the console window.

I did a little testing and I see that if units 1 through 10 are all first assigned to files then write(*,*) and print * both write to the file attached to unit 2. So * and 2 are synonymous.

Is there a default unit for reading from the keyboard?

I am writing short test programs to try replicating the error in the ported program. But no luck so far. (i.e. I cannot duplicate the error.)

Any ideas why print * and write (*, *) works and sometimes I get the following error at run time:

*** Error 94, Unit has neither been OPENed nor preconnected

It looks like error 94 should never happen with print * and write (*, *).
_________________
Regards,
Bob
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Mon Feb 17, 2014 9:28 am    Post subject: Reply with quote

Units 1,2,5 and 6 are reserved for standard input and output.
Back to top
View user's profile Send private message AIM Address
Magliola



Joined: 10 Feb 2014
Posts: 8
Location: Chicago, Illinois USA

PostPosted: Mon Feb 17, 2014 12:10 pm    Post subject: Reply with quote

Thank you John and thank you Paul for helping me solve this code problem.

For reference, the symptoms the code had and the error are thus:
1) WRITE (*,*) works as expected with output to the console window.
2) the code then opens unit 2 as a scratch file.
3) WRITE (*,*) now writes to the scratch file. [That explains why the write (*,*) stopped writing to the console window.]
4) the code then executes CLOSE(2,STATUS='KEEP'). The next occurrence of WRITE (*,*) crashes the program with the Error 94.

Follow up Question:
In good practice how should one take advantage of units 1,2,5 and 6 in their code?
_________________
Regards,
Bob
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Mon Feb 17, 2014 11:59 pm    Post subject: Reply with quote

My approach to good practice is to never open a file using a file unit number less than 11. (11 for read, 12 for write) This copes with all fortran compilers I have ever used.
I typically open text files for units 11-19, binary files on 21+ and a log file on unit 98. This approach has been based on once using a compiler that limited the file number to 99.
I am not sure what the maximum number can be, but I have seen examples of unit numbers 1000+. I have never realy had to find out.
Over the years, there have been many posts where people got in trouble with "reserved" file unit numbers < 10. I did know that units 1,5 and 6 were often special but have never had the need to find out that unit 2 is also reserved in FTN95. There's always somenthig new.

John
Code:
    integer*4 lu, iostat
    character line*80
!
    do lu = 1,10
      write (lu,*, iostat=iostat) 'successful test for unit',lu
      if (iostat /= 0) write (*,*) 'ERROR : unsuccessful test for unit',lu
    end do
!    write (lu,*) 'error example for unit',lu
!
    do lu = 11,11011,500
!
      open (unit=lu, file='some_file.txt', iostat=iostat)
       if (iostat/=0) then
         write (*,*) 'unable to use file unit',lu
         cycle
       end if
!
      if (lu==11) then
       write (11,*) 'test line written using file unit',lu
      else
!
       read (lu,fmt='(a)', iostat=iostat) line
        if (iostat/=0) then
         write (*,*) 'unable to read file unit',lu
        else
         write (*,*) lu,' ',trim (line)
        end if
      end if
!
      close (unit=lu,iostat=iostat)
       if (iostat/=0) then
         write (*,*) 'unable to close file unit',lu
       end if
!
    end do
!
end
The limit must be a big number !
Back to top
View user's profile Send private message
Magliola



Joined: 10 Feb 2014
Posts: 8
Location: Chicago, Illinois USA

PostPosted: Tue Feb 18, 2014 3:38 am    Post subject: Reply with quote

John, Thank you for your help and advice. I am definitely adopting your practice to unit numbering.
_________________
Regards,
Bob
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