Index: XIOS/trunk/inputs/REMAP/iodef.xml
===================================================================
--- XIOS/trunk/inputs/REMAP/iodef.xml	(revision 822)
+++ XIOS/trunk/inputs/REMAP/iodef.xml	(revision 823)
@@ -14,4 +14,5 @@
      <field id="dst_field_regular" operation="instant" field_ref="tmp_field_2" grid_ref="dst_grid_regular" read_access="true"/>
      <field id="dst_field_regular_pole" operation="instant" field_ref="src_field" domain_ref="dst_domain_regular_pole"/>
+     <field id="dst_field_regular_pole_1" operation="instant" field_ref="tmp_field" domain_ref="dst_domain_regular_pole"/>
    </field_definition>
 
@@ -27,4 +28,7 @@
         <field field_ref="dst_field_regular_pole" name="field" />
      </file>
+     <file id="out_dst_regular_pole_1" name="out_dst_regular_pole_1" type="one_file">
+        <field field_ref="dst_field_regular_pole_1" name="field" />
+     </file>
      <file id="output_dst_regular" name="output_dst_regular" type="one_file">
         <field field_ref="dst_field_regular" name="field" />
@@ -39,5 +43,4 @@
         <field id="src_field_regular_tmp" name="field" domain_ref="src_domain_regular_tmp" operation="instant"/>
      </file>
-
      <file id="output_src_curvilinear" name="output_src_curvilinear" mode="read" type="one_file">
         <field id="src_field_curvilinear" name="field_A" grid_ref="src_grid_curvilinear" operation="instant"/>
Index: XIOS/trunk/src/node/axis.cpp
===================================================================
--- XIOS/trunk/src/node/axis.cpp	(revision 822)
+++ XIOS/trunk/src/node/axis.cpp	(revision 823)
@@ -911,4 +911,12 @@
   }
 
+  void CAxis::duplicateTransformation(CAxis* src)
+  {
+    if (src->hasTransformation())
+    {
+      this->setTransformations(src->getAllTransformations());
+    }
+  }
+
   /*!
    * Go through the hierarchy to find the axis from which the transformations must be inherited
Index: XIOS/trunk/src/node/axis.hpp
===================================================================
--- XIOS/trunk/src/node/axis.hpp	(revision 822)
+++ XIOS/trunk/src/node/axis.hpp	(revision 823)
@@ -113,4 +113,5 @@
          TransMapTypes getAllTransformations();
          void fillInValues(const CArray<double,1>& values);
+         void duplicateTransformation(CAxis*);                   \
 
       public:
Index: XIOS/trunk/src/node/context.cpp
===================================================================
--- XIOS/trunk/src/node/context.cpp	(revision 822)
+++ XIOS/trunk/src/node/context.cpp	(revision 823)
@@ -451,4 +451,18 @@
       for (unsigned int i = 0; i < this->enabledReadModeFiles.size(); ++i)
         (void)this->enabledReadModeFiles[i]->readAttributesOfEnabledFieldsInReadMode();
+   }
+
+   void CContext::solveOnlyRefOfEnabledFields(bool sendToServer)
+   {
+     int size = this->enabledFiles.size();
+     for (int i = 0; i < size; ++i)
+     {
+       this->enabledFiles[i]->solveOnlyRefOfEnabledFields(sendToServer);
+     }
+
+     for (int i = 0; i < size; ++i)
+     {
+       this->enabledFiles[i]->generateNewTransformationGridDest();
+     }
    }
 
@@ -804,4 +818,8 @@
       this->readAttributesOfEnabledFieldsInReadModeFiles();
      }
+
+      // Only search and rebuild all reference objects of enable fields, don't transform
+      this->solveOnlyRefOfEnabledFields(false);
+
       // Search and rebuild all reference object of enabled fields
       this->solveAllRefOfEnabledFields(false);
Index: XIOS/trunk/src/node/context.hpp
===================================================================
--- XIOS/trunk/src/node/context.hpp	(revision 822)
+++ XIOS/trunk/src/node/context.hpp	(revision 823)
@@ -113,4 +113,5 @@
          void checkAxisDomainsGridsEligibilityForCompressedOutput();
          void prepareTimeseries(void);
+         void solveOnlyRefOfEnabledFields(bool sendToServer);
          void solveAllRefOfEnabledFields(bool sendToServer);
          void buildFilterGraphOfEnabledFields();
Index: XIOS/trunk/src/node/domain.cpp
===================================================================
--- XIOS/trunk/src/node/domain.cpp	(revision 822)
+++ XIOS/trunk/src/node/domain.cpp	(revision 823)
@@ -1947,4 +1947,12 @@
   }
 
+  void CDomain::duplicateTransformation(CDomain* src)
+  {
+    if (src->hasTransformation())
+    {
+      this->setTransformations(src->getAllTransformations());
+    }
+  }
+
   /*!
    * Go through the hierarchy to find the domain from which the transformations must be inherited
Index: XIOS/trunk/src/node/domain.hpp
===================================================================
--- XIOS/trunk/src/node/domain.hpp	(revision 822)
+++ XIOS/trunk/src/node/domain.hpp	(revision 823)
@@ -78,4 +78,5 @@
          TransMapTypes getAllTransformations();
          void redistribute(int nbLocalDomain);
+         void duplicateTransformation(CDomain*);
 
       public:
Index: XIOS/trunk/src/node/field.cpp
===================================================================
--- XIOS/trunk/src/node/field.cpp	(revision 822)
+++ XIOS/trunk/src/node/field.cpp	(revision 823)
@@ -34,5 +34,5 @@
       , nstep(0), nstepMax(0)
       , hasOutputFile(false)
-      , domAxisIds_("", ""), areAllReferenceSolved(false)
+      , domAxisIds_("", ""), areAllReferenceSolved(false), isReferenceSolved(false)
       , useCompressedOutput(false)
       , isReadDataRequestPending(false)
@@ -45,5 +45,5 @@
       , nstep(0), nstepMax(0)
       , hasOutputFile(false)
-      , domAxisIds_("", ""), areAllReferenceSolved(false)
+      , domAxisIds_("", ""), areAllReferenceSolved(false), isReferenceSolved(false)
       , useCompressedOutput(false)
       , isReadDataRequestPending(false)
@@ -492,7 +492,132 @@
    //----------------------------------------------------------------
 
-   void CField::solveAllReferenceEnabledField(bool doSending2Sever)
+   void CField::solveOnlyReferenceEnabledField(bool doSending2Server)
    {
      CContext* context = CContext::getCurrent();
+     if (!isReferenceSolved)
+     {
+        isReferenceSolved = true;
+
+        if (context->hasClient)
+        {
+          solveRefInheritance(true);
+          if (hasDirectFieldReference()) getDirectFieldReference()->solveOnlyReferenceEnabledField(false);
+        }
+        else if (context->hasServer)
+          solveServerOperation();
+
+        solveGridReference();
+
+       if (context->hasClient)
+       {
+         solveGenerateGrid();
+         buildGridTransformationGraph();
+       }
+     }
+   }
+
+   /*!
+     Build up graph of grids which plays role of destination and source in grid transformation
+     This function should be called before \func solveGridReference()
+   */
+   void CField::buildGridTransformationGraph()
+   {
+     CContext* context = CContext::getCurrent();
+     if (context->hasClient)
+     {
+       if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid)
+       {
+         grid->addTransGridSource(getDirectFieldReference()->grid);
+       }
+     }
+   }
+
+   /*!
+     Generate a new grid destination if there are more than one grid source pointing to a same grid destination
+   */
+   void CField::generateNewTransformationGridDest()
+   {
+     CContext* context = CContext::getCurrent();
+     if (context->hasClient)
+     {
+       std::map<CGrid*,std::pair<bool,StdString> >& gridSrcMap = grid->getTransGridSource();
+       if (1 < gridSrcMap.size())
+       {
+         // Search for grid source
+         CGrid* gridSrc = grid;
+         CField* currField = this;
+         std::vector<CField*> hieraField;
+
+         while (currField->hasDirectFieldReference() && (gridSrc == grid))
+         {
+           hieraField.push_back(currField);
+           CField* tmp = currField->getDirectFieldReference();
+           currField = tmp;
+           gridSrc = currField->grid;
+         }
+
+         if (gridSrcMap.end() != gridSrcMap.find(gridSrc))
+         {
+           CGrid* gridTmp;
+           std::pair<bool,StdString> newGridDest = gridSrcMap[gridSrc];
+           if (newGridDest.first)
+           {
+             StdString newIdGridDest = newGridDest.second;
+             if (!CGrid::has(newIdGridDest))
+             {
+                ERROR("CGrid* CGrid::generateNewTransformationGridDest()",
+                  << " Something wrong happened! Grid whose id " << newIdGridDest
+                  << "should exist ");
+             }
+             gridTmp = CGrid::get(newIdGridDest);
+           }
+           else
+           {
+             StdString newIdGridDest = CGrid::generateId(gridSrc, grid);
+             gridTmp = CGrid::cloneGrid(newIdGridDest, grid);
+
+             (gridSrcMap[gridSrc]).first = true;
+             (gridSrcMap[gridSrc]).second = newIdGridDest;
+           }
+
+           // Update all descendants
+           for (std::vector<CField*>::iterator it = hieraField.begin(); it != hieraField.end(); ++it)
+           {
+             (*it)->grid = gridTmp;
+             (*it)->updateRef((*it)->grid);
+           }
+         }
+       }
+     }
+   }
+
+   void CField::updateRef(CGrid* grid)
+   {
+     if (!grid_ref.isEmpty()) grid_ref.setValue(grid->getId());
+     else
+     {
+       std::vector<CAxis*> axisTmp = grid->getAxis();
+       std::vector<CDomain*> domainTmp = grid->getDomains();
+       if ((1<axisTmp.size()) || (1<domainTmp.size()))
+         ERROR("void CField::updateRef(CGrid* grid)",
+           << "More than one domain or axis is available for domain_ref/axis_ref of field " << this->getId());
+
+       if ((!domain_ref.isEmpty()) && (domainTmp.empty()))
+         ERROR("void CField::updateRef(CGrid* grid)",
+           << "Incoherent between available domain and domain_ref of field " << this->getId());
+       if ((!axis_ref.isEmpty()) && (axisTmp.empty()))
+         ERROR("void CField::updateRef(CGrid* grid)",
+           << "Incoherent between available axis and axis_ref of field " << this->getId());
+
+       if (!domain_ref.isEmpty()) domain_ref.setValue(domainTmp[0]->getId());
+       if (!axis_ref.isEmpty()) axis_ref.setValue(axisTmp[0]->getId());
+     }
+   }
+
+   void CField::solveAllReferenceEnabledField(bool doSending2Server)
+   {
+     CContext* context = CContext::getCurrent();
+     solveOnlyReferenceEnabledField(doSending2Server);
+
      if (!areAllReferenceSolved)
      {
@@ -509,10 +634,6 @@
         solveGridReference();
      }
-     if (context->hasClient)
-     {
-       solveGenerateGrid();
-     }
-
-     solveGridDomainAxisRef(doSending2Sever);
+
+     solveGridDomainAxisRef(doSending2Server);
 
      if (context->hasClient)
@@ -521,5 +642,5 @@
      }
 
-     solveCheckMaskIndex(doSending2Sever);
+     solveCheckMaskIndex(doSending2Server);
    }
 
@@ -773,4 +894,5 @@
         if (!domain_ref.isEmpty())
         {
+          StdString tmp = domain_ref.getValue();
           if (CDomain::has(domain_ref))
             vecDom.push_back(CDomain::get(domain_ref));
Index: XIOS/trunk/src/node/field.hpp
===================================================================
--- XIOS/trunk/src/node/field.hpp	(revision 822)
+++ XIOS/trunk/src/node/field.hpp	(revision 823)
@@ -110,5 +110,9 @@
          void solveServerOperation(void);
          void solveCheckMaskIndex(bool doSendingIndex);
-         void solveAllReferenceEnabledField(bool doSending2Sever);
+         void solveAllReferenceEnabledField(bool doSending2Server);
+         void solveOnlyReferenceEnabledField(bool doSending2Server);
+         void generateNewTransformationGridDest();
+         void updateRef(CGrid* grid);
+         void buildGridTransformationGraph();
          void solveGridDomainAxisRef(bool checkAtt);
          void solveTransformedGrid();
@@ -196,4 +200,5 @@
 
          bool areAllReferenceSolved;
+         bool isReferenceSolved;
          std::pair<StdString,StdString> domAxisIds_;
          bool isReadDataRequestPending;
Index: XIOS/trunk/src/node/file.cpp
===================================================================
--- XIOS/trunk/src/node/file.cpp	(revision 822)
+++ XIOS/trunk/src/node/file.cpp	(revision 823)
@@ -647,4 +647,31 @@
    \param [in] sendToServer: Send all info to server (true) or only a part of it (false)
    */
+   void CFile::solveOnlyRefOfEnabledFields(bool sendToServer)
+   {
+     int size = this->enabledFields.size();
+     for (int i = 0; i < size; ++i)
+     {
+       this->enabledFields[i]->solveOnlyReferenceEnabledField(sendToServer);
+//       this->enabledFields[i]->buildGridTransformationGraph();
+     }
+   }
+
+   void CFile::generateNewTransformationGridDest()
+   {
+     int size = this->enabledFields.size();
+     for (int i = 0; i < size; ++i)
+     {
+       this->enabledFields[i]->generateNewTransformationGridDest();
+     }
+   }
+
+   /*!
+   \brief Resolve all reference of active fields.
+      In order to know exactly which data each active field has, a search for all its
+   reference to find its parents or/and its base reference object must be done. Moreover
+   during this search, there are some information that can only be sent to server AFTER
+   all information of active fields are created on server side, e.g: checking mask or index
+   \param [in] sendToServer: Send all info to server (true) or only a part of it (false)
+   */
    void CFile::solveAllRefOfEnabledFields(bool sendToServer)
    {
Index: XIOS/trunk/src/node/file.hpp
===================================================================
--- XIOS/trunk/src/node/file.hpp	(revision 822)
+++ XIOS/trunk/src/node/file.hpp	(revision 823)
@@ -106,4 +106,6 @@
          void solveFieldRefInheritance(bool apply);
          void processEnabledFile(void);
+         void solveOnlyRefOfEnabledFields(bool sendToServer);
+         void generateNewTransformationGridDest();
          void solveAllRefOfEnabledFields(bool sendToServer);
          void buildFilterGraphOfEnabledFields(CGarbageCollector& gc);
Index: XIOS/trunk/src/node/grid.cpp
===================================================================
--- XIOS/trunk/src/node/grid.cpp	(revision 822)
+++ XIOS/trunk/src/node/grid.cpp	(revision 823)
@@ -32,4 +32,5 @@
       , transformations_(0), isTransformed_(false)
       , axisPositionInGrid_(), positionDimensionDistributed_(1), hasDomainAxisBaseRef_(false)
+      , gridSrc_()
    {
      setVirtualDomainGroup();
@@ -46,4 +47,5 @@
       , transformations_(0), isTransformed_(false)
       , axisPositionInGrid_(), positionDimensionDistributed_(1), hasDomainAxisBaseRef_(false)
+      , gridSrc_()
    {
      setVirtualDomainGroup();
@@ -551,4 +553,33 @@
    }
 
+   CGrid* CGrid::cloneGrid(const StdString& idNewGrid, CGrid* gridSrc)
+   {
+     std::vector<CAxis*> axisSrcTmp = gridSrc->getAxis(), axisSrc;
+     std::vector<CDomain*> domainSrcTmp = gridSrc->getDomains(), domainSrc;
+     for (int idx = 0; idx < axisSrcTmp.size(); ++idx)
+     {
+       CAxis* axis = CAxis::createAxis();
+       axis->duplicateAttributes(axisSrcTmp[idx]);
+       axis->duplicateTransformation(axisSrcTmp[idx]);
+       axis->solveRefInheritance(true);
+       axis->solveInheritanceTransformation();
+       axisSrc.push_back(axis);
+     }
+
+     for (int idx = 0; idx < domainSrcTmp.size(); ++idx)
+     {
+       CDomain* domain = CDomain::createDomain();
+       domain->duplicateAttributes(domainSrcTmp[idx]);
+       domain->duplicateTransformation(domainSrcTmp[idx]);
+       domain->solveRefInheritance(true);
+       domain->solveInheritanceTransformation();
+       domainSrc.push_back(domain);
+     }
+
+      CGrid* grid = CGrid::createGrid(idNewGrid, domainSrc, axisSrc, gridSrc->axis_domain_order);
+
+      return grid;
+   }
+
    StdString CGrid::generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
                                const CArray<bool,1>& axisDomainOrder)
@@ -588,4 +619,15 @@
 
       return id.str();
+   }
+
+   StdString CGrid::generateId(const CGrid* gridSrc, const CGrid* gridDest)
+   {
+     StdString idSrc  = gridSrc->getId();
+     StdString idDest = gridDest->getId();
+
+     std::ostringstream id;
+     id << idSrc << "__" << idDest;
+
+     return id.str();
    }
 
@@ -1298,4 +1340,15 @@
   }
 
+  void CGrid::addTransGridSource(CGrid* gridSrc)
+  {
+    if (gridSrc_.end() == gridSrc_.find(gridSrc))
+      gridSrc_.insert(make_pair(gridSrc,make_pair(false,"")));
+  }
+
+  std::map<CGrid*,std::pair<bool,StdString> >& CGrid::getTransGridSource()
+  {
+    return gridSrc_;
+  }
+
   /*!
      Complete all the necessary (and lacking) attributes of a grid
Index: XIOS/trunk/src/node/grid.hpp
===================================================================
--- XIOS/trunk/src/node/grid.hpp	(revision 822)
+++ XIOS/trunk/src/node/grid.hpp	(revision 823)
@@ -127,4 +127,6 @@
          static StdString generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis,
                                      const CArray<bool,1>& axisDomainOrder = CArray<bool,1>());
+         static StdString generateId(const CGrid* gridSrc, const CGrid* gridDest);
+         static CGrid* cloneGrid(const StdString& idNewGrid, CGrid* gridSrc);
 
       public:
@@ -191,4 +193,6 @@
          bool isTransformed();
          void setTransformed();
+         void addTransGridSource(CGrid* gridSrc);
+         std::map<CGrid*, std::pair<bool,StdString> >& getTransGridSource();
 
       public:
@@ -242,5 +246,5 @@
         void setTransformationAlgorithms();
 
-        std::vector<int> globalDim_;
+
 
       private:
@@ -267,4 +271,6 @@
         CGridTransformation* transformations_;
         bool hasDomainAxisBaseRef_;
+        std::vector<int> globalDim_;
+        std::map<CGrid*, std::pair<bool,StdString> > gridSrc_;
    }; // class CGrid
 
Index: XIOS/trunk/src/transformation/grid_transformation.cpp
===================================================================
--- XIOS/trunk/src/transformation/grid_transformation.cpp	(revision 822)
+++ XIOS/trunk/src/transformation/grid_transformation.cpp	(revision 823)
@@ -43,31 +43,5 @@
   }
 
-//  std::vector<CAxis*> axisSrcTmp = gridSource_->getAxis(), axisSrc;
-//  std::vector<CDomain*> domainSrcTmp = gridSource_->getDomains(), domainSrc;
-//  for (int idx = 0; idx < axisSrcTmp.size(); ++idx)
-//  {
-//    CAxis* axis = CAxis::createAxis();
-//    axis->axis_ref.setValue(axisSrcTmp[idx]->getId());
-//    axis->solveRefInheritance(true);
-//    axis->solveInheritanceTransformation();
-//    axis->checkAttributesOnClient();
-//    axisSrc.push_back(axis);
-//  }
-//
-//  for (int idx = 0; idx < domainSrcTmp.size(); ++idx)
-//  {
-//    CDomain* domain = CDomain::createDomain();
-//    domain->domain_ref.setValue(domainSrcTmp[idx]->getId());
-//    domain->solveRefInheritance(true);
-//    domain->solveInheritanceTransformation();
-//    domain->checkAttributesOnClient();
-//    domainSrc.push_back(domain);
-//  }
-//
-//  gridSource_ = CGrid::createGrid(domainSrc, axisSrc, gridDestination_->axis_domain_order);
-//  gridSource_->computeGridGlobalDimension(domainSrc, axisSrc, gridDestination_->axis_domain_order);
-
   initializeMappingOfOriginalGridSource();
-//  initializeAlgorithms();
 }
 
