Standard conforming way to get command line arguments in FORTRAN77

127 Views Asked by At

The gcc manual mentions getarg as a gnu extension. It seems to be supported by many compilers (i.e. the rather strict f2c also understands it). But getarg is not mentioned in the FORTRAN77 standard. So is/was there any standard conforming way to get command line arguments in FORTRAN77?

2

There are 2 best solutions below

0
Vladimir F Героям слава On BEST ANSWER

No there are no features for this in standard FORTRAN 77. This kind of interaction with the operating system is not covered in the ancient FORTRAN 77 standard and must be done using extensions to the standard or using standard features from Fortran 2003 as in How to use command line arguments in Fortran?.

I realized that the exact formulation of your question was rather "So is/was there any standard conforming way to get command line arguments in FORTRAN77?". This opens way to discussion what exactly is and is not standard conforming and involves subtleties you may not have originally in mind when originally asking.

I agree that extensions, especially additional intrinsic procedures, are allowed by the standard and hence calling them does not make any FORTRAN 77 program not standard conforming. My point was that the standard itself does not offer any such features and the extensions are not standardized and can be different in different processors.

Similarly, a FORTRAN 77 program calling an external library written in another language or directly in the processor's machine code or assembly is still perfectly legal FORTRAN 77 program. It is just not a program that only uses features available in FORTRAN 77.

3
francescalus On

It is possible to write a standard-conforming F77 program which gives access to the command line arguments on some processor; it is not possible to write a standard-conforming F77 program which is guaranteed by the standard to give access to command line arguments on all processors.

Consider the two programs:

      EXTERNAL GETARG
      CHARACTER*32 ARG
      CALL GETARG(1,ARG)
      END

and

      INTRINSIC GETARG
      CHARACTER*32 ARG
      CALL GETARG(1,ARG)
      END

The second program is not a conforming F77 program as it relies on a non-standard intrinsic. But, the first?

Consider also

      CHARACTER*32 ARG
C Unit 785 is preconnected to a file with command arguments
C We may also be able to connect 785 to a file like a Linuxy /proc/self/cmdline
      READ(785,*) ARG
      END

The question prompted by the first and third programs is not whether there's a standard-conforming way to get the command line arguments, but whether there's a portable standard-conforming way.1

For some systems it's possible to write a standard F77 program which reads command line arguments. It isn't possible to write a standard F77 program which is (portably) guaranteed by that Fortran standard to access command line arguments. Before F2003, Fortran itself had no concept of command line arguments, and even F2023 doesn't assume command line arguments are supported by the processor.

Similarly, in F77 we can call C functions. What F2003 and later add are portable and well-defined ways to interoperate with C.


1 Recall what F77 has to say:

Because a standard-conforming program may place demands on the processor that are not within the scope of this standard or may include standard items that are not portable, such as external procedures defined by means other than FORTRAN, conformance to this standard does not ensure that a standard-conforming program will execute consistently on all or any standard-conforming processors.