The Iw and Iw.m descriptors are used for INTEGER input; however, the effect of Iw.d is identical to that of Iw. Therefore, we shall only discuss Iw. The general form of the Iw descriptor is as follows:
The meaning of r, w and m are:
and the inputINTEGER :: a, b, c, d READ(*,"(4I5)") a, b, c, d
Then, all four variables receive the same value, 135. Let us see why. All four variables are read with I5. Variable a takes the first five positions, which contain 1, followed by a space, followed by 3, followed by a space, followed by 5. After removing all spaces, we have 135, which becomes the value for a. You can reach the same conclusion for variables b, c and d.1 1 2 ....5....0....5....0 1 3 5 135 135 135
Whether a space is treated as a zero or ignored is system dependent. But, you can easily figure it out. Type in the following example and run it with the above input. Based on the output, you will know how your Fortran compiler handles spaces.
The way of treating spaces affects your input. If your system chooses to ignore spaces, then the input integer can be anywhere in the w positions, even with embedded spaces. Otherwise, all of your input integers must be right-justified. Note that Fortran has edit descriptors to change this behavior (e.g., BN and BZ). Also note that our system ignores spaces.PROGRAM To_see_if_spaces_are_zeros IMPLICIT NONE INTEGER :: a, b, c, d READ(*,"(4I5)") a, b, c, d WRITE(*,*) a, b, c, d END PROGRAM To_see_if_spaces_are_zeros
1 1 2 ....5....0....5....0 12 34 56 78 90
Variable a takes the first position, which contains 1. Thus, a receives 1. Variable b takes the next two positions, which contain 2, followed by a space. Since all spaces are ignored, b receives 2. Variable c takes the next three positions, which contain 3, 4 and a space. Therefore, c receives 34. Variable d takes the next four positions, which contain a space, followed by 5, followed by 6, followed by a space. Thus, d receives 56.INTEGER :: a, b, c, d READ(*,"(I1, I2, I3, I4)") a, b, c, d
If the system treats spaces as zeros, a, b, c and d receive 1, 20, 340 and 560, respectively.
Since all variables have received values, the remaining input are ignored. This is exactly the same as what you have learned in listed-directed READ.
Variable a takes the first 3 positions, which contain 1, 2 and a space. Thus, a receives 12. Variable b takes the next four positions, which contain 3, 4 and two spaces. Thus, b receives 34. Variable c takes the next seven positions, which contains 5, 6, two spaces, 7, 8 and a space. Hence, c receives 5678. Finally, the only position for d contains a space. Since if all w are spaces, the value is considered to be a zero and d receives zero.INTEGER :: a, b, c, d READ(*,"(I3, I4, I7, I1)") a, b, c, d
If the system treats spaces as zeros, a, b, c and d receive 120, 3400, 5600780 and 0, respectively.
Since all variables have receives values, the remaining input are ignored. This is exactly the same as what you have learning in listed-directed READ.