c
c $Header$
c
c
cIM on initialise les champs en debut du jour ou du mois 
c
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,tsumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,usumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,vsumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,wsumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,phisumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,qsumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,rhsumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,uvsumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,vqsumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,vTsumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,wqsumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,vphisumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,wTsumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,u2sumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,v2sumSTD)
        CALL ini_undefSTD(nlevSTD,itap,
     $           dtime,ecrit_day,ecrit_mth,
     $                    tnondef,T2sumSTD)
c
cIM on interpole sur les niveaux STD de pression a chaque pas de temps de la physique
c
       DO k=1, nlevSTD
c
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .              t_seri,tlevSTD(:,k))
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             u_seri,ulevSTD(:,k))
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             v_seri,vlevSTD(:,k))
c
        DO l=1, klev
        DO i=1, klon
         zx_tmp_fi3d(i,l)=paprs(i,l)
        ENDDO !i
        ENDDO !l
        CALL plevel(klon,klev,.true.,zx_tmp_fi3d,rlevSTD(k),
     .             omega,wlevSTD(:,k))
c
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             zphi/RG,philevSTD(:,k))
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             qx(:,:,ivap),qlevSTD(:,k))
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             zx_rh*100.,rhlevSTD(:,k))
c
        DO l=1, klev
         DO i=1, klon
          zx_tmp_fi3d(i,l)=u_seri(i,l)*v_seri(i,l)
         ENDDO !i
        ENDDO !l
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             zx_tmp_fi3d,uvSTD(:,k))
c
        DO l=1, klev
         DO i=1, klon
          zx_tmp_fi3d(i,l)=v_seri(i,l)*q_seri(i,l)
         ENDDO !i
        ENDDO !l
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             zx_tmp_fi3d,vqSTD(:,k))
c
        DO l=1, klev
         DO i=1, klon
          zx_tmp_fi3d(i,l)=v_seri(i,l)*t_seri(i,l)
         ENDDO !i
        ENDDO !l
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             zx_tmp_fi3d,vTSTD(:,k))
c
        DO l=1, klev
         DO i=1, klon
          zx_tmp_fi3d(i,l)=omega(i,l)*qx(i,l,ivap)
         ENDDO !i 
        ENDDO !l
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             zx_tmp_fi3d,wqSTD(:,k))
c
        DO l=1, klev
         DO i=1, klon
          zx_tmp_fi3d(i,l)=v_seri(i,l)*zphi(i,l)/RG
         ENDDO !i
        ENDDO !l
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             zx_tmp_fi3d,vphiSTD(:,k))
c
        DO l=1, klev
         DO i=1, klon
          zx_tmp_fi3d(i,l)=omega(i,l)*t_seri(i,l)
         ENDDO !i
        ENDDO !l
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             zx_tmp_fi3d,wTSTD(:,k))
c
        DO l=1, klev
         DO i=1, klon
          zx_tmp_fi3d(i,l)=u_seri(i,l)*u_seri(i,l)
         ENDDO !i
        ENDDO !l
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             zx_tmp_fi3d,u2STD(:,k))
c
        DO l=1, klev
         DO i=1, klon
          zx_tmp_fi3d(i,l)=v_seri(i,l)*v_seri(i,l)
         ENDDO !i
        ENDDO !l
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             zx_tmp_fi3d,v2STD(:,k))
c
        DO l=1, klev
         DO i=1, klon
          zx_tmp_fi3d(i,l)=t_seri(i,l)*t_seri(i,l)
         ENDDO !i
        ENDDO !l
        CALL plevel(klon,klev,.true.,pplay,rlevSTD(k),
     .             zx_tmp_fi3d,T2STD(:,k))
c
       ENDDO !k=1,nlevSTD
c
cIM on somme les valeurs definies a chaque pas de temps de la physique ou 
cIM toutes les "hautes frequences"
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.TRUE.
       CALL undefSTD(nlevSTD,itap,tlevSTD,
     $               dtime,ecrit_hf,
     $               oknondef,tnondef,tsumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,ulevSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,usumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,vlevSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,vsumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,wlevSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,wsumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,philevSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,phisumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,qlevSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,qsumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,rhlevSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,rhsumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,uvSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,uvsumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,vqSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,vqsumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,vTSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,vTsumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,wqSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,wqsumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,vphiSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,vphisumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,wTSTD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,wTsumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,u2STD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,u2sumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,v2STD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,v2sumSTD)
c
       oknondef(1:klon,1:nlevSTD,1:nout)=.FALSE.
       CALL undefSTD(nlevSTD,itap,T2STD,
     $           dtime,ecrit_hf,
     $               oknondef,tnondef,T2sumSTD)
c
cIM on moyenne a la fin du jour ou du mois 
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,tsumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,usumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,vsumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,wsumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,phisumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,qsumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,rhsumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,uvsumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,vqsumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,vTsumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,wqsumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,vphisumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,wTsumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,u2sumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,v2sumSTD)
c
       CALL moy_undefSTD(nlevSTD,itap,
     $      dtime,ecrit_day,ecrit_mth,ecrit_hf2mth,
     $                   tnondef,T2sumSTD)
c
cIM interpolation a chaque pas de temps du SWup(clr) et SWdn(clr) a 200 hPa
c
      CALL plevel(klon,klevp1,.true.,paprs,20000.,
     $     swdn0,SWdn200clr)
      CALL plevel(klon,klevp1,.false.,paprs,20000.,
     $     swdn,SWdn200)
      CALL plevel(klon,klevp1,.false.,paprs,20000.,
     $     swup0,SWup200clr)
      CALL plevel(klon,klevp1,.false.,paprs,20000.,
     $     swup,SWup200)
c
      CALL plevel(klon,klevp1,.false.,paprs,20000.,
     $     lwdn0,LWdn200clr)
      CALL plevel(klon,klevp1,.false.,paprs,20000.,
     $     lwdn,LWdn200)
      CALL plevel(klon,klevp1,.false.,paprs,20000.,
     $     lwup0,LWup200clr)
      CALL plevel(klon,klevp1,.false.,paprs,20000.,
     $     lwup,LWup200)
c
