Index: XIOS/trunk/inputs/COMPLETE/context_atmosphere.xml
===================================================================
--- XIOS/trunk/inputs/COMPLETE/context_atmosphere.xml	(revision 741)
+++ XIOS/trunk/inputs/COMPLETE/context_atmosphere.xml	(revision 742)
@@ -5,5 +5,5 @@
   <field_definition level="1" enabled=".FALSE." default_value="9.96921e+36">
     <field id="field_A_atm"  name="field_A_atm_origin" operation="average" freq_op="1ts" grid_ref="grid_A_atm" />
-    <field id="field_A_atm_zoom"  name="field_A_atm" operation="average" freq_op="1ts" field_ref="field_A_atm" grid_ref="grid_A_atm_zoom" />
+    <field id="field_A_atm_zoom"  name="field_A_atm" operation="average" freq_op="1ts" field_ref="field_A_atm" domain_ref="domain_atm_zoom" axis_ref="axis_atm" />
   </field_definition>
 
@@ -36,8 +36,4 @@
      <axis axis_ref="axis_atm" />
    </grid>
-   <grid id="grid_A_atm_zoom">
-     <domain domain_ref="domain_atm_zoom" />
-     <axis axis_ref="axis_atm_zoom" />
-   </grid>
   </grid_definition>
 
Index: XIOS/trunk/inputs/REMAP/iodef.xml
===================================================================
--- XIOS/trunk/inputs/REMAP/iodef.xml	(revision 741)
+++ XIOS/trunk/inputs/REMAP/iodef.xml	(revision 742)
@@ -7,8 +7,10 @@
 
    <field_definition level="1" >
-     <field id="src_field"  operation="instant" grid_ref="src_grid"/>
-     <field id="dst_field"  operation="instant" field_ref="src_field" grid_ref="dst_grid"/>
-     <field id="dst_field_regular"  operation="instant" field_ref="tmp_field" grid_ref="dst_grid_regular"  read_access="true"/>
-     <field id="tmp_field"  operation="instant" grid_ref="src_grid_regular"/>
+     <field id="src_field"  operation="instant" domain_ref="src_domain"/>
+     <field id="dst_field"  operation="instant" field_ref="src_field" domain_ref="dst_domain"/>
+     <field id="tmp_field"  operation="instant" domain_ref="src_domain_regular"/>
+     <field id="dst_field_regular_grid"  operation="instant" field_ref="tmp_field" grid_ref="dst_grid_regular"  read_access="true"/>
+     <field id="dst_field_regular"  operation="instant" field_ref="tmp_field" domain_ref="dst_domain_regular"  read_access="true"/>
+
    </field_definition>
 
@@ -18,12 +20,16 @@
         <field field_ref="src_field" name="field" />
      </file>
-     <file id="output_dst" name="output_dst">
+     <file id="output_dst" name="output_dst" type="one_file">
         <field field_ref="dst_field" name="field" />
      </file>
      <file id="output_dst_regular" name="output_dst_regular" type="one_file">
         <field field_ref="dst_field_regular" name="field" />
+        <field field_ref="dst_field_regular_grid" name="field_grid" />
      </file>
      <file id="output_src_regular" name="output_src_regular" mode="read" type="multiple_file">
-        <field id="src_field_regular" name="field" grid_ref="src_grid_regular" operation="instant"/>
+        <field id="src_field_regular" name="field" domain_ref="src_domain_regular" operation="instant"/>
+     </file>
+     <file id="output_src_regular_tmp" name="output_src_regular_tmp">
+        <field field_ref="tmp_field"/>
      </file>
    </file_definition>
@@ -38,5 +44,5 @@
        <interpolate_domain/>
      </domain>
-     <domain id="dst_domain_regular" domain_src="src_domain_regular" ni_glo="360" nj_glo="180" type="rectilinear">
+     <domain id="dst_domain_regular" domain_src="src_domain_regular" ni_glo="90" nj_glo="45" type="rectilinear">
        <generate_rectilinear_domain />
        <interpolate_domain/>
@@ -48,15 +54,6 @@
 
    <grid_definition>
-     <grid id="dst_grid">
-       <domain domain_ref="dst_domain" />
-     </grid>
      <grid id="dst_grid_regular">
        <domain domain_ref="dst_domain_regular" />
-     </grid>
-     <grid id="src_grid">
-       <domain domain_ref="src_domain" />
-     </grid>
-     <grid id="src_grid_regular">
-       <domain domain_ref="src_domain_regular" />
      </grid>
    </grid_definition>
@@ -69,5 +66,5 @@
             <variable id="optimal_buffer_size" type="string">performance</variable>
             <variable id="buffer_size_factor" type="double">30.0</variable>
-            <variable id="buffer_size_min" type="double">800000</variable>
+            <variable id="min_buffer_size" type="double">800000</variable>
          </variable_group>
 
Index: XIOS/trunk/src/declare_ref_func.hpp
===================================================================
--- XIOS/trunk/src/declare_ref_func.hpp	(revision 741)
+++ XIOS/trunk/src/declare_ref_func.hpp	(revision 742)
@@ -79,6 +79,8 @@
      sset.insert(refer_ptr);                                                       \
   }                                                                                \
+  baseRefObject = refer_ptr;                                                      \
+  baseRefObject->addReference(this) ;               \
                                                                                    \
-  if (hasDirect##type##Reference()) baseRefObject->addReference(this) ;               \
+ /* if (hasDirect##type##Reference()) baseRefObject->addReference(this) ;*/               \
 }                                                                                  \
                                                                                    \
Index: XIOS/trunk/src/node/axis.cpp
===================================================================
--- XIOS/trunk/src/node/axis.cpp	(revision 741)
+++ XIOS/trunk/src/node/axis.cpp	(revision 742)
@@ -66,5 +66,5 @@
    /*!
     * Test whether the data defined on the axis can be outputted in a compressed way.
-    * 
+    *
     * \return true if and only if a mask was defined for this axis
     */
@@ -326,6 +326,5 @@
    }
 
-   void CAxis::checkAttributesOnClient(const std::vector<int>& globalDim, int orderPositionInGrid,
-                                       CServerDistributionDescription::ServerDistributionType distType)
+   void CAxis::checkAttributesOnClient()
    {
      if (this->areClientAttributesChecked_) return;
@@ -340,7 +339,5 @@
                                      CServerDistributionDescription::ServerDistributionType distType)
    {
-     if (!this->areClientAttributesChecked_) checkAttributesOnClient(globalDim,
-                                                                     orderPositionInGrid,
-                                                                     distType);
+     if (!this->areClientAttributesChecked_) checkAttributesOnClient();
      CContext* context = CContext::getCurrent();
 
Index: XIOS/trunk/src/node/axis.hpp
===================================================================
--- XIOS/trunk/src/node/axis.hpp	(revision 741)
+++ XIOS/trunk/src/node/axis.hpp	(revision 742)
@@ -102,6 +102,5 @@
          static void recvServerAttribut(CEventServer& event);
          void recvServerAttribut(CBufferIn& buffer) ;
-         void checkAttributesOnClient(const std::vector<int>& globalDim, int orderPositionInGrid,
-                                      CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION);
+         void checkAttributesOnClient();
          void sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid,
                                     CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION);
Index: XIOS/trunk/src/node/field.cpp
===================================================================
--- XIOS/trunk/src/node/field.cpp	(revision 741)
+++ XIOS/trunk/src/node/field.cpp	(revision 742)
@@ -755,4 +755,10 @@
    void CField::solveGridReference(void)
    {
+      if (grid_ref.isEmpty() && domain_ref.isEmpty() && axis_ref.isEmpty())
+      {
+        ERROR("CField::solveGridReference(void)",
+              << "At least one dimension must be defined for this field.");
+      }
+
       CDomain* domain;
       CAxis* axis;
@@ -761,9 +767,25 @@
       std::vector<std::string> domList, axisList;
 
+      // In some cases, domain_ref, axis_ref and grid_ref don't come from the current field but from his direct field_ref
+      // To make sure to use the correct *_ref, we need to compare these values to direct field_ref's
+      CField* baseFieldRef = this->getBaseFieldReference();
+      bool hasDomainFromFieldRef = false;
+      bool hasAxisFromFieldRef = false;
+      bool hasGridFromFieldRef = false;
+
       if (!domain_ref.isEmpty())
       {
+         if (0 != baseFieldRef)
+         {
+           if ((!baseFieldRef->domain_ref.isEmpty()) && (baseFieldRef->domain_ref.getValue() == domain_ref.getValue()))
+            hasDomainFromFieldRef = true;
+         }
+
          if (CDomain::has(domain_ref.getValue()))
          {
            domain = CDomain::get(domain_ref.getValue());
+           // It's a direct reference, so we use this ref as its name
+           domain->name.setValue(domain_ref.getValue());
+
            vecDom.push_back(domain);
          }
@@ -776,7 +798,15 @@
       if (!axis_ref.isEmpty())
       {
+         if (0 != baseFieldRef)
+         {
+           if ((!baseFieldRef->axis_ref.isEmpty()) && (baseFieldRef->axis_ref.getValue() == axis_ref.getValue()))
+            hasAxisFromFieldRef = true;
+         }
          if (CAxis::has(axis_ref.getValue()))
          {
            axis = CAxis::get(axis_ref.getValue());
+                      // It's a direct reference, so we use this ref as its name
+           axis->name.setValue(axis_ref.getValue());
+
            vecAxis.push_back(axis);
          }
@@ -789,28 +819,31 @@
       if (!grid_ref.isEmpty())
       {
-         if (CGrid::has(grid_ref.getValue()))
+         if (0 != baseFieldRef)
          {
-           this->grid = CGrid::get(grid_ref.getValue());
-           domList = grid->getDomainList();
-           axisList = grid->getAxisList();
-           if (domList.empty() && axisList.empty())
+           if ((!baseFieldRef->grid_ref.isEmpty()) && (baseFieldRef->grid_ref.getValue() == grid_ref.getValue()))
+            hasGridFromFieldRef = true;
+         }
+
+        if ((domain_ref.isEmpty() && axis_ref.isEmpty()) || (!hasGridFromFieldRef))
+        {
+           if (CGrid::has(grid_ref.getValue()))
            {
-             this->grid = CGrid::createGrid(vecDom, vecAxis);
+             this->grid = CGrid::get(grid_ref.getValue());
            }
-         }
-         else
-            ERROR("CField::solveGridReference(void)",
-                  << "Reference to the grid \'"
-                  << grid_ref.getValue() << "\' is wrong");
+           else
+              ERROR("CField::solveGridReference(void)",
+                    << "Reference to the grid \'"
+                    << grid_ref.getValue() << "\' is wrong");
+        }
+        else
+        {
+          this->grid = CGrid::createGrid(vecDom, vecAxis);
+          this->grid_ref.setValue(this->grid->getId());
+        }
       }
       else
       {
          this->grid = CGrid::createGrid(vecDom, vecAxis);
-      }
-
-      if (grid_ref.isEmpty() && domain_ref.isEmpty() && axis_ref.isEmpty())
-      {
-            ERROR("CField::solveGridReference(void)",
-                  << "At least one dimension must be defined for this field.");
+         this->grid_ref.setValue(this->grid->getId());
       }
    }
Index: XIOS/trunk/src/node/grid.cpp
===================================================================
--- XIOS/trunk/src/node/grid.cpp	(revision 741)
+++ XIOS/trunk/src/node/grid.cpp	(revision 742)
@@ -21,5 +21,5 @@
 namespace xios {
 
-   /// ////////////////////// DÃ©finitions ////////////////////// ///
+   /// ////////////////////// Dfinitions ////////////////////// ///
 
    CGrid::CGrid(void)
@@ -126,5 +126,5 @@
        }
      }
-     
+
      return attributesSizes;
    }
@@ -342,5 +342,5 @@
             axisListP[i]->sendCheckedAttributes(globalDim_,axisPositionInGrid_[i]);
           else
-            axisListP[i]->checkAttributesOnClient(globalDim_,axisPositionInGrid_[i]);
+            axisListP[i]->checkAttributesOnClient();
           ++idx;
         }
@@ -500,5 +500,6 @@
       }
 
-      grid->computeGridGlobalDimension(domains, axis, grid->axis_domain_order);
+
+      grid->solveDomainAxisRefInheritance(true);
 
       return grid;
@@ -1307,5 +1308,11 @@
     if (isDomListSet) return;
     std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren();
-    if (!domains.empty() && domList.empty()) domList = domains;
+    if (!domains.empty() && domList.empty())
+    {
+      for (int i = 0; i < domains.size(); ++i)
+        this->getVirtualDomainGroup()->addChild(domains[i]);
+      domList = this->getVirtualDomainGroup()->getAllChildren();
+    }
+
     if (!domList.empty())
     {
@@ -1329,5 +1336,11 @@
     if (isAxisListSet) return;
     std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren();
-    if (!axis.empty() && aList.empty()) aList = axis;
+    if (!axis.empty() && aList.empty())
+    {
+      for (int i = 0; i < axis.size(); ++i)
+        this->getVirtualAxisGroup()->addChild(axis[i]);
+      aList = this->getVirtualAxisGroup()->getAllChildren();
+    }
+
     if (!aList.empty())
     {
Index: XIOS/trunk/src/node/grid.hpp
===================================================================
--- XIOS/trunk/src/node/grid.hpp	(revision 741)
+++ XIOS/trunk/src/node/grid.hpp	(revision 742)
@@ -202,4 +202,8 @@
          void modifyMask(const CArray<int,1>& indexToModify);
 
+         void computeGridGlobalDimension(const std::vector<CDomain*>& domains,
+                                         const std::vector<CAxis*>& axis,
+                                         const CArray<bool,1>& axisDomainOrder);
+
       private:
        template<int N>
@@ -218,8 +222,4 @@
         void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>());
         void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>());
-
-        void computeGridGlobalDimension(const std::vector<CDomain*>& domains,
-                                        const std::vector<CAxis*>& axis,
-                                        const CArray<bool,1>& axisDomainOrder);
 
         CDomain* addDomain(const std::string& id);
Index: XIOS/trunk/src/test/test_remap.f90
===================================================================
--- XIOS/trunk/src/test/test_remap.f90	(revision 741)
+++ XIOS/trunk/src/test/test_remap.f90	(revision 742)
@@ -119,7 +119,4 @@
                             bounds_lon_1D=dst_boundslon, bounds_lat_1D=dst_boundslat, nvertex=dst_nvertex)
 
-!  CALL xios_set_domain_attr("dst_domain_regular", type="rectilinear")
-
-
   ALLOCATE(tmp_field(180*90/2))
   dtime%second = 3600
Index: XIOS/trunk/src/transformation/grid_transformation.cpp
===================================================================
--- XIOS/trunk/src/transformation/grid_transformation.cpp	(revision 741)
+++ XIOS/trunk/src/transformation/grid_transformation.cpp	(revision 742)
@@ -46,5 +46,8 @@
   {
     CAxis* axis = CAxis::createAxis();
-    axis->setAttributes(axisSrcTmp[idx]);
+    axis->axis_ref.setValue(axisSrcTmp[idx]->getId());
+    axis->solveRefInheritance(true);
+    axis->solveInheritanceTransformation();
+    axis->checkAttributesOnClient();
     axisSrc.push_back(axis);
   }
@@ -53,5 +56,6 @@
   {
     CDomain* domain = CDomain::createDomain();
-    domain->setAttributes(domainSrcTmp[idx]);
+    domain->domain_ref.setValue(domainSrcTmp[idx]->getId());
+    domain->solveRefInheritance(true);
     domain->solveInheritanceTransformation();
     domain->checkAttributesOnClient();
@@ -60,4 +64,5 @@
 
   gridSource_ = CGrid::createGrid(domainSrc, axisSrc, gridDestination_->axis_domain_order);
+  gridSource_->computeGridGlobalDimension(domainSrc, axisSrc, gridDestination_->axis_domain_order);
 
   initializeMappingOfOriginalGridSource();
