In all examples discussed previously, we always assumed that blanks in input are ignored and we also discussed the other possibility that blanks can be treated as zeros. Now, you can control the meaning of these blanks in a READ statement. They are either ignored or treated as zeros. The edit descriptors for this purpose are BN and BZ, which have the following forms:
In the above example, when using I5 and F6.2 to read in values, blanks are ignored. However, when using F7.3 and I10 to read in values blanks are treated as zeros.(BN, I5, F6.2, BZ, F7.3, T25, I10)
The number read with I5 uses the compiler system's default setting. Then, we see BZ, which indicates in all subsequent input blanks are treated as zeros. This affects F7.0. Moreover, if format rescanning occurs, the influence of this BZ will also affect I5.(1X, I5, BZ, F7.0)
Suppose we have the following input:PROGRAM BlankTest IMPLICIT NONE INTEGER :: a, b REAL :: x, y INTEGER :: IO CHARACTER(LEN=60) :: Format CHARACTER(LEN=5) :: Input Format = "(A5, BN, T1, I5, BZ, T1, I5, BN, T1, F5.2, BZ, T1, F5.2)" WRITE(*,"(1X,A)") "Input BN BZ BN BZ" WRITE(*,"(1X,A)") "----- --- --- ----- -----" DO READ(*,Format, IOSTAT=IO) Input, a, b, x, y IF (IO < 0) EXIT WRITE(*,"(1X, A, 2I6, 2F8.2)") Input, a, b, x, y END DO END PROGRAM BlankTest
We should have the following output:....5 1 3 5 2 4 6 8 9 112 23 4 5 678
Take the first input line as an example. The first five positions contain 1 3 5, which is read and printed as a character string on the first column. Then, we use BN to reread these five positions with I5. Since blanks are ignored, the result is 135. Then, BZ is set and the first five positions are reread with I5. Since now blanks are treated as zeros, these positions are considered as 10305 which is the result read into variable b.1 1 2 2 3 3 ....5....0....5....0....5....0....5 Input BN BZ BN BZ ----- --- --- ----- ----- 1 3 5 135 10305 1.35 103.05 2 4 24 2040 0.24 20.40 6 8 9 689 60809 6.89 608.09 112 112 11200 1.12 112.00 23 4 234 2304 2.34 23.04 5 678 5678 50678 56.78 506.78
Now BN is set and read with F5.2. Since blanks are ignored, these five positions are considered to be 135. Taking the right-most two digits for the fractional part, variable x receives 1.35. Finally, BZ is set and read using F5.2. Since blanks are treated as zeros, these five positions contains 10305. Hence, taking the right-most two digits for the fractional part, variable y receives 103.05.