include file: comchem.cdk 78
#if defined (DOC)
!
!
!Author  : Y. Yang    July 2003
!             - Variables related to chemical species
!Revision:
!          Y.J. Rochon, ARQX/MSC, May 2005
!             - Addition of NGENOPER, N*TRFLAG
!             - Addition of NLOGTR
!          Y. Yang    June 2005
!             - Addition of LSPLIT for splitting algorithm
!          Y.J. Rochon, ARQX/MSC, Sept 2005 - Feb. 2006
!             - Addition of CSPECIESN and SPECIESM and minor changes in format
!             - Change in definition of NTRCODELIST and CNAMANAL.
!             - Added CTRSTNID
!             - Addition for balance operator on/off flags NBALOPER(NBALOP)
!               N.B.: Application of any new balance operator must be 
!                     hardcoded in the following routines. 
!                     - Operators must be in the file(s) with name(s) hardcoded 
!                       in code and file(s) must be in the directory specified
!                       by the "chemdir" cfg key (in felix).
!                     - Selection and application of operators must be done in
!                       the following three driver routines:
!
!                       CH_RDSBALOPER: Reading and storage of operator(s)
!                       CH_BALOPER: Application of operator
!                       CH_ABALOPER: Application of operator adoint.
!
!          Y.J. Rochon, ARQX/EC, March 2006. Updated Aug. 2010
!             - Addition of quality control threshold factors
!               QCFACT1 and QCFACT2. Zeroth order quality control is
!               applied with QCFACT2 in CH_CMABDY prior to inserting
!		data in the CMA. The data not satisfying the following
!		conditions will not be assimilated (i.e. MOBDATA(NMCASS,*) 
!		will be set to 0).
!
!		In CH_CMABDY, for constituent data, 
!!
!			obs is > QCFACT2 * sigma(obs) or < 0.1 * sigma(obs) 
!
!			where dy is the innovation y-F(x) and dx=xb-x.
!
!		When NCONF=101 (background check):
!
!		     [y-F(x)]^2 <= QCFACT1 * ztrcrit *[var(F(x))+var(y)]
!
!		     where 'ztrcrit' is a hardcoded value in isetflag.ftn
!
!	      
!	  Y. Yang ARQI Feb. 2007
!	     -   add character string CDIROBSSTD for directives of how to
!		 use the input observation error std. dev.
!	     -   add charaacter string CFRMTOBS to distinguish between
!		 new and old format for the input observation std. dev.
!		 file
!			
!	   Y.J. Rochon, ARQX/EC, Feb 2007
!		 - Added DAYNIGHTP for use in day/night/near-terminator  
!		   criteria for accepting obs.
!		   Default of PDAYNIGHT(:)<=0 for no application of criterion.
!		   For criteria see CH_TERMCOND called in CH_JOCALC.
!	   Y.J. Rochon ARQX/EC April. 2007
!		 - Added parameters for balance operators (CBALOP*) and
!		   removed NBALOPER
!		 - Added CSCMT
!	   Y.J. Rochon ARQX/EC June 2008
!		 - Addition of array NOBSLOS for line of sight coordinate
!		   parameters. Only the observing direction relative to North
!		   has been included at this point.
!          Y. Yang and Y.J. Rochon March 2010
!                - Introduced NTUNETROBS and NTUNETRBG
!                  replacing LTUNEOBS and LTUNEBG of the earlier 3D-Var-Chem.
!                  Chosen for consistency with NTUNESTATS in comcva.cdk for
!                  dynamical variables.
!          Y.J. Rochon March 2010
!                - Added CTUNETRBG to identify choice of tuning coeff. set 
!                  (instead of  being hardcoded)
!          Y.J. Rochon ARQX/EC March 2010
!                - Added NTRCOUNT,NTRLEV,RTRLEV,RTROMAP
!
!     COMDECK: COMCHEM
!     --------------
!
! Definition of variables related to chemical species
!
! Integer variables/constants:
!
! NCMTMAX     : maxmum # of chemical species allowed -- moved to comdim.cdk
!
! NSCMT       : number of species in spectral space
! NGCMT       : number of species in grid space
! NOCMT       : number of species at obs. locations from CMVONEED
! NCMTASSI    : number of chemical species to be assimilated
! NALLVCORD   : number of all possible vertical coordinates  
! NDESCVCORD  : descriptors for vertical coordinates
! NDESVTYP    : code for vertical coordinate type, corresponding to elements in$
! NTRCODELIST(NCMTMAX) 
!	      : List of the species codes for species obs to be assimilated.
!		Values obtained from the 'tablespecies' file according to
!		the CNAMANAL list provided by the NAMCHEM namelist
! NGENOPER    : Flag indicating if generalized innovation operator used
!		for total or partial column species obs (1 for yes)
! NTOTTRFLAG  : Max number of quality flags
! NTRFLAG(*)  : Possible quality flags identifying "acceptable" data for
!		assimilation.
! NLOGTR      : Flag indicating form of analysis variables for species
!		0 for vmr (default)
!		1 for log(vmr)
! NFLGSTDTR(NCMTMAX) : Flag to indicate how the user wants to specify the obs. std. dev.
!		for species.
!		= 0, 1, or 2 - See routine ch_getobserr.
! NBALOP      : Number of variable transformations to consider/apply
! NETR(NCMTAX): BURF descriptor of desired data. Read from NAMCHEM namelist.
! NOBSLOS(*)  : Array of line of sight coordinate parameters.
! NTUNETRBG   : 0 no tuning  
!               5 tune constituent background error std. dev.
! NTUNETROBS  : 0 no tuning
!               5 tune TR family obs error std. dev.
! NTRCOUNT(NTRLEV,NCMTMAX): Number of OmA or OmP
! NTRLEV(NCMTMAX)     : Number of diagnostic layers in RTRLEV
!
! Real*8 variables:
!
! MAXFILTSZA  : maximum solar zenith angle to filtered. 
!		if >= 90.00, no filtering is performed.
! SCALERRTR(NCMTMAX) : Scaling factor of the species obs. std. dev.
!		       Valid when NFLGSCALOZ >0.
! ROBSSTDTR(NCMTMAX) : if NFLGSTDTR() = 1, give the % of observation value
!		       if NFLGSTDTR() = 2, give the actual std. dev.
! SPECIESM(NCMTMAX): Molecular mass of species read from tablespecies file
! QCFACT1(NCMTMAX):  Quality control threshold (see above)
! QCFACT2(NCMTMAX):  Quality control threshold (see above)
! DAYNIGHTP(NCMTMAX) : Max pressure (Pa) above which to 
!		       apply day/night/near-terminator 
!		       acceptance criterion. If <= 0, criteria not applied.
! RTRLEV(NTRLEV+1,NCMTMAX)  : Boundaries of diagnostic layers
! RTROMAP(4,NTRLEV,NCMTMAX) : Sum of
!                                    (1) OmA/var(O) or OmP/var(O),
!                                    (2) (OmA)^2/var(O) or (OmP)^2/var(O)
!                                    (3) P (trial) or A (analysis)
!                                    (4) 1/var(O)
!                             for different diagnostic layers and TR subfamilies.
!
! Character strings:
!
! CMVOCMT(NOCMT) name of the variables of trial field at obs. location
! CSCMT(NGCMT):  spectral space analysis field name of the variables
! CGCMT(NGCMT):  grid point trial field name of the variables
! CNAMANAL(NCMTMAX): List of names of analysis (and trail field) variables 
!		     read from NAMCHEM namelist for which obs will be 
!		     assimilated. Relation of analysis and trial field 
!		     variable names with BURP species id/code is determined 
!		     from table in the tablespecies file. 
!
!		     IMPORTANT:
!
!		     Species in CSNEED and CVFSTVAR must be in CNAMANAL!!
!
!		     Fields (3D and 2D) in CSNEED must
!		     be consistent with those in CVFSTVAR*.
! 
! CTRSTNID(NCMTMAX): Station/instrument identifier. Read from NAMCHEM namelist.
!		     When blank (default), use all available data for 
!		     species CNAMANAL and NETR. Otherwise, use only data of
!		     specified STNID in BURP report headers.
!  
! CSPECIESN(NCMTMAX): Species formula read from tablespecies file (not needed)
!
! CDIROBSSTD(NCMTMAX): For directives of how to use the input observation error std. dev. 
!		       = 'val' or 'VAL': use the input profile as actual obs. 
!				    error std. dev.
!		       = 'fct' or 'FCT': use the input profile as scaling (tuning)
!				    factor to scale the obs. error std. dev.
!		       = 'NON' or any other 3 char than 'fct' or 'val': no change on the 
!				    obs. error std. dev. read from  BURP file
!
! CFORMTOBS	     : format of the input ASCII file for observation std. dev.
!		       = 'old' or 'OLD': old format, with  7 columns, inlcuding 3 regions.
!			  Species are distinguished by ID
!		       = 'new' or 'NEW': new  format, with 5 columns and only one global 
!			  profile. Sepcies are distinguished by NOMVAR name
!
! CBALOPSRC(NBALOP):   Name of source variable (to which is applied the balance
!		       operator)
! CBALOPDEST(NBALOP):  Name of destination variable (associated with the 
!		       unbalanced part but referring to the full field, i.e.
!		       O3 and not UO3, TT and not UT)
! CBALOPETIK(NBALOP):  Etiket of operator in RPN file CBALOPFILE
!		     
! CBALOPFILE:	       Name of file containing balance operators.
! CTUNETRBG:           Identifier for choice of TR BG variance scaling factors.
!                      Only needed if NTUNETRBG=5.
!
! Logicals:
!
! LSPLIT      : Logical flag indicating whether the splitting analysis is to be$
!		the unobserved variables
!
#endif
!
      INTEGER NTOTTRFLAG
      PARAMETER (NTOTTRFLAG=10)
      INTEGER NSCMT, NGCMT, NOCMT, NCMTASSI,NBALOP
      INTEGER NETR(NCMTMAX),NLOGTR
      INTEGER NTRCODELIST(NCMTMAX),NGENOPER
      INTEGER NTRFLAG(NTOTTRFLAG)
      INTEGER NFLGSTDTR(NCMTMAX)
      INTEGER NTUNETRBG,NTUNETROBS
      INTEGER NALLVCORD
      PARAMETER (NALLVCORD = 50)
      INTEGER NDESCVCORD(NALLVCORD), NDESVTYP(NALLVCORD),NOBSLOS(NALLVCORD)
      REAL*8  RTROMAP(4,100,NCMTMAX),RTRLEV(100,NCMTMAX)
      INTEGER NTRCOUNT(100,NCMTMAX),NTRLEV(NCMTMAX)
!
      REAL*8  SCALERRTR(NCMTMAX)
      REAL*8  ROBSSTDTR(NCMTMAX)
      REAL*8  MAXFILTSZA,SPECIESM(NCMTMAX)
      REAL*8  QCFACT1(NCMTMAX),QCFACT2(NCMTMAX),DAYNIGHTP(NCMTMAX)
!
      CHARACTER*4 CMVOCMT(NCMTMAX), CGCMT(NCMTMAX), CSCMT(NCMTMAX)
      CHARACTER*4 CNAMANAL(NCMTMAX)
      CHARACTER*3 CDIROBSSTD(NCMTMAX)
      CHARACTER*3 CFORMTOBS
      CHARACTER*20 CSPECIESN(NCMTMAX)
      CHARACTER*9 CTRSTNID(NCMTMAX)
      CHARACTER*4 CBALOPSRC(NCMTMAX),CBALOPDEST(NCMTMAX)
      CHARACTER*80 CBALOPFILE
      CHARACTER*12 CBALOPETIK(NCMTMAX)
      CHARACTER*12 CTUNETRBG
!
      LOGICAL LSPLIT
      LOGICAL LGLOBAL_STD_MEAN
!
      COMMON /COMCHEMI/NSCMT,NGCMT,NOCMT,NCMTASSI  
      COMMON /COMCHEMI/NTRCODELIST, NGENOPER      
      COMMON /COMCHEMI/NETR,NTRFLAG,NLOGTR,NBALOP      
      COMMON /COMCHEMI/NFLGSTDTR, NDESCVCORD, NDESVTYP, NOBSLOS  
      COMMON /COMCHEMI/NTUNETRBG,NTUNETROBS
      COMMON /COMCHEMI/NTRLEV,NTRCOUNT
!
      COMMON /COMCHEMR/SCALERRTR, MAXFILTSZA    
      COMMON /COMCHEMR/ROBSSTDTR,SPECIESM,QCFACT1,QCFACT2  
      COMMON /COMCHEMR/DAYNIGHTP
      COMMON /COMCHEMR/RTRLEV,RTROMAP
!
      COMMON /COMCHEMC/CNAMANAL, CSPECIESN, CSCMT              
      COMMON /COMCHEMC/CMVOCMT, CGCMT,CTRSTNID, CDIROBSSTD, CFORMTOBS  
      COMMON /COMCHEMC/CBALOPSRC, CBALOPDEST, CBALOPFILE,CBALOPETIK
      COMMON /COMCHEMC/CTUNETRBG
!
      COMMON /COMCHEML/LSPLIT, LGLOBAL_STD_MEAN
!