Blank Control: BN and BZ

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:

BN     and     BZ

Example

Consider the following example. (Click here to download a copy of this program.) This program repeatedly reads in the first five positions into different variables with different edit descriptors. Please refer to the Tabbing: Tc, TLc and TRc page for the use of the T edit descriptor. When a READ starts, it reads in the first positions into CHARACTER variable Input. Then, T1 brings the next position back to position 1 and reads it with BN and I5. In this way, the first five positions are read five times, each with a different setting of BN and BZ:
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
Suppose we have the following input:
....5
1 3 5
 2 4
6 8 9
112 
 23 4
5 678
We should have the following output:
         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
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.

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.