!-------------------------------------- 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 OBSINCR(KULOUT) 1
#if defined (DOC)
*
***s/r OBSINCR  - output of the analysis increments at a single
*     .           point and along the zonal and meridional direction
*     .           passing through this point
*     .
*
*Author  : P. Gauthier *ARMA/AES  Dec. 10, 1993
*
*Revision: L. Fillion *ARMA/AES Feb 95.
*                      Generalization of the subroutine.
*                      The longitudinal direction being not a great circle, should be
*                      discarded except for very short variation about the obs. point.
*                      Comdeck comsim was introduced and computations are done at the
*                      vertical level of the observation.
*          S. Pellerin *ARMA/AES Sep 97
*                       Change from TT to GZ variable.
*
*Arguments
*     i-  KULOUT  : unit used for output
*
#endif
C
      IMPLICIT NONE
#include "pardim.cdk"
#include "comdim.cdk"
#include "comdimo.cdk"
#include "comlun.cdk"
#include "comcst.cdk"
#include "comgd0.cdk"
#include "comgem.cdk"
#include "comleg.cdk"
#include "comsim.cdk"
#include "comspg.cdk"
#include "comoahdr.cdk"
#include "comoabdy.cdk"
#include "comoba.cdk"
#include "compstat.cdk"
      INTEGER KULOUT
C
      INTEGER  JLON, JLAT, II
      REAL*8     ZUU, ZVV, ZTT, ZDIST, ZR, ZLON, ZLON0
     S     ,ZUU2, ZVV2, ZTT2, ZSIGPHI, ZWEIGHT, ZEXACT
      REAL*8   DLDIST, DLENSC2, DLCORR
C
C*    1.  Values of the increments at the observation point
C
 100     CONTINUE
      WRITE(NULOUT,FMT=9100)
 9100 FORMAT(//,10X,"Simulated Obs.: Values of analysis"
     S     ," increments at the observation point")
C
      ZUU = UT0(MLONOBS,MLEVOBS,MLATOBS)*CONPHY(MLATOBS)
      WRITE(NULOUT,FMT='(//,4X,"Ua - Ug = ",g12.6)')ZUU
      ZVV = VT0(MLONOBS,MLEVOBS,MLATOBS)*CONPHY(MLATOBS)
      WRITE(NULOUT,FMT='(//,4X,"Va - Vg = ",g12.6)')ZVV
      ZTT = GZ0(MLONOBS,MLEVOBS,MLATOBS)
      ZSIGPHI = RGSIGUU(MLATOBS,MLEVOBS)*RCSCLVO(MLEVOBS)
     S     *2.*ROMEGA*RMU(MLATOBS)
      ZSIGPHI = ZSIGPHI**2
      ZWEIGHT = ROBDATA8(NCMOER,1)**2 + ZSIGPHI
      ZWEIGHT = ZSIGPHI/ZWEIGHT
      ZEXACT = -ROBDATA8(NCMOMF,1)*ROBDATA8(NCMOER,1)*ZWEIGHT
      WRITE(NULOUT,9101)ZTT,ZEXACT
 9101 FORMAT(//,4X,'PHIa - PHIb = ',G20.10, 4X,'Theor. Value: '
     S     ,G20.10)
C
C*    2.  Zonal variation of the analysis increment
C
 200  CONTINUE
      WRITE(NULOUT,FMT=9200)
 9200 FORMAT(//,10X,"Simulated Obs.: zonal variation of the"
     S     ," increment",/,3X,"r",1x,"$","UU",1x,"$"
     S     ,"VV",1x,"$","TT")
C
      ZR    = RA*COS(RLATI(MLATOBS))/1000.
      ZLON0 = 2.*RPI*(MLONOBS-1)/FLOAT(NILON(MLATOBS))
      DO JLON = 1,NI
         ZLON = 2.*RPI*(JLON-1)/FLOAT(NILON(MLATOBS))
         ZDIST = ZR * (ZLON - ZLON0)
         ZUU =  UT0(JLON,MLEVOBS,MLATOBS)*CONPHY(MLATOBS)
         ZVV =  VT0(JLON,MLEVOBS,MLATOBS)*CONPHY(MLATOBS)
         ZTT =  GZ0(JLON,MLEVOBS,MLATOBS)
         WRITE(NULOUT,FMT='(2X,G12.6,3(2x,"$",G12.6))')
     S        ZDIST,ZUU,ZVV,ZTT
      END DO
C
C*    3.  Meridional  variation of the analysis increment
C
 300  CONTINUE
      WRITE(NULOUT,FMT=9300)
 9300 FORMAT(//,10X,"Simulated Obs.: meridional variation of the"
     S     ," increment",/,3X,"r",1x,"$","PHI",1x,"$"
     S     ,"UU",1x,"$","VV")
C
      ii = mlonobs + ni/2
      ii = mod(ii-1,ni)+1
      DO JLAT = 1, NJ
         ZDIST = RA * ABS((RLATI(JLAT) - RLATI(MLATOBS)))/1000.
         ZUU  =  UT0(MLONOBS,MLEVOBS,JLAT)*CONPHY(JLAT)
         ZUU2 =  UT0     (ii,MLEVOBS,JLAT)*CONPHY(JLAT)
         ZVV  =  VT0(MLONOBS,MLEVOBS,JLAT)*CONPHY(JLAT)
         ZVV2 =  VT0     (ii,MLEVOBS,JLAT)*CONPHY(JLAT)
         ZTT  =  GZ0(MLONOBS,MLEVOBS,JLAT)
         ZTT2 =  GZ0     (ii,MLEVOBS,JLAT)
         WRITE(NULOUT,FMT='("%%",2X,F6.1,6(1x,G12.6))')
     S        RLATI(JLAT)*180./RPI,ZTT,ZTT2,ZUU,ZUU2,ZVV,ZVV2
      END DO
C
      WRITE(NULOUT,FMT=9310)
 9310 FORMAT(//,10X,"Simulated Obs.: normalized meridional variation"
     S     ," of the increment",/,3X,"r",1x,"$","UU",1x,"$"
     S     ,"VV",1x,"$","TT",1X,"$","GAUSS")
C
C     GAUSSIAN CORRELATION ALSO COMPUTED
C
      DLENSC2 = 1.D0/DBLE(RCSCLVO(MLEVOBS)/1000.)
      DLENSC2 = 0.5*DLENSC2*DLENSC2
      DO JLAT = MLATOBS, NJ
        DLDIST = RA * ABS((RLATI(JLAT) - RLATI(MLATOBS)))/1000.
        DLCORR = DEXP(-(DLDIST**2)*DLENSC2)
        ZUU = (UT0(MLONOBS,MLEVOBS,JLAT)
     S       /UT0(MLONOBS,MLEVOBS,MLATOBS))*CONPHY(JLAT)
        ZVV = (VT0(MLONOBS,MLEVOBS,JLAT)
     S       /VT0(MLONOBS,MLEVOBS,MLATOBS))*CONPHY(JLAT)
        ZTT = (GZ0(MLONOBS,MLEVOBS,JLAT)/GZ0(MLONOBS,MLEVOBS,MLATOBS))
        WRITE(NULOUT,FMT='(2X,G12.6,4(2x,"$",G12.6))')
     S        DLDIST,ZUU,ZVV,ZTT,DLCORR
      END DO
C
      RETURN
      END