Index: /LMDZ5/branches/testing/libf/dyn3d/guide_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3d/guide_mod.F90	(revision 2023)
+++ /LMDZ5/branches/testing/libf/dyn3d/guide_mod.F90	(revision 2024)
@@ -437,5 +437,5 @@
 ! 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) CALL guide_out("SP",jjp1,1,ps)
     
     if (guide_u) then
@@ -447,5 +447,7 @@
         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("ua",jjp1,llm,(1.-tau)*ugui1+tau*ugui2)
+        IF (f_out) CALL guide_out("u",jjp1,llm,ucov)
+        IF (f_out) CALL guide_out("ucov",jjp1,llm,f_add/factt)
         ucov=ucov+f_add
     endif
@@ -459,5 +461,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("teta",jjp1,llm,f_add/factt)
         teta=teta+f_add
     endif
@@ -471,5 +473,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("ps",jjp1,1,f_add(1:ip1jmp1,1)/factt)
         ps=ps+f_add(1:ip1jmp1,1)
         CALL pression(ip1jmp1,ap,bp,ps,p)
@@ -485,5 +487,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=q+f_add
     endif
@@ -497,5 +499,7 @@
         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,vcov)
+        IF (f_out) CALL guide_out("va",jjm,llm,(1.-tau)*vgui1+tau*vgui2)
+        IF (f_out) CALL guide_out("vcov",jjm,llm,f_add(1:ip1jm,:)/factt)
         vcov=vcov+f_add(1:ip1jm,:)
     endif
@@ -1507,5 +1511,5 @@
     
     ! Variables entree
-    CHARACTER, INTENT(IN)                          :: varname
+    CHARACTER*(*), INTENT(IN)                          :: varname
     INTEGER,   INTENT (IN)                         :: hsize,vsize
     REAL, DIMENSION (iip1,hsize,vsize), INTENT(IN) :: field
@@ -1516,7 +1520,9 @@
     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
+    INTEGER                :: ierr, varid,l
+    REAL, DIMENSION (iip1,hsize,vsize) :: field2
 
     print *,'Guide: output timestep',timestep,'var ',varname
@@ -1542,5 +1548,7 @@
         ierr=NF_DEF_VAR(nid,"LEVEL",NF_FLOAT,1,id_lev,vid_lev)
         ierr=NF_DEF_VAR(nid,"cu",NF_FLOAT,2,(/id_lonu,id_latu/),vid_cu)
+        ierr=NF_DEF_VAR(nid,"au",NF_FLOAT,2,(/id_lonu,id_latu/),vid_au)
         ierr=NF_DEF_VAR(nid,"cv",NF_FLOAT,2,(/id_lonv,id_latv/),vid_cv)
+        ierr=NF_DEF_VAR(nid,"av",NF_FLOAT,2,(/id_lonv,id_latv/),vid_av)
         
         ierr=NF_ENDDEF(nid)
@@ -1555,4 +1563,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,alpha_u)
+        ierr = NF_PUT_VAR_DOUBLE(nid,vid_av,alpha_v)
 #else
         ierr = NF_PUT_VAR_REAL(nid,vid_lonu,rlonu*180./pi)
@@ -1563,4 +1573,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
 ! --------------------------------------------------------------------
@@ -1579,4 +1591,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
@@ -1584,4 +1598,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
@@ -1606,62 +1622,36 @@
     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 ("S")
-        timestep=timestep+1
-        ierr = NF_INQ_VARID(nid,"SP",varid)
+    CASE ("SP","ps")
         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)
-#endif
-    CASE ("P")
-        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)
-#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 ; field2(:,2:jjm,l)=field(:,2:jjm,l)/cu(:,2:jjm) ; ENDDO
+        field2(:,1,:)=0. ; field2(:,jjp1,:)=0.
+    CASE("v","va")
+        DO l=1,llm ; field2(:,:,l)=field(:,:,l)/cv(:,:) ; ENDDO
+    CASE DEFAULT
+        field2=field
+    END SELECT
+
+
 #ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field)
+    ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field2)
 #else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
+    ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field2)
 #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)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
-#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)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
-#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)
-#else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field)
-#endif
-    END SELECT
- 
+
     ierr = NF_CLOSE(nid)
 
Index: /LMDZ5/branches/testing/libf/dyn3dpar/guide_p_mod.F90
===================================================================
--- /LMDZ5/branches/testing/libf/dyn3dpar/guide_p_mod.F90	(revision 2023)
+++ /LMDZ5/branches/testing/libf/dyn3dpar/guide_p_mod.F90	(revision 2024)
@@ -491,19 +491,19 @@
     IF (f_out) THEN
 !       Calcul niveaux pression milieu de couches 
-	CALL pression_p( ip1jmp1, ap, bp, ps, p )
-	if (pressure_exner) then
+        CALL pression_p( ip1jmp1, ap, bp, ps, p )
+        if (pressure_exner) then
           CALL exner_hyb_p(ip1jmp1,ps,p,alpha,beta,pks,pk,pkf)
-	else
+        else
           CALL exner_milieu_p(ip1jmp1,ps,p,beta,pks,pk,pkf)
         endif
         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.)
+        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("SP",jjp1,llm,p(1:ip1jmp1,1:llm),1.)
     ENDIF
     
@@ -517,5 +517,7 @@
         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,ucov,factt)
+        IF (f_out) CALL guide_out("ua",jjp1,llm,(1.-tau)*ugui1(:,:)+tau*ugui2(:,:),factt)
+        IF (f_out) CALL guide_out("ucov",jjp1,llm,f_add(:,:)/factt,factt)
         ucov(ijb_u:ije_u,:)=ucov(ijb_u:ije_u,:)+f_add(ijb_u:ije_u,:)
     endif
@@ -529,5 +531,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("teta",jjp1,llm,f_add(:,:)/factt,factt)
         teta(ijb_u:ije_u,:)=teta(ijb_u:ije_u,:)+f_add(ijb_u:ije_u,:)
     endif
@@ -541,5 +543,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("SP",jjp1,1,f_add(1:ip1jmp1,1),factt)
+        IF (f_out) CALL guide_out("ps",jjp1,1,f_add(1:ip1jmp1,1)/factt,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)
@@ -555,5 +557,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,factt)
         q(ijb_u:ije_u,:)=q(ijb_u:ije_u,:)+f_add(ijb_u:ije_u,:)
     endif
@@ -568,5 +570,7 @@
         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,vcov(1:ip1jm,:),factt)
+        IF (f_out) CALL guide_out("va",jjm,llm,(1.-tau)*vgui1(:,:)+tau*vgui2(:,:),factt)
+        IF (f_out) CALL guide_out("vcov",jjm,llm,f_add(1:ip1jm,:)/factt,factt)
         vcov(ijb_v:ije_v,:)=vcov(ijb_v:ije_v,:)+f_add(ijb_v:ije_v,:)
     endif
@@ -784,25 +788,25 @@
     IF (guide_plevs.EQ.1) THEN
         DO l=1,llm
-	    DO j=jjb_u,jje_u
-		DO i =1, iip1
+            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
         ENDDO
     ELSE
-	CALL pression_p( ip1jmp1, ap, bp, psi, p )
-	if (pressure_exner) then
+        CALL pression_p( ip1jmp1, ap, bp, psi, p )
+        if (pressure_exner) then
           CALL exner_hyb_p(ip1jmp1,psi,p,alpha,beta,pks,pk,pkf)
         else
           CALL exner_milieu_p(ip1jmp1,psi,p,beta,pks,pk,pkf)
         endif
-	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
+        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
 
@@ -1024,10 +1028,10 @@
         ! 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)
+         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
@@ -1041,10 +1045,10 @@
             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)
+         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
@@ -1807,5 +1811,5 @@
     
     ! Variables entree
-    CHARACTER, INTENT(IN)                          :: varname
+    CHARACTER*(*), INTENT(IN)                          :: varname
     INTEGER,   INTENT (IN)                         :: hsize,vsize
     REAL, DIMENSION (iip1,hsize,vsize), INTENT(IN) :: field
@@ -1817,7 +1821,10 @@
     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       :: l
     INTEGER, DIMENSION (3) :: dim3
     INTEGER, DIMENSION (4) :: dim4,count,start
     INTEGER                :: ierr, varid
+    REAL, DIMENSION (iip1,hsize,vsize) :: field2
     
     CALL gather_field(field,iip1*hsize,vsize,0)
@@ -1834,4 +1841,5 @@
 ! Definition des dimensions
         ierr=NF_DEF_DIM(nid,"LONU",iip1,id_lonu) 
+        print*,'id_lonu 1 ',id_lonu
         ierr=NF_DEF_DIM(nid,"LONV",iip1,id_lonv) 
         ierr=NF_DEF_DIM(nid,"LATU",jjp1,id_latu) 
@@ -1842,4 +1850,5 @@
 ! Creation des variables dimensions
         ierr=NF_DEF_VAR(nid,"LONU",NF_FLOAT,1,id_lonu,vid_lonu)
+        print*,'id_lonu 2 ',id_lonu
         ierr=NF_DEF_VAR(nid,"LONV",NF_FLOAT,1,id_lonv,vid_lonv)
         ierr=NF_DEF_VAR(nid,"LATU",NF_FLOAT,1,id_latu,vid_latu)
@@ -1848,4 +1857,6 @@
         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)
@@ -1853,4 +1864,5 @@
 ! Enregistrement des variables dimensions
 #ifdef NC_DOUBLE
+        print*,'id_lonu DOUBLE ',id_lonu,rlonu*180./pi
         ierr = NF_PUT_VAR_DOUBLE(nid,vid_lonu,rlonu*180./pi)
         ierr = NF_PUT_VAR_DOUBLE(nid,vid_lonv,rlonv*180./pi)
@@ -1860,5 +1872,8 @@
         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,alpha_u)
+        ierr = NF_PUT_VAR_DOUBLE(nid,vid_av,alpha_v)
 #else
+        print*,'id_lonu 3 ',id_lonu,rlonu*180./pi
         ierr = NF_PUT_VAR_REAL(nid,vid_lonu,rlonu*180./pi)
         ierr = NF_PUT_VAR_REAL(nid,vid_lonv,rlonv*180./pi)
@@ -1868,4 +1883,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
 ! --------------------------------------------------------------------
@@ -1875,5 +1892,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
@@ -1883,5 +1900,8 @@
 ! Zonal wind
         IF (guide_u) THEN
+        print*,'id_lonu 4 ',id_lonu,varname
             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
@@ -1889,4 +1909,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
@@ -1912,61 +1934,41 @@
     ierr=NF_OPEN("guide_ins.nc",NF_WRITE,nid)
 
+    IF (varname=="SP") timestep=timestep+1
+
+    IF (varname=="SP") THEN
+      print*,'varname=SP=',varname
+    ELSE
+      print*,'varname diff SP=',varname
+    ENDIF
+
+
+    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 ; field2(:,2:jjm,l)=field(:,2:jjm,l)/cu(:,2:jjm) ; ENDDO
+        field2(:,1,:)=0. ; field2(:,jjp1,:)=0.
+    CASE("v","va")
+        DO l=1,llm ; field2(:,:,l)=field(:,:,l)/cv(:,:) ; ENDDO
+    CASE DEFAULT
+        field2=field
+    END SELECT
+
 #ifdef NC_DOUBLE
-        ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field/factt)
+    ierr = NF_PUT_VARA_DOUBLE(nid,varid,start,count,field2)
 #else
-        ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field/factt)
+    ierr = NF_PUT_VARA_REAL(nid,varid,start,count,field2)
 #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)
