Index: LMDZ5/branches/IPSLCM5A2.1/libf/phylmd/iophy.F90
===================================================================
--- LMDZ5/branches/IPSLCM5A2.1/libf/phylmd/iophy.F90	(revision 2866)
+++ LMDZ5/branches/IPSLCM5A2.1/libf/phylmd/iophy.F90	(revision 3629)
@@ -884,6 +884,6 @@
 ! ug NOUVELLE VERSION DES WRITE AVEC LA BOUCLE DO RENTREE
   SUBROUTINE histwrite2d_phy(var,field, STD_iff)
-  USE dimphy, only: klon
-  USE mod_phys_lmdz_para, only: gather_omp, grid1dto2d_mpi, &
+  USE dimphy, ONLY: klon, klev
+  USE mod_phys_lmdz_para, ONLY: gather_omp, grid1dto2d_mpi, &
                                 jj_nb, klon_mpi, klon_mpi_begin, &
                                 klon_mpi_end, is_sequential
@@ -917,7 +917,7 @@
     REAL, ALLOCATABLE, DIMENSION(:) :: fieldok
 
-    IF (prt_level >= 10) THEN
+!    IF (prt_level >= 10) THEN
       WRITE(lunout,*)'Begin histwrite2d_phy for ',trim(var%name)
-    ENDIF
+!    ENDIF
 ! ug RUSTINE POUR LES STD LEVS.....
       IF (PRESENT(STD_iff)) THEN
@@ -948,12 +948,15 @@
 
     !Et sinon on.... écrit
-    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_phy','Field first DIMENSION not equal to klon',1)
+    IF (SIZE(field)/=klon .AND. SIZE(field)/=klev .AND. SIZE(field)/=klev+1) CALL abort_physic('iophy::histwrite2d_phy','Field first DIMENSION not equal to klon/klev',1)    
+    IF (prt_level >= 10) THEn
+      WRITE (lunout,*)"histwrite2d_phy: .not.vars_defined ; time to gather and write ", trim(var%name)
+    ENDIF
     
-    if (prt_level >= 10) then
-      write(lunout,*)"histwrite2d_phy: .not.vars_defined ; time to gather and write ", &
-                     trim(var%name)
-    endif
     
-    CALL Gather_omp(field,buffer_omp)
+    IF (SIZE(field) == klon) then
+        CALL Gather_omp(field,buffer_omp)
+    ELSE
+        buffer_omp(:)=0.
+    ENDIF
 !$OMP MASTER
     CALL grid1Dto2D_mpi(buffer_omp,Field2d)
@@ -964,13 +967,15 @@
       IF (ok_all_xml) THEN
 #ifdef CPP_XIOS
-          if (prt_level >= 10) then
-             write(lunout,*)'Dans iophy histwrite2D,var%name ',&
-                             trim(var%name)                       
-          endif
-          CALL xios_send_field(var%name, Field2d)
-          if (prt_level >= 10) then
-             write(lunout,*)'Dans iophy histwrite2D,var%name apres xios_send ',&
-                             trim(var%name)                       
-          endif
+          IF (prt_level >= 10) THEN
+             write(lunout,*)'Dans iophy histwrite2D,var%name ', trim(var%name)                       
+          ENDIF
+          IF (SIZE(field) == klon) then
+              CALL xios_send_field(var%name, Field2d)
+          ELSE
+             CALL xios_send_field(var%name, field)
+          ENDIF 
+          IF (prt_level >= 10) THEN
+             WRITE (lunout,*)'Dans iophy histwrite2D,var%name apres xios_send ', trim(var%name)                       
+          ENDIF
 #else
         CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
@@ -982,10 +987,13 @@
 #ifdef CPP_XIOS
                IF (firstx) THEN
-                  if (prt_level >= 10) then
-                     write(lunout,*)'Dans iophy histwrite2D,iff,var%name ',&
-                                    iff,trim(var%name)                       
-                     write(lunout,*)"histwrite2d_phy:.NOT.clef_stations(iff)and iff==iff_beg, call xios_send_field"
-                  endif
-                  CALL xios_send_field(var%name, Field2d)
+                  IF (prt_level >= 10) THEN
+                     WRITE (lunout,*)'Dans iophy histwrite2D,iff,var%name ', iff,trim(var%name)                       
+                     WRITE (lunout,*)"histwrite2d_phy:.NOT.clef_stations(iff)and iff==iff_beg, call xios_send_field"
+                  ENDIF
+                  IF (SIZE(field) == klon) then
+                     CALL xios_send_field(var%name, Field2d)
+                  ELSE
+                     CALL xios_send_field(var%name, field)
+                  ENDIF
                   firstx=.false.
                ENDIF
@@ -1083,5 +1091,5 @@
             iff_beg = 1
             iff_end = nfiles
-      END IF
+      ENDIF
 
   ! On regarde si on est dans la phase de définition ou d'écriture:
@@ -1097,5 +1105,7 @@
   ELSE
     !Et sinon on.... écrit
-    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
+
+    IF (SIZE(field,1)/=klon .AND. SIZE(field,1)/=klev .AND. SIZE(field,1)/=klev+1) CALL abort_physic('iophy::histwrite3d_phy','Field first DIMENSION not equal to klon/klev',1)
+
     nlev=SIZE(field,2)
     if (nlev.eq.klev+1) then
@@ -1105,5 +1115,9 @@
     endif
 
-    CALL Gather_omp(field,buffer_omp)
+    IF (SIZE(field,1) == klon) then
+        CALL Gather_omp(field,buffer_omp)
+    ELSE
+        buffer_omp(:,:)=0.
+    ENDIF
 !$OMP MASTER
     CALL grid1Dto2D_mpi(buffer_omp,field3d)
@@ -1118,6 +1132,10 @@
              write(lunout,*)'Dans iophy histwrite3D,var%name ',&
                              trim(var%name)                       
-          endif
-          CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
+          ENDIF
+          IF (SIZE(field,1) == klon) then
+             CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
+          ELSE
+             CALL xios_send_field(var%name, field)
+          ENDIF
 #else
         CALL abort_physic ('iophy','cannot have ok_all_xml = .T. without CPP_XIOS defined' ,1)
@@ -1136,7 +1154,11 @@
                                   trim(var%name), ' with iim jjm nlevx = ', &
                                   nbp_lon,jj_nb,nlevx
-                endif
-                CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
-                            firstx=.false.
+                ENDIF
+                IF (SIZE(field,1) == klon) then
+                    CALL xios_send_field(var%name, Field3d(:,:,1:nlevx))
+                ELSE
+                     CALL xios_send_field(var%name, field)
+                ENDIF
+                firstx=.false.
               ENDIF
 #endif
@@ -1194,6 +1216,6 @@
 #ifdef CPP_XIOS
   SUBROUTINE histwrite2d_xios(field_name,field)
-  USE dimphy, only: klon
-  USE mod_phys_lmdz_para, only: gather_omp, grid1Dto2D_mpi, &
+  USE dimphy, ONLY: klon, klev
+  USE mod_phys_lmdz_para, ONLY: gather_omp, grid1Dto2D_mpi, &
                                 is_sequential, klon_mpi_begin, klon_mpi_end, &
                                 jj_nb, klon_mpi
@@ -1217,7 +1239,12 @@
 
     !Et sinon on.... écrit
-    IF (SIZE(field)/=klon) CALL abort_physic('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon',1)
+    IF (SIZE(field)/=klon .AND. SIZE(field)/=klev .AND. SIZE(field)/=klev+1) CALL abort_physic('iophy::histwrite2d_xios','Field first DIMENSION not equal to klon/klev',1)
     
-    CALL Gather_omp(field,buffer_omp)    
+    IF (SIZE(field) == klev .OR. SIZE(field) == klev+1) then
+!$OMP MASTER
+        CALL xios_send_field(field_name,field)
+!$OMP END MASTER   
+    ELSE
+        CALL Gather_omp(field,buffer_omp)    
 !$OMP MASTER
     CALL grid1Dto2D_mpi(buffer_omp,Field2d)
@@ -1257,4 +1284,5 @@
     deallocate(fieldok)
 !$OMP END MASTER   
+    ENDIF
 
   IF (prt_level >= 10) WRITE(lunout,*)'End histrwrite2d_xios ',field_name
@@ -1286,6 +1314,15 @@
 
     !Et on.... écrit
-    IF (SIZE(field,1)/=klon) CALL abort_physic('iophy::histwrite3d','Field first DIMENSION not equal to klon',1)
-    nlev=SIZE(field,2)
+    IF (SIZE(field,1)/=klon .AND. SIZE(field,1)/=klev .AND. SIZE(field,1)/=klev+1) then
+      write(lunout,*)' histrwrite3d_xios ', field_name, SIZE(field)
+      CALL abort_physic('iophy::histwrite3d_xios','Field first DIMENSION not equal to klon/klev',1)
+    ENDIF
+    
+    IF (SIZE(field,1) == klev .OR. SIZE(field,1) == klev+1) then
+!$OMP MASTER
+        CALL xios_send_field(field_name,field)
+!$OMP END MASTER   
+    ELSE
+        nlev=SIZE(field,2)
 
 
@@ -1328,7 +1365,24 @@
     deallocate(fieldok)
 !$OMP END MASTER   
+    ENDIF
 
   IF (prt_level >= 10) write(lunout,*)'End histrwrite3d_xios ',field_name
   END SUBROUTINE histwrite3d_xios
+
+#ifdef CPP_XIOS
+  SUBROUTINE histwrite0d_xios(field_name, field)
+  USE xios, ONLY: xios_send_field
+  IMPLICIT NONE
+
+    CHARACTER(LEN=*), INTENT(IN) :: field_name
+    REAL, INTENT(IN) :: field ! --> scalar
+
+!$OMP MASTER
+   CALL xios_send_field(field_name, field)
+!$OMP END MASTER
+
+  END SUBROUTINE histwrite0d_xios
+#endif
+
 #endif
 end module iophy
