HP 3000 Manuals

I/O Standard Procedures and Functions [ HP Pascal/iX Reference Manual ] MPE/iX 5.0 Documentation


HP Pascal/iX Reference Manual

I/O Standard Procedures and Functions 

append 

Usage 

     append(f) 
     append(f, s) 
     append(f, s, t) 

Parameters 

f    A variable of type file.  The parameter f may not be omitted.

s    The name of a physical file associated with f.  This can be a string
     or PAC expression whose range is implementation defined.

t    A string or PAC expression whose value is implementation dependent.
     Refer to the HP Pascal/iX Programmer's Guide or the HP Pascal/HP-UX 
     Programmer's Guide, depending on your implementation, for more
     information.  This parameter specifies carriage control and file
     access.

Description 

The procedure append(f) opens file f in the output state, and places the
current position immediately after the last component.  All previous
contents of f remain unchanged.  The eof(f) function returns true, and
the file buffer f^ is undefined.  Data may now be written on f.

If f is already open, append closes and then reopens it.  If a file name
is specified, the system closes any physical file previously associated
with f.

When f does not appear as a program parameter and s is not specified, the
system maintains any previous association of a physical file with f.  If
there is no such association, it opens a temporary nameless file.  This
file cannot be saved.  It becomes inaccessible after the process
terminates or the physical-to-logical file association changes.  For more
information, see the HP Pascal/iX Programmer's Guide or the HP 
Pascal/HP-UX Programmer's Guide, depending on your implementation.

Example 

     append(file_var)
     append(file_var,phy_file_spec)
     append(file_var,phy_file_spec,opt_str)
     append(fvar,'SHORTFIL')

Illustration 

Suppose examp_file is a closed logical file of char containing three
components.  In order to open it and write additional material without
disturbing its contents, append is called.

[]
associate Usage associate(f, num, option_str) Parameters f A variable of type file. num The system-provided file number of a previously opened file. option_str Must be one of the following: READ associate to sequential access file with read access. WRITE associate to sequential access file with write access. READ, DIRECT associate to direct access file with read access. WRITE, DIRECT associate to direct access file with write access. READ, WRITE, DIRECT associate to direct access file with read/write access. DIRECT same as READ, WRITE, DIRECT. NOREWIND associate to a file without changing the current file position. Description The procedure associate(f,num,option_str) allows the opened file num to be used with Pascal input/output routines through f. The file must already be open as the result of a direct call to an operating system routine or as the result of a call to a non-Pascal procedure. The file cannot be opened as a result of a Pascal append, associate, open, reset, or rewrite. Therefore, the Pascal function fnum cannot be used to determine the file number of a file opened by Pascal. The file must also be open. One of the above-mentioned combinations must appear in option_str. It is also an error to specify read or write access if the physical file is not opened for read or write access, respectively. Other options legal for opening a file, such as those in the HP Pascal/iX Programmer's Guide or the HP Pascal/HP-UX Programmer's Guide, are ignored. Associate places the current file position at the first component of the file unless NOREWIND is specified. The contents of f, if any, are undisturbed, and f is undefined. If the option_str parameter specifies WRITE, then eof(f) returns true, even though the actual end of file remains at the end of any previously existing data in the file. If the option_str parameter specifies read access for a sequential file or read or write access for a direct access file, eof(f) returns false after the call to associate. If the file is empty and is associated to read access, a subsequent read causes an error. Example associate(file_var,file_number,option_str) Illustration Suppose examp_file is an opened logical file of char with three components. To read sequentially from examp_file, we call associate:
[]
close Usage close(f) close(f, t) Parameters f A variable of type file. f may not be omitted. t Options string that may be a string or PAC expression whose value is implementation dependent. Refer to the HP Pascal/iX Programmer's Guide or the HP Pascal/HP-UX Programmer's Guide, depending on your implementation, for more information. Description The procedure close(f) closes the file f so that it is no longer accessible. After being closed, any references to the file f, except through one of the file-open routines, results in an error, and f is not associated with any physical file. When closing a direct access file, the last component of the file is the highest-indexed component ever written to the file (lastpos(f)). The value of maxpos for the file, however, remains unchanged. Once a file is closed, it may be reopened. The options string specifies the disposition of any physical file associated with the file. The value is implementation defined. The compiler ignores leading and trailing blanks and considers upper and lower case equivalent. If no options string is supplied, the file retains its previous (original) status. Example close(fil_var) close(fil_var,opt_str) disassociate Usage disassociate(f) Parameter f A variable of type file. Description This procedure removes the logical-physical file association that was previously created with the associate procedure. Consequently, the file f is no longer available to Pascal input and output routines. Normally a file is closed upon exit from the block in which it is declared. A file that has been disassociated will not be closed upon exit, and must be explicitly closed with a direct call to the operating system routines. The disassociate procedure is useful when a file is passed to a Pascal routine and must remain open when control returns to the routine that passed the procedure to Pascal. Example disassociate (file_var) eof Usage eof(f) eof Parameter f A variable of type file that must be open. If f is omitted, the system uses the standard file input. Description This Boolean function returns true if the end of a file is reached. If the file f is open, the Boolean function eof(f) returns true when f is in the output state, when f is in the direct access state, and its current position is greater than the highest-indexed component ever written to f, or when no component remains for sequential input. Otherwise, eof(f) returns false. If false, the next component is placed in the buffer variable. If f is omitted, the system uses the standard file input. When reading non-character values, such as integers or reals, from a textfile, eof may remain false even if no other value of that type exists in the file. This can occur if the remaining components are blanks; for example, eoln is still false. Example eof eof(file_var) eoln Usage eoln(f) eoln Parameter f A variable of type TEXT opened in the input state. If f is omitted, the system uses the standard file input. Description This Boolean function returns true when the end of a line is reached in a textfile. This happens when the current position of textfile f is at an end-of-line marker. The function references the buffer variable f^, possibly causing an input operation to occur. For example, after readln, a call to eoln places the first character of the new line in the buffer variable. If f is omitted, the system uses the standard file input. Example eoln eoln(text_file) get Usage get(f) get Parameter f A variable of type file opened in input or direct access state. If f is omitted, the system uses the standard file input. Description The procedure get(f) advances the current file position and causes a subsequent reference to the buffer variable f^ to actually load the buffer with the current component. This definition of get is known as the deferred get. It is an error if f is in the output state or if eof(f) is true prior to the call to get. If a file is opened with open, a get must be performed to load the buffer variable with valid data. However, if a file is opened with reset, the buffer variable contains valid data and a get should not be performed until the second component is accessed. If get is called after read, one file component is skipped because read concludes with a get operation. Example get(file_var) Illustration Suppose examp_file is a logical file of char with three components which has just been opened in the direct state. The current position is the first component and examp_file^ is undefined. To inspect the first component, get is called.
[]
The current position is unchanged. Now, however, a reference to examp_file^ loads the first component into the buffer. We assign the buffer to a variable.
[]
lastpos Usage lastpos(f) Parameter f A variable of type file opened in the direct access state. f must be specified. Description The function lastpos(f) returns the integer index of the last component of f that has been accessed while the program has been running, or in the life of the file. It is an error if f is not opened as a direct access file. Example i:=lastpos(file_var) { File_var is the name of a file type variable } linepos Usage linepos(f) Parameter f A textfile variable that must be opened. f may not be omitted. The program must specify the standard files input and output by name. Description The function linepos(f) returns the integer number of characters read from or written to the textfile f since the last end-of-line marker. This does not include the character in the buffer variable f^. The result is zero after reading a line marker, or immediately after a call to readln, writeln, prompt, or overprint. Example i:=linepos(text_file) maxpos Usage maxpos(f) Parameter f A file variable that must be opened in the direct access state where f may not be omitted. Description The function maxpos(f) returns the integer index of the last component of f that the program could possibly access. An error occurs if f is not opened as a direct access file. Note that the value returned is implementation defined. On implementations that allow direct access files to be extended, maxpos returns the value of maxint or the maximum possible number. Example i:=maxpos(file_var) { File_var is the name of a file type variable } open Usage open(f) open(f, s) open(f, s, t) Parameters f A file variable that is not a textfile. s The name of a physical file that the system associates with f. t A string or PAC expression whose value is implementation dependent. See the HP Pascal/iX Programmer's Guide or the HP Pascal/HP-UX Programmer's Guide, depending on your implementation, for more details. Description The procedure open(f) opens f in the direct state and places the current position at the beginning of the file. The function eof returns false, unless the file is empty. The buffer variable f^ is undefined. After a call to open, f is said to be a direct access file. Data may be read or written using the procedures read, write, readdir, writedir, get or put. The procedure seek and the functions lastpos and maxpos are also legal. eof(f) becomes true when the current position is greater than the highest-indexed component ever written to f. Direct access files have a maximum number of components. The function maxpos returns this number. The lastpos function returns the index of the highest-written component of a direct access file. A textfile cannot be opened for direct access since its format is incompatible with direct access operations. When the physical file specifier parameter is specified, the system closes any physical file previously associated with f. When f does not appear as a program parameter and s is not specified, the system maintains any previous association of a physical file with f. If there is no such association, it opens a temporary, nameless file. This file cannot be saved. It becomes inaccessible after the process terminates or the physical-to-logical file association changes. For more information, see the HP Pascal/iX Programmer's Guide or the HP Pascal/HP-UX Programmer's Guide, depending on your implementation. Example open(file_var) open(file_var,phys_file_string) open(file_var,phys_file_string,opt_str) open(file_var,'TESTFILE') Illustration Suppose examp_file is a file of integer with three components. To perform both input and output, we call open:
[]
overprint Usage overprint(f) overprint(f, e) overprint(f, e1, ..., en) overprint overprint(e) overprint(e1, ..., en) Parameters f A textfile variable that must be opened. If f is omitted, the system uses the standard file output. e An expression of simple, string, or PAC type, or a string literal. The system writes the value of e on f according to the formatting conventions described for the procedure write. Description The procedure overprint has the same function as writeln, except that it does not terminate the line with a line feed. This causes the next write or overprint to overlay the line written by the original overprint. Several successive overprints all write to the same line, and printing advances to the next line after the first writeln.
NOTE Some printers do not support the overprint procedure. Refer to the manual for your particular printer.
After the execution of overprint(f), the buffer variable f^ is undefined and eoln(f) is false. The expression parameter, e, behaves exactly like the equivalent parameter for the procedure write. If the output device is not a printer, overprint will be ignored. Examples overprint(file_var) overprint(file_var,exp) overprint(file_var,exp1,...,expn) overprint(exp) overprint(exp1,...,expn) overprint or writeln('def'); overprint('___'); def page Usage page(f) page Parameter f A textfile variable that must be open. If f is omitted, the system uses the standard file output. Description The procedure page(f) writes a special character to the text file f, which causes the printer to skip to the top of the form when f is printed. The current position in f advances, and the buffer variable f^ is undefined. Example page(text_file) page position Usage position(f) Parameter f A file variable that must not be a textfile. Description The function position(f) returns the integer index of the current component of f, starting from 1. Input or output operations references this component. The parameter f must not be a textfile. Example i:=position(file_var) prompt Usage prompt(f) prompt(f, e) prompt(f, e1, ..., en) prompt prompt(e) prompt(e1, ..., en) Parameters f A textfile variable. The system uses the standard file output if f is omitted. e The expression of any simple, string, or PAC type or string literal. Description The procedure prompt(f) causes the system to write any buffers associated with textfile f to the device. prompt does not write a line marker on f. The current position is not advanced, and the buffer variable f^ becomes undefined. prompt is normally used when directing output to a terminal. prompt causes the cursor to remain on the same line after output to the screen is complete. The user may then respond with input on the same line. The expression parameter, e, behaves exactly like the equivalent parameters in the procedure write. Example prompt(file_var) prompt(file_var,exp) prompt(file_var,exp1,...,expn) prompt(exp) prompt(exp1,...,expn) prompt put Usage put(f) put Parameter f A file variable opened in the output or direct access state. The system uses the standard file output if f is omitted. Description The procedure put(f) assigns the value of the buffer variable f^ to the current component and advances the current position. Following the call, f^ is undefined. It is an error if f is open in the input state. Example put(file_var) Illustration Suppose examp_file is a file of integer with a single component opened in the output state by append. Furthermore, 9 has been assigned to the buffer variable examp_file^. To place this value in the second component, put is called.
[]
read Usage read(f,v) read(f, v1, ..., vn) read(v) read(v1, ..., vn) Parameters f A file variable opened in the input or direct access state. If f is omitted, the system uses the standard file input. v The name of a variable or component of a structure whose type is not FILE and does not contain a component of type FILE. Description The procedure read(f, v) assigns the value of the current component of f to the variable v, according to the rules below, advances the current position, and causes any subsequent reference to the buffer variable f^ to actually load the buffer with the current component. If the file is a textfile, the read variables can be simple, string, or PAC variable. If the file is not a textfile, its components must be assignment compatible with the variable. The following statement: read(f,v) is equivalent to accessing the file variable and establishing a reference to that file variable for the remaining execution of the statement (denoted by ff) and then calling get on ff. v := ff^ get(ff); For example, the call read(f,v1,...,vn); establishes a reference, ff, to the file variable, f. It is equivalent to: read(ff,v1); read(ff,v2); . . . read(ff,vn); Example read(file_var,variable) read(file,variable1,...,variablen) read(variable) read(variable1,...,variablen) Illustration Suppose examp_file is a file of char opened in the input state. The current position is at the second component. To read the value of this component into char_var, we call read:
[]
Implicit Data Conversion. If f is a textfile, its components are type char. The parameter, v, however, need not be of type char. It may be any simple, string, or PAC type, which is an HP extension. The read procedure performs an implicit conversion from the ASCII form that appears in the textfile f to actual form stored in the variable v. If v is type real, longreal, integer, or an integer subrange, the read(f,v) operation searches f for a sequence of characters which satisfies the syntax below for these types. The search skips preceding blanks or end-of-line markers. If v is longreal, the result is independent of the letter preceding the scale factor. It is an error if the read operation finds no non-blank characters or a faulty sequence of characters, or if the value is outside the range of v. After read, a subsequent reference to the buffer variable f^ actually loads the buffer with the character immediately following the number previously read. Also note that eof is false if a file has more blanks or line markers, even though it contains no more numeric values. If v is a variable of type string or PAC, then read(f, v) fills v with characters from f up to the number of elements of v. When v is type PAC and eoln(f) becomes true before v is filled, the operation puts blanks in the rest of v. If v is type string and eoln(f) becomes true before v is filled to its maximum length, no blank padding occurs. Strlen(v) then returns the actual number of characters in v. If eoln(f) is true when the call is made, no additional characters are read from f. The length of a string variable is set to zero, and PAC variables are filled with blanks. Readln must be used to proceed to the next line. If v is a variable of an enumerated type, read(f, v) searches f for a sequence of characters satisfying the syntax of an HP Pascal identifier. The search skips preceding blanks and line markers. Then the operation compares the identifier from f with the identifiers which are values of the type of v, ignoring upper and lower case distinctions. Finally, it assigns an appropriate value to v. It is an error if the search finds no non-blank characters, if the string from f is not a valid HP Pascal identifier, or if the identifier does not match one of the identifiers of the type of v. Table 10-2 shows the results of calls to read with various sequences of characters for different types of v. Table 10-2. Implicit Data Conversion ---------------------------------------------------------------------------------------------- | | | | | Sequence of Characters in f | Type of v | Result Stored in v | | Following Current Position | | | | | | | ---------------------------------------------------------------------------------------------- | | | | | (space)(space)1.850 | real | 1.850 | | | | | ---------------------------------------------------------------------------------------------- | | | | | (space)(linemarker)(space)1.850 | longreal | 1.850 | | | | | ---------------------------------------------------------------------------------------------- | | | | | 10000(space)10 | integer | 10000 | | | | | ---------------------------------------------------------------------------------------------- | | | | | 8135(end-of-line) | integer | 8135 | | | | | ---------------------------------------------------------------------------------------------- | | | | | 54(end-of-line)36 | integer | 54 | | | | | ---------------------------------------------------------------------------------------------- | | | | | 1.583E7 | real | 1.583x10(7) | | | | | ---------------------------------------------------------------------------------------------- | | | | | 1.583E+7 | longreal | 1.583x10(7) | | | | | ---------------------------------------------------------------------------------------------- | | | | | (space)Pascal | string[5] | '_Pasc' | | | | | ---------------------------------------------------------------------------------------------- | | | | | (space)Pas(end-of-line)cal | string[9] | '_Pas' | | | | | ---------------------------------------------------------------------------------------------- | | | | | (space)Pas(end-of-line)cal | PAC {length 9} | '_Pas_____' | | | | | ---------------------------------------------------------------------------------------------- | | | | | (end-of-line)Pascal | PAC {length 5} | '_____' | | | | | ---------------------------------------------------------------------------------------------- | | | | | (space)Monday(space) | enumerated | MONDAY | | | | | ---------------------------------------------------------------------------------------------- readdir Usage readdir(f, k, v) readdir(f, k, v1, ..., vn) Parameters f A file variable open to read that is not a textfile. k The index of a component in f. v The name of a variable or component of a structure whose type is not FILE and does not contain a component of type FILE. Description The procedure readdir(f, k, v) places the current position at component k, and then reads the value of that component into v. The index, k, is relative to the beginning of the file. Formally, this is equivalent to: seek(f,k); read(f,v); The call get(f) is not required between seek and read because of the definition of read. The procedure readdir can be used only with files opened for direct access. Therefore, a textfile cannot appear as a parameter for readdir. Example readdir(file_var,indx,variable) readdir(file_var,indx,variable1,...,variablen) Illustration Suppose examp_file is a file of integer with four components just opened in the direct access state. The current position is the first component. To read the third component into int_var, readdir is called. After readdir executes, the current position is the fourth component.
[]
readln Usage readln(f) readln(f, v) readln(f, v1, ..., vn) readln readln(v) readln(v1, ..., vn) Parameters f A textfile variable. The system uses the standard file input if f is omitted. v The name of a variable or component of a structure whose type is not FILE and does not contain a component of type FILE. Description The procedure readln(f) reads zero or more values from a textfile and then advances the current position to the beginning of the next line. The operation performs implicit data conversion if v is not type char, string, or PAC. The call readln(f,v1,...,vn) is equivalent to: read(f,v1,...,vn); readln(f); If the parameter, v, is omitted, readln simply advances the current position to the beginning of the next line. Example readln(file) readln(file,variable) readln(file,variable1,...,variablen) readln(variable) readln(variable1,...,variablen) readln reset Usage reset(f) reset(f, s) reset(f, s, t) Parameters f A file variable that may not be omitted. s The name of a physical file that the system associates with f. s may be a string or PAC expression. t An options string that may be a string or PAC expression whose value is implementation dependent. Description The procedure reset(f) opens the file f in the input state and places the current position at the first component. The contents of f, if any, are undisturbed. The file f may then be read sequentially. If f is not empty, eof(f) is false, and a subsequent reference to the buffer variable f^ actually loads the buffer with the first component. The components of f may now be read in sequence. If f is empty, however, eof(f) is true and f^ is undefined, then subsequent calls to read are errors. If f is already open at the time reset is called, the system automatically closes and then reopens it, retaining the contents of the file. If the parameter s is specified, the system closes any physical file previously associated with f. When f does not appear as a program parameter and s is not specified, the system maintains any previous association of a physical file with f. For more information on opening files, see the HP Pascal/iX Programmer's Guide or the HP Pascal/HP-UX Programmer's Guide, depending on your implementation. Example reset(file_var) reset(file_var,file_name) reset(file_var,file_name,opt_str) Illustration Suppose examp_file is a closed file of char with three components. To read sequentially from examp_file, we call reset:
[]
rewrite Usage rewrite(f) rewrite(f, s) rewrite(f, s, t) Parameters f A file variable that may not be omitted. s The name of a physical file the system associates with f. t May be a string or PAC expression whose value is implementation dependent. Description The procedure rewrite(f) opens the file f in the output state and places the current position at the first component. The system discards any previously existing components of f. The function eof(f) returns true and the buffer variable f^ is undefined. The file f may now be written sequentially. If f is already open at the time rewrite is called, the system closes it automatically, flushes the buffers, and then reopens it, losing the contents of the file. If s is specified, the system closes any physical file previously associated with f and associates s with f. When f does not appear as a program parameter and s is not specified, the system maintains any previous association of a physical file with f. If there is no such association, it opens a temporary, nameless file. This file cannot be saved. It becomes inaccessible after the process terminates or the physical-to-logical file association changes. For more information, see the HP Pascal/iX Programmer's Guide or the HP Pascal/HP-UX Programmer's Guide, depending on your implementation. Example rewrite(file) rewrite(file,file_name) rewrite(file,file_name,opt_str) Illustration Suppose examp_file is a closed file of char with three components. To discard these components and write sequentially to examp_file, rewrite is called.
[]
seek Usage seek(f, k) Parameters f A file variable that must be opened in the direct access state. It may not be a textfile. k The integer index of a component of f. This must be an integer expression >0. Description The procedure seek(f, k) places the current position of f at component k. If k is greater than the index of the highest-indexed component ever written to f, the function eof(f) returns true, otherwise false. The buffer variable f^ is undefined following the call to seek. It is an error if f is not open in the direct access state, or k is greater than maxpos(f). The index, k, is relative to the beginning of the file. Example seek(file_var,indx) Illustration Suppose examp_file is a file of char with four components opened for direct access. The current position is the second component. To change it to the fourth component, seek is called.
[]
write Usage write(f, e) write(f, e1, ..., en) write(e) write(e1, ..., en) Parameters f A file variable that must be open in the output or direct access state. e A variable or expression whose type is not FILE and which does not contain a component of type FILE. Description The procedure write(f, e) assigns the value of e to the current component of f and then advances the current position. After the call to write, the buffer variable f^ is undefined. It is an error if f is not open in the output or direct access state. It is also an error if the current position of a direct access file is greater than maxpos (f). If f is not a textfile, e must be an expression whose result type is assignment compatible with the components of f. If f is a textfile, e may be an expression whose result type is any simple, string, or PAC type. Also, the value of e may be formatted as it is written to a textfile as described later in this chapter. The call write(f, e) is equivalent to accessing the file variable, f, and establishing a reference to that file variable for the remaining execution of the statement denoted by ff. The call write(f,e1,...en) is equivalent to: write(ff,e1); write(ff,e2); . . write(ff,en); Example write(file_var,exp:5) write(file_var,exp1,...,expn) write(exp) write(exp1,...,expn) Illustration Suppose examp_file is a file of integer opened in the output state, and that one number has been written to it. To write another number, write is called again:
[]
Formatting of Output to Textfiles When f is a textfile, the result type of e need not be char. It may be any simple, string, or PAC type, or a string literal. The value of e may be formatted as it is written to f using the integer field-width parameters m and, for real or longreal values, n. If m and n are omitted, the system uses default formatting values. Therefore, three forms of e are possible: e {default formatting} e:m {when e is any type} e:m:n {when e is real or longreal} Table 10-3 shows the system default values for m. Table 10-3. Default Field Widths --------------------------------------------------------------------------- | | | | Type of e | Default Field Width (m) | | | | --------------------------------------------------------------------------- | | | | char | 1 | | | | --------------------------------------------------------------------------- | | | | integer | 12 | | | | --------------------------------------------------------------------------- | | | | real | 12 | | | | --------------------------------------------------------------------------- | | | | longreal | 20 | | | | --------------------------------------------------------------------------- | | | | bit16 | 12 | | | | --------------------------------------------------------------------------- | | | | bit32 | 12 | | | | --------------------------------------------------------------------------- | | | | bit52 | 12 | | | | --------------------------------------------------------------------------- | | | | longint | 12 | | | | --------------------------------------------------------------------------- | | | | shortint | 12 | | | | --------------------------------------------------------------------------- | | | | boolean | 5 * | | | | --------------------------------------------------------------------------- | | | | enumerated | length of identifier | | | | --------------------------------------------------------------------------- | | | | string | current length of string | | | | --------------------------------------------------------------------------- | | | | PAC | length of PAC | | | | --------------------------------------------------------------------------- | | | | string literal | length of string literal | | | | --------------------------------------------------------------------------- * If $STANDARD_LEVEL$ is not ANSI or ISO, then the default width of TRUE is 4.
NOTE If e is Boolean or an enumerated type, the case of the letters written is implementation defined.
When m is specified and the value of e requires less than m characters for its representation, the operation writes e on f preceded by an appropriate number of blanks. If the value of e is longer than m, it is written on f without loss of significance; such that m is defeated, provided that e is a numeric type. Otherwise, the operation writes only the leftmost m characters. m may be 0 if e is not a numeric type. When e is type real or longreal, you may specify n as well as m. In this case, the operation writes e in fixed-point format with n digits after the decimal point. If n is 0, the decimal point and subsequent digits are omitted. If n is not specified, the operation writes e in floating-point format consisting of a coefficient and a scale factor. In no case is it possible to write more significant digits than the internal representation contains. This means write may change a fixed-point format to a floating-point format in certain circumstances. Example PROGRAM show_formats (output); VAR x: real; lr: longreal; george: boolean; list: (yes, no, maybe); BEGIN writeln(999); {default formatting} writeln(999:1); {format defeated} writeln('abc'); writeln('abc':2); {string literal truncated} x:= 10.999; writeln(x); {default formatting} writeln(x:25); writeln(x:25:5); writeln(x:25:1); writeln(x:25:0); lr:= 19.1111; writeln(lr); george:= true; writeln(george); {default format} writeln(george:2); list:= maybe; writeln(list); {default formatting} END. Output: 999 999 abc ab 1.099900E+01 1.099900E+01 10.99900 11.0 11 1.9111099243164L+01 TRUE TR MAYBE writedir Usage writedir(f, k, e) writedir(f, k, e1, ..., en) Parameter f A file variable opened in direct access state. k The integer index of a component of f. e An expression whose result type must be assignment compatible with the components of f. Description The procedure writedir(f, k, e) places the current position at the component of f specified by k, and then writes the value of e to that component. It is equivalent to: seek(f,k); write(f,e) An error occurs if f has not been opened in the direct-access state or if k is greater than maxpos(f). After writedir executes, the buffer variable f^ is undefined, and the current position is k+ n, where n is from en. Example writedir(fil_var,indx,exp) writedir(fil_var,indx,exp1,....,expn) Illustration Suppose file examp_file is a file of integer opened for direct access. The current position is the third component. To write a number to the first component, we call writedir:
[]
writeln Usage writeln(f) writeln(f, e) writeln(f, e1, ..., en) writeln writeln(e) writeln(e1, ..., en) Parameters f A file variable for a text file opened in the output state. The system uses the standard file output if f is omitted. e A variable or expression whose type is not FILE and does not contain a component of type FILE. Description The procedure writeln(f, e) writes the value of the expression e to the textfile f, appends an end-of-line marker, and places the current position immediately after this marker. After execution, the file buffer f^ is undefined, and eof(f) is true. You may write the value of e with the formatting conventions described for the procedure write. The call writeln(f, e1,..., en) is equivalent to write(f,e1); write(f,e2); . . . write(f,en); writeln(f) The call writeln without the file or expression parameters effectively inserts an end-of-line marker in the standard file output. Example writeln(fil_var) writeln(fil_var,exp:4) writeln(fil_var,exp1,...,expn) writeln(exp) writeln(exp1,...,expn) writeln


MPE/iX 5.0 Documentation