perm filename CARDS.SIM[SIM,SYS] blob sn#456657 filedate 1979-07-20 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	BEGIN
C00010 ENDMK
CāŠ—;
BEGIN

Comment
DECSYSTEM-10 SIMULA LANGUAGE HANDBOOK, PART I                 Page 249

Example:
--------

This example shows the use of three types of file and how to open  and
close  them.  The example was chosen to demonstrate these features and
how formatting is available by use of the sub-text concept.  The logic
of  the  example  is  particularly simple.  A file of transactions has
been punched on cards in the format


col  1-5       customer number               CNO
col  7-16      sum of debit transactions     DB
col 19-28      sum of credit transactions    CR


Each transaction is on  a  fresh  card.   The  information  is  to  be
compressed  and recorded on a new sequential file on tape.  The length
of each tape record is 15 CHARACTERS, and its format is:


               5           10
          *************************
          *   CNR   *   CR - DB   *
          *************************

          customer   total sum of
           number    transactions


Checks are made that the customer number is valid (1-3-7 digit  check)
and  that  the card is validly punched.  If not, a copy of the card is
printed on a line printer, and the scan continues.

Note that the INFILE and PRINTFILE share the same buffer.


                                     *******
                                    *      *
                              -----* CARDS *
                              !    *       *
                              !    *********
                              !
                              !
       ***********************************************
       *       *                                     *
BUFFER *       *               CUSTOMER              *
       *       *                                     *
       ***********************************************
                         !            !
                         !            !
                  --------            --------
                  !                          !
                  !                          !
             ***********                 ***********
             *         *                 *         *
NCUSTOMER.   *         *                 * PRINTER *
   IMAGE     *         *                 *        *
             ***********                 * * * * *
                  !                       * * * *
                  !
             ------
             !
             !
          ****** 
         *      *
        *  TAPE  *
         *      *
          ****** 

;

    EXTERNAL INTEGER PROCEDURE checkint;
    TEXT cnr, db, cr, nr, t1, t2, t3, t4, kt, tsum,
    ts, buffer, err;
    INTEGER sum, balance;
    REF(Infile) customercards;
    REF(Printfile) print;
    REF(Outfile) ncustomer;

    BOOLEAN PROCEDURE nonnumeric(t); TEXT t;
    COMMENT ***THIS PROCEDURE RETURNS TRUE IF THE TEXT
    PARAMETER CAN NOT BE NUMERICALLY INTER-
    PRETED FROM THE LEFT*** ;
    BEGIN
        t.Setpos(1);
        nonnumeric:= checkint(t) NE 1;
    END;

    buffer :- Blanks(132);
    COMMENT ***CONSTRUCT THE CARDFILE*** ;
    customercards :- NEW Infile("CCARD DSK: CCARD.CDR");
    customercards.Open(buffer.Sub(10,80));
    cnr :- buffer.Sub(10,5);
    nr :- cnr.Sub(1,4);
    t1 :- nr.Sub(1,1);
    t2 :- nr.Sub(2,1);
    t3 :- nr.Sub(3,1);
    t4 :- nr.Sub(4,1);
    kt :- cnr.Sub(5,1);
    db :- buffer.Sub(16,10);
    cr :- buffer.Sub(28,10);

    COMMENT ***CONSTRUCT PRINTFILE*** ;
    print :- NEW Printfile("PRINT LPT:");
    print.Open(buffer);
    err:- buffer.Sub(1,6);

    COMMENT ***CONSTRUCT TAPEFILE*** ;
    ncustomer :- NEW Outfile("NCUSTOMER MTA:");
    ncustomer.Open(Blanks(15));

    COMMENT ***CONSTRUCT WORKING TEXT TSUM*** ;
    tsum :- Blanks(3);
    ts :- tsum.Sub(3,1);

    INSPECT ncustomer DO
    BEGIN
        customercards.Inimage;
        WHILE NOT customercards.Endfile DO
        BEGIN IF nonnumeric(cnr) OR
            nonnumeric(db) OR
            nonnumeric(cr)
            THEN error:
            BEGIN err:= "ERROR"; print.Outimage
            END ELSE
            BEGIN COMMENT ***137 DIGIT CHECK*** ;
                sum := 7*(t1.Getint + t4.Getint) +
                3*t3.Getint + t2.Getint;
                tsum.Putint(sum);
                IF ts NE kt THEN GOTO error;

                COMMENT ***OUTPUT TO TAPE*** ;
                balance := cr.Getint - db.Getint;
                Outtext(cnr);
                Outint(balance,10);
                Outimage;
            END;
            customercards.Inimage;
        END;
    END ***INSPECT NCUSTOMER*** ;

    slutt: customercards.Close;
    ncustomer.Close;
    print.Close
END