      PROGRAM read_c2

c----------------------------------------------------------------
c PROGRAM:  read_c2.f
c
c PURPOSE:  Reads HIRS C2 all-sky data files.
c
c LANGUAGE:  Fortran-77
c
c CREATION HISTORY:  Darren Jackson  CIRES/ETL October 2004
c-----------------------------------------------------------------

      IMPLICIT NONE

c Declarations

      BYTE      ispot,iref,iemis,icmask,icldfnl
      INTEGER*2 ilon,ilat,line,isolz,ialt,itb(7),ictt,isfct
      INTEGER*2 idif(4),icld(5)
      INTEGER   itime,i,j
      REAL      xlon,xlat,xsolz,xalt,tb(7),ctt,sfct,dif(4)

c Open and read C2 data

      OPEN(5,FILE='HIRS.N14.Y99.D031.A10.C2',ACCESS='DIRECT',RECL=55)
      DO i=1,10
         READ(5,rec=i) itime,ilon,ilat,line,ispot,isolz,ialt,iref,itb,
     .        iemis,ictt,isfct,idif,icmask,icld,icldfnl

c Make conversions

         xlon = ilon/100.
         xlat = ilat/100.
         xsolz =  isolz/100.
         xalt = ialt/10.
         DO j=1,7
            tb(j) = itb(j)/100. + 100.
         ENDDO
         ctt = ictt/100. + 100.
         sfct = isfct/100. + 100.
         DO j=1,4
            dif(j) = idif(j)/100.
         ENDDO
         
         WRITE(*,*) 'GMT time from Midnight in seconds = ',itime
         WRITE(*,*) 'Longitude (0-360) = ',xlon
         WRITE(*,*) 'Latitude (90S to 90N) = ',xlat
         WRITE(*,*) 'Line number = ',line
         WRITE(*,*) 'Scan spot = ',ispot
         WRITE(*,*) 'Solar zenith angle (degrees) = ',xsolz
         WRITE(*,*) 'Altitude (km) = ',xalt
         WRITE(*,*) 'Reflectance (%) = ',iref
         WRITE(*,*) 'Brightness Temperature (K)'
         DO j=1,7
	    IF(j .le. 5) THEN
               WRITE(*,*) '  HIRS CHANNEL ',j+3,' = ',tb(j)
	    ELSEIF(j .eq. 6) THEN
               WRITE(*,*) '  HIRS CHANNEL 10 = ',tb(j)
            ELSE
               WRITE(*,*) '  HIRS CHANNEL 12 = ',tb(j)
            ENDIF
         ENDDO
         WRITE(*,*) 'Cloud IR emissivity (%) = ',iemis
         WRITE(*,*) 'Cloud top temperature (K) = ',ctt
         WRITE(*,*) 'Surface Temperature (K) = ',sfct
         WRITE(*,*) 'Rclr - Rcld signal'
         DO j=1,4
            WRITE(*,*) '  HIRS CHANNEL ',j+3,' = ',dif(j)
         ENDDO
         WRITE(*,*) 'CLOUD MASK (0 = cloud, >0 = clear) = ',icmask
         WRITE(*,*) 'CLOUD HEIGHT SOLUTIONS (hPa)'
         DO j=1,5
            WRITE(*,*) '  SOLUTION ',j,' = ',icld(j)
         ENDDO
         WRITE(*,*) 'FINAL CLOUD HEIGHT SOLUTION (hPa) = ',icldfnl
         WRITE(*,*) ' '
         WRITE(*,*) '---------------------------'
         WRITE(*,*) ' '

      ENDDO
      CLOSE(5)
      END
