HP 3000 Manuals

General File Information [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation


HP Pascal/iX Programmer's Guide

General File Information 

You need the general file information in this section to understand the
rest of this chapter.  Examine Figure 3-2 , and then read the
explanations of the entities in italics, whose relationships it shows.

Figure 3-2  illustrates the relationship between physical files (in
the operating system environment) and logical files (in the program
environment).  It also shows how logical files, textfiles, and the
standard textfiles input and output are related.

[]
Figure 3-2. File Relationships Physical Files A physical file is a program-independent entity that the operating system controls. It can be a file on a disk or other medium, or an interactive file created at a terminal (refer to your operating system manual for information on creating and controlling physical files). Your program can manipulate a physical file if the physical file is associated with one of the program's logical files. In this case, the physical file assumes the characteristics of the logical file. Logical Files A logical file is a data structure that a program declares and controls. It is a sequence of components of the same type. The declaration of a logical file determines the type of its components but not their number. A logical file that is declared FILE OF x has components of type x. File operations can change the number of file components. A logical file does not exist outside the main program or routine that declares it. If it is associated with a physical file, however, anything that happens to the logical file within the program also happens to the physical file. This is how a program can manipulate its external environment.
NOTE In subsequent sections of this chapter, the term file refers to a logical file unless otherwise noted.
Textfiles A textfile is a logical file that is subdivided into lines, each of which ends with an end-of-line marker. The components of a textfile are of type char, but a textfile declaration specifies the type text, not FILE OF char. The standard files input and output are textfiles. If you declare them in the program header, they are the default file parameters for all of the sequential input and output procedures, respectively. Example PROGRAM prog (input,output); VAR tfile : text; c : char; BEGIN . . . read(tfile, c); {Reads from tfile} read(c); {Reads from input} write(c); {Writes to output} END. The preceding program has three textfiles: the standard textfiles input and output, and the file tfile. End-of-line markers are not file components, and are not of type char. The predefined procedure writeln writes them to the file (see "Textfile Input/Output" ). An end-of-line marker always precedes the end-of-file mark in a textfile, whether writeln wrote the last component to the file or not. Current Position Indexes Every logical file has a current position index that indicates either its current component, an end-of-file marker, or (in a textfile) an end-of-line marker. This index is an integer--the ordinal number of the current component or marker. A file's current component is the component that the next I/O operation on that file will input or output. Figure 3-3 illustrates the relationship between current position index and current component.
[]
Figure 3-3. Relationship Between Current Position Index and Current Component File Buffer Variables and Selectors Every logical file has a file buffer variable, or buffer, which is a variable of the same type as the file components. Some file operations assign the value of the current component to the buffer; other operations leave the buffer undefined. When the buffer is defined, you can access its value with its file buffer selector. The file buffer selector for the file f is f^ or f@. Accessing an undefined buffer causes an error.


MPE/iX 5.0 Documentation