![]()
Formatting input
The same formatting statements we used last class in the PRINT statement can also be assigned to a READ statement
Using a character mask in a READ statement can be very useful - the mask A80 is often used to read an entire line of text, and another function is later used to break it down into words
Try writing a short program which reads a 20-character variable using first a READ * statement and then a READ '( A20)' statement and print the variable out to the screen. Notice the differences between the two values of the variable when you use spaces, quotation marks and slashes in the input.
FORTRAN 77, as I have mentioned previously, does not support unformatted character input. In order to read a character from the keyboard, the mask for the character must be set in the READ statement.
Verify this by modifying the READ statement in your project to read the units on a separate line, then compiling using f77
FORMAT
An alternative to having the character masks in front of each PRINT or READ statement is to place them in a FORMAT statement, which is given a line reference number.
The line reference number is used in the parentheses after the PRINT or READ statement
Once a FORMAT statement has been written, it can be used anywhere in that program *NOTE - the FORMAT statement does NOT have to be before the line where it is used*
Try replacing the formatted READ and PRINT statements in your programs with FORMAT statements