      SUBROUTINE TOZONE(HIRDAT, HIRANC, HNSPOT, HTOTLN, HDATEL, HNANC,
     1  RETANC, RNGRDP, RTOTLN, RNANC, TOZDAT, ULCHIR, ERSTAT)
      IMPLICIT NONE
C
C***********************************************************************
C
C   NAME- TOZONE
C
C   LANGUAGE- VS FORTRAN      TYPE- SUBROUTINE   
C
C   VERSION- 1.0      DATE- 8/12/92     PROGRAMMER-  DAVE MOREL (SMSRC)
C   VERSION- 2.0      DATE- 5/26/94     PROGRAMMER-  JEFF MANNING,SMSRC
C            XATOV-7  ADDED THE PARAMETER FILE /CDBPARM/ BEFORE THE
C            COMMON /COMCDB/.
C   VERSION- 2.1      DATE- 1/06/95     PROGRAMMER-  ALEX POZDNYAK,SMSRC
C            XATOV-94 HIRDAT(II,JJ,24) CHANGED TO HIRDAT(II,JJ,29).
C   VERSION- 2.1      DATE- 1/06/95     PROGRAMMER-  ALEX POZDNYAK,SMSRC
C            ATOVS-183 CHECK FOR ELEMENT 17 OF HIRANC BUFFER NOT EQUAL
C            TO A MISSING VALUE IS REPLACED BY A CHECK FOR THE LAST BIT
C            OF ELEMENT 14 OF HIRANC BUFFER EQUAL TO 1.
C   VERSION- 3.0      DATE- 06/03/96    PROGRAMMER-  TIM GARDNER (HSTX)
C   VERSION- 3.1      DATE- 01/29/96    PROGRAMMER-  LEAH WILSON (HSTX)
C   VERSION- 3.2      DATE- 06/17/97    PROGRAMMER-  LEAH WILSON (HSTX)
C   VERSION- 3.3      DATE- 07/28/97    PROGRAMMER-  LEAH WILSON (HSTX)
C   VERSION- 3.4      DATE- 09/17/97    PROGRAMMER-  LEAH WILSON (HSTX)
C   VERSION- 3.5      DATE- 11/19/97    PROGRAMMER-  LEAH WILSON (HSTX)
C   VERSION- 3.6      DATE- 05/06/98    PROGRAMMER-  LEAH WILSON (RSTX)
C   VERSION- 3.7      DATE- 10/05/98    PROGRAMMER-  LEAH WILSON (RSTX)
C   VERSION- 3.8      DATE- 08/16/99    PROGRAMMER-  A. ALLEGRINO (RITSS)
C   VERSION- 3.9      DATE- 10/01/99    PROGRAMMER-  A. ALLEGRINO (RITSS)
C   VERSION- 4.0      DATE- 11/15/99    PROGRAMMER-  A. ALLEGRINO (RITSS)
C   VERSION- 4.1      DATE- 11/23/99    PROGRAMMER-  A. ALLEGRINO (RITSS)
C   VERSION- 4.2      DATE- 11/29/99    PROGRAMMER-  A. ALLEGRINO (RITSS)
C   VERSION- 4.3      DATE- 12/01/99    PROGRAMMER-  A. ALLEGRINO (RITSS)
C   VERSION- 4.4      DATE- 12/06/99    PROGRAMMER-  A. ALLEGRINO (RITSS)
C   VERSION- 4.5      DATE- 12/16/99    PROGRAMMER-  A. ALLEGRINO (RITSS)
C   VERSION- 4.6      DATE- 11/01/00    PROGRAMMER-  FRANK TILLEY (RAYTHEON)
C   VERSION- 4.7      DATA- 06/04/02    PROGRAMMER-  RICH KELLEY (CSC)
C   VERSION- 5.0      DATE- 02/27/03    PROGRAMMER-  Rickey Rollins (CSC)
C   VERSION- 5.1      DATE- 09/04/03    PROGRAMMER-  Rickey Rollins (CSC)
C   VERSION- 5.2      DATE- 12/27/05    PROGRAMMER-  FRANK TILLEY (ERT)
C   VERSION- 5.3      DATE- 07/16/07    PROGRAMMER-  FRANK TILLEY (IMSG)
C
C   FUNCTION- THIS SUBROUTINE COMPUTES THE TOTAL OZONE FOR EACH
C   RETRIEVAL HIRS SPOT.  UPPER AND LOWER STRATOSPHERIC OZONE ARE
C   CALCULATED SEPARATELY, THEN ADDED.   WHEN ONE OF THE INPUTS IS
C   MISSING OR THE TOTAL VALUE IS TOO LOW, THE OUTPUT IS SET TO
C   A MISSING VALUE.
C
C   VERSION 3.0- DOCUMENTATION AND SYNTAX CHANGES FOR ATOVS BASELINE ON
C                THE CRAY.
C   VERSION 3.1- RTOVS UPGRADES - CHANGE ACCOUNTING FOR WARM SURGE DURING
C                STRATOSPHERIC WARMING FROM '.LT.OR.LT' TO '.LE.OR.LE'; ADD
C                CALL TO MAKSO2 TO CALCULATE SULFUR DIOXIDE; CHANGE TMPBAK
C                CALCULATION PER A. NEUENDORFFER'S REQUEST.
C   VERSION 3.2- CHANGE TMPBAK AGAIN PER A. NEUENDORFFER'S REQUEST.
C   VERSION 3.3- CONVERT CDB UTILITIES TO NEW 8-BYTE CONVENTION. REMOVE    
C                TOZON$ SINCE CDB UTILITES HANDLE ERRORS.  USE DEGRAD AS
C                A VARIABLE IN /RMPARM/ RATHER THAN A FUNCTION.  ADDS S/W
C                TO ONLY READ CDB COEFFICIENTS ONCE, SAVING THEM FOR 
C                FUTURE CALLS.
C   VERSION 3.4- AVERAGE UNLIMB CORRECTED HIRS CHANNEL 8 AND LIMB CORRECTED
C                HIRS CHANNEL 8 TO GET BACKGROUND TEMPERATURE.  USE SECANT
C                OF SATELLITE ZENITH ANGLE IN CALCULATIONS.
C   VERSION 3.5- RECALCULATE THE BACKGROUND TEMPERATURE USING 2/3 OF LIMB
C                CORRECTED HIRS8, ADDING 1/3 UNLIMB CORRECTED HIRS 8, AND
C                SUBTRACTING ONE.
C   VERSION 3.6- CHANGE TMPBAK AGAIN PER A. NEUENDORFFER'S REQUEST.
C   VERSION 3.7- CHANGE CLEAR/CLOUDY DETERMINATION CRITERIA TO MATCH RTOVS.
C                CHANGE TMPBAK PER A.NEUENDORFFER'S EMAIL.
C   VERSION 3.8- SUBTRACTED A CONSTANT FROM THE SO2 VALUES TO  MATCH RTOVS.
C   VERSION 3.9- SET THE VARIABLE SURGWM TO ZERO PER A. NEUENDORFFER'S REQUEST.
C   VERSION 4.0- CHANGED THE EPILSON CALCULATION FROM 2.0E-7 FOR CLEAR AND
C                12.0E-7*EQUIL**3 FOR CLOUDY TO 1.0E-7 FOR CLEAR AND 3.0E-7
C                *EQUIL**3 FOR CLOUDY PER A. NEUENDORFFER'S REQUEST.
C   VERSION 4.1- ADDED CODE TO USE HIRS CH 4 TO SCREEN FOR CIRRUS.        
C   VERSION 4.2- CHANGED THE HIRS CH4 CIRRUS TEST THRESHOLD FROM 207 TO
C                209 AND CHANGED THE EPSLON CONSTANT FOR CLOUDY FROM 3.0E-7
C                TO 1.5E-7 PER A. NEUENDORFFER'S REQUEST.
C   VERSION 4.3- CHANGED THE LOWER OZONE CALCULATION CONSTANT FROM -400 TO
C                -375
C   VERSION 4.4- CHANGED THE CIRRUS TEST TO USE HIRS CHANNEL 12 INSTEAD OF 
C                HIRS CHANNEL 4  PER A. NEUENDORFFER'S REQUEST.
C   VERSION 4.5- CHANGED THE CIRRUS TEST TO USE A COMBINATION OF HIRS CHANNEL
C                12 AND 4 AND, AMSU-A CHANNEL 7 PER A. NEUENDORFFER'S REQUEST.
C   VERSION 4.6- ADDED CODE TO SKIP OVER NOHIRS RETRIEVALS. (WR #121)
C   VERSION 4.7- MODIFIED CONSTANT IN THE COMPUTATION OF THE EFFECTIVE 
C                PLANCK RADIANCE.  PREVIOUSLY THE CONSTANT HAD A VALUE OF 1.44,
C                NOW IT TAKES ON A VALUE OF 1.4387752.  THIS WAS DONE IN RES-
C                PONSE TO FPDT PR47 DATED 8/13/2001.  
C   VERSION- 5.0    DATE- 02/27/03   PROGRAMMER- Rickey Rollins (CSC)
C        Replace R4SPV equivalence test with ISR4SPV function 
C   VERSION- 5.1    DATE- 09/04/03   PROGRAMMER- Rickey Rollins (CSC)
C                Used INT function in MOD to integerize RETANC
C   VERSION 5.2- ADDED COMMON /HIRUSE/ AND LOCAL VARIABLE 'HIRCH1'. WHEN
C                /HIRUSE/:H1REPL IS FALSE, HIRCH1 IS HIRS CHANNEL 1 BT.
C                WHEN H1REPL IS TRUE, HIRS CHANNEL 1 BT IS REPLACED WITH
C                THE AVERAGE OF AMSU-A CHANNEL 10-14 BTS FOR OZONE
C                CALCULATION (WR #286). CHANGED MINIMUM OZONE FROM 99 TO
C                85 DOBSON UNITS. REMOVED CODE THAT RESET SURGWM TO 0.0
C                AFTER ITS COMPUTATION.
C   VERSION 5.3- RESET THE SURGE OF WARM AIR (SURGWM) VALUE TO 0.0 BECAUSE
C                IT RESULTED IN ABNORMALLY HIGH OZONE VALUES. EXPLICITLY
C                CONVERTED SPOT NUMBER TO INTEGER BEFORE USING IT TO
C                CALCULATE THE LINE NUMBER IN THE BUFFER (WR #307).
C
C   FILES-
C        DSN             UNIT     I/O    FUNCTIONAL DESCRIPTION
C   ----------------    -------  -----   ----------------------
C   //.. ... .CDB       CDBUNT     I     COEFFICIENT DATABASE
C
C   CALLING SEQUENCE PARAMETERS-
C
C   NAME    TYPE  I/O    DESCRIPTION
C   ----    ----  ---    -----------
C   HIRDAT  REAL   I     HIRS DATA BUFFER, DIMENSIONED(HNSPOT,HTOTLN,
C                        HDATEL).
C
C   HIRANC  REAL   I     HIRS ANCILLARY BUFFER, DIMENSIONED(HNSPOT,
C                        HTOTLN,HNANC).
C
C   HNSPOT  INT    I     NUMBER OF SPOTS PER SCAN LINE.
C
C   HTOTLN  INT    I     NUMBER OF SCAN LINES IN THE HIRS DATA BUFFERS.
C
C   HDATEL  INT    I     NUMBER OF DATA ELEMENTS IN THE BUFFER HIRDAT.
C
C   HNANC   INT    I     NUMBER OF DATA ELEMENTS IN THE BUFFER HIRANC.
C
C   RETANC  REAL   I     RETRIEVAL ANCILLARY BUFFER, DIMENSIONED
C                        (RNGRDP X RTOTLN X RNANC).
C
C   RNGRDP  INT    I     RETRIEVAL NUMBER OF GRID POINTS.
C
C   RTOTLN  INT    I     RETRIEVAL GRID TOTAL LINE NUMBER.
C
C   RNANC   INT    I     RETRIEVAL NUMBER OF ANCILLARY DATA.
C
C   TOZDAT  REAL  I/O    TOTAL OZONE (IN DOBSON UNITS), DIMENSIONED
C                        (RNGRDP,RTOTLN,2).  SECOND ELEMENT STORES
C                        SULFUR DIOXIDE CONTENT.
C   
C   ULCHIR  REAL   I     UN-LIMB CORRECTED HIRS CHANNELS (DIMENSIONED
C                        (HNSPOT X HTOTLN X 2, WHERE 1=HIRS CHANNEL 8
C                        AND 2=HIRS CHANNEL 9)
C
C   ERSTAT  INT    O     ERROR STATUS CODE RETURNED.
C                        0  - NO ERROR
C                        99 - FATAL ERROR
C
C   COMMOM AREA PARAMETERS - SPGUNT, SPVAL
C
C   LOCAL VARIABLES
C   NAME      TYPE       DESCRIPTION
C   ----      ----       -----------
C   I,J       INT        DO LOOP VARIABLES.
C   II        INT        HIRS SPOT NUMBER BELONGING TO RETRIEVAL GRID.
C   JJ        INT        HIRS LINE NUMBER BELONGING TO RETRIEVAL GRID.
C   LAPSE     REAL       TROPOPAUSE LAPSE RATE.
C   ANOMLY    REAL       LOWER STRATOSPHERIC TEMPERATURE ANOMALY.
C   TMPDIF    REAL       TEMPERATURE DIFFERENCE.
C   SURGWM    REAL       SURGES OF WARM OZONE DURING WARMING.
C   EQUIL     REAL       CLIMATOLOGICAL EQUILIBRIUM OZONE COMPONENT.
C   ESU       REAL       EQUIL + SURGWM. (NONDIMENSIONAL)
C   COEFA     REAL       COEFFICIENT A.
C   COEFB     REAL       COEFFICIENT B.
C   COEFC     REAL       COEFFICIENT C.
C   COEFD     REAL       COEFFICIENT D.
C   ABSUPR    REAL       UPPER STRATOSPHERIC OZONE LINE ABSORPTION.
C   TRNLWR    REAL       LOWER STRATOSPHERIC OZONE LINE TRANSMISSION.
C   OZUPR     REAL       UPPER STRATOSPHERIC OZONE.
C   OZLWR     REAL       LOWER STRATOSPHERIC OZONE.
C   TMPBAK    REAL       BACKGROUND TEMPERATURE IN LOWER STRATOSPHERE.
C   TMPFOR    REAL       FOREGROUND TEMPERATURE IN LOWER STRATOSPHERE.
C   RADBAK    REAL       RADIANCE BACKGROUND, DERIVED FROM TMPBAK.
C   RADFOR    REAL       RADIANCE FOREGROUND, DERIVED FROM TMPFOR.
C   RADCH1    REAL       RADIANCE OF CHANNEL 1.
C   RADCH9    REAL       RADIANCE OF CHANNEL 9.
C   RADCC9    REAL       CORRECTED RADIANCE OF CHANNEL 9.
C   EPSLON    REAL       EPSILON VALUES: 2.0E-7 FOR CLEAR AND
C                        12.0E-7*EQUIL**3 FOR CLOUDY.
C   LOGTRN    REAL       NATURAL LOG OF TRNLWR.
C   LATTUD    REAL       LATITUDE IN RADIANS.
C   PLANCK    REAL       STATEMENT FUNCTION TO COMPUTE PLANCK RADIANCE
C                        FORMULA.
C   STATUS    INT        ERROR STATUS RETURNED FROM REALCOEF.
C   TEMP      REAL       TEMPERATURE IN K.
C   RTEMP     REAL       TEMPORARY VARIABLE (REAL TYPE) FOR THE CLOUD
C                        TEST RESULTS.
C   ITEMP     REAL       TEMPORARY VARIABLE (INTEGER TYPE) FOR THE CLOUD
C                        TEST RESULTS.
C   SO2       REAL       SULFUR DIOXIDE CONTENT.
C   FIRST     LOGICAL    DENOTES IF THIS IS THE FIRST CALL TO TOZONE.
C   SECANG    REAL       SECANT OF THE SATELLITE ZENITH ANGLE.
C   HIRCH1    REAL       EITHER HIRS CHANNEL 1 BRIGHTNESS TEMPERATURE OR
C                        THE MEAN OF AMSU-A CHANNELS 10-14, DEPENDING ON
C                        THE VALUE OF /HIRUSE/:H1REPL

C
C
C   SUBPROGRAMS CALLED- REALCOEF, MAKSO2
C
C   FUNCTIONS USED- EXP,MOD,REAL,COS,SQRT,PLANCK,LOG,BTEST
C
C   EXIT STATES- ROUTINE WILL RETURN IF THERE IS A PROBLEM OBTAINING
C                CDB VALUES.
C
C***********************************************************************
C
      INTEGER HNSPOT,HTOTLN,HDATEL,HNANC, RNGRDP,RTOTLN,RNANC, ERSTAT
      REAL HIRDAT(HNSPOT,HTOTLN,HDATEL), HIRANC(HNSPOT,HTOTLN,HNANC)
      REAL TOZDAT(RNGRDP,RTOTLN,2), RETANC(RNGRDP,RTOTLN,RNANC)
      REAL ULCHIR(HNSPOT,HTOTLN,2), RTFLAG
C
      INTEGER STATUS, I,J,II,JJ, ITEMP
      LOGICAL FIRST
      LOGICAL   ISR4SPV
      REAL LAPSE, ANOMLY, TMPDIF, SURGWM, EQUIL, ESU, ABSUPR, TRNLWR,
     +          OZUPR, OZLWR, COEFA, COEFB, COEFC, COEFD, SO2
      REAL TMPBAK, TMPFOR, RADBAK, RADFOR, RADCH1, RADCH9, RADCC9,
     +          EPSLON, LOGTRN, LATTUD, PLANCK, TEMP, RTEMP, SECANG
      REAL HIRCH1
C
      EQUIVALENCE (ITEMP,RTEMP)
      DATA FIRST /.TRUE./
      SAVE FIRST,COEFA,COEFB,COEFC,COEFD
C
      INCLUDE 'SPGUNT'
      INCLUDE 'SPVAL'
      INCLUDE 'RMPARM'
      INCLUDE 'HIRUSE'
C
C STATEMENT FUNCTION TO COMPUTE THE EFFECTIVE PLANCK RADIANCE FORMULA.
C
C     PLANCK(TEMP) = 1.0 / (EXP(1.44 * 1030. / TEMP) - 1.)
      PLANCK(TEMP) = 1.0 / (EXP(1.4387752 * 1030.0 / TEMP) - 1.0)
C
C  OBTAIN THE OZONE COEFFICIENTS FROM THE CDB.
C
      IF(FIRST) THEN
         CALL REALCOEF(CDBUNT,'GOODIES ','TOTOZONE','COEFA   ',1,0,
     +                 0,0,COEFA,'GET',STATUS)
         IF(STATUS.NE.0) GO TO 900
         CALL REALCOEF(CDBUNT,'GOODIES ','TOTOZONE','COEFB   ',1,0,
     +                 0,0,COEFB,'GET',STATUS)
         IF(STATUS.NE.0) GO TO 900
         CALL REALCOEF(CDBUNT,'GOODIES ','TOTOZONE','COEFC   ',1,0,
     +                 0,0,COEFC,'GET',STATUS)
         IF(STATUS.NE.0) GO TO 900
         CALL REALCOEF(CDBUNT,'GOODIES ','TOTOZONE','COEFD   ',1,0,
     +                 0,0,COEFD,'GET',STATUS)
         IF(STATUS.NE.0) GO TO 900
         FIRST = .FALSE.
      ENDIF
C
C  LOOP OVER THE SPOTS AND SCAN LINES IN THE RETRIEVAL BUFFER.
C
      DO 30 J = 1, RTOTLN
         DO 20 I = 1, RNGRDP
C
C   IF THE RETRIEVAL FLAG SHOWS A NOHIRS RETRIEVAL, SKIP TO
C   THE NEXT RETRIEVAL.
C
            IF (RETANC(I,J,4) .EQ. 48.0) THEN
               TOZDAT(I,J,1) = R4SPV
               TOZDAT(I,J,2) = R4SPV
               GO TO 20
            ENDIF
C
C   COMPUTE ACTUAL HIRS SPOT AND LINE NUMBER.  THIS CANNOT BE DONE
C   IF THE HIRS SPOT NUMBER STORED IN RETANC IS INVALID.
C
            IF (RETANC(I,J,1) .LE. 0.) THEN   
               TOZDAT(I,J,1) = R4SPV
               TOZDAT(I,J,2) = R4SPV
               GO TO 20
            ENDIF
            JJ=(RETANC(I,J,1)/HNSPOT) + 1
            II=MOD(INT(RETANC(I,J,1)),HNSPOT)
            IF (II .EQ. 0) THEN
               JJ=JJ-1
               II=HNSPOT
            ENDIF
C
C  SET THE VALUE FOR HIRS CHANNEL 1 AS EITHER THE LIMB CORRECTED
C  HIRS CHANNEL 1 BRIGHTNESS TEMPERATURE OR AS THE MEAN OF
C  LIMB CORRECTED AMSU-A CHANNELS 10-14.
C
            IF (.NOT.(H1REPL)) THEN
               HIRCH1 = HIRDAT(II,JJ,1)

C  SET HIRS CHANNEL 1 TO MISSING IF ANY OF THE AMSU-A CHANNELS
C  USED TO CALCULATE A MEAN BT FOR REPLACING HIRS CHANNEL 1 IS
C  MISSING.
C
            ELSE
               IF (ISR4SPV(HIRDAT(II,JJ,30)) .OR.
     +             ISR4SPV(HIRDAT(II,JJ,31)) .OR.
     +             ISR4SPV(HIRDAT(II,JJ,32)) .OR.
     +             ISR4SPV(HIRDAT(II,JJ,33)) .OR.
     +             ISR4SPV(HIRDAT(II,JJ,34))) THEN
                   HIRCH1 = R4SPV
               ELSE
                   HIRCH1 = (HIRDAT(II,JJ,30) +
     +                       HIRDAT(II,JJ,31) +
     +                       HIRDAT(II,JJ,32) +
     +                       HIRDAT(II,JJ,33) +
     +                       HIRDAT(II,JJ,34)) / 5.0
               END IF
            END IF

C
C  CHECK FOR MISSING HIRS CHANNEL VALUES IN ORDER OF IMPORTANCE.
C  SET THE OZONE TO A MISSING VALUE IF ANY ARE MISSING.
C
            IF (HIRCH1 .LE. 0. .OR. ISR4SPV(HIRDAT(II,JJ,29))
     +              ) THEN    
               TOZDAT(I,J,1) = R4SPV
               GO TO 15
            ENDIF
            IF (ISR4SPV(HIRANC(II,JJ,1)) .OR. ISR4SPV(HIRDAT(II,JJ,8))
     +               ) THEN   
               TOZDAT(I,J,1) = R4SPV
               GO TO 15
            ENDIF
            IF (ISR4SPV(HIRDAT(II,JJ,3)) .OR. ISR4SPV(HIRDAT(II,JJ,9))
     +               ) THEN    
               TOZDAT(I,J,1) = R4SPV
               GO TO 15
            ENDIF
            IF (ISR4SPV(HIRDAT(II,JJ,10)) .OR. ISR4SPV(HIRDAT(II,JJ,2))
     +               ) THEN   
               TOZDAT(I,J,1) = R4SPV
               GO TO 15
            ENDIF
C
C  CHECK HIRS CH 12 TO SCREEN FOR CIRRUS CLOUDS.
C  MODIFIED ON 12/16/99 TO USE A COMBINATION OF HIRS CHANNEL 4 & 12 AND
C  AMSU-A CHANNEL 7 TO CHECK FOR CIRRUS CLOUDS.
C
C  COMMENTED OUT AT A. NEUENDORFFER'S REQUEST (WR #286)
C
C           IF((HIRDAT(II,JJ,12) + HIRDAT(II,JJ,4)) .LE.
C    >(HIRDAT(II,JJ,27) + 219)) THEN
C              TOZDAT(I,J,1) = R4SPV
C              GO TO 15
C           ENDIF
            
C
C ************* COMPUTE THE UPPER STRATOSPHERIC OZONE. **************
C ### COMMENTED OUT CALCULATION OF SURGWM IN VERSION 5.3 ###
C
C  COMPUTE TROPOPAUSE LAPSE RATE.
C
c           LAPSE = HIRDAT(II,JJ,2) - HIRDAT(II,JJ,3) - 1.
C
C  COMPUTE LOWER STRATOSPHERIC TEMPERATURE ANOMALY.
C
c           ANOMLY = 2. * HIRDAT(II,JJ,2) - HIRCH1 - 205.
C
c           TMPDIF = LAPSE * ANOMLY / 40.
C
C  ACCOUNT FOR THE SURGE OF WARM OZONE INTO A NARROW REGION DURING
C  A MAJOR STRATOSPHERIC WARMING.  IN MOST CASES IT WILL BE ZERO.
C
c           IF(LAPSE .LE. 0.0 .OR. ANOMLY .LE. 0.0) THEN
c              SURGWM = 0.
c           ELSE
c              SURGWM = TMPDIF * (1. + TMPDIF * (2. + TMPDIF)) *
c    +               (270. + HIRANC(II,JJ,1)) / 9000.
c           ENDIF
C
C -------------------------------------------------------------------
C-- SET SURGWM TO 0.0.
C
           SURGWM = 0.0
C
C  CONVERT THE LATITUDE TO RADIANS.
C
            LATTUD = DEGRAD*HIRANC(II,JJ,1)

C  COMPUTE CLIMATOLOGICAL EQUILIBRIUM OZONE COMPONENT.
C
            EQUIL = 0.9 + 1.1 * COS(LATTUD)
C
            ESU = EQUIL + SURGWM
C
C  CALCULATE UPPER STRATOSPHERIC OZONE LINE ABSORPTION.
C
            SECANG = 1.0/(COS(1.00*(HIRANC(II,JJ,5)*3.1415/180.0)))
            ABSUPR = 0.18 * SQRT(ESU*SECANG)
C
            OZUPR = 102.0 * ESU
C
C ************* COMPUTE THE LOWER STRATOSPHERIC OZONE. **************
C
C  DETERMINE FOREGROUND AND BACKGROUND TEMPERATURES, AND UNDO WATER
C    VAPOR CORRECTIONS IF NEEDED.
C
            TMPBAK = (0.85*HIRDAT(II,JJ,8)) + (0.15*HIRDAT(II,JJ,10))
            TMPFOR=(HIRDAT(II,JJ,2)*COEFC+HIRDAT(II,JJ,29)*COEFD)
     +               / (COEFC + COEFD)
C
C  SET OZONE TO A MISSING VALUE IF UPPER STRATOSPHERIC TEMPERATURE (HIRS
C  CHANNEL 1) EXCEEDS THE AVERAGE OF THE BACKGROUND TEMPERATURE AND
C  HIRS CHANNEL 9.
C
        IF(HIRCH1 .GT. (TMPBAK + ULCHIR(II,JJ,2)) / 2.) THEN   
           TOZDAT(I,J,1) = R4SPV
           GO TO 15
        ENDIF
C
C  CONVERT BRIGHTNESS TEMPERATURES TO RADIANCES.
C
            RADBAK = PLANCK(TMPBAK)
            RADFOR = PLANCK(TMPFOR)
            RADCH9 = PLANCK(ULCHIR(II,JJ,2))
            RADCH1 = PLANCK(HIRCH1)
C
C  REMOVE EFFECTS OF THE UPPER STRATOSPHERE FROM HIRS CHANNEL 9
C     RADIANCE VALUES.
C
            RADCC9 = (RADCH9 - ABSUPR * RADCH1) / (1 - ABSUPR)
C
C  CHECK THE LAST BIT OF SECOND WORD OF CLOUD TEST RESULTS.
C  IF IT IS EQUAL TO 1 THEN THE RESULT IS NOT CLEAR.
C
            RTEMP = HIRANC(II,JJ,14)
            IF ( BTEST(ITEMP,0) ) THEN
C
C  SET THE EPSILON VALUE FOR CLOUDY AND N* RETRIEVALS.
C
               EPSLON = 1.5E-7 * EQUIL * EQUIL * EQUIL
C
            ELSE
C  SET THE EPSILON VALUE FOR CLEAR RETRIEVALS.
C
               EPSLON = 1.0E-7
            ENDIF
C
C  SET OZONE TO A MISSING VALUE IF NUMERATOR AND DENOMINATOR OF TRNLWR
C          EXPRESSION ARE NOT LARGE ENOUGH.
C
            IF(((RADCC9-RADFOR)*(RADBAK-RADFOR)) .LE. EPSLON) THEN
               TOZDAT(I,J,1) = R4SPV
              GO TO 15
            ENDIF
C
C  SOLVE FOR LOWER STRATOSPHERIC OZONE LINE TRANSMISSION.
C
            TRNLWR = (RADCC9 - RADFOR) / (RADBAK - RADFOR)
C
C  INVERT BEERS' LAW (TRNLWR = EXP(-OZLWR/400)) TO SOLVE FOR LOWER
C     STRATOSPHERIC OZONE.
C
            LOGTRN = LOG(TRNLWR)
            OZLWR = -375. * (LOGTRN + 0.2 * LOGTRN * LOGTRN * LOGTRN)
C
C ********************* TOTAL OZONE VALUE. **************************
C
            TOZDAT(I,J,1) = OZUPR + (OZLWR/SECANG)
C
C  SET OZONE TO A MISSING VALUE IF LESS THAN 85 DOBSON UNITS.
C
            IF(TOZDAT(I,J,1) .LE. 85.) TOZDAT(I,J,1) = R4SPV
C
C  CALCULATE SULFUR DIOXIDE.
C
   15       CONTINUE
            CALL MAKSO2(HIRDAT(II,JJ,10),HIRDAT(II,JJ,11),
     1                  HIRDAT(II,JJ,12),TOZDAT(I,J,2))
            TOZDAT(I,J,2)=TOZDAT(I,J,2) -6.0
C
   20    CONTINUE
   30 CONTINUE
      RETURN
C
C     SET FATAL ERROR FLAG IF THERE IS A PROBLEM WITH CDB VALUES.
C
  900 ERSTAT=99
      RETURN
      END
