!-----------------------BEGIN NOTICE -- DO NOT EDIT-----------------------
! NASA Goddard Space Flight Center Land Information System (LIS) v7.2
!
! Copyright (c) 2015 United States Government as represented by the
! Administrator of the National Aeronautics and Space Administration.
! All Rights Reserved.
!-------------------------END NOTICE -- DO NOT EDIT-----------------------
#include "LIS_misc.h"
!BOP
!
! !ROUTINE: ibis_setup
! \label{ibis_setup}
!
! !REVISION HISTORY:
!  This subroutine is generated with the Model Implementation Toolkit developed
!  by Shugong Wang for the NASA Land Information System Version 7. The initial 
!  specification of the subroutine is defined by Sujay Kumar. 
!   9/4/14: Shugong Wang; initial implementation for LIS 7 and ibis
!   2/7/18: Soni Yatheendradas; code added for OPTUE to work 
!
! !INTERFACE:
subroutine ibis_setup()
! !USES:
    use LIS_logMod,    only: LIS_logunit, LIS_verify, LIS_endrun
    use LIS_fileIOMod, only: LIS_read_param
    use LIS_coreMod,   only: LIS_rc, LIS_surface
    !use IBIS_VEG_PARAMETERS_36, only: read_mp_veg_parameters
    !use MODULE_SF_IBISMPLSM_36, only: read_mp_veg_parameters
    use MODULE_SF_IBISMPLSM_36, only: read_mp_veg_parameters, &
           SLCATS, LUCATS, CSOIL_DATA, BB, SATDK, SATDW, &
           SATPSI, QTZ, MAXSMC, REFSMC, WLTSMC, &
           CZIL_DATA, FRZK_DATA, REFDK_DATA, REFKDT_DATA, SLOPE_DATA, &
           TOPT_DATA, RGLTBL, RSMAX_DATA, RSTBL, HSTBL, NROTBL, &
           CH2OP, DLEAF, Z0MVT, HVT, HVB, RC, RHOL, RHOS, TAUL, TAUS, &
           XL, CWPVT, C3PSN, KC25, AKC, KO25, AKO, AVCMX, AQE, &         
           LTOVRC,  DILEFC,  DILEFW,  RMF25,  SLA,  FRAGR,  TMIN, &
           VCMX25,  TDLEF,  BP, MP, QE25, RMS25, RMR25, ARM, &
           FOLNMX, WDPOOL, WRRAT, MRP, DRYSMC ! SY: adding 
           ! calibratable parameters + DVEG to this list for OPTUE to work by 
           ! updating further below the corresponding values in ibis_module 
           ! after call to subroutine SOIL_VEG_GEN_PARM_IBIS   
           ! SY: Not used by ibis3.6 from REDPRM:  F11, DRYSMC            
           ! SY: Not used by ibis3.6 from read_mp_veg_parameters : AQE and 
           !     SLAREA (since subroutine BVOCFLUX not used), DEN
           ! SY: Also added DRYSMC used as constraint by OPTUE
 

    use ibis_lsmMod

  USE Utils, ONLY :tmstmp2,lati

  USE InitAll, ONLY : InitA, InitB

  USE Options, ONLY : idate,idatec,idatep,tod,tod2,ifday,ifday2,dtt,intg,initlz,ilwrad,iswrad,epsflt,istrt,filta,&
                      DELTAIN,DELTAOUT,maxtim,UNDIMENSION

  USE Constants, ONLY: &
       r8,             &
       i8,             &
       pi

  USE Sfc_Ibis_Interface, ONLY : Ibis_Interface

  USE Sizes,ONLY :ibMax,jbMax,kMax

  USE FieldsPhysics, ONLY: iMask,MskAnt

  USE AtmosModel, ONLY : RunAtmosModel,FinalizeAtmosModel,RunAtmosModel1D,&
       gu,gv,gq,gt,gps,dcupr_sib,&
       dlspr_sib,radvbc_sib,radnbc_sib,radvdc_sib,radndc_sib,& 
       dlwbot_sib,cosz_sib,ws,psb_g,bps_g,tseam ,tsea,slrad ,&
       tsurf,qsurf,zorl,tmtx,qmtx,umtx ,sigki ,delsig,latic,longc
  USE Sfc_Ibis_Fiels

  USE IbisOutput, ONLY : RunOutput,RunOutput1D



!
! !DESCRIPTION:
!
!  This routine is the entry point to set up the parameters
!  required for ibis.  These include: 
!    vegetype     - land cover type index [-]
!    soiltype     - soil type index [-]
!    slopetype    - slope type for IBIS baseflow [-]
!    tbot         - deep-layer soil temperature [K]
!    pblh         - planetary boundary layer height [m]
! 
!  The routines invoked are:
!  \begin{description}
!  \item[LIS\_read\_param](\ref{LIS_read_param}) \newline
!    retrieves LIS parameter data from NetCDF file
!  \item[ibis\_read\_MULTILEVEL\_param](\ref{ibis_read_MULTILEVEL_param}) \newline
!    retrieves MULTILEVEL spatial parameter from NetCDF file
!  \end{description}
!EOP
    implicit none
    integer           :: mtype
    integer           :: t, k, n
    integer           :: col, row
    real, allocatable :: placeholder(:,:)
    real              :: lat, lon
    integer           :: i, j

   WRITE(0,*)' Init' 
    
  !CALL Init()    
  CALL InitA()
!  print *, 'LGG calling init in ibis_setup  STOP ', plai
!  STOP

    
    mtype = LIS_rc%lsm_index
    
    do n=1, LIS_rc%nnest
        ! allocate memory for place holder for #n nest
        allocate(placeholder(LIS_rc%lnc(n), LIS_rc%lnr(n)))
        
        !------------------------------------!
        ! reading spatial spatial parameters !
        !------------------------------------!
        ! vegetype takes value from the LIS built-in parameter vegt
        !TODO: convert vegetation data source into vegetation types
        if(LIS_rc%uselcmap(n) .ne. 'none') then
            write(LIS_logunit,*) "ibis: retrieve parameter VEGETYPE from LIS"
            do t=1, LIS_rc%npatch(n, mtype)
                ibis_struc(n)%ibis(t)%vegetype= LIS_surface(n, mtype)%tile(t)%vegt
            enddo
        else 
            ! read: vegetype
            write(LIS_logunit,*) "ibis: reading parameter VEGETYPE from ", trim(LIS_rc%paramfile(n))
            call LIS_read_param(n, trim(ibis_struc(n)%LDT_ncvar_vegetype), placeholder)
            do t = 1, LIS_rc%npatch(n, mtype)
                col = LIS_surface(n, mtype)%tile(t)%col
                row = LIS_surface(n, mtype)%tile(t)%row
                ibis_struc(n)%ibis(t)%vegetype = placeholder(col, row)
            enddo 
        endif
        ! read: soiltype
        !write(LIS_logunit,*) "ibis: reading parameter SOILTYPE from ", trim(LIS_rc%paramfile(n))
        !call LIS_read_param(n, trim(ibis_struc(n)%LDT_ncvar_soiltype), placeholder)
        !do t = 1, LIS_rc%npatch(n, mtype)
        !    col = LIS_surface(n, mtype)%tile(t)%col
        !    row = LIS_surface(n, mtype)%tile(t)%row
        !    ibis_struc(n)%ibis(t)%soiltype = placeholder(col, row)
        !enddo 

        ! soiltype takes value from the LIS built-in parameter soilt
        !TODO: convert soil texture into soil types according to scheme
        if(LIS_rc%usetexturemap(n) .ne. 'none') then
            write(LIS_logunit,*) "ibis: retrieve parameter SOILTYPE from LIS"
            do t=1, LIS_rc%npatch(n, mtype)
                ibis_struc(n)%ibis(t)%soiltype= LIS_surface(n, mtype)%tile(t)%soilt
            enddo
        else 
            ! read: soiltype
            write(LIS_logunit,*) "ibis: reading parameter SOILTYPE from ", trim(LIS_rc%paramfile(n))
            call LIS_read_param(n, trim(ibis_struc(n)%LDT_ncvar_soiltype), placeholder)
            do t = 1, LIS_rc%npatch(n, mtype)
                col = LIS_surface(n, mtype)%tile(t)%col
                row = LIS_surface(n, mtype)%tile(t)%row
                ibis_struc(n)%ibis(t)%soiltype = placeholder(col, row)
            enddo 
        endif

        ! read: slopetype
        write(LIS_logunit,*) "ibis: reading parameter SLOPETYPE from ", trim(LIS_rc%paramfile(n))
        call LIS_read_param(n, trim(ibis_struc(n)%LDT_ncvar_slopetype), placeholder)
        do t = 1, LIS_rc%npatch(n, mtype)
            col = LIS_surface(n, mtype)%tile(t)%col
            row = LIS_surface(n, mtype)%tile(t)%row
            ibis_struc(n)%ibis(t)%slopetype = placeholder(col, row)
        enddo 

        ! read: tbot
        write(LIS_logunit,*) "ibis: reading parameter TBOT from ", trim(LIS_rc%paramfile(n))
        call LIS_read_param(n, trim(ibis_struc(n)%LDT_ncvar_tbot), placeholder)
        do t = 1, LIS_rc%npatch(n, mtype)
            col = LIS_surface(n, mtype)%tile(t)%col
            row = LIS_surface(n, mtype)%tile(t)%row
            ibis_struc(n)%ibis(t)%tbot = placeholder(col, row)
        enddo 

        ! read: pblh
        write(LIS_logunit,*) "ibis: reading parameter PBLH from ", trim(LIS_rc%paramfile(n))
        call LIS_read_param(n, trim(ibis_struc(n)%LDT_ncvar_pblh), placeholder)
        do t = 1, LIS_rc%npatch(n, mtype)
            col = LIS_surface(n, mtype)%tile(t)%col
            row = LIS_surface(n, mtype)%tile(t)%row
            ibis_struc(n)%ibis(t)%pblh = placeholder(col, row)
        enddo 

        !----------------------------------------------!
        ! MULTILEVEL reading spatial spatial parameters !
        !----------------------------------------------!
        ! read: shdfac_monthly
        write(LIS_logunit,*) "ibis: reading parameter SHDFAC_MONTHLY from ", trim(LIS_rc%paramfile(n))
        do k = 1, 12
            call ibis_read_MULTILEVEL_param(n, ibis_struc(n)%LDT_ncvar_shdfac_monthly, k, placeholder)
            do t = 1, LIS_rc%npatch(n, mtype)
                col = LIS_surface(n, mtype)%tile(t)%col
                row = LIS_surface(n, mtype)%tile(t)%row
                ibis_struc(n)%ibis(t)%shdfac_monthly(k) = placeholder(col, row)
            enddo 
        enddo 

        ! read: smceq for (opt_run=5)  Miguez-Macho & Fan groundwater with equilibrium water table
        if(ibis_struc(n)%run_opt .eq. 5) then
            write(LIS_logunit,*) "ibis: reading parameter SMCEQ from ", trim(LIS_rc%paramfile(n))
            do k = 1, ibis_struc(n)%nsoil
                call ibis_read_MULTILEVEL_param(n, ibis_struc(n)%LDT_ncvar_smceq, k, placeholder)
                do t = 1, LIS_rc%npatch(n, mtype)
                    col = LIS_surface(n, mtype)%tile(t)%col
                    row = LIS_surface(n, mtype)%tile(t)%row
                    ibis_struc(n)%ibis(t)%smceq(k) = placeholder(col, row)
                enddo 
            enddo 
        endif

        deallocate(placeholder)
        call SOIL_VEG_GEN_PARM_IBIS(ibis_struc(n)%landuse_tbl_name,   & 
                                  ibis_struc(n)%soil_tbl_name,      &
                                  ibis_struc(n)%gen_tbl_name,       &
                                  ibis_struc(n)%landuse_scheme_name,& 
                                  ibis_struc(n)%soil_scheme_name)
        ! SY: Begin for enabling OPTUE 
        do t = 1, LIS_rc%npatch(n, mtype)
            
            col = LIS_surface(n, mtype)%tile(t)%col
            row = LIS_surface(n, mtype)%tile(t)%row

            ! SY: Begin lines following those in REDPRM

            ! SY: Begin SOIL PARAMETERS
            IF (ibis_struc(n)%ibis(t)%soiltype .gt. SLCATS) THEN
               write(LIS_logunit, *) 'SOILTYP must be less than SLCATS:'
               write(LIS_logunit, '("t = ", I6, "; SOILTYP = ", I6, ";    SLCATS = ", I6)') &
                         t, ibis_struc(n)%ibis(t)%soiltype, SLCATS
               write(LIS_logunit, *) 'ibis_setup: Error: too many input soil types'
               write(LIS_logunit, *) 'program stopping ...'
               call LIS_endrun
            END IF
            ibis_struc(n)%ibis(t)%csoil = CSOIL_DATA
            ibis_struc(n)%ibis(t)%bexp = BB(ibis_struc(n)%ibis(t)%soiltype)
            ibis_struc(n)%ibis(t)%dksat = SATDK(ibis_struc(n)%ibis(t)%soiltype)
            ibis_struc(n)%ibis(t)%dwsat = SATDW(ibis_struc(n)%ibis(t)%soiltype)
            ibis_struc(n)%ibis(t)%psisat = SATPSI(ibis_struc(n)%ibis(t)%soiltype)
            ibis_struc(n)%ibis(t)%quartz = QTZ(ibis_struc(n)%ibis(t)%soiltype)
            ibis_struc(n)%ibis(t)%smcmax = MAXSMC(ibis_struc(n)%ibis(t)%soiltype)
            ibis_struc(n)%ibis(t)%smcref = REFSMC(ibis_struc(n)%ibis(t)%soiltype)
            ibis_struc(n)%ibis(t)%smcwlt = WLTSMC(ibis_struc(n)%ibis(t)%soiltype)
            ! SY: End SOIL PARAMETERS

            ! SY: Begin SOIL PARAMETER CONSTRAINT
            ibis_struc(n)%ibis(t)%smcdry = DRYSMC(ibis_struc(n)%ibis(t)%soiltype)
            ! SY: End SOIL PARAMETER CONSTRAINT

            ! SY: Begin UNIVERSAL PARAMETERS
            ibis_struc(n)%ibis(t)%czil = CZIL_DATA
            ibis_struc(n)%ibis(t)%frzk = FRZK_DATA
            ibis_struc(n)%ibis(t)%refdk = REFDK_DATA
            ibis_struc(n)%ibis(t)%refkdt = REFKDT_DATA
            ibis_struc(n)%ibis(t)%slope = SLOPE_DATA(ibis_struc(n)%ibis(t)%slopetype)
            ! SY: End UNIVERSAL PARAMETERS

            ! SY: Begin VEGETATION PARAMETERS
            IF (ibis_struc(n)%ibis(t)%vegetype .gt. LUCATS) THEN
               write(LIS_logunit, *) 'VEGTYP must be less than LUCATS:'
               write(LIS_logunit, '("t = ", I6, "; VEGTYP = ", I6, ";    LUCATS = ", I6)') &
                         t, ibis_struc(n)%ibis(t)%vegetype, LUCATS
               write(LIS_logunit, *) 'ibis_setup: Error: too many input landuse types'
               write(LIS_logunit, *) 'program stopping ...'
               call LIS_endrun
            END IF
            ibis_struc(n)%ibis(t)%topt = TOPT_DATA
            ibis_struc(n)%ibis(t)%rgl = RGLTBL(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%rsmax = RSMAX_DATA
            ibis_struc(n)%ibis(t)%rsmin = RSTBL(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%hs = HSTBL(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%nroot = & 
                 NROTBL(ibis_struc(n)%ibis(t)%vegetype)

            IF (NROTBL(ibis_struc(n)%ibis(t)%vegetype) .gt. &
                ibis_struc(n)%nsoil) THEN
               WRITE (LIS_logunit,*) 'Warning: too many root layers'
               write (LIS_logunit,*) 'NROOT = ', NROTBL(ibis_struc(n)%ibis(t)%vegetype)
               write (LIS_logunit,*) 'NSOIL = ', ibis_struc(n)%nsoil
               write(LIS_logunit, *) 'program stopping ...'
               call LIS_endrun
            END IF
            ! SY: End VEGETATION PARAMETERS

            ! SY: End lines following those in REDPRM

        enddo ! do t = 1, LIS_rc%npatch(n, mtype)
        ! SY: End for enabling OPTUE 

        call read_mp_veg_parameters(trim(ibis_struc(n)%ibis_tbl_name), &
                                    trim(ibis_struc(n)%landuse_scheme_name))

        ! SY: Begin for enabling OPTUE 
        do t = 1, LIS_rc%npatch(n, mtype)
            
            col = LIS_surface(n, mtype)%tile(t)%col
            row = LIS_surface(n, mtype)%tile(t)%row

            ! SY: Begin lines following those in read_mp_veg_parameters
            ibis_struc(n)%ibis(t)%CH2OP = CH2OP(ibis_struc(n)%ibis(t)%vegetype)
            !ibis_struc(n)%ibis(t)%DLEAF = DLEAF(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%Z0MVT = Z0MVT(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%HVT = HVT(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%HVB = HVB(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%RC = RC(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%RHOL1 = RHOL(ibis_struc(n)%ibis(t)%vegetype,1)
            ibis_struc(n)%ibis(t)%RHOL2 = RHOL(ibis_struc(n)%ibis(t)%vegetype,2)
            !ibis_struc(n)%ibis(t)%RHOS1 = RHOS(ibis_struc(n)%ibis(t)%vegetype,1)
            !ibis_struc(n)%ibis(t)%RHOS2 = RHOS(ibis_struc(n)%ibis(t)%vegetype,2)
            ibis_struc(n)%ibis(t)%TAUL1 = TAUL(ibis_struc(n)%ibis(t)%vegetype,1)
            ibis_struc(n)%ibis(t)%TAUL2 = TAUL(ibis_struc(n)%ibis(t)%vegetype,2)
            ibis_struc(n)%ibis(t)%TAUS1 = TAUS(ibis_struc(n)%ibis(t)%vegetype,1)
            ibis_struc(n)%ibis(t)%TAUS2 = TAUS(ibis_struc(n)%ibis(t)%vegetype,2)
            ibis_struc(n)%ibis(t)%XL = XL(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%CWPVT = CWPVT(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%C3PSN = C3PSN(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%KC25 = KC25(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%AKC = AKC(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%KO25 = KO25(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%AKO = AKO(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%AVCMX = AVCMX(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%AQE = AQE(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%LTOVRC = LTOVRC(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%DILEFC = DILEFC(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%DILEFW = DILEFW(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%RMF25 = RMF25(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%SLA = SLA(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%FRAGR = FRAGR(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%TMIN = TMIN(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%VCMX25 = VCMX25(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%TDLEF = TDLEF(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%BP = BP(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%MP = MP(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%QE25 = QE25(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%RMS25 = RMS25(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%RMR25 = RMR25(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%ARM = ARM(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%FOLNMX = FOLNMX(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%WDPOOL = WDPOOL(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%WRRAT = WRRAT(ibis_struc(n)%ibis(t)%vegetype)
            ibis_struc(n)%ibis(t)%MRP = MRP(ibis_struc(n)%ibis(t)%vegetype)
            ! SY: End lines following those in read_mp_veg_parameters

        enddo ! do t = 1, LIS_rc%npatch(n, mtype)
        ! SY: End for enabling OPTUE 

     !
     ! IBIS
     !
!    do n=1, LIS_rc%nnest
      do t = 1, LIS_rc%npatch(n, mtype)
        ibis_struc(n)%ibis(t)%nsx       = 0.0
        ibis_struc(n)%ibis(t)%colrad    = 3.140/2.0
        ibis_struc(n)%ibis(t)%snow      = 0.0
        ibis_struc(n)%ibis(t)%speedm    = 0.0
        ibis_struc(n)%ibis(t)%taux      = 0.0
        ibis_struc(n)%ibis(t)%tauy      = 0.0
        ibis_struc(n)%ibis(t)%sens      = 0.0
        ibis_struc(n)%ibis(t)%evap      = 0.0
        ibis_struc(n)%ibis(t)%umom      = 0.0
        ibis_struc(n)%ibis(t)%vmom      = 0.0
        ibis_struc(n)%ibis(t)%rmi       = 0.0
        ibis_struc(n)%ibis(t)%rhi       = 0.0
        ibis_struc(n)%ibis(t)%z0        = 0.0
        ibis_struc(n)%ibis(t)%ustar     = 0.0
        ibis_struc(n)%ibis(t)%hc        = 0.0
        ibis_struc(n)%ibis(t)%hg        = 0.0
        ibis_struc(n)%ibis(t)%ec        = 0.0
        ibis_struc(n)%ibis(t)%eg        = 0.0
        ibis_struc(n)%ibis(t)%ts2       = 0.0
        ibis_struc(n)%ibis(t)%qs2       = 0.0
        ibis_struc(n)%ibis(t)%qsfc      = 0.0
        ibis_struc(n)%ibis(t)%tsfc      = 0.0
        ibis_struc(n)%ibis(t)%z0sea     = 0.0
        ibis_struc(n)%ibis(t)%d	        = 0.0
        ibis_struc(n)%ibis(t)%cu        = 0.0
        ibis_struc(n)%ibis(t)%Ustarm    = 0.0
        ibis_struc(n)%ibis(t)%tgrd      = 0.0
        ibis_struc(n)%ibis(t)%roff      = 0.0
        ibis_struc(n)%ibis(t)%ect       = 0.0
        ibis_struc(n)%ibis(t)%eci       = 0.0
        ibis_struc(n)%ibis(t)%egt       = 0.0
        ibis_struc(n)%ibis(t)%egi       = 0.0
        ibis_struc(n)%ibis(t)%egs       = 0.0
        ibis_struc(n)%ibis(t)%rho       = 0.0
        ibis_struc(n)%ibis(t)%bstar     = 0.0
      enddo
!    enddo


      do t = 1, LIS_rc%npatch(n, mtype)
!     print *, "LGG in ibis_setup calling InitB() ",t
     CALL InitB(ibis_struc(n)%ibis(t)%soiltype)
! this section will convert surfacetype from noahmp into IBIS clay/sand equivalences
!1,     2.79,    0.010,    -0.472,   0.339,   0.192,   0.069,  4.66E-5,  2.65E-5,   0.010,  0.92, 'SAND'
!2,     4.26,    0.028,    -1.044,   0.421,   0.283,   0.036,  1.41E-5,  5.14E-6,   0.028,  0.82, 'LOAMY SAND'
!3,     4.74,    0.047,    -0.569,   0.434,   0.312,   0.141,  5.23E-6,  8.05E-6,   0.047,  0.60, 'SANDY LOAM'
!4,     5.33,    0.084,     0.162,   0.476,   0.360,   0.759,  2.81E-6,  2.39E-5,   0.084,  0.25, 'SILT LOAM'
!5,     3.86,    0.061,     0.162,   0.484,   0.347,   0.955,  2.18E-6,  1.66E-5,   0.061,  0.10, 'SILT'
!6,     5.25,    0.066,    -0.327,   0.439,   0.329,   0.355,  3.38E-6,  1.43E-5,   0.066,  0.40, 'LOAM'
!7,     6.77,    0.069,    -1.491,   0.404,   0.315,   0.135,  4.45E-6,  1.01E-5,   0.069,  0.60, 'SANDY CLAY LOAM'
!8,     8.72,    0.120,    -1.118,   0.464,   0.387,   0.617,  2.03E-6,  2.35E-5,   0.120,  0.10, 'SILTY CLAY LOAM'
!9,     8.17,    0.103,    -1.297,   0.465,   0.382,   0.263,  2.45E-6,  1.13E-5,   0.103,  0.35, 'CLAY LOAM'
!10,   10.73,    0.100,    -3.209,   0.406,   0.338,   0.098,  7.22E-6,  1.87E-5,   0.100,  0.52, 'SANDY CLAY'
!11,   10.39,    0.126,    -1.916,   0.468,   0.404,   0.324,  1.34E-6,  9.64E-6,   0.126,  0.10, 'SILTY CLAY'
!12,   11.55,    0.138,    -2.138,   0.468,   0.412,   0.468,  9.74E-7,  1.12E-5,   0.138,  0.25, 'CLAY'
!13,    5.25,    0.066,    -0.327,   0.439,   0.329,   0.355,  3.38E-6,  1.43E-5,   0.066,  0.05, 'ORGANIC MATERIAL'
!14,     0.0,      0.0,       0.0,     1.0,     0.0,     0.0,      0.0,      0.0,     0.0,  0.60, 'WATER'
!15,    2.79,    0.006,    -1.111,    0.20,    0.17,   0.069,  1.41E-4,  1.36E-4,   0.006,  0.07, 'BEDROCK'
!16,    4.26,    0.028,    -1.044,   0.421,   0.283,   0.036,  1.41E-5,  5.14E-6,   0.028,  0.25, 'OTHER(land-ice)'
!17,   11.55,    0.030,   -10.472,   0.468,   0.454,   0.468,  9.74E-7,  1.12E-5,   0.030,  0.60, 'PLAYA'
!18,    2.79,    0.006,    -0.472,   0.200,    0.17,   0.069,  1.41E-4,  1.36E-4,   0.006,  0.52, 'LAVA'
!19,    2.79,     0.01,    -0.472,   0.339,   0.192,   0.069,  4.66E-5,  2.65E-5,    0.01,  0.92, 'WHITE SAND'

!      ------------------
!       sand  silt  clay
!      ------------------
!
!      data texdat /
!     >  0.92, 0.05, 0.03,  ! sand
!     >  0.81, 0.12, 0.07,  ! loamy sand
!     >  0.65, 0.25, 0.10,  ! sandy loam
!     >  0.42, 0.40, 0.18,  ! loam
!     >  0.20, 0.65, 0.15,  ! silt loam
!     >  0.60, 0.13, 0.27,  ! sandy clay loam
!     >  0.32, 0.34, 0.34,  ! clay loam
!     >  0.09, 0.58, 0.33,  ! silty clay loam
!     >  0.53, 0.07, 0.40,  ! sandy clay
!     >  0.10, 0.45, 0.45,  ! silty clay
!     >  0.20, 0.20, 0.60   ! clay
!     >  /
   j = ibis_struc(n)%ibis(t)%soiltype
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 4  ) j = 5
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 6  ) j = 4
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 7  ) j = 6
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 9  ) j = 7
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 10 ) j = 9
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 11 ) j = 10
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 12 ) j = 11
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 13 ) j = 8
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 14 ) j = 6
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 15 ) j = 8
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 16 ) j = 11
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 17 ) j = 3
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 18 ) j = 9
   if ( ibis_struc(n)%ibis(t)%soiltype .eq. 19 ) j = 1

   
   
!   do k=1,nsoilay
!     sand    (1,k,1) = texdat(1,j)
!     clay    (1,k,1) = texdat(3,j)
!   enddo

!     write(0,*) "LGG in ibis_setup after InitB() ",t,clay(1,1,1),sand(1,1,1)

      if ( ibis_struc(n)%ibis(t)%vegetype .eq. 16 ) then
        xinveg(1, 1) = 15
      else
        xinveg(1, 1) = ibis_struc(n)%ibis(t)%vegetype
      endif
   ibis_struc(n)%ibis(t)%iMaskIBIS(1, 1) =  iMaskIBIS(1, 1)
   ibis_struc(n)%ibis(t)%MskAntIBIS(1, 1)=  MskAntIBIS(1, 1)
   ibis_struc(n)%ibis(t)%nlpoints(1)	 =  nlpoints(1) 
   ibis_struc(n)%ibis(t)%lonscale(1, 1) = lonscale  (1, 1)
   ibis_struc(n)%ibis(t)%latscale(1, 1) = latscale  (1, 1)
   ibis_struc(n)%ibis(t)%xintopo (1, 1) = xintopo   (1, 1)
   ibis_struc(n)%ibis(t)%garea	(1, 1) = garea	 (1, 1)
   ibis_struc(n)%ibis(t)%xinveg  (1, 1) = xinveg	 (1, 1)
   ibis_struc(n)%ibis(t)%deltat  (1, 1) = deltat	 (1, 1)
   do k=1,nsoilay
    ibis_struc(n)%ibis(t)%sand(1, k, 1) = sand    (1,k,1)
    ibis_struc(n)%ibis(t)%clay(1, k, 1) = clay    (1,k,1)
   enddo

  do k=1,12
  ibis_struc(n)%ibis(t)%clmwet (1, k, 1) = clmwet  (1, k ,1)
  ibis_struc(n)%ibis(t)%clmt   (1, k, 1) = clmt	   (1, k ,1)
  ibis_struc(n)%ibis(t)%clmtrng(1, k, 1) = clmtrng (1, k ,1)
  ibis_struc(n)%ibis(t)%clmprec(1, k, 1) = clmprec (1, k ,1)
  ibis_struc(n)%ibis(t)%xinwind(1, k, 1) = xinwind (1, k ,1)
  ibis_struc(n)%ibis(t)%clmcld (1, k, 1) = clmcld  (1, k ,1)
  ibis_struc(n)%ibis(t)%clmq   (1, k, 1) = clmq	   (1, k ,1)
  ibis_struc(n)%ibis(t)%xint   (1, k, 1) = xint	   (1, k ,1)  
  ibis_struc(n)%ibis(t)%xintrng(1, k, 1) = xintrng (1, k ,1)
  ibis_struc(n)%ibis(t)%xinprec(1, k, 1) = xinprec (1, k ,1)
  ibis_struc(n)%ibis(t)%xincld (1, k, 1) = xincld  (1, k ,1)
  ibis_struc(n)%ibis(t)%xinq   (1, k, 1) = xinq	   (1, k ,1)  
  ibis_struc(n)%ibis(t)%xinwet (1, k, 1) = xinwet  (1, k ,1)
  enddo

  
  ibis_struc(n)%ibis(t)%gdd0	(1, 1) =  gdd0	  (1, 1) 
  ibis_struc(n)%ibis(t)%gdd5	(1, 1) =  gdd5	  (1, 1) 
  ibis_struc(n)%ibis(t)%gdd0this(1, 1) =  gdd0this(1, 1) 
  ibis_struc(n)%ibis(t)%tcthis  (1, 1) =  tcthis  (1, 1) 
  ibis_struc(n)%ibis(t)%twthis  (1, 1) =  twthis  (1, 1) 
  ibis_struc(n)%ibis(t)%gdd5this(1, 1) =  gdd5this(1, 1) 
  ibis_struc(n)%ibis(t)%tc	(1, 1) =  tc	  (1, 1) 
  ibis_struc(n)%ibis(t)%tw	(1, 1) =  tw	  (1, 1) 
  ibis_struc(n)%ibis(t)%tcmin	(1, 1) =  tcmin	  (1, 1) 
  ibis_struc(n)%ibis(t)%ndtimes (1, 1) =  ndtimes (1, 1) 
  ibis_struc(n)%ibis(t)%nmtimes (1, 1) =  nmtimes (1, 1) 
  ibis_struc(n)%ibis(t)%nytimes (1, 1) =  nytimes (1, 1) 
  do k=1,npft
  ibis_struc(n)%ibis(t)%nppdummy(1, k, 1) = nppdummy  (1,k,1)  ! canopy NPP before accounting for stem and root respiration
  enddo
  ibis_struc(n)%ibis(t)%tco2root(1, 1) = tco2root(1, 1) ! local instantaneous fine co2 flux from soil (mol-CO2 / m-2 / second)
  ibis_struc(n)%ibis(t)%bperm   (1, 1) = bperm   (1, 1) ! lower b.c. for soil profile drainage  (0.0 =  1.0 = fully permeable) 
!  write(ttxt,*) wsib	  (1, 1)
!  write(ttxt,*) iMaskSSiB(1, 1)
  do k=1,npft
  ibis_struc(n)%ibis(t)%exist(1, k, 1) = exist   (1,k ,1)
  enddo
  ibis_struc(n)%ibis(t)%fi	  (1, 1) = fi	    (1,  1)
  ibis_struc(n)%ibis(t)%Tsfc0IBIS (1, 1) = Tsfc0IBIS(1,  1)
  ibis_struc(n)%ibis(t)%Qsfc0IBIS (1, 1) = Qsfc0IBIS(1,  1)
  ibis_struc(n)%ibis(t)%TsfcmIBIS (1, 1) = TsfcmIBIS(1,  1)
  ibis_struc(n)%ibis(t)%QsfcmIBIS (1, 1) = QsfcmIBIS(1,  1)
!!!!!!!!!!!!!!!!!!!!!
  do k=1,nsoilay
  ibis_struc(n)%ibis(t)%tsoi0  (1, k, 1) = tsoi0 (1,k,1)
  ibis_struc(n)%ibis(t)%tsoi   (1, k, 1) = tsoi(1,k,1)
  ibis_struc(n)%ibis(t)%tsoim  (1, k, 1) = tsoim (1,k,1)
  enddo
  ibis_struc(n)%ibis(t)%hvasug (1, 1) = hvasug (1, 1)
  ibis_struc(n)%ibis(t)%hvasui (1, 1) = hvasui (1, 1)
  do k=1,nsoilay
  ibis_struc(n)%ibis(t)%wsoim  (1, k, 1) = wsoim (1,k,1)
  ibis_struc(n)%ibis(t)%wsoi   (1, k, 1) = wsoi	 (1,k,1)
  ibis_struc(n)%ibis(t)%wsoi0  (1, k, 1) = wsoi0 (1,k,1)
  ibis_struc(n)%ibis(t)%wisoi  (1, k, 1) = wisoi (1,k,1)
  ibis_struc(n)%ibis(t)%consoi (1, k, 1) = consoi(1,k,1)
  enddo
  ibis_struc(n)%ibis(t)%wpud  (1, 1) = wpud  (1, 1)
  ibis_struc(n)%ibis(t)%wipud (1, 1) = wipud (1, 1)
  do k=1,4
  ibis_struc(n)%ibis(t)%qglif(1, k, 1) = qglif(1,k ,1)
  enddo
!!!!!!!!!!!!!!!!!!!!!

  ibis_struc(n)%ibis(t)%z0soi (1, 1) = z0soi  (1, 1)
  ibis_struc(n)%ibis(t)%tg_ib    (1, 1) = tg(1, 1) 
  ibis_struc(n)%ibis(t)%ti    (1, 1) = ti(1, 1)
  ibis_struc(n)%ibis(t)%albsav(1, 1) = albsav (1, 1)
  ibis_struc(n)%ibis(t)%albsan(1, 1) = albsan (1, 1)
  do k=1,nsoilay
  ibis_struc(n)%ibis(t)%rhosoi(1, k, 1) = rhosoi (1,k,1)
  ibis_struc(n)%ibis(t)%csoi  (1, k, 1) = csoi   (1,k,1)
  ibis_struc(n)%ibis(t)%poros (1, k, 1) = poros  (1,k,1)
  ibis_struc(n)%ibis(t)%sfield(1, k, 1) = sfield (1,k,1)
  ibis_struc(n)%ibis(t)%swilt (1, k, 1) = swilt  (1,k,1)
  ibis_struc(n)%ibis(t)%bex   (1, k, 1) = bex    (1,k,1)
  ibis_struc(n)%ibis(t)%upsoiu(1, k, 1) = upsoiu (1,k,1)
  ibis_struc(n)%ibis(t)%upsoil(1, k, 1) = upsoil (1,k,1)
  enddo
  ibis_struc(n)%ibis(t)%heatg(1, 1) = heatg (1, 1)
  ibis_struc(n)%ibis(t)%heati(1, 1) = heati (1, 1)
  do k=1,nsoilay
  ibis_struc(n)%ibis(t)%ibex(1, k, 1) = ibex (1,k,1)
  enddo   
  do k=1,nsoilay+1
  ibis_struc(n)%ibis(t)%hflo(1, k, 1) = hflo (1,k,1)
  enddo


  do k=1,nsoilay
  ibis_struc(n)%ibis(t)%suction (1, k, 1) = suction (1,k,1) 
  ibis_struc(n)%ibis(t)%hydraul (1, k, 1) = hydraul (1,k,1)
  ibis_struc(n)%ibis(t)%porosflo(1, k, 1) = porosflo(1,k,1)
  ibis_struc(n)%ibis(t)%stressl (1, k, 1) = stressl (1,k,1)
  ibis_struc(n)%ibis(t)%stressu (1, k, 1) = stressu (1,k,1)
  enddo
  ibis_struc(n)%ibis(t)%stresstu(1, 1) = stresstu(1, 1) 
  ibis_struc(n)%ibis(t)%stresstl(1, 1) = stresstl(1, 1)

  do k=1,nsnolay
  ibis_struc(n)%ibis(t)%tsno(1, k, 1) = tsno(1,k,1)
  ibis_struc(n)%ibis(t)%hsno(1, k, 1) = hsno(1,k,1)
!  ibis_struc(n)%ibis(t)%tsno(1, k, 1) = 273.16
!  ibis_struc(n)%ibis(t)%hsno(1, k, 1) = 0.0
  enddo

  ibis_struc(n)%ibis(t)%iwet(1, 1) = iwet(1, 1)

  do k=1,31
  ibis_struc(n)%ibis(t)%iwetday  (1, k, 1) = iwetday  (1, k, 1)
  ibis_struc(n)%ibis(t)%precipday(1, k, 1) = precipday(1, k, 1)
  enddo
  do k=1,nband
  ibis_struc(n)%ibis(t)%asurd(1, k, 1) = asurd   (1, k  ,1)
  ibis_struc(n)%ibis(t)%asuri(1, k, 1) = asuri   (1, k  ,1)
  enddo
!!!!!!!!!!!!!!!!!!!!!
  do k=1,3
  ibis_struc(n)%ibis(t)%xstore(1, k, 1) = xstore  (1, k, 1)
  enddo
  ibis_struc(n)%ibis(t)%ginvap (1, 1) = ginvap  (1, 1) 
  ibis_struc(n)%ibis(t)%gsuvap (1, 1) = gsuvap  (1, 1) 
  ibis_struc(n)%ibis(t)%gtrans (1, 1) = gtrans  (1, 1) 
  ibis_struc(n)%ibis(t)%gtransu(1, 1) = gtransu (1, 1) 
  ibis_struc(n)%ibis(t)%gtransl(1, 1) = gtransl (1, 1) 
  ibis_struc(n)%ibis(t)%grunof (1, 1) = grunof  (1, 1) 
  ibis_struc(n)%ibis(t)%gdrain (1, 1) = gdrain  (1, 1) 
  ibis_struc(n)%ibis(t)%gadjust(1, 1) = gadjust (1, 1) 
  ibis_struc(n)%ibis(t)%wtot   (1, 1) = wtot    (1, 1)
  ibis_struc(n)%ibis(t)%adfalll(1, 1) = adfalll (1, 1)
  ibis_struc(n)%ibis(t)%adfallr(1, 1) = adfallr (1, 1)
  ibis_struc(n)%ibis(t)%adfallw(1, 1) = adfallw (1, 1)
  do k=1,npft
  ibis_struc(n)%ibis(t)%adnpp(1, k, 1) = adnpp(1, k, 1)
  enddo

  ibis_struc(n)%ibis(t)%a10td	     (1, 1) = a10td	 (1, 1)
  ibis_struc(n)%ibis(t)%a10ancub     (1, 1) = a10ancub	 (1, 1)
  ibis_struc(n)%ibis(t)%a10ancuc     (1, 1) = a10ancuc	 (1, 1)
  ibis_struc(n)%ibis(t)%a10ancls     (1, 1) = a10ancls	 (1, 1)
  ibis_struc(n)%ibis(t)%a10ancl4     (1, 1) = a10ancl4	 (1, 1)
  ibis_struc(n)%ibis(t)%a10ancl3     (1, 1) = a10ancl3	 (1, 1)
  ibis_struc(n)%ibis(t)%a10scalparamu(1, 1) = a10scalparamu(1, 1)
  ibis_struc(n)%ibis(t)%a10scalparaml(1, 1) = a10scalparaml(1, 1)
  ibis_struc(n)%ibis(t)%a10daylightu (1, 1) = a10daylightu (1, 1)
  ibis_struc(n)%ibis(t)%a10daylightl (1, 1) = a10daylightl (1, 1)
  ibis_struc(n)%ibis(t)%adrain       (1, 1) = adrain	 (1, 1)
  ibis_struc(n)%ibis(t)%adsnow       (1, 1) = adsnow	 (1, 1)
  ibis_struc(n)%ibis(t)%adaet	     (1, 1) = adaet	 (1, 1)
  ibis_struc(n)%ibis(t)%adtrunoff    (1, 1) = adtrunoff	 (1, 1)
  ibis_struc(n)%ibis(t)%adsrunoff    (1, 1) = adsrunoff	 (1, 1)
  ibis_struc(n)%ibis(t)%addrainage   (1, 1) = addrainage   (1, 1)
  ibis_struc(n)%ibis(t)%adrh	     (1, 1) = adrh	 (1, 1)
  ibis_struc(n)%ibis(t)%adsnod       (1, 1) = adsnod	 (1, 1)
  ibis_struc(n)%ibis(t)%adsnof       (1, 1) = adsnof	 (1, 1)
  ibis_struc(n)%ibis(t)%adwsoi       (1, 1) = adwsoi	 (1, 1)
  ibis_struc(n)%ibis(t)%adtsoi       (1, 1) = adtsoi	 (1, 1)
  ibis_struc(n)%ibis(t)%adwisoi      (1, 1) = adwisoi	 (1, 1)
  ibis_struc(n)%ibis(t)%adtlaysoi    (1, 1) = adtlaysoi	 (1, 1)
  ibis_struc(n)%ibis(t)%adwlaysoi    (1, 1) = adwlaysoi	 (1, 1)
  ibis_struc(n)%ibis(t)%adwsoic      (1, 1) = adwsoic	 (1, 1)
  ibis_struc(n)%ibis(t)%adtsoic      (1, 1) = adtsoic	 (1, 1)
  ibis_struc(n)%ibis(t)%adco2mic     (1, 1) = adco2mic	 (1, 1)
  ibis_struc(n)%ibis(t)%adco2root    (1, 1) = adco2root	 (1, 1)
  ibis_struc(n)%ibis(t)%adco2soi     (1, 1) = adco2soi	 (1, 1)
  ibis_struc(n)%ibis(t)%adco2ratio   (1, 1) = adco2ratio   (1, 1)
  ibis_struc(n)%ibis(t)%adnmintot    (1, 1) = adnmintot	 (1, 1)


  ibis_struc(n)%ibis(t)%amtemp     (1, 1) = amtemp    (1, 1)
  ibis_struc(n)%ibis(t)%amrain     (1, 1) = amrain    (1, 1)
  ibis_struc(n)%ibis(t)%amsnow     (1, 1) = amsnow    (1, 1)
  ibis_struc(n)%ibis(t)%amaet	   (1, 1) = amaet     (1, 1)
  ibis_struc(n)%ibis(t)%amtrunoff  (1, 1) = amtrunoff (1, 1)
  ibis_struc(n)%ibis(t)%amsrunoff  (1, 1) = amsrunoff (1, 1)
  ibis_struc(n)%ibis(t)%amdrainage (1, 1) = amdrainage(1, 1)
  ibis_struc(n)%ibis(t)%amqa	   (1, 1) = amqa      (1, 1)
  ibis_struc(n)%ibis(t)%amsolar    (1, 1) = amsolar   (1, 1)
  ibis_struc(n)%ibis(t)%amirup     (1, 1) = amirup    (1, 1)
  ibis_struc(n)%ibis(t)%amirdown   (1, 1) = amirdown  (1, 1)
  ibis_struc(n)%ibis(t)%amsens     (1, 1) = amsens    (1, 1)
  ibis_struc(n)%ibis(t)%amlatent   (1, 1) = amlatent  (1, 1)
  ibis_struc(n)%ibis(t)%amlaiu     (1, 1) = amlaiu    (1, 1)
  ibis_struc(n)%ibis(t)%amlail     (1, 1) = amlail    (1, 1)
  ibis_struc(n)%ibis(t)%amtsoi     (1, 1) = amtsoi    (1, 1)
  ibis_struc(n)%ibis(t)%amwsoi     (1, 1) = amwsoi    (1, 1)
  ibis_struc(n)%ibis(t)%amwisoi    (1, 1) = amwisoi   (1, 1)
  ibis_struc(n)%ibis(t)%amvwc	   (1, 1) = amvwc     (1, 1)
  ibis_struc(n)%ibis(t)%amawc	   (1, 1) = amawc     (1, 1)
  ibis_struc(n)%ibis(t)%amsnod     (1, 1) = amsnod    (1, 1)
  ibis_struc(n)%ibis(t)%amsnof     (1, 1) = amsnof    (1, 1)
  ibis_struc(n)%ibis(t)%amco2mic   (1, 1) = amco2mic  (1, 1)
  ibis_struc(n)%ibis(t)%amco2root  (1, 1) = amco2root (1, 1)
  ibis_struc(n)%ibis(t)%amnmintot  (1, 1) = amnmintot (1, 1) 
  do k=1,npft
  ibis_struc(n)%ibis(t)%tauwood(1, k, 1) = tauwood(1, k, 1)    ! wood biomass turnover(rotatividade) time constant (years)
  ibis_struc(n)%ibis(t)%amnpp  (1, k, 1) = amnpp  (1, k, 1)
  enddo 
  ibis_struc(n)%ibis(t)%amts2	  (1, 1) = amts2     (1, 1) 
  ibis_struc(n)%ibis(t)%amtransu  (1, 1) = amtransu  (1, 1) 
  ibis_struc(n)%ibis(t)%amtransl  (1, 1) = amtransl  (1, 1) 
  ibis_struc(n)%ibis(t)%amsuvap   (1, 1) = amsuvap   (1, 1) 
  ibis_struc(n)%ibis(t)%aminvap   (1, 1) = aminvap   (1, 1) 
  ibis_struc(n)%ibis(t)%amneetot  (1, 1) = amneetot  (1, 1) 
  ibis_struc(n)%ibis(t)%amco2ratio(1, 1) = amco2ratio(1, 1) 
  ibis_struc(n)%ibis(t)%amnpptot  (1, 1) = amnpptot  (1, 1) 
  ibis_struc(n)%ibis(t)%amco2soi  (1, 1) = amco2soi  (1, 1) 
  ibis_struc(n)%ibis(t)%amalbedo  (1, 1) = amalbedo  (1, 1)
  do k=1,nsoilay
  ibis_struc(n)%ibis(t)%amtsoil (1, k, 1) = amtsoil   (1, k, 1)
  ibis_struc(n)%ibis(t)%amwsoil (1, k, 1) = amwsoil   (1, k, 1)
  ibis_struc(n)%ibis(t)%amwisoil(1, k, 1) = amwisoil  (1, k, 1)
  enddo
  ibis_struc(n)%ibis(t)%aysolar   (1, 1) = aysolar   (1, 1) 
  ibis_struc(n)%ibis(t)%ayirup    (1, 1) = ayirup    (1, 1) 
  ibis_struc(n)%ibis(t)%ayirdown  (1, 1) = ayirdown  (1, 1) 
  ibis_struc(n)%ibis(t)%aysens    (1, 1) = aysens    (1, 1) 
  ibis_struc(n)%ibis(t)%aylatent  (1, 1) = aylatent  (1, 1) 
  ibis_struc(n)%ibis(t)%ayprcp    (1, 1) = ayprcp    (1, 1) 
  ibis_struc(n)%ibis(t)%ayaet	  (1, 1) = ayaet     (1, 1) 
  ibis_struc(n)%ibis(t)%aytrans   (1, 1) = aytrans   (1, 1) 
  ibis_struc(n)%ibis(t)%aytrunoff (1, 1) = aytrunoff (1, 1) 
  ibis_struc(n)%ibis(t)%aysrunoff (1, 1) = aysrunoff (1, 1) 
  ibis_struc(n)%ibis(t)%aydrainage(1, 1) = aydrainage(1, 1) 
  ibis_struc(n)%ibis(t)%aydwtot   (1, 1) = aydwtot   (1, 1)   
  ibis_struc(n)%ibis(t)%aydrainage(1, 1) = aygpptot  (1, 1)     
  do k=1,npft  
  ibis_struc(n)%ibis(t)%aynpp  (1, k, 1) = aynpp  (1, k, 1) 
  enddo

  ibis_struc(n)%ibis(t)%aydrainage(1, 1) = aynpptot  (1 ,1)	 
  ibis_struc(n)%ibis(t)%aydrainage(1, 1) = ayco2soi  (1 ,1)	 
  ibis_struc(n)%ibis(t)%aydrainage(1, 1) = ayneetot  (1 ,1)	 
  ibis_struc(n)%ibis(t)%totnsoi   (1, 1) = totnsoi   (1 ,1)     
  ibis_struc(n)%ibis(t)%aywsoi    (1, 1) = aywsoi    (1 ,1) 
  ibis_struc(n)%ibis(t)%aywisoi   (1, 1) = aywisoi   (1 ,1) 
  ibis_struc(n)%ibis(t)%aytsoi    (1, 1) = aytsoi    (1 ,1) 
  ibis_struc(n)%ibis(t)%ayvwc	  (1, 1) = ayvwc     (1 ,1) 
  ibis_struc(n)%ibis(t)%ayawc	  (1, 1) = ayawc     (1 ,1) 
  ibis_struc(n)%ibis(t)%aystresstu(1, 1) = aystresstu(1 ,1) 
  ibis_struc(n)%ibis(t)%aystresstl(1, 1) = aystresstl(1 ,1) 
  ibis_struc(n)%ibis(t)%ayco2mic  (1, 1) = ayco2mic  (1 ,1) 
  ibis_struc(n)%ibis(t)%ayco2root (1, 1) = ayco2root (1 ,1) 
  ibis_struc(n)%ibis(t)%ayrootbio (1, 1) = ayrootbio (1 ,1) 
  ibis_struc(n)%ibis(t)%aynmintot (1, 1) = aynmintot (1 ,1) 
  ibis_struc(n)%ibis(t)%ayalit    (1, 1) = ayalit    (1 ,1) 
  ibis_struc(n)%ibis(t)%ayblit    (1, 1) = ayblit    (1 ,1) 
  ibis_struc(n)%ibis(t)%aycsoi    (1, 1) = aycsoi    (1 ,1) 
  ibis_struc(n)%ibis(t)%aycmic    (1, 1) = aycmic    (1 ,1) 
  ibis_struc(n)%ibis(t)%ayanlit   (1, 1) = ayanlit   (1 ,1) 
  ibis_struc(n)%ibis(t)%aybnlit   (1, 1) = aybnlit   (1 ,1) 
  ibis_struc(n)%ibis(t)%aynsoi    (1, 1) = aynsoi    (1 ,1) 
  ibis_struc(n)%ibis(t)%ayalbedo  (1, 1) = ayalbedo  (1 ,1)
  do k=1,npft
  ibis_struc(n)%ibis(t)%aygpp  (1, k, 1) = aygpp  (1, k, 1)
  ibis_struc(n)%ibis(t)%ayanpp (1, k, 1) = ayanpp (1, k, 1) 
  enddo
  ibis_struc(n)%ibis(t)%ayanpptot (1, 1) = ayanpptot (1 ,1) 
  ibis_struc(n)%ibis(t)%ayrratio  (1, 1) = ayrratio  (1 ,1) 
  ibis_struc(n)%ibis(t)%aytratio  (1, 1) = aytratio  (1 ,1) 
  ibis_struc(n)%ibis(t)%totcondub (1, 1) = totcondub (1 ,1) 
  ibis_struc(n)%ibis(t)%totconduc (1, 1) = totconduc (1 ,1) 
  ibis_struc(n)%ibis(t)%totcondls (1, 1) = totcondls (1 ,1) 
  ibis_struc(n)%ibis(t)%totcondl3 (1, 1) = totcondl3 (1 ,1) 
  ibis_struc(n)%ibis(t)%totcondl4 (1, 1) = totcondl4 (1 ,1)
  do k=1,npft
  ibis_struc(n)%ibis(t)%frac (1, k, 1) = frac (1, k, 1)
  enddo
  ibis_struc(n)%ibis(t)%tum	(1, 1) = tum     (1, 1)
  ibis_struc(n)%ibis(t)%tu	(1, 1) = tu      (1, 1)
  ibis_struc(n)%ibis(t)%tu0	(1, 1) = tu0     (1, 1)
  ibis_struc(n)%ibis(t)%ts	(1, 1) = ts      (1, 1)
  ibis_struc(n)%ibis(t)%tl	(1, 1) = tl      (1, 1)
  ibis_struc(n)%ibis(t)%topparu (1, 1) = topparu (1, 1)
  ibis_struc(n)%ibis(t)%topparl (1, 1) = topparl (1, 1)
  ibis_struc(n)%ibis(t)%agcub	(1, 1) = agcub   (1, 1)
  ibis_struc(n)%ibis(t)%agcuc	(1, 1) = agcuc   (1, 1)
  ibis_struc(n)%ibis(t)%ancub	(1, 1) = ancub   (1, 1)
  ibis_struc(n)%ibis(t)%ancuc	(1, 1) = ancuc   (1, 1)
  ibis_struc(n)%ibis(t)%tlsub	(1, 1) = tlsub   (1, 1)
  ibis_struc(n)%ibis(t)%t12	(1, 1) = t12     (1, 1)
  ibis_struc(n)%ibis(t)%t34	(1, 1) = t34     (1, 1)
  ibis_struc(n)%ibis(t)%q12	(1, 1) = q12     (1, 1)
  ibis_struc(n)%ibis(t)%q34	(1, 1) = q34     (1, 1)
  ibis_struc(n)%ibis(t)%ciub	(1, 1) = ciub    (1, 1)
  ibis_struc(n)%ibis(t)%ciuc	(1, 1) = ciuc    (1, 1)
  ibis_struc(n)%ibis(t)%cils	(1, 1) = cils    (1, 1)
  ibis_struc(n)%ibis(t)%cil3	(1, 1) = cil3    (1, 1)
  ibis_struc(n)%ibis(t)%cil4	(1, 1) = cil4    (1, 1)
  ibis_struc(n)%ibis(t)%csub	(1, 1) = csub    (1, 1)
  ibis_struc(n)%ibis(t)%csuc	(1, 1) = csuc    (1, 1)
  ibis_struc(n)%ibis(t)%csls	(1, 1) = csls    (1, 1)
  ibis_struc(n)%ibis(t)%csl3	(1, 1) = csl3    (1, 1)
  ibis_struc(n)%ibis(t)%csl4	(1, 1) = csl4    (1, 1)
  ibis_struc(n)%ibis(t)%gsub	(1, 1) = gsub    (1, 1)
  ibis_struc(n)%ibis(t)%gsuc	(1, 1) = gsuc    (1, 1)
  ibis_struc(n)%ibis(t)%gsls	(1, 1) = gsls    (1, 1)
  ibis_struc(n)%ibis(t)%gsl3	(1, 1) = gsl3    (1, 1)
  ibis_struc(n)%ibis(t)%gsl4	(1, 1) = gsl4    (1, 1)
  ibis_struc(n)%ibis(t)%agcls	(1, 1) = agcls   (1, 1)
  ibis_struc(n)%ibis(t)%agcl4	(1, 1) = agcl4   (1, 1)
  ibis_struc(n)%ibis(t)%agcl3	(1, 1) = agcl3   (1, 1)
  ibis_struc(n)%ibis(t)%ancls	(1, 1) = ancls   (1, 1)
  ibis_struc(n)%ibis(t)%ancl4	(1, 1) = ancl4   (1, 1)
  ibis_struc(n)%ibis(t)%ancl3	(1, 1) = ancl3   (1, 1)
  ibis_struc(n)%ibis(t)%clitlm  (1, 1) = clitlm  (1, 1)
  ibis_struc(n)%ibis(t)%clitls  (1, 1) = clitls  (1, 1)
  ibis_struc(n)%ibis(t)%clitll  (1, 1) = clitll  (1, 1)
  ibis_struc(n)%ibis(t)%clitrm  (1, 1) = clitrm  (1, 1)
  ibis_struc(n)%ibis(t)%clitrs  (1, 1) = clitrs  (1, 1)
  ibis_struc(n)%ibis(t)%clitrl  (1, 1) = clitrl  (1, 1)
  ibis_struc(n)%ibis(t)%clitwm  (1, 1) = clitwm  (1, 1)
  ibis_struc(n)%ibis(t)%clitws  (1, 1) = clitws  (1, 1)
  ibis_struc(n)%ibis(t)%clitwl  (1, 1) = clitwl  (1, 1)
  ibis_struc(n)%ibis(t)%totcmic (1, 1) = totcmic (1, 1)
  ibis_struc(n)%ibis(t)%csoislop(1, 1) = csoislop(1, 1)
  ibis_struc(n)%ibis(t)%csoislon(1, 1) = csoislon(1, 1)
  ibis_struc(n)%ibis(t)%csoipas (1, 1) = csoipas (1, 1)
  ibis_struc(n)%ibis(t)%totlit  (1, 1) = totlit  (1, 1)
  ibis_struc(n)%ibis(t)%totnlit (1, 1) = totnlit (1, 1)
  ibis_struc(n)%ibis(t)%totfall (1, 1) = totfall (1, 1)
  ibis_struc(n)%ibis(t)%totalit (1, 1) = totalit (1, 1)
  ibis_struc(n)%ibis(t)%totrlit (1, 1) = totrlit (1, 1)
  ibis_struc(n)%ibis(t)%totanlit(1, 1) = totanlit(1, 1)
  ibis_struc(n)%ibis(t)%totrnlit(1, 1) = totrnlit(1, 1)
  ibis_struc(n)%ibis(t)%totcsoi (1, 1) = totcsoi (1, 1)
  ibis_struc(n)%ibis(t)%totnmic (1, 1) = totnmic (1, 1)
  ibis_struc(n)%ibis(t)%tco2mic (1, 1) = tco2mic (1, 1)
  ibis_struc(n)%ibis(t)%tnpptot (1, 1) = tnpptot (1, 1)
  ibis_struc(n)%ibis(t)%tneetot (1, 1) = tneetot (1, 1)
  ibis_struc(n)%ibis(t)%tnmin	(1, 1) = tnmin   (1, 1)
  ibis_struc(n)%ibis(t)%cdisturb(1, 1) = cdisturb(1, 1)
  ibis_struc(n)%ibis(t)%tempu	(1, 1) = tempu   (1, 1)
  ibis_struc(n)%ibis(t)%templ	(1, 1) = templ   (1, 1)
  ibis_struc(n)%ibis(t)%dropu	(1, 1) = dropu   (1, 1)
  ibis_struc(n)%ibis(t)%dropls  (1, 1) = dropls  (1, 1)
  ibis_struc(n)%ibis(t)%dropl4  (1, 1) = dropl4  (1, 1)
  ibis_struc(n)%ibis(t)%dropl3  (1, 1) = dropl3  (1, 1)
  ibis_struc(n)%ibis(t)%wliqu	(1, 1) = wliqu   (1, 1)
  ibis_struc(n)%ibis(t)%wliqs	(1, 1) = wliqs   (1, 1)
  ibis_struc(n)%ibis(t)%wliql	(1, 1) = wliql   (1, 1)
  ibis_struc(n)%ibis(t)%wsnou	(1, 1) = wsnou   (1, 1)
  ibis_struc(n)%ibis(t)%wsnos	(1, 1) = wsnos   (1, 1)
  ibis_struc(n)%ibis(t)%wsnol	(1, 1) = wsnol   (1, 1)
  ibis_struc(n)%ibis(t)%su	(1, 1) = su      (1, 1)
  ibis_struc(n)%ibis(t)%ss	(1, 1) = ss      (1, 1)  
  ibis_struc(n)%ibis(t)%sl	(1, 1) = sl      (1, 1)
  ibis_struc(n)%ibis(t)%agddu	(1, 1) = agddu   (1, 1)	 
  ibis_struc(n)%ibis(t)%agddl	(1, 1) = agddl   (1, 1)
  ibis_struc(n)%ibis(t)%storedn (1, 1) = storedn (1, 1)
  ibis_struc(n)%ibis(t)%yrleach (1, 1) = yrleach (1, 1)
  ibis_struc(n)%ibis(t)%ynleach (1, 1) = ynleach (1, 1)
  ibis_struc(n)%ibis(t)%falll	(1, 1) = falll   (1, 1)	
  ibis_struc(n)%ibis(t)%fallr	(1, 1) = fallr   (1, 1)	
  ibis_struc(n)%ibis(t)%fallw	(1, 1) = fallw   (1, 1)	
  ibis_struc(n)%ibis(t)%vegtype0(1, 1) = vegtype0(1, 1) 


  do k=1,npft
  !plai   (1 ,k, 1) = 5.0
  !adplai   (1 ,k, 1) = 5.0
  ibis_struc(n)%ibis(t)%plai  (1, k, 1) = plai   (1 ,k, 1)  
  ibis_struc(n)%ibis(t)%adplai(1, k, 1) = adplai (1 ,k, 1)
  enddo
  ibis_struc(n)%ibis(t)%sapfrac (1, 1) = sapfrac (1, 1) 
  do k=1,npft
  ibis_struc(n)%ibis(t)%cbiol  (1, k, 1) = cbiol  (1, k, 1)  
  ibis_struc(n)%ibis(t)%adcbiol(1, k, 1) = adcbiol(1, k, 1) 
  ibis_struc(n)%ibis(t)%cbior  (1, k, 1) = cbior  (1, k, 1)  
  ibis_struc(n)%ibis(t)%adcbior(1, k, 1) = adcbior(1, k, 1) 
  ibis_struc(n)%ibis(t)%cbiow  (1, k, 1) = cbiow  (1, k, 1)  
  ibis_struc(n)%ibis(t)%adcbiow(1, k, 1) = adcbiow(1, k, 1)  
  ibis_struc(n)%ibis(t)%biomass(1, k, 1) = biomass(1, k, 1)
  enddo
  ibis_struc(n)%ibis(t)%totlaiu (1, 1) = totlaiu(1, 1)	
  ibis_struc(n)%ibis(t)%totlail (1, 1) = totlail(1, 1)	
  ibis_struc(n)%ibis(t)%totbiou (1, 1) = totbiou(1, 1)   
  ibis_struc(n)%ibis(t)%totbiol (1, 1) = totbiol(1, 1)   
  do k=1,2
  ibis_struc(n)%ibis(t)%sai_ib  (1, k, 1) = sai  (1 ,k ,1) 
  enddo
  ibis_struc(n)%ibis(t)%fu     (1, 1) = fu     (1, 1)  
  ibis_struc(n)%ibis(t)%fl     (1, 1) = fl     (1, 1)  
  do k=1,2
  ibis_struc(n)%ibis(t)%lai_ib (1, k, 1) = lai(1 ,k  ,1) 	 
  ibis_struc(n)%ibis(t)%zbot(1, k, 1) = zbot   (1 ,k  ,1) 	 
  ibis_struc(n)%ibis(t)%ztop(1, k, 1) = ztop   (1 ,k  ,1)
  enddo		 
  ibis_struc(n)%ibis(t)%decompl (1, 1) = decompl(1, 1) 
  ibis_struc(n)%ibis(t)%decomps (1, 1) = decomps(1, 1) 
  ibis_struc(n)%ibis(t)%firefac (1, 1) = firefac(1, 1) 
  do k=1,nsoilay
  do j=1,2
  ibis_struc(n)%ibis(t)%froot(1, k, j, 1) = froot    (1,k,j,1) 
  enddo
  enddo
  do k=1,nsoilay+1
  ibis_struc(n)%ibis(t)%hsoi(1, k, 1) = hsoi(1,k,1)  
  enddo
  ibis_struc(n)%ibis(t)%vzero (1, 1) = vzero(1, 1)
  ibis_struc(n)%ibis(t)%td    (1, 1) = td   (1, 1)

  ibis_struc(n)%ibis(t)%ynleach_p (1, 1) =  ynleach_p (1 ,1)  ! annual total amount P leached from soil profile (kg_N m-2/yr)
  ibis_struc(n)%ibis(t)%tnmin_p   (1, 1) =  tnmin_p   (1 ,1)  ! instantaneous phosphorus mineralization (kg_N m-2/timestep)
  ibis_struc(n)%ibis(t)%totnmic_p (1, 1) =  totnmic_p (1 ,1)  ! total phosphorus residing in microbial pool	(kg_N m-2)
  ibis_struc(n)%ibis(t)%totnlit_p (1, 1) =  totnlit_p (1 ,1)  ! total phosphorus in all litter pools	   (kg_N m-2)
  ibis_struc(n)%ibis(t)%totanlit_p(1, 1) =  totanlit_p(1 ,1)  ! total standing aboveground phosphorus in litter (kg_N m-2)
  ibis_struc(n)%ibis(t)%totrnlit_p(1, 1) =  totrnlit_p(1 ,1)  ! total root litter phosphorus belowground	    (kg_N m-2)
  ibis_struc(n)%ibis(t)%totnsoi_p (1, 1) =  totnsoi_p (1 ,1)  ! total phosphorus in soil			    (kg_N m-2)
  ibis_struc(n)%ibis(t)%storedn_p (1, 1) =  storedn_p (1 ,1)  ! total storage of P in soil profile (kg_N m-2) 
  do k=1,nsoilay
  ibis_struc(n)%ibis(t)%depth(k) =  depth(k)
  enddo	

      enddo


    enddo

end subroutine ibis_setup

!BOP
!
! !ROUTINE: ibis_read_MULTILEVEL_param
!  \label{ibis_read_MULTILEVEL_param}
!
! !REVISION HISTORY:
!  03 Sept 2004: Sujay Kumar; Initial Specification for read_laiclimo
!  30 Oct  2013: Shugong Wang; Generalization for reading MULTILEVEL spatial parameter
!
! !INTERFACE:
subroutine ibis_read_MULTILEVEL_param(n, ncvar_name, level, placeholder)
! !USES:
    use netcdf
    use LIS_coreMod, only : LIS_rc, LIS_domain, LIS_localPet,   &   
                            LIS_ews_halo_ind, LIS_ewe_halo_ind, &
                            LIS_nss_halo_ind, LIS_nse_halo_ind   
    use LIS_logMod,  only : LIS_logunit, LIS_verify, LIS_endrun
    use LIS_fileIOMod, only: LIS_read_param
    implicit none
! !ARGUMENTS: 
    integer, intent(in)          :: n
    integer, intent(in)          :: level
    character(len=*), intent(in) :: ncvar_name 
    real, intent(out)            :: placeholder(LIS_rc%lnc(n), LIS_rc%lnr(n))
! !DESCRIPTION:
!  This subroutine reads MULTILEVEL parameters from the LIS
!  NetCDF parameter data file
!  
!  The arguments are:
!  \begin{description}
!   \item[n]
!    index of n
!   \item[level]
!    level index (month, quarter, soil layer, snow layer) of the data to be read
!   \item[array]
!    array containing returned values
!   \end{description}
!
!EOP      

    integer       :: ios1
    integer       :: ios, nid, param_ID, nc_ID, nr_ID, dimids(3)
    integer       :: nc, nr, t, nlevel, k
    real, pointer :: level_data(:, :, :)
    logical       :: file_exists

    inquire(file=LIS_rc%paramfile(n), exist=file_exists)
    if(file_exists) then
        write(LIS_logunit, *) 'Reading '//trim(ncvar_name)//' map for level ', level

        ! open NetCDF parameter file
        ios = nf90_open(path=trim(LIS_rc%paramfile(n)), mode=NF90_NOWRITE, ncid=nid)
        call LIS_verify(ios, 'Error in nf90_open in ibis_read_MULTILEVEL_param')

        ! inquire the ID of east-west dimension
        ios = nf90_inq_dimid(nid, 'east_west', nc_ID)
        call LIS_verify(ios, 'Error in nf90_inq_dimid in ibis_read_MULTILEVEL_param')

        ! inquire the ID of north-south dimension
        ios = nf90_inq_dimid(nid, 'north_south', nr_ID)
        call LIS_verify(ios, 'Error in nf90_inq_dimid in ibis_read_MULTILEVEL_param')

        ! inquire the length of east-west dimension
        ios = nf90_inquire_dimension(nid, nc_ID, len=nc)
        call LIS_verify(ios, 'Error in nf90_inquire_dimension in ibis_read_MULTILEVEL_param')

        ! inquire the length of north-south dimension
        ios = nf90_inquire_dimension(nid, nr_ID, len=nr)
        call LIS_verify(ios, 'Error in nf90_inquire_dimension in ibis_read_MULTILEVEL_param')

        ! inquire the ID of parameter. 
        ios = nf90_inq_varid(nid, Trim(ncvar_name), param_ID)
        call LIS_verify(ios, trim(ncvar_name)//' field not found in the LIS param file')

        ! inquire the IDs of all dimensions. The third dimension is the level dimension
        ios = nf90_inquire_variable(nid, param_ID, dimids = dimids)
        call LIS_verify(ios, trim(ncvar_name)//' failed to inquire dimensions')

        ! inquire the length of the level dimension
        ios = nf90_inquire_dimension(nid, dimids(3), len=nlevel)
        call LIS_verify(ios, trim(ncvar_name)//' failed to inquire the length of the 3rd dimension')

        ! allocate memory
        allocate(level_data (LIS_rc%gnc(n), LIS_rc%gnr(n), nlevel))

        ! inquire the variable ID of parameter 
        ios = nf90_inq_varid(nid, trim(ncvar_name), param_ID)
        call LIS_verify(ios, trim(ncvar_name)//' field not found in the LIS param file')

        ! read parameter 
        ios = nf90_get_var(nid, param_ID, level_data)
        call LIS_verify(ios, 'Error in nf90_get_var in ibis_read_MULTILEVEL_param')

        ! close netcdf file 
        ios = nf90_close(nid)
        call LIS_verify(ios, 'Error in nf90_close in ibis_read_MULTILEVEL_param')

        ! grab parameter at specific level
        placeholder(:, :) = & 
             level_data(LIS_ews_halo_ind(n, LIS_localPet+1):LIS_ewe_halo_ind(n, LIS_localPet+1), &
                        LIS_nss_halo_ind(n, LIS_localPet+1):LIS_nse_halo_ind(n, LIS_localPet+1), level)

        ! free memory 
        deallocate(level_data)

    else
        write(LIS_logunit, *) 'MULTILEVEL parameter data file: ', LIS_rc%paramfile(n), ' does not exist'
        write(LIS_logunit, *) 'program stopping ...'
        call LIS_endrun
    endif
 end subroutine ibis_read_MULTILEVEL_param
                                          

