SUBROUTINE CH_OBSTYP(KIND,KIND2,KNDESC,CDSTNID,KOBSTYP,KDESC) 1
*
      IMPLICIT NONE
*
      CHARACTER*(*) CDSTNID
      INTEGER KIND,KIND2,KNDESC,KOBSTYP
      INTEGER KDESC(kndesc)
*
#if defined (DOC)
*-----------------------------------------------------------------------
*
***s/r CH_OBSTYP - Set observation handling flag KOBSTYP. 
*                  This flag identifies which forward model, 
*                  and related adjoint model and TLM, are to be used
*                  for observation (see CH_JOCALC, CH_ODA_H*tr, and CH_ONEOBS)
*
*
*Author    . Y.J. Rochon and Y. Yang, *AQRB/MSC June 2005 
*            Based on initial code by Y. Yang
*
*Revision:
*          Y.J. Rochon ARQX/EC Apr 2009
*          - Updated for use with newly official constituent descriptors
*            (in addition to previous local descriptors).
*          Y.J. Rochon ARQX/EC fEB 2013
*          - Added column sums for 15024.
*         
*
*   PURPOSE:  Set observation handling flag KOBSTYP. 
*             This flag identifies which forward model, 
*             and related adjoint model and TLM, are to be used
*             for observation (see CH_JOCALC, CH_ODA_H*TR, and CH_ONEOBS)
*
*   ARGUMENTS:
*
*               INPUT:
*
*                   KIND    : Flag indicating presence of reference 
*                             vertical coordinate profile (<0 for no)
*                   KIND2   : Flag indicating presence of second reference
*                             vertical coordinate profile (<0 for no)
*                   KNDESC  : Number of obs descriptors found
*                   KDESC   : List of obs descriptors found 
*                   CDSTNID : Stn id (can also represent instrument)
*                             - Not currently used but could be used in
*                             combination with KDESC to set KOBSTYP for
*                             special processing dependent on instrument.
*                
*               OUTPUT:
* 
*                   KOBSTYP  : Flag for observation handling
*                              to be stored in MOBHDR(NCMCORD1, IOBS)
*                              1:  Observation to be treated as point by point 
*                                  profile
*                              2:  Observation to be treated as piecewise
*                                  constant profile (layer averages).
*                              3:  Observation to be treated as total or
*                                  partial column amounts
*
*-----------------------------------------------------------------------
#endif
*
#include "comlun.cdk"
*
      INTEGER J
C
C     Set obs handling flag.
C 
      J=1
      IF (kIND2.LE.0)THEN
         kIND2=0
C
         if (kdesc(j).eq.15003.or.kdesc(j).eq.15026.or.
     &       kdesc(j).eq.15027.or.kdesc(j).eq.15223.or.
     &       kdesc(j).eq.15007.or.kdesc(j).eq.15010.or.
     &       kdesc(j).eq.15199.or.kdesc(j).eq.15230.or.
     &       kdesc(j).eq.15022.or.kdesc(j).eq.15008.or.
     &       kdesc(j).eq.15197.or.kdesc(j).eq.15024.or.
     &       kdesc(j).lt.15000.or.kdesc(j).gt.15999) then
C
C            Point profile data. 
C            Forward model involves only spatial interpolation to
C            the obs location.
C
             kobstyp = 1
C        
         else
C
C           Unknown forward model
C
            write(nulout, *) 'CH_OBSTYP:'
            write(nulout, *) 'Unknown forward model for ',kdesc(j)
            write(nulout,*)
            call abort3d(nulout,'CH_OBSTYP')
C
         endif
C
      ELSE
C
C        An acceptable second column has been found.
C
         if (kdesc(j).eq.15003.or.kdesc(j).eq.15026.or.
     &       kdesc(j).eq.15027.or.kdesc(j).eq.15223.or.
     &       kdesc(j).eq.15007.or.kdesc(j).eq.15010.or.
     &       kdesc(j).eq.15199.or.kdesc(j).eq.15230.or.
     &       kdesc(j).eq.15022.or.kdesc(j).eq.15008.or.
     &       kdesc(j).eq.15197.or.
     &       kdesc(j).lt.15000.or.kdesc(j).gt.15999) then
C
C           Obs is a column average.
C
            kobstyp = 2
C
         else if (kdesc(j).eq.15001.or.kdesc(j).eq.15198.or.
     &            kdesc(j).eq.15008.or.kdesc(j).eq.15021.or.
     &            kdesc(j).eq.15020.or.kdesc(j).eq.15200.or.
     &            kdesc(j).eq.15005) then
C
C           Obs are partial or total column amounts 
C
            kobstyp = 3
C
         else if (kdesc(j).eq.15024) then
C
C           Obs are column sums 
C
            kobstyp = 4
C
         else
C
C           Unknown forward model.
C
            write(nulout, *) 'CH_OBSTYP:'
            write(nulout, *) 'Unknown forward model for ',kdesc(j)
            write(nulout,*)
            call abort3d(nulout,'CH_OBSTYP')
         endif
      ENDIF
C
      RETURN
      END