4

I am compiling a program (that I did not write) using gfortran. The make file specified f77 as the compiler, but I do not have it.

I have run into an error related to the OPEN command.

Error: The STATUS specified in OPEN statement at (1) is 'NEW' and no FILE specifier is present

I looked into Fortran 77 OPEN, and according to the Oracle language reference there is a default behaviour when 'FILE=name' is not specified.

http://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vnaf/index.html

'NEW' -- The file doesn't exist (existence is an error). If 'FILE=name' is not specified, then a file named 'fort.n' is opened, where n is the specified logical unit.

Is there a way to force the compiler to use the language specified default behaviour. Alternatively, can I modify the code to perform the expected default behaviour?

nedlrichards
  • 322
  • 2
  • 14

1 Answers1

5

The document you cite is not a language specification, it is a description of one particular compiler. The behaviour regarding the file fort.n is compiler specific. For actual standard documents see https://stackoverflow.com/tags/fortran/info

Specifically, the Fortran 2008 says:

9.5.6.10 FILE= specifier in the OPEN statement

1 The value of the FILE= specifier is the name of the file to be connected to the specified unit. Any trailing blanks are ignored. The file-name-expr shall be a name that is allowed by the processor. If this specifier is omitted and the unit is not connected to a file, the STATUS= specifier shall be specified with a value of SCRATCH; in this case, the connection is made to a processor-dependent file. The interpretation of case is processor dependent.

That means that your program is not conforming, because when FILE= is omited, the only permissible value of STATUS= is "SCRATCH".

Gfortran also does create the fort.n files when you write to a unit which you did not open, but not when you execute the open statement with status="new". It should be easy for you to add the file= specifier to the code. You can even use the fort.N names if you insist on them. See Convert integers to strings to create output filenames at run time for the way how to get the integer into the file name.

Another option is to download the Oracle Solaris Studio, it contains the f77 command and is likely to follow the compiler specific document you have cited. It is actually quite a good compiler (if lacking some modern Fortran features) with very good visual debugging and profiling utilities. However, I recommend you to make your code portable and standard conforming first.

Community
  • 1
  • 1