Index: XIOS/trunk/inputs/REMAP/iodef.xml
===================================================================
--- XIOS/trunk/inputs/REMAP/iodef.xml	(revision 981)
+++ XIOS/trunk/inputs/REMAP/iodef.xml	(revision 982)
@@ -109,5 +109,5 @@
     <domain_group id="domain_dst">
      <domain id="dst_domain">
-       <interpolate_domain/>
+       <interpolate_domain file="weight.nc" />
      </domain>
      <domain id="dst_domain_regular_pole" ni_glo="90" nj_glo="45" type="rectilinear">
Index: XIOS/trunk/src/config/interpolate_domain_attribute.conf
===================================================================
--- XIOS/trunk/src/config/interpolate_domain_attribute.conf	(revision 981)
+++ XIOS/trunk/src/config/interpolate_domain_attribute.conf	(revision 982)
@@ -3,2 +3,5 @@
 DECLARE_ATTRIBUTE(int, order)
 DECLARE_ATTRIBUTE(bool, renormalize)
+
+/* Write interpolation weights into file */
+DECLARE_ENUM2(mode,write,read)
Index: XIOS/trunk/src/node/interpolate_domain.cpp
===================================================================
--- XIOS/trunk/src/node/interpolate_domain.cpp	(revision 981)
+++ XIOS/trunk/src/node/interpolate_domain.cpp	(revision 982)
@@ -47,4 +47,50 @@
              << "Please define a correct one") ;
     }
+
+    StdString weightFile = "interpolation_weights_" + domainSrc->getDomainOutputName();
+
+    if (!this->mode.isEmpty())
+    { 
+      if (mode_attr::read == this->mode)
+      {
+         if (this->file.isEmpty())
+         {
+            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
+                 << "Read mode is activated but there is no file specified." << std::endl
+                 << "Please define a correct file containing interpolation weights with option 'file'. ");
+         }
+         else
+         {
+           weightFile = this->file;
+           ifstream f(weightFile.c_str());
+           if (!f.good())
+             ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
+                   << "Read mode is activated but file "  << weightFile << " doesn't exist." << std::endl
+                   << "Please check this file ");
+         }
+      }
+      else
+      {
+        if (file.isEmpty())
+          this->file.setValue(weightFile);
+      }   
+    }
+    else
+    {
+      if (!file.isEmpty()) // set mode read
+      {
+         weightFile = this->file;
+         ifstream f(weightFile.c_str());
+         if (!f.good()) // file doesn't exist
+           this->mode.setValue(mode_attr::write);
+         else
+           this->mode.setValue(mode_attr::read);
+      }
+      else // only calculate weights() Mode set write but there is no file)
+      {
+        this->mode.setValue(mode_attr::write);
+      }
+    }
+
   }
 
Index: XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp
===================================================================
--- XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp	(revision 981)
+++ XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp	(revision 982)
@@ -48,7 +48,10 @@
 
 CDomainAlgorithmInterpolate::CDomainAlgorithmInterpolate(CDomain* domainDestination, CDomain* domainSource, CInterpolateDomain* interpDomain)
-: CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain)
+: CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain), writeToFile_(false)
 {
   interpDomain_->checkValid(domainSource);
+  if ((CInterpolateDomain::mode_attr::write == interpDomain_->mode) &&
+      (!interpDomain_->file.isEmpty()))
+    writeToFile_ = true;
 }
 
@@ -351,4 +354,6 @@
   }
 
+  if (writeToFile_)
+     writeRemapInfo(interpMapValue);
   exchangeRemapInfo(interpMapValue);
 
@@ -434,16 +439,20 @@
 void CDomainAlgorithmInterpolate::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
 {
-  if (!interpDomain_->file.isEmpty())
+  if (CInterpolateDomain::mode_attr::read == interpDomain_->mode)  
     readRemapInfo();
   else
-    computeRemap();
+  {
+    computeRemap(); 
+  }
+}
+
+void CDomainAlgorithmInterpolate::writeRemapInfo(std::map<int,std::vector<std::pair<int,double> > >& interpMapValue)
+{
+  std::string filename = interpDomain_->file.getValue();
+  writeInterpolationInfo(filename, interpMapValue);
 }
 
 void CDomainAlgorithmInterpolate::readRemapInfo()
 {
-  CContext* context = CContext::getCurrent();
-  CContextClient* client=context->client;
-  int clientRank = client->clientRank;
-
   std::string filename = interpDomain_->file.getValue();
   std::map<int,std::vector<std::pair<int,double> > > interpMapValue;
@@ -637,4 +646,107 @@
   delete [] recvBuff;
 }
+ 
+/*! Redefined some functions of CONetCDF4 to make use of them */
+CDomainAlgorithmInterpolate::WriteNetCdf::WriteNetCdf(const StdString& filename, const MPI_Comm comm)
+  : CNc4DataOutput(filename, false, false, true, comm, false, true) {}
+int CDomainAlgorithmInterpolate::WriteNetCdf::addDimensionWrite(const StdString& name, 
+                                                                const StdSize size)
+{
+  CONetCDF4::addDimension(name, size);  
+}
+
+int CDomainAlgorithmInterpolate::WriteNetCdf::addVariableWrite(const StdString& name, nc_type type,
+                                                               const std::vector<StdString>& dim)
+{
+  CONetCDF4::addVariable(name, type, dim);
+}
+
+void CDomainAlgorithmInterpolate::WriteNetCdf::writeDataIndex(const CArray<int,1>& data, const StdString& name,
+                                                              bool collective, StdSize record,
+                                                              const std::vector<StdSize>* start,
+                                                              const std::vector<StdSize>* count)
+{
+  CONetCDF4::writeData<int,1>(data, name, collective, record, start, count);
+}
+
+void CDomainAlgorithmInterpolate::WriteNetCdf::writeDataIndex(const CArray<double,1>& data, const StdString& name,
+                                                              bool collective, StdSize record,
+                                                              const std::vector<StdSize>* start,
+                                                              const std::vector<StdSize>* count)
+{
+  CONetCDF4::writeData<double,1>(data, name, collective, record, start, count);
+}
+
+/*
+   Write interpolation weights into a file
+   \param [in] filename name of output file
+   \param interpMapValue mapping of global index of domain destination and domain source as well as the corresponding weight
+*/
+void CDomainAlgorithmInterpolate::writeInterpolationInfo(std::string& filename,
+                                                         std::map<int,std::vector<std::pair<int,double> > >& interpMapValue)
+{
+  CContext* context = CContext::getCurrent();
+  CContextClient* client=context->client;
+
+  size_t n_src = domainSrc_->ni_glo * domainSrc_->nj_glo;
+  size_t n_dst = domainDest_->ni_glo * domainDest_->nj_glo;
+
+  long localNbWeight = 0;
+  long globalNbWeight;
+  long startIndex;
+  typedef std::map<int,std::vector<std::pair<int,double> > > IndexRemap;
+  IndexRemap::iterator itb = interpMapValue.begin(), it,
+                       ite = interpMapValue.end();
+  for (it = itb; it!=ite; ++it)
+  {
+    localNbWeight += (it->second).size();
+  }
+
+  CArray<int,1> src_idx(localNbWeight);
+  CArray<int,1> dst_idx(localNbWeight);
+  CArray<double,1> weights(localNbWeight);
+
+  int index = 0;
+  for (it = itb; it !=ite; ++it)
+  {
+    std::vector<std::pair<int,double> >& tmp = it->second;
+    for (int idx = 0; idx < tmp.size(); ++idx)
+    {
+      dst_idx(index) = it->first + 1;
+      src_idx(index) = tmp[idx].first + 1;
+      weights(index) = tmp[idx].second;
+      ++index;
+    }    
+  }
+
+  MPI_Allreduce(&localNbWeight, &globalNbWeight, 1, MPI_LONG, MPI_SUM, client->intraComm);
+  MPI_Scan(&localNbWeight, &startIndex, 1, MPI_LONG, MPI_SUM, client->intraComm);
+  
+  std::vector<StdSize> start(1, startIndex - localNbWeight);
+  std::vector<StdSize> count(1, localNbWeight);
+
+  WriteNetCdf netCdfWriter(filename, client->intraComm);
+
+  // netCdfWriter = CONetCDF4(filename, false, false, true, client->intraComm, false);
+
+  // Define some dimensions
+  netCdfWriter.addDimensionWrite("n_src", n_src);
+  netCdfWriter.addDimensionWrite("n_dst", n_dst);
+  netCdfWriter.addDimensionWrite("n_weight", globalNbWeight);
+  
+  std::vector<StdString> dims(1,"n_weight");
+
+  // Add some variables
+  netCdfWriter.addVariableWrite("src_idx", NC_INT, dims);
+  netCdfWriter.addVariableWrite("dst_idx", NC_INT, dims);
+  netCdfWriter.addVariableWrite("weight", NC_DOUBLE, dims);
+
+  // // Write variables
+  netCdfWriter.writeDataIndex(src_idx, "src_idx", true, 0, &start, &count);
+  netCdfWriter.writeDataIndex(dst_idx, "dst_idx", true, 0, &start, &count);
+  netCdfWriter.writeDataIndex(weights, "weight", true, 0, &start, &count);
+
+  netCdfWriter.closeFile();
+}
 
 /*!
Index: XIOS/trunk/src/transformation/domain_algorithm_interpolate.hpp
===================================================================
--- XIOS/trunk/src/transformation/domain_algorithm_interpolate.hpp	(revision 981)
+++ XIOS/trunk/src/transformation/domain_algorithm_interpolate.hpp	(revision 982)
@@ -12,4 +12,5 @@
 #include "domain_algorithm_transformation.hpp"
 #include "transformation.hpp"
+#include "nc4_data_output.hpp"
 
 namespace xios {
@@ -17,4 +18,5 @@
 class CDomain;
 class CInterpolateDomain;
+
 
 /*!
@@ -35,11 +37,34 @@
 private:
   void readInterpolationInfo(std::string& filename, std::map<int,std::vector<std::pair<int,double> > >& interpMapValue);
+  void writeInterpolationInfo(std::string& filename, std::map<int,std::vector<std::pair<int,double> > >& interpMapValue);
   void processPole(std::map<int,std::vector<std::pair<int,double> > >& interMapValuePole,
                    int nbGlobalPointOnPole);
   void computeRemap();
   void readRemapInfo();
+  void writeRemapInfo(std::map<int,std::vector<std::pair<int,double> > >&);
   void exchangeRemapInfo(std::map<int,std::vector<std::pair<int,double> > >& interpMapValue);
+
 private:
   CInterpolateDomain* interpDomain_;
+  bool writeToFile_;
+
+  // class WriteNetCdf;
+  class WriteNetCdf : public CNc4DataOutput
+  {
+  public:
+    WriteNetCdf(const StdString& filename, const MPI_Comm comm);
+    int addDimensionWrite(const StdString& name, const StdSize size = UNLIMITED_DIM);
+    int addVariableWrite(const StdString& name, nc_type type,
+                         const std::vector<StdString>& dim);
+    void writeDataIndex(const CArray<int,1>& data, const StdString& name,
+                        bool collective, StdSize record,
+                        const std::vector<StdSize>* start = NULL,
+                        const std::vector<StdSize>* count = NULL);
+    void writeDataIndex(const CArray<double,1>& data, const StdString& name,
+                        bool collective, StdSize record,
+                        const std::vector<StdSize>* start = NULL,
+                        const std::vector<StdSize>* count = NULL);
+  };
+
 
 private:
