      PROGRAM PGM06
************************************************************************
*    PROGRAMMER: B. Alex Bridges
*    CLASS:      9:00AM
*    PROGRAM:    PGM06.F
*    DUE DATE:   02/18/99
*
* Program Description:
*    This program reads loan information from a data file. It uses the
*    values to determine the amortization table for the life of the
*    loan.
* Variables:
*    NAMEF   : student's first name
*    NAMEL   : student's last name
*    NUMBER  : number of data items
*    TEMPO   : old temperature
*    TEMPU   : unit of temperature ('C' or 'F')
*    TEMPN   : new temperature
* Input  : NAMEF,NAMEL,NUMBER,TEMPO,TEMPU
* Output : TEMPO,TEMPN
************************************************************************

        CHARACTER*5 NAMEF,NAMEL*7,TEMPU*1
        REAL TEMPO,TEMPN
        INTEGER NUMBER,I

* open the data file
        OPEN (UNIT=12, FILE="pgm06.dat")

* read in values for name and number of data items
        READ (12, *), NAMEF, NAMEL
        READ (12, *), NUMBER

* display the header
        PRINT '(T30,"TEMPERATURE CONVERSION PROGRAM",/)'
        PRINT '("PROGRAMMED BY: ",A,A,/)', NAMEF,NAMEL

* repeat until no more data values
        DO 10 I=1,NUMBER,+1
*  => read in values for name and number of data items
        READ (12, *), TEMPO,TEMPU

*  => calculate temperature conversion and display the output
        IF (TEMPU .EQ. 'C') THEN
          TEMPN = CTOF(TEMPO)
          PRINT '(T5,I,T20,F5.1," DEGREES CELSIUS    = ",F5.1,
     1     " FAHRENHEIT")', I,TEMPO,TEMPN
        ELSE IF (TEMPU .EQ. 'F') THEN
          TEMPN = FTOC(TEMPO)
          PRINT '(T5,I,T20,F5.1," DEGREES FAHRENHEIT = ",F5.1,
     1     " CELSIUS")', I,TEMPO,TEMPN
        ELSE
          PRINT '(" ERROR: ''",A,"'' as unit of temperature is invalid.",/
     1            "        Must be either ''C'' or ''F''.")',TEMPU
        ENDIF
 10     CONTINUE

* close the data file and print end of program message
        CLOSE (12)
        PRINT '(/,T28, "End of program - PGM06.F",/)'
        END

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

************************************************************************
* Method: CTOF                                                         *
* Purpose: Converts temperature from Celsius to Fahrenheit.            *
* Input: --PARAMETERS--                                                *
*        => 'TEMP' = The temperature in Fahrenheit.                    *
* Output: --RETURNS--                                                  *
*         => The temperature in Celsius.                               *
************************************************************************
        REAL FUNCTION CTOF(TEMP)
        REAL TEMP

        CTOF = ((9./5.) * TEMP) + 32

        END

************************************************************************
* Method: FTOC                                                         *
* Purpose: Converts temperature from Fahrenheit to Celsius.            *
* Input: --PARAMETERS--                                                *
*        => 'TEMP' = The temperature in Celsius.                       *
* Output: --RETURNS--                                                  *
*         => The temperature in Fahrenheit.                            *
************************************************************************
        REAL FUNCTION FTOC(TEMP)
        REAL TEMP

        FTOC = (5./9.) * (TEMP - 32)

        END

