Index: /LMDZ5/trunk/libf/dyn3dmem/guide_loc_mod.F90
===================================================================
--- /LMDZ5/trunk/libf/dyn3dmem/guide_loc_mod.F90	(revision 2027)
+++ /LMDZ5/trunk/libf/dyn3dmem/guide_loc_mod.F90	(revision 2028)
@@ -535,8 +535,8 @@
     IF (f_out) THEN
 !       Calcul niveaux pression milieu de couches 
-	CALL pression_loc( ijnb_u, ap, bp, ps, p )
-	if (pressure_exner) then
+        CALL pression_loc( ijnb_u, ap, bp, ps, p )
+        if (pressure_exner) then
           CALL exner_hyb_loc(ip1jmp1,ps,p,pks,pk)
-	else
+        else
           CALL exner_milieu_loc(ip1jmp1,ps,p,pks,pk)
         endif
@@ -544,15 +544,12 @@
         unskap=1./kappa
 !$OMP DO
-	DO l = 1, llm
-	    DO j=jjbu,jjeu
-		DO i =1, iip1
-		    p(i+(j-1)*iip1,l) = preff * ( pk(i,j,l)/cpp) ** unskap
-		ENDDO
-	    ENDDO
-	ENDDO
-!$OMP MASTER
-        CALL guide_out("P",jjp1,llm,p,1.)
-!$OMP END MASTER
-!$OMP BARRIER
+        DO l = 1, llm
+            DO j=jjbu,jjeu
+                DO i =1, iip1
+                    p(i+(j-1)*iip1,l) = preff * ( pk(i,j,l)/cpp) ** unskap
+                ENDDO
+            ENDDO
+        ENDDO
+        CALL guide_out("SP",jjp1,llm,p,1.)
     ENDIF
     
@@ -574,11 +571,8 @@
         if (guide_zon) CALL guide_zonave_u(1,llm,f_addu)
         CALL guide_addfield_u(llm,f_addu,alpha_u)
-!        CALL WriteField_u('f_addu',f_addu)
-!        CALL WriteField_u('alpha_u',alpha_u)
-!$OMP MASTER
-        IF (f_out) CALL guide_out("U",jjp1,llm,f_addu(:,:),factt)
-!$OMP END MASTER
-!$OMP BARRIER
-
+!       IF (f_out) CALL guide_out("ua",jjp1,llm,ugui1(ijb_u:ije_u,:),factt)
+        IF (f_out) CALL guide_out("ua",jjp1,llm,(1.-tau)*ugui1(ijb_u:ije_u,:)+tau*ugui2(ijb_u:ije_u,:),factt)
+        IF (f_out) CALL guide_out("u",jjp1,llm,ucov(ijb_u:ije_u,:),factt)
+        IF (f_out) CALL guide_out("ucov",jjp1,llm,f_addu(ijb_u:ije_u,:),factt)
 !$OMP DO
         DO l=1,llm
@@ -602,8 +596,5 @@
         if (guide_zon) CALL guide_zonave_u(2,llm,f_addu)
         CALL guide_addfield_u(llm,f_addu,alpha_T)
-!$OMP MASTER
-        IF (f_out) CALL guide_out("T",jjp1,llm,f_addu(:,:),factt)
-!$OMP END MASTER
-!$OMP BARRIER
+        IF (f_out) CALL guide_out("teta",jjp1,llm,f_addu(:,:)/factt,factt)
 !$OMP DO
         DO l=1,llm
@@ -626,8 +617,5 @@
         if (guide_zon) CALL guide_zonave_u(2,1,f_addu(ijb_u:ije_u,1))
         CALL guide_addfield_u(1,f_addu(ijb_u:ije_u,1),alpha_P)
-!$OMP MASTER
-        IF (f_out) CALL guide_out("SP",jjp1,1,f_addu(1:ip1jmp1,1),factt)
-!$OMP END MASTER
-!$OMP BARRIER
+        IF (f_out) CALL guide_out("ps",jjp1,1,f_addu(1:ip1jmp1,1)/factt,factt)
 !$OMP MASTER
         ps(ijbu:ijeu)=ps(ijbu:ijeu)+f_addu(ijbu:ijeu,1)
@@ -653,8 +641,5 @@
         if (guide_zon) CALL guide_zonave_u(2,llm,f_addu)
         CALL guide_addfield_u(llm,f_addu,alpha_Q)
-!$OMP MASTER
-        IF (f_out) CALL guide_out("Q",jjp1,llm,f_addu(:,:),factt)
-!$OMP END MASTER
-!$OMP BARRIER
+        IF (f_out) CALL guide_out("q",jjp1,llm,f_addu(:,:)/factt,factt)
 
 !$OMP DO
@@ -678,17 +663,11 @@
 
         endif 
-!        CALL WriteField_v('f_addv',f_addv)        
     
         if (guide_zon) CALL guide_zonave_v(2,jjm,llm,f_addv(ijb_v:ije_v,:))
-!        CALL WriteField_v('f_addv',f_addv)        
         
         CALL guide_addfield_v(llm,f_addv(ijb_v:ije_v,:),alpha_v)
-!        CALL WriteField_v('f_addv',f_addv)        
-!        CALL WriteField_v('alpha_v',alpha_v)        
-!$OMP MASTER
-        IF (f_out) CALL guide_out("V",jjm,llm,f_addv(1:ip1jm,:),factt)
-!$OMP END MASTER
-!$OMP BARRIER
-!        CALL WriteField_v('f_addv',f_addv)        
+        IF (f_out) CALL guide_out("v",jjm,llm,vcov(ijb_v:ije_v,:),factt)
+        IF (f_out) CALL guide_out("va",jjm,llm,(1.-tau)*vgui1(ijb_v:ije_v,:)+tau*vgui2(ijb_v:ije_v,:),factt)
+        IF (f_out) CALL guide_out("vcov",jjm,llm,f_addv(:,:)/factt,factt)
 
 !$OMP DO
@@ -697,9 +676,4 @@
         ENDDO
     endif
-
-!    CALL WriteField_u('ucov_guide',ucov)
-!    CALL WriteField_v('vcov_guide',vcov)
-!    CALL WriteField_u('teta_guide',teta)
-!    CALL WriteField_u('masse_guide',masse)
 
   END SUBROUTINE guide_main
@@ -1022,24 +996,24 @@
 		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
         ENDDO
     ELSE
-	CALL pression_loc( ijnb_u, ap, bp, psi, p )
-	if (disvert_type==1) then
+        CALL pression_loc( ijnb_u, ap, bp, psi, p )
+        if (disvert_type==1) then
           CALL exner_hyb_loc(ijnb_u,psi,p,pks,pk)
         else ! we assume that we are in the disvert_type==2 case
           CALL exner_milieu_loc(ijnb_u,psi,p,pks,pk)
         endif
-	unskap=1./kappa
-!$OMP BARRIER
-!$OMP DO
-	DO l = 1, llm
-	    DO j=jjbu,jjeu
-		DO i =1, iip1
-		    pls(i,j,l) = preff * ( pk(i,j,l)/cpp) ** unskap
-		ENDDO
-	    ENDDO
-	ENDDO
+        unskap=1./kappa
+!$OMP BARRIER
+!$OMP DO
+   DO l = 1, llm
+       DO j=jjbu,jjeu
+   	DO i =1, iip1
+   	    pls(i,j,l) = preff * ( pk(i,j,l)/cpp) ** unskap
+   	ENDDO
+       ENDDO
+   ENDDO
     ENDIF
 
@@ -1751,4 +1725,5 @@
      endif
 
+
 !  Temperature
      if (guide_T) then
@@ -1904,4 +1879,5 @@
              if (ncidpl.eq.-99) ncidpl=ncidu
          endif
+
 ! Vent meridien
          if (guide_v) then
@@ -2041,4 +2017,5 @@
      endif
 
+
 !  Temperature
      if (guide_T) then
@@ -2126,6 +2103,7 @@
   
 !=======================================================================
-  SUBROUTINE guide_out(varname,hsize,vsize,field,factt)
+  SUBROUTINE guide_out(varname,hsize,vsize,field_loc,factt)
     USE parallel_lmdz
+    USE mod_hallo, ONLY : gather_field_u, gather_field_v
     IMPLICIT NONE
 
@@ -2138,7 +2116,7 @@
     
     ! Variables entree
-    CHARACTER, INTENT(IN)                          :: varname
+    CHARACTER*(*), INTENT(IN)                      :: varname
     INTEGER,   INTENT (IN)                         :: hsize,vsize
-    REAL, DIMENSION (iip1,hsize,vsize), INTENT(IN) :: field
+    REAL, DIMENSION (iip1,hsize,vsize), INTENT(IN) :: field_loc
     REAL, INTENT (IN)                              :: factt
 
@@ -2148,13 +2126,26 @@
     INTEGER       :: nid, id_lonu, id_lonv, id_latu, id_latv, id_tim, id_lev
     INTEGER       :: vid_lonu,vid_lonv,vid_latu,vid_latv,vid_cu,vid_cv,vid_lev
+    INTEGER       :: vid_au,vid_av
     INTEGER, DIMENSION (3) :: dim3
     INTEGER, DIMENSION (4) :: dim4,count,start
-    INTEGER                :: ierr, varid
-    
-    CALL gather_field(field,iip1*hsize,vsize,0)
-    
+    INTEGER                :: ierr, varid,l
+    REAL zu(ip1jmp1),zv(ip1jm)
+    REAL, ALLOCATABLE, DIMENSION(:,:,:) :: field_glo
+    
+!$OMP MASTER
+
+    ALLOCATE(field_glo(iip1,hsize,vsize))
+    IF (hsize==jjp1) THEN
+       CALL gather_field_u(field_loc,field_glo,vsize)
+    ELSE IF (hsize==jjm) THEN
+       CALL gather_field_v(field_loc,field_glo, vsize)
+    ENDIF
+
+    CALL Gather_field_u(alpha_u,zu,1)
+    CALL Gather_field_v(alpha_v,zv,1)
+
     IF (mpi_rank /= 0) RETURN
     
-    print *,'Guide: output timestep',timestep,'var ',varname
+!   print *,'Guide: output timestep',timestep,'var ',varname
     IF (timestep.EQ.0) THEN 
 ! ----------------------------------------------
@@ -2179,5 +2170,7 @@
         ierr=NF_DEF_VAR(nid,"cu",NF_FLOAT,2,(/id_lonu,id_latu/),vid_cu)
         ierr=NF_DEF_VAR(nid,"cv",NF_FLOAT,2,(/id_lonv,id_latv/),vid_cv)
-        
+        ierr=NF_DEF_VAR(nid,"au",NF_FLOAT,2,(/id_lonu,id_latu/),vid_au)
+        ierr=NF_DEF_VAR(nid,"av",NF_FLOAT,2,(/id_lonv,id_latv/),vid_av)
+
         ierr=NF_ENDDEF(nid)
 
@@ -2191,4 +2184,6 @@
         ierr = NF_PUT_VAR_DOUBLE(nid,vid_cu,cu)
         ierr = NF_PUT_VAR_DOUBLE(nid,vid_cv,cv)
+        ierr = NF_PUT_VAR_DOUBLE(nid,vid_au,zu)
+        ierr = NF_PUT_VAR_DOUBLE(nid,vid_av,zv)
 #else
         ierr = NF_PUT_VAR_REAL(nid,vid_lonu,rlonu*180./pi)
@@ -2199,4 +2194,6 @@
         ierr = NF_PUT_VAR_REAL(nid,vid_cu,cu)
         ierr = NF_PUT_VAR_REAL(nid,vid_cv,cv)
+        ierr = NF_PUT_VAR_REAL(nid,vid_au,alpha_u)
+        ierr = NF_PUT_VAR_REAL(nid,vid_av,alpha_v)
 #endif
 ! --------------------------------------------------------------------
@@ -2206,5 +2203,5 @@
 ! Pressure (GCM)
         dim4=(/id_lonv,id_latu,id_lev,id_tim/)
-        ierr = NF_DEF_VAR(nid,"P",NF_FLOAT,4,dim4,varid)
+        ierr = NF_DEF_VAR(nid,"SP",NF_FLOAT,4,dim4,varid)
 ! Surface pressure (guidage)
         IF (guide_P) THEN
@@ -2215,4 +2212,6 @@
         IF (guide_u) THEN
             dim4=(/id_lonu,id_latu,id_lev,id_tim/)
+            ierr = NF_DEF_VAR(nid,"u",NF_FLOAT,4,dim4,varid)
+            ierr = NF_DEF_VAR(nid,"ua",NF_FLOAT,4,dim4,varid)
             ierr = NF_DEF_VAR(nid,"ucov",NF_FLOAT,4,dim4,varid)
         ENDIF
@@ -2220,4 +2219,6 @@
         IF (guide_v) THEN
             dim4=(/id_lonv,id_latv,id_lev,id_tim/)
+            ierr = NF_DEF_VAR(nid,"v",NF_FLOAT,4,dim4,varid)
+            ierr = NF_DEF_VAR(nid,"va",NF_FLOAT,4,dim4,varid)
             ierr = NF_DEF_VAR(nid,"vcov",NF_FLOAT,4,dim4,varid)
         ENDIF
@@ -2243,63 +2244,45 @@
     ierr=NF_OPEN("guide_ins.nc",NF_WRITE,nid)
 
+    IF (varname=="SP") timestep=timestep+1
+
+    ierr = NF_INQ_VARID(nid,varname,varid)
     SELECT CASE (varname)
-    CASE ("P")
-        timestep=timestep+1
-        ierr = NF_INQ_VARID(nid,"P",varid)
+    CASE ("SP","ps")
         start=(/1,1,1,timestep/)
         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)
-#endif
-    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/factt)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field/factt)
-#endif
-    CASE ("U")
-        ierr = NF_INQ_VARID(nid,"ucov",varid)
+    CASE ("v","va","vcov")
+        start=(/1,1,1,timestep/)
+        count=(/iip1,jjm,llm,1/)
+    CASE DEFAULT
         start=(/1,1,1,timestep/)
         count=(/iip1,jjp1,llm,1/)
+    END SELECT
+
+    SELECT CASE (varname)
+
+    CASE("u","ua")
+        DO l=1,llm ; field_glo(:,2:jjm,l)=field_glo(:,2:jjm,l)/cu(:,2:jjm) ; ENDDO
+        field_glo(:,1,:)=0. ; field_glo(:,jjp1,:)=0.
+    CASE("v","va")
+        DO l=1,llm ; field_glo(:,:,l)=field_glo(:,:,l)/cv(:,:) ; ENDDO
+    END SELECT
+
+!    if (varname=="ua") then
+!    call dump2d(iip1,jjp1,field_glo,'ua gui1 1ere couche ')
+!    call dump2d(iip1,jjp1,field_glo(:,:,llm),'ua gui1 llm ')
+!    endif
 #ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field/factt)
+    ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field_glo)
 #else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field/factt)
+    ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field_glo)
 #endif
-    CASE ("V")
-        ierr = NF_INQ_VARID(nid,"vcov",varid)
-        start=(/1,1,1,timestep/)
-        count=(/iip1,jjm,llm,1/)
-#ifdef NC_DOUBLE
-        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")
-        ierr = NF_INQ_VARID(nid,"teta",varid)
-        start=(/1,1,1,timestep/)
-        count=(/iip1,jjp1,llm,1/)
-#ifdef NC_DOUBLE
-        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")
-        ierr = NF_INQ_VARID(nid,"q",varid)
-        start=(/1,1,1,timestep/)
-        count=(/iip1,jjp1,llm,1/)
-#ifdef NC_DOUBLE
-        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
- 
+
     ierr = NF_CLOSE(nid)
+
+
+!$OMP END MASTER
+!$OMP BARRIER
+
+    RETURN
 
   END SUBROUTINE guide_out
@@ -2325,4 +2308,53 @@
   end subroutine correctbid
 
+
+!====================================================================
+! Ascii debug output. Could be reactivated
+!====================================================================
+
+subroutine dump2du(var,varname)
+use parallel_lmdz
+use mod_hallo
+implicit none
+include 'dimensions.h'
+include 'paramet.h'
+
+      CHARACTER (len=*) :: varname
+
+
+real, dimension(ijb_u:ije_u) :: var
+
+real, dimension(ip1jmp1) :: var_glob
+
+    RETURN
+
+    call barrier
+    CALL Gather_field_u(var,var_glob,1)
+    call barrier
+
+    if (mpi_rank==0) then
+       call dump2d(iip1,jjp1,var_glob,varname)
+    endif
+
+    call barrier
+
+    return
+    end subroutine dump2du
+
+!====================================================================
+! Ascii debug output. Could be reactivated
+!====================================================================
+subroutine dumpall
+     implicit none
+     include "dimensions.h"
+     include "paramet.h"
+     include "comgeom.h"
+     call barrier
+     call dump2du(alpha_u(ijb_u:ije_u),'  alpha_u couche 1')
+     call dump2du(unat2(:,jjbu:jjeu,nlevnc),'  unat2 couche nlevnc')
+     call dump2du(ugui1(ijb_u:ije_u,1)*sqrt(unscu2(ijb_u:ije_u)),'  ugui1 couche 1')
+     return
+end subroutine dumpall
+
 !===========================================================================
 END MODULE guide_loc_mod
