Index: codes/icosagcm/trunk/arch/arch-X64_CURIE.env
===================================================================
--- codes/icosagcm/trunk/arch/arch-X64_CURIE.env	(revision 170)
+++ codes/icosagcm/trunk/arch/arch-X64_CURIE.env	(revision 171)
@@ -1,6 +1,6 @@
 module unload netcdf
 module unload hdf5
-module load netcdf/3.6.3
-module load hdf5
+module load netcdf/4.2_hdf5_parallel
+module load  hdf5/1.8.9_parallel
 module load vampir
 module load vampirtrace
Index: codes/icosagcm/trunk/arch/arch-X64_CURIE.fcm
===================================================================
--- codes/icosagcm/trunk/arch/arch-X64_CURIE.fcm	(revision 170)
+++ codes/icosagcm/trunk/arch/arch-X64_CURIE.fcm	(revision 171)
@@ -5,5 +5,5 @@
 %MAKE                gmake
 %FPP_FLAGS           -P
-%FPP_DEF             KEY_NONE
+%FPP_DEF             KEY_NONE CPP_NETCDF4
 %BASE_FFLAGS         -i4 -r8 -auto -align all -I${MKLROOT}/include
 %PROD_FFLAGS         -g -traceback -O3 -vec-report2
Index: codes/icosagcm/trunk/arch/arch-X64_CURIE.path
===================================================================
--- codes/icosagcm/trunk/arch/arch-X64_CURIE.path	(revision 170)
+++ codes/icosagcm/trunk/arch/arch-X64_CURIE.path	(revision 171)
@@ -10,2 +10,6 @@
 HDF5_LIBDIR="-Wl,-rpath=$HDF5_LIB_DIR -L$HDF5_LIB_DIR"
 HDF5_LIB="-lhdf5_hl -lhdf5 -lhdf5 -lz -lcurl"
+
+XIOS_INCDIR="-I$WORKDIR/XIOS_COMMIT_V1.7/inc"
+XIOS_LIBDIR="-L$WORKDIR/XIOS_COMMIT_V1.7/lib"
+XIOS_LIB="-lxios -lstdc++"
Index: codes/icosagcm/trunk/bld.cfg
===================================================================
--- codes/icosagcm/trunk/bld.cfg	(revision 170)
+++ codes/icosagcm/trunk/bld.cfg	(revision 171)
@@ -37,4 +37,5 @@
 bld::excl_dep        use::omp_lib
 bld::excl_dep        inc::mpif.h
+bld::excl_dep        use::xios
 
 bld::tool::SHELL   /bin/bash
Index: codes/icosagcm/trunk/make_icosa
===================================================================
--- codes/icosagcm/trunk/make_icosa	(revision 170)
+++ codes/icosagcm/trunk/make_icosa	(revision 171)
@@ -8,4 +8,5 @@
 job=1
 full_defined="FALSE"
+with_xios_defined="FALSE"
 arch_defined="FALSE"
 parallel_defined="FALSE"
@@ -13,4 +14,5 @@
 parallel="none"
 CPP_KEY="CPP_NONE" 
+ICOSA_LIB=""
 
 while (($# > 0))
@@ -46,4 +48,7 @@
       "-full")
 	  full_defined="TRUE" ; shift ;;
+
+      "-with_xios")
+	  with_xios_defined="TRUE" ; shift ;;
 
       *)
@@ -110,5 +115,12 @@
 fi
 
-ICOSA_LIB="$NETCDF_LIBDIR $NETCDF_LIB $HDF5_LIBDIR $HDF5_LIB"
+if [[ "$with_xios_defined" == "TRUE" ]]
+then
+  CPP_KEY="$CPP_KEY CPP_USING_XIOS"
+  COMPIL_FFLAGS="$COMPIL_FFLAGS $XIOS_INCDIR"
+  ICOSA_LIB="$ICOSA_LIB $XIOS_LIBDIR $XIOS_LIB"
+fi  
+
+ICOSA_LIB="$ICOSA_LIB $NETCDF_LIBDIR $NETCDF_LIB $HDF5_LIBDIR $HDF5_LIB"
 
 rm -f config.fcm
Index: codes/icosagcm/trunk/src/caldyn_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/caldyn_gcm.f90	(revision 170)
+++ codes/icosagcm/trunk/src/caldyn_gcm.f90	(revision 171)
@@ -129,4 +129,5 @@
     USE trace
     USE omp_para
+    USE output_field_mod
     IMPLICIT NONE
     LOGICAL,INTENT(IN)    :: write_out
@@ -266,13 +267,13 @@
 !            f_buf_i, f_buf_v, f_buf_u3d, f_buf_ulon, f_buf_ulat, f_buf_s, f_buf_p)
 
-       CALL writefield("ps",f_ps)
-       CALL writefield("dps",f_dps)
-       CALL writefield("mass",f_mass)
-       CALL writefield("dmass",f_dmass)
-       CALL writefield("vort",f_qu)
-       CALL writefield("theta",f_theta)
-       CALL writefield("exner",f_pk)
-       CALL writefield("pv",f_qv)
-
+       CALL output_field("ps",f_ps)
+       CALL output_field("dps",f_dps)
+       CALL output_field("mass",f_mass)
+       CALL output_field("dmass",f_dmass)
+       CALL output_field("vort",f_qv)
+       CALL output_field("theta",f_theta)
+       CALL output_field("exner",f_pk)
+       CALL output_field("pv",f_qv)
+ 
     END IF
     
Index: codes/icosagcm/trunk/src/icosa_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/icosa_gcm.f90	(revision 170)
+++ codes/icosagcm/trunk/src/icosa_gcm.f90	(revision 171)
@@ -9,4 +9,7 @@
   USE vertical_interp_mod
   USE trace
+  USE output_field_mod
+  USE xios_mod
+  USE write_field
   IMPLICIT NONE
   
@@ -21,4 +24,5 @@
  
   CALL init_mpipara
+  CALL xios_init
   CALL init_earth_const 
   CALL init_grid_param
@@ -67,4 +71,5 @@
   CALL init_time
 
+  CALL output_field_init
   CALL init_timeloop
 
@@ -73,4 +78,5 @@
 !$OMP END PARALLEL
 
+  CALL output_field_finalize
   CALL close_files
   CALL close_time_counter
Index: codes/icosagcm/trunk/src/mpi_mod.F90
===================================================================
--- codes/icosagcm/trunk/src/mpi_mod.F90	(revision 170)
+++ codes/icosagcm/trunk/src/mpi_mod.F90	(revision 171)
@@ -11,4 +11,5 @@
   INTEGER :: MPI_INFO_NULL
   INTEGER :: MPI_STATUS_SIZE 
+  INTEGER :: MPI_SUM
   INTEGER,PARAMETER :: MPI_ADDRESS_KIND=KIND(INTEGER)
 #endif
Index: codes/icosagcm/trunk/src/mpipara.F90
===================================================================
--- codes/icosagcm/trunk/src/mpipara.F90	(revision 170)
+++ codes/icosagcm/trunk/src/mpipara.F90	(revision 171)
@@ -17,4 +17,7 @@
   SUBROUTINE init_mpipara
   USE mpi_mod
+#ifdef CPP_USING_XIOS
+  USE xios
+#endif
   IMPLICIT NONE
 
@@ -26,5 +29,10 @@
     IF (using_mpi) THEN
       CALL MPI_INIT(ierr)
-      comm_icosa=MPI_COMM_WORLD
+
+#ifdef CPP_USING_XIOS
+      CALL xios_initialize("icosagcm",return_comm=comm_icosa)
+#else
+     comm_icosa=MPI_COMM_WORLD
+#endif
       CALL MPI_COMM_SIZE(comm_icosa,mpi_size,ierr)
       CALL MPI_COMM_RANK(comm_icosa,mpi_rank,ierr)
Index: codes/icosagcm/trunk/src/output_field.f90
===================================================================
--- codes/icosagcm/trunk/src/output_field.f90	(revision 171)
+++ codes/icosagcm/trunk/src/output_field.f90	(revision 171)
@@ -0,0 +1,58 @@
+MODULE output_field_mod
+USE genmod
+  PRIVATE
+  LOGICAL,SAVE :: xios_output    
+
+  PUBLIC xios_output,output_field_init,output_field,output_field_finalize
+
+CONTAINS 
+  
+  SUBROUTINE output_field_init
+  USE IOIPSL
+  USE xios_mod
+  USE write_field
+  IMPLICIT NONE
+
+    IF (using_xios) THEN
+      xios_output=.TRUE.
+      CALL getin('xios_output',xios_output)
+    ELSE
+      xios_output=.FALSE.
+    ENDIF
+    
+    IF (xios_output) THEN
+      CALL xios_init_write_field
+    ENDIF
+
+    
+  END SUBROUTINE output_field_init
+
+  SUBROUTINE output_field(name_in,field)
+    USE field_mod
+    USE xios_mod
+    USE write_field
+    IMPLICIT NONE  
+     CHARACTER(LEN=*),INTENT(IN) :: name_in
+      TYPE(t_field),POINTER :: field(:)
+
+      IF (xios_output) THEN
+        CALL xios_write_field(name_in,field)
+      ELSE
+       CALL writeField(name_in,field)
+      ENDIF
+
+  END SUBROUTINE output_field
+
+  SUBROUTINE output_field_finalize
+  USE IOIPSL
+  USE xios_mod
+  IMPLICIT NONE
+    
+    IF (xios_output) THEN
+      CALL xios_write_field_finalize
+    ENDIF
+    
+  END SUBROUTINE output_field_finalize
+
+END MODULE output_field_mod
+  
Index: codes/icosagcm/trunk/src/timeloop_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 170)
+++ codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 171)
@@ -40,4 +40,6 @@
   USE check_conserve_mod
   USE ioipsl
+  USE output_field_mod
+  USE write_field
   IMPLICIT NONE
 
@@ -71,4 +73,5 @@
    CALL getin('start_time',start_time) 
 
+   
    write_period=0
    CALL getin('write_period',write_period)
@@ -96,4 +99,5 @@
 !----------------------------------------------------
 
+   IF (xios_output) itau_out=1
 
 ! Time-independant orography
@@ -203,4 +207,6 @@
   USE transfert_mod
   USE check_conserve_mod
+  USE xios_mod
+  USE output_field_mod
   IMPLICIT NONE  
     REAL(rstd),POINTER :: q(:,:,:)
@@ -232,4 +238,6 @@
 
   DO it=0,itaumax
+    
+    CALL xios_update_calendar(it)
     IF (MOD(it,itau_sync)==0) THEN
       CALL send_message(f_ps,req_ps0)
@@ -247,6 +255,6 @@
 !    IF (is_mpi_root) PRINT *,"It No :",It,"   t :",dt*It
     IF (mod(it,itau_out)==0 ) THEN
-      CALL writefield("q",f_q)
       CALL update_time_counter(dt*it)
+      CALL output_field("q",f_q)
       CALL check_conserve(f_ps,f_dps,f_u,f_theta_rhodz,f_phis,it)  
     ENDIF
@@ -303,8 +311,8 @@
 
 !----------------------------------------------------
-    jD_cur = jD_ref + day_ini - day_ref + it/day_step
-    jH_cur = jH_ref + start_time + mod(it,day_step)/float(day_step)
-    jD_cur = jD_cur + int(jH_cur)
-    jH_cur = jH_cur - int(jH_cur)
+!    jD_cur = jD_ref + day_ini - day_ref + it/day_step
+!    jH_cur = jH_ref + start_time + mod(it,day_step)/float(day_step)
+!    jD_cur = jD_cur + int(jH_cur)
+!    jH_cur = jH_cur - int(jH_cur)
     CALL physics(it,jD_cur,jH_cur,f_phis, f_ps, f_theta_rhodz, f_u, f_q)
     ENDDO
Index: codes/icosagcm/trunk/src/write_field.f90
===================================================================
--- codes/icosagcm/trunk/src/write_field.f90	(revision 170)
+++ codes/icosagcm/trunk/src/write_field.f90	(revision 171)
@@ -2,5 +2,5 @@
 USE genmod
 implicit none
-  
+  PRIVATE  
   INTEGER,SAVE :: ncprec
   
@@ -11,13 +11,15 @@
   END TYPE ncvar
 
-  integer, parameter :: MaxWriteField = 1000
-  integer, dimension(MaxWriteField),save :: FieldId
-  TYPE(ncvar), dimension(MaxWriteField),save :: FieldVarId
-  integer, dimension(MaxWriteField),save :: FieldIndex
-  character(len=255), dimension(MaxWriteField) ::  FieldName 
+  INTEGER, PARAMETER :: MaxWriteField = 1000
+  INTEGER, DIMENSION(MaxWriteField),SAVE :: FieldId
+  TYPE(ncvar), dimension(MaxWriteField),SAVE :: FieldVarId
+  INTEGER, DIMENSION(MaxWriteField),SAVE :: FieldIndex
+  CHARACTER(len=255), DIMENSION(MaxWriteField) ::  FieldName 
    
-  integer,save :: NbField = 0
+  INTEGER,SAVE :: NbField = 0
   
-  contains
+  PUBLIC init_writeField, writefield, close_files
+  
+  CONTAINS
   
     SUBROUTINE init_writeField
Index: codes/icosagcm/trunk/src/xios_mod.F90
===================================================================
--- codes/icosagcm/trunk/src/xios_mod.F90	(revision 171)
+++ codes/icosagcm/trunk/src/xios_mod.F90	(revision 171)
@@ -0,0 +1,429 @@
+MODULE xios_mod
+
+#ifdef CPP_USING_XIOS
+   USE xios
+#endif
+
+  PUBLIC
+  LOGICAL,SAVE :: using_xios
+  INTEGER,SAVE :: ncell_i
+  INTEGER,SAVE :: ncell_v
+
+  PRIVATE ncell_i,ncell_v
+  
+CONTAINS
+
+#ifdef CPP_USING_XIOS
+ 
+ SUBROUTINE xios_init
+   USE IOIPSL
+   IMPLICIT NONE
+
+   using_xios=.TRUE.
+   
+ END SUBROUTINE xios_init  
+ 
+ SUBROUTINE xios_init_write_field
+ USE genmod
+ USE mpipara
+ USE xios
+ USE grid_param
+ USE domain_mod
+ USE dimensions
+ USE spherical_geom_mod
+ USE geometry
+ USE mpi_mod
+ USE time_mod
+ USE metric, ONLY : vup,vdown
+ IMPLICIT NONE
+  TYPE(xios_context) :: ctx_hdl
+  TYPE(xios_time)      :: dtime
+  REAL(rstd) :: lev_value(llm)
+  REAL(rstd) :: lev_valuep1(llm+1)
+  INTEGER :: ncell, ncell_tot, ncell_glo(0:mpi_size-1), displ
+  INTEGER :: ind, i,j,k,l
+  REAL(rstd),ALLOCATABLE    :: lon(:), lat(:), bounds_lon(:,:), bounds_lat(:,:)
+  TYPE(t_domain),POINTER :: d
+
+   CALL xios_context_initialize("icosagcm",comm_icosa)
+   CALL xios_get_handle("icosagcm",ctx_hdl)
+   CALL xios_set_current_context(ctx_hdl)
+   lev_value(:) = (/ (l,l=1,llm) /)     
+   lev_valuep1(:) = (/ (l,l=1,llm+1) /)     
+   CALL xios_set_axis_attr("lev",size=llm ,value=lev_value) ;
+   CALL xios_set_axis_attr("levp1",size=llm+1 ,value=lev_value) ;
+   
+   ncell=0
+   DO ind=1,ndomain
+     d=>domain(ind)
+        
+     DO j=d%jj_begin,d%jj_end
+       DO i=d%ii_begin,d%ii_end
+         IF (domain(ind)%own(i,j)) ncell=ncell+1
+       ENDDO
+     ENDDO
+   ENDDO      
+   ncell_i=ncell
+   
+   CALL MPI_ALLGATHER(ncell,1,MPI_INTEGER,ncell_glo,1,MPI_INTEGER,comm_icosa,ierr)
+
+   displ=0
+   DO i=1,mpi_rank
+     displ=displ+ncell_glo(i-1)
+   ENDDO
+
+   ncell_tot=sum(ncell_glo(:))
+   
+   ALLOCATE(lon(ncell), lat(ncell), bounds_lon(0:5,ncell), bounds_lat(0:5,ncell)) 
+   
+   ncell=0
+   DO ind=1,ndomain
+     d=>domain(ind)
+        
+     DO j=d%jj_begin,d%jj_end
+       DO i=d%ii_begin,d%ii_end
+         IF (domain(ind)%own(i,j)) THEN 
+           ncell=ncell+1
+           CALL xyz2lonlat(d%xyz(:,i,j),lon(ncell),lat(ncell))
+           lon(ncell)=lon(ncell)*180/Pi
+           lat(ncell)=lat(ncell)*180/Pi
+           DO k=0,5
+             CALL xyz2lonlat(d%vertex(:,k,i,j),bounds_lon(k,ncell), bounds_lat(k,ncell))
+             bounds_lat(k,ncell)=bounds_lat(k,ncell)*180/Pi
+             bounds_lon(k,ncell)=bounds_lon(k,ncell)*180/Pi
+           ENDDO
+         ENDIF
+       ENDDO
+     ENDDO
+   ENDDO         
+
+  
+   CALL xios_set_domain_attr("i",ni_glo=ncell_tot, ibegin=displ+1, ni=ncell)
+   CALL xios_set_domain_attr("i", data_dim=1, type='unstructured' , nvertex=6)
+   CALL xios_set_domain_attr("i",lonvalue=lon, latvalue=lat, bounds_lon=bounds_lon, bounds_lat=bounds_lat)
+   
+   DEALLOCATE(lon, lat, bounds_lon, bounds_lat) 
+    
+   ncell=0
+   DO ind=1,ndomain
+     d=>domain(ind)
+        
+     DO j=d%jj_begin+1,d%jj_end
+       DO i=d%ii_begin,d%ii_end-1
+         ncell=ncell+1
+       ENDDO
+     ENDDO
+
+     DO j=d%jj_begin,d%jj_end-1
+       DO i=d%ii_begin+1,d%ii_end
+          ncell=ncell+1
+        ENDDO
+     ENDDO
+
+   ENDDO      
+   
+   ncell_v=ncell
+   
+   CALL MPI_ALLGATHER(ncell,1,MPI_INTEGER,ncell_glo,1,MPI_INTEGER,comm_icosa,ierr)
+
+   displ=0
+   DO i=1,mpi_rank
+     displ=displ+ncell_glo(i-1)
+   ENDDO
+
+   ncell_tot=sum(ncell_glo(:))
+   
+   ALLOCATE(lon(ncell), lat(ncell), bounds_lon(0:2,ncell), bounds_lat(0:2,ncell)) 
+   
+   ncell=0
+   DO ind=1,ndomain
+     d=>domain(ind)
+ 
+     DO j=d%jj_begin+1,d%jj_end
+       DO i=d%ii_begin,d%ii_end-1
+           ncell=ncell+1
+           CALL xyz2lonlat(d%vertex(:,vdown,i,j),lon(ncell),lat(ncell))
+           lon(ncell)=lon(ncell)*180/Pi
+           lat(ncell)=lat(ncell)*180/Pi
+
+           CALL xyz2lonlat(d%xyz(:,i,j),bounds_lon(0,ncell), bounds_lat(0,ncell))
+           CALL xyz2lonlat(d%xyz(:,i,j-1),bounds_lon(1,ncell), bounds_lat(1,ncell))
+           CALL xyz2lonlat(d%xyz(:,i+1,j-1),bounds_lon(2,ncell), bounds_lat(2,ncell))
+
+           DO k=0,2
+             bounds_lat(k,ncell)=bounds_lat(k,ncell)*180/Pi
+             bounds_lon(k,ncell)=bounds_lon(k,ncell)*180/Pi
+           ENDDO
+         ENDDO
+       ENDDO 
+ 
+       DO j=d%jj_begin,d%jj_end-1
+         DO i=d%ii_begin+1,d%ii_end
+           ncell=ncell+1
+           CALL xyz2lonlat(d%vertex(:,vup,i,j),lon(ncell),lat(ncell))
+           lon(ncell)=lon(ncell)*180/Pi
+           lat(ncell)=lat(ncell)*180/Pi
+           CALL xyz2lonlat(d%xyz(:,i,j),bounds_lon(0,ncell), bounds_lat(0,ncell))
+           CALL xyz2lonlat(d%xyz(:,i,j+1),bounds_lon(1,ncell), bounds_lat(1,ncell))
+           CALL xyz2lonlat(d%xyz(:,i-1,j+1),bounds_lon(2,ncell), bounds_lat(2,ncell))
+
+           DO k=0,2
+             bounds_lat(k,ncell)=bounds_lat(k,ncell)*180/Pi
+             bounds_lon(k,ncell)=bounds_lon(k,ncell)*180/Pi
+           ENDDO
+         ENDDO
+       ENDDO 
+        
+   ENDDO         
+
+  
+   CALL xios_set_domain_attr("v",ni_glo=ncell_tot, ibegin=displ+1, ni=ncell)
+   CALL xios_set_domain_attr("v", data_dim=1, type='unstructured' , nvertex=3)
+   CALL xios_set_domain_attr("v",lonvalue=lon, latvalue=lat, bounds_lon=bounds_lon, bounds_lat=bounds_lat)
+
+
+   dtime%second=dt
+   CALL xios_set_timestep(dtime) 
+   CALL xios_close_context_definition()
+    
+ END SUBROUTINE xios_init_write_field
+  
+  
+ SUBROUTINE xios_write_field(name,field)
+ USE field_mod
+ IMPLICIT NONE 
+   CHARACTER(LEN=*),INTENT(IN) :: name
+   TYPE(t_field), POINTER :: field(:)
+   CHARACTER(LEN=10) :: str_number
+   INTEGER :: iq
+   
+   IF (Field(1)%field_type==field_T) THEN
+     IF (field(1)%ndim==2) THEN
+        CALL xios_write_field_scalar(name,field,1)
+      ELSE IF (field(1)%ndim==3) THEN
+        CALL xios_write_field_scalar(name,field,size(field(1)%rval3d,2))
+      ELSE IF (field(1)%ndim==4) THEN
+        DO iq=1,size(field(1)%rval4d,3)
+          WRITE(str_number,'(i10)') iq
+          CALL xios_write_field_scalar(name//TRIM(ADJUSTL(str_number)),field,size(field(1)%rval4d,2),iq)
+        ENDDO
+      ELSE
+        PRINT *, "xios_write_field : dimension > 4 are not supported for now"
+      ENDIF
+    ELSE IF (Field(1)%field_type==field_Z) THEN
+     IF (field(1)%ndim==2) THEN
+        CALL xios_write_field_vort(name,field,1)
+      ELSE IF (field(1)%ndim==3) THEN
+        CALL xios_write_field_vort(name,field,size(field(1)%rval3d,2))
+      ELSE IF (field(1)%ndim==4) THEN
+        DO iq=1,size(field(1)%rval4d,3)
+          WRITE(str_number,'(i10)') iq
+          CALL xios_write_field_vort(name//TRIM(ADJUSTL(str_number)),field,size(field(1)%rval4d,2),iq)
+        ENDDO
+      ELSE
+        PRINT *, "xios_write_field : dimension > 4 are not supported for now"
+      ENDIF
+    ENDIF
+      
+ END SUBROUTINE xios_write_field
+ 
+ SUBROUTINE xios_write_field_scalar(name,field,nlev,iq)
+ USE genmod
+ USE mpipara
+ USE xios
+ USE grid_param
+ USE domain_mod
+ USE dimensions
+ USE spherical_geom_mod
+ USE geometry
+ USE mpi_mod
+ IMPLICIT NONE 
+   CHARACTER(LEN=*),INTENT(IN) :: name
+   TYPE(t_field), POINTER :: field(:)
+   INTEGER,INTENT(IN) :: nlev
+   INTEGER,INTENT(IN),OPTIONAL :: iq
+   
+   REAL(rstd) :: field_tmp(ncell_i,nlev)
+   TYPE(t_domain),POINTER :: d
+   INTEGER :: n,i,j,ij,ind
+   
+   IF (field(1)%ndim==2) THEN
+     n=0
+     DO ind=1,ndomain
+       d=>domain(ind)
+        
+       DO j=d%jj_begin,d%jj_end
+         DO i=d%ii_begin,d%ii_end
+           IF (d%own(i,j)) THEN
+             n=n+1
+             ij=d%iim*(j-1)+i
+             field_tmp(n,1)=field(ind)%rval2d(ij)
+           ENDIF
+         ENDDO
+       ENDDO
+     ENDDO
+   ELSE IF (field(1)%ndim==3) THEN
+     n=0
+     DO ind=1,ndomain
+       d=>domain(ind)
+        
+       DO j=d%jj_begin,d%jj_end
+         DO i=d%ii_begin,d%ii_end
+           IF (d%own(i,j)) THEN
+             n=n+1
+             ij=d%iim*(j-1)+i
+             field_tmp(n,:)=field(ind)%rval3d(ij,:)
+           ENDIF
+         ENDDO
+       ENDDO
+     ENDDO
+   ELSE IF (field(1)%ndim==4) THEN
+     n=0
+     DO ind=1,ndomain
+       d=>domain(ind)
+        
+       DO j=d%jj_begin,d%jj_end
+         DO i=d%ii_begin,d%ii_end
+           IF (d%own(i,j)) THEN
+             n=n+1
+             ij=d%iim*(j-1)+i
+             field_tmp(n,:)=field(ind)%rval4d(ij,:,iq)
+           ENDIF
+         ENDDO
+       ENDDO
+     ENDDO     
+   ENDIF
+   
+   CALL xios_send_field(name,field_tmp)
+ 
+ END SUBROUTINE xios_write_field_scalar  
+      
+ SUBROUTINE xios_write_field_vort(name,field,nlev,iq)
+ USE genmod
+ USE mpipara
+ USE xios
+ USE grid_param
+ USE domain_mod
+ USE dimensions
+ USE spherical_geom_mod
+ USE geometry
+ USE mpi_mod
+ IMPLICIT NONE 
+   CHARACTER(LEN=*),INTENT(IN) :: name
+   TYPE(t_field), POINTER :: field(:)
+   INTEGER,INTENT(IN) :: nlev
+   INTEGER,INTENT(IN),OPTIONAL :: iq
+   
+   REAL(rstd) :: field_tmp(ncell_v,nlev)
+   TYPE(t_domain),POINTER :: d
+   INTEGER :: n,i,j,ij,ind
+   
+   IF (field(1)%ndim==2) THEN
+     n=0
+     DO ind=1,ndomain
+       d=>domain(ind)
+        
+       DO j=jj_begin+1,jj_end
+         DO i=ii_begin,ii_end-1
+           n=n+1
+           ij=iim*(j-1)+i
+           Field_tmp(n,1)=field(ind)%rval2d(ij+z_down)
+         ENDDO
+       ENDDO
+
+       DO j=jj_begin,jj_end-1
+         DO i=ii_begin+1,ii_end
+           n=n+1
+           ij=iim*(j-1)+i
+           Field_tmp(n,1)=field(ind)%rval2d(ij+z_up)
+          ENDDO
+       ENDDO
+          
+     ENDDO
+
+   ELSE IF (field(1)%ndim==3) THEN
+     n=0
+     DO ind=1,ndomain
+       d=>domain(ind)
+        
+       DO j=jj_begin+1,jj_end
+         DO i=ii_begin,ii_end-1
+           n=n+1
+           ij=iim*(j-1)+i
+           Field_tmp(n,:)=field(ind)%rval3d(ij+z_down,:)
+         ENDDO
+       ENDDO
+
+       DO j=jj_begin,jj_end-1
+         DO i=ii_begin+1,ii_end
+           n=n+1
+           ij=iim*(j-1)+i
+           Field_tmp(n,:)=field(ind)%rval3d(ij+z_up,:)
+          ENDDO
+       ENDDO
+          
+     ENDDO
+
+   ELSE IF (field(1)%ndim==4) THEN
+     n=0
+     DO ind=1,ndomain
+       d=>domain(ind)
+        
+       DO j=jj_begin+1,jj_end
+         DO i=ii_begin,ii_end-1
+           n=n+1
+           ij=iim*(j-1)+i
+           Field_tmp(n,:)=field(ind)%rval4d(ij+z_down,:,iq)
+         ENDDO
+       ENDDO
+
+       DO j=jj_begin,jj_end-1
+         DO i=ii_begin+1,ii_end
+           n=n+1
+           ij=iim*(j-1)+i
+           Field_tmp(n,:)=field(ind)%rval4d(ij+z_up,:,iq)
+          ENDDO
+       ENDDO
+          
+     ENDDO
+
+   ENDIF
+   
+   CALL xios_send_field(name,field_tmp)
+ 
+ END SUBROUTINE xios_write_field_vort 
+  
+ SUBROUTINE xios_write_field_finalize
+ IMPLICIT NONE
+   CALL xios_context_finalize
+ END SUBROUTINE xios_write_field_finalize
+   
+#else
+  
+  SUBROUTINE xios_init
+   IMPLICIT NONE
+         
+    using_xios=.FALSE.
+    
+  END SUBROUTINE xios_init
+  
+  SUBROUTINE xios_write_field(name,field)
+  USE field_mod
+  IMPLICIT NONE 
+   CHARACTER(LEN=*),INTENT(IN) :: name
+   TYPE(t_field), POINTER :: field(:)
+  END SUBROUTINE xios_write_field
+ 
+  SUBROUTINE xios_update_calendar(step)
+  IMPLICIT NONE
+   INTEGER, INTENT(IN):: step  
+  END SUBROUTINE xios_update_calendar
+
+  SUBROUTINE xios_write_field_finalize
+  END SUBROUTINE xios_write_field_finalize
+  
+  SUBROUTINE xios_init_write_field
+  END SUBROUTINE xios_init_write_field  
+#endif  
+  
+END MODULE xios_mod
