Fortran format 1H in legacy and modern versions of fortran with the gfortran


The functioning of 1H in the Fortran format statement leaves a space before the text. Any suggestions?

"1H " is the very old way to define a string of one character, in this case a space. Try it with “1HA” instead. Although I am not entirely sure how it interacts with the more modern way of specifying a string.

I just scanned over the f2023 draft, and I do not see any description of the H edit descriptor there. Maybe I overlooked it?

Back when the H edit descriptor was still part of the language (e.g. in the f77 standard), it was described as a nonrepeatable edit descriptor. The list of edit descriptors in a format specification was separated with commas, with a few exceptions (slash, colon, and a few numerical descriptors). The H edit descriptor was not included in that exception list.

So if I’m correct on this, the above legacy code is incorrect because it is missing the comma between the two list items. It should have been written as

9010  format(1H ,"Hello World")

As for the question about suggestions, I’m unclear what is being requested. Do you want to eliminate the space? If so, then just delete the first edit descriptor in the format list (along with the comma separator).

[edit] The nagfor compiler flags the missing comma error, while gfortran compiles it without warning.

The H edit descriptor was deleted in Fortran 1995.

Edit: 1995, not 2005. I was actually looking at the 1995 standard as I typed.

Omitting the comma between  1H and "Hello World" does not flag an error. The program fortt runs. 
ian@ian-Latitude-E7440:~$ nano fortt.f
ian@ian-Latitude-E7440:~$ gfortran fortt.f -o fortt
ian@ian-Latitude-E7440:~$ ./fortt
 Hello World
ian@ian-Latitude-E7440:~$ nano fortt.f
ian@ian-Latitude-E7440:~$ gfortran fortt.f -o fortt
ian@ian-Latitude-E7440:~$ gfortran fortt.f -std=legacy -o fortt
ian@ian-Latitude-E7440:~$ ./fortt
 Hello World
ian@ian-Latitude-E7440:~$ cat fortt.f
        write(6,9010) 
 9010   format(1H "Hello World")
        end program
ian@ian-Latitude-E7440:~$ nano fortt.f
ian@ian-Latitude-E7440:~$ gfortran fortt.f -std=legacy -o fortt
ian@ian-Latitude-E7440:~$ ./fortt
 Hello World
ian@ian-Latitude-E7440:~$ nano fortt.f
ian@ian-Latitude-E7440:~$ gfortran fortt.f -std=legacy -o fortt
ian@ian-Latitude-E7440:~$ ./fortt
 Hello World
ian@ian-Latitude-E7440:~$ cat fortt.f
        write(6,9010) 
 9010   format(1H ,"Hello World")
        end program
ian@ian-Latitude-E7440:~$ nano fortt.t
ian@ian-Latitude-E7440:~$ nano fortt.f
ian@ian-Latitude-E7440:~$ gfortran fortt.f -o fortt
ian@ian-Latitude-E7440:~$ cat fortt.f
        write(6,9010) 
 9010   format(1H "Hello World")
        end program
ian@ian-Latitude-E7440:~$ ./fortt
 Hello World
ian@ian-Latitude-E7440:~$ nano fortt.f
ian@ian-Latitude-E7440:~$ cat fortt.f
        write(6,9010) 
 9010   format(1H ,"Hello World")
        end program
ian@ian-Latitude-E7440:~$ gfortran fortt.f -o fortt
ian@ian-Latitude-E7440:~$ ./fortt
 Hello World
ian@ian-Latitude-E7440:~$ nano fortt.f
ian@ian-Latitude-E7440:~$ cat fortt.f
        write(6,9010) 
 9010   format("Hello World")
        end program
ian@ian-Latitude-E7440:~$ gfortran fortt.f -o fortt
ian@ian-Latitude-E7440:~$ ./fortt
Hello World
ian@ian-Latitude-E7440:~$
ian@ian-Latitude-E7440:~$ gfortran fortt.f -o fortt
ian@ian-Latitude-E7440:~$ cat fortt.f
        write(6,9010) 
 9010   format(1H "Hello World")
        end program
ian@ian-Latitude-E7440:~$ ./fortt
 Hello World
ian@ian-Latitude-E7440:~$ nano fortt.f
ian@ian-Latitude-E7440:~$ cat fortt.f
        write(6,9010) 
 9010   format(1H ,"Hello World")
        end program
ian@ian-Latitude-E7440:~$ gfortran fortt.f -o fortt
ian@ian-Latitude-E7440:~$ ./fortt
 Hello World
ian@ian-Latitude-E7440:~$ nano fortt.f
ian@ian-Latitude-E7440:~$ cat fortt.f
        write(6,9010) 
 9010   format("Hello World")
        end program
ian@ian-Latitude-E7440:~$ gfortran fortt.f -o fortt
ian@ian-Latitude-E7440:~$ ./fortt
Hello World
ian@ian-Latitude-E7440:~$ nano fortt.f
ian@ian-Latitude-E7440:~$ gfortran fortt.f -o fortt
ian@ian-Latitude-E7440:~$ ./fortt
AHello World
ian@ian-Latitude-E7440:~$ cat fortt.f
        write(6,9010) 
 9010   format(1HA "Hello World")
        end program
ian@ian-Latitude-E7440:~$ 
![Screenshot from 2024-04-05 11-01-43|690x388](upload://7w2wC0PxEjG7COlAbvspFzccgK.png)
![Screenshot from 2024-04-05 11-02-17|690x388](upload://WnyCd8gH9m39o0lh1Xp0l6i0wb.png)

Every now and then someone posts something that makes me really feel my age. Back when most computer printers were large line printers there were a handfull of special characters known as carriage control characters which told the printers how many VERTICAL (ie line feeds) spaces to move the printer head down before starting to print as well as other ways to move the printer head around. The majority of these were usually coded as the first output character in a record (or line of print). A single blank character as the first character told the printer to move one vertical space from its last position before printing. Here are the commonly used values for the first character control character:

First output character           Preprinting carriage movement
blank                            move one vertical space
0                                move two veritcal spaces
1                                move to new paper sheet
+                                no vertical spacing

The carriage control character was treated as a non-printing character and discarded in the output.
Note a FORMAT statement like

100 FORMAT(5F15.5)

could have a blank space in the output field that would be lost in the resulting output because the printer would interpret the leading blank character in the output as carriage control blank. I guess when the Hollerith constants were deleted the notion of the action of old fashion carriage control characters went with them.

So ends the history lesson for today :smile:

If you add the -pedantic option to gfortran, then it also reports the missing comma error. The error message indicates that dropping the comma is an extension.

It was only ASA line printers that processed the first character of each line like that. ASCII printers started becoming popular in the 1970s. There were several years of overlap, when programmers needed to write output files for both types of printer. There was a popular utility program (called “asa”) during that time that would convert files with ASA conventions to files with ASCII embedded characters (and maybe the reverse, I don’t remember). I think the last ASA printer I used was in the mid 1990s. I don’t remember the model number, but it was not a mechanical chain printer, it was a xerox type printer.

[edit] That printer was one of these IBM 3800 - Wikipedia. but I don’t remember the exact model number. It was black-and-white only, no color, and it was one of the models that used continuous form fan-fold paper where each page was 8.5x11.

There was something satisfying in a perverse way about standing in front of a line printer and listening to the clicky-clack of the printer as in spewed out a 5 inch thick pile of output from a compiler or a simulation you just ran. Gave you a real sense of accomplishment :smile:

History lesson part 2. The last standard mentioning Hollerith data was f77, Appendix C, saying it had been deleted but recommending rules for processors that allowed it as an extension. In f90 and f95 the only references to carriage control were that in various circumstances each output record begins with a blank character to provide carriage control when the record is printed.
Those references were not in f2003 though the blank characters still were (and still are in f2023). The H edit descriptor was explicitly deleted in f2003.

I was more familiar with the landscape size paper (either 14x11 or 14x8.5) printers. This format was great when you were developing code (pre interactive terminals) because it left enough space in the right margin to make notes, corrections etc. Here is what the wikipedia says about line printers in case the young folks are wondering just what the heck we are talking about.

I remember TV shows in the late 1960s and 1970s that would show how “powerful” the computer was by showing how fast the line printer could scroll the paper. Then the camera would switch over to watch a tape drive rewind a tape – the reel would spin faster doing a rewind that it would reading it. The line printer was typically the size of a washing machine, while the tape drive was the size of a refrigerator.

The H edit descriptor was deleted from F95. FWIW, when using gfortran -std=f95 option, the compiler issues a warning. Whereas with other deleted ancient Fortran-isms (e.g., PAUSE, ASSIGN/assigned GOTO, etc) the compiler issues an error.

I submitted a bug report on this (114611 – H edit descriptor should flag as error with -std-f95 (or higher)). Looks like a fix is already forthcoming. The gfortran team rocks!

(As an aside, the table in the Standard on carriage control was quietly deleted from F2003.)