next up previous contents
Next: File I/O Up: Formats Previous: Example: READ Integer Data   Contents

Example: READ Character Data

Consider the length 10 character variables

character(len=10) :: C1, C2
which are initialized by a READ statement. The input string is
michigantech
Depending on the format, the values assigned to A, B are different.

Statement C1 C2
READ "(A8,A4)",C1,C2 michigan tech
READ "(A12,A12)",C1,C2 chigantech
READ "(A,A)",C1,C2 michigante ch

(we denote the blank spaces by ). In case 1 the first 8 characters are read in C1 (which is padded with 2 additional blanks), and the remaining 4 characters are read in C2 (which is padded with additional 6 blanks). In case 2 the required width (12) is greater than the length of the string; the rightmost 10 characters are stored in C1, and there is no input left for C2 (which is therefore not changed). In case 3 we do not specify any width; the plain A descriptor reads in as many characters as needed to fill the variable (here, the first 10 characters fill in C1).


next up previous contents
Next: File I/O Up: Formats Previous: Example: READ Integer Data   Contents
Adrian Sandu 2001-08-26