The Fw.d, Ew.d, ESw.d, ENw.d, Ew.dEe, ESw.dEe and ENw.dEe descriptors are used for REAL input; however, they all have the same effect as Fw.d. Therefore, we shall only discuss Fw.d. The general form of the Fw.d descriptor is as follows:
The meaning of r, w and m are:
For example, suppose we have the following:
and the input isREAL :: u, v, w READ(*,"(F5.2,F5.2,F5.2)") u, v, w
Let us assume that spaces are ignored. u takes the first five positions which contains 1, a space, 2, a space and 3. Since F5.2 is used to read this number (i.e., 123) which does not have a decimal point, a decimal point is inserted between 1 and 2. Hence, u receives 1.23. Variable v takes the next five positions, which contains a space, 4.5 and another space. Since this value contains a decimal point, it is read as is and v receives 4.5. Variable w takes the last five positions, which contain 1, a space, and 9.4. This gives 19.4 and therefore w receives 19.4.1 1 ....5....0....5 1 2 3 4.5 1 9.4
Suppose spaces are treated as zeros. The first five positions are 1, space, 2, space and 3, which is equivalent to 10203. Therefore, u receives 102.03. Similarly, variables v and w receive 4.5 and 109.4, respectively.
A real number without a decimal point in the w positions consists of an optional sign, followed by a sequence of digits. In this case, the place of the decimal point is determined by the value of d.
A real number with a decimal point starts with an optional sign, followed by zero or more digits (the integral part), followed by a decimal point, followed by zero or more digits (the fractional part). Thus, -.345, 0.345, +123 are all correct input real numbers. Note that the integral part or the fractional part must have one digit. As a result, -. is not a correct input real number.
A real number with an exponent starts with a real number, with or without a decimal point, followed by E, followed by an optional sign, followed by an integer. Thus, 12345E-9 and 12.345E-23 are correct real numbers. If the input real number contains an exponent, then d applies to the number itself. For example, if we have
and the input isREAL :: u READ(*,"(F10.4)") u
then u takes the first ten positions. If spaces are ignored, the exponent is 20 and 12345 is read in with 4 digits in the fractional part. Therefore, the actual value read in is 1.2345×1020. If spaces are treated as zeros, the value read in becomes 1.2345×102000. For most computers, this value could be too larger to be stored in memory.1 ....5....0 12345E20
No other symbols can be used; otherwise, the READ statement that uses this format will report an error and stop. If all w positions are spaces, the value is treated as a zero.
1 1 2 ....5....0....5....0 12 3.4 56E 78. 90
Suppose spaces are ignored. Variable a takes the first three positions, which contains 1, 2 and a space. After removing spaces, we have 12 and since F3.0 states no digits for the fractional part, the value read in is 12.0. Variable b takes the next four positions, which contain 3, a decimal point, a 4 and a space. After removing all spaces, we have 3.4. Since there is a decimal point, the value will be read in as is. Thus, b receives 3.4. Variable c takes the next six positions, which contain a space, 5, 6, E, a space and 7. After removing all spaces, we have 56E7. Thus, the exponent is 7 and 56 is read with F6.2 (i.e., two digits after the decimal point). Therefore, variable c receives 0.56×107. Variable d takes the next seven positions, which contain a 8, a decimal point, two spaces, 9, 0 and a space. After removing all spaces, we have 8.90. Since it contains a decimal point, the value will be read in as is and d receives 8.9REAL :: a, b, c, d READ(*,"(F3.0, F4.1, F6.2, F7.3)") a, b, c, d
If the system treats spaces as zeros, a, b, c and d receive 120, 3.4, 0.56×107, and 8.009, respectively.
Variable a takes the first 6 positions, which contain 1, 2, a space, 3, a decimal point and 4. Thus, a receives 123.4. Variable b takes the next three positions, which contain two spaces and 5. Thus, b receives 0.05. Variable c takes the next five positions, which contains 6, E, a space, 7 and 8. Hence, c receives 6×1078. Finally, d takes the next six positions, which contains a decimal point, two spaces, 9, 0 and a space. Hence, d receives 0.9.REAL :: a, b, c, d READ(*,"(F6.1, F3.2, F5.0, F6.1)") a, b, c, d
If the system treats spaces as zeros, a, b, c and d receive 1203.4, 0.05, 6×1078 and 0.009, respectively.