Previous:The #fclose Directive Main Index Next:The #write Directive

#### The #read Directive

You may read string, float or vector values from a plain ASCII text file directly into POV-Ray variables using the #read directive. The file must first be opened in "read" mode using the #fopen directive. The syntax for #read is as follows:

READ_DIRECTIVE:
`
  #read(
` FILE_HANDLE_IDENTIFIER`,` DATA_IDENTIFIER[`,`DATA_IDENTIFIER]...`)`
DATA_IDENTIFIER:
  UNDECLARED_IDENTIFIER
| FLOAT_IDENTIFIER |
  VECTOR_IDENTIFIER
| STRING_IDENTIFIER

Where FILE_HANDLE_IDENTIFIER is the previously opened file. It is followed by one or more DATA_IDENTIFIERs separated by commas. The parentheses around the identifier list are required. A DATA_IDENTIFIER is any undeclared identifier or any previously declared string identifier, float identifier, or vector identifier. Undefined identifiers will be turned into global identifiers of the type determined by the data which is read. Previously defined identifiers remain at whatever global/local status they had when originally created. Type checking is performed to insure that the proper type data is read into these identifiers.

The format of the data to be read must be a series of valid string literals, float literals, or vector literals separated by commas. Expressions or identifiers are not permitted in the data file however unary minus signs and exponential notation are permitted on float values.

If you attempt to read past end-of-file, the file is automatically closed and the FILE_HANDLE_IDENTIFIER is deleted from the symbol table. This means that the boolean function `defined(`IDENTIFIER`)` can be used to detect end-of-file. For example:

      #fopen MyFile "mydata.txt" read

      #while (defined(MyFile))

        #read (MyFile,Var1,Var2,Var3)

        ...

      #end

Previous:The #fclose Directive Main Index Next:The #write Directive