home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug175.arc / JRTMAN2.LBR / JRTMAN.0Z7 / JRTMAN.007
Text File  |  1979-12-31  |  78KB  |  2,432 lines

  1. .OP
  2.  
  3.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -73-
  4.  
  5.  
  6.  
  7.       7.    Input/output
  8.  
  9.            JRT  Pascal includes a powerful input/output subsystem which can
  10.       be used to meet virtually any processing requirement.  Three modes of
  11.       input/output - console, sequential disk, random disk - are provided.
  12.  
  13.            Disk files can be processed in either TEXT  mode  or  in  BINARY
  14.       mode.   TEXT  mode is most commonly used by BASIC languages.  Data is
  15.       stored in ASCII text readable format.  BINARY mode is found on larger
  16.       mini and mainframe computers.  The data is input/output in the binary
  17.       format used internally by the language.  Not only is  the  data  more
  18.       compact  in  some cases but it is also of fixed length.  For example,
  19.       an integer in text format could occupy from two bytes to  six  bytes,
  20.       depending  on  its  value.  But in binary format an integer is always
  21.       exactly two bytes.
  22.  
  23.            TEXT mode is sometimes called  "stream  I/O".   BINARY  mode  is
  24.       sometimes called "record I/O".
  25.  
  26.            Another  advantage of binary format is that the user can process
  27.       data files or COM files containing special control characters.
  28.  
  29.            All files in JRT Pascal are "untyped". That  is,  the  user  can
  30.       read  and  write  data of any format to any file.  The user can write
  31.       records of entirely different formats and sizes on the same file.
  32.  
  33.            JRT  Pascal  also  supports  direct  access  to   the   hardware
  34.       input/output  ports  without  having  to  write  an assembly language
  35.       subroutine.   The  builtin  function  PORTIN  and  builtin  procedure
  36.       PORTOUT  are  described  in  the  sections  on  builtin functions and
  37.       builtin procedures.
  38.  
  39.            JRT Pascal version 3 now supports Pascal file  variables.  Files
  40.       may  now  be passed as parameters to procedures, allocated locally in
  41.       procedures, be used in records  or  arrays,  be  used  in  assignment
  42.       statements.  The  Pascal  builtin  procedures  GET  and  PUT  are now
  43.       supported.
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  56. .PAè
  57.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -74-
  58.  
  59.  
  60.  
  61.       7.1   Console input/output
  62.  
  63.            Console input/output  is  the  usual  means  for  a  program  to
  64.       interact  with  the  user.   Data  values can be displayed at a video
  65.       terminal or teletype and data can be keyed in.
  66.  
  67.            Console input/output always occurs in text  rather  than  binary
  68.       format. Integers, real numbers, strings, characters and Booleans will
  69.       be  displayed  in text format.  Set variables have no meaningful text
  70.       format and cannot be written to the console.
  71.  
  72.            IMPORTANT - Since the console is regarded as a text device, data
  73.       items are delimited by commas, spaces, tabs and semicolons.  To  read
  74.       one character at a time, use this function:
  75.               FUNCTION GET_CHAR : CHAR;
  76.               VAR R : RECORD
  77.                       FLAG,A,C,D,E,D,L,H : CHAR;
  78.                       END;
  79.               BEGIN
  80.               R.C := CHR(1);
  81.               CALL( 5,R,R );
  82.               GET_CHAR := R.A
  83.               END;
  84.  
  85.  
  86.            Using  the  HEX$ builtin function, any variable can be converted
  87.       to hex format for direct display.  On  console  input  for  integers,
  88.       data  may be keyed in using standard decimal format or in hex format.
  89.       An 'H' character suffix indicates hex format.
  90.  
  91.            On input to the console, data items may be separated by  spaces,
  92.       tabs,  commas or semicolons.  Character or structured variable inputs
  93.       which contain special characters may be  entered  in  single  quotes.
  94.       The quote character itself may be entered by doubling it.
  95.  
  96.             Sample input lines:
  97.  
  98.                   3.14159,77
  99.                   03ch,'JRT Systems'
  100.                   'don''t say you can''t'
  101.                   6.70234e-25,0.0000003
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  110. .PAè
  111.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -75-
  112.  
  113.  
  114.  
  115.            Reading  from  the  console  into  a  dynamic string variable is
  116.       treated differently.  An entire line of text  is  obtained  from  the
  117.       console  and  moved  directly  into  the  string variable.  Separator
  118.       characters and single quotes are ignored.  The system will not  allow
  119.       more  characters to be keyed in than can fit into the variable in the
  120.       READ's parameter list.
  121.  
  122.            Console output can also be routed to the printer or list device.
  123.       The SYSTEM procedure is fully described in  the  section  on  builtin
  124.       procedures. Some of its options are:
  125.  
  126.                   SYSTEM( LIST );         route output to printer
  127.                   SYSTEM( NOLIST );       do not route to printer
  128.                   SYSTEM( CONS );         route to console device
  129.                   SYSTEM( NOCONS );       do not route to console
  130.            The  builtin  procedures/functions  used in console input/output
  131.       are:
  132.  
  133.                   READ, READLN            read data into storage
  134.                   WRITE, WRITELN          write data to console/printer
  135.                   EOLN                    end of line function
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  164. .PAè
  165.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -76-
  166.  
  167.  
  168.  
  169.       7.2   Sequential file processing
  170.  
  171.            Disk files are not inherently sequential or random.  Those terms
  172.       apply to the means of access which may be applied to any disk file.
  173.  
  174.            Sequential file  processing  is  generally  faster  than  random
  175.       access  because  input/output  can  be  buffered and because the disk
  176.       positioning mechanism only needs to move short distances.
  177.  
  178.            JRT Pascal lets the user  obtain  maximum  processing  speed  by
  179.       defining  the  buffer  size  for sequential files.  The buffer is the
  180.       holding area where disk data is loaded and  written.   This  area  is
  181.       filled  or  emptied in one burst - one disk access with one head load
  182.       operation. A very small buffer may  cause  disk  "chattering"  during
  183.       processing  because of frequent accesses.  A large buffer will result
  184.       in less frequent but longer disk accesses.
  185.  
  186.            The buffer size is specified as an  integer  expression  in  the
  187.       RESET  or  REWRITE procedure.  It will be rounded up to a multiple of
  188.       128.  If storage is plentiful, buffers of 4096  or  8192  bytes  will
  189.       improve processing.
  190.  
  191.            The  builtin  procedures/functions  used in sequential disk file
  192.       processing are
  193.  
  194.                   RESET             open file for input
  195.                   REWRITE           open file for output
  196.                   CLOSE             terminate file processing
  197.                   READ, READLN      read data into storage
  198.                   WRITE, WRITELN    write data to disk
  199.                   EOF               end of file function
  200.                   EOLN              end of line function
  201.                   ERASE             delete a file
  202.                   RENAME            rename a file
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  218. .PAè
  219.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -77-
  220.  
  221.  
  222.  
  223.            This sample program reads in a file and dumps it in  hex  format
  224.       to the console:
  225.  
  226.                   PROGRAM DUMP;
  227.  
  228.                   TYPE BLOCK = ARRAY [1..16] OF CHAR;
  229.                         NAME = ARRAY [1..14] OF CHAR;
  230.  
  231.                   VAR
  232.                   B : BLOCK;
  233.                   DUMP_FILE : FILE OF BLOCK;
  234.                   FILENAME : NAME;
  235.  
  236.                   BEGIN
  237.                   WHILE TRUE DO     (* INFINITE LOOP *)
  238.                         BEGIN
  239.                         WRITE('enter filename : ');
  240.                         READLN( FILENAME );
  241.                         RESET( DUMP_FILE, FILENAME,
  242.                               BINARY, 4096);
  243.                         WHILE NOT EOF( DUMP_FILE ) DO 
  244.                               BEGIN
  245.                               READ( DUMP_FILE; B);
  246.                               WRITELN( HEX$(B) );
  247.                               END;
  248.                         CLOSE( DUMP_FILE );
  249.                         WRITELN;
  250.                         END;
  251.                   END.
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  272. .PAè
  273.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -78-
  274.  
  275.  
  276.  
  277.       7.3   Random file processing
  278.  
  279.            CP/M  version 2.2 or higher is required to use JRT Pascal random
  280.       file processing.
  281.  
  282.            For many types of processing it is not known in advance in which
  283.       sequence the records of a file will be needed.  A spelling dictionary
  284.       or online inquiry customer database obviously must use random  access
  285.       files.
  286.  
  287.            In  JRT  Pascal,  random access is fully supported.  Data can be
  288.       read and updated by providing the relative record number (RRN) within
  289.       the file for fixed length records.  The first  record  is  at  RRN=0.
  290.       For  variable  length  records,  the  data  can be read or updated by
  291.       providing the relative byte address (RBA).  The RBA is  the  location
  292.       of the data item within the file.  The first byte is at RBA=0.
  293.  
  294.            The  RBA  mode of processing gives much greater flexibility than
  295.       RRN.  If all records had to be the same size, then all would have  to
  296.       be the size of the largest, resulting in much wasted space and slower
  297.       access.
  298.  
  299.            Beginning  with  JRT  Pascal version 2.1, random files up to the
  300.       CP/M maximum of 8 megabytes are supported. The RBA or RRN  value  may
  301.       be  an  integer  or a real expression. Programs written under earlier
  302.       versions are source code compatible but must be recompiled using  the
  303.       version 2.1 or later compiler.
  304.  
  305.            The procedures used in random file processing are:
  306.  
  307.                       OPEN            open or create random file
  308.                       CLOSE           terminate file processing
  309.                       READ            read data into storage
  310.                       WRITE           transfer data to disk
  311.                       ERASE           delete a file
  312.                       RENAME          rename a file
  313.  
  314.            A  sample program shows random access to a file containing sales
  315.       information for the  various  departments  of  a  retail  store.  The
  316.       records are located by department number.
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  326. .PAè
  327.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -79-
  328.  
  329.  
  330.  
  331.       Sample program:
  332.  
  333.  
  334.               PROGRAM INQUIRY;
  335.  
  336.               LABEL 10;
  337.  
  338.               TYPE
  339.               DEPT_RECORD = RECORD
  340.                       INVENTORY       : REAL;
  341.                       MTD_SALES       : REAL;
  342.                       YTD_SALES       : REAL;
  343.                       DISCOUNT        : REAL;
  344.                       END;
  345.  
  346.               VAR
  347.               INPUT_AREA      : DEPT_RECORD;
  348.               DEPT_FILE       : FILE OF DEPT_RECORD;
  349.               DEPT            : INTEGER;
  350.  
  351.               BEGIN   (* INQUIRY *)
  352.               OPEN( DEPT_FILE, 'C:DEPTDATA.RND', BINARY );
  353.  
  354.               REPEAT
  355.                 WRITE('Enter dept number : ');
  356.                 READLN( DEPT );
  357.                 IF DEPT = 999 THEN GOTO 10;   (* EXIT *)
  358.                 READ( DEPT_FILE, RRN, DEPT;
  359.                       INPUT_AREA );
  360.                 WRITELN;
  361.                 WRITELN('dept ',DEPT,
  362.                       '   inv ',INPUT_AREA.INVENTORY:9:2,
  363.                       '   disc ',INPUT_AREA.DISCOUNT:9:2);
  364.                 WRITELN('   MTD sales',MTD_SALES:9:2,
  365.                       '   YTD sales',YTD_SALES:9:2);
  366.                 WRITELN;
  367.               10:     (* EXIT LABEL *)
  368.               UNTIL DEPT = 999;
  369.  
  370.               CLOSE( DEPT_FILE );
  371.               END     (* INQUIRY *).
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  380. .PAè
  381.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -80-
  382.  
  383.  
  384.  
  385.       7.4   Indexed file processing
  386.  
  387.  
  388.            CP/M version 2.2 or higher is required to use JRT Pascal indexed
  389.       file processing.
  390.  
  391.            Beginning with version 3.0, JRT Pascal provides full support for
  392.       indexed  files.   The  index file system is implemented as 2 external
  393.       procedures so that it occupies no main storage when it is  not  being
  394.       used.
  395.  
  396.            Indexed  files consist of two separate disk files: the main data
  397.       file with a filetype of DAT and an index file with  the  filetype  of
  398.       IX0.
  399.  
  400.            The  indexed  file  system  has  3  components.  INDEX0 external
  401.       procedure performs most of the functions. INDEX1  external  procedure
  402.       compresses  the  data  files  and rebalances the indexes.  The INDEX2
  403.       program is executed by itself and  reorganizes  the  files  for  more
  404.       efficient access.
  405.  
  406.            The external procedure INDEX0 performs these operations:
  407.  
  408.               A       add a new record
  409.               B       read first record (beginning)
  410.               C       close file
  411.               D       delete a record
  412.               F       flush buffers, close and reopen files
  413.               N       new file allocation
  414.               O       open file
  415.               Q       query whether indexes should be balanced
  416.               R       read a record
  417.               S       read next record in sequence
  418.               U       update a record
  419.               W       issue a warning
  420.               Z       turn off warning message
  421.  
  422.           INDEX1 performs these operations:
  423.  
  424.               J       rebalance the indexes
  425.               K       compress data file and balance indexes
  426.  
  427.            Records must all be the same size - from 16 to 2048 bytes.  They
  428.       need  not  be  a multiple of 128 bytes. The maximum number of records
  429.       depends on the key size:
  430.  
  431.  
  432.  
  433.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  434. .PAè
  435.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -81-
  436.  
  437.  
  438.  
  439.               (1024 DIV (KEY_SIZE +3)) * 256
  440.  
  441.               key size        max records
  442.               ________        ___________
  443.                  4              32767  <---   Not more than 32767
  444.                  6              28928         records ever allowed
  445.                  8              23808
  446.                 15              14336
  447.  
  448.            The maximum number of records should be  set  to  somewhat  less
  449.       than  the  maximum theoretical number of records, to prevent the loss
  450.       of a record when adding to an unbalanced file.  Note  also  that  the
  451.       file  of  indexes will be 257k when the maximum number of records are
  452.       entered, so a reasonable (high)  estimate  should  be  used  for  the
  453.       maximum number of records.
  454.  
  455.            IMPORTANT  -  No key should contain all zeroes, since a zero key
  456.       is used to indicate deleted keys and records.
  457.  
  458.            The key must be the first field in each record.   The  key  size
  459.       may be from 2 to 32 bytes.
  460.  
  461.            A utility program INDEX2 is provided to reorganize the data file
  462.       and generate new index files.
  463.  
  464.  
  465.       7.4.1  Index file format
  466.  
  467.            The  index  file is divided into one primary index and up to 256
  468.       secondary indexes.  Each index block is 1024 bytes.
  469.  
  470.            The primary index contains 256 4-byte fields.  Each of these  is
  471.       the first 4 bytes of the lowest key in a secondary index.
  472.  
  473.            The  secondary  indexes  contain  actual  key  values and 3-byte
  474.       record loacator fields.  The number of keys per secondary index is:
  475.  
  476.               1024 DIV (KEY_SIZE +3)
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  488. .PAè
  489.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -82-
  490.  
  491.  
  492.  
  493.       7.4.2  Data file format
  494.  
  495.            The data file consists of a 1024 byte control record followed by
  496.       the data records.
  497.  
  498.            The control record contains the filename, maximum record  count,
  499.       current  record  count,  key  size,  record  size,  delete count, and
  500.       deleted record list.
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  542. .PAè
  543.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -83-
  544.  
  545.  
  546.  
  547.                               Index file format
  548.  
  549.                               !-------------------------------!
  550.                               !                               !
  551.               1 K blocks      !    primary index              !
  552.                               !-------------------------------!
  553.                               !                               !
  554.                               !                               !
  555.                               !----- up to 256        --------!
  556.                               !                               !
  557.                               !      secondary indexes        !
  558.                               !-----                  --------!
  559.                               !                               !
  560.                               !                               !
  561.                               !-------------------------------!
  562.  
  563.  
  564.  
  565.                               Data file format
  566.  
  567.                               !-------------------------------!
  568.                               !                               !
  569.                               !   control record  1 K         !
  570.                               !-------------------------------!
  571.                               !                               !
  572.                               !                               !
  573.                               !                               !
  574.                               !                               !
  575.                               !   data records                !
  576.                               !                               !
  577.                               !                               !
  578.                               !                               !
  579.                               !                               !
  580.                               !                               !
  581.                               !                               !
  582.                               !                               !
  583.                               !                               !
  584.                               !                               !
  585.                               !                               !
  586.                               !                               !
  587.                               !-------------------------------!
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  596. .PAè
  597.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -84-
  598.  
  599.  
  600.  
  601.       7.4.3  Using INDEX0
  602.  
  603.            The indexed file system is implemented in an external  procedure
  604.       named  INDEX0.  To access it, these declarations are required in your
  605.       main program:
  606.  
  607.               TYPE
  608.               KEY_TYPE =  -------------- { your key type declarations }
  609.               RECORD_TYPE =  ----------- { your record type declarations }
  610.               INDEX_RECORD = RECORD
  611.                       DISK : CHAR;
  612.                       FILENAME : ARRAY [1..8] OF CHAR;
  613.                       RETURN_CODE : INTEGER;
  614.                       RESERVED : ARRAY [1..200] OF CHAR;
  615.                       END;
  616.  
  617.               PROCEDURE INDEX0 ( COMMAND : CHAR;
  618.                                 VAR KEY : KEY_TYPE;
  619.                                 VAR DATA : RECORD_TYPE;
  620.                                 VAR IR : INDEX_RECORD ); EXTERN;
  621.  
  622.            To use INDEX0 the index_record  must  be  initialized  with  the
  623.       filename  and  disk  on which the file is located. The return code is
  624.       set by INDEX0  and  indicates  if  each  operation  was  successfully
  625.       completed.   Warning  messages  may optionally be issued, see command
  626.       'W'.
  627.  
  628.            An indexed file must be allocated before it  can  be  opened  or
  629.       used in any way.
  630.  
  631.            Each time INDEX0 is called, a valid command code must be passed.
  632.       The  key, data, and ir parameters are also required, although key and
  633.       data will not be used by every command.
  634.  
  635.            It is allowed to have multiple indexed files open  at  the  same
  636.       time.  Each one is indentified by a different index_record.
  637.  
  638.            The  index record (IR) should be set to blanks before individual
  639.       fields are initialized.  For a given index file, the  first  call  to
  640.       INDEX0 in a program should be to open ('O') or create ('N') the index
  641.       and  data  files.  (INDEX0  can be called with the 'W' first, so that
  642.       error messages will be printed.)
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  650. .PAè
  651.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -85-
  652.  
  653.  
  654.  
  655.       7.4.4  INDEX commands
  656.  
  657.            Commands J and K  are  processed  by  INDEX1.   All  others  are
  658.       processed by INDEX0.
  659.  
  660.       A       add a new record
  661.                       - insert a new key into index, if duplicate key
  662.                         exists, abort operation
  663.                       - write new data record to data file
  664.  
  665.       B       read first record (begin)
  666.                       - read the first record (in sorted order)
  667.                       - returns key and record
  668.  
  669.       C       close indexed files
  670.                       - this MUST be done on completion of processing
  671.                         or newly written data may be lost
  672.  
  673.       D       delete a record
  674.                       - nullify key entry for record
  675.                       - add record locator to delete list
  676.  
  677.       F       flush buffers, close and reopen files
  678.                       - flush buffers that have changed
  679.                       - close files to preserve changes
  680.  
  681.       J       rebalance indexes (INDEX1)
  682.                       - uses temporary file
  683.                       - deletes old index file
  684.                       - renames new index file
  685.  
  686.       K       rebalance indexes and compact data file (INDEX1)
  687.                       - uses temporary files
  688.                       - deletes old index and data files
  689.                       - renames new index and data files
  690.                       - reopen files for further processing
  691.  
  692.       N       new file allocation
  693.                       - program will inquire at the console the
  694.                         parameters of the new indexed file
  695.                               1. record size in bytes
  696.                               2. key size in bytes
  697.                               3. maximum number of records to be
  698.                                  allowed; the index file will be
  699.                                  allocated based on this number
  700.  
  701.  
  702.  
  703.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  704. .PAè
  705.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -86-
  706.  
  707.  
  708.  
  709.                       - index files are left open for
  710.                         further processing
  711.                       - files must be closed (or flushed)
  712.                         to preserve the new contents
  713.  
  714.       O       open indexed files
  715.                       - open the index and data files
  716.                       - load the primary index into dynamic
  717.                         storage
  718.  
  719.       Q       query data base status
  720.                       - return 'Y' in key[1] if the data
  721.                         base should be reorganized ('J')
  722.                       - else return 'N' in key[1]
  723.  
  724.       R       read a record
  725.                       - search the indexes for the key
  726.                       - read the data record into the 
  727.                         user's record variable
  728.  
  729.       S       read next record in sequence
  730.                       - will read next record after a
  731.                         previous 'B', 'R', 'S', or 'U'
  732.  
  733.       U       update a record
  734.                       - the update operation MUST ALWAYS be
  735.                         preceded by a read operation with the
  736.                         same key
  737.                       - write modified record to data file
  738.  
  739.       W       warning messages
  740.                       - turn on the warning message feature
  741.                       - caused non-zero return codes to print
  742.                         verbal error messages
  743.  
  744.       Z       turn off warning messages
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  758. .PAè
  759.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -87-
  760.  
  761.  
  762.  
  763.       7.4.5  INDEX return codes
  764.  
  765.  
  766.       0       successful completion
  767.  
  768.       1       duplicate key
  769.  
  770.       2       maximum number of records exceeded
  771.  
  772.       3       key not found
  773.  
  774.       4       update key does not match read key or
  775.               previous read was not successful
  776.  
  777.       5       key value does not match key in record
  778.  
  779.       6       second open or new without closing previous
  780.               file
  781.  
  782.       7       invalid command (eg. 'M' or an 'S' without
  783.               a preceeding 'B', 'R', 'S', or 'U')
  784.  
  785.       8       file not open
  786.  
  787.       9       serious error ( no specific message )
  788.  
  789.  
  790.       7.4.6  Balanced indexes
  791.  
  792.            Searching  for records is usually very efficient, both in random
  793.       and sequential modes. Adding to a  data  base  is  usually  efficient
  794.       until one or more of the secondary indexes gets full. (If records are
  795.       added  in  sorted  order,  then  the  addition  process  will be very
  796.       efficient.) INDEX0 will not automatically "balance" keys in the index
  797.       files, so that additions fill up the secondary indexes.
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  812. .PAè
  813.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -88-
  814.  
  815.  
  816.  
  817.            Your program can "Query" the status of an indexed file by  using
  818.       'Q'  in a call to the index.  The first letter of the key will be set
  819.       to 'Y' if the indexes should be balanced, and  'N'  if  that  is  not
  820.       necessary  yet.   (INDEX0 decides that the indexes should be balanced
  821.       when an add ('A') must move a  secondary  index  from  one  block  to
  822.       another).
  823.  
  824.     Reorganizing indexes
  825.  
  826.            To reorganize an indexed file so that adding new records will be
  827.       efficient, set the record argument to all blanks and call INDEX1 with
  828.       command  'J'  (for  adJust  or  Justify).   INDEX1  will create a new
  829.       balanced index file on the same  disk  as  the  current  index  file.
  830.       There  must  be  space  for  the new index file, which will be called
  831.       name.$$I.  INDEX1 will then delete the old .IX0 file and  rename  the
  832.       new  file  to  name.IX0.   Reorganization takes 2500 to 3200 bytes of
  833.       space in main memory as well as space on the disk,  so  it  is  never
  834.       done automatically.  INDEX1 must be declared as an external procedure
  835.       (just  as  INDEX0  was  declared) if your program is going to balance
  836.       indexes "on the fly".
  837.  
  838.               PROCEDURE INDEX1 ( COMMAND : CHAR;
  839.                                 VAR KEY : KEY_TYPE;
  840.                                 VAR DATA : RECORD_TYPE;
  841.                                 VAR IR : INDEX_RECORD ); EXTERN;
  842.  
  843.            INDEX1 supports the J and K operations which  are  described  in
  844.       section 7.4.4.
  845.  
  846.            In  general,  the  record  variable  should be set to all blanks
  847.       before INDEX1 is called.
  848.  
  849.  
  850.       7.4.7  INDEX2 utility
  851.  
  852.            Type EXEC INDEX2 to rebalance the indexes in  the  file  and  to
  853.       compact  the data after many deletions.  INDEX2 will ask for the name
  854.       of the disk drive containing the indexed files (A to P), the name  of
  855.       index  files  (which  you  would  enter  without any '.' or '.DAT' or
  856.       '.IX0'), and the name of the compacted files.  You can have  the  new
  857.       files put on the same or another disk drive as the original files.
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  866. .PAè
  867.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -89-
  868.  
  869.  
  870.  
  871.            INDEX2  will  also  ask for a new number of maximum records.  If
  872.       you enter 0, the previous maximum will be used.
  873.  
  874.  
  875.     Compressing data from within a program
  876.  
  877.            INDEX2 uses INDEX0 and INDEX1 to perform the actual indexed file
  878.       accesses.  Highly sophisticated  programs  can  also  use  INDEX1  to
  879.       compact  the  data  file  as well as balance the indexes. Call INDEX1
  880.       with the command 'K' (kompress) to do a complete reorganization.   If
  881.       the  record  argument  is set to all blanks, then the same disk drive
  882.       and same maximum record count will be used in creating the  new  data
  883.       base   copies.   If  the  record  argument  is  given  the  following
  884.       structure, then alternate disk drives or a different  maximum  number
  885.       of records can be set.
  886.  
  887.             VAR
  888.                   new_param : RECORD
  889.                         new_disk_flag : CHAR;
  890.                         new_disk : CHAR;
  891.                         max_nr_flag : CHAR;
  892.                         max_nr_rec : INTEGER;
  893.                         old_leave : CHAR;
  894.                         END;
  895.  
  896.            Set   new_param.new_disk_flag   to   'Y'  if  new_param.new_disk
  897.       contains  another   disk   drive   letter   (such   as   'C').    Set
  898.       new_param.max_nr_flag  to  'Y' if new_param.max_nr_rec contains a new
  899.       maximum number of records, such as 2000.
  900.  
  901.            The new_disk_flag only works with the 'K' option.  The old_leave
  902.       flag only works with the 'K' option when a new_disk is specified.
  903.  
  904.            When the 'K' option is used,  the  record  passed  must  be  big
  905.       enough  to hold records read from the disk.  You might want to assign
  906.       rec to contain new_param, and then call INDEX1, for example
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  920. .PAè
  921.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -90-
  922.  
  923.  
  924.  
  925.             rec := new_param;
  926.             INDEX1 ('K',key, rec, ir);
  927.  
  928.            Most programs will not need to use the  'K'  option,  since  the
  929.       equivalent  can  be  done as needed by having the user issue the CP/M
  930.       command EXEC INDEX2, preferably after the data bases have been copied
  931.       to backup disks.
  932.  
  933.  
  934.  
  935.       7.4.8  Efficiency notes
  936.  
  937.  
  938.            Reading records from the data base is only slow when  very  many
  939.       keys  have  the  same  first four characters.  If the indexes in more
  940.       than one secondary index block have the same first  four  characters,
  941.       INDEX0 may have to search more than one secondary index block to find
  942.       a given record. Generally, this will not occur.
  943.  
  944.            Random  output  in  general  under  CP/M  is  inefficient due to
  945.       buffering requirements.  Random output will be  most  efficient  with
  946.       double density disks with 1K blocks or with single density disks with
  947.       128 blocks.
  948.  
  949.  
  950.     Maximum number of records
  951.  
  952.            The  maximum  number of records should be set to somewhat (50 to
  953.       200) less than the theoretical maximum.  If, for example, 8-byte keys
  954.       are declared with up to 23808 records, 256 records are  entered,  the
  955.       indexes  are  balanced  (with  'J').  There will now be 256 secondary
  956.       indexes blocks with one key each.  Then, if 92 records are added with
  957.       key greater than the 256th record, the last secondary index  will  be
  958.       full.   Since  one  secondary  index  block  can hold 93 8-byte keys,
  959.       adding a 93rd key larger than  the  256th  will  "overflow"  the  top
  960.       secondary index block. A serious error.
  961.  
  962.            Currently,  the  maximum  number  of  records is 32767 for index
  963.       files with 2-, 3-, and 4-byte keys.
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  974. .PAè
  975.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -91-
  976.  
  977.  
  978.  
  979.       7.4.9  Sample indexed file program
  980.  
  981.  
  982.            The following simple program will let you create, add to, query,
  983.       close, and search any data base.  It assumes that the record and  the
  984.       key   are   alphanumeric  (printable)  information.   You  can  enter
  985.       individual commands to  the  program,  which  will  call  INDEX0  (or
  986.       INDEX1)  to perform the equivalent command.  The runtime example that
  987.       follows the listing of  TSTINDEX  shows  the  creation  of  a  simple
  988.       address  file, with 16 character search keys and (one line) addresses
  989.       up to 80 characters long.  The resulting records are  then  96  bytes
  990.       long.
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1028. .PAè
  1029.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -92-
  1030.  
  1031.  
  1032.  
  1033.       PROGRAM tstindex;
  1034.  
  1035.       TYPE
  1036.             key_t = ARRAY[1..256] of CHAR;
  1037.             rec_t = ARRAY[1..2048] of CHAR;
  1038.             ctrl_rec = RECORD
  1039.                   c_1 : ARRAY[1..4] of INTEGER;
  1040.                   rec_size : INTEGER;
  1041.                   c_2 : INTEGER;
  1042.                   key_size : INTEGER;
  1043.                   end;
  1044.             index_record = RECORD
  1045.                   disk : CHAR;
  1046.                   filename : ARRAY[1..8] of CHAR;
  1047.                   return_code : INTEGER;
  1048.                   res_1 : INTEGER;
  1049.                   ctrl : ^ctrl_rec;
  1050.                   reserved : ARRAY[1..196] of CHAR;
  1051.                   END;
  1052.  
  1053.       VAR
  1054.             key : key_t;
  1055.             rec : rec_t;
  1056.             cmd : CHAR;
  1057.             ir : index_record;
  1058.             tem_d : ARRAY[1..2048] of CHAR;
  1059.  
  1060.       PROCEDURE INDEX0 ( command : CHAR;
  1061.                   var key : key_t;
  1062.                   var rec : rec_t;
  1063.                   var ir : index_record ); extern;
  1064.  
  1065.       PROCEDURE INDEX1 ( command : CHAR;
  1066.                   var key : key_t;
  1067.                   var rec : rec_t;
  1068.                   var ir : index_record ); extern;
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1082. .PAè
  1083.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -93-
  1084.  
  1085.  
  1086.  
  1087.       BEGIN       (* tstindex *)
  1088.       ir := ' ';
  1089.       write('Disk: ');
  1090.       readln(ir.disk);
  1091.       write('File: ');
  1092.       readln(ir.filename);
  1093.       REPEAT
  1094.             write('cmd: ');
  1095.             readln(cmd);
  1096.             cmd := upcase(cmd);
  1097.             key := ' ';
  1098.             rec := ' ';
  1099.             IF (cmd in ['A', 'D', 'R', 'U']) THEN 
  1100.                   BEGIN
  1101.                   write('key: ');
  1102.                   readln(key);
  1103.                   IF (cmd in ['A', 'U'] THEN
  1104.                         BEGIN
  1105.                         write('data: ');
  1106.                         readln(tem_d);
  1107.                         rec := copy(key, 1, ir.ctl^.key_size) +
  1108.                                copy(tem_d, 1, ir.ctl^.rec_size -
  1109.                                     ir.ctl^.key_size);
  1110.                         END;
  1111.                   END;
  1112.             (* justify or kompress must call INDEX1 *)
  1113.             IF (cmd in ['J', 'K'] THEN
  1114.                   BEGIN
  1115.                   rec := ' ';
  1116.                   INDEX1(cmd, key, rec, ir);
  1117.                   END
  1118.             ELSE
  1119.                   INDEX0(cmd, key, rec, ir);
  1120.             IF (ir.return_code <> 0) THEN
  1121.                   BEGIN
  1122.                   writeln('Error:', ir.return_code);
  1123.                   END;
  1124.             IF (cmd = 'Q') THEN
  1125.                   writeln('query result: ',key[1]);
  1126.             IF (cmd in ['B', 'R', 'S']) THEN
  1127.                   BEGIN
  1128.                   writeln('key: ', copy(rec, 1, ir.ctl^.key_size));
  1129.                   writeln('data: ', copy(rec, ir.ctl^.key_size + 1,
  1130.                           ir.ctl^.rec_size - ir.ctl^.key_size));
  1131.                   END;
  1132.             UNTIL (cmd = '?');
  1133.       END.        (* tstindex *)
  1134.  
  1135.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1136. .PAè
  1137.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -94-
  1138.  
  1139.  
  1140.  
  1141.            Execution  of  TSTINDEX  is shown for a simple data base with 16
  1142.       character names and up to 96 characters of information (which happens
  1143.       to be addresses).  Note that the key length  and  record  length  are
  1144.       entered from the terminal in the N command.
  1145.  
  1146.       A>EXEC B:TSTINDEX
  1147.       Exec  ver 3.0
  1148.  
  1149.       Disk: B
  1150.       File: ADDRESS
  1151.       cmd: W
  1152.       cmd: N
  1153.       Record size in bytes: 96
  1154.       Key size in bytes: 16
  1155.       Maximum number of records: 500
  1156.       cmd: A
  1157.       key: JRT
  1158.       data: 'JRT Systems/45 Camino Alto/Mill Valley, CA 94941'
  1159.       cmd: A
  1160.       key: OLD
  1161.       data: 'Old JRT Office/550 Irving St/SF, CA 94122'
  1162.       cmd: B
  1163.       key: JRT
  1164.       data: JRT Systems/45 camino Alto/Mill Valley, CA 94941
  1165.       cmd: S
  1166.       key: OLD
  1167.       data: Old JRT Office/550 Irving St/SF, CA 94122
  1168.       cmd: S
  1169.       %INDEX error: Key not found
  1170.       Error: 3
  1171.       cmd: a
  1172.       key: LITTLE
  1173.       data: 'Little Italy/4109 24th St/SF, CA 94114'
  1174.       cmd: a
  1175.       key: SZECHWAN
  1176.       data: 'Szechwan Court/1668 Haight St/SF, CA 94117'
  1177.       cmd: f
  1178.       cmd: r
  1179.       key: JRT
  1180.       key: JRT
  1181.       data: JRT Systems/45 Camino Alto/Mill Valley, CA 94941
  1182.       cmd: r
  1183.       key: OTHER
  1184.       %INDEX error: Key not found
  1185.       return code 3
  1186.       cmd: z
  1187.  
  1188.  
  1189.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1190. .PAè
  1191.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -95-
  1192.  
  1193.  
  1194.  
  1195.       cmd: ?
  1196.       Error: 7
  1197.  
  1198.       Program termination
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1244. .PAè
  1245.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -96-
  1246.  
  1247.  
  1248.  
  1249.  
  1250.       7.5  CLOSE
  1251.  
  1252.       Format
  1253.       CLOSE ( file_variable );
  1254.  
  1255.            The  CLOSE  builtin  procedure  terminates  processing against a
  1256.       sequential or random disk file.  If a sequential output file  is  not
  1257.       properly  closed,  the  data  written  out will be lost because CLOSE
  1258.       updates the disk directory.  This  procedure  also  releases  storage
  1259.       reserved for input/output buffers of sequential files.
  1260.  
  1261.       Examples:
  1262.  
  1263.               CLOSE ( F1 );
  1264.               CLOSE ( DATA_FILE );
  1265.               CLOSE ( MASTER_CUSTOMER_REPORT );
  1266.  
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1298. .PAè
  1299.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -97-
  1300.  
  1301.  
  1302.  
  1303.       7.5.1   EOF
  1304.  
  1305.       Format
  1306.       EOF ( file_variable );
  1307.  
  1308.            The  end  of  file  function indicates when the end of a file is
  1309.       reached during input processing.  It returns a Boolean value of  true
  1310.       immediately  after end of file detection, otherwise it returns false.
  1311.       The EOF function has no meaning in console or random disk processing.
  1312.  
  1313.            When processing a file in text mode, end  of  file  is  detected
  1314.       when  all  data  up to the first CTRL-Z (1AH) has been read.  This is
  1315.       the standard character to indicate the end of data.
  1316.  
  1317.            When processing a file in binary mode, end of file  is  detected
  1318.       when  all  the data in the last allocated sector of the file has been
  1319.       read.
  1320.  
  1321.       Examples:
  1322.  
  1323.       1.      (* COMPUTE THE AVERAGE OF A FILE OF NUMBERS *)
  1324.               RESET( F1, 'DAILY.SAL', TEXT, 4096);
  1325.               TOTAL := 0;
  1326.               COUNT := 0;
  1327.               WHILE NOT EOF(F1) DO
  1328.                       BEGIN
  1329.                       READ(F1; DAILY_SALES);
  1330.                       TOTAL := TOTAL + DAILY_SALES;
  1331.                       COUNT := COUNT + 1;
  1332.                       END;
  1333.               AVERAGE := TOTAL / COUNT;
  1334.               CLOSE( F1 );
  1335.  
  1336.  
  1337.       2.      (* WRITE A FILE TO THE PRINTER *)
  1338.               SYSTEM( LIST );
  1339.               RESET( F1, 'TEST.PAS', BINARY, 2048 );
  1340.               READ(F1; CH);
  1341.               (* INSTEAD OF USING EOF, WE DIRECTLY TEST FOR 
  1342.               A CHARACTER 1AH, SINCE THIS IS BINARY FILE  *)
  1343.               WHILE CH <> CHR(1AH) DO
  1344.                       BEGIN
  1345.                       WRITE( CH );
  1346.                       READ(F1; CH);
  1347.                       END;
  1348.               CLOSE( F1 );
  1349.  
  1350.  
  1351.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1352. .PAè
  1353.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -98-
  1354.  
  1355.  
  1356.  
  1357.       7.6     EOLN
  1358.  
  1359.       Format 1
  1360.       EOLN ( file_variable );
  1361.  
  1362.       Format 2
  1363.       EOLN;
  1364.  
  1365.  
  1366.            The end of line function returns a Boolean value true if the end
  1367.       of line is  reached,  otherwise  it  returns  false.   This  function
  1368.       applies only to console and text files, not to binary files.
  1369.  
  1370.            Format  1 is used to sense end of line while reading disk files.
  1371.       Format 2 is used to sense end of line in console input.
  1372.  
  1373.            This function is used primarily to read in an unknown number  of
  1374.       data  items from a line of text.  Executing a READLN, with or without
  1375.       any parameters, always resets EOLN to false and positions the file at
  1376.       the start of the next line of text.
  1377.  
  1378.       Examples:
  1379.  
  1380.       1.      (* READ NUMBERS FROM CONSOLE, COMPUTE AVG *)
  1381.               TOTAL := 0;     COUNT := 0;
  1382.               WHILE NOT EOLN DO
  1383.                       BEGIN
  1384.                       READ( NUMBER );
  1385.                       TOTAL := TOTAL + NUMBER;
  1386.                       COUNT := COUNT + 1;
  1387.                       END;
  1388.               READLN;
  1389.               AVERAGE := TOTAL DIV COUNT;
  1390.  
  1391.  
  1392.       2.      (* READ DATA FROM FILE, COUNT LINES OF TEXT *)
  1393.               LINE_COUNT := 0;
  1394.               WHILE NOT EOF(F1) DO
  1395.                       BEGIN
  1396.                       READ(F1; DATA_ITEM);
  1397.                       PROCESS_DATA( DATA_ITEM );
  1398.                       IF EOLN(F1) THEN
  1399.                               BEGIN
  1400.                               LINE_COUNT := LINE_COUNT + 1;
  1401.                               READLN(F1)
  1402.                               END;
  1403.                       END;
  1404.  
  1405.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1406. .PAè
  1407.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -99-
  1408.  
  1409.  
  1410.  
  1411.       7.7     ERASE
  1412.  
  1413.       Format
  1414.       ERASE ( filename );
  1415.  
  1416.  
  1417.            The ERASE procedure deletes files from the disk.  It can be used
  1418.       to delete files  from  any  available  disk  by  including  the  disk
  1419.       identifier in the filename.
  1420.  
  1421.            ERASE  is  implemented  as  an  external procedure.  Any program
  1422.       referencing it must include it declaration:
  1423.  
  1424.                       PROCEDURE ERASE ( NAME : STRING[20] ); EXTERN;
  1425.  
  1426.  
  1427.       Examples:
  1428.  
  1429.                       ERASE( 'TESTPGM.PAS' );
  1430.  
  1431.                       ERASE( CONCAT( 'B:', FILENAME, FILETYPE ) );
  1432.  
  1433.                       ERASE( 'A:' + NAME + '.HEX' );
  1434.  
  1435.                       ERASE( BACKUP_FILE );
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1460. .PAè
  1461.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -100-
  1462.  
  1463.  
  1464.  
  1465.       7.8  GET
  1466.  
  1467.       Format
  1468.       GET ( file_variable );
  1469.  
  1470.  
  1471.            This standard Pascal procedure moves the next data item from the
  1472.       sequential file into the file's buffer variable.   If  there  is  not
  1473.       another data item in the file then the EOF function becomes true.
  1474.  
  1475.            The  READ procedure allows reading directly from a file into any
  1476.       variable.
  1477.  
  1478.               READ ( F; X );
  1479.  
  1480.            is equivalent to:
  1481.  
  1482.               X := F^;
  1483.               GET ( F );
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1514. .PAè
  1515.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -101-
  1516.  
  1517.  
  1518.  
  1519.       7.9   OPEN
  1520.  
  1521.       Format 1
  1522.       OPEN ( file_variable, filename, BINARY );
  1523.  
  1524.       Format 2
  1525.       OPEN ( file_variable, filename, TEXT );
  1526.  
  1527.  
  1528.            The OPEN builtin procedure is used  to  open  files  for  random
  1529.       access.   Format 1 is used to open files in binary mode.  Format 2 is
  1530.       used to open files in text mode.
  1531.  
  1532.            The file_variable refers to a file variable declared in the  VAR
  1533.       declaration   section.   The  filename  is  a  string  or  structured
  1534.       expression which may include disk identifier letter.
  1535.  
  1536.            The file specified by the filename is opened for use if present.
  1537.       If not present, a new file is created.
  1538.  
  1539.            Both formats may be used with both RRN and RBA accessing.
  1540.  
  1541.       Examples:
  1542.  
  1543.                       OPEN ( INVENTORY, 'INVENTRY.DAT', BINARY );
  1544.  
  1545.                       OPEN ( F1, RANGE + '.DAT', TEXT );
  1546.  
  1547.                       OPEN ( CASE_HISTORY, 'D:TORTS.LIB', BINARY );
  1548.  
  1549.                       OPEN ( DICTIONARY, 'B:SPELLING.LIB', BINARY );
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1568. .PAè
  1569.  
  1570.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -102-
  1571.  
  1572.  
  1573.  
  1574.       7.10  PICTURE
  1575.  
  1576.  
  1577.            The external  function  PICTURE  allows  you  to  format  (real)
  1578.       numbers  in  powerful  ways.   Check  printing is easy, as are commas
  1579.       within a number and exponential notation.  Floating (or fixed) dollar
  1580.       signa are easy to specify.   Credit  and  debit  indications  can  be
  1581.       included.   Literal characters such as currency signs can also be put
  1582.       in the formatted  string.   COBOL  and  PL/I  programmers  will  find
  1583.       familiar features such as with trailing signs.
  1584.  
  1585.            PICTURE  takes  a  format string and a real number as arguments.
  1586.       It returns a formated string, which can be printed  on  the  console,
  1587.       the line printer, written to a file, concatenated with other strings,
  1588.       or saved for further processing.  For example,
  1589.  
  1590.               RES$ := PICTURE("*$##,###.##", 1456.20);
  1591.               WRITELN ("Sum: ", PICTURE("###,###.### ###",
  1592.                       6583.1234567));
  1593.  
  1594.       will  set  RES$  (which  should  be  declared as a string or array of
  1595.       characters) to the eleven characters **$1,456.20  and  next  write  a
  1596.       line consisting of the twenty characters  Sum:   6,583.123 456.
  1597.  
  1598.            PICTURE   is   supplied   as   a  compiled  function  (the  file
  1599.       PICTURE.INT).  PICTURE must be declared in any program that  uses  it
  1600.       as
  1601.  
  1602.               FUNCTION PICTURE (FMT : STRING; R : REAL) :
  1603.                                STRING; EXTERN;
  1604.  
  1605.            The format string is not hard to create.  PICTURE generally puts
  1606.       one  character in the result string for every character in the format
  1607.       string, the exceptions marked with a *.  The  format  characters  are
  1608.       summarized below.
  1609.  
  1610.            Note  that  you  will usually need only pound signs, commas, and
  1611.       periods in your formats.
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1622. .PAè
  1623.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -103-
  1624.  
  1625.  
  1626.  
  1627.            Format     Replaced with
  1628.  
  1629.               0       Literal zero (used only with exponential notation
  1630.               9       A decimal digit (always)
  1631.               B       Space (or fill character)
  1632.               CR      CR if the number is positive, else spaces
  1633.               DB      DB if the number is negative, else spaces
  1634.               E       Exponent (consisting of E, sign, and two digits) (*)
  1635.               E+##    Exponent (sign and digit indications are ignored) (*)
  1636.               L       Literal L (as a currency sign)
  1637.               S       Minus or plus sign
  1638.               V       Implied decimal point  (*)
  1639.               Z       Digit or fill character
  1640.               -       Minus sign if negative, else space
  1641.               +       Plus sign if positive, else minus sign
  1642.               #       Digit or fill character
  1643.               %       Digit or fill character
  1644.               *       Asterisk fill
  1645.               **      Asterisk fill and one digit
  1646.               *$      Asterisk fill and floating dollar sign
  1647.               **$     Asterisk fill, floating dollar sign, and one digit
  1648.               ,       Comma if digit has already been formated, else space
  1649.               /       Literal / (or fill character)
  1650.               :       Literal : (or fill character)
  1651.               space   Literal space (or fill character)
  1652.               ^       Exponent (E, sign, and two digits)  (*)
  1653.               ^^^^    Exponent  (*)
  1654.               _       Next character is included literally (*)
  1655.               _* or * A single asterisk (*)
  1656.               _$ or $ A single dollar sign (*)
  1657.  
  1658.       Examples (our favorite formats)
  1659.  
  1660.               -#.### ###^^^^          Large and small numbers
  1661.               $##.##                  Price of JRT Pascal
  1662.               ###,###                 Number of happy customers
  1663.               *$###,###.##            Checks (especially pay checks)
  1664.               -##,###,###,###,###.##  Change in the national debt
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1676. .PAè
  1677.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -104-
  1678.  
  1679.  
  1680.  
  1681.            In general, PICTURE can use any format  with  legal  characters.
  1682.       It  is  possible  to  create  ridiculous  formats,  such as "-+".  An
  1683.       appropriate matching string will be returned (either space, plus,  or
  1684.       minus  in  this  case).   If  the  format contains and invalid format
  1685.       character, PICTURE will complain and  will  return  a  two  character
  1686.       string ??
  1687.  
  1688.            Upper  case and lower case letters are equivalent in the format,
  1689.       so E or e can be used for the exponent.
  1690.  
  1691.  
  1692.     Simple number formating
  1693.  
  1694.            Pound signs (#) are usually used to indicate where digits should
  1695.       be placed.  A decimal point indicates where the decimal point  should
  1696.       go.   PICTURE  does  NO  rounding,  but  just truncates insignificant
  1697.       digits.  (The vertical bar just indicates the start of the result  in
  1698.       the  following  examples,  and  will  not  be  included in the actual
  1699.       result).
  1700.  
  1701.               Format          Number           Result      Length
  1702.                                               |              #####           15000            15000          5
  1703.                                               |                              -2.6                -2          5
  1704.                                               |                              -17.98             -17          5
  1705.                                               |              ###.##          29.95             29.95         6
  1706.                                               |                              -10.756          -10.75         6
  1707.  
  1708.  
  1709.     Punctuation
  1710.  
  1711.            Commas can be inserted in the formated number.  A comma  in  the
  1712.       format  will  cause  a comma AT THE CORRESPONDING POSITION if a digit
  1713.       has already been put into the result  in  a  position  to  the  comma
  1714.       position.   If  no  significant  digit has been seen, then a space or
  1715.       asterisk is substituted.  Note that PICTURE  DOES  NOT  automatically
  1716.       put  commas  every  third  position.   You  can  place  commas in any
  1717.       meaningful (or meaningless) position in your number.
  1718.  
  1719.               Format          Number           Result      Length
  1720.                                               |              ###,###         2470               2,470        7
  1721.                                               |              #,###           -999              -999          5
  1722.                                               |              #,######        2743562          2,743562       8
  1723.  
  1724.       COUNT YOUR COMMAS AND DIGITS.  Commas can be used after  the  decimal
  1725.       point if desired.
  1726.  
  1727.  
  1728.  
  1729.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1730. .PAè
  1731.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -105-
  1732.  
  1733.  
  1734.  
  1735.            A space (or B) works exactly the same as commas for those of you
  1736.       who  want  to  punctuate numbers with spaces instead of commas.  Note
  1737.       that this is different from the  PRINT  USING  statement  in  Basics,
  1738.       which treat blanks as delimiters.
  1739.  
  1740.  
  1741.     Exponential Notation
  1742.  
  1743.            Exponential  notation is indicated either with an uparrow (^) or
  1744.       the letter E.  Following uparrows, signs, and  digit  indicators  are
  1745.       ignored,  so  you can use ^^^^ or E+##.  The formated exponent ALWAYS
  1746.       takes four characters:  the letter E, the sign of the  exponent,  and
  1747.       two digits.
  1748.  
  1749.            If  you  want  PICTURE to create numbers in exponential notation
  1750.       with a leading 0 before the decimal point, you can use the digit 0 in
  1751.       a format before the decimal.
  1752.  
  1753.               Format          Number           Result      Length
  1754.                                               |              #.###^          15000            1.500E+04      9
  1755.                                               |                              -2.5             -.250E+01      9
  1756.                                               |              ###.####^       15000            150.0000E+01   12
  1757.                                               |                              -2.5             -25.0000E-01   12
  1758.                                               |              ###.####E+##    -2.5             -25.0000E-01   12
  1759.                                               |              0.### ###^^^^   15000            0.150 000E+05  13
  1760.  
  1761.  
  1762.     Signs
  1763.  
  1764.            Normally, PICTURE  will  put  a  minus  sign  before  the  first
  1765.       significant  digit  in  a number if that number is negative.  This is
  1766.       called a floating sign, and will take up one digit position.  You can
  1767.       have PICTURE handle the sign in many other ways.  To  put  the  minus
  1768.       sign  (or  blank)  in  a  fixed position, use a - in the format.  The
  1769.       minus sign can be before the first significant digit or at the end of
  1770.       the number.
  1771.  
  1772.            To put a negative or positive sign in a fixed  position,  use  a
  1773.       plus sign (+) or an S instead of the minus sign.
  1774.  
  1775.               Format          Number           Result      Length
  1776.                                               |              -####           -12              -  12          5
  1777.                                               |                              134                134          5
  1778.                                               |              ####+           -12                12-          5
  1779.                                               |                              134               134+          5
  1780.  
  1781.  
  1782.  
  1783.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1784. .PAè
  1785.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -106-
  1786.  
  1787.  
  1788.  
  1789.            With  exponential  notation,  you will generally want to specify
  1790.       the location of the sign, since a floating sign will cause  one  less
  1791.       digit  before  the  decimal  to be printed WITH NEGATIVE NUMBERS than
  1792.       with POSITIVE NUMBERS.
  1793.  
  1794.               Format          Number           Result         Length
  1795.                                               |              -0.### ###^^^^  15000             0.150 000E+05    14
  1796.                                               |                              -15000           -0.150 000E+05    14
  1797.                                               |              -#.######^^^^   15000             1.500000E+04     13
  1798.                                               |              -.###^          15001             .150E+04          9
  1799.                                               |              +.###^          15001            +.150E+04          9
  1800.                                               |                              -2.506           -.250E+01          9
  1801.                                               |              .###-^          15001            .150 E+04          9
  1802.                                               |                              -2.506           .250-E+01          9
  1803.  
  1804.  
  1805.            Note that you can put the sign  in  a  number  of  inappropriate
  1806.       places and can even have the sign appear more that once.
  1807.  
  1808.  
  1809.     Dollar signs and check printing
  1810.  
  1811.            Floating   dollar   signs   and   asterisks   fill   work  in  a
  1812.       straightforward manner, and will produce  the  sort  of  results  you
  1813.       would  want for printing dollar sign amounts or checks.  To enter a $
  1814.       or * at a fixed position, use one of the "literal  next"  characters,
  1815.       the underline (_) or backslash () before the $ or *.
  1816.  
  1817.               Format          Number           Result       Length
  1818.                                               |              _$##,###.##     2745.23          $ 2,745.23     10
  1819.                                               |              $##,###.##      2645.23           $2,745.23     10
  1820.  
  1821.            Note  that  the  **,  $$,  and  **$  formats are optional in JRT
  1822.       Pascal's PICTURE function.  They are equivalent to *#, $#,  and  *$#,
  1823.       respectively
  1824.  
  1825.            The  only  exceptions  to  the "one format character, one result
  1826.       character" rule are
  1827.  
  1828.               1) the two "literal next" characters (_ and  )
  1829.                  which do not appear in the result
  1830.               2) the V, which is not printed
  1831.               3) the two exponent characters (^ and E) which
  1832.                  always take four characters (and which cause
  1833.                  following ^, +, -, #, and 9 specifications to
  1834.                  be ignored in the format).
  1835.  
  1836.  
  1837.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1838. .PAè
  1839.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -107-
  1840.  
  1841.  
  1842.  
  1843.     Overflow
  1844.  
  1845.            Overflow occurs when the number to be formated cannot fit in the
  1846.       format provided, as when 1000 is to be  formated  in  a  three  digit
  1847.       field  (###).   When  that  happens, PICTURE puts a % in place of ALL
  1848.       digits.  In exponential notation, the only cause of overflow is  with
  1849.       negative  numbers when no sign is indicated and no digits are allowed
  1850.       before the decimal point.
  1851.  
  1852.               Format          Number           Result       Length
  1853.                                               |              -##             200005            %%            3
  1854.                                               |              ######          -40000102        -%%%%%         6
  1855.                                               |              *$#,###         400102           *$%,%%%        7
  1856.                                               |              .###^           -207             .%%%E+03       8
  1857.  
  1858.  
  1859.     Testing formats for PICTURE
  1860.  
  1861.            Here is  a  routine  you  can  use  to  test  your  own  PICTURE
  1862.       specifications.   (We  use  an  extension of this program that allows
  1863.       file input and output to test ours.) The program reads the number  of
  1864.       real  digits  to be formated and the numbers to be formated.  It then
  1865.       reads one format specification at  a  time  an  prints  each  of  the
  1866.       numbers in that format.
  1867.  
  1868.               PROGRAM TESTPICT
  1869.  
  1870.               CONST
  1871.                       MAX_REAL = 100;
  1872.  
  1873.               VAR
  1874.                       I : INTEGER;
  1875.                       NR_REALS : INTEGER;
  1876.                       PIC : STRING;
  1877.                       REAL_ARR : ARRAY[1..MAX_REAL] OF REAL;
  1878.  
  1879.               EXTERN PICTURE ( FMT : STRING; R : REAL) : STRING; EXTERN;
  1880.  
  1881.               BEGIN
  1882.               REPEAT
  1883.                       WRITE('Number of real numbers to format: ');
  1884.                       READLN(NR_REALS);
  1885.                       UNTIL (NR_REALS < MAX_REAL);
  1886.               FOR I := 1 TO NR_REALS DO
  1887.                       READ(REAL_ARR[I]);
  1888.               READLN;
  1889.  
  1890.  
  1891.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1892. .PAè
  1893.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -108-
  1894.  
  1895.  
  1896.  
  1897.               REPEAT
  1898.                       WRITE('Format: ');
  1899.                       READLN(PIC);
  1900.                       IF(PIC <> '*') THEN
  1901.                             FOR I := 1 TO NR_REALS DO
  1902.                                     BEGIN
  1903.                                     WRITELN(I:3, ' ',
  1904.                                                                 |                                          REAL$(REAL_ARR[I], '   ',
  1905.                                           PICTURE(PIC, REAL_ARR[I]),
  1906.                                            |                                          ' ');
  1907.                                     END;
  1908.                        UNTIL (PIC = '*');
  1909.               END.
  1910.  
  1911.       Note that currently, JRT Pascal requires that real numbers entered in
  1912.       exponential  form  must have a exponent sign and two exponent decimal
  1913.       digits.  This restriction will be relaxed in the future.
  1914.  
  1915.  
  1916.     Formats for ex-COBOL and PL/I programmers
  1917.  
  1918.       The format character V can be used to set an  implied  decimal  point
  1919.       without  printing  one.   (V.  and  .V  can also be used.  The . will
  1920.       always be included in the result.  Z can be used in place of #, and 9
  1921.       can be used to force printing of a digit.
  1922.  
  1923.       The "literal" / and : can be used.  They will be replaced by the fill
  1924.       character (space or *) if appropriate.  Multiple + and - signs can be
  1925.       used in place of # to cause floating signs.
  1926.  
  1927.       Subtle differences between JRT Pascal's PICTURE and  other  languages
  1928.       will be found.  Use the TESTPICT routine to experiment as needed.
  1929.  
  1930.  
  1931.  
  1932.  
  1933.  
  1934.  
  1935.  
  1936.  
  1937.  
  1938.  
  1939.  
  1940.  
  1941.  
  1942.  
  1943.  
  1944.  
  1945.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  1946. .PAè
  1947.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -109-
  1948.  
  1949.  
  1950.  
  1951.       7.11  PUT
  1952.  
  1953.       Format
  1954.       PUT ( file_variable );
  1955.  
  1956.  
  1957.            This  standard Pascal procedure appends the current value of the
  1958.       buffer variable to the sequential file.
  1959.  
  1960.            The WRITE procedure allows writing directly to a file  from  any
  1961.       variable.
  1962.  
  1963.               WRITE ( F; X );
  1964.  
  1965.            is equivalent to:
  1966.  
  1967.               F^ := X;
  1968.               PUT ( F );
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.  
  1988.  
  1989.  
  1990.  
  1991.  
  1992.  
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  
  1998.  
  1999.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  2000. .PAè
  2001.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -110-
  2002.  
  2003.  
  2004.  
  2005.       7.12    READ, READLN
  2006.  
  2007.       Format 1  (console)
  2008.       READ/LN (variable1, variable2,... );
  2009.  
  2010.       Format 2  (sequential disk)
  2011.       READ/LN ( file_variable ; variable1, variable2,... );
  2012.  
  2013.       Format 3  (random disk)
  2014.       READ/LN ( file_variable, RRN, integer_or_real_expr ;
  2015.                       variable1, variable2,... );
  2016.  
  2017.       Format 4  (random disk)
  2018.       READ/LN ( file_variable, RBA, integer_or_real_expr ;
  2019.                       variable1, variable2,... );
  2020.  
  2021.  
  2022.            The  READ  standard procedure is used to bring data from console
  2023.       or disk into main storage.
  2024.  
  2025.            Format 1 is used for reading data  from  the  console  keyboard.
  2026.       When  it  is  executed  it  will obtain data from the console buffer,
  2027.       convert it to the proper format, and store the data in the  specified
  2028.       variables.  If sufficient data is not available, the system will wait
  2029.       for  more  data to be keyed in. If data is keyed in with unacceptable
  2030.       format, a warning message is issued.
  2031.  
  2032.            Dynamic string variables may only be used in READ format 1 -  in
  2033.       console  input  - and not in disk file input.  To read character data
  2034.       from disk files, arrays of characters or records may be used.
  2035.  
  2036.            Reading from the console  into  a  dynamic  string  variable  is
  2037.       treated  differently.   An  entire  line of text is obtained from the
  2038.       console and moved  directly  into  the  string  variable.   Separator
  2039.       characters  and single quotes are ignored.  The system will not allow
  2040.       more characters to be keyed in than can fit into the  variable.   The
  2041.       string  variable  must  be  the only variable in the READ's parameter
  2042.       list.
  2043.  
  2044.            When all data on a given input line has been read in,  the  EOLN
  2045.       function  becomes  true.   The  READLN  procedure  has the additional
  2046.       purpose of resetting EOLN to false.  READLN  always  clears  out  the
  2047.       current  input  line.  For example, if 5 numbers were keyed in on one
  2048.       line and a READLN were issued with 3 variables in its parameter list,
  2049.       the last 2 numbers on that line would be lost.
  2050.  
  2051.  
  2052.  
  2053.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  2054. .PAè
  2055.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -111-
  2056.  
  2057.  
  2058.  
  2059.            Format 2 is used to read in data from a  sequential  disk  file.
  2060.       Whether  the  file  is  processed as text or binary data is specified
  2061.       when the file is opened (RESET).  The file_variable must refer  to  a
  2062.       file  which  has  been  successfully  opened or a run-time error will
  2063.       occur.
  2064.  
  2065.            Note that JRT Pascal uses a semicolon  after  the  file_variable
  2066.       rather than a comma.
  2067.  
  2068.            Format  3  is  used to read in data from a random file by giving
  2069.       the relative record number (RRN) of the record required.   The  first
  2070.       record  number  is  at  RRN=0.   The file must have been successfully
  2071.       opened with the OPEN procedure.  Sequential and random file  accesses
  2072.       cannot be mixed unless the file is first closed and then re-opened in
  2073.       the  other  mode.  The size of records on the file for RRN processing
  2074.       is determined when the file is declared.  For example, a FILE OF REAL
  2075.       has a record size of 8 bytes.
  2076.  
  2077.            Format 4 is used to read data from a random file by  giving  the
  2078.       relative  byte  address  (RBA)  of the data item required.  The first
  2079.       byte of the file is at RBA=0.  The file must have  been  successfully
  2080.       opened  with  the  OPEN procedure.  Random processing cannot be mixed
  2081.       with sequential processing but RRN and RBA processing  can  be  mixed
  2082.       without re-opening the file.
  2083.  
  2084.       Examples:
  2085.  
  2086.                       READLN( A, B );
  2087.  
  2088.                       READ( DATA_FILE; X_DATA, Y_DATA );
  2089.  
  2090.                       READ( HISTORY_FILE, RRN, YEAR; MAJOR_EVENT );
  2091.  
  2092.                       READ( INQUIRY_FILE, RBA, 0; INDEX );
  2093.  
  2094.                       READLN;         (* RESET EOLN *)
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  2108. .PAè
  2109.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -112-
  2110.  
  2111.  
  2112.  
  2113.       7.13    RENAME
  2114.  
  2115.       Format
  2116.       RENAME ( old_name, new_name );
  2117.  
  2118.  
  2119.            The  RENAME  procedure is used to rename disk files on any disk.
  2120.       The old_name and new_name are string expressions.
  2121.  
  2122.            RENAME is implemented as an  external  procedure.   Any  program
  2123.       referencing it must include it declarations:
  2124.  
  2125.                   PROCEDURE RENAME ( OLD, NEW1 : STRING[20] );
  2126.                              EXTERN;
  2127.  
  2128.  
  2129.       Examples:
  2130.  
  2131.                   RENAME( 'C:TEST.PAS', 'TEST2.PAS' );
  2132.  
  2133.                   RENAME( OLD_FILE_NAME, NEW_FILE_NAME );
  2134.  
  2135.                   RENAME( DISK + OLD_NAME, NEW_NAME );
  2136.  
  2137.                   RENAME( 'SORT.BAK', 'SORT.PAS' );
  2138.  
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  2162. .PAè
  2163.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -113-
  2164.  
  2165.  
  2166.  
  2167.       7.14  RESET 
  2168.  
  2169.       Format 1
  2170.       RESET ( file_variable, filename, BINARY, bufr_size );
  2171.  
  2172.       Format 2
  2173.       RESET ( file_variable, filename, TEXT, bufr_size );
  2174.  
  2175.  
  2176.            The  RESET  standard  procedure is used to open already existing
  2177.       files for sequential input.
  2178.  
  2179.            IMPORTANT CHANGE from version 2.2 to version 3.0 of JRT  Pascal:
  2180.       RESET  now sets the EOF function to true and issues a warning message
  2181.       if the file does not exist on disk.  It used to cause the old program
  2182.       to terminate with an error.  NOTE: All programs should now  test  EOF
  2183.       immediately after RESET.
  2184.  
  2185.            Format  1  is used to open files in binary mode.  Format 2 opens
  2186.       files in text mode.
  2187.  
  2188.            The file_variable refers to a file variable declared in the  VAR
  2189.       declaration   section.   The  filename  is  a  string  or  structured
  2190.       expression which may include disk identifier letter.
  2191.  
  2192.            The bufr_size is an integer expression which indicates the  size
  2193.       of  the  input  buffer  to  be  allocated  in  dynamic storage.  When
  2194.       storarage is available, larger buffers  are  preferred  because  they
  2195.       result in fewer disk accesses and thus faster processing.  The buffer
  2196.       size is rounded up to a multiple of 128.
  2197.  
  2198.            Values like 1024, 2048 and 4096 are recommended for bufr_size.
  2199.  
  2200.       Examples:
  2201.  
  2202.                   RESET( INPUT_FILE, 'SOURCE.PAS', BINARY, 1024 );
  2203.  
  2204.                   RESET( LOG, 'B:LOG.DAT', TEXT, 2048 );
  2205.  
  2206.                   RESET( DAILY_SALES, 'C:DAILY.DAT', TEXT, 256 );
  2207.  
  2208.                   RESET( STATISTICS, 'STAT.DAT', BINARY, 1024 );
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  2216. .PAè
  2217.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -114-
  2218.  
  2219.  
  2220.  
  2221.       7.15  REWRITE
  2222.  
  2223.       Format 1
  2224.       REWRITE( file_variable, filename, BINARY, bufr_size );
  2225.  
  2226.       Format 2
  2227.       REWRITE( file_variable, filename, TEXT, bufr_size );
  2228.  
  2229.  
  2230.            The  REWRITE  standard  procedure  is used to open all files for
  2231.       sequential disk output.  A  new  file  with  the  given  filename  is
  2232.       allocated.  If a file with that name already exists, it is deleted to
  2233.       free the space allocated to it.
  2234.  
  2235.            Format  1  is used to open files in binary mode.  Format 2 opens
  2236.       files in text mode.
  2237.  
  2238.            The file_variable refers to a file variable declared in the  VAR
  2239.       declaration   section.   The  filename  is  a  string  or  structured
  2240.       expression which may include disk identifier letter.
  2241.  
  2242.            The bufr_size is an integer expression which indicates the  size
  2243.       of the input buffer to be allocated in dynamic storage.  When storage
  2244.       is  available,  larger  buffers  are preferred because they result in
  2245.       fewer disk accesses and thus faster processing.  The buffer  size  is
  2246.       rounded up to a multiple of 128.
  2247.  
  2248.            Values like 1024, 2048 and 4096 are recommended for bufr_size.
  2249.  
  2250.       Examples:
  2251.  
  2252.                   REWRITE( LOG_FILE, 'F:LOG.DAT', TEXT, 512 );
  2253.  
  2254.                   REWRITE( REPORT, MONTH + '.RPT', TEXT, 1024 );
  2255.  
  2256.                   REWRITE( SYMBOL, PGM + '.SYM', BINARY, 256 );
  2257.  
  2258.                   REWRITE( STATISTICS, 'B:STATS.DAT', TEXT, 768 );
  2259.  
  2260.  
  2261.  
  2262.  
  2263.  
  2264.  
  2265.  
  2266.  
  2267.  
  2268.  
  2269.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  2270. .PAè
  2271.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -115-
  2272.  
  2273.  
  2274.  
  2275.       7.16  WRITE, WRITELN
  2276.  
  2277.       Format 1  (console)
  2278.       WRITE/LN ( variable1, variable2,... );
  2279.  
  2280.       Format 2  (sequential disk)
  2281.       WRITE/LN ( file_variable ; variable1, variable2,... );
  2282.  
  2283.       Format 3  (random disk)
  2284.       WRITE/LN ( file_variable, RRN, integer_or_real_expr ;
  2285.                   variable1, variable2,... );
  2286.  
  2287.       Format 4  (random disk)
  2288.       WRITE/LN ( file_variable, RBA, integer_or_real_expr ;
  2289.                   variable1, variable2,... );
  2290.  
  2291.  
  2292.            The  WRITE standard procedure is used to transfer data from main
  2293.       storage to the console for display or to disk for storage.
  2294.  
  2295.            Format 1 is used to write data to the console or  printer.   The
  2296.       console  is  always  considered  to  be  a text device, i.e., data is
  2297.       always converted to readable text  format  before  output.   Standard
  2298.       ASCII control characters are supported:
  2299.  
  2300.                decimal  hex   purpose
  2301.                -------  ---   --------
  2302.                   9     09h   horizontal tab
  2303.                   10    0ah   line feed
  2304.                   12    0ch   form feed, clear screen
  2305.                   13    0dh   carriage return, end line
  2306.  
  2307.            For  example,  executing  the Pascal statement WRITE( CHR(12) );
  2308.       will clear the screen of most types of CRT terminals.
  2309.  
  2310.            The WRITELN statement is identical to the WRITE except  that  it
  2311.       also writes a carriage return character after the data, i.e., it ends
  2312.       the  current  output  line.  A WRITELN may be used by itself, without
  2313.       any variables, to write a blank line to the output device.
  2314.  
  2315.            Format 2 is used to write data to  squential  disk  files.   The
  2316.       file  must  have  been  successfully opened with a REWRITE procedure.
  2317.       This format may be used in either binary or text mode processing.
  2318.  
  2319.  
  2320.  
  2321.  
  2322.  
  2323.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  2324. .PAè
  2325.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -116-
  2326.  
  2327.  
  2328.  
  2329.            Note that JRT Pascal uses a semicolon  after  the  file_variable
  2330.       rather than a comma.
  2331.  
  2332.            Format  3  is  used to write data to a random file by giving the
  2333.       relative record number (RRN) of the record being updated or  created.
  2334.       The  first  record is at RRN=0.  The file must have been successfully
  2335.       opened  with  the  OPEN  procedure.   Sequential  and   random   file
  2336.       processing  cannot  be  mixed  unless  the  file is first closed then
  2337.       re-opened in the other mode.  The size of records on the file for RRN
  2338.       processing is determined when the file is declared.  For  example,  a
  2339.       FILE  OF  REAL  has  a  record  size  of  8  bytes,  the size of real
  2340.       variables.
  2341.  
  2342.            Format 4 is used to write data to a random file  by  giving  the
  2343.       relative  byte  address (RBA) at which the data is to be stored.  The
  2344.       first byte of the  file  is  at  RBA=0.   The  data  will  be  stored
  2345.       beginning at the specified RBA and continuing until it is all written
  2346.       out.   The  file  must  have  been  successfully opened with the OPEN
  2347.       procedure.   Random  processing  cannot  be  mixed  with   sequential
  2348.       processing but RRN and RBA processing can be mixed without re-opening
  2349.       the file.
  2350.  
  2351.            When  processing in text mode, a convenient formatting option is
  2352.       available.  Any of the variables in the WRITE parameter list  may  be
  2353.       suffixed  with a colon and an integer expression.  This specifies the
  2354.       field width of the data value being written.  IF  the  data  item  is
  2355.       shorter  than  this  then  spaces will be inserted on the left of the
  2356.       item.  This option is used when columns of figures must be aligned.
  2357.  
  2358.            A second option is available for real numbers.  After the  field
  2359.       width  integer  expression, a second colon and integer expression may
  2360.       be used to indicate the number of digits right of the  decimal  place
  2361.       to be displayed.
  2362.  
  2363.       Examples:
  2364.  
  2365.                   WRITELN( 'THE TIME IS ',GET_TIME );
  2366.  
  2367.                   WRITE( DATA_FILE; X[1], X[2], X[3] );
  2368.  
  2369.                   FOR I:=1 TO 100 DO
  2370.                         WRITE( DATA_FILE; X[1] );
  2371.  
  2372.                   IF DATA < 0 THEN
  2373.                         WRITE( NEGATIVE_DATA; DATA )
  2374.                   ELSE
  2375.                         WRITE( POSITIVE_DATA; DATA );
  2376.  
  2377.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  2378. .PAè
  2379.       JRT Pascal  User's Guide     version 3.0         NOT FOR SALE   -117-
  2380.  
  2381.  
  2382.  
  2383.                   WRITELN( REPORT; TOTAL_SALES:12:2 );
  2384.  
  2385.                   WRITE( CUSTOMER_FILE, RRN, CUST_NUM;
  2386.                         NEW_CUSTOMER_RECORD );
  2387.  
  2388.                   WRITE( INQUIRY, RBA, 0; INDEX );
  2389.  
  2390.                   WRITELN;    (* WRITE BLANK LINE *)
  2391.  
  2392.                   WRITE( CHR(0CH) );      (* CLEAR SCREEN *)
  2393.  
  2394.  
  2395.  
  2396.  
  2397.  
  2398.  
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.  
  2405.  
  2406.  
  2407.  
  2408.  
  2409.  
  2410.  
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.       Copy compliments of Merle Schnick            SECTION 7:  Input/output
  2432. .PAè