!-------------------------------------- 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 --------------------------------------
*** S/P SHALLCONV3
#include "phy_macros_f.h"

      subroutine shallconv3 (d, dsiz, f, fsiz, v, vsiz, kount,trnch, 1,2
     1                       cdt1, ni, nk              )
*
#include "impnone.cdk"
*
      INTEGER ni, nk, kount, trnch
      INTEGER dsiz,fsiz,vsiz
      REAL d(dsiz), f(fsiz), v(vsiz)
      REAL cdt1
*
*Author
*          A-M Leduc. (March 2002)
*
*Revisions
* 001      S-Belair, A-M.Leduc (nov 2002) add convective counter 
*                                      kshal for ktrsnt.
* 002      A-M.Leduc (nov 2002)  - add switch ishlcvt(2) and remove
*                             delt as argument--->shallconv2
* 003      B. Bilodeau (Jul 2004) - add option KTRSNT_MG
* 004      L. Spacek (Aug 2004) - cloud clean-up v(ckt) changes to f(fsc)
*                                 qktl to qlsc, qkti to qssc
* 053      L. Spacek (Dec 2007) -  Staggered version, use sigw instead of sigm
*                                  d(sigw) is defined in subroutine sigmalev

*
*Object
*          This is the interface routine for shallow convection schemes
*
*Arguments
*
*          - Input -
* D        "dynamic" bus (dynamics input fields)
*
*          - Input/Output -
* F        "permanent" bus (field of permanent physics variables)
* V        "volatile" bus 
*
*          - Input -
* DSIZ     dimension of d
* FSIZ     dimension of f
* VSIZ     dimension of v
* TRNCH    row number
* KOUNT    timestep number
* CDT1     timestep * factdt
*          see common block "options"
* NI       horizontal running length
* NK       vertical dimension
*
**
*
#include "indx_sfc.cdk"
#include "phybus.cdk"
#include "options.cdk"
*
      INTEGER i,k,ik
      INTEGER zilab(ni,nk)
      REAL    zdbdt(ni)
*
**
      DO k=1,nk
      DO i=1,ni
        zilab(i,k) = 0
      END DO
      END DO
*
      DO i=1,ni
       zdbdt(i) = 0.
      END DO
*
      IF(ISHLCVT(2).EQ.1)THEN
*
*       KUO TRANSIENT SHALLOW CONVECTION - IT DOES GENERATE PRECIPITATION
*                                             ----
*
        CALL ktrsnt3( v(tshal), v(hushal), zilab, f(fsc), v(qlsc),
     1               v(qssc), zdbdt,f(tlcs),f(tscs),v(qcz),
     1               d(tplus), d(tmoins), d(huplus), d(humoins),
     1               d(gzmoins6), v(qdifv), d(pplus), d(pmoins), 
     1               d(sigw), cdt1, v(kshal),ni, nk-1  )
*
*       TRANSFORMATION EN HAUTEUR D'EAU (M) - DIVISER PAR DENSITE EAU
*
        DO i=1,ni
           f(tscs+i-1) = f(tscs+i-1) * 1.e-03
           f(tlcs+i-1) = f(tlcs+i-1) * 1.e-03
        END DO
*
      ELSE IF(ISHLCVT(2).EQ.2) THEN
*
*       KUO TRANSIENT SHALLOW CONVECTION USED BY THE MESO-GLOBAL MODEL (mg)
*
        CALL ktrsnt_mg   ( v(tshal), v(hushal), zilab, f(fsc), v(qlsc), 
     1                   v(qssc), zdbdt,  
     1                   d(tplus), d(tmoins), d(huplus), d(humoins),
     1                   d(gzmoins6), v(qdifv), d(pplus), d(pmoins), 
     1                   d(sigw), cdt1, v(kshal),ni, nk-1  ) 
*
      ENDIF
*
*
      RETURN
      END