Your compiler system may or may not print the optional sign of a positive number. If your compiler system does not print the optional plus sign, you can force it to print. On the other hand, if your compiler system does print a plus sign, you can also force the compiler not to print it. Note that whether a plus sign should be printed is not part of the ANSI Fortran 90 standard. A compiler vendor is allowed to make a choice. This choice is called the default setting of your system. Edit descriptors S, SP and SS are used to enforce or suppress the printing of the optional plus sign of a positive number. The forms of these descriptors are as follows:
In the above example, the number printed by I5 will use the default setting. Then, SP indicates that positive numbers must be printed with a plus sign. This affects the numbers printed with I6 and F6.2. Then, we see S, which indicates that the plus sign of a positive number is up to the compiler system's default setting. This only affects the number printed by F5.0. After this, SS indicates that the plus sign of a positive number should not be printed. This affects the number printed using I4.(I5, SP, I6, F6.2 / S, F5.0, SS, I4 )
The printing of a plus sign for the number printed by I5 is up to the compiler system's default setting. Then, we see SP, which indicates that a plus sign must be printed for all positive numbers. This affects I6. What if there are unprocessed data items? In this case, format rescanning occurs and the number printed by I5 will have a plus sign if it is positive. This is the meaning of "all subsequent output".(1X, I5, SP, I6)
The following is the output. All positive numbers on the second and fourth columns are printed with plus signs since SP is used in the format. All positive numbers on the first and third columns are printed without plus signs because SS is used.PROGRAM SignControl IMPLICIT NONE INTEGER :: i REAL :: x CHARACTER(LEN=*), PARAMETER :: Format = "(1X,SS,I5,SP,I5,SS,F6.1,SP,F6.1)" CHARACTER(LEN=*), PARAMETER :: Heading = " SS SP SS SP" WRITE(*,"(1X,A)") Heading DO i = -5, 5 x = REAL(i) WRITE(*,Format) i, i, x, x END DO END PROGRAM SignControl
1 1 2 2 ....5....0....5....0....5 SS SP SS SP -5 -5 -5.0 -5.0 -4 -4 -4.0 -4.0 -3 -3 -3.0 -3.0 -2 -2 -2.0 -2.0 -1 -1 -1.0 -1.0 0 +0 0.0 +0.0 1 +1 1.0 +1.0 2 +2 2.0 +2.0 3 +3 3.0 +3.0 4 +4 4.0 +4.0 5 +5 5.0 +5.0