HPlogo Accessing Files Programmer's Guide > Chapter 6 Closing a File

Closing a Disk File

MPE documents

Complete PDF
Table of Contents
Index

E0300 Edition 6 ♥
E0692 Edition 5

The following examples show how you use the FCLOSE intrinsic to close a disk file:
  • "Closing a New Disk File as Permanent" shows an example of an FCLOSE call that closes the file opened in Example 5-1.

  • "Closing a Permanent Disk File" shows an example of an FCLOSE call that closes the file opened in Example 5-2.

Closing a new disk file as permanent


Example 6-1 is an HP Pascal/XL code segment containing an HPFOPEN call that opens a new file, and an FCLOSE intrinsic call that changes the disposition of the file to permanent prior to closing it. (Refer to Example 5-1 for details on this HPFOPEN call.)

In Example 6-1, there is a disposition conflict between the FCLOSE call and the HPFOPEN call that opened the file identified by file_num:
  • The disposition parameter of FCLOSE specifies that the file is to be closed as a permanent file.

  • The final disposition option of the HPFOPEN call specifies that the file should be closed as a temporary file.

The disposition parameter of FCLOSE takes precedence over the final disposition option of HPFOPEN because the integer value of FCLOSE's disposition (1) is a smaller positive value than that of HPFOPEN's final disposition option (2).

Example 6-1. Closing a New Disk File as Permanent

  .
  .
  .
  save_temp := 2;
  HPFOPEN(file_num, status,
     formal_designator_option, file_name, {formaldesignator option}
     record_size_option, line_len,        {record size option}
     final_disp_option, save_temp,        {final disp option}
     ASCII_binary_option, ascii           {ASCII/binary option}
         );
  .
  .
  .
  error         := 1;
  disposition   := 1;    {close file as a permanent file          }
  security_code := 0;    {No additional restrictions              }

  FCLOSE ( file_num,     {file_num returned by HPFOPEN            }
           disposition,  {close file with permanent disposition   }
           security_code {no additional restrictions are added    }
         );

  if ccode = error then handle_file_error (file_num, 0)
  .
  .
  .

If the file could not be closed because an incorrect file_num was specified, or another file of the same name and disposition already exists, ccode returns a value of one, thus invoking the error-handling procedure handle_file_error.

In Appendix A, "Pascal/XL Program Examples," Example A-1 uses a similar procedure to close a new disk file. For more information about FCLOSE parameters, refer to the MPE/iX Intrinsics Reference Manual.

Closing a permanent disk file


Example 6-2 closes the permanent file opened in Example 5-2. (Refer to Example 5-2 for details on this HPFOPEN call.) The disposition of the file is not changed when it is closed. The file remains a permanent disk file.

Example 6-2. Closing a Permanent Disk File

  .
  .
  .
  HPFOPEN(file_num, status,
     formal_designator_option, file_name,  {formaldesignator option}
     domain_option, permanent,             {domain option     }
     access_type_option, update,           {access type option}
     dynamic_locking_option, lockable,     {dynamic locking option}
     exclusive_option, shared              {exclusive option }
     ASCII_binary_option, ascii            {ASCII/binary option}
     );
  .
  .
  .
  error         := 1;
  disposition   := 0;    {no change to disposition                }
  security_code := 0;    {No additional restrictions              }

  FCLOSE ( file_num,     {file_num returned by HPFOPEN            }
           disposition,  {don't change prior disposition          }
           security_code {no additional restrictions are added    }
         );

  if ccode = error then handle_file_error (file_num, 0)
  .
  .
  .

If the file could not be closed because an incorrect file_num was specified, or another file of the same name and disposition already exists, ccode returns a value of one, thus invoking the error-handling procedure handle_file_error.

In Appendix A, "Pascal/XL Program Examples," Example A-5 uses a similar procedure to close a permanent disk file. For more information about FCLOSE parameters, refer to the MPE/iX Intrinsics Reference Manual.




How the File System Closes a File


Closing a Magnetic Tape File