Index: /LMDZ5/trunk/libf/dyn3dpar/guide_p_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/dyn3dpar/guide_p_mod.F90	(revision 1511)
+++ /LMDZ5/trunk/libf/dyn3dpar/guide_p_mod.F90	(revision 1512)
@@ -19,10 +19,10 @@
 ! ---------------------------------------------
   INTEGER, PRIVATE, SAVE  :: iguide_read,iguide_int,iguide_sav
-  INTEGER, PRIVATE, SAVE  :: nlevnc
+  INTEGER, PRIVATE, SAVE  :: nlevnc, guide_plevs
   LOGICAL, PRIVATE, SAVE  :: guide_u,guide_v,guide_T,guide_Q,guide_P
   LOGICAL, PRIVATE, SAVE  :: guide_hr,guide_teta  
   LOGICAL, PRIVATE, SAVE  :: guide_BL,guide_reg,guide_add,gamma4,guide_zon 
-  LOGICAL, PRIVATE, SAVE  :: guide_modele,invert_p,invert_y,ini_anal
-  LOGICAL, PRIVATE, SAVE  :: guide_2D,guide_sav
+  LOGICAL, PRIVATE, SAVE  :: invert_p,invert_y,ini_anal
+  LOGICAL, PRIVATE, SAVE  :: guide_2D,guide_sav,guide_modele
   
   REAL, PRIVATE, SAVE     :: tau_min_u,tau_max_u
@@ -48,4 +48,5 @@
   REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE   :: tnat1,tnat2
   REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE   :: qnat1,qnat2
+  REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE   :: pnat1,pnat2
   REAL, ALLOCATABLE, DIMENSION(:,:),   PRIVATE, SAVE   :: psnat1,psnat2
   REAL, ALLOCATABLE, DIMENSION(:),     PRIVATE, SAVE   :: apnc,bpnc
@@ -65,5 +66,5 @@
 
   SUBROUTINE guide_init
-
+    
     USE control_mod
     IMPLICIT NONE
@@ -127,11 +128,19 @@
 ! Parametres pour lecture des fichiers
     CALL getpar('iguide_read',4,iguide_read,'freq. lecture guidage')
-    CALL getpar('iguide_int',4,iguide_int,'freq. lecture guidage')
-    IF (iguide_int.GT.0) THEN
+    CALL getpar('iguide_int',4,iguide_int,'freq. interpolation vert')
+    IF (iguide_int.EQ.0) THEN
+        iguide_int=1
+    ELSEIF (iguide_int.GT.0) THEN
         iguide_int=day_step/iguide_int
     ELSE
         iguide_int=day_step*iguide_int
     ENDIF
-    CALL getpar('guide_modele',.false.,guide_modele,'guidage niveaux modele')
+    CALL getpar('guide_plevs',0,guide_plevs,'niveaux pression fichiers guidage')
+    ! Pour compatibilite avec ancienne version avec guide_modele
+    CALL getpar('guide_modele',.false.,guide_modele,'niveaux pression ap+bp*psol')
+    IF (guide_modele) THEN
+        guide_plevs=1
+    ENDIF
+    ! Fin raccord
     CALL getpar('ini_anal',.false.,ini_anal,'Etat initial = analyse')
     CALL getpar('guide_invertp',.true.,invert_p,'niveaux p inverses')
@@ -144,16 +153,16 @@
 ! ---------------------------------------------
     ncidpl=-99
-    if (guide_modele) then
+    if (guide_plevs.EQ.1) then
        if (ncidpl.eq.-99) rcod=nf90_open('apbp.nc',Nf90_NOWRITe, ncidpl)
-    else
-         if (guide_u) then
-           if (ncidpl.eq.-99) rcod=nf90_open('u.nc',Nf90_NOWRITe,ncidpl)
-         elseif (guide_v) then
-           if (ncidpl.eq.-99) rcod=nf90_open('v.nc',nf90_nowrite,ncidpl)
-         elseif (guide_T) then
-           if (ncidpl.eq.-99) rcod=nf90_open('T.nc',nf90_nowrite,ncidpl)
-         elseif (guide_Q) then
-           if (ncidpl.eq.-99) rcod=nf90_open('hur.nc',nf90_nowrite, ncidpl)
-         endif
+    elseif (guide_plevs.EQ.2) then
+       if (ncidpl.EQ.-99) rcod=nf90_open('P.nc',Nf90_NOWRITe,ncidpl)
+    elseif (guide_u) then
+       if (ncidpl.eq.-99) rcod=nf90_open('u.nc',Nf90_NOWRITe,ncidpl)
+    elseif (guide_v) then
+       if (ncidpl.eq.-99) rcod=nf90_open('v.nc',nf90_nowrite,ncidpl)
+    elseif (guide_T) then
+       if (ncidpl.eq.-99) rcod=nf90_open('T.nc',nf90_nowrite,ncidpl)
+    elseif (guide_Q) then
+       if (ncidpl.eq.-99) rcod=nf90_open('hur.nc',nf90_nowrite, ncidpl)
     endif 
     error=NF_INQ_DIMID(ncidpl,'LEVEL',rid)
@@ -240,5 +249,13 @@
     ENDIF
 
-    IF (guide_P.OR.guide_modele) THEN
+    IF (guide_plevs.EQ.2) THEN
+        ALLOCATE(pnat1(iip1,jjp1,nlevnc), stat = error)
+        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
+        ALLOCATE(pnat2(iip1,jjp1,nlevnc), stat = error)
+        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
+        pnat1=0.;pnat2=0.;
+    ENDIF
+
+    IF (guide_P.OR.guide_plevs.EQ.1) THEN
         ALLOCATE(psnat1(iip1,jjp1), stat = error)
         IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
@@ -267,5 +284,6 @@
     IF (guide_T) tnat1=tnat2
     IF (guide_Q) qnat1=qnat2
-    IF (guide_P.OR.guide_modele) psnat1=psnat2
+    IF (guide_plevs.EQ.2) pnat1=pnat2
+    IF (guide_P.OR.guide_plevs.EQ.1) psnat1=psnat2
 
   END SUBROUTINE guide_init
@@ -293,5 +311,10 @@
     LOGICAL       :: f_out ! sortie guidage
     REAL, DIMENSION (ip1jmp1,llm) :: f_add ! var aux: champ de guidage
-    REAL, DIMENSION (ip1jmp1,llm) :: p ! besoin si guide_P
+    ! Variables pour fonction Exner (P milieu couche)
+    REAL, DIMENSION (iip1,jjp1,llm)    :: pk, pkf
+    REAL, DIMENSION (iip1,jjp1,llm)    :: alpha, beta
+    REAL, DIMENSION (iip1,jjp1)        :: pks    
+    REAL                               :: unskap
+    REAL, DIMENSION (ip1jmp1,llmp1)    :: p ! besoin si guide_P
     ! Compteurs temps:
     INTEGER, SAVE :: step_rea,count_no_rea,itau_test ! lecture guidage
@@ -300,5 +323,5 @@
     REAL, SAVE    :: factt ! pas de temps en fraction de jour
     
-    INTEGER       :: l
+    INTEGER       :: i,j,l
     
     ijb_u=ij_begin ; ije_u=ij_end ; ijn_u=ije_u-ijb_u+1  
@@ -313,6 +336,4 @@
     ENDIF
       
-    
-    
      PRINT *,'---> on rentre dans guide_main'
 !    CALL AllGather_Field(ucov,ip1jmp1,llm)
@@ -380,7 +401,7 @@
       dday_step=real(day_step)
       IF (iguide_read.LT.0) THEN
-          tau=ditau/dday_step/ REAL(iguide_read)
+          tau=ditau/dday_step/REAL(iguide_read)
       ELSE
-          tau= REAL(iguide_read)*ditau/dday_step
+          tau=REAL(iguide_read)*ditau/dday_step
       ENDIF
       reste=tau-AINT(tau)
@@ -394,5 +415,6 @@
               IF (guide_T) tnat1(:,jjb_u:jje_u,:)=tnat2(:,jjb_u:jje_u,:)
               IF (guide_Q) qnat1(:,jjb_u:jje_u,:)=qnat2(:,jjb_u:jje_u,:)
-              IF (guide_P.OR.guide_modele) psnat1(:,jjb_u:jje_u)=psnat2(:,jjb_u:jje_u)
+              IF (guide_plevs.EQ.2) pnat1(:,jjb_u:jje_u,:)=pnat2(:,jjb_u:jje_u,:)
+              IF (guide_P.OR.guide_plevs.EQ.1) psnat1(:,jjb_u:jje_u)=psnat2(:,jjb_u:jje_u)
               step_rea=step_rea+1
               itau_test=itau
@@ -430,5 +452,18 @@
 ! Sauvegarde du guidage?
     f_out=((MOD(itau,iguide_sav).EQ.0).AND.guide_sav)  
-    IF (f_out) CALL guide_out("S",jjp1,1,ps)
+    IF (f_out) THEN
+!       Calcul niveaux pression milieu de couches 
+	CALL pression_p( ip1jmp1, ap, bp, ps, p )
+	CALL exner_hyb_p(ip1jmp1,ps,p,alpha,beta,pks,pk,pkf)
+	unskap=1./kappa
+	DO l = 1, llm
+	    DO j=jjb_u,jje_u
+		DO i =1, iip1
+		    p(i+(j-1)*iip1,l) = preff * ( pk(i,j,l)/cpp) ** unskap
+		ENDDO
+	    ENDDO
+	ENDDO
+        CALL guide_out("P",jjp1,llm,p(1:ip1jmp1,1:llm),1.)
+    ENDIF
     
     if (guide_u) then
@@ -441,5 +476,5 @@
         if (guide_zon) CALL guide_zonave(1,jjp1,llm,f_add)
         CALL guide_addfield(ip1jmp1,llm,f_add,alpha_u)
-        IF (f_out) CALL guide_out("U",jjp1,llm,f_add/factt)
+        IF (f_out) CALL guide_out("U",jjp1,llm,f_add(:,:),factt)
         ucov(ijb_u:ije_u,:)=ucov(ijb_u:ije_u,:)+f_add(ijb_u:ije_u,:)
     endif
@@ -453,5 +488,5 @@
         if (guide_zon) CALL guide_zonave(2,jjp1,llm,f_add)
         CALL guide_addfield(ip1jmp1,llm,f_add,alpha_T)
-        IF (f_out) CALL guide_out("T",jjp1,llm,f_add/factt)
+        IF (f_out) CALL guide_out("T",jjp1,llm,f_add(:,:),factt)
         teta(ijb_u:ije_u,:)=teta(ijb_u:ije_u,:)+f_add(ijb_u:ije_u,:)
     endif
@@ -465,5 +500,5 @@
         if (guide_zon) CALL guide_zonave(2,jjp1,1,f_add(1:ip1jmp1,1))
         CALL guide_addfield(ip1jmp1,1,f_add(1:ip1jmp1,1),alpha_P)
-        IF (f_out) CALL guide_out("P",jjp1,1,f_add(1:ip1jmp1,1)/factt)
+        IF (f_out) CALL guide_out("SP",jjp1,1,f_add(1:ip1jmp1,1),factt)
         ps(ijb_u:ije_u)=ps(ijb_u:ije_u)+f_add(ijb_u:ije_u,1)
         CALL pression_p(ip1jmp1,ap,bp,ps,p)
@@ -479,5 +514,5 @@
         if (guide_zon) CALL guide_zonave(2,jjp1,llm,f_add)
         CALL guide_addfield(ip1jmp1,llm,f_add,alpha_Q)
-        IF (f_out) CALL guide_out("Q",jjp1,llm,f_add/factt)
+        IF (f_out) CALL guide_out("Q",jjp1,llm,f_add(:,:),factt)
         q(ijb_u:ije_u,:)=q(ijb_u:ije_u,:)+f_add(ijb_u:ije_u,:)
     endif
@@ -492,5 +527,5 @@
         if (guide_zon) CALL guide_zonave(2,jjm,llm,f_add(1:ip1jm,:))
         CALL guide_addfield(ip1jm,llm,f_add(1:ip1jm,:),alpha_v)
-        IF (f_out) CALL guide_out("V",jjm,llm,f_add(1:ip1jm,:)/factt)
+        IF (f_out) CALL guide_out("V",jjm,llm,f_add(1:ip1jm,:),factt)
         vcov(ijb_v:ije_v,:)=vcov(ijb_v:ije_v,:)+f_add(ijb_v:ije_v,:)
     endif
@@ -580,5 +615,5 @@
               ENDDO
           ENDDO 
-          fieldm(:,l)=fieldm(:,l)/ REAL(imax(typ)-imin(typ)+1)
+          fieldm(:,l)=fieldm(:,l)/REAL(imax(typ)-imin(typ)+1)
     ! Compute forcing
           DO j=jjb_v,jje_v
@@ -598,5 +633,5 @@
               ENDDO
           ENDDO 
-          fieldm(:,l)=fieldm(:,l)/ REAL(imax(typ)-imin(typ)+1)
+          fieldm(:,l)=fieldm(:,l)/REAL(imax(typ)-imin(typ)+1)
     ! Compute forcing
           DO j=jjb_u,jje_u
@@ -640,5 +675,5 @@
   REAL, DIMENSION (iip1,jjp1,llm)    :: alpha, beta
   REAL, DIMENSION (iip1,jjp1)        :: pks    
-  REAL                               :: prefkap,unskap
+  REAL                               :: unskap
   ! Pression de vapeur saturante
   REAL, DIMENSION (ip1jmp1,llm)      :: qsat
@@ -652,26 +687,17 @@
     print *,'Guide: conversion variables guidage'
 ! -----------------------------------------------------------------
-! Calcul des niveaux de pression champs guidage
+! Calcul des niveaux de pression champs guidage (pour T et Q)
 ! -----------------------------------------------------------------
-if (guide_modele) then
-    do i=1,iip1
-        do j=jjb_u,jje_u
-            do l=1,nlevnc
-                plnc2(i,j,l)=apnc(l)+bpnc(l)*psnat2(i,j)
-                plnc1(i,j,l)=apnc(l)+bpnc(l)*psnat1(i,j)
-            enddo
-        enddo
-    enddo
-else
-    do i=1,iip1
-        do j=jjb_u,jje_u
-            do l=1,nlevnc
-                plnc2(i,j,l)=apnc(l)
-                plnc1(i,j,l)=apnc(l)
-           enddo
-        enddo
-    enddo
-
-endif
+    IF (guide_plevs.EQ.0) THEN
+        DO l=1,nlevnc
+            DO j=jjb_u,jje_u
+                DO i=1,iip1
+                    plnc2(i,j,l)=apnc(l)
+                    plnc1(i,j,l)=apnc(l)
+               ENDDO
+            ENDDO
+        ENDDO
+    ENDIF   
+
     if (first) then
         first=.FALSE.
@@ -683,7 +709,18 @@
         enddo
         print*,'Fichiers guidage'
-        do l=1,nlevnc
-             print*,'PL(',l,')=',plnc2(1,jjb_u,l)
-        enddo
+        SELECT CASE (guide_plevs)
+        CASE (0) 
+            do l=1,nlevnc
+                 print*,'PL(',l,')=',plnc2(1,jjb_u,l)
+            enddo
+        CASE (1)
+            DO l=1,nlevnc
+                 print*,'PL(',l,')=',apnc(l)+bpnc(l)*psnat2(i,jjb_u)
+             ENDDO
+        CASE (2)
+            do l=1,nlevnc
+                 print*,'PL(',l,')=',pnat2(1,jjb_u,l)
+            enddo
+        END SELECT
         print *,'inversion de l''ordre: invert_p=',invert_p
         if (guide_u) then
@@ -702,17 +739,26 @@
 ! Calcul niveaux pression modele 
 ! -----------------------------------------------------------------
-    CALL pression_p( ip1jmp1, ap, bp, psi, p )
-    CALL exner_hyb_p(ip1jmp1,psi,p,alpha,beta,pks,pk,pkf)
 
 !    ....  Calcul de pls , pression au milieu des couches ,en Pascals
-    unskap=1./kappa
-    prefkap =  preff  ** kappa
-    DO l = 1, llm
-        DO j=jjb_u,jje_u
-            DO i =1, iip1
-                pls(i,j,l) = preff * ( pk(i,j,l)/cpp) ** unskap
-            ENDDO
+    IF (guide_plevs.EQ.1) THEN
+        DO l=1,llm
+	    DO j=jjb_u,jje_u
+		DO i =1, iip1
+                    pls(i,j,l)=(ap(l)+ap(l+1))/2.+psi(i,j)*(bp(l)+bp(l+1))/2.
+		ENDDO
+	    ENDDO
         ENDDO
-    ENDDO
+    ELSE
+	CALL pression_p( ip1jmp1, ap, bp, psi, p )
+	CALL exner_hyb_p(ip1jmp1,psi,p,alpha,beta,pks,pk,pkf)
+	unskap=1./kappa
+	DO l = 1, llm
+	    DO j=jjb_u,jje_u
+		DO i =1, iip1
+		    pls(i,j,l) = preff * ( pk(i,j,l)/cpp) ** unskap
+		ENDDO
+	    ENDDO
+	ENDDO
+    ENDIF
 
 !   calcul des pressions pour les grilles u et v
@@ -747,5 +793,5 @@
 
 ! -----------------------------------------------------------------
-! Interpolation champs guidage sur niveaux modele (+inversion N/S)
+! Interpolation verticale champs guidage sur niveaux modele
 ! Conversion en variables gcm (ucov, vcov...)
 ! -----------------------------------------------------------------
@@ -762,5 +808,147 @@
     endif
 
+    IF (guide_T) THEN
+        ! Calcul des nouvelles valeurs des niveaux de pression du guidage
+        IF (guide_plevs.EQ.1) THEN
+            DO l=1,nlevnc
+                DO j=jjb_u,jje_u
+                    DO i=1,iip1
+                        plnc2(i,j,l)=apnc(l)+bpnc(l)*psnat2(i,j)
+                        plnc1(i,j,l)=apnc(l)+bpnc(l)*psnat1(i,j)
+                    ENDDO
+                ENDDO
+            ENDDO
+        ELSE IF (guide_plevs.EQ.2) THEN
+            DO l=1,nlevnc
+                DO j=jjb_u,jje_u
+                    DO i=1,iip1
+                        plnc2(i,j,l)=pnat2(i,j,l)
+                        plnc1(i,j,l)=pnat1(i,j,l)
+                    ENDDO
+                ENDDO
+            ENDDO
+        ENDIF
+
+        ! Interpolation verticale
+        CALL pres2lev(tnat1(:,jjb_u:jje_u,:),zu1(:,jjb_u:jje_u,:),nlevnc,llm,           &
+                    plnc1(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
+        CALL pres2lev(tnat2(:,jjb_u:jje_u,:),zu2(:,jjb_u:jje_u,:),nlevnc,llm,           &
+                    plnc2(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
+
+        ! Conversion en variables GCM
+        do l=1,llm
+            do j=jjb_u,jje_u
+                IF (guide_teta) THEN
+                    do i=1,iim
+                        ij=(j-1)*iip1+i
+                        tgui1(ij,l)=zu1(i,j,l)
+                        tgui2(ij,l)=zu2(i,j,l)
+                    enddo
+                ELSE
+                    do i=1,iim
+                        ij=(j-1)*iip1+i
+                        tgui1(ij,l)=zu1(i,j,l)*cpp/pk(i,j,l)
+                        tgui2(ij,l)=zu2(i,j,l)*cpp/pk(i,j,l)
+                    enddo
+                ENDIF
+                tgui1(j*iip1,l)=tgui1((j-1)*iip1+1,l)    
+                tgui2(j*iip1,l)=tgui2((j-1)*iip1+1,l)    
+            enddo
+            do i=1,iip1
+                tgui1(i,l)=tgui1(1,l)
+                tgui1(ip1jm+i,l)=tgui1(ip1jm+1,l) 
+                tgui2(i,l)=tgui2(1,l)
+                tgui2(ip1jm+i,l)=tgui2(ip1jm+1,l) 
+            enddo
+        enddo
+    ENDIF
+
+    IF (guide_Q) THEN
+        ! Calcul des nouvelles valeurs des niveaux de pression du guidage
+        IF (guide_plevs.EQ.1) THEN
+            DO l=1,nlevnc
+                DO j=jjb_u,jje_u
+                    DO i=1,iip1
+                        plnc2(i,j,l)=apnc(l)+bpnc(l)*psnat2(i,j)
+                        plnc1(i,j,l)=apnc(l)+bpnc(l)*psnat1(i,j)
+                    ENDDO
+                ENDDO
+            ENDDO
+        ELSE IF (guide_plevs.EQ.2) THEN
+            DO l=1,nlevnc
+                DO j=jjb_u,jje_u
+                    DO i=1,iip1
+                        plnc2(i,j,l)=pnat2(i,j,l)
+                        plnc1(i,j,l)=pnat1(i,j,l)
+                    ENDDO
+                ENDDO
+            ENDDO
+        ENDIF
+
+        ! Interpolation verticale
+        CALL pres2lev(qnat1(:,jjb_u:jje_u,:),zu1(:,jjb_u:jje_u,:),nlevnc,llm,             &
+                      plnc1(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
+        CALL pres2lev(qnat2(:,jjb_u:jje_u,:),zu2(:,jjb_u:jje_u,:),nlevnc,llm,             &
+                      plnc2(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
+
+        ! Conversion en variables GCM
+        ! On suppose qu'on a la bonne variable dans le fichier de guidage:
+        ! Hum.Rel si guide_hr, Hum.Spec. sinon.
+        do l=1,llm
+            do j=jjb_u,jje_u
+                do i=1,iim
+                    ij=(j-1)*iip1+i
+                    qgui1(ij,l)=zu1(i,j,l)
+                    qgui2(ij,l)=zu2(i,j,l)
+                enddo
+                qgui1(j*iip1,l)=qgui1((j-1)*iip1+1,l)    
+                qgui2(j*iip1,l)=qgui2((j-1)*iip1+1,l)    
+            enddo
+            do i=1,iip1
+                qgui1(i,l)=qgui1(1,l)
+                qgui1(ip1jm+i,l)=qgui1(ip1jm+1,l) 
+                qgui2(i,l)=qgui2(1,l)
+                qgui2(ip1jm+i,l)=qgui2(ip1jm+1,l) 
+            enddo
+        enddo
+        IF (guide_hr) THEN
+            CALL q_sat(iip1*jjn_u*llm,teta(:,jjb_u:jje_u,:)*pk(:,jjb_u:jje_u,:)/cpp,       &
+                       plsnc(:,jjb_u:jje_u,:),qsat(ijb_u:ije_u,:))
+            qgui1(ijb_u:ije_u,:)=qgui1(ijb_u:ije_u,:)*qsat(ijb_u:ije_u,:)*0.01 !hum. rel. en %
+            qgui2(ijb_u:ije_u,:)=qgui2(ijb_u:ije_u,:)*qsat(ijb_u:ije_u,:)*0.01 
+        ENDIF
+    ENDIF
+
     IF (guide_u) THEN
+        ! Calcul des nouvelles valeurs des niveaux de pression du guidage
+        IF (guide_plevs.EQ.1) THEN
+            DO l=1,nlevnc
+                DO j=jjb_u,jje_u
+                    DO i=1,iim
+                        plnc2(i,j,l)=apnc(l)+bpnc(l)*(psnat2(i,j)*aire(i,j)*alpha1p2(i,j) &
+                       &           +psnat2(i+1,j)*aire(i+1,j)*alpha3p4(i+1,j))/aireu(i,j)
+                        plnc1(i,j,l)=apnc(l)+bpnc(l)*(psnat1(i,j)*aire(i,j)*alpha1p2(i,j) &
+                       &           +psnat1(i+1,j)*aire(i+1,j)*alpha3p4(i+1,j))/aireu(i,j)
+                    ENDDO
+                    plnc2(iip1,j,l)=plnc2(1,j,l)
+                    plnc1(iip1,j,l)=plnc1(1,j,l)
+                ENDDO
+            ENDDO
+        ELSE IF (guide_plevs.EQ.2) THEN
+            DO l=1,nlevnc
+                DO j=jjb_u,jje_u
+                    DO i=1,iim
+                        plnc2(i,j,l)=(pnat2(i,j,l)*aire(i,j)*alpha1p2(i,j) &
+                       & +pnat2(i+1,j,l)*aire(i,j)*alpha3p4(i+1,j))/aireu(i,j)
+                        plnc1(i,j,l)=(pnat1(i,j,l)*aire(i,j)*alpha1p2(i,j) &
+                       & +pnat1(i+1,j,l)*aire(i,j)*alpha3p4(i+1,j))/aireu(i,j)
+                    ENDDO
+                    plnc2(iip1,j,l)=plnc2(1,j,l)
+                    plnc1(iip1,j,l)=plnc1(1,j,l)
+                ENDDO
+            ENDDO
+        ENDIF
+        
+        ! Interpolation verticale
         CALL pres2lev(unat1(:,jjb_u:jje_u,:),zu1(:,jjb_u:jje_u,:),nlevnc,llm,            &
                       plnc1(:,jjb_u:jje_u,:),plunc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
@@ -768,4 +956,5 @@
                       plnc2(:,jjb_u:jje_u,:),plunc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
 
+        ! Conversion en variables GCM
         do l=1,llm
             do j=jjb_u,jje_u
@@ -787,44 +976,47 @@
     ENDIF
     
-    IF (guide_T) THEN
-        CALL pres2lev(tnat1(:,jjb_u:jje_u,:),zu1(:,jjb_u:jje_u,:),nlevnc,llm,           &
-                      plnc1(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
-        CALL pres2lev(tnat2(:,jjb_u:jje_u,:),zu2(:,jjb_u:jje_u,:),nlevnc,llm,           &
-                      plnc2(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
-
-        do l=1,llm
-            do j=jjb_u,jje_u
-                IF (guide_teta) THEN
-		    do i=1,iim
-			ij=(j-1)*iip1+i
-			tgui1(ij,l)=zu1(i,j,l)
-			tgui2(ij,l)=zu2(i,j,l)
-		    enddo
-                ELSE
-		    do i=1,iim
-			ij=(j-1)*iip1+i
-			tgui1(ij,l)=zu1(i,j,l)*cpp/pk(i,j,l)
-			tgui2(ij,l)=zu2(i,j,l)*cpp/pk(i,j,l)
-		    enddo
-                ENDIF
-                tgui1(j*iip1,l)=tgui1((j-1)*iip1+1,l)    
-                tgui2(j*iip1,l)=tgui2((j-1)*iip1+1,l)    
-            enddo
-            do i=1,iip1
-                tgui1(i,l)=tgui1(1,l)
-                tgui1(ip1jm+i,l)=tgui1(ip1jm+1,l) 
-                tgui2(i,l)=tgui2(1,l)
-                tgui2(ip1jm+i,l)=tgui2(ip1jm+1,l) 
-            enddo
-        enddo
-    ENDIF
-
     IF (guide_v) THEN
-        
+        ! Calcul des nouvelles valeurs des niveaux de pression du guidage
+        IF (guide_plevs.EQ.1) THEN
+	 CALL Register_SwapFieldHallo(psnat1,psnat1,ip1jmp1,1,jj_Nb_caldyn,1,2,Req)
+	 CALL SendRequest(Req)
+	 CALL WaitRequest(Req)
+	 CALL Register_SwapFieldHallo(psnat2,psnat2,ip1jmp1,1,jj_Nb_caldyn,1,2,Req)
+	 CALL SendRequest(Req)
+	 CALL WaitRequest(Req)
+            DO l=1,nlevnc
+                DO j=jjb_v,jje_v
+                    DO i=1,iip1
+                        plnc2(i,j,l)=apnc(l)+bpnc(l)*(psnat2(i,j)*aire(i,j)*alpha2p3(i,j) &
+                       &           +psnat2(i,j+1)*aire(i,j+1)*alpha1p4(i,j+1))/airev(i,j)
+                        plnc1(i,j,l)=apnc(l)+bpnc(l)*(psnat1(i,j)*aire(i,j)*alpha2p3(i,j) &
+                       &           +psnat1(i,j+1)*aire(i,j+1)*alpha1p4(i,j+1))/airev(i,j)
+                    ENDDO
+                ENDDO
+            ENDDO
+        ELSE IF (guide_plevs.EQ.2) THEN
+	 CALL Register_SwapFieldHallo(pnat1,pnat1,ip1jmp1,llm,jj_Nb_caldyn,1,2,Req)
+	 CALL SendRequest(Req)
+	 CALL WaitRequest(Req)
+	 CALL Register_SwapFieldHallo(pnat2,pnat2,ip1jmp1,llm,jj_Nb_caldyn,1,2,Req)
+	 CALL SendRequest(Req)
+	 CALL WaitRequest(Req)
+            DO l=1,nlevnc
+                DO j=jjb_v,jje_v
+                    DO i=1,iip1
+                        plnc2(i,j,l)=(pnat2(i,j,l)*aire(i,j)*alpha2p3(i,j) &
+                       & +pnat2(i,j+1,l)*aire(i,j)*alpha1p4(i,j+1))/airev(i,j)
+                        plnc1(i,j,l)=(pnat1(i,j,l)*aire(i,j)*alpha2p3(i,j) &
+                       & +pnat1(i,j+1,l)*aire(i,j)*alpha1p4(i,j+1))/airev(i,j)
+                    ENDDO
+                ENDDO
+            ENDDO
+        ENDIF
+        ! Interpolation verticale
         CALL pres2lev(vnat1(:,jjb_v:jje_v,:),zv1(:,jjb_v:jje_v,:),nlevnc,llm,             &
                       plnc1(:,jjb_v:jje_v,:),plvnc(:,jjb_v:jje_v,:),iip1,jjn_v,invert_p)
         CALL pres2lev(vnat2(:,jjb_v:jje_v,:),zv2(:,jjb_v:jje_v,:),nlevnc,llm,             &
                       plnc2(:,jjb_v:jje_v,:),plvnc(:,jjb_v:jje_v,:),iip1,jjn_v,invert_p)
-
+        ! Conversion en variables GCM
         do l=1,llm
             do j=jjb_v,jje_v
@@ -840,36 +1032,4 @@
     ENDIF
     
-    IF (guide_Q) THEN
-        ! On suppose qu'on a la bonne variable dans le fichier de guidage:
-        ! Hum.Rel si guide_hr, Hum.Spec. sinon.
-        CALL pres2lev(qnat1(:,jjb_u:jje_u,:),zu1(:,jjb_u:jje_u,:),nlevnc,llm,             &
-                      plnc1(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
-        CALL pres2lev(qnat2(:,jjb_u:jje_u,:),zu2(:,jjb_u:jje_u,:),nlevnc,llm,             &
-                      plnc2(:,jjb_u:jje_u,:),plsnc(:,jjb_u:jje_u,:),iip1,jjn_u,invert_p)
-
-        do l=1,llm
-            do j=jjb_u,jjb_v
-                do i=1,iim
-                    ij=(j-1)*iip1+i
-                    qgui1(ij,l)=zu1(i,j,l)
-                    qgui2(ij,l)=zu2(i,j,l)
-                enddo
-                qgui1(j*iip1,l)=qgui1((j-1)*iip1+1,l)    
-                qgui2(j*iip1,l)=qgui2((j-1)*iip1+1,l)    
-            enddo
-            do i=1,iip1
-                qgui1(i,l)=qgui1(1,l)
-                qgui1(ip1jm+i,l)=qgui1(ip1jm+1,l) 
-                qgui2(i,l)=qgui2(1,l)
-                qgui2(ip1jm+i,l)=qgui2(ip1jm+1,l) 
-            enddo
-        enddo
-        IF (guide_hr) THEN
-            CALL q_sat(iip1*jjn_u*llm,teta(:,jjb_u:jje_u,:)*pk(:,jjb_u:jje_u,:)/cpp,       &
-                       plsnc(:,jjb_u:jje_u,:),qsat(ijb_u:ije_u,:))
-            qgui1(ijb_u:ije_u,:)=qgui1(ijb_u:ije_u,:)*qsat(ijb_u:ije_u,:)*0.01 !hum. rel. en %
-            qgui2(ijb_u:ije_u,:)=qgui2(ijb_u:ije_u,:)*qsat(ijb_u:ije_u,:)*0.01 
-        ENDIF
-    ENDIF
 
   END SUBROUTINE guide_interp
@@ -1055,6 +1215,6 @@
     LOGICAL, SAVE         :: first=.TRUE.
 ! Identification fichiers et variables NetCDF:
-    INTEGER, SAVE         :: ncidu,varidu,ncidv,varidv,ncidQ
-    INTEGER, SAVE         :: varidQ,ncidt,varidt,ncidps,varidps
+    INTEGER, SAVE         :: ncidu,varidu,ncidv,varidv,ncidp,varidp
+    INTEGER, SAVE         :: ncidQ,varidQ,ncidt,varidt,ncidps,varidps
     INTEGER               :: ncidpl,varidpl,varidap,varidbp
 ! Variables auxiliaires NetCDF:
@@ -1068,11 +1228,18 @@
          ncidpl=-99
          print*,'Guide: ouverture des fichiers guidage '
-! Niveaux de pression si non constants
-         if (guide_modele) then
-             print *,'Lecture du guidage sur niveaux mod�le'
+! Ap et Bp si Niveaux de pression hybrides
+         if (guide_plevs.EQ.1) then
+             print *,'Lecture du guidage sur niveaux modele'
              rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
              rcode = nf90_inq_varid(ncidpl, 'AP', varidap)
              rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
              print*,'ncidpl,varidap',ncidpl,varidap
+         endif
+! Pression si guidage sur niveaux P variables
+         if (guide_plevs.EQ.2) then
+             rcode = nf90_open('P.nc', nf90_nowrite, ncidp)
+             rcode = nf90_inq_varid(ncidp, 'PRES', varidp)
+             print*,'ncidp,varidp',ncidp,varidp
+             if (ncidpl.eq.-99) ncidpl=ncidp
          endif
 ! Vent zonal
@@ -1105,5 +1272,5 @@
          endif
 ! Pression de surface
-         if ((guide_P).OR.(guide_modele)) then
+         if ((guide_P).OR.(guide_plevs.EQ.1)) then
              rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
              rcode = nf90_inq_varid(ncidps, 'SP', varidps)
@@ -1111,5 +1278,5 @@
          endif
 ! Coordonnee verticale
-         if (.not.guide_modele) then
+         if (guide_plevs.EQ.0) then
               rcode = nf90_inq_varid(ncidpl, 'LEVEL', varidpl)
               IF (rcode.NE.0) rcode = nf90_inq_varid(ncidpl, 'PRESSURE', varidpl)
@@ -1117,5 +1284,5 @@
          endif
 ! Coefs ap, bp pour calcul de la pression aux differents niveaux
-         if (guide_modele) then
+         IF (guide_plevs.EQ.1) THEN
 #ifdef NC_DOUBLE
              status=NF_GET_VARA_DOUBLE(ncidpl,varidap,1,nlevnc,apnc)
@@ -1125,5 +1292,5 @@
              status=NF_GET_VARA_REAL(ncidpl,varidbp,1,nlevnc,bpnc)
 #endif
-         else
+         ELSEIF (guide_plevs.EQ.0) THEN
 #ifdef NC_DOUBLE
              status=NF_GET_VARA_DOUBLE(ncidpl,varidpl,1,nlevnc,apnc)
@@ -1133,7 +1300,7 @@
              apnc=apnc*100.! conversion en Pascals
              bpnc(:)=0.
-         endif
+         ENDIF
          first=.FALSE.
-     endif ! (first)
+     ENDIF ! (first)
 
 ! -----------------------------------------------------------------
@@ -1152,4 +1319,16 @@
      count(4)=1
 
+! Pression 
+     if (guide_plevs.EQ.2) then
+#ifdef NC_DOUBLE
+         status=NF_GET_VARA_DOUBLE(ncidp,varidp,start,count,pnat2)
+#else
+         status=NF_GET_VARA_REAL(ncidp,varidp,start,count,pnat2)
+#endif
+         IF (invert_y) THEN
+           CALL invert_lat(iip1,jjp1,nlevnc,pnat2)
+         ENDIF
+     endif
+
 !  Vent zonal
      if (guide_u) then
@@ -1204,5 +1383,5 @@
 
 !  Pression de surface
-     if ((guide_P).OR.(guide_modele))  then
+     if ((guide_P).OR.(guide_plevs.EQ.1))  then
          start(3)=timestep
          start(4)=0
@@ -1235,6 +1414,6 @@
     LOGICAL, SAVE         :: first=.TRUE.
 ! Identification fichiers et variables NetCDF:
-    INTEGER, SAVE         :: ncidu,varidu,ncidv,varidv,ncidQ
-    INTEGER, SAVE         :: varidQ,ncidt,varidt,ncidps,varidps
+    INTEGER, SAVE         :: ncidu,varidu,ncidv,varidv,ncidp,varidp
+    INTEGER, SAVE         :: ncidQ,varidQ,ncidt,varidt,ncidps,varidps
     INTEGER               :: ncidpl,varidpl,varidap,varidbp
 ! Variables auxiliaires NetCDF:
@@ -1252,6 +1431,6 @@
          ncidpl=-99
          print*,'Guide: ouverture des fichiers guidage '
-! Niveaux de pression si non constants
-         if (guide_modele) then
+! Ap et Bp si niveaux de pression hybrides
+         if (guide_plevs.EQ.1) then
              print *,'Lecture du guidage sur niveaux mod�le'
              rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
@@ -1259,4 +1438,11 @@
              rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
              print*,'ncidpl,varidap',ncidpl,varidap
+         endif
+! Pression
+         if (guide_plevs.EQ.2) then
+             rcode = nf90_open('P.nc', nf90_nowrite, ncidp)
+             rcode = nf90_inq_varid(ncidp, 'PRES', varidp)
+             print*,'ncidp,varidp',ncidp,varidp
+             if (ncidpl.eq.-99) ncidpl=ncidp
          endif
 ! Vent zonal
@@ -1289,5 +1475,5 @@
          endif
 ! Pression de surface
-         if ((guide_P).OR.(guide_modele)) then
+         if ((guide_P).OR.(guide_plevs.EQ.1)) then
              rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
              rcode = nf90_inq_varid(ncidps, 'SP', varidps)
@@ -1295,5 +1481,5 @@
          endif
 ! Coordonnee verticale
-         if (.not.guide_modele) then
+         if (guide_plevs.EQ.0) then
               rcode = nf90_inq_varid(ncidpl, 'LEVEL', varidpl)
               IF (rcode.NE.0) rcode = nf90_inq_varid(ncidpl, 'PRESSURE', varidpl)
@@ -1301,5 +1487,5 @@
          endif
 ! Coefs ap, bp pour calcul de la pression aux differents niveaux
-         if (guide_modele) then
+         if (guide_plevs.EQ.1) then
 #ifdef NC_DOUBLE
              status=NF_GET_VARA_DOUBLE(ncidpl,varidap,1,nlevnc,apnc)
@@ -1309,5 +1495,5 @@
              status=NF_GET_VARA_REAL(ncidpl,varidbp,1,nlevnc,bpnc)
 #endif
-         else
+         elseif (guide_plevs.EQ.0) THEN
 #ifdef NC_DOUBLE
              status=NF_GET_VARA_DOUBLE(ncidpl,varidpl,1,nlevnc,apnc)
@@ -1336,4 +1522,19 @@
      count(4)=1
 
+!  Pression
+     if (guide_plevs.EQ.2) then
+#ifdef NC_DOUBLE
+         status=NF_GET_VARA_DOUBLE(ncidp,varidp,start,count,zu)
+#else
+         status=NF_GET_VARA_REAL(ncidp,varidp,start,count,zu)
+#endif
+         DO i=1,iip1
+             pnat2(i,:,:)=zu(:,:)
+         ENDDO
+
+         IF (invert_y) THEN
+           CALL invert_lat(iip1,jjp1,nlevnc,pnat2)
+         ENDIF
+     endif
 !  Vent zonal
      if (guide_u) then
@@ -1350,5 +1551,4 @@
            CALL invert_lat(iip1,jjp1,nlevnc,unat2)
          ENDIF
-
      endif
 
@@ -1367,5 +1567,4 @@
            CALL invert_lat(iip1,jjp1,nlevnc,tnat2)
          ENDIF
-
      endif
 
@@ -1384,5 +1583,4 @@
            CALL invert_lat(iip1,jjp1,nlevnc,qnat2)
          ENDIF
-
      endif
 
@@ -1402,9 +1600,8 @@
            CALL invert_lat(iip1,jjm,nlevnc,vnat2)
          ENDIF
-
      endif
 
 !  Pression de surface
-     if ((guide_P).OR.(guide_modele))  then
+     if ((guide_P).OR.(guide_plevs.EQ.1))  then
          start(3)=timestep
          start(4)=0
@@ -1424,5 +1621,4 @@
            CALL invert_lat(iip1,jjp1,1,psnat2)
          ENDIF
-
      endif
 
@@ -1430,5 +1626,5 @@
   
 !=======================================================================
-  SUBROUTINE guide_out(varname,hsize,vsize,field)
+  SUBROUTINE guide_out(varname,hsize,vsize,field,factt)
     USE parallel
     IMPLICIT NONE
@@ -1445,4 +1641,5 @@
     INTEGER,   INTENT (IN)                         :: hsize,vsize
     REAL, DIMENSION (iip1,hsize,vsize), INTENT(IN) :: field
+    REAL, INTENT (IN)                              :: factt
 
     ! Variables locales
@@ -1507,7 +1704,7 @@
 ! --------------------------------------------------------------------
         ierr = NF_REDEF(nid)
-! Surface pressure (GCM)
-        dim3=(/id_lonv,id_latu,id_tim/)
-        ierr = NF_DEF_VAR(nid,"SP",NF_FLOAT,3,dim3,varid)
+! Pressure (GCM)
+        dim4=(/id_lonv,id_latu,id_lev,id_tim/)
+        ierr = NF_DEF_VAR(nid,"P",NF_FLOAT,4,dim4,varid)
 ! Surface pressure (guidage)
         IF (guide_P) THEN
@@ -1543,12 +1740,13 @@
 ! Enregistrement du champ
 ! --------------------------------------------------------------------
+ 
     ierr=NF_OPEN("guide_ins.nc",NF_WRITE,nid)
 
     SELECT CASE (varname)
-    CASE ("S")
+    CASE ("P")
         timestep=timestep+1
-        ierr = NF_INQ_VARID(nid,"SP",varid)
-        start=(/1,1,timestep,0/)
-        count=(/iip1,jjp1,1,0/)
+        ierr = NF_INQ_VARID(nid,"P",varid)
+        start=(/1,1,1,timestep/)
+        count=(/iip1,jjp1,llm,1/)
 #ifdef NC_DOUBLE
         ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
@@ -1556,12 +1754,12 @@
         ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
 #endif
-    CASE ("P")
+    CASE ("SP")
         ierr = NF_INQ_VARID(nid,"ps",varid)
         start=(/1,1,timestep,0/)
         count=(/iip1,jjp1,1,0/)
 #ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
+        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field/factt)
+#else
+        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field/factt)
 #endif
     CASE ("U")
@@ -1570,7 +1768,7 @@
         count=(/iip1,jjp1,llm,1/)
 #ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
+        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field/factt)
+#else
+        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field/factt)
 #endif
     CASE ("V")
@@ -1579,7 +1777,7 @@
         count=(/iip1,jjm,llm,1/)
 #ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
+        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field/factt)
+#else
+        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field/factt)
 #endif
     CASE ("T")
@@ -1588,7 +1786,7 @@
         count=(/iip1,jjp1,llm,1/)
 #ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
+        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field/factt)
+#else
+        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field/factt)
 #endif
     CASE ("Q")
@@ -1597,7 +1795,7 @@
         count=(/iip1,jjp1,llm,1/)
 #ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
+        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field/factt)
+#else
+        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field/factt)
 #endif
     END SELECT
