!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer,
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer
!version 3 or (at your option) any later version that should be found at:
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software;
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec),
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
!


      SUBROUTINE NEW_OZONE(O3P, fozo,totozo,toto3obs,zlat,  & 1,1
     &                          plev,nlev,po3,nlato3,nlevo3,nprf)

#if defined (DOC)
!***********************************************************************
!
!**ID NEW_OZONE -- GET OZONE PROFILE FROM CLIMATOLOGY INTERPOLATED TO DESIRED P LEVELS
!
!       AUTHOR:   A. BEAULNE (CMDA/SMC) March 2006
!
!       REVISION:
!
!       OBJECT:   GET OZONE PROFILE FROM CLIMATOLOGY INTERPOLATED TO DESIRED P LEVELS
!
!       ARGUMENTS:
!          INPUT:
!            -FOZO(NLATO3,NLEVO3) : CLIMATOLOGICAL OZONE FIELD (PPMV)
!            -TOTOZO(NLATO3,12)   : CLIMATOLOGICAL TOTAL OZONE
!            -TOTO3OBS(NPRF)      : TOTAL OZONE IF KNOWN FROM OUTSIDE SOURCE SUCH AS TOMS
!            -ZLAT(NPRF)          : ARRAY OF LATITUDE (-90S TO 90N)
!            -PLEV(NLEV)          : PRESSURE LEVELS (HPA)
!            -NLEV                : NUMBER OF VERTICAL LEVELS
!            -PO3(NLEVO3)         : PRESSURE LEVELS IN CLIMATOLOGY FILE (HPA)
!            -NLATO3              : NUMBER OF LATITUDES IN CLIMATOLOGY FILE
!            -NLEVO3              : NUMBER OF VERTICAL LEVELS IN CLIMATOLOGY FILE
!            -NPRF                : NUMBER OF PROFILES
!
!          OUTPUT:
!            -O3P(NLEV,NPRF)      : OZONE PROFILES (PPMV)
!
!
***********************************************************************
#endif

      IMPLICIT NONE       

!implicits
#include "comdimo.cdk"
#include "comoabdy.cdk"
#include "comoahdr.cdk"
#include "comoba.cdk"
#include "comlun.cdk"


      INTEGER   :: JN, K, NLEV, NLATO3, NLEVO3, NPRF, NUMLAT(NPRF)
      INTEGER   :: IJOUR,IJ,IMONTH
      REAL      :: FOZO(NLATO3,NLEVO3), TOTOZO(NLATO3,12)
      REAL(8)   :: QO3B(NLEVO3,NPRF),O3P(NLEV,NPRF)
      REAL(8)   :: ZLAT(NPRF), TOTO3OBS(NPRF)
      REAL(8)   :: PLEV(NLEV), PO3(NLEVO3), PRO3(NLEVO3,NPRF)


!* assign default qgas values if need be

      DO JN = 1, NPRF
        NUMLAT(JN) = NINT( (ZLAT(JN)+90.) / (180./(REAL(NLATO3-1))) ) + 1
        DO K = 1, NLEVO3
          QO3B(K,JN) = FOZO(NUMLAT(JN),K)
        END DO
      END DO

!* interpolation of field QO3B at NLEVO3 levels of height PO3mbb
!* into field O3P at NLEV levels of height XPRES

      FORALL(K=1:NLEVO3) PRO3(K,:) = PO3(K)

      CALL LINTV2(pro3,qo3b,nlevo3,nlevo3,nprf,nlev,plev,O3P)


!* if total climatological ozone is known from outside source
!* then set the climatological profile so that it matches that total

      DO JN = 1, NPRF
        IF ( NINT(TOTO3OBS(JN)) /= 0 ) THEN
          IJOUR = MOBHDR(NCMDAT,1)
          IJ = IJOUR/100
          IMONTH = IJ - (IJ/100)*100
          O3P(:,JN) = O3P(:,JN) * TOTO3OBS(JN) / TOTOZO(NUMLAT(JN),IMONTH)
        END IF
      ENDDO


      END SUBROUTINE NEW_OZONE