HPlogo Accessing Files Programmer's Guide > Chapter 9 Reading from a File

Reading From a Magnetic Tape File

MPE documents

Complete PDF
Table of Contents
Index

E0300 Edition 6 ♥
E0692 Edition 5

Example 9-4 is an HP Pascal/iX code segment that reads records sequentially from an unlabeled magnetic tape file (indicated by variable tape_file_num) and uses FWRITE to write them to a disk file (indicated by variable disk_file_num). The operation is performed in a loop. The loop ends when the FREAD intrinsic encounters an EOF marker on the tape (indicating the end of the tape file).

Example 9-4. Reading From a Magnetic Tape File

  procedure copy_tape_to_disk_file;

  var
     record          : packed array [1..30] of char; {declare record}
     end_of_file     : boolean;              {declare exit condition}
     record_length   : shortint;                {size of record read}
     length          : shortint;                  {declare parameter}
     control_code    : 0..65535;                  {declare parameter}

  begin
     end_of_file := false;                {initialize exit condition}
     control_code := 0;                       {initialize to default}
     length := -80;                     {size of record to be copied}

     repeat                               {loop until exit condition}

        record_length := FREAD (tape_file_num, record, length);
        if ccode = ccl then
           handle_file_error (tape_file, 3)
        else
           if ccode = ccg then             {FREAD returns ccg if EOF}
              end_of_file := true        {exit condition encountered}
           else begin
              FWRITE( disk_file_num,   {identity returned by HPFOPEN}
                      record,               {read from tape_file_num}
                      record_length,        {actual size of record  }
                      control_code          {default                }
                    );
              if ccode <> cce then   {check condition code for error}
              handle_file_error (disk_file, 5);
           end

     until end_of_file;
  end;                                                {end procedure}

If an error is encountered by either FREAD or FWRITE, procedure handle_file_error is invoked. For more information about FREAD intrinsic parameters, refer to the MPE/iX Intrinsics Reference Manual. For more information about the FWRITE intrinsic, refer to chapter 8, "Writing to a File". In appendix A, "HP Pascal/iX Program Examples", example A-1 uses a similar procedure to copy records from a tape file to a disk file.




Reading From $STDIN


Reading a File Label from a Labeled Tape File