Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!linac!unixhub!slacvm!ljm From: LJM@SLACVM.SLAC.STANFORD.EDU (Len Moss) Newsgroups: comp.lang.fortran Subject: Re: integer variable format address Message-ID: <91065.121307LJM@SLACVM.SLAC.STANFORD.EDU> Date: 6 Mar 91 20:13:05 GMT References: <6769@idunno.Princeton.EDU> Organization: Stanford Linear Accelerator Center Lines: 56 In article , userAKDU@mts.ucs.UAlberta.CA (Al Dunbar) says: > >In article <6769@idunno.Princeton.EDU>, hsbrown@lemmy.Princeton.EDU (Scott >Brown) writes: >>What is wrong with the following program? >> program test >> integer k >> k=1 >> write(*,k) >> >> 1 format('here is line 1') >> end [Stuff omitted.] >Sell your two books, or read them more carefully; this is not >standard Fortran. When a variable appears as a format specifier, >it supplies an address at which should be found a format >specification in the form of a string literal. The only way I >know to get an integer variable to store a statement number is >with the ASSIGNED GOTO; even then the docs/standard warn severely >against referencing in any other way a variable used for this >purpose. Which standard for Fortran do you mean? Indeed, in Fortran 66 an INTEGER variable mentioned in an ASSIGN statement could not be referenced in any statement other than an assigned GOTO until it was redefined; and any type of array (but not a scalar variable) containing leading Hollerith data defining a valid format specification could be used in a formatted input/output statement in place of the reference to a statement label. However, as others have already noted, Fortran 77 permits the ASSIGN statement to assign the statement label of a FORMAT statement to an INTEGER variable which may then be used in a formatted input/output statement as the format identifier (the relevant parts of X3.9-1978 are page 12-8, lines 10-13 and page 10-2, lines 17-46). Dynamic formats in Fortran 77 are handled via the CHARACTER data type. Strictly speaking, Hollerith data was deleted from the language by the 77 standard, so the use of non-CHARACTER arrays as format identifiers is prohibited. However, Appendix C of X3.9-1978 contains recommendations for implementing Hollerith as an extension for those processors concerned about Fortran 66 compatibility. (This is roughly equivalent to the notion of an "obsolescent feature" in Fortran 90, especially since Hollerith is completely absent from Fortran 90.) These recommendations include the use of arrays containing Hollerith data as format identifiers, just as in Fortran 66. Note that there is no ambiguity for INTEGERs: when used as a format identifier, an INTEGER variable (i.e., scalar) can only contain an ASSIGNed statement label, and an INTEGER array can only contain a Hollerith format specification. -- Leonard J. Moss | My views don't necessarily Stanford Linear Accelerator Center, Bin 97 | reflect those of SLAC, Stanford, CA 94309 | Stanford or the DOE