8 File Storage

File Storage Functions

The TYP Function

The TYP (type) function is used to determine what type of data is to be accessed by READ#.

TYP (file number)

The possible values returned and their meanings are shown in the following table:

File Table Reset Conditions
Value Meaning
0Unrecognized type.
1Real-precision number.
2Total string.
3End-of-file (EOF) mark.
4End-of-record (EOR) mark.
5Integer-precision number.
6Short-precision number.
7Dinteger
8First part of a string.
9Intermediate part of a string.
10Last part of a string.
11HP-UX text file.

If the file number is negative, the record and word pointers are not advanced. If it is positive, however, the pointers move until positioned at something other than an EOR mark. In effect, a negative file number causes a direct read. A positive file number causes a serial read, ignoring EOR marks.

The next program is used to print (serially) various types of data on a new file named TYPE?:

10   CREATE "TYPE?",5
20   ASSIGN "TYPE?" TO #1
30   INTEGER Int
40   SHORT Short
50   Real=1E99
60   String$="STRING"
70   Int=12345
80   Short=654321
90   PRINT #1;Real,String$,Int,Short
100  END
Now run this program which uses the TYP function to identify each data item, and then stores it into the appropriate type of variable:

10        ASSIGN #1 TO "TYPE?"
20        INTEGER Int
30        SHORT Short
40        READ #1,1
50 Type:  !
60        ON TYP(-1) GOTO Real,String,Eof,Eor,Integer,Short
70 Real:  !
80        READ #1;Real
90        PRINT Real,"is a real-precision value."
100       GOTO Type
110 String:  !
120       READ #1;String$
130       PRINT String$,"is a string variable."
140       GOTO Type
150 Eof:  !
160       PRINT "EOF mark is next."
170       STOP
180 Eor:  !
190       PRINT "EOR mark is next."
200       STOP
210 Integer:  !
220       READ #1;Int
230       PRINT Int,"is an integer-precision value."
240       GOTO Type
250 Short:  !
260       READ #1;Short
270       PRINT Short,"is a short-precision value."
280       GOTO Type
290       END
Line 40 sets the record pointer to record 1 of file TYPE?. The computed GOTO statement (line 60) branches the program to one of six labels, depending upon the value returned by TYP(-1). This statement is executed before the READ# to determine which type of data is to be read next. Here is the printout:

1.00000000000E+99   is a real-precision value.
STRING              is a string variable.
 12345              is an integer-precision value.
 654321             is a short-precision value.
EOR mark is next.
Notice that if the record pointer had been set to any other record of file TYPE? (for example, READ#1,4) the TYP function would return 3, indicating an EOF mark. Remember that each record is filled with EOFs when it is CREATEd; the EOFs are replaced by data via PRINT# statements.

The SIZE Function

The SIZE function returns the size of the specified file.

SIZE (file number)

A positive file number, for all files except HP-UX text files, returns the file size expressed in logical records. For HP-UX text files (TYP 11), the file size is expressed in bytes.

A negative file number, for all files except HP-UX files, returns the logical record size in words (one word equals two bytes). For HP-UX text files, a negative file number returns the number 1.

The REC Function

The REC (record) function returns the current position of the data pointer within the specified file.

REC (file number)

A negative file number always returns 0.

The WRD Function

The WRD (word) function returns the current position of the word pointer for the specified file.

WRD (file number)

A value of 1 indicates the first word of the record.

NOTE: The WRD function cannot be used on an regular text file (TYP 11). Doing so will result in error 69 ("operation not allowed for this file type").

NOTE: The AVAIL and HOLE functions are no longer valid.

The FNAME$ Function

The keyword

FNAME$ (expr)

returns the file name associated with the given file number.

For example:

ASSIGN #1 TO"foo,TMP"
DISP FNAME$(1)

-> /tmp/foo.DATA
An absolute path-name is returned, depending on the platform.


Eloquence Language Manual - 19 DEC 2002