HP 3000 Manuals

Associate Procedure [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation


HP Pascal/iX Programmer's Guide

Associate Procedure 

The predefined procedure associate associates a logical file with an open
physical file, and puts the current position index at the first
component.

Syntax 

     associate (logical_file, file_number, open_options)

Parameters 

logical_file  The name of the logical file.

file_number   The file number of the open physical file.  The physical
              file must have been opened with a direct call to an
              operating system routine or a non-Pascal routine.  You
              cannot call the associate procedure with the file number of
              a closed file or a file that was opened with the Pascal
              procedure append, associate, open, reset, or rewrite.

open_options  One of the following options.  It must be a string literal:

              'READ'              Associate with sequential access file
                                  with read-only access.

              'WRITE'             Associate with sequential access file
                                  with write-only access.

              'READ,DIRECT'       Associate with direct access file with
                                  read-only access.

              'WRITE,DIRECT'      Associate with direct access file with
                                  write-only access.

              'READ,WRITE,DIRECT' Associate with direct access file with
                                  read-write access.

              'DIRECT'            Associate with direct access file with
                                  read-write access (same as 'READ,
                                  WRITE, DIRECT' ).

              'NOREWIND'          Associates with a file without changing
                                  the current file position.

              You must specify one of the above strings for open_options.
              The system-dependent open options listed in Appendix A  
              (for MPE/iX) and Appendix B  (for HP-UX) apply to the
              file-opening procedures append, open, reset, and rewrite.
              Pascal ignores them when they are used with associate.

You cannot specify read access if the physical file is not open for read
access, or to specify write access if it is not open for write access.
If you associate a logical file with an empty physical file, for read
access, the next read causes an error.

Table 3-3  summarizes the characteristics of the predefined procedure
associate.

          Table 3-3.  Characteristics of Associate Procedure 

---------------------------------------------------------------------------------------------
|                                             |                                             |
| Type of File That it Can Open               | Any.                                        |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| State in Which it Opens File                | Specified in open_options.                  |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Manner in Which File Can Be Accessed        | Either--Defined by characteristics of       |
|                                             | physical file.                              |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Purpose for Which it Opens File             | Input, output or both.                      |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Where it Puts Current Position Index        | Before first component.                     |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Value of eof for File *                     | False unless opened for write, in which     |
|                                             | case eof returns true despite possible old  |
|                                             | data after the current component.           |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Erases Old file Contents                    | No.                                         |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| File Buffer Variables *                     | First component for a textfile that is open |
|                                             | for reading; undefined otherwise.           |
|                                             |                                             |
---------------------------------------------------------------------------------------------

*    For a nonempty file.  For an empty file, every file-opening
     procedure puts the current position index before the [nonexistent]
     first component, eof returns true, and the file buffer variable is
     undefined.

If the physical file is not empty, the first reference to its file buffer
variable loads its file buffer with its first component.  If the physical
file is empty, the first reference to its file buffer variable causes an
error.

Figure 3-4  illustrates the effect of the associate procedure on the
open file whose file number is file_num:

Condition of file:

[]
After associate(examp_file,file_num,'READ'), the file is open in the read-only state and looks like this:
[]
Now examp_file is open in the read-only state. Figure 3-4. Effect of Associate Procedure on Open File Example 1 This example applies to HP Pascal on the MPE/iX operating system only. For a description of the MPE/iX intrinsic FOPEN, refer to the MPE/iX Intrinsics Reference Manual. PROGRAM test; TYPE pac100 = PACKED ARRAY [1..100] OF char; VAR f : FILE OF integer; {f is not a textfile} buffer : pac100; name : pac100; fnum : integer; j : integer; e,g,h : text; FUNCTION FOPEN : shortint; INTRINSIC; {MPE/&XL; file-opening intrinsic} BEGIN fnum := FOPEN(,0,octal('44'),-4); {open direct access read-write temp. file} associate(f,fnum,'READ,WRITE,DIRECT'); {associate with file for read-write direct access} writedir(f,3,5); readdir(f,3,j); rewrite(e,'UDC'); {create file 'UDC'} writeln('This is a test'); close(e,'SAVE'); {close file 'UDC'} name := 'UDC'; fnum := FOPEN(name,octal('40')); {open 'UDC' for sequential read access} associate(g,fnum,'READ'); {associate with 'UDC' for seq. read access} read(g,buffer); fnum := FOPEN(,4,octal('101')); {open write access sequential temp. file} associate(h,fnum,'WRITE'); {associate for sequential write access} writeln(h,'This is a test'); END. Example 2 This example applies to HP Pascal on the HP-UX operating system only. For descriptions of the HP-UX routines tmpnam and open, refer to the HP-UX Reference manual. PROGRAM test; TYPE pac100 = PACKED ARRAY [1..100] OF char; VAR f : FILE OF integer; {f is not a textfile} buffer : pac100; name : pac100; mode : integer; fnum : integer; j : integer; e,g,h : text; option : integer; {External HP-UX routine that returns a unique file name} PROCEDURE tmpnam (VAR fpathname : pac100); EXTERNAL; {External HP-UX routine that opens a file} FUNCTION file_open $ALIAS 'open'$ {use alias to avoid conflict w/Pascal open} (VAR fpathname : pac100; foption : integer; mode : integer) : integer; EXTERNAL; BEGIN tmpnam(name); {get unique name for temporary file} mode := octal('666'); {read-write access for file} option := octal('402'); {specify read-write access} fnum := file_open(name,option,mode); {open the file} associate(f,fnum,'READ,WRITE,DIRECT');{associate with file for read-write direct access} writedir(f,3,5); readdir(f,3,j); rewrite(e,'UDC'); {create text file 'UDC'} writeln('This is a test'); {write to file} close(e,'SAVE'); {close text file 'UDC'} name := 'UDC'#0; {open the same file through HP-UX} mode := octal('666'); fnum := file_open(name,0,mode); associate(g,fnum,'READ'); {associate with 'UDC' for seq. read access} read(g,buffer); tmpnam(name); {open text file through HP-UX} mode := octal('666'); option := octal('401'); {specify write access} fnum := file_open(name,option,mode); associate(h,fnum,'WRITE'); {associate for sequential write access} writeln(h,'This is a test'); END.


MPE/iX 5.0 Documentation