Append a record to the end of a text file: Difference between revisions

(→‎{{header|Fortran}}: And, on checking...)
(→‎{{header|Fortran}}: File format.)
Line 838:
END</lang>
 
The output can be read back in with the same free-format style. The fields are separated by spaces (outside a quoted string) though commas are also allowed. ToThe demonstratefile that they have been read successfully, the data aggregatecontent is printed out using the NAMELIST protocol, whereby each item in the output list is presented in the form <''name''> = <''value''>, as follows:
<pre>
"jsmith " "x " 1001 1000 "Joe Smith " "Room 1007 " "(234)555-8917 " "(234)555-0077 " "jsmith@rosettacode.org " "/home/jsmith " "/bin/bash "
"jdoe " "x " 1002 1000 "Jane Doe " "Room 1004 " "(234)555-8914 " "(234)555-0044 " "jdoe@rosettacode.org " "home/jdoe " "/bin/bash "
"xyz " "x " 1003 1000 "X Yz " "Room 1003 " "(234)555-8193 " "(234)555-033 " "xyz@rosettacode.org " "/home/xyz " "/bin/bash "
</pre>
Numerical values are written with sufficient space to allow for their maximum value, so the sixteen-bit integers are allowed six spaces (in case a minus sign might be needed) and so on for other types. Thus, complex numbers are written in the (''real'',''imaginary'') style. Given this fixed layout, an explicit FORMAT statement could be used and delimiters be abandoned along with worry over quoting, but any changes to the data structure will require corresponding changes to the associated FORMAT statement, and mistakes are easily made. For input via free-format, the trailing spaces in the quoted strings could be omitted; any needed will be supplied by the READ process.
 
To demonstrate that they have been read successfully, the data aggregate is printed out using the NAMELIST protocol, whereby each item in the output list is presented in the form <''name''> = <''value''>, as follows:
<pre>
 
1,220

edits