0
votes

I'm attempting to modernize an old code (or at least make it a bit more understandable) but I've run into an odd format for a, uh, FORMAT statement.

Specifically, it's a FORMAT statement with Hollerith constants in it (the nH where n is a number):

  FORMAT(15H  ((C(I,J),J=1,I3,12H),(D(J),J=1,I3, 6H),I=1,I3,')  te'        
 1,'xt'  ) 

This messes with the syntax highlighting as it appears this has unclosed parenthesis. It compiles fine with this format statement as is, but closing the parenthesis causes a compiling error (using either the intel or gfortran compiler).

As I understand it, Hollerith constants were a creature of Fortran 66 and were replaced with the advent of the CHARACTERin Fortran 77. I generally understand them when used as something like a character, but use as a FORMAT confuses me.

Further, if I change 15H ((... to 15H ((... (i.e. I remove one space) it won't compile. In fact, it won't compile even if I change the code to this:

  FORMAT(15H  ((C(I,J),J=1,I3,12H),(D(J),J=1,I3, 6H),I=1,I3,')  text'  ) 

I would like this to instead be in a more normal (F77+) format. Any help is appreciated.

1

1 Answers

5
votes

What you have are actually Hollerith edit descriptors, not constants (which would occur in a DATA or CALL statement), although they use the same syntax. F77 replaced Hollerith constants outright; it added char-literal edit descriptor as a (much!) better alternative, but H edit descriptor remained in the standard until F95 (and even then some compilers still accepted it as a compatibility feature).

In any case, the number before the H takes that number of characters after the H, without any other delimiter; that's why deleting (or adding) a character after the H screws it up. Parsing your format breaks it into these pieces

15H  ((C(I,J),J=1,
I3,
12H),(D(J),J=1,
I3,
 6H),I=1,
I3,
')  te' 
'xt'

and thus a modern equivalent (with optional spaces for clarity) is

   nn FORMAT( '  ((C(I,J),J=1,', I3, '),(D(J),J=1,', I3, '),I=1,', I3 
     1,') text' )

or if you prefer you can put that text after continuation (including the parens) in a CHARACTER value, variable or parameter, used in the I/O statement instead of a FORMAT label, but since you must double all the quote characters to get them in a CHARACTER value that's less convenient.

Your all-on-one-line version probably didn't compile because you were using fixed-form, perhaps by default, and only the first 72 characters of each source line are accepted in fixed-form, of which the first 6 are reserved for statement number and continuation indicator, leaving only 66 and that statement is 71 by my count. Practically any compiler you will find today also accepts free-form, which allows longer lines and has other advantages too for new code, but may require changes in existing code, sometimes extensive changes.