SUBROUTINE WRTDCDF
USE PARKIND1  ,ONLY : JPIM     ,JPRB,JPRM,JPRD

!**** *WRTDCDF*  - writes diagnostics to NetCDF files

!     Purpose.
!     --------
!        writes out diagnostic variables

!**   Interface.
!     ----------
!        *CALL* *WRTDCDF

!     Explicit arguments :
!     --------------------

!        Implicit arguments :
!        --------------------

!     Method.
!     -------
!        See documentation

!     Externals.
!     ----------
!        None

!     Reference.
!     ----------

!     Author.
!     -------
!        Bart vd Hurk (KNMI)

!     Modifications.
!     --------------
!        original: 14/7/2000
!        E. Dutra - NEW OUTPUT FILE FOR LAKES : 04/07/2008
!        Y. Takaya - Add ocean mixed layer output : 07/10/2008

USE YOMLUN1S , ONLY : NPOSEFL  ,NPOSWAT  ,NPOSSUS  ,NPOSSUB &
           &,NPOSEVA  ,NPOSCLD ,RMISS, NPOSLKE, NPOSOCD &
           &,NPOSCO2 ,NPOSVEG  ,NPOSEXT &
	   &,NPOSBIO  ,NPOSTIL  ,NPOSVTY,NPOSGGD
USE YOMLOG1S , ONLY : LACCUMW  ,LRESET   ,NACCUR   ,NDIMCDF &
           &,LWREFL   ,LWRWAT   ,LWRSUB   ,LWRSUS   ,LWREVA &
           &,LWRCLD   ,LWRLKE   ,LWROCD &
           &,LWRCO2   ,LWRVEG  ,LWREXT   ,LWRBIO &
	   &,LWRTIL   ,LWRVTY,LWRGGD,LNCSNC
USE YOMCT01S , ONLY : NSTART   ,NFRPOS
USE YOETHF   , ONLY : R2ES, R3LES, R3IES, R4LES, R4IES, R5LES, R5ALVCP, &
           &          R5IES, R5ALSCP, RALVDCP, RTICE, RTWAT, RTWAT_RTICE_R, &
           &          RTICECU, RTWAT_RTICECU_R, RALSDCP,RHOH2O

USE YOMGPD1S , ONLY : VFCVL    ,VFCVH    ,VFTVL    ,VFTVH    ,VFSOTY   ,&
           &VFOCDEPTH,VFZO     ,VDZ0F    ,VDZ0H  
USE YOMGC1S  , ONLY : LMASK
USE YOMDYN1S , ONLY : NSTEP    ,TSTEP
USE YOMRIP   , ONLY : RSTATI
USE YOEPHY   , ONLY : LEVGEN, LECTESSEL 
USE YOESOIL1S, ONLY : RDAW     ,RWPWP    ,RWSAT    ,RWPWPM,RWSATM,RWCAPM
USE YOMDPHY  , ONLY : NLAT     ,NLON     ,NPOI ,NTILES ,NVHILO, &
                    & NLALO    ,NSLAB    ,ISLAB   ,NCSS , NSOTY, NCOM, YDSURF !KPP
USE YOMGP1SA , ONLY : FSNNUA   ,TSLNUA   ,QLINUA   ,QLQNUA,&
            &TSNNUA   ,WRENUA   ,ASNNUA   ,RSNNUA,&
            &TLICENUA,TLMNWNUA,TLWMLNUA,TLBOTNUA,TLSFNUA,HLICENUA,HLMLNUA,&
            &WSNNUA
USE YOMGDI1S , ONLY :&
            &D1SRFLD2 ,D1SRFLU2 ,D1TRFLD2 ,D1TRFLU2 &
           &,D1STISRD2,D1STISRU2,D1STASF2 ,D1SWNJQ2 &
           &,D1SWLJQ2 ,D1SW1JBG2,D1SWAEXT2,D1SGHF2 &
           &,D1STITK2 ,D1SVEGTK2,D1STIFR2 ,D1SDSH2 &
           &,D1AHFS2  ,D1AHFL2  ,D1SAVTK2 ,D1SRADTK2 &
           &,D1SALB2  ,D1STNDH2 ,D1SWDS2  ,D1SW1C2 &
           &,D1SSDS2  ,D1SWLDS2 ,D1SNFR2  ,D1SNTFR2 &
           &,D1SNAFR2 &
           &,D1SLSRF2 ,D1SCRF2  ,D1SLSSF2 ,D1SCSF2  &
           &,D1STE2   ,D1STRO2  ,D1STSRO2 ,D1SMLT2  &
           &,D1SVTRA2 ,D1T2M2    ,D1D2M2            &
           &,D1STITRD2,D1STITRU2,D1STILE2,D1STIH2   &
           &,D1STIEVAP2,D1HFLUXRF2,D1WFLUXRF2,D1WSN2 &
! CO2	   
           &,D1SAN2,D1SAG2,D1SRD2,D1SRSOIL_STR2,D1SRECO2,D1SCO2FLUX2 &
	   &,D1SVTAN2,D1SVTAG2,D1SVTRD2,D1SVTRSOIL_STR2,D1SVTRECO2,D1SVTCO2FLUX2 &
! LAI, biomass
           &,D1SLAI2,D1SBIOM2,D1SBLOSS2,D1SBGAIN2,D1SBIOMSTR2,D1SBIOMSTRB2 &
	   &,D1SVTLAI2,D1SVTBIOM2,D1SVTBLOSS2,D1SVTBGAIN2 &
	   &,D1SVTBIOMSTR2,D1SVTBIOMSTRB2 &
! vegetation variables
	   &,D1SVTGC2 ,D1SVTGA2 ,D1SVTF22 &
	   &,D1SVTLE2 ,D1SVTFR2 ,D1SVTDS2 ,D1SVTDMAX2 &
! fractions
           &,D1SWFR2 &
! tiled ouput
           &,D1STIH2,D1STILE2,D1STIALB2 &
! extra WATER
	   &,D1SWLIT2,D1SWAGFL2,D1SWDSSL2 &
! extra FORCING (Alterra validation)	
           &,D1STAIR2, D1SQAIR2, D1SUWIND2, D1SVWIND2,D1STIEVAPU2 &
           &,D1STNGFL2,D1STNM2,D1STISKC2

USE YOMCST   , ONLY : RTT      ,RDAY,  RMV   ,  RMD, RLVTT, RLSTT
USE YOMGP1S0 , ONLY :TRENU0

IMPLICIT NONE

!* Netcdf Interface
INTEGER NVARID,NPOS,NSTPP,IERR
INTEGER ISTART1(1),ISTART3(3),ISTART4(4)
INTEGER ICOUNT1(1),ICOUNT3(3),ICOUNT4(4),ICOUNT4O(4)
REAL(KIND=JPRM),ALLOCATABLE :: ZOUTPUTS(:)
REAL(KIND=JPRM),ALLOCATABLE :: ZOUTPUT3S(:,:)
REAL(KIND=JPRD),ALLOCATABLE :: ZOUTPUT(:)
REAL(KIND=JPRD),ALLOCATABLE :: ZOUTPUT3(:,:)
REAL(KIND=JPRM),ALLOCATABLE :: ZOUTOCN3S(:,:) !KPP
REAL(KIND=JPRD),ALLOCATABLE :: ZOUTOCN3(:,:)  !KPP
REAL(KIND=JPRD) :: ZTIME

!* Local variables
INTEGER(KIND=JPIM), PARAMETER :: JPNCDF=14  !KPP 7+6CTESSEL
REAL(KIND=JPRB),ALLOCATABLE :: ZVALUE(:)
REAL(KIND=JPRB),ALLOCATABLE :: ZSNOFR(:)
REAL(KIND=JPRB),ALLOCATABLE :: ZICEFR(:)
REAL(KIND=JPRB),ALLOCATABLE :: ZQLINUA(:,:) 
! ARDU ADDED
REAL(KIND=JPRB),ALLOCATABLE :: ZQFINUA(:,:)    
REAL(KIND=JPRB),ALLOCATABLE :: ZLIQ(:,:)
REAL(KIND=JPRB),ALLOCATABLE :: ZSWET(:)   
REAL(KIND=JPRB),ALLOCATABLE :: ZSROOT(:)
REAL(KIND=JPRB),ALLOCATABLE :: ZFDEPT(:)  
REAL(KIND=JPRB),ALLOCATABLE :: ZFTHAW(:)    
REAL(KIND=JPRB),ALLOCATABLE :: ZSNDEP(:)  
REAL(KIND=JPRB),ALLOCATABLE :: ZACOND(:)
INTEGER(KIND=JPIM) IPOS(JPNCDF)
LOGICAL LPOS(JPNCDF)
INTEGER(KIND=JPIM) :: IX1,IX2,IY1,IY2,NLEN,IST,IEN,IA,IYYMD,IHM,&
     &  ITYPL,ITYPH,JL,JK,JS,ISLOT,J,JTILE,JVT
REAL(KIND=JPRB) :: ZWA,ZMM,ZMM2,ZPA,ZJUL,ZWPWP,ZWSAT,ZCVL,ZCVH,ZBOT,ZF,&
     &  ZTOP,ZRVCOV(0:20),ZRVROOTSA(NCSS,0:20),RLMLT,ZIHCAP,ZEPSILON
REAL(KIND=JPRB), ALLOCATABLE :: ZSSN(:),ZRSN(:),ZTSN(:),ZWSN(:),ZTMP1(:)
INTERFACE
#include "surf_inq.h"
END INTERFACE
#include "netcdf.inc"
#include "fcttre.h"

ZEPSILON=10._JPRB*EPSILON(ZEPSILON)

IF (LEVGEN) THEN
    IF (.NOT.ALLOCATED(RWSATM)) ALLOCATE(RWSATM(0:NSOTY))
    IF (.NOT.ALLOCATED(RWCAPM)) ALLOCATE(RWCAPM(0:NSOTY))
    IF (.NOT.ALLOCATED(RWPWPM)) ALLOCATE(RWPWPM(0:NSOTY))
!EC   CALL SURF_INQ(YDSURF,PRVCOV=ZRVCOV,PRVROOTSA=ZRVROOTSA,&
!EC               &PRDAW=RDAW,PRWSATM=RWSATM,PRWPWPM=RWPWPM)
  CALL SURF_INQ(PRVCOV=ZRVCOV,PRVROOTSA=ZRVROOTSA,&
              &PRDAW=RDAW,PRWSATM=RWSATM,PRWPWPM=RWPWPM)
ELSE
!EC   CALL SURF_INQ(YDSURF,PRVCOV=ZRVCOV,PRVROOTSA=ZRVROOTSA,&
!EC               &PRDAW=RDAW,PRWSAT=RWSAT,PRWPWP=RWPWP)
    CALL SURF_INQ(PRVCOV=ZRVCOV,PRVROOTSA=ZRVROOTSA,&
              &PRDAW=RDAW,PRWSAT=RWSAT,PRWPWP=RWPWP)
ENDIF

IF(NDIMCDF == 2)THEN
  IX1=1
  IX2=NLON
  IY1=(ISLAB-1)*NSLAB+1
  IY2=MIN(NLAT,ISLAB*NSLAB)
  NLEN=(IX2-IX1+1)*(IY2-IY1+1)
  IST=IX1+(IY1-1)*NLON
  IEN=IST+NLEN-1
ELSE
  IST=(ISLAB-1)*NSLAB+1
  IEN=MIN(NLALO,ISLAB*NSLAB)
  NLEN=IEN-IST+1
ENDIF
ALLOCATE (ZOUTPUT(NLEN))		!INFLATED OUTPUT ARRAY
ALLOCATE (ZOUTPUTS(NLEN))		!INFLATED OUTPUT ARRAY
ALLOCATE (ZOUTPUT3(NLEN,NCSS))	!INFLATED OUTPUT ARRAY
ALLOCATE (ZOUTPUT3S(NLEN,NCSS))	!INFLATED OUTPUT ARRAY
ALLOCATE (ZOUTOCN3(NLEN,NCOM+1))	!KPP
ALLOCATE (ZOUTOCN3S(NLEN,NCOM+1))	!KPP

IF (LACCUMW) THEN
  IF(LRESET)THEN
!     ZWA - FACTOR TO TRANSFORM W/M**2*S INTO W/M**2
!     ZMM - FACTOR TO TRANSFORM KG/M**2 INTO MM/S (AVERAGING)
!     ZMM2 - FACTOR TO TRANSFORM KG/M**2 PER MODEL TIMESTEP INTO MM
!            PER OUTPUT TIME STEP (ACCUMULATING)
    ZWA=1./(NFRPOS*TSTEP)
    ZMM=1./(NFRPOS*TSTEP)
    ZMM2=1./TSTEP
  ELSE
!     ZWA - FACTOR TO TRANSFORM W/M**2*S INTO W/M**2
!     ZMM - FACTOR TO TRANSFORM KG/M**2 INTO MM
    IF(NSTEP == 0)THEN
      ZWA=0.
    ELSE
      ZWA=1./(NSTEP*TSTEP)
    ENDIF
    ZMM=1.
    ZMM2=1.
  ENDIF
  IA=2
ELSE
!     ZWA - FACTOR TO TRANSFORM W/M**2 INTO W/M**2
!     ZMM - FACTOR TO TRANSFORM KG/M**2/S INTO MM/DAY
  ZWA=1.
  ZMM=RDAY
  ZMM2=1.
  IA=1
ENDIF

IF(NSTEP == NSTART)THEN
  ZPA=1.
ELSE
  ZPA=1./NFRPOS
ENDIF

!*     UNIT CONVERSION OF PROGNOSTIC QUANTITIES

ALLOCATE (ZQLINUA(NPOI,NCSS))	!RESCALED SOIL WATER
! ARDU ADDED:
ALLOCATE (ZQFINUA(NPOI,NCSS))	!FROZEN FRACTION OF SOIL WATER
ALLOCATE (ZLIQ(NPOI,NCSS))	!LIQUID SOIL WATER
ALLOCATE (ZSWET(NPOI))		!TOTAL SOIL WETNESS
ALLOCATE (ZSROOT(NPOI))		!ROOT AVAILABLE SOIL WATER
ALLOCATE (ZFDEPT(NPOI))		!DEPTH OF FROZEN SOIL
ALLOCATE (ZFTHAW(NPOI))		!DEPTH OF THAW LAYER
ALLOCATE (ZSNDEP(NPOI))		!SNOW DEPTH
ALLOCATE (ZSNOFR(NPOI))     !SNOW FRACTION
ALLOCATE (ZICEFR(NPOI))     !ICE FRACTION
ALLOCATE (ZACOND(NPOI))		!AERODYNAMIC RESISTANCE

!* calculating average aerodynamic conductance
!DO JL=1,NPOI
!   ZACOND(JL)=1.0_JPRB/D1SVTRA2(JL,1,IA)
!ENDDO

DO JK=1,NCSS
  ZQLINUA(1:NPOI,JK)=QLINUA(1:NPOI,JK)*RDAW(JK)*RHOH2O
  ZLIQ(1:NPOI,JK)=QLQNUA(1:NPOI,JK)
ENDDO


!* store snow and ice fraction for later use
ZSNOFR(1:NPOI)=D1SNFR2(1:NPOI,IA)*ZWA
ZICEFR(1:NPOI)=D1STIFR2(1:NPOI,2,IA)*ZWA

!* calculation of snow depth
ZSNDEP(:)=SUM(FSNNUA(:,:)/RSNNUA(:,:),DIM=2)

! RTT=273.16_JPRB
RLMLT=2.8345E+6_JPRB-2.5008E+6_JPRB
ZIHCAP=2.05E6_JPRB/920._JPRB
ALLOCATE (ZSSN(NPOI))
ALLOCATE (ZRSN(NPOI))
ALLOCATE (ZTSN(NPOI))
ALLOCATE (ZWSN(NPOI))
ALLOCATE (ZTMP1(NPOI))
! Total snow variables
ZSSN(:) = SUM(FSNNUA(:,:)*ZPA,DIM=2)
ZTMP1(:) = SUM(ZIHCAP*FSNNUA(:,:)*ZPA*(TSNNUA(:,:)*ZPA-RTT) - &    ! INTERNAL ENERGY
              RLMLT*(FSNNUA(:,:)*ZPA-WSNNUA(:,:)*ZPA),DIM=2)
WHERE (ZSSN > ZEPSILON .AND. ZSNDEP > ZEPSILON )
  ZRSN = ZSSN / ZSNDEP
  ZTSN = MIN(RTT, RTT + (ZTMP1+RLMLT*ZSSN)/(ZIHCAP*ZSSN))
  ZWSN = MAX(0._JPRB,ZSSN+ZTMP1/RLMLT)
ELSEWHERE
  ZRSN = 100._JPRB
  ZTSN = RTT
  ZWSN = 0._JPRB
ENDWHERE

!* calculation of total soil wetness

DO JL=1,NPOI
  IF(LEVGEN)THEN
    JS=NINT(VFSOTY(JL))
    ZWPWP=RWPWPM(JS)
    ZWSAT=RWSATM(JS)
  ELSE
    ZWPWP=RWPWP
    ZWSAT=RWSAT
  ENDIF
  IF ( (ZWSAT-ZWPWP) > 0._JPRB ) THEN
    ZSWET(JL)=&
     &(DOT_PRODUCT(ZPA*QLINUA(JL,:),RDAW(:))-&
     &SUM(RDAW)*ZWPWP)/&
     &(SUM(RDAW)*(ZWSAT-ZWPWP))
  ELSE
    ZSWET(JL)=0.0_JPRB
  ENDIF
ENDDO

!* calculation of root zone soil moisture content: all liquid water
!  above wilting point in layers where roots are found

DO JL=1,NPOI
  ITYPL=NINT(VFTVL(JL))
  ITYPH=NINT(VFTVH(JL))
  ZCVL=VFCVL(JL)*ZRVCOV(ITYPL)
  ZCVH=VFCVH(JL)*ZRVCOV(ITYPH)
  IF(LEVGEN)THEN
    JS=NINT(VFSOTY(JL))
    ZWPWP=RWPWPM(JS)
  ELSE
    ZWPWP=RWPWP
  ENDIF

  ZSROOT(JL)=0.
  DO JK=1,NCSS
    IF((ZCVL > 0. .AND. ZRVROOTSA(JK,ITYPL) > 0.) .OR.&
     &(ZCVH > 0. .AND. ZRVROOTSA(JK,ITYPH) > 0.)) THEN
      ZSROOT(JL)=ZSROOT(JL)+&
       &MAX(ZPA*ZLIQ(JL,JK)-RDAW(JK)*RHOH2O*ZWPWP, 0.0_JPRB)
    ENDIF
  ENDDO
ENDDO

!* calculation of depth of frozen ground and thaw layer
ZQFINUA(:,:)=0._JPRB 
DO JL=1,NPOI
  ZFDEPT(JL)=0.
  ZBOT=0.
  DO JK=1,NCSS
    ZF = 0_JPRB
    IF (ZQLINUA(JL,JK) > 0._JPRB ) THEN
      ZF=MAX(0._JPRB,MIN(1._JPRB,1._JPRB-QLQNUA(JL,JK)/ZQLINUA(JL,JK)))
! ARDU ADDED
! Storing of fraction of frozen liquid water
      ZQFINUA(JL, JK) = ZF
    ENDIF
    ZTOP=ZBOT
    ZBOT=ZTOP+RDAW(JK)
    IF(ZF > 0.)THEN
      ZFDEPT(JL)=MIN(SUM(RDAW),ZTOP+ZF*(ZBOT-ZTOP))
    ENDIF
  ENDDO

  ZBOT=SUM(RDAW)
  ZFTHAW(JL)=ZBOT
  DO JK=NCSS,1,-1
    ZF=0._JPRB
    IF ( ZQLINUA(JL,JK) > 0._JPRB ) THEN
      ZF=MAX(0._JPRB,MIN(1._JPRB,1._JPRB-QLQNUA(JL,JK)/ZQLINUA(JL,JK)))
    ENDIF
    ZTOP=ZBOT-RDAW(JK)
    IF(ZF > 0.)THEN
      ZFTHAW(JL)=MAX(0._JPRB,ZBOT+ZF*(ZTOP-ZBOT))
    ENDIF
    ZBOT=ZTOP
  ENDDO
ENDDO

!* ===============================================================
!     START OUTPUT
!* ===============================================================

IPOS(1)=NPOSEFL
IPOS(2)=NPOSWAT
IPOS(3)=NPOSSUS
IPOS(4)=NPOSSUB
IPOS(5)=NPOSEVA
IPOS(6)=NPOSCLD
IPOS(7)=NPOSOCD
IPOS(8)=NPOSCO2
IPOS(9)=NPOSBIO
IPOS(10)=NPOSVEG
IPOS(11)=NPOSEXT
IPOS(12)=NPOSTIL
IPOS(13)=NPOSVTY
IPOS(14)=NPOSGGD

      
LPOS(1)=LWREFL
LPOS(2)=LWRWAT
LPOS(3)=LWRSUS
LPOS(4)=LWRSUB
LPOS(5)=LWREVA
LPOS(6)=LWRCLD
LPOS(7)=LWROCD
LPOS(8)=LWRCO2
LPOS(9)=LWRBIO
LPOS(10)=LWRVEG
LPOS(11)=LWREXT
LPOS(12)=LWRTIL
LPOS(13)=LWRVTY
LPOS(14)=LWRGGD

!     time level
!CALL DATTIM(zjul,IYYMD,IHM)

! when accumulated or averaged output is required, output is backwar
! averaged, and output just before the first time step is skipped

IF(LACCUMW)THEN
  ISTART1(1)=(NSTEP-NSTART)/NFRPOS
ELSE
  ISTART1(1)=(NSTEP-NSTART)/NFRPOS+1
ENDIF
ISLOT=ISTART1(1)
NSTPP=NSTEP
ZTIME=RSTATI-0.5*TSTEP
IF (ISLOT < 1) RETURN
DO J=1,JPNCDF
  IF(LPOS(J))THEN
    NPOS=IPOS(J)
    NVARID = NCVID(NPOS,'time',IERR)
    CALL NCVPT1 (NPOS,NVARID,ISTART1,ZTIME,IERR)
    NVARID = NCVID(NPOS,'timestp',IERR)
    CALL NCVPT1 (NPOS,NVARID,ISTART1,NSTPP,IERR)
  ENDIF
ENDDO
IF(NDIMCDF == 2)THEN
  ISTART3(1)=IX1
  ISTART3(2)=IY1
  ISTART3(3)=ISLOT
  ICOUNT3(1)=IX2-IX1+1
  ICOUNT3(2)=IY2-IY1+1
  ICOUNT3(3)=1

  ISTART4(1)=IX1
  ISTART4(2)=IY1
  ISTART4(3)=1
  ISTART4(4)=ISLOT
  ICOUNT4(1)=IX2-IX1+1
  ICOUNT4(2)=IY2-IY1+1
  ICOUNT4(3)=NCSS
  ICOUNT4(4)=1
ELSE
  ISTART3(1)=IST
  ISTART3(2)=ISLOT
  ICOUNT3(1)=NLEN
  ICOUNT3(2)=1

  ISTART4(1)=IST
  ISTART4(2)=1
  ISTART4(3)=ISLOT
  ICOUNT4(1)=NLEN
  ICOUNT4(2)=NCSS
  ICOUNT4(3)=1
ENDIF

ALLOCATE (ZVALUE(NPOI))

IF(LWREFL)THEN
!* -- The surface fluxes
!******************************************************************
  NPOS = NPOSEFL

!     net shortwave
  NVARID = NCVID(NPOS,'SWnet',IERR)
  ZVALUE(:)=(D1SRFLD2(:,IA)+D1SRFLU2(:,IA))*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     net longwave
  NVARID = NCVID(NPOS,'LWnet',IERR)
  ZVALUE(:)=(D1TRFLD2(:,IA)+D1TRFLU2(:,IA))*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     latent heat flux
  NVARID = NCVID(NPOS,'Qle',IERR)
  ZVALUE(:)=D1AHFL2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     sensible heat flux
  NVARID = NCVID(NPOS,'Qh',IERR)
  ZVALUE(:)=D1AHFS2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     soil heat flux (conduction of Tsk - T1 + shortwave transmission)
  NVARID = NCVID(NPOS,'Qg',IERR)
  ZVALUE(:)=D1SGHF2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
 
!     snow basal heat flux 
  NVARID = NCVID(NPOS,'Qgsn',IERR)
  ZVALUE(:)=D1STNGFL2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
  
!     snow phase changes
  NVARID = NCVID(NPOS,'Qfsn',IERR)
  ZVALUE(:)=D1STNM2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     soil freezing flux
  NVARID = NCVID(NPOS,'Qf',IERR)
  ZVALUE(:)=SUM(D1STASF2(:,:,IA),DIM=2)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     soil heat content change
  NVARID = NCVID(NPOS,'DelSoilHeat',IERR)
  ZVALUE(:)=D1SDSH2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     snow heat content change
  NVARID = NCVID(NPOS,'DelColdCont',IERR)
  ZVALUE(:)=D1STNDH2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     upward longwave
  NVARID = NCVID(NPOS,'LWup',IERR)
  ZVALUE(:)=D1TRFLU2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!    SWdown
  NVARID = NCVID(NPOS,'SWdown',IERR)
  ZVALUE(:)=D1SRFLD2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !    SWdown
  NVARID = NCVID(NPOS,'LWdown',IERR)
  ZVALUE(:)=D1TRFLD2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF


ENDIF

IF(LWRWAT)THEN
!* -- Water balance
!******************************************************************
  NPOS = NPOSWAT

!     snowfall
  NVARID = NCVID(NPOS,'Snowf',IERR)
  ZVALUE(:)=(D1SLSSF2(:,IA)+D1SCSF2(:,IA))*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     rainfall
  NVARID = NCVID(NPOS,'Rainf',IERR)
  ZVALUE(:)=(D1SLSRF2(:,IA)+D1SCRF2(:,IA))*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     evapotranspiration
  NVARID = NCVID(NPOS,'Evap',IERR)
  ZVALUE(:)=D1STE2(:,IA)*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     surface runoff
  NVARID = NCVID(NPOS,'Qs',IERR)
  ZVALUE(:)=-(D1STSRO2(:,IA))*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     Subsurface runoff
  NVARID = NCVID(NPOS,'Qsb',IERR)
  ZVALUE(:)=-(D1STRO2(:,IA)-D1STSRO2(:,IA))*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     snowmelt
  NVARID = NCVID(NPOS,'Qsm',IERR)
  ZVALUE(:)=D1SMLT2(:,IA)*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     soil water storage change
  NVARID = NCVID(NPOS,'DelSoilMoist',IERR)
  ZVALUE(:)=D1SWDS2(:,IA)*ZMM2
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     snow water storage change
  NVARID = NCVID(NPOS,'DelSWE',IERR)
  ZVALUE(:)=D1SSDS2(:,IA)*ZMM2
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     interception water storage change
  NVARID = NCVID(NPOS,'DelIntercept',IERR)
  ZVALUE(:)=D1SWLDS2(:,IA)*ZMM2
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     interception 
  NVARID = NCVID(NPOS,'Intercept',IERR)
  ZVALUE(:)=D1SWLIT2(:,IA)*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
! 
!   !     soil water storage change per soil layer 
!   NVARID = NCVID(NPOS,'DelSoilMoistLayer',IERR)
!   DO JK=1,NCSS
!     ZVALUE(:)=D1SWDSSL2(:,JK,IA)*ZMM2
!     ZOUTPUT3(:,JK)= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!   ENDDO
!   IF(NACCUR == 1)THEN
!     ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
!   ENDIF
! 
!  !     root extraction per soil layer
!   NVARID = NCVID(NPOS,'RootExtLayer',IERR)
!   DO JK=1,NCSS
!     ZVALUE(:)=D1SWAEXT2(:,JK,IA)*ZMM
!     ZOUTPUT3(:,JK)= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!   ENDDO
!   IF(NACCUR == 1)THEN
!     ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
!   ENDIF
! 
!  !     Ground water flux per soil layer
!   NVARID = NCVID(NPOS,'GWLayer',IERR)
!   DO JK=1,NCSS
!     ZVALUE(:)=D1SWAGFL2(:,JK,IA)*ZMM
!     ZOUTPUT3(:,JK)= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!   ENDDO
!   IF(NACCUR == 1)THEN
!     ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
!   ENDIF


ENDIF
      
IF(LWRSUS)THEN
!* -- Surface state variables
!******************************************************************
  NPOS = NPOSSUS

!     momentum roughness
  NVARID = NCVID(NPOS,'z0m',IERR)
  ZOUTPUT=UNPACK(VDZ0F,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     heat roughness
  NVARID = NCVID(NPOS,'lz0h',IERR)
  ZOUTPUT=UNPACK(LOG(VDZ0H),LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     vegetation temperature: area weighted average over tiles 4 & 6
  NVARID = NCVID(NPOS,'VegT',IERR)
  ZVALUE(:)=D1SVEGTK2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     bare soil temperature
  NVARID = NCVID(NPOS,'BaresoilT',IERR)
  ZVALUE(:)=D1STITK2(:,8,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF


!     surface radiative temperature
  NVARID = NCVID(NPOS,'RadT',IERR)
  ZVALUE(:)=D1SRADTK2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     surface albedo
  NVARID = NCVID(NPOS,'Albedo',IERR)
  ZVALUE(:)=D1SALB2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !* -- LAI
  NVARID = NCVID(NPOS,'lai',IERR)
  ZVALUE(:)=D1SLAI2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF  


ENDIF

IF (LWRGGD) THEN
  NPOS = NPOSGGD

  !     soil moisture
  NVARID = NCVID(NPOS,'SoilMoist',IERR)
  DO JK=1,NCSS
    ZVALUE(:)=ZQLINUA(:,JK)*ZPA
    ZOUTPUT3(:,JK)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF

  !     soil temperature
  NVARID = NCVID(NPOS,'SoilTemp',IERR)
  DO JK=1,NCSS
    ZVALUE(:)=TSLNUA(:,JK)*ZPA
    ZOUTPUT3(:,JK)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF

  !     average surface temperature
  NVARID = NCVID(NPOS,'AvgSurfT',IERR)
  ZVALUE(:)=D1SAVTK2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !     Canopy interception
  NVARID = NCVID(NPOS,'CanopInt',IERR)
  ZVALUE(:)=WRENUA(:)*ZPA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !     snow water equivalent
  NVARID = NCVID(NPOS,'SWE',IERR)
  ZVALUE(:)=ZSSN
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !     snow temperature
  NVARID = NCVID(NPOS,'SnowT',IERR)
  ZVALUE(:)=ZTSN
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !* -- Snow albedo
  NVARID = NCVID(NPOS,'SAlbedo',IERR)
  ZVALUE(:)=ASNNUA(:)*ZPA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
  
  !* -- Snow density
  NVARID = NCVID(NPOS,'snowdens',IERR)
  ZVALUE(:)=ZRSN
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
  
  !* -- Snow LIQUID WATER
  NVARID = NCVID(NPOS,'slw',IERR)
  ZVALUE(:)=ZWSN*ZPA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !* -- Lake ice temperature
  NVARID = NCVID(NPOS,'TLICE',IERR)
  ZVALUE(:)=TLICENUA(:)*ZPA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !* --lake mean water temperature
  NVARID = NCVID(NPOS,'TLMNW',IERR)
  ZVALUE(:)=TLMNWNUA(:)*ZPA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !* --lake mix layer water temperature
  NVARID = NCVID(NPOS,'TLWML',IERR)
  ZVALUE(:)=TLWMLNUA(:)*ZPA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !* --lake bottom water temperature
  NVARID = NCVID(NPOS,'TLBOT',IERR)
  ZVALUE(:)=TLBOTNUA(:)*ZPA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
 
  !* --lake mix layer shape factor
  NVARID = NCVID(NPOS,'TLSF',IERR)
  ZVALUE(:)=TLSFNUA(:)*ZPA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
 
  !* --lake ice thickness
  NVARID = NCVID(NPOS,'HLICE',IERR)
  ZVALUE(:)=HLICENUA(:)*ZPA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !* --lake mixed layer depth
  NVARID = NCVID(NPOS,'HLML',IERR)
  ZVALUE(:)=HLMLNUA(:)*ZPA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

ENDIF ! GGD

IF(LWRSUB)THEN

!* -- Sub-surface state variables
!******************************************************************
  NPOS = NPOSSUB

! !     soil temperature
!   NVARID = NCVID(NPOS,'SoilTemp',IERR)
!   DO JK=1,NCSS
!     ZVALUE(:)=TSLNUA(:,JK)*ZPA
!     ZOUTPUT3(:,JK)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!   ENDDO
!   IF(NACCUR == 1)THEN
!     ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
!   ENDIF
! !     soil moisture
!   NVARID = NCVID(NPOS,'SoilMoist',IERR)
!   DO JK=1,NCSS
!     ZVALUE(:)=ZQLINUA(:,JK)*ZPA
!     ZOUTPUT3(:,JK)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!   ENDDO
!   IF(NACCUR == 1)THEN
!     ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
!   ENDIF

! !     liquid soil moisture
!   NVARID = NCVID(NPOS,'LSoilMoist',IERR)
!   DO JK=1,NCSS
!     ZVALUE(:)=ZLIQ(:,JK)*ZPA
!     ZOUTPUT3(:,JK)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!   ENDDO
!   IF(NACCUR == 1)THEN
!     ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
!   ENDIF
! !     total soil wetness
!   NVARID = NCVID(NPOS,'SoilWet',IERR)
!   ZVALUE(:)=ZSWET(:)
!   ZOUTPUT= UNPACK(ZSWET,LMASK(IST:IEN),RMISS)
!   IF(NACCUR == 1)THEN
!     ZOUTPUTS(:)=ZOUTPUT(:)
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
!   ENDIF
ENDIF
      
IF(LWREVA)THEN
!* -- Evaporation components
!******************************************************************
  NPOS = NPOSEVA

!     interception evaporation
  NVARID = NCVID(NPOS,'ECanop',IERR)
  ZVALUE(:)=D1SWLJQ2(:,IA)*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     vegetation transpiration
  NVARID = NCVID(NPOS,'TVeg',IERR)
  !ZVALUE(:)=(D1SWAEXT2(:,1,IA)+D1SWAEXT2(:,2,IA)+&
  ! &D1SWAEXT2(:,3,IA)+D1SWAEXT2(:,4,IA))*ZMM
  ZVALUE(:)=0._JPRB
  DO JK=1,NCSS
	ZVALUE(:)=ZVALUE(:)+D1SWAEXT2(:,JK,IA)*ZMM
  ENDDO  
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     excess condensation
  NVARID = NCVID(NPOS,'Conds',IERR)
  ZVALUE(:)=D1SW1C2(:,IA)*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     bare soil evaporation
  NVARID = NCVID(NPOS,'ESoil',IERR)
  ZVALUE(:)=D1SW1JBG2(:,IA)*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
!     rootzone soil moisture
  NVARID = NCVID(NPOS,'RootMoist',IERR)
  ZVALUE(:)=ZSROOT(:)
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

! !     Canopy interception
!   NVARID = NCVID(NPOS,'CanopInt',IERR)
!   ZVALUE(:)=WRENUA(:)*ZPA
!   ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!   IF(NACCUR == 1)THEN
!     ZOUTPUTS(:)=ZOUTPUT(:)
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
!   ENDIF

!     Snow sublimation
  NVARID = NCVID(NPOS,'SubSnow',IERR)
  ZVALUE(:)=D1SWNJQ2(:,IA)*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !     PotEvapI
  NVARID = NCVID(NPOS,'PotEvapI',IERR)
  ZVALUE(:)=D1STIEVAPU2(:,4,IA)*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !     PotEvapWA
  NVARID = NCVID(NPOS,'PotEvapWA',IERR)
  ZVALUE(:)=D1STIEVAPU2(:,1,IA)*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !     PotEvapU
  NVARID = NCVID(NPOS,'PotEvapU',IERR)
  ZVALUE(:)=D1STIEVAPU2(:,2,IA)*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

  !     EWater
  NVARID = NCVID(NPOS,'EWater',IERR)
!EC   ZVALUE(:)=(D1STIEVAP2(:,1,IA)+D1STIEVAP2(:,9,IA))*ZMM
  ZVALUE(:)=(D1STIEVAP2(:,1,IA))*ZMM
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     Aerodynamic Conductance (1/ra) on veg.
!  NVARID = NCVID(NPOS,'ACond',IERR)
!  ZVALUE(:)=ZACOND(:)
!  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!  IF(NACCUR == 1)THEN
!    ZOUTPUTS(:)=ZOUTPUT(:)
!    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
!  ELSE
!    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
!  ENDIF
ENDIF
      
IF(LWRCLD)THEN
!* -- Cold-season processes
!******************************************************************
  NPOS = NPOSCLD

!     Snow fraction
  NVARID = NCVID(NPOS,'SnowFrac',IERR)
  ZVALUE(:)=ZSNOFR(:)
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     Ice fraction
  NVARID = NCVID(NPOS,'IceFrac',IERR)
  ZVALUE(:)=D1STIFR2(:,2,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

! ARDU ADDED
!     Soil frozen water fraction 
  NVARID = NCVID(NPOS,'SoilMoistFrz',IERR)
  DO JK=1,NCSS
    ZVALUE(:)=ZQFINUA(:,JK)*ZPA
    ZOUTPUT3(:,JK)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF

!* -- Sea ice thickness
! JUST A MODEL CONSTANT
!      NVARID = NCVID(NPOS,'IceT',IERR)

!* -- Frozen soil depth
  NVARID = NCVID(NPOS,'Fdepth',IERR)
  ZVALUE(:)=ZFDEPT(:)
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!* -- Depth to soil thaw
  NVARID = NCVID(NPOS,'Tdepth',IERR)
  ZVALUE(:)=ZFTHAW(:)
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

! !* -- Snow albedo
!   NVARID = NCVID(NPOS,'SAlbedo',IERR)
! !      ZVALUE(:)=ASNNUA(:)*ZPA
!   WHERE(ZSNOFR(1:NPOI) == 0.)
!     ZVALUE(1:NPOI)=RMISS
!   ELSEWHERE
!     ZVALUE(1:NPOI)=D1SNAFR2(1:NPOI,IA)*ZWA/ZSNOFR(1:NPOI)
!   END WHERE
!   ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!   IF(NACCUR == 1)THEN
!     ZOUTPUTS(:)=ZOUTPUT(:)
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
!   ENDIF

!* -- Snow depth
  NVARID = NCVID(NPOS,'SnowDepth',IERR)
  ZVALUE(:)=ZSNDEP(:)
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

! !* -- SNOW LIQUID WATER CONTENT
!   NVARID = NCVID(NPOS,'WSN',IERR)
!   ZVALUE(:)=D1WSN2(:,IA)*ZWA
!   ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!   IF(NACCUR == 1)THEN
!     ZOUTPUTS(:)=ZOUTPUT(:)
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
!   ENDIF
!     
!   !* -- heat changes due to rainfall freezing
!   NVARID = NCVID(NPOS,'HFLUXRF',IERR)
!   ZVALUE(:)=D1HFLUXRF2(:,IA)*ZWA
!   ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!   IF(NACCUR == 1)THEN
!     ZOUTPUTS(:)=ZOUTPUT(:)
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
!   ENDIF
!  
!   !* -- MASS advected by rainfall
!   NVARID = NCVID(NPOS,'MFLUXRF',IERR)
!   ZVALUE(:)=D1WFLUXRF2(:,IA)*ZMM
!   ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
!   IF(NACCUR == 1)THEN
!     ZOUTPUTS(:)=ZOUTPUT(:)
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
!   ELSE
!     CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
!   ENDIF
 
ENDIF

IF(LWRLKE)THEN
!* -- LAKE SURFACE FLUXES
!******************************************************************
  NPOS = NPOSLKE
  JTILE=9
!    LAKE net shortwave
  NVARID = NCVID(NPOS,'LSWnet',IERR)
!   ZVALUE(:)=(D1SRFLD2(:,IA)+D1SRFLU2(:,IA))*ZWA
  ZVALUE(:)=(D1STISRD2(:,JTILE,IA)+D1STISRU2(:,JTILE,IA))*ZWA
  DO JL=1,NPOI
    ZVALUE(JL)=ZVALUE(JL)/(D1STIFR2(JL,JTILE,IA)*ZWA)
  ENDDO
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!    LAKE net longwave
  NVARID = NCVID(NPOS,'LLWnet',IERR)
!   ZVALUE(:)=(D1TRFLD2(:,IA)+D1TRFLU2(:,IA))*ZWA
  ZVALUE(:)=(D1STITRD2(:,JTILE,IA)+D1STITRU2(:,JTILE,IA))*ZWA
  DO JL=1,NPOI
    ZVALUE(JL)=ZVALUE(JL)/(D1STIFR2(JL,JTILE,IA)*ZWA)
  ENDDO 
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!   LAKE  latent heat flux
  NVARID = NCVID(NPOS,'LQle',IERR)
!   ZVALUE(:)=D1AHFL2(:,IA)*ZWA
  ZVALUE(:)=D1STILE2(:,JTILE,IA)*ZWA
  DO JL=1,NPOI
    ZVALUE(JL)=ZVALUE(JL)/(D1STIFR2(JL,JTILE,IA)*ZWA)
  ENDDO
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!  LAKE   sensible heat flux
  NVARID = NCVID(NPOS,'LQh',IERR)
!   ZVALUE(:)=D1AHFS2(:,IA)*ZWA
  ZVALUE(:)=D1STIH2(:,JTILE,IA)*ZWA
  DO JL=1,NPOI
    ZVALUE(JL)=ZVALUE(JL)/(D1STIFR2(JL,JTILE,IA)*ZWA)
  ENDDO
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

! LAKE    upward longwave
  NVARID = NCVID(NPOS,'LLWup',IERR)
!   ZVALUE(:)=D1TRFLU2(:,IA)*ZWA
  ZVALUE(:)=D1STITRU2(:,JTILE,IA)*ZWA
  DO JL=1,NPOI
    ZVALUE(JL)=ZVALUE(JL)/(D1STIFR2(JL,JTILE,IA)*ZWA)
  ENDDO
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
  
  ! LAKE    evaporation
  NVARID = NCVID(NPOS,'LEvap',IERR)
!   ZVALUE(:)=D1STE2(:,IA)*ZMM
  ZVALUE(:)=D1STIEVAP2(:,JTILE,IA)*ZMM
  DO JL=1,NPOI
    ZVALUE(JL)=ZVALUE(JL)/(D1STIFR2(JL,JTILE,IA)*ZWA)
  ENDDO
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
  
  !    LAKE surface radiative temperature
  NVARID = NCVID(NPOS,'LSkinT',IERR)
!   ZVALUE(:)= D1SRADTK2(:,IA)*ZWA
  ZVALUE(:)=D1STITK2(:,JTILE,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
  
  !    LAKE fraction - fraction tile 9 
  NVARID = NCVID(NPOS,'Clake',IERR)
  ZVALUE(:)=D1STIFR2(:,JTILE,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
ENDIF

IF(LWROCD)THEN

!* -- Ocean mixed layer model
!******************************************************************
  NPOS = NPOSOCD

  IF(NDIMCDF == 2)THEN
    ISTART3(1)=IX1
    ISTART3(2)=IY1
    ISTART3(3)=ISLOT
    ICOUNT3(1)=IX2-IX1+1
    ICOUNT3(2)=IY2-IY1+1
    ICOUNT3(3)=1

    ISTART4(1)=IX1
    ISTART4(2)=IY1
    ISTART4(3)=1
    ISTART4(4)=ISLOT
    ICOUNT4(1)=IX2-IX1+1  !KPP
    ICOUNT4(2)=IY2-IY1+1  !KPP
    ICOUNT4(3)=NCOM+1     !KPP
    ICOUNT4(4)=1          !KPP
  ELSE
    ISTART3(1)=IST
    ISTART3(2)=ISLOT
    ICOUNT3(1)=NLEN
    ICOUNT3(2)=1

    ISTART4(1)=IST
    ISTART4(2)=1
    ISTART4(3)=ISLOT
    ICOUNT4O(1)=NLEN    !KPP
    ICOUNT4O(2)=NCOM+1  !KPP
    ICOUNT4O(3)=1       !KPP
  ENDIF

!     ocean depth
  NVARID = NCVID(NPOS,'OceanD',IERR)
  ZVALUE(:)=VFOCDEPTH(:)
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!     ocean vertical level
  NVARID = NCVID(NPOS,'OceanL',IERR)
  DO JK=1,NCOM+1
    ZVALUE(:)=VFZO(:,JK)
    ZOUTOCN3(:,JK)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTOCN3S(:,:)=ZOUTOCN3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4O,ZOUTOCN3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4O,ZOUTOCN3,IERR)
  ENDIF

ENDIF

!IF (LECTESSEL) THEN

IF(LWRCO2)THEN
!* -- CO2 fluxes
!******************************************************************
  NPOS = NPOSCO2
!* -- Ag
  NVARID = NCVID(NPOS,'Ag',IERR)
  ZVALUE(:)=D1SAG2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF  

!* -- Rd
  NVARID = NCVID(NPOS,'Rd',IERR)
  ZVALUE(:)=D1SRD2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!* -- An
  NVARID = NCVID(NPOS,'An',IERR)
  ZVALUE(:)=D1SAN2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!* -- Rsoil_str = RESPIRATION FROM SOIL AND STRUCTURAL BIOMASS.
  NVARID = NCVID(NPOS,'Rsoil_str',IERR)
  ZVALUE(:)=D1SRSOIL_STR2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF  

!* -- Reco = ECOSYSTEM RESPIRATION.
  NVARID = NCVID(NPOS,'Reco',IERR)
  ZVALUE(:)=D1SRECO2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF  

!* -- CO2 flux = NEE
  NVARID = NCVID(NPOS,'CO2flux',IERR)
  ZVALUE(:)=D1SCO2FLUX2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

ENDIF 

IF(LWRBIO)THEN
!* -- Biomass
!******************************************************************
  NPOS = NPOSBIO
!* -- LAI
  NVARID = NCVID(NPOS,'lai',IERR)
  ZVALUE(:)=D1SLAI2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF  
!* -- Active biomass
  NVARID = NCVID(NPOS,'biomass',IERR)
  ZVALUE(:)=D1SBIOM2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!* -- Active biomass loss
  NVARID = NCVID(NPOS,'Bloss',IERR)
  ZVALUE(:)=D1SBLOSS2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
  
!* -- Active biomass gain
  NVARID = NCVID(NPOS,'Bgain',IERR)
  ZVALUE(:)=D1SBGAIN2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!* -- Above ground structural biomass
  NVARID = NCVID(NPOS,'Biomstr',IERR)
  ZVALUE(:)=D1SBIOMSTR2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!* -- Below ground structural biomass
  NVARID = NCVID(NPOS,'Biomstr2',IERR)
  ZVALUE(:)=D1SBIOMSTRB2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF
  
ENDIF 

IF(LWRVEG)THEN
!* -- Vegetation variables
!******************************************************************
  NPOS = NPOSVEG

  DEALLOCATE (ZOUTPUT3)
  DEALLOCATE (ZOUTPUT3S)
  ALLOCATE (ZOUTPUT3(NLEN,NVHILO))	!INFLATED OUTPUT ARRAY
  ALLOCATE (ZOUTPUT3S(NLEN,NVHILO))	!INFLATED OUTPUT ARRAY
  IF(NDIMCDF == 2)THEN
    ISTART4(1)=IX1
    ISTART4(2)=IY1
    ISTART4(3)=1
    ISTART4(4)=ISLOT
    ICOUNT4(1)=IX2-IX1+1
    ICOUNT4(2)=IY2-IY1+1
    ICOUNT4(3)=NVHILO
    ICOUNT4(4)=1
  ELSE
    ISTART4(1)=IST
    ISTART4(2)=1
    ISTART4(3)=ISLOT
    ICOUNT4(1)=NLEN
    ICOUNT4(2)=NVHILO
    ICOUNT4(3)=1
  ENDIF

!* -- Canopy resistance
  NVARID = NCVID(NPOS,'rc',IERR)
  DO JVT=1,NVHILO  
    ZVALUE(:)=D1SVTGC2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF  

!* -- Aerodynamic resistance
  NVARID = NCVID(NPOS,'ra',IERR)
  DO JVT=1,NVHILO  
    ZVALUE(:)=D1SVTGA2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

 !* -- Latent heat per vegetation type
  NVARID = NCVID(NPOS,'LEvt',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTLE2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

 !* -- Stress function F2 per vegetation type
  NVARID = NCVID(NPOS,'f2vt',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTF22(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

 !* -- Ds, specific humidity deficit at canopy level per vegetation type
  NVARID = NCVID(NPOS,'dsvt',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTDS2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

 !* -- Dmax, max specific humidity deficit per vegetation type
  NVARID = NCVID(NPOS,'dmaxvt',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTDMAX2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

ENDIF 

IF(LWREXT)THEN
!* -- Extra variables 30 MIN VALIDATION ALTERRA
!******************************************************************
  NPOS = NPOSEXT

!* -- Snow fraction
  NVARID = NCVID(NPOS,'snfr',IERR)
  ZVALUE(:)=D1SNFR2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF

!* -- Interception fraction
  NVARID = NCVID(NPOS,'intfr',IERR)
  ZVALUE(:)=D1SWFR2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF  
  
!* -- Tair (forcing T+1, end of time step)
  NVARID = NCVID(NPOS,'Tair',IERR)
  ZVALUE(:)=D1STAIR2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF  

!* -- Qair (forcing T+1, end of time step)
  NVARID = NCVID(NPOS,'Qair',IERR)
  ZVALUE(:)=D1SQAIR2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF    
  
 !* -- Uwind (forcing T+1, end of time step)
  NVARID = NCVID(NPOS,'Uwind',IERR)
  ZVALUE(:)=D1SUWIND2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF 
  
 !* -- Vwind (forcing T+1, end of time step)
  NVARID = NCVID(NPOS,'Vwind',IERR)
  ZVALUE(:)=D1SVWIND2(:,IA)*ZWA
  ZOUTPUT= UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  IF(NACCUR == 1)THEN
    ZOUTPUTS(:)=ZOUTPUT(:)
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUTS,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART3,ICOUNT3,ZOUTPUT,IERR)
  ENDIF     

ENDIF 

IF(LWRTIL)THEN
!* -- Tiled output
!******************************************************************
  NPOS = NPOSTIL

  DEALLOCATE (ZOUTPUT3)
  DEALLOCATE (ZOUTPUT3S)
  ALLOCATE (ZOUTPUT3(NLEN,NTILES))	!INFLATED OUTPUT ARRAY
  ALLOCATE (ZOUTPUT3S(NLEN,NTILES))	!INFLATED OUTPUT ARRAY
  IF(NDIMCDF == 2)THEN
    ISTART4(1)=IX1
    ISTART4(2)=IY1
    ISTART4(3)=1
    ISTART4(4)=ISLOT
    ICOUNT4(1)=IX2-IX1+1
    ICOUNT4(2)=IY2-IY1+1
    ICOUNT4(3)=NTILES
    ICOUNT4(4)=1
  ELSE
    ISTART4(1)=IST
    ISTART4(2)=1
    ISTART4(3)=ISLOT
    ICOUNT4(1)=NLEN
    ICOUNT4(2)=NTILES
    ICOUNT4(3)=1
  ENDIF

 !* -- Tile fraction
  NVARID = NCVID(NPOS,'tifr',IERR)
  DO JTILE=1,NTILES
    ZVALUE(:)=D1STIFR2(:,JTILE,IA)*ZWA
    ZOUTPUT3(:,JTILE)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

  !* -- Tiled Swnet
  NVARID = NCVID(NPOS,'SWnet',IERR)
  DO JTILE=1,NTILES
    ZVALUE(:)=(D1STISRD2(:,JTILE,IA)+D1STISRU2(:,JTILE,IA))*ZWA
    ZOUTPUT3(:,JTILE)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

  !* -- Tiled Lwnet
  NVARID = NCVID(NPOS,'LWnet',IERR)
  DO JTILE=1,NTILES
    ZVALUE(:)=(D1STITRD2(:,JTILE,IA)+D1STITRU2(:,JTILE,IA))*ZWA
    ZOUTPUT3(:,JTILE)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 


 !* -- Tiled latent heat flux NOT normalized to grid square
  NVARID = NCVID(NPOS,'Qle',IERR)
  DO JTILE=1,NTILES
    ZVALUE(:)=(D1STILE2(:,JTILE,IA))*ZWA
    ZOUTPUT3(:,JTILE)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 


 !* -- Tiled sensible heat flux NOT normalized to grid square
  NVARID = NCVID(NPOS,'Qh',IERR)
  DO JTILE=1,NTILES
    ZVALUE(:)=(D1STIH2(:,JTILE,IA))*ZWA
    ZOUTPUT3(:,JTILE)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

  !* -- LWup
  NVARID = NCVID(NPOS,'LWup',IERR)
  DO JTILE=1,NTILES
    ZVALUE(:)=D1STITRU2(:,JTILE,IA)*ZWA
    ZOUTPUT3(:,JTILE)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

  !* --Evap
  NVARID = NCVID(NPOS,'Evap',IERR)
  DO JTILE=1,NTILES
    ZVALUE(:)=D1STIEVAP2(:,JTILE,IA)*ZMM
    ZOUTPUT3(:,JTILE)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

  !* -- Tiled Skin Temperature
  NVARID = NCVID(NPOS,'SkinT',IERR)
  DO JTILE=1,NTILES
    ZVALUE(:)=(D1STITK2(:,JTILE,IA))*ZWA
    ZOUTPUT3(:,JTILE)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 
  
  !* -- Tiled Skin thermal Conductivity
  NVARID = NCVID(NPOS,'SkinC',IERR)
  DO JTILE=1,NTILES
    ZVALUE(:)=(D1STISKC2(:,JTILE,IA))*ZWA
    ZOUTPUT3(:,JTILE)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

ENDIF

IF(LWRVTY)THEN
!* -- Output per vegetation type
!******************************************************************
  NPOS = NPOSVTY

  DEALLOCATE (ZOUTPUT3)
  DEALLOCATE (ZOUTPUT3S)
  ALLOCATE (ZOUTPUT3(NLEN,NVHILO))	!INFLATED OUTPUT ARRAY
  ALLOCATE (ZOUTPUT3S(NLEN,NVHILO))	!INFLATED OUTPUT ARRAY
  IF(NDIMCDF == 2)THEN
    ISTART4(1)=IX1
    ISTART4(2)=IY1
    ISTART4(3)=1
    ISTART4(4)=ISLOT
    ICOUNT4(1)=IX2-IX1+1
    ICOUNT4(2)=IY2-IY1+1
    ICOUNT4(3)=NVHILO
    ICOUNT4(4)=1
  ELSE
    ISTART4(1)=IST
    ISTART4(2)=1
    ISTART4(3)=ISLOT
    ICOUNT4(1)=NLEN
    ICOUNT4(2)=NVHILO
    ICOUNT4(3)=1
  ENDIF

!* -- Vegetation type fraction
  NVARID = NCVID(NPOS,'vtfr',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTFR2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF

!* -- LAI per vegetation type
  NVARID = NCVID(NPOS,'lai',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTLAI2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF

!* -- Active biomass per vegetation type
  NVARID = NCVID(NPOS,'biomass',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTBIOM2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF

!* -- Biomass loss per vegetation type
  NVARID = NCVID(NPOS,'Bloss',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTBLOSS2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS) 
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF
  
 !* -- Biomass gain per vegetation type
  NVARID = NCVID(NPOS,'Bgain',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTBGAIN2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF 

!* -- Below ground structural biomass per vegetation type
  NVARID = NCVID(NPOS,'Biomstr',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTBIOMSTR2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF
  
!* -- Below ground structural biomass per vegetation type
  NVARID = NCVID(NPOS,'Biomstr2',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTBIOMSTRB2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF  
 
 !* -- Ag per vegetation type
  NVARID = NCVID(NPOS,'Ag',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTAG2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF  
 
  !* -- Rd per vegetation type
  NVARID = NCVID(NPOS,'Rd',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTRD2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF  
  
  !* -- An per vegetation type
  NVARID = NCVID(NPOS,'An',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTAN2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF  
 
  !* -- Rsoil_str per vegetation type
  NVARID = NCVID(NPOS,'Rsoil_str',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTRSOIL_STR2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF  
  
  !* -- Reco per vegetation type
  NVARID = NCVID(NPOS,'Reco',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTRECO2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF   
  
  !* -- CO2 flux per vegetation type
  NVARID = NCVID(NPOS,'CO2flux',IERR)
  DO JVT=1,NVHILO
    ZVALUE(:)=D1SVTCO2FLUX2(:,JVT,IA)*ZWA
    ZOUTPUT3(:,JVT)=UNPACK(ZVALUE,LMASK(IST:IEN),RMISS)
  ENDDO
  IF(NACCUR == 1)THEN
    ZOUTPUT3S(:,:)=ZOUTPUT3(:,:)
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3S,IERR)
  ELSE
    CALL NCVPT (NPOS,NVARID,ISTART4,ICOUNT4,ZOUTPUT3,IERR)
  ENDIF
 
ENDIF


DO J=1,JPNCDF
  IF(LPOS(J) .AND. LNCSNC )THEN
    NPOS=IPOS(J)
    CALL NCSNC(NPOS,IERR)
  ENDIF
ENDDO


DEALLOCATE (ZOUTPUT)	!INFLATED OUTPUT ARRAY
DEALLOCATE (ZOUTPUTS)	!INFLATED OUTPUT ARRAY
DEALLOCATE (ZOUTPUT3)	!INFLATED OUTPUT ARRAY
DEALLOCATE (ZOUTPUT3S)	!INFLATED OUTPUT ARRAY
DEALLOCATE (ZOUTOCN3)	!INFLATED OUTPUT ARRAY
DEALLOCATE (ZOUTOCN3S)	!INFLATED OUTPUT ARRAY
DEALLOCATE (ZQLINUA)	!RESCALED SOIL WATER
DEALLOCATE (ZLIQ)		!LIQUID SOIL WATER
DEALLOCATE (ZSWET)		!TOTAL SOIL WETNESS
DEALLOCATE (ZSROOT)		!ROOT AVAILABLE SOIL WATER
DEALLOCATE (ZFDEPT)		!DEPTH OF FROZEN SOIL
DEALLOCATE (ZFTHAW)		!DEPTH OF THAW LAYER
DEALLOCATE (ZSNDEP)		!SNOW DEPTH
DEALLOCATE (ZSNOFR)     !SNOW FRACTION
DEALLOCATE (ZICEFR)     !ICE FRACTION
DEALLOCATE (ZACOND)
DEALLOCATE (ZVALUE)
DEALLOCATE (ZSSN)
DEALLOCATE (ZRSN)
DEALLOCATE (ZTSN)
DEALLOCATE (ZWSN)
DEALLOCATE (ZTMP1)
DEALLOCATE (ZQFINUA)

RETURN
END SUBROUTINE WRTDCDF
