      PROGRAM PGM09
************************************************************************
*    PROGRAMMER: B. Alex Bridges
*    CLASS:      9:00AM
*    PROGRAM:    PGM09.F
*    DUE DATE:   03/18/99
*
* Program Description:
*    This program reads quantity and cost information from a data file.
*    It uses the information to determine the total cost of the compon-
*    ents for each type of radio.
* Variables:
*    NAMEF   : student's first name
*    NAMEL   : student's last name
*    TYPES   : number of types for radios
*    COMPS   : number of components for radios
*    COSTMAT : matrix containing cost of component J
*    COMPMAT : matrix containing no. of component J for radio type I
*    TCOSTMAT: matrix containing total cost of components for
*              radio type I
*    I,J     : matix subsripts
*    LIMIT   : max. number of radios/components
* Input  : NAMEF,NAMEL,TYPES,COMPS,COSTMAT,COMPMAT
* Output : TCOSTMAT
************************************************************************

        CHARACTER*5 NAMEF,NAMEL*8
        INTEGER TYPES,COMPS
        PARAMETER (LIMIT = 9)
        REAL COSTMAT(LIMIT,1),COMPMAT(LIMIT,LIMIT),TCOSTMAT(LIMIT,1)

* open the data + output file
        OPEN (UNIT=12, FILE="pgm09.dat")
        OPEN (UNIT=13, FILE="pgm09.out")

* read in values for data items
        READ (12, *), NAMEF,NAMEL
        READ (12, *), TYPES
        READ (12, *), COMPS
        READ (12, *), (COSTMAT(I,1), I=1,COMPS)
        READ (12, *), ((COMPMAT(I,J),J = 1,COMPS),I = 1,TYPES)

* write the header
c       PRINT '("Student Name: ",A,A,//,
c    1          T30,"PROGRAM - PGM09.F",/)', NAMEF,NAMEL
        WRITE (13, '("Student Name: ",A,A,//,
     1               T30,"PROGRAM - PGM09.F",/)') NAMEF,NAMEL

* write the input
c       PRINT '("Input Data:",/,
c    1          T5,"No. of Radio Types",T25,I1,/,
c    2          T5,"No. of Components",T25,I1,/)', TYPES,COMPS
c       PRINT '("Cost of Individual Components:",/,
c    1          T5,"Capacitor",T20,"Resistor",T35,"Transistor",/,
c    2          T7,F4.2,T22,F4.2,T37,F4.2,/)')
c    3           COSTMAT(1,1),COSTMAT(2,1),COSTMAT(3,1)
c       PRINT '("Number of Components:",//,
c    1          "Radio",/,
c    2          "Type",T12,"Capacitor",T27,"Resistor",T42,
c    3           "Transistor")')
        WRITE (13, '("Input Data:",/,
     1               T5,"No. of Radio Types",T25,I1,/,
     2               T5,"No. of Components",T25,I1,/)') TYPES,COMPS
        WRITE (13, '("Cost of Individual Components:",/,
     1               T5,"Capacitor",T20,"Resistor",T35,"Transistor",/,
     2               T7,F4.2,T22,F4.2,T37,F4.2,/)')
     3                COSTMAT(1,1),COSTMAT(2,1),COSTMAT(3,1)
        WRITE (13, '("Number of Components:",//,
     1               "Radio",/,
     2               "Type",T12,"Capacitor",T27,"Resistor",T42,
     3               "Transistor")')
        DO 30 I = 1, TYPES
c         PRINT '(1X,I1,T15,F3,T30,F3,T45,F3)',
c    1             I,COMPMAT(I,1),COMPMAT(I,2),COMPMAT(I,3)
          WRITE (13, '(1X,I1,T15,F3,T30,F3,T45,F3)')
     1                  I,COMPMAT(I,1),COMPMAT(I,2),COMPMAT(I,3)
 30     CONTINUE

* calculate total cost
        CALL MATMUL(COMPMAT,COSTMAT,TCOSTMAT,LIMIT,TYPES,COMPS,COMPS,1)

* write output
c       PRINT '(/,T15,"TOTAL COMPONENT COST FOR TYPES OF RADIOS",/)'
        WRITE (13, '(/,T15,"TOTAL COMPONENT COST FOR TYPES OF RADIOS",
     1               /)')
        DO 40 I = 1, TYPES
c         PRINT '(T20,"RADIO NO. ",I1," IS $",T38,F5.2)',
c    1             I,TCOSTMAT(I,1)
          WRITE (13, '(T20,"RADIO NO. ",I1," IS $",T38,F5.2)')
     1                  I,TCOSTMAT(I,1)
 40     CONTINUE

* write end of program message and close the data + output file
c       PRINT '(/,T28,"End of program - PGM09.F",/)'
        WRITE (13, '(/,T28,"End of program - PGM09.F",/)')
        CLOSE(12)
        CLOSE(13)

        END

************************************************************************

************************************************************************
* Subroutine: MATMUL                                                   *
* Purpose: Calculates the product of matrix A by matrix B.             *
* Input: --PARAMETERS--                                                *
*        => 'A','B'  = Matrices for input.                             *
*        => 'LIMIT'  = Max. number of rows/columns.                    *
*        => 'ROWSA'  = Number of rows in matrix A.                     *
*        => 'COLSA'  = Number of columns in matrix A.                  *
*        => 'ROWSB'  = Number of rows in matrix B.                     *
*        => 'COLSB'  = Number of columns in matrix B.                  *
* Output: --PARAMETERS--                                               *
*        => 'PROD'   = Resultant matrix.                               *
************************************************************************
        SUBROUTINE MATMUL (A,B,PROD,LIMIT,ROWSA,COLSA,ROWSB,COLSB)

        INTEGER LIMIT,ROWSA,COLSA,ROWSB,COLSB,I,J,K
        REAL A(LIMIT,LIMIT),B(LIMIT,LIMIT),PROD(LIMIT,LIMIT),SUM

        IF(COLSA .NE. ROWSB) THEN
          RETURN
        ELSE
          DO 12 I = 1, ROWSA
            DO 11 J = 1, COLSB
              SUM = 0
              DO 10 K = 1, COLSA
                SUM = SUM + A(I,K) * B(K,J)
 10           CONTINUE
              PROD (I,J) = SUM
 11         CONTINUE
 12       CONTINUE
        END IF

        END
