HP 3000 Manuals

Closing Files [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation


HP Pascal/iX Programmer's Guide

Closing Files 

When your program closes a file, it breaks the association between the
logical file and the physical file; therefore, it cannot access the file
or file buffer variable.  It must reopen the file before attempting to
operate on it in any other way, or it is a run-time error.  One way to
close a file is with the predefined procedure close.  A call to close has
the following syntax and parameters.

Syntax 

     close (logical_file [, close_option])

Parameters 

logical_file  The name of the logical file to be closed.

close_option  A string or PAC expression whose value is one of the
              following:

              SAVE or LOCK    The file is saved permanently.

              TEMP or NORMAL  The file is saved temporarily.  What
                              happens to the temporary file when the
                              current session or job ends is
                              system-dependent.  For the MPE/iX operating
                              system, see Appendix A ; for HP-UX, see
                              Appendix B .

              CRUNCH          The effect of this option on the space
                              after the end-of-file marker is
                              system-dependent.  See Appendix A  
                              (MPE/iX) or Appendix B  (HP-UX).

              PURGE           The file is removed.

A program also closes a logical file and its associated physical file
when the program:

   *   Terminates.

   *   Exits the routine that declares the file, either because the
       routine ends, because it executes a goto statement that transfers
       control to a routine outside its scope, or it calls the predefined
       procedure escape because of a run-time error Chapter 11  
       explains escape).

   *   Reopens the file (in which case the file is closed before it is
       reopened).

Also, a program closes a file that is stored on the heap when it
deallocates the file's heap space by calling the predefined procedure
dispose or release with the appropriate parameter (see Chapter 6 ).

A program closes a pre-existing physical file (one that it did not
create) in the same state that it was in before the program opened it.
If a program creates a file, however, it can specify the state in which
the close procedure closes it.

Example 

     PROGRAM prog;

     LABEL
        9999;

     TYPE
        ftype = FILE OF integer;

     VAR
        f1 : ftype;

     PROCEDURE p;
     VAR
        f2 : ftype;
     BEGIN
        reset(f2);  {Opens f2}
        goto 9999;  {Closes f2 and f3}
     END;

     PROCEDURE q;
     VAR
        f3 : ftype;
     BEGIN
        open(f3);  {Opens f3}
        p;
        {p never returns here}
     END;

     BEGIN
        rewrite(f1);       {Opens f1}
        q;
        9999 : reset(f1);  {Closes and reopens f1}
        close(f1);         {Closes f1}
     END.



MPE/iX 5.0 Documentation