Index: XIOS/trunk/src/config/interpolate_domain_attribute.conf
===================================================================
--- XIOS/trunk/src/config/interpolate_domain_attribute.conf	(revision 1003)
+++ XIOS/trunk/src/config/interpolate_domain_attribute.conf	(revision 1004)
@@ -5,3 +5,5 @@
 
 /* Write interpolation weights into file */
-DECLARE_ENUM2(mode,write,read)
+DECLARE_ENUM3(mode,compute,read,read_or_compute)
+DECLARE_ATTRIBUTE(StdString, weight_filename)
+DECLARE_ATTRIBUTE(bool, write_weight)
Index: XIOS/trunk/src/node/interpolate_domain.cpp
===================================================================
--- XIOS/trunk/src/node/interpolate_domain.cpp	(revision 1003)
+++ XIOS/trunk/src/node/interpolate_domain.cpp	(revision 1004)
@@ -48,47 +48,43 @@
     }
 
-    StdString weightFile = "interpolation_weights_" + domainSrc->getDomainOutputName();
+    if (this->mode.isEmpty()) this->mode.setValue(mode_attr::compute);
+    if (this->write_weight.isEmpty()) this->write_weight.setValue(false);
 
-    if (!this->mode.isEmpty())
-    { 
-      if (mode_attr::read == this->mode)
-      {
-         if (this->file.isEmpty())
-         {
+    StdString weightFile;
+    switch (this->mode)
+    {
+      case mode_attr::read:
+        if (this->file.isEmpty())
+        {
+          if (!this->write_weight)
             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);
-      }
+        }
+        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 ");
+        }
+        break;
+      case mode_attr::compute:
+        break;
+      case mode_attr::read_or_compute:
+        if (!this->file.isEmpty() && !this->write_weight)
+        {
+          weightFile = this->file;
+          ifstream f(weightFile.c_str());
+          if (!f.good())
+            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
+                  << "read_or_compute mode is activated but file "  << weightFile << " doesn't exist." << std::endl
+                  << "Please check this file ");
+        }
+        break;
+      default:
+        break;
     }
 
Index: XIOS/trunk/src/node/interpolate_domain.hpp
===================================================================
--- XIOS/trunk/src/node/interpolate_domain.hpp	(revision 1003)
+++ XIOS/trunk/src/node/interpolate_domain.hpp	(revision 1004)
@@ -50,5 +50,5 @@
       virtual ~CInterpolateDomain(void);
 
-      virtual void checkValid(CDomain* axisDest);
+      virtual void checkValid(CDomain* domainSource);
 
       /// Accesseurs statiques ///
Index: XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp
===================================================================
--- XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp	(revision 1003)
+++ XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp	(revision 1004)
@@ -48,10 +48,40 @@
 
 CDomainAlgorithmInterpolate::CDomainAlgorithmInterpolate(CDomain* domainDestination, CDomain* domainSource, CInterpolateDomain* interpDomain)
-: CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain), writeToFile_(false)
-{
+: CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain), writeToFile_(false), readFromFile_(false)
+{
+  CContext* context = CContext::getCurrent();
   interpDomain_->checkValid(domainSource);
-  if ((CInterpolateDomain::mode_attr::write == interpDomain_->mode) &&
-      (!interpDomain_->file.isEmpty()))
-    writeToFile_ = true;
+  fileToReadWrite_ = "xios_interpolation_weights_";
+
+  if (interpDomain_->weight_filename.isEmpty())
+  {
+    fileToReadWrite_ += context->getId() + "_" + 
+                    domainSource->getDomainOutputName() + "_" + 
+                    domainDestination->getDomainOutputName() + ".nc";    
+  }
+  else 
+    fileToReadWrite_ = interpDomain_->weight_filename;
+
+  ifstream f(fileToReadWrite_.c_str());  
+  switch (interpDomain_->mode)
+  {
+    case CInterpolateDomain::mode_attr::read:
+      readFromFile_ = true;      
+      break;
+    case CInterpolateDomain::mode_attr::compute:
+      readFromFile_ = false;
+      break;
+    case CInterpolateDomain::mode_attr::read_or_compute:      
+      if (!f.good())
+        readFromFile_ = false;
+      else
+        readFromFile_ = true;
+      break;
+    default:
+      break;
+  } 
+
+  writeToFile_ = interpDomain_->write_weight;  
+    
 }
 
@@ -354,5 +384,5 @@
   }
 
-  if (writeToFile_)
+  if (writeToFile_ && !readFromFile_)
      writeRemapInfo(interpMapValue);
   exchangeRemapInfo(interpMapValue);
@@ -439,5 +469,5 @@
 void CDomainAlgorithmInterpolate::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
 {
-  if (CInterpolateDomain::mode_attr::read == interpDomain_->mode)  
+  if (readFromFile_ && !writeToFile_)  
     readRemapInfo();
   else
@@ -448,14 +478,12 @@
 
 void CDomainAlgorithmInterpolate::writeRemapInfo(std::map<int,std::vector<std::pair<int,double> > >& interpMapValue)
-{
-  std::string filename = interpDomain_->file.getValue();
-  writeInterpolationInfo(filename, interpMapValue);
+{  
+  writeInterpolationInfo(fileToReadWrite_, interpMapValue);
 }
 
 void CDomainAlgorithmInterpolate::readRemapInfo()
-{
-  std::string filename = interpDomain_->file.getValue();
+{  
   std::map<int,std::vector<std::pair<int,double> > > interpMapValue;
-  readInterpolationInfo(filename, interpMapValue);
+  readInterpolationInfo(fileToReadWrite_, interpMapValue);
 
   exchangeRemapInfo(interpMapValue);
Index: XIOS/trunk/src/transformation/domain_algorithm_interpolate.hpp
===================================================================
--- XIOS/trunk/src/transformation/domain_algorithm_interpolate.hpp	(revision 1003)
+++ XIOS/trunk/src/transformation/domain_algorithm_interpolate.hpp	(revision 1004)
@@ -48,4 +48,6 @@
   CInterpolateDomain* interpDomain_;
   bool writeToFile_;
+  bool readFromFile_;
+  StdString fileToReadWrite_;
 
   // class WriteNetCdf;
