8 File Storage
TYP (file number)
The possible values returned and their meanings are shown in the following table:
|3||End-of-file (EOF) mark.|
|4||End-of-record (EOR) mark.|
|8||First part of a string.|
|9||Intermediate part of a string.|
|10||Last part of a string.|
|11||HP-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 ENDNow 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 ENDLine 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.
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.
REC (file number)
A negative file number always returns 0.
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.
returns the file name associated with the given file number.
ASSIGN #1 TO"foo,TMP" DISP FNAME$(1) -> /tmp/foo.DATAAn absolute path-name is returned, depending on the platform.