3

I have been tasked with porting some old (circa 1986) VAX VMS FORTRAN code to c++ and have run into a bit of a stumbling block. The following two lines of code are part of a computed goto.

WRITE(2'N) (Y (I), I = 1, 5)
READ(2'N, ERR = 48) (Y (I), I = 1, 5)

My problem is the unit designator "2'N" , if that is indeed what it is. "N" is an integer variable passed in to the subroutine. I've done quite a bit of googleing for this pattern and reading what VMS documentation I could find, but have been unable to locate any info with respect to this pattern with the apostrophe. I understand the implied do loop that follows the write and read statements, but I don't understand 'where' this is writing to and reading from. Browsing the rest of the FORTRAN code doesn't reveal a unit=2 open statement that could be associated with this call, so it seems likely it's not a disk file, but I'm not certain. I'm hoping someone here can reach back into their memory and help me out.

Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68

1 Answers1

3

If I read the VMS VAX FORTRAN manual correctly, 'N specifies the N-th record in unit 2. From Cl. 7.1.1.6 "Record Specifier":

The record specifier identifies the number of the record you wish to access in a file with relative organization. It takes either one of the following forms:

REC = r
'r

r
Is a numeric expression with a value that represents the position in a direct access file of the record to be accessed. [...]

Please note that this is not Standard-conforming Fortran! Most compilers will not accept this syntax. Instead, use REC=...:

WRITE(2, REC=N) (Y (I), I = 1, 5)
READ(2, REC=N, ERR = 48) (Y (I), I = 1, 5)

The file at unit 2 needs not be open explicitly. This is specified in the same document, Cl. 7.1.1.2 "Logical Unit Specifier":

A logical unit number is assigned to a file or device in one of the two ways:

  • Explicitly trough an OPEN statement [...]
  • Implicitly by the system [...]

In the latter case, the file name used is defined in Cl. 4.2.2.1 "FORTRAN Logical Names" of the VAX Fortran user manual:

VAX FORTRAN provides predefined logical names in the following form:

FOR0nn[.DAT]

[...]

For example:

   WRITE (17,200)

If you enter the preceding statement without including an explicit file specification, the data is written to a file named FOR017.DAT on your default disk under your default directory.

Most modern compilers will create a file fort.nn in this case.

Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68
  • Thank you for this! It makes much more sense now. Thanks also for the links to the manual. There is one spot in the code that does open a file explicitly as unit4, "ELIBn.DAT", and the file directory location has those files numbered 1 thru 9. I can figure out the rest from here. – Thomas Gamble May 23 '16 at 19:47