Index: /XIOS/trunk/inputs/REMAP/iodef.xml
===================================================================
--- /XIOS/trunk/inputs/REMAP/iodef.xml	(revision 1063)
+++ /XIOS/trunk/inputs/REMAP/iodef.xml	(revision 1064)
@@ -5,16 +5,16 @@
    <calendar type="Gregorian" start_date="2012-03-01 15:00:00" time_origin="2012-02-28 15:00:00 + 1d" />
    <field_definition level="1" >
-    <field_group id="fields_src" operation="instant">
+    <field_group id="fields_src" operation="instant" default_value="100000">
        <field id="src_field_2D" domain_ref="src_domain" />
-       <field id="src_field_2D_clone" domain_ref="src_domain_clone"/>
+       <field id="src_field_2D_clone" domain_ref="src_domain_clone" detect_missing_value=".TRUE." />
        <field id="src_field_3D" domain_ref="src_domain" axis_ref="src_axis"  />
-       <field id="src_field_3D_clone" grid_ref="src_grid_3D" detect_missing_value=".TRUE." default_value="100000" />       
+       <field id="src_field_3D_clone" grid_ref="src_grid_3D" detect_missing_value=".TRUE."  />       
        <field id="src_field_3D_pression" grid_ref="src_grid_3D"  />
-       <field id="src_field_4D" grid_ref="src_grid_4D" detect_missing_value=".TRUE." default_value="100000"/>       
+       <field id="src_field_4D" grid_ref="src_grid_4D" detect_missing_value=".TRUE." />       
     </field_group>
     <field_group  id="fields_dst">
       <field id="dst_field_2D" field_ref="src_field_2D" domain_ref="dst_domain"/>
       <field id="dst_field_2D_regular_pole" field_ref="src_field_2D" domain_ref="dst_domain_regular_pole"/>
-      <field id="dst_field_2D_clone" field_ref="src_field_2D_clone" domain_ref="dst_domain"/>
+      <field id="dst_field_2D_clone" field_ref="src_field_2D_clone" domain_ref="dst_domain_regular_pole"  expr="@this" operation="average" detect_missing_value=".true."/>
       <field id="dst_field_2D_extract" field_ref="src_field_3D_clone" grid_ref="dst_grid_2D_extract"/>
       <field id="dst_field_3D" field_ref="src_field_3D" grid_ref="dst_grid_3D"/>
@@ -23,11 +23,11 @@
     </field_group>
     <field_group id="read_fields" operation="instant">
-<!--       <field id="tmp_field_0" domain_ref="src_domain_regular_read"/>
-      <field id="tmp_field_clone" field_ref="tmp_field_0"/>
+      <field id="tmp_field_0" domain_ref="src_domain_regular_read"/>      
       <field id="tmp_field_1" grid_ref="src_grid_curvilinear_read" />
       <field id="tmp_field_2" grid_ref="src_grid_unstructured_read" />
+      <field id="tmp_field_clone" field_ref="tmp_field_0"/>
       <field id="dst_field_regular" field_ref="tmp_field_2" grid_ref="dst_grid_regular"/>      
       <field id="dst_field_regular_pole_0" field_ref="tmp_field_0" domain_ref="dst_domain_regular_pole"/>
-      <field id="dst_field_regular_pole_1" field_ref="tmp_field_clone" domain_ref="dst_domain_regular_pole"/> -->
+      <field id="dst_field_regular_pole_1" field_ref="tmp_field_clone" domain_ref="dst_domain_regular_pole"/>
     </field_group> 
    </field_definition>
@@ -37,4 +37,5 @@
         <file id="output_2D" name="output_2D" >
           <field field_ref="src_field_2D" name="field_src" />
+          <field field_ref="src_field_2D_clone" name="field_src_clone" />
           <field field_ref="src_field_2D" name="field_dst_regular_0"  domain_ref="dst_domain_regular_pole" />
           <field field_ref="dst_field_2D" name="field_dst_regular_1" />
@@ -49,5 +50,5 @@
           <field field_ref="dst_field_3D_interp" name="field_dst_interp_domain_axis" domain_ref="dst_domain_regular_pole"/>  
        </file>
-       <file id="output_4D" name="output_4D" enabled=".FALSE.">
+       <file id="output_4D" name="output_4D" enabled=".TRUE.">
           <field field_ref="src_field_4D" name="field_4D" />
           <field field_ref="dst_field_4D_extract" name="field_4D_extract" />
@@ -55,5 +56,5 @@
      </file_group>
      <file_group id="read_files" >
-<!--        <file id="output_src_regular" name="output_src_regular" mode="read" >
+       <file id="output_src_regular" name="output_src_regular" mode="read" >
           <field id="src_field_regular" name="field" grid_ref="src_grid_regular_read" operation="instant"/>
        </file>
@@ -63,8 +64,9 @@
        <file id="output_src_unstructured" name="output_src_unstructured" mode="read" >
           <field id="src_field_unstructured" name="field" grid_ref="src_grid_unstructured_read" operation="instant"/>
-       </file> -->
+       </file>
       </file_group>
-     <file_group id="read_then_write_files" enabled=".FALSE.">
-<!--        <file id="output_regular_pole" name="output_dst_regular" >
+     <file_group id="read_then_write_files" enabled=".TRUE.">
+       <file id="output_regular_pole" name="output_dst_regular" >
+          <field field_ref="tmp_field_0" name="field_regular_0" />
           <field field_ref="dst_field_regular" name="field_regular" />
           <field field_ref="dst_field_regular_pole_0" name="field_regular_pole_0" />
@@ -76,5 +78,5 @@
        <file id="output_dst_unstructured" name="output_dst_unstructured" >
           <field field_ref="tmp_field_2" operation="instant"/>
-       </file> -->
+       </file>
      </file_group>
    </file_definition>
@@ -94,5 +96,5 @@
       <axis id="src_axis" positive="down" />
       <axis id="nq" positive="down" />
-      <axis id="src_axis_curvilinear_read" />
+      <axis id="src_axis_curvilinear_read" positive="down" />
     </axis_group>
     <axis_group id="axis_dst">
@@ -113,4 +115,5 @@
       </domain>
       <domain id="src_domain_unstructured_read" type="unstructured">
+        <generate_rectilinear_domain/>
       </domain>
     </domain_group>
@@ -126,5 +129,5 @@
      <domain id="dst_domain_regular_pole" ni_glo="90" nj_glo="45" type="rectilinear">
        <generate_rectilinear_domain id="domain_regular_pole"/>
-       <interpolate_domain write_weight="false"/>       
+       <interpolate_domain write_weight="false" order="1" renormalize="true"/>       
        <!-- <zoom_domain ibegin="0" ni="45" jbegin="0" nj="45" /> -->
      </domain>
Index: /XIOS/trunk/src/config/domain_attribute_private.conf
===================================================================
--- /XIOS/trunk/src/config/domain_attribute_private.conf	(revision 1063)
+++ /XIOS/trunk/src/config/domain_attribute_private.conf	(revision 1064)
@@ -10,7 +10,19 @@
 DECLARE_ATTRIBUTE_PRIVATE(double,  bounds_lat_end)
 
-// Array contain whole value (non distributed) of longitude and latitude read from a file
+// Array contain whole value (non distributed) of longitude and latitude of rectilinear read from a file
 DECLARE_ARRAY_PRIVATE(double, 1, lonvalue_rectilinear_read_from_file)
 DECLARE_ARRAY_PRIVATE(double, 1, latvalue_rectilinear_read_from_file)
+
+// Array contain whole value (non distributed) of longitude and latitude of curvilinear read from a file
+DECLARE_ARRAY_PRIVATE(double, 2, lonvalue_curvilinear_read_from_file)
+DECLARE_ARRAY_PRIVATE(double, 2, latvalue_curvilinear_read_from_file)
+DECLARE_ARRAY_PRIVATE(double, 3, bounds_lonvalue_curvilinear_read_from_file)
+DECLARE_ARRAY_PRIVATE(double, 3, bounds_latvalue_curvilinear_read_from_file)
+
+// Array contain whole value (non distributed) of longitude and latitude of unstructured read from a file
+DECLARE_ARRAY_PRIVATE(double, 1, lonvalue_unstructured_read_from_file)
+DECLARE_ARRAY_PRIVATE(double, 1, latvalue_unstructured_read_from_file)
+DECLARE_ARRAY_PRIVATE(double, 2, bounds_lonvalue_unstructured_read_from_file)
+DECLARE_ARRAY_PRIVATE(double, 2, bounds_latvalue_unstructured_read_from_file)
 
 DECLARE_ATTRIBUTE_PRIVATE(int,  global_zoom_ibegin)
Index: /XIOS/trunk/src/io/nc4_data_input.cpp
===================================================================
--- /XIOS/trunk/src/io/nc4_data_input.cpp	(revision 1063)
+++ /XIOS/trunk/src/io/nc4_data_input.cpp	(revision 1064)
@@ -262,5 +262,5 @@
     itMapNj = itMapNi; ++itMapNj;
 
-    if ((CDomain::type_attr::rectilinear == domain->type))// || this->isRectilinear(fieldId))
+    if ((CDomain::type_attr::rectilinear == domain->type))
     {
       // Ok, try to read some f.. attributes such as longitude and latitude
@@ -279,26 +279,25 @@
         std::vector<StdSize> nBeginLon(1, 0), nSizeLon(1, itMapNi->second);
         readFieldVariableValue(domain->lonvalue_rectilinear_read_from_file, itMapNi->first, nBeginLon, nSizeLon, true);
-      }
-      domain->fillInRectilinearLonLat();
-    }
-    else if ((CDomain::type_attr::curvilinear == domain->type))// || (this->isCurvilinear(fieldId)))
+      }      
+    }
+    else if ((CDomain::type_attr::curvilinear == domain->type))
     {
       int ni = domain->ni;
       int nj = domain->nj;
       std::vector<StdSize> nBeginLatLon(2), nSizeLatLon(2);
-      nBeginLatLon[0] = domain->jbegin.getValue(); nBeginLatLon[1] = domain->ibegin.getValue();
-      nSizeLatLon[0]  = nj; nSizeLatLon[1] = ni;
+      nBeginLatLon[0] = 0; nBeginLatLon[1] = 0;
+      nSizeLatLon[0]  = domain->nj_glo.getValue(); nSizeLatLon[1] = domain->ni_glo.getValue();
 
       StdString latName = this->getLatCoordName(fieldId);
-      if (SuperClassWriter::hasVariable(latName)) //(0 != latName.compare(""))
-      {
-        domain->latvalue_2d.resize(ni,nj);
-        readFieldVariableValue(domain->latvalue_2d, latName, nBeginLatLon, nSizeLatLon);
+      if (SuperClassWriter::hasVariable(latName))
+      {
+        domain->latvalue_curvilinear_read_from_file.resize(domain->ni_glo,domain->nj_glo);
+        readFieldVariableValue(domain->latvalue_curvilinear_read_from_file, latName, nBeginLatLon, nSizeLatLon);
       }
       StdString lonName = this->getLonCoordName(fieldId);
-      if (SuperClassWriter::hasVariable(lonName)) //(0 != lonName.compare(""))
-      {
-        domain->lonvalue_2d.resize(ni,nj);
-        readFieldVariableValue(domain->lonvalue_2d, lonName, nBeginLatLon, nSizeLatLon);
+      if (SuperClassWriter::hasVariable(lonName))
+      {
+        domain->lonvalue_curvilinear_read_from_file.resize(domain->ni_glo,domain->nj_glo);
+        readFieldVariableValue(domain->lonvalue_curvilinear_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
       }
 
@@ -307,44 +306,36 @@
 
       int nbVertex = this->getNbVertex(fieldId);
-      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) //if ((0 != boundsLatName.compare("")) || (0 != boundsLonName.compare("")))
+      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
+      {
+        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
+          << "The domain " << domain->getDomainOutputName()
+          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
+          << " are not coherent. They should be the same." << std::endl 
+          << " nvertex read from file: "<< nbVertex
+          << " nvertex from model: "<< domain->nvertex << std::endl);
+      } 
+
+      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
         domain->nvertex.setValue(nbVertex);
+
       std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3);
-      nBeginBndsLatLon[0] = domain->jbegin.getValue(); nSizeBndsLatLon[0] = nj;
-      nBeginBndsLatLon[1] = domain->ibegin.getValue(); nSizeBndsLatLon[1] = ni;
+      nBeginBndsLatLon[0] = 0; nSizeBndsLatLon[0] = domain->nj_glo.getValue();
+      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = domain->nj_glo.getValue();
       nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex;
 
-      if (SuperClassWriter::hasVariable(boundsLatName)) //(0 != boundsLatName.compare(""))
-      {
-        domain->bounds_lat_2d.resize(nbVertex,ni,nj);
-        readFieldVariableValue(domain->bounds_lat_2d, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
-
-      }
-      if (SuperClassWriter::hasVariable(boundsLonName)) //(0 != boundsLonName.compare(""))
-      {
-        domain->bounds_lon_2d.resize(nbVertex,ni,nj);
-        readFieldVariableValue(domain->bounds_lon_2d, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
-      }
+      if (SuperClassWriter::hasVariable(boundsLatName))
+      {
+        domain->bounds_latvalue_curvilinear_read_from_file.resize(nbVertex,domain->ni_glo,domain->nj_glo);
+        readFieldVariableValue(domain->bounds_latvalue_curvilinear_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
+
+      }
+      if (SuperClassWriter::hasVariable(boundsLonName)) 
+      {
+        domain->bounds_lonvalue_curvilinear_read_from_file.resize(nbVertex,domain->ni_glo,domain->nj_glo);
+        readFieldVariableValue(domain->bounds_lonvalue_curvilinear_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
+      }      
     }
     else if ((CDomain::type_attr::unstructured == domain->type))// || (this->isUnstructured(fieldId)))
     {
-      /*
-      if (domain->i_index.isEmpty())
-         ERROR("CNc4DataInput::readDomainAttributeValueFromFile(...)",
-              << "Field '" << fieldId << std::endl
-              << "Trying to read attributes from unstructured grid."
-              << "i_index of domain" << domain->getId() << " is mandatory");
-
-      int ni = domain->i_index.numElements();
-*/
-
-      int ni     = domain->ni.isEmpty() ? 0 : domain->ni;
-      int ibegin = domain->ibegin.isEmpty() ? 0 : domain->ibegin;
-
-      if (domain->i_index.isEmpty() && (!domain->ni.isEmpty()) )
-      {
-        domain->i_index.resize(ni) ;
-        for(int idx = 0; idx < ni; ++idx) domain->i_index(idx)=ibegin+idx ;
-      }
-
       std::vector<StdSize> nBeginLatLon(1,0), nSizeLatLon(1,0);
       nSizeLatLon[0]  = domain->ni_glo.getValue();
@@ -352,10 +343,8 @@
 
       StdString latName = this->getLatCoordName(fieldId);
-      if (SuperClassWriter::hasVariable(latName)) //(0 != latName.compare(""))
-      {
-        readFieldVariableValue(globalLonLat, latName, nBeginLatLon, nSizeLatLon);
-        domain->latvalue_1d.resize(ni);
-        for (int idx = 0; idx < ni; ++idx)
-          domain->latvalue_1d(idx) =  globalLonLat(domain->i_index(idx));
+      if (SuperClassWriter::hasVariable(latName))
+      {
+        domain->latvalue_unstructured_read_from_file.resize(domain->ni_glo);
+        readFieldVariableValue(domain->latvalue_unstructured_read_from_file, latName, nBeginLatLon, nSizeLatLon);  
       }
 
@@ -363,8 +352,7 @@
       if (SuperClassWriter::hasVariable(lonName)) //(0 != lonName.compare(""))
       {
-        readFieldVariableValue(globalLonLat, lonName, nBeginLatLon, nSizeLatLon);
-        domain->lonvalue_1d.resize(ni);
-        for (int idx = 0; idx < ni; ++idx)
-          domain->lonvalue_1d(idx) = globalLonLat(domain->i_index(idx));
+        // readFieldVariableValue(globalLonLat, lonName, nBeginLatLon, nSizeLatLon);
+        domain->lonvalue_unstructured_read_from_file.resize(domain->ni_glo);
+        readFieldVariableValue(domain->lonvalue_unstructured_read_from_file, lonName, nBeginLatLon, nSizeLatLon);
       }
 
@@ -373,5 +361,15 @@
 
       int nbVertex = this->getNbVertex(fieldId);
-      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) // (0 != boundsLatName.compare("")) || (0 != boundsLonName.compare("")))
+      if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex))
+      {
+        ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)",
+          << "The domain " << domain->getDomainOutputName()
+          << " has nvertex read from file " << this->filename << " and nvertex provided from model"
+          << " are not coherent. They should be the same." << std::endl 
+          << " nvertex read from file: "<< nbVertex
+          << " nvertex from model: "<< domain->nvertex << std::endl);
+      } 
+      
+      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) 
         domain->nvertex.setValue(nbVertex);
 
@@ -380,24 +378,17 @@
       nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = nbVertex;
 
-      if (SuperClassWriter::hasVariable(boundsLatName)) //(0 != boundsLatName.compare(""))
-      {
-        CArray<double,2> globalBndsLonLat(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
-        readFieldVariableValue(globalBndsLonLat, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
-        domain->bounds_lat_1d.resize(nbVertex,ni);
-        for (int idx = 0; idx < ni; ++idx)
-          for (int jdx = 0; jdx < nbVertex; ++jdx)
-            domain->bounds_lat_1d(jdx,idx) = globalBndsLonLat(jdx, domain->i_index(idx));
-      }
-
-      if (SuperClassWriter::hasVariable(boundsLonName)) //(0 != boundsLonName.compare(""))
-      {
-        CArray<double,2> globalBndsLonLat(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
-        readFieldVariableValue(globalBndsLonLat, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
-        domain->bounds_lon_1d.resize(nbVertex,ni);
-        for (int idx = 0; idx < ni; ++idx)
-          for (int jdx = 0; jdx < nbVertex; ++jdx)
-            domain->bounds_lon_1d(jdx,idx) = globalBndsLonLat(jdx, domain->i_index(idx));
-      }
-    }
+      if (SuperClassWriter::hasVariable(boundsLatName)) 
+      {
+        domain->bounds_latvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
+        readFieldVariableValue(domain->bounds_latvalue_unstructured_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon);
+      }
+
+      if (SuperClassWriter::hasVariable(boundsLonName)) 
+      {
+        domain->bounds_lonvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]);
+        readFieldVariableValue(domain->bounds_lonvalue_unstructured_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon);
+      }      
+    }
+    domain->fillInLonLat();
   }
 
@@ -421,5 +412,24 @@
     if (this->isRectilinear(fieldId) || this->isCurvilinear(fieldId))
     {
+      if (!domain->nj_glo.isEmpty() && (domain->nj_glo != itMapNj->second))
+      {
+        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
+          << "The domain " << domain->getDomainOutputName()
+          << " has nj_glo read from file " << this->filename << " and nj_glo provided from model"
+          << " are not coherent. They should be the same." << std::endl 
+          << " nj_glo read from file: "<< itMapNj->second
+          << " nj_glo from model: "<< domain->nj_glo << std::endl);
+      } 
       domain->nj_glo.setValue(itMapNj->second);
+
+      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
+      {
+        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
+          << "The domain " << domain->getDomainOutputName()
+          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
+          << " are not coherent. They should be the same." << std::endl 
+          << " ni_glo read from file: "<< itMapNi->second
+          << " ni_glo from model: "<< domain->ni_glo << std::endl);
+      } 
       domain->ni_glo.setValue(itMapNi->second);
     }
@@ -427,4 +437,14 @@
     {
       domain->nj_glo.setValue(1);
+
+      if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second))
+      {
+        ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)",
+          << "The domain " << domain->getDomainOutputName()
+          << " has ni_glo read from file " << this->filename << " and ni_glo provided from model"
+          << " are not coherent. They should be the same." << std::endl 
+          << " ni_glo read from file: "<< itMapNi->second
+          << " ni_glo from model: "<< domain->ni_glo << std::endl);
+      }       
       domain->ni_glo.setValue(itMapNi->second);
     }
@@ -444,4 +464,14 @@
                                                               iteMap = dimSizeMap.end();
     for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
+
+    if (!axis->n_glo.isEmpty() && (axis->n_glo != itMapN->second))
+    {
+      ERROR("void CNc4DataInput::readAxisAttributesFromFile(...)",
+        << "The axis " << axis->getAxisOutputName()
+        << " has n_glo read from file " << this->filename << " and n_glo provided from model"
+        << " are not coherent. They should be the same." << std::endl 
+        << " n_glo read from file: "<< itMapN->second
+        << " n_glo from model: "<< axis->n_glo << std::endl);
+    }    
     axis->n_glo.setValue(itMapN->second);
   }
@@ -483,8 +513,5 @@
                                                   int elementPosition, const StdString& fieldId)
   {
-//    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
-//                                                              iteMap = dimSizeMap.end();
-//    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
-//    axis->n_glo.setValue(itMapN->second);
+    /*Nothing to do */
   }
 
@@ -499,18 +526,5 @@
                                                       int elementPosition, const StdString& fieldId)
   {
-//    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(),
-//                                                              iteMap = dimSizeMap.end();
-//    for (int i = 0; i < elementPosition; ++i, ++itMapN) {}
-//
-//    { // Read axis value
-//      std::vector<StdSize> nBegin(1, 0), nSize(1, itMapN->second);
-//      CArray<double,1> readAxisValue(itMapN->second);
-//      readFieldVariableValue(readAxisValue, itMapN->first, nBegin, nSize, true);
-//      int begin = 0, n = itMapN->second;
-//      if (!axis->begin.isEmpty()) begin = axis->begin.getValue();
-//      if (!axis->n.isEmpty()) n = axis->n.getValue();
-//      axis->value.resize(n);
-//      for (int i = 0; i < n; ++i) axis->value(i) = readAxisValue(begin + i);
-//    }
+    /*Nothing to do */
   }
 
Index: /XIOS/trunk/src/node/domain.cpp
===================================================================
--- /XIOS/trunk/src/node/domain.cpp	(revision 1063)
+++ /XIOS/trunk/src/node/domain.cpp	(revision 1064)
@@ -225,4 +225,21 @@
 
    //----------------------------------------------------------------
+
+   /*!
+      Verify if all distribution information of a domain are available
+      This checking verifies the definition of distribution attributes (ni, nj, ibegin, jbegin)
+   */
+   bool CDomain::distributionAttributesHaveValue() const
+   {
+      bool hasValues = true;
+
+      if (ni.isEmpty() && ibegin.isEmpty() && i_index.isEmpty())
+      {
+        hasValues = false;
+        return hasValues;
+      }
+
+      return hasValues;
+   }
 
    /*!
@@ -333,8 +350,5 @@
             ni.setValue(ni_glo - ibeginVec[iIdx]);
           }
-        }
-
-        // Now fill other attributes
-        if (type_attr::rectilinear == type) fillInRectilinearLonLat();
+        } 
      }
      else  // unstructured domain
@@ -382,4 +396,7 @@
             nj.setValue(1);
           }
+
+          i_index.resize(ni);          
+          for(int idx = 0; idx < ni; ++idx) i_index(idx)=ibegin+idx;
         }
         else
@@ -393,4 +410,27 @@
 
      checkDomain();
+   }
+
+   /*!
+     Fill in longitude and latitude whose values are read from file
+   */
+   void CDomain::fillInLonLat()
+   {
+     switch (type)
+     {
+      case type_attr::rectilinear:
+        fillInRectilinearLonLat();
+        break;
+      case type_attr::curvilinear:
+        fillInCurvilinearLonLat();
+        break;
+      case type_attr::unstructured:
+        fillInUnstructuredLonLat();
+        break;
+
+      default:
+      break;
+     }
+
    }
 
@@ -470,6 +510,114 @@
    }
 
-
-
+    /*
+      Fill in longitude and latitude of curvilinear domain read from a file
+      If there are already longitude and latitude defined by model. We just igonore reading value.
+    */
+   void CDomain::fillInCurvilinearLonLat()
+   {
+     if (!lonvalue_curvilinear_read_from_file.isEmpty() && lonvalue_2d.isEmpty())
+     {
+       lonvalue_2d.resize(ni,nj);
+       for (int jdx = 0; jdx < nj; ++jdx)
+        for (int idx = 0; idx < ni; ++idx)
+         lonvalue_2d(idx,jdx) = lonvalue_curvilinear_read_from_file(idx+ibegin, jdx+jbegin);
+
+       lonvalue_curvilinear_read_from_file.free();
+     }
+
+     if (!latvalue_curvilinear_read_from_file.isEmpty() && latvalue_2d.isEmpty())
+     {
+       latvalue_2d.resize(ni,nj);
+       for (int jdx = 0; jdx < nj; ++jdx)
+        for (int idx = 0; idx < ni; ++idx)
+         latvalue_2d(idx,jdx) = latvalue_curvilinear_read_from_file(idx+ibegin, jdx+jbegin);
+
+       latvalue_curvilinear_read_from_file.free();
+     }
+
+     if (!bounds_lonvalue_curvilinear_read_from_file.isEmpty() && bounds_lon_2d.isEmpty())
+     {
+       bounds_lon_2d.resize(nvertex,ni,nj);
+       for (int jdx = 0; jdx < nj; ++jdx)
+        for (int idx = 0; idx < ni; ++idx)
+          for (int ndx = 0; ndx < nvertex; ++ndx)
+         bounds_lon_2d(ndx,idx,jdx) = bounds_lonvalue_curvilinear_read_from_file(ndx,idx+ibegin, jdx+jbegin);
+
+       bounds_lonvalue_curvilinear_read_from_file.free();
+     }
+
+     if (!bounds_latvalue_curvilinear_read_from_file.isEmpty() && bounds_lat_2d.isEmpty())
+     {
+       bounds_lat_2d.resize(nvertex,ni,nj);
+       for (int jdx = 0; jdx < nj; ++jdx)
+        for (int idx = 0; idx < ni; ++idx)
+          for (int ndx = 0; ndx < nvertex; ++ndx)
+            bounds_lat_2d(ndx,idx,jdx) = bounds_latvalue_curvilinear_read_from_file(ndx,idx+ibegin, jdx+jbegin);
+
+       bounds_latvalue_curvilinear_read_from_file.free();
+     }
+
+   }
+
+    /*
+      Fill in longitude and latitude of unstructured domain read from a file
+      If there are already longitude and latitude defined by model. We just igonore reading value.
+    */
+   void CDomain::fillInUnstructuredLonLat()
+   {
+     if (i_index.isEmpty())
+     {
+       i_index.resize(ni);
+       for(int idx = 0; idx < ni; ++idx) i_index(idx)=ibegin+idx;
+     }
+
+     if (!lonvalue_unstructured_read_from_file.isEmpty() && lonvalue_1d.isEmpty())
+     {
+        lonvalue_1d.resize(ni);
+        for (int idx = 0; idx < ni; ++idx)
+          lonvalue_1d(idx) = lonvalue_unstructured_read_from_file(i_index(idx));
+
+        // We dont need these values anymore, so just delete them
+        lonvalue_unstructured_read_from_file.free();
+     } 
+
+     if (!latvalue_unstructured_read_from_file.isEmpty() && latvalue_1d.isEmpty())
+     {
+        latvalue_1d.resize(ni);
+        for (int idx = 0; idx < ni; ++idx)
+          latvalue_1d(idx) =  latvalue_unstructured_read_from_file(i_index(idx));
+
+        // We dont need these values anymore, so just delete them
+        latvalue_unstructured_read_from_file.free();
+     }
+
+     if (!bounds_lonvalue_unstructured_read_from_file.isEmpty() && bounds_lon_1d.isEmpty())
+     {
+        int nbVertex = nvertex;
+        bounds_lon_1d.resize(nbVertex,ni);
+        for (int idx = 0; idx < ni; ++idx)
+          for (int jdx = 0; jdx < nbVertex; ++jdx)
+            bounds_lon_1d(jdx,idx) = bounds_lonvalue_unstructured_read_from_file(jdx, i_index(idx));
+
+        // We dont need these values anymore, so just delete them
+        lonvalue_unstructured_read_from_file.free();
+     }
+
+     if (!bounds_latvalue_unstructured_read_from_file.isEmpty() && bounds_lat_1d.isEmpty())
+     {
+        int nbVertex = nvertex;
+        bounds_lat_1d.resize(nbVertex,ni);
+        for (int idx = 0; idx < ni; ++idx)
+          for (int jdx = 0; jdx < nbVertex; ++jdx)
+            bounds_lat_1d(jdx,idx) = bounds_latvalue_unstructured_read_from_file(jdx, i_index(idx));
+
+        // We dont need these values anymore, so just delete them
+        lonvalue_unstructured_read_from_file.free();
+     }
+   }
+
+  /*
+    Get global longitude and latitude of rectilinear domain.
+  */
    void CDomain::AllgatherRectilinearLonLat(CArray<double,1>& lon, CArray<double,1>& lat, CArray<double,1>& lon_g, CArray<double,1>& lat_g)
    {
Index: /XIOS/trunk/src/node/domain.hpp
===================================================================
--- /XIOS/trunk/src/node/domain.hpp	(revision 1063)
+++ /XIOS/trunk/src/node/domain.hpp	(revision 1064)
@@ -103,4 +103,5 @@
          bool isDistributed(void) const;
          bool isCompressible(void) const;
+         bool distributionAttributesHaveValue() const;
 
          int ni_srv,ibegin_srv,iend_srv ;
@@ -136,5 +137,6 @@
          void fillInRectilinearBoundLonLat(CArray<double,1>& lon, CArray<double,1>& lat,
                                            CArray<double,2>& boundsLon, CArray<double,2>& boundsLat);
-         void fillInRectilinearLonLat();
+         
+         void fillInLonLat();
 
          static bool dispatchEvent(CEventServer& event);
@@ -189,4 +191,7 @@
          void sendLonLat();
 
+         void fillInRectilinearLonLat();
+         void fillInCurvilinearLonLat();
+         void fillInUnstructuredLonLat();
        private:
          bool isChecked;
Index: /XIOS/trunk/src/test/test_remap.f90
===================================================================
--- /XIOS/trunk/src/test/test_remap.f90	(revision 1063)
+++ /XIOS/trunk/src/test/test_remap.f90	(revision 1064)
@@ -16,9 +16,9 @@
   TYPE(xios_context) :: ctx_hdl
 
-  DOUBLE PRECISION,ALLOCATABLE :: src_lon(:), dst_lon(:)
-  DOUBLE PRECISION,ALLOCATABLE :: src_lat(:), dst_lat(:)
+  DOUBLE PRECISION,ALLOCATABLE :: src_lon(:), dst_lon(:), src_lon_tmp(:)
+  DOUBLE PRECISION,ALLOCATABLE :: src_lat(:), dst_lat(:), src_lat_tmp(:)
   DOUBLE PRECISION,ALLOCATABLE :: src_boundslon(:,:), dst_boundslon(:,:)
   DOUBLE PRECISION,ALLOCATABLE :: src_boundslat(:,:), dst_boundslat(:,:)
-  DOUBLE PRECISION,ALLOCATABLE :: src_field_2D(:)
+  DOUBLE PRECISION,ALLOCATABLE :: src_field_2D(:), src_field_2D_clone(:)
   DOUBLE PRECISION,ALLOCATABLE :: tmp_field_0(:), tmp_field_1(:), tmp_field_2(:)
   DOUBLE PRECISION,ALLOCATABLE :: src_field_3D(:,:), src_field_4D(:,:,:), lval(:), lval1(:), lval2(:), src_field_pression(:,:)
@@ -36,6 +36,7 @@
   INTEGER :: varid
   INTEGER :: ts
-  INTEGER :: i
+  INTEGER :: i,j
   INTEGER,PARAMETER :: llm=5, interpolatedLlm = 4, llm2 = 6
+  DOUBLE PRECISION, PARAMETER :: missing_value = 100000
 
   CALL MPI_INIT(ierr)
@@ -64,9 +65,9 @@
   ENDIF
 
-  ALLOCATE(src_lon(src_ni))
-  ALLOCATE(src_lat(src_ni))
+  ALLOCATE(src_lon(src_ni), src_lon_tmp(src_ni))
+  ALLOCATE(src_lat(src_ni), src_lat_tmp(src_ni))
   ALLOCATE(src_boundslon(src_nvertex,src_ni))
   ALLOCATE(src_boundslat(src_nvertex,src_ni))
-  ALLOCATE(src_field_2D(src_ni))
+  ALLOCATE(src_field_2D(src_ni), src_field_2D_clone(src_ni))
   ALLOCATE(src_field_3D(src_ni,llm))
   ALLOCATE(src_field_4D(src_ni,llm,llm2))
@@ -89,11 +90,14 @@
   DO i=1,src_ni
     src_field_3D(i,:) = src_field_2D(i)
-    IF (MOD(i,10)==0) THEN
+    IF ((23.5 < src_lat(i)) .AND. (src_lat(i) < 65.5) .AND. (0 < src_lon(i)) .AND. (src_lon(i) < 30)) THEN
       src_mask_2D(i)=.FALSE.
-      src_field_2D(i) = 100000
+      src_field_2D(i) = missing_value
     ELSE
       src_mask_2D(i)=.TRUE.      
     ENDIF
-  ENDDO
+    src_lon_tmp(i) = src_lon(i) + 1000
+    src_lat_tmp(i) = src_lat(i) + 10000
+  ENDDO
+  src_field_2D_clone = src_field_2D
 
   DO i=1,llm
@@ -101,6 +105,6 @@
     src_field_pression(:,i) = i * 100
     IF (MOD(i,3)==0) THEN
-      ! src_field_pression(:,i) = 100000
-      src_field_3D(:,i) = 100000
+      ! src_field_pression(:,i) = missing_value
+      src_field_3D(:,i) = missing_value
     ELSE
       ! src_field_pression(:,i) = i * 100
@@ -170,32 +174,45 @@
                             bounds_lon_1D=dst_boundslon, bounds_lat_1D=dst_boundslat, nvertex=dst_nvertex)
 
+  CALL xios_set_domain_attr("src_domain_unstructured_read", ni_glo=src_ni_glo, ibegin=src_ibegin, ni=src_ni, type="unstructured")
+  CALL xios_set_domain_attr("src_domain_unstructured_read", lonvalue_1D=src_lon_tmp, latvalue_1D=src_lat_tmp, &
+                            bounds_lon_1D=src_boundslon, bounds_lat_1D=src_boundslat, nvertex=src_nvertex)
+
+
   dtime%second = 3600
   CALL xios_set_timestep(dtime)
 
   CALL xios_close_context_definition()
-  ! CALL xios_get_domain_attr("src_domain_regular_read", ni=src_tmp_ni, nj=src_tmp_nj)
-  ! ALLOCATE(tmp_field_0(src_tmp_ni*src_tmp_nj))
-
-  ! CALL xios_get_axis_attr("src_axis_curvilinear_read", n=src_tmp_n)
-  ! CALL xios_get_domain_attr("src_domain_curvilinear_read", ni=src_tmp_ni, nj=src_tmp_nj)
-  ! ALLOCATE(tmp_field_1(src_tmp_ni*src_tmp_nj*src_tmp_n))
-
-  ! CALL xios_get_domain_attr("src_domain_unstructured_read", ni=src_tmp_ni, nj=src_tmp_nj)
-  ! ALLOCATE(tmp_field_2(src_tmp_ni*src_tmp_nj))
-
-  DO ts=1,5
-    ! CALL xios_recv_field("src_field_regular", tmp_field_0)
-    ! CALL xios_recv_field("src_field_curvilinear", tmp_field_1)
-    ! CALL xios_recv_field("src_field_unstructured", tmp_field_2)
+  CALL xios_get_domain_attr("src_domain_regular_read", ni=src_tmp_ni, nj=src_tmp_nj)
+  ALLOCATE(tmp_field_0(src_tmp_ni*src_tmp_nj))
+
+  CALL xios_get_axis_attr("src_axis_curvilinear_read", n=src_tmp_n)
+  CALL xios_get_domain_attr("src_domain_curvilinear_read", ni=src_tmp_ni, nj=src_tmp_nj)
+  ALLOCATE(tmp_field_1(src_tmp_ni*src_tmp_nj*src_tmp_n))
+
+  CALL xios_get_domain_attr("src_domain_unstructured_read", ni=src_tmp_ni, nj=src_tmp_nj)
+  ALLOCATE(tmp_field_2(src_tmp_ni*src_tmp_nj))
+
+  DO ts=1,1
+    CALL xios_recv_field("src_field_regular", tmp_field_0)
+    CALL xios_recv_field("src_field_curvilinear", tmp_field_1)
+    CALL xios_recv_field("src_field_unstructured", tmp_field_2)
     CALL xios_update_calendar(ts)
     CALL xios_send_field("src_field_2D",src_field_2D)
-    CALL xios_send_field("src_field_2D_clone",src_field_2D)
+    
+    DO i=1,src_ni
+      src_field_2D_clone(i) = src_field_2D(i)
+      IF ((23.5 * ts < src_lat(i)) .AND. (src_lat(i) < 65.5 *ts) .AND. (0 < src_lon(i)) .AND. (src_lon(i) < 30*ts)) THEN      
+        src_field_2D_clone(i) = missing_value    
+      ENDIF
+    ENDDO
+
+    CALL xios_send_field("src_field_2D_clone",src_field_2D_clone)
     CALL xios_send_field("src_field_3D",src_field_3D)
     CALL xios_send_field("src_field_3D_clone",src_field_3D)
     CALL xios_send_field("src_field_4D",src_field_4D)
     CALL xios_send_field("src_field_3D_pression",src_field_pression)
-    ! CALL xios_send_field("tmp_field_0",tmp_field_0)
-    ! CALL xios_send_field("tmp_field_1",tmp_field_1)
-    ! CALL xios_send_field("tmp_field_2",tmp_field_2)
+    CALL xios_send_field("tmp_field_0",tmp_field_0)
+    CALL xios_send_field("tmp_field_1",tmp_field_1)
+    CALL xios_send_field("tmp_field_2",tmp_field_2)
     CALL wait_us(5000) ;
    ENDDO
@@ -205,5 +222,5 @@
   DEALLOCATE(src_lon, src_lat, src_boundslon,src_boundslat, src_field_2D)
   DEALLOCATE(dst_lon, dst_lat, dst_boundslon,dst_boundslat)
-  ! DEALLOCATE(tmp_field_0, tmp_field_1, tmp_field_2)
+  DEALLOCATE(tmp_field_0, tmp_field_1, tmp_field_2)
 
   CALL MPI_COMM_FREE(comm, ierr)
Index: /XIOS/trunk/src/transformation/domain_algorithm_generate_rectilinear.cpp
===================================================================
--- /XIOS/trunk/src/transformation/domain_algorithm_generate_rectilinear.cpp	(revision 1063)
+++ /XIOS/trunk/src/transformation/domain_algorithm_generate_rectilinear.cpp	(revision 1064)
@@ -127,5 +127,7 @@
 void CDomainAlgorithmGenerateRectilinear::fillInAttributesDomainDestination()
 {
-  domainDest_->redistribute(nbDomainDistributedPart_);
+  if (!domainDest_->distributionAttributesHaveValue())
+    domainDest_->redistribute(nbDomainDistributedPart_);
+  domainDest_->fillInLonLat();
 }
 
