Please enable JavaScript to view this site.

ESL Documentation

FILEIO Subroutine

Output the variables specified by a record definition to a file.

call WriteRecord(FILE_ID_IV, RECORD_NAME_REC)

FILE_ID_IV

An integer variable for the file id.

RECORD_NAME_REC

The name of the source record.

Description

This output subroutine allows you to create an ASCII or EBCDIC file on disk from a record.

WriteRecord( ) assembles the output line(s) in its buffer and then, for the sake of efficiency, outputs the buffer to disk at one time. Therefore, adequate buffer size is essential. A 1K buffer is the default, but the buffer size can be adjusted. If the buffer size is not large enough for all the fields of a record to fit evenly, the buffer is repeatedly increased to the next larger 1K increment until they fit.

Errors

FIO_E_BADFIELD

Bad field in a record (must be integer, float, or string).

FIO_E_BUFFTOOSMALL

Internal buffer too small. Although an attempt was made to increase the buffer's size to fit in a single line, system memory ran out before the current line could be accommodated. Make sure lines are terminated by a carriage return (\r) or newline (\n); otherwise, the entire file is interpreted as one line.

FIO_E_DISKFULL

Disk has no more space for writing. The disk to which the file is being written is full.

FIO_E_FILEHANDLE

Invalid file handle--internal error. Unlikely error. Contact your support representative.

FIO_E_FILELOCKED

File locked by another program.

FIO_E_LINETOOBIG

Current line exceeded buffer size. Although an attempt was made to increase the buffer's size to fit in a complete line, system memory ran out before the current line could be accommodated. Make sure lines are terminated by a carriage return (\r) or newline (\n); otherwise the entire file is interpreted as one line.

FIO_E_LONGSTRING

String length exceeded 64K. Unlikely error. Contact your support representative.

FIO_E_NOTOPEN

File has not been opened. A file must be opened before a read attempt is made.

FIO_E_OPENFORREAD

Writing to file open for reading only.

FIO_E_SUBSCRIPTCOUNT

Wrong number of array subscripts. The array referenced in the record has more dimensions than the number of subscripts specified.

FIO_E_SUBSCRIPTRANGE

Array subscript out of range. One array subscript in the record is greater than the highest allowable subscript for that dimension.

FIO_E_WRITEACC

Write access violation. Should never happen during output.

FIO_E_WRITEERR

Unknown write error occurred.

Example

integer FileID_IV

string FileNameOut_SV is "myfile.txt"

string FileMode_SV

string Source_SV is "This is a string."

string Line_SV is "This is a line."

string NewLine_SV is "\n"

record Out_Rec is

filler 10

Line 80

NewLine 1

end record

include "fileio.inc"

 

# To be brief, error handling is omitted

response to line "Open Myfile" from keyboard

 copy "w" to FileMode_SV

 call OpenFile ( FileID_IV, FileNameOut_SV, FileMode_SV )

 

response to line "Close Myfile" from keyboard

 call CloseFile ( FileID_IV )

 

response to line "Write String" from keyboard

 call WriteString ( FileID_IV, Source_SV )

 

response to line "Write Record" from keyboard

 call WriteRecord ( FileID_IV, Out_Rec )