      SUBROUTINE INITTVCALC_CO2(ICHID,MWRKTVMDS,MPOUT,MTOUT,MSOUT,ML,
     &MGS,MGB,MSTATES,MG3,NCEL,NGAS,IDG,NGB,IDGB,RE,ZT,PT,TT,QM,TVPATH,
     &VIBTRAN,VIBSTS,VIBTRANTV,VSTSCM,VSTSG3,WRKTVMDS,RLT,RUT,TVT,IQUIT)
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C INITTVCALCT CALCULATES ALL THE VIBRATIONAL TEMPERATURES MODELED
C AND INTIALIZES THE NLTE/LTE POPULATION RATIOS, USING THE A PRIORI 
C ATMOSPHERIC STATE.
C
C INPUT PARAMETERS:
C
C   ICHID     --- CHANNEL LOCATION INDEX.
C   MWRKTVMDS --- MAXIMUM SIZE OF WRKTVMDS WORK ARRAY. 
C   MPOUT     --- MAXIMUM SIZE OF TBL DATA SUBSET.
C   MTOUT     --- MAXIMUM SIZE OF TOUT DATA SUBSET.
C   MSOUT     --- MAX SIZE OF SOUT SUBSET PER GAS. 
C   NCH       --- NUMBER OF CHANNELS.
C   ML        --- MAXIMUM LEVELS IN MODEL ATMOSPHERE.
C   MGS       --- MAXIMUM SIMULATED GASES.
C   MGB       --- MAXIMUM SIMULATED VIBRATIONAL TRANSITIONS.
C   NCEL      --- NUMBER OF LEVELS IN INPUT ATMOSPHERE.
C   NGAS      --- NUMBER OF SIMULATED GASES IN FORWARD.
C   IDG       --- SIMULATED GASID'S IN FORWARD.
C   NGB       --- NUMBER OF SIMULATED GASES/ISOTOPES/LEVELS IN FORWARD.
C   IDGB      --- SIMULATED PSEUDO GASID'S IN FORWARD.
C   RE        --- EARTH'S RADIUS (KM).
C   ZT        --- INPUT ATMOSPHERE ALTITUDES (KM).
C   PT        --- INPUT ATMOSPHERE PRESSURES (MBAR).
C   TT        --- INPUT ATMOSPHERE TEMPERATURES (K).
C   QM        --- INPUT ATMOSPHERE MIXING RATIOS (VMR).
C   TVPATH    --- DIRECTORY PATH TO INITIAL TV'S.
C   VIBTRAN   --- VIBRATIONAL TRANSITION DESCRIPTOR FOR FORWARD MODEL.
C   VIBSTS    --- UPPER/LOWER VIBRATIONAL STATE DESIGNATIONS IN FORWARD.
C   VIBTRANTV --- VIBRATIONAL TRANSITION DESCRIPTOR FOR TV MODEL.
C   VSTSCM    --- UPPER/LOWER VIBRATIONAL STATE DESIGNATIONS IN TV MOD.
C   WRKTVMDS  --- WORK ARRAY CONTAINING MOST OF THE PARAMETERS AND
C                 ARRAY NEEDED BY THE TV MODELS AND NON-LTE FORWARD
C                 RADIANCE MODEL.
C
C OUTPUT PARAMETERS:
C
C   TVT       --- COMPUTED VIBRATIONAL TEMPERATURES.
C   RLT       --- LOWER STATE NLTE/LTE POPULATION RATIOS.
C   RUT       --- UPPER STATE NLTE/LTE POPULATION RATIOS.
C
C SOFTWARE WRITTEN BY Christopher J. Mertens
C Modified by Benjamin T. Marshall December 2002
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C      (c) Copyright 1987-2000 by GATS, Inc.
C          11864 Canon Blvd., Suite 101, Newport News, Virginia, 23606
C          Phone: (757) 873-5920
C
C  All Rights Reserved. No part of this software or publication may be
C  reproduced, stored in a retrieval system, or transmitted, in any form
C  or by any means, electronic, mechanical, photocopying, recording, or
C  otherwise without the prior written permission of GATS, Inc.
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
      LOGICAL INITTV,IQUIT
      CHARACTER*(*) TVPATH,VIBSTS,VSTSCM,VSTSG3,VIBTRAN,VIBTRANTV
      DIMENSION IDG(MGS),IDGB(MGB,*),VIBTRAN(MGB,*),VIBSTS(2,MGB,*),
     &VIBTRANTV(MSTATES),VSTSCM(2,MSTATES),VSTSG3(2,MG3),NGB(*)
      DIMENSION ZT(ML),PT(ML),TT(ML),QM(ML,MGS),WRKTVMDS(MWRKTVMDS)
      DIMENSION RLT(ML,MGB,*),RUT(ML,MGB,*),TVT(ML,MGB,2,*)
      COMMON/LWRKTVMDST/LIDAY,LINITTV,LLVSED,LLVSEDTV,LLTV,LLMCM,LLSHR,
     &LIFLUXAL,LICCM,LISLH,LISECANT,LNITN,LNITD,LNITC,LITVOPT,LITVOPTN2,
     &LMG3,LMSSPC,LMTBLTV,LMWRKTV,LNLTV,LNVTS,LIVTS,LIVTSN,LIVTSG3,
     &LITVID,LITVIDVMR,LNLMX,LNLMXVMR,LNMXTV,LIRADTV,LZATV,LABDISO,
     &LABDISOG3,LENGY,LENGYG3,LSZA,LCSSPC,LWRKTV,LTVTBL,LTVPOUT,LTVTOUT,
     &LTVSOUT,LPN21RMOD,LPN21TMOD,LTVRMOD,LTVTMOD,LTVRN2MOD,LTVTN2MOD,
     &LTVRG3,LTVTG3,LSLHRMOD,LSLHTMOD,LSLHKRMOD,LSLHKTMOD,LSPHARRMOD,
     &LSPHARTMOD,LHRRMOD,LHRTMOD,LFQQ,LFQQT,LFQQVMR,LFQQTVMR
      LOGICAL MP_ERROR
      CHARACTER*100 MP_MESSAGE
      COMMON/MP_STATUS/MP_ERROR,MP_MESSAGE
c          print*, "inside tvib model "
      INITTV=.TRUE.
      CALL KP_GETINT(WRKTVMDS(LNLTV),1,NL)
      CALL TVCALC_CO2(WRKTVMDS(LIDAY),INITTV,WRKTVMDS(LITVOPT),
     & WRKTVMDS(LITVOPTN2),WRKTVMDS(LIFLUXAL),WRKTVMDS(LICCM),
     & WRKTVMDS(LISLH),WRKTVMDS(LISECANT),WRKTVMDS(LNITN),
     & WRKTVMDS(LNITD),WRKTVMDS(LNITC),WRKTVMDS(LLVSEDTV),
     & WRKTVMDS(LLTV),WRKTVMDS(LLMCM),WRKTVMDS(LLSHR),WRKTVMDS(LMTBLTV),
     & MPOUT,MTOUT,MSOUT,WRKTVMDS(LMSSPC),WRKTVMDS(LMWRKTV),ML,ML,MGS,
     & MSTATES,WRKTVMDS(LMG3),NCEL,NL,NGAS,WRKTVMDS(LNVTS),IDG,
     & WRKTVMDS(LIVTS),WRKTVMDS(LIVTSG3),WRKTVMDS(LNMXTV),
     & WRKTVMDS(LIRADTV),RE,WRKTVMDS(LZATV),ZT,PT,TT,QM,
     & WRKTVMDS(LPN21RMOD),TVPATH,VSTSCM,VSTSG3,WRKTVMDS(LABDISO),
     & WRKTVMDS(LENGY),WRKTVMDS(LSZA),WRKTVMDS(LCSSPC),WRKTVMDS(LTVTBL),
     & WRKTVMDS(LTVPOUT),WRKTVMDS(LTVTOUT),WRKTVMDS(LTVSOUT),
     & WRKTVMDS(LWRKTV),WRKTVMDS(LTVRMOD),WRKTVMDS(LTVRN2MOD),
     & WRKTVMDS(LTVRG3),WRKTVMDS(LSLHRMOD),WRKTVMDS(LSLHKRMOD),
     & WRKTVMDS(LSPHARRMOD),WRKTVMDS(LHRRMOD))
      IF(MP_ERROR) THEN
        MP_MESSAGE=MP_MESSAGE(1:55)//':INITTVCALC_CO2'
        IQUIT=.TRUE.
        RETURN
      ENDIF
CTM Initialize TVT to TT
      DO IL=1,NCEL
        DO IG=1,NGB(ICHID)
          DO IS=1,2
            TVT(IL,IG,IS,ICHID)=TT(IL)
          ENDDO
        ENDDO
      ENDDO
CTM Set TVT to TVRMOD
      CALL SETTVT(ICHID,ML,MGB,MSTATES,WRKTVMDS(LMG3),NCEL,NGB(ICHID),
     &IDGB(1,ICHID),WRKTVMDS(LIVTS),WRKTVMDS(LIVTSG3),WRKTVMDS(LTVRMOD),
     &WRKTVMDS(LTVRG3),TVT,VIBTRAN,VIBTRANTV)
CTM Update population ratios
      CALL KP_UPDTPOPRAT(WRKTVMDS(LLVSED),ML,ML,MGB,NCEL,NCEL,1,NCEL,
     & NGB(ICHID),IDGB(1,ICHID),WRKTVMDS(LNLMX),ZT,ZT,TT,
     & TVT(1,1,1,ICHID),VIBSTS(1,1,ICHID),WRKTVMDS(LFQQ),WRKTVMDS(LFQQ),
     & RUT(1,1,ICHID),RLT(1,1,ICHID))
      RETURN
      END
