Index: XIOS/trunk/src/node/domain.cpp
===================================================================
--- XIOS/trunk/src/node/domain.cpp	(revision 383)
+++ XIOS/trunk/src/node/domain.cpp	(revision 384)
@@ -412,7 +412,30 @@
    void CDomain::completeLonLatClient(void)
    {
-      CArray<double,1> lonvalue_temp ;
-      CArray<double,1> latvalue_temp ;
-      
+      int i,j,k ;
+      CArray<double,1> lonvalue_temp(ni*nj) ;
+      CArray<double,1> latvalue_temp(ni*nj) ;
+      
+      if ( lonvalue.numElements() == ni*nj && latvalue.numElements() == ni*nj ) isCurvilinear=true ;
+      else if ( lonvalue.numElements() == ni && latvalue.numElements() == nj ) isCurvilinear=false ;
+      else ERROR("void CDomain::completeLonLatClient(void)",<<"the grid is nor curvilinear, nor cartesian, because the size of longitude and latitude array is not coherent with the domain size"<<endl
+                                                            <<"lonvalue size = " << lonvalue.numElements() << "different of ni or ni*nj"<<endl
+                                                            <<"latvalue size = " << latvalue.numElements() << "different of nj or ni*nj" ) ;
+      if (isCurvilinear)
+      {
+        lonvalue_temp=lonvalue ;
+        latvalue_temp=latvalue ;
+      }
+      else
+      {
+        for(j=0;j<nj;j++)
+          for(i=0;i<ni;i++) 
+          {
+            k=j*ni+i ;
+            lonvalue_temp(k)=lonvalue(i) ;
+            latvalue_temp(k)=latvalue(j) ;
+          }
+      }
+         
+        
       const int zoom_ibegin_client  = zoom_ibegin_loc.getValue(),
                 zoom_jbegin_client  = zoom_jbegin_loc.getValue(),
@@ -420,41 +443,17 @@
                 zoom_nj_client      = zoom_nj_loc.getValue();
                 
-      if (this->data_dim.getValue() == 2)
-      {
-         StdSize dm = zoom_ni_client * zoom_nj_client;
-
-         lonvalue_temp.resize(dm);
-         latvalue_temp.resize(dm);
-         
-         for (int i = 0; i < zoom_ni_client; i++)
-         {
-            for (int j = 0; j < zoom_nj_client; j++)
-            {
-               lonvalue_temp(i + j * zoom_ni_client) = lonvalue( (i + zoom_ibegin_client -1) + (j + zoom_jbegin_client -1)*ni.getValue() ); 
-               latvalue_temp(i + j * zoom_ni_client) = latvalue( (i + zoom_ibegin_client -1)+(j + zoom_jbegin_client -1)*ni.getValue() );
-            }
-         }
-         lonvalue.reference(lonvalue_temp.copy()) ;
-         latvalue.reference(latvalue_temp.copy()) ;
-      }
-      else
-      {
-         lonvalue_temp.resize(zoom_ni_client);
-         latvalue_temp.resize(zoom_nj_client);
-
-// Attention ici Ã  revoir, probablement faux         
-         for (int i = zoom_ibegin_client - 1; i < (zoom_ni_client - zoom_ibegin_client + 1); i++)
-         {
-            lonvalue_temp(i) = lonvalue(i); 
-         }
-         
-         for (int j = zoom_jbegin_client - 1; j < (zoom_nj_client - zoom_jbegin_client + 1); j++)
-         {
-            latvalue_temp(j) = latvalue(j);
-         }
-         
-         lonvalue.reference(lonvalue_temp.copy()) ;
-         latvalue.reference(latvalue_temp.copy()) ;
-      }  
+      StdSize dm = zoom_ni_client * zoom_nj_client;
+
+      lonvalue.resize(dm);
+      latvalue.resize(dm);
+         
+      for (int i = 0; i < zoom_ni_client; i++)
+      {
+        for (int j = 0; j < zoom_nj_client; j++)
+        {
+          lonvalue(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client -1) + (j + zoom_jbegin_client -1)*ni.getValue() ); 
+          latvalue(i + j * zoom_ni_client) = latvalue_temp( (i + zoom_ibegin_client -1)+(j + zoom_jbegin_client -1)*ni.getValue() );
+        }
+      }
    }
  
@@ -539,9 +538,9 @@
           !this->zoom_ibegin.isEmpty() || !this->zoom_jbegin.isEmpty())
       {
-         if (this->zoom_ni.isEmpty()     && this->zoom_nj.isEmpty() &&
-             this->zoom_ibegin.isEmpty() && this->zoom_jbegin.isEmpty())
+         if (this->zoom_ni.isEmpty()     || this->zoom_nj.isEmpty() ||
+             this->zoom_ibegin.isEmpty() || this->zoom_jbegin.isEmpty())
          {
             ERROR("CDomain::checkZoom(void)",
-                  <<"Les attributs dÃ©finissant un zoom doivent tous Ãªtre dÃ©finis") ;
+                  <<"if one of zoom attributes is defined then all zoom attributes must be defined") ;
          }
          else
@@ -870,5 +869,5 @@
       list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ;
 
-      *list_msg.back()<<this->getId() ;
+      *list_msg.back()<<this->getId()<<isCurvilinear ;
       *list_msg.back()<<*list_indi.back()<<*list_indj.back()<<*list_lon.back()<<*list_lat.back() ;
       event.push(connectedServer[ns],nbSenders[ns],*list_msg.back()) ;
@@ -961,5 +960,7 @@
     CArray<double,1> lat ;
      
-    buffer>>indi>>indj>>lon>>lat ;
+    buffer>>isCurvilinear>>indi>>indj>>lon>>lat ;
+    if (isCurvilinear) cout<<"Grid Curvilinear"<<endl ;
+    else cout<<"Grid Cartesian"<<endl ;
     int i,j,ind_srv ;
 
Index: XIOS/trunk/src/node/domain.hpp
===================================================================
--- XIOS/trunk/src/node/domain.hpp	(revision 383)
+++ XIOS/trunk/src/node/domain.hpp	(revision 384)
@@ -145,5 +145,5 @@
 
          CArray<int, 2> local_mask;
-
+         bool isCurvilinear ;
        private :
 
Index: XIOS/trunk/src/output/nc4_data_output.cpp
===================================================================
--- XIOS/trunk/src/output/nc4_data_output.cpp	(revision 383)
+++ XIOS/trunk/src/output/nc4_data_output.cpp	(revision 384)
@@ -80,5 +80,5 @@
                              : latid;
 
-         bool isCurvilinear = true ; //for moment
+         bool isCurvilinear = domain->isCurvilinear ;
 
          switch (SuperClass::type)
@@ -152,7 +152,18 @@
 
                SuperClassWriter::definition_end();
-               SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0);
-               SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0);
+               if (isCurvilinear)
+               {
+ 
+                 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0);
+                 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0);
 // supress mask               if (server->intraCommSize > 1) SuperClassWriter::writeData(mask, maskid);
+               }
+               else
+               {
+                  CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ;
+                  SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0);
+                  CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ;
+                  SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0);
+               }
                SuperClassWriter::definition_start();
 
@@ -187,21 +198,46 @@
 
                SuperClassWriter::definition_end();
-               std::vector<StdSize> start(2) ; 
-               std::vector<StdSize> count(2) ;
-               if (domain->isEmpty())
-               {
-                 start[0]=0 ; start [1]=0 ; 
-                 count[0]=0 ; count[1]=0 ; 
+               if (isCurvilinear)
+               {
+                 std::vector<StdSize> start(2) ; 
+                 std::vector<StdSize> count(2) ;
+                 if (domain->isEmpty())
+                 {
+                   start[0]=0 ; start [1]=0 ; 
+                   count[0]=0 ; count[1]=0 ; 
+                 }
+                 else
+                 {
+                   start[1]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start [0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 
+                   count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ; 
+                 }
+                 
+                 SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count);
+                 SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count);
                }
                else
                {
-                 start[1]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; start [0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 
-                 count[1]=domain->zoom_ni_srv ; count[0]=domain->zoom_nj_srv ; 
-               }
-               
-               SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count);
-               SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count);
+                 std::vector<StdSize> start(1) ; 
+                 std::vector<StdSize> count(1) ;
+                 if (domain->isEmpty())
+                 {
+                   start[0]=0 ;  
+                   count[0]=0 ;  
+                   SuperClassWriter::writeData(domain->latvalue_srv, latid, isCollective, 0,&start,&count);
+                   SuperClassWriter::writeData(domain->lonvalue_srv, lonid, isCollective, 0,&start,&count);                 }
+                 else
+                 {
+                   start[0]=domain->zoom_jbegin_srv-domain->zoom_jbegin.getValue() ; 
+                   count[0]=domain->zoom_nj_srv ; 
+                   CArray<double,1> lat = domain->latvalue_srv(Range(fromStart,toEnd,domain->zoom_ni_srv)) ;
+                   SuperClassWriter::writeData(CArray<double,1>(lat.copy()), latid, isCollective, 0,&start,&count);
+
+                   start[0]=domain->zoom_ibegin_srv-domain->zoom_ibegin.getValue() ; 
+                   count[0]=domain->zoom_ni_srv ; 
+                   CArray<double,1> lon=domain->lonvalue_srv(Range(0,domain->zoom_ni_srv-1)) ;
+                   SuperClassWriter::writeData(CArray<double,1>(lon.copy()), lonid, isCollective, 0,&start,&count);
+                 }
+               }
                SuperClassWriter::definition_start();
-
                break;
             }           
@@ -301,5 +337,5 @@
 //         unsigned int ssize = domain->zoom_ni_loc.getValue() * domain->zoom_nj_loc.getValue();
 //         bool isCurvilinear = (domain->lonvalue.getValue()->size() == ssize);
-          bool isCurvilinear = true ; // for moment 
+          bool isCurvilinear = domain->isCurvilinear ; 
           
          nc_type type = (!field->prec.isEmpty() &&
@@ -492,4 +528,5 @@
             CAxis* axis = grid->axis ;
             CArray<double,3> field_data3D(domain->zoom_ni_srv,domain->zoom_nj_srv,axis->zoom_size) ;
+            if (!field->default_value.isEmpty()) field_data3D = field->default_value ;
             field->outputField(field_data3D);
             switch (SuperClass::type)
@@ -526,4 +563,5 @@
          {
             CArray<double,2> field_data2D(domain->zoom_ni_srv,domain->zoom_nj_srv) ;
+            if (!field->default_value.isEmpty()) field_data2D = field->default_value ;
             field->outputField(field_data2D);
             switch (SuperClass::type)
Index: XIOS/trunk/src/test/test_cs.f90
===================================================================
--- XIOS/trunk/src/test/test_cs.f90	(revision 383)
+++ XIOS/trunk/src/test/test_cs.f90	(revision 384)
@@ -10,6 +10,6 @@
   CALL MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierr)
   
-  IF (rank<7) THEN
-   CALL client("client",rank,7)
+  IF (rank<11) THEN
+   CALL client("client",rank,11)
   ELSE 
     CALL server
@@ -43,7 +43,9 @@
   DOUBLE PRECISION,DIMENSION(ni_glo,nj_glo) :: lon_glo,lat_glo
   DOUBLE PRECISION :: field_A_glo(ni_glo,nj_glo,llm)
-  DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),field_A(:,:,:), lonvalue(:) ;
-  INTEGER :: ni,ibegin,iend,nj,jbegin,jend
-  INTEGER :: i,j,l,ts,n
+  DOUBLE PRECISION,ALLOCATABLE :: lon(:),lat(:),field_A(:,:), lonvalue(:) ;
+  LOGICAL,ALLOCATABLE :: mask(:,:)
+  INTEGER :: ni,ibegin,iend,nj,jbegin,jend,data_ibegin,data_ni
+  INTEGER :: i,j,k,l,ts,n,nij_begin
+  
   
   CALL init_wait
@@ -61,18 +63,36 @@
   ni=ni_glo ; ibegin=1
 
-  jbegin=1
+  
+  nij_begin=1
   DO n=0,size-1
-    nj=nj_glo/size
-    IF (n<MOD(nj_glo,size)) nj=nj+1
-    IF (n==rank) exit 
-    jbegin=jbegin+nj
+    data_ni=(ni_glo*nj_glo)/size
+    IF (n < MOD (ni_glo*nj_glo,size)) data_ni=data_ni+1
+    IF (n==rank) THEN
+      ibegin=1 ; iend=ni_glo ; ni=iend-ibegin+1
+      jbegin=(nij_begin-1)/ni_glo +1 
+      jend=MOD(nij_begin-1 + data_ni-1,ni_glo) +1
+      nj = jend-jbegin+1
+      data_ibegin=MOD(nij_begin-1,ni_glo)
+      exit
+    ELSE
+      nij_begin=nij_begin+data_ni
+    ENDIF
   ENDDO
   
-  iend=ibegin+ni-1 ; jend=jbegin+nj-1
 
-  ALLOCATE(lon(ni,nj),lat(ni,nj),field_A(0:ni+1,-1:nj+2,llm),lonvalue(ni*nj))
-  lon(:,:)=lon_glo(ibegin:iend,jbegin:jend)
-  lat(:,:)=lat_glo(ibegin:iend,jbegin:jend)
-  field_A(1:ni,1:nj,:)=field_A_glo(ibegin:iend,jbegin:jend,:)
+  ALLOCATE(lon(ni),lat(nj),field_A(data_ni,llm),lonvalue(ni*nj))
+  ALLOCATE(mask(ni,nj))
+  lon(:)=lon_glo(ibegin:iend,1)
+  lat(:)=lat_glo(1,jbegin:jend)
+
+  DO k=1,data_ni
+    n=k-1+(jbegin-1)*ni_glo+data_ibegin
+    i=MOD(n,ni_glo)+1
+    j=n/ni_glo+1
+    field_A(k,:)=field_A_glo(i,j,:)
+  ENDDO
+  
+  mask(:,:)=.TRUE.
+  mask(1:ni,6)=.TRUE.
   
 
@@ -89,8 +109,9 @@
   CALL xios_set_context_attr("test",calendar_type="Gregorian") 
   CALL xios_set_axis_attr("axis_A",size=llm ,value=lval) ;
-  CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj)
-!  CALL xios_set_domain_attr("domain_A",zoom_ni=10,zoom_ibegin=5,zoom_nj=20,zoom_jbegin=10)
-  CALL xios_set_domain_attr("domain_A",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
-  CALL xios_set_domain_attr("domain_A",lonvalue=RESHAPE(lon,(/ni*nj/)),latvalue=RESHAPE(lat,(/ni*nj/)))
+  CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, iend=iend,jbegin=jbegin,jend=jend)
+!  CALL xios_set_domain_attr("domain_A",zoom_ni=10,zoom_ibegin=5,zoom_nj=nj_glo,zoom_jbegin=1)
+  CALL xios_set_domain_attr("domain_A",data_dim=1, data_ibegin=data_ibegin, data_ni=data_ni)
+  CALL xios_set_domain_attr("domain_A",lonvalue=lon,latvalue=lat)
+!  CALL xios_set_domain_attr("domain_A",mask=mask)
   CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.)
   
@@ -107,9 +128,9 @@
     CALL xios_set_timestep(dtime) 
     
-    ni=0 ; lonvalue(:)=0
-    CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue=lonvalue)
+!    ni=0 ; lonvalue(:)=0
+!    CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue=lonvalue)
     
-    print *,"ni",ni
-    print *,"lonvalue",lonvalue ;
+!    print *,"ni",ni
+!    print *,"lonvalue",lonvalue ;
 
     CALL xios_close_context_definition()
