READ and WRITE simple variables, strings, arrays
READ and WRITE are binary I/O statements.  They read and write data without alteration, interpretation, or conversion.

Strings are written without a length, and neither null terminators nor newline characters are appended.  Only the string data itself is written. If a string is empty, nothing is written. Arrays are handled much like strings.  No length is written, only the array data.

Except for arrays and strings, all variables including those of user-defined composite types, have a known, fixed size.  Reading fixed-size variables from a file is simple. Reading into variables of the same types that were written guarantees correct operation.

Arrays and strings of known size can be written much like fixed-size variables.   Before they are read back correctly, however, the array or string must be sized properly.  Arrays and strings can be sized by DIM and NULL$() in preparation for a READ.

When arrays or strings of unknown size or type must be stored in a binary file, additional information must be written before the data.

For example, when a variable size string is written, an SLONG variable containing the number of elements could be written before the string.  Before the string is read, the number of elements is read into an SLONG variable, which is used in NULL$() to size string appropriately for the read.

For example:

  READ [ifile], n
  a$ = NULL$ (n)
  READ [ifile], a$
  READ [ifile], n
  IF (n <= 0) THEN
    DIM a[]
    DIM a[n-1]
    READ [ifile], a[]