Kim Reed

ATMS 491 - Computation Technology in Atmospheric Sciences

Homework/Machine Problem #4


FORTRAN source code:

!ATMS 491 - Computational Technology in Atmospheric Sciences
!Homework/Machine Problem #4

!    DATE          PROGRAMMER          MODIFICATIONS
!    ====          ==========          =============
!  10.2.2013        K. Reed            Original Code


!The purpose of this code is to satisfy the MP #4 instructions below.

!Heat Index Chart
!You will write a Fortran program to compute the heat index for a variety of 
!temperature and humidity combinations.  The output will be in the form of 
!text that can be renamed (redirected output) to a .html file.

!The HTML the Fortran program produces will portray a table of heat indices
!with temperatures varying from 80 to 120 by 5 degree icrements and 
!humdity varying from 0 to 100% by 10% increments.

!You can receive 1 point extra credit for displaying the cell's background 
!different colors depending on the severity of the heat index.  Another
!possible point of extra credit can be obtained if you calculate background
!from the heat index values themselves so that each unique heat index value
!has a unique color.

!Submit three URL's here:
!(1) The URL to your heat index table.
!(2) The URL to a webpage showing your code (embedded in <PRE> tags) and 
!    notes on the assignment.
!(3) The URL to YOUR class web index page with these two URLs linked. 

!===========================================================================      
!===========================================================================

PROGRAM Reed_ATMS491_HW4
  IMPLICIT NONE
  
  !Declaration of variables.
    INTEGER :: T, RH, Heat_Index, temp
    REAL    :: c1, c2, c3, c4, c5, c6, c7, c8, c9

  !Define variable values.
    c1 = -42.379
    c2 = 2.04901523
    c3 = 10.14333127
    c4 = -0.22475541
    c5 = -6.83783E-3
    c6 = -5.481717E-2
    c7 = 1.22874E-3
    c8 = 8.5282E-4
    c9 = -1.99E-6

  !Open a new file to write html output to.
    OPEN(unit=1,file="Reed_ATMS491_HW4_Table_html.html",action="write")

  !Formatting to write data to a html formatted table.
    WRITE(1,*) "<table>"
    WRITE(1,*) "<table border=1>"
    WRITE(1,*) "  <tr>"
    WRITE(1,*) "    <td> </td>"
    DO temp = 80,120,5
      WRITE(1,*) "    <th>",temp,"</th>"
    END DO
    WRITE(1,*) "  </tr>"

  !Calculate heat index for each combiniation of relative humdity and temperature.
    !Loop through relative humidities.
      DO RH = 0,100,10
        !Create a new row for each RH value.
          WRITE(1,*)"  <tr>"
          WRITE(1,*)"    <th>",RH,"</th>"

        !Loop through temperatures.  
          DO T = 80,120,5
            Heat_Index = c1 + (c2*T) + (c3*RH) + (c4*T*RH) + (c5*(T**2)) + (c6*(RH**2)) + (c7*(T**2)*RH) + (c8*T*(RH**2)) + (c9*(T**2)*(RH**2))
            !If statements for background color & write the data to an html table.
              IF (Heat_Index <= 98 ) THEN
                  WRITE(1,*)"    <td style='background-color:#339933'>",Heat_Index,"</td>"  
              ELSE IF (Heat_Index > 98 .AND. Heat_Index <= 104) THEN
                  WRITE(1,*)"    <td style='background-color:#FFFF00'>",Heat_Index,"</td>" 
              ELSE IF (Heat_Index > 104 .AND. Heat_Index <= 112) THEN
                  WRITE(1,*)"    <td style='background-color:#FF9900'>",Heat_Index,"</td>" 
              ELSE IF (Heat_Index > 112) THEN
                  WRITE(1,*)"    <td style='background-color:#FF0000'>",Heat_Index,"</td>" 
              END IF
        
            !WRITE(*,*) RH,T,Heat_Index
          END DO !temp loop (T)

        WRITE(1,*)"  </tr>"  

      END DO !rh loop (RH)

  !Formatting to write data to a html formatted table.
    WRITE(1,*) "</table>"

END PROGRAM Reed_ATMS491_HW4