Index: /XIOS/trunk/src/attribute.hpp
===================================================================
--- /XIOS/trunk/src/attribute.hpp	(revision 459)
+++ /XIOS/trunk/src/attribute.hpp	(revision 460)
@@ -42,4 +42,5 @@
 //            template <typename T> inline bool isType(void) const;
             virtual void set(const CAttribute& ) =0 ;
+            virtual void reset(void ) =0 ;
             /// Destructeur ///
             virtual ~CAttribute(void);
Index: /XIOS/trunk/src/attribute_array.hpp
===================================================================
--- /XIOS/trunk/src/attribute_array.hpp	(revision 459)
+++ /XIOS/trunk/src/attribute_array.hpp	(revision 460)
@@ -36,5 +36,5 @@
             void set(const CAttribute& attr) ;
             void set(const CAttributeArray& attr) ;
-            
+            void reset(void) ;            
             void setInheritedValue(const CAttributeArray& attr );
             void setInheritedValue(const CAttribute& attr );
Index: /XIOS/trunk/src/attribute_array_impl.hpp
===================================================================
--- /XIOS/trunk/src/attribute_array_impl.hpp	(revision 459)
+++ /XIOS/trunk/src/attribute_array_impl.hpp	(revision 460)
@@ -41,4 +41,11 @@
       ///--------------------------------------------------------------
 
+      template <typename T_numtype, int N_rank>
+      void CAttributeArray<T_numtype, N_rank>::reset(void)
+      {
+        CArray<T_numtype, N_rank>::reset() ;
+        inheritedValue.reset() ;
+      }
+      
       template <typename T_numtype, int N_rank>
       CArray<T_numtype,N_rank> CAttributeArray<T_numtype, N_rank>::getValue(void) const
Index: /XIOS/trunk/src/attribute_enum.hpp
===================================================================
--- /XIOS/trunk/src/attribute_enum.hpp	(revision 459)
+++ /XIOS/trunk/src/attribute_enum.hpp	(revision 460)
@@ -39,4 +39,5 @@
             void set(const CAttribute& attr) ;
             void set(const CAttributeEnum& attr) ;
+            void reset(void);
             
             void setInheritedValue(const CAttributeEnum& attr );
Index: /XIOS/trunk/src/attribute_enum_impl.hpp
===================================================================
--- /XIOS/trunk/src/attribute_enum_impl.hpp	(revision 459)
+++ /XIOS/trunk/src/attribute_enum_impl.hpp	(revision 460)
@@ -44,5 +44,11 @@
 
       ///--------------------------------------------------------------
-
+      template <class T>
+      void CAttributeEnum<T>::reset(void)
+      {
+         CEnum<T>::reset() ;
+         inheritedValue.reset() ;
+      }
+      
       template <class T>
       typename T::t_enum CAttributeEnum<T>::getValue(void) const
Index: /XIOS/trunk/src/attribute_template.hpp
===================================================================
--- /XIOS/trunk/src/attribute_template.hpp	(revision 459)
+++ /XIOS/trunk/src/attribute_template.hpp	(revision 460)
@@ -48,4 +48,5 @@
             void set(const CAttribute& attr) ;
             void set(const CAttributeTemplate& attr) ;
+            void reset(void) ;
 
             void setInheritedValue(const CAttributeTemplate& attr );
Index: /XIOS/trunk/src/attribute_template_impl.hpp
===================================================================
--- /XIOS/trunk/src/attribute_template_impl.hpp	(revision 459)
+++ /XIOS/trunk/src/attribute_template_impl.hpp	(revision 460)
@@ -60,4 +60,11 @@
 */
       ///--------------------------------------------------------------
+      template <class T>
+      void CAttributeTemplate<T>::reset(void)
+      {
+        CType<T>::reset() ;
+        inheritedValue.reset() ;
+      }
+
 
       template <class T>
Index: /XIOS/trunk/src/node/field.cpp
===================================================================
--- /XIOS/trunk/src/node/field.cpp	(revision 459)
+++ /XIOS/trunk/src/node/field.cpp	(revision 460)
@@ -25,5 +25,5 @@
       , last_Write(), last_operation()
       , foperation(), hasInstantData(false), hasExpression(false)
-      , active(false) , hasOutputFile(false), slotUpdateDate(NULL)
+      , active(false) , hasOutputFile(false),hasFieldOut(false), slotUpdateDate(NULL)
       , processed(false)
       { /* Ne rien faire de plus */ }
@@ -37,5 +37,5 @@
       , last_Write(), last_operation()
       , foperation(), hasExpression(false)
-      , active(false), hasOutputFile(false), slotUpdateDate(NULL)
+      , active(false), hasOutputFile(false), hasFieldOut(false), slotUpdateDate(NULL)
       , processed(false)
    { /* Ne rien faire de plus */ }
@@ -387,5 +387,5 @@
       using namespace func;
       
-      if (!hasOutputFile) return ;
+      if (!hasOutputFile && !hasFieldOut) return ;
       
       StdString id ;
@@ -418,8 +418,9 @@
       if (context->hasServer)
       {
-         this->freq_operation_srv =
-             CDuration::FromString(this->file->output_freq.getValue());
-         this->freq_write_srv     =
-             CDuration::FromString(this->file->output_freq.getValue());
+         if (hasOutputFile) 
+         {
+           this->freq_operation_srv =CDuration::FromString(this->file->output_freq.getValue());
+           this->freq_write_srv = CDuration::FromString(this->file->output_freq.getValue());
+         }
          this->lastlast_Write_srv     = boost::shared_ptr<CDate>
                         (new CDate(context->getCalendar()->getInitDate()));
@@ -431,6 +432,9 @@
 //             boost::shared_ptr<func::CFunctor>(new CInstant(this->data_srv));
              
-         const CDuration toffset = this->freq_operation_srv - freq_offset_ - context->getCalendar()->getTimeStep(); 
-         *this->last_operation_srv   = *this->last_operation_srv - toffset; 
+         if (hasOutputFile) 
+         {
+           const CDuration toffset = this->freq_operation_srv - freq_offset_ - context->getCalendar()->getTimeStep(); 
+           *this->last_operation_srv   = *this->last_operation_srv - toffset;
+         }
       }
       
@@ -438,5 +442,9 @@
 //      {                  
          this->freq_operation = CDuration::FromString(freq_op.getValue());
-         this->freq_write     = CDuration::FromString(this->file->output_freq.getValue());
+         if (hasOutputFile) this->freq_write     = CDuration::FromString(this->file->output_freq.getValue());
+         if (hasFieldOut) 
+         {
+           this->freq_write = CDuration::FromString(this->fieldOut->freq_op.getValue());
+         }
          this->last_Write     = boost::shared_ptr<CDate>
                         (new CDate(context->getCalendar()->getInitDate()));
@@ -665,11 +673,51 @@
       expression=CFieldNode::newNode(simpleExpr) ;
       delete simpleExpr ;
-      set<string> fieldIds ;
-      expression->getFieldIds(fieldIds) ;
-      for (set<string>::iterator it=fieldIds.begin() ; it!=fieldIds.end();++it) if (*it!="this") CField::get(*it)->processEnabledField() ;
-      
-      expression->reduce(this) ;
-
-      slots.resize(fieldIds.size()) ;
+      set<string> instantFieldIds ;
+      map<string,CField*> associatedInstantFieldIds ;
+      expression->getInstantFieldIds(instantFieldIds) ;
+      for (set<string>::iterator it=instantFieldIds.begin() ; it!=instantFieldIds.end();++it) 
+      {
+        if (*it!="this") 
+        {
+          if (CField::has(*it)) 
+          {
+            CField* field=CField::get(*it) ;
+            field->processEnabledField() ;
+            associatedInstantFieldIds[*it]=field ;
+          }
+          else  ERROR("void CField::buildExpression(void)",<<" Field "<<*it<<" does not exist") ;
+        }
+      }
+      
+      set<string> averageFieldIds ;
+      map<string,CField*> associatedAverageFieldIds ;
+
+      expression->getAverageFieldIds(averageFieldIds) ;
+      for (set<string>::iterator it=averageFieldIds.begin() ; it!=averageFieldIds.end();++it) 
+      {      
+        if (CField::has(*it)) 
+        {
+           CFieldGroup* root=CFieldGroup::get("field_definition") ;
+           CField* averageField=root->createChild() ;
+           CField* instantField=root->createChild() ;
+           averageField->field_ref=*it ;
+           averageField->hasFieldOut=true ;
+           averageField->fieldOut=instantField ;
+           instantField->freq_op=freq_op ;
+           averageField-> processEnabledField() ;
+           cout<<" outputfreq of averageField "<<  freq_op <<"  "<<instantField->freq_op<<"  "<< averageField->freq_write << endl ;
+           instantField->SuperClassAttribute::setAttributes(averageField, true);
+           instantField->field_ref.reset() ;
+           instantField->operation.reset() ;
+
+           instantField-> processEnabledField() ;
+           associatedAverageFieldIds[*it]=instantField  ;
+        }
+        else ERROR("void CField::buildExpression(void)",<<" Field "<<*it<<" does not exist") ;
+      }
+
+      expression->reduce(this,associatedInstantFieldIds,associatedAverageFieldIds) ;
+
+      slots.resize(instantFieldIds.size()+averageFieldIds.size()) ;
       resetSlots() ;
       int slotId=0 ;
Index: /XIOS/trunk/src/node/field.hpp
===================================================================
--- /XIOS/trunk/src/node/field.hpp	(revision 459)
+++ /XIOS/trunk/src/node/field.hpp	(revision 460)
@@ -95,4 +95,5 @@
          template <int N> bool updateData(const CArray<double, N>&   data);
          bool updateDataFromExpression(const CArray<double, 1>&   data);
+         void setDataFromExpression(const CArray<double, 1>& _data) ;         
          
          bool updateDataServer
@@ -107,4 +108,5 @@
          bool active ;
          bool hasOutputFile ;
+         bool hasFieldOut ;
 
          /// Traitements ///
@@ -143,4 +145,5 @@
          CGrid*  grid ;
          CFile*  file;
+         CField* fieldOut ;
 
          CDuration freq_operation, freq_write;
Index: /XIOS/trunk/src/node/field_impl.hpp
===================================================================
--- /XIOS/trunk/src/node/field_impl.hpp	(revision 459)
+++ /XIOS/trunk/src/node/field_impl.hpp	(revision 460)
@@ -28,9 +28,27 @@
      
       for (; it != end; it++) (*it)->setData(_data) ;
-      if (hasOutputFile) updateData(_data) ;
+      if (hasOutputFile || hasFieldOut) updateData(_data) ;
     }
      
   }
 
+  void CField::setDataFromExpression(const CArray<double, 1>& _data)
+  {
+    if (hasInstantData) 
+    {
+      instantData=_data; 
+      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second) ;
+    }
+    
+    if (!hasExpression)
+    {
+      const std::vector<CField*>& refField=getAllReference();
+      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end();
+     
+      for (; it != end; it++) (*it)->setData(_data) ;
+      if (hasOutputFile || hasFieldOut) updateData(_data) ;
+    }
+     
+  }
 
    template <int N>
@@ -82,8 +100,16 @@
          this->foperation->final();
          *last_Write = writeDate;
-         info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
-         CTimer::get("XIOS Send Data").resume() ;
-         sendUpdateData() ;
-         CTimer::get("XIOS Send Data").suspend() ;
+         if (hasOutputFile)
+         {
+           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
+           CTimer::get("XIOS Send Data").resume() ;
+           sendUpdateData() ;
+           CTimer::get("XIOS Send Data").suspend() ;
+         }
+         
+         if (hasFieldOut)
+         {
+           fieldOut->setDataFromExpression(data) ;
+         }
          return (true);        
       }
Index: /XIOS/trunk/src/parse_expr/expr_node.cpp
===================================================================
--- /XIOS/trunk/src/parse_expr/expr_node.cpp	(revision 459)
+++ /XIOS/trunk/src/parse_expr/expr_node.cpp	(revision 460)
@@ -34,5 +34,5 @@
   };
 
-  void CInstantFieldNode::reduce(CField* thisField)
+  void CInstantFieldNode::reduce(CField* thisField, map<string,CField*>& associatedInstantField, map<string,CField*>& associatedAverageField)
   {
     if (!reduced)
@@ -44,26 +44,21 @@
         reduced=true ;
       }
-      else if (CField::has(fieldId)) 
+      else
       {
-        field =CField::get(fieldId) ;
+        field=associatedInstantField[fieldId] ;
         array=field->getInstantData() ;
         reduced=true ;
       }
-      else ERROR("void CInstantFieldNode::reduce(void)",<<" Field "<<fieldId<<" does not exist")
-      }
+    }
   }   
 
-  void CAverageFieldNode::reduce(CField* thisField)
+  void CAverageFieldNode::reduce(CField* thisField, map<string,CField*>& associatedInstantField, map<string,CField*>& associatedAverageField)
   {
     if (!reduced)
     {
-      if (CField::has(fieldId)) 
-      {
-        field=thisField ;
-        array=CField::get(fieldId)->getInstantData() ;
-        reduced=true ;
-      }
-      else ERROR("void CAverageFieldNode::reduce(void)",<<" Field "<<fieldId<<" does not exist")
-      }
+      field=associatedAverageField[fieldId] ;
+      array=field->getInstantData() ;
+      reduced=true ;
+    }
   }
   
Index: /XIOS/trunk/src/parse_expr/expr_node.hpp
===================================================================
--- /XIOS/trunk/src/parse_expr/expr_node.hpp	(revision 459)
+++ /XIOS/trunk/src/parse_expr/expr_node.hpp	(revision 460)
@@ -193,8 +193,12 @@
     CFieldNode(void) : CNodeExpr() {}
     static CFieldNode* newNode(CSimpleNodeExpr* simpleNode) ;
-    virtual void reduce(CField* thisField = NULL) =0 ; 
+    virtual void reduce(CField* thisField, map<string,CField*>& associatedInstantField, map<string,CField*>& associatedAverageField) =0 ; 
     virtual CArray<double,1> compute(void)=0 ;
     virtual void getFieldIds(set<string>& fieldIds)=0 ;
+    virtual void getInstantFieldIds(set<string>& fieldIds)=0 ;
+    virtual void getAverageFieldIds(set<string>& fieldIds)=0 ;
     virtual void getFields(set<CField*>& fields)=0 ;
+    virtual void getInstantFields(set<CField*>& fields)=0 ;
+    virtual void getAverageFields(set<CField*>& fields)=0 ;
       
     virtual ~CFieldNode() {}
@@ -212,9 +216,13 @@
     public:
     CInstantFieldNode(CSimpleNodeExpr* simpleNode) : CFieldNode(), fieldId(simpleNode->id) {}
-    virtual void reduce(CField* thisField = NULL) ;
+    virtual void reduce(CField* thisField, map<string,CField*>& associatedInstantField, map<string,CField*>& associatedAverageField) ; 
     virtual CArray<double,1> compute(void) { return CArray<double,1>(*array);}
     virtual ~CInstantFieldNode() { }
     virtual void getFieldIds(set<string>& fieldIds) { fieldIds.insert(fieldId) ;}
+    virtual void getInstantFieldIds(set<string>& fieldIds) { fieldIds.insert(fieldId) ;}
+    virtual void getAverageFieldIds(set<string>& fieldIds) { }
     virtual void getFields(set<CField*>& fields) { fields.insert(field) ;}
+    virtual void getInstantFields(set<CField*>& fields) { fields.insert(field) ;}
+    virtual void getAverageFields(set<CField*>& fields) { }
        
     string fieldId;
@@ -238,8 +246,12 @@
     CAverageFieldNode(CSimpleNodeExpr* simpleNode) : CFieldNode(), fieldId(simpleNode->id) {}
     
-    virtual void reduce(CField* thisField = NULL) ;
+    virtual void reduce(CField* thisField, map<string,CField*>& associatedInstantField, map<string,CField*>& associatedAverageField) ; 
     virtual CArray<double,1> compute(void) { return CArray<double,1>(*array); }
     virtual void getFieldIds(set<string>& fieldIds) { fieldIds.insert(fieldId) ;}
+    virtual void getInstantFieldIds(set<string>& fieldIds) { }
+    virtual void getAverageFieldIds(set<string>& fieldIds) { fieldIds.insert(fieldId) ;}
     virtual void getFields(set<CField*>& fields) { fields.insert(field) ;}
+    virtual void getInstantFields(set<CField*>& fields) { } 
+    virtual void getAverageFields(set<CField*>& fields) { fields.insert(field) ;}
     virtual ~CAverageFieldNode() {}
     string fieldId;
@@ -264,7 +276,7 @@
     }
     
-    virtual void reduce(CField* thisField = NULL)
-    {
-      child->reduce(thisField) ;
+    virtual void reduce(CField* thisField, map<string,CField*>& associatedInstantField, map<string,CField*>& associatedAverageField) 
+    {
+      child->reduce(thisField, associatedInstantField, associatedAverageField) ;
       op=operatorExpr.getOpField(opId) ;
       reduced=true ;
@@ -272,6 +284,9 @@
     
     virtual void getFieldIds(set<string>& fieldIds) {child-> getFieldIds(fieldIds);}
-    virtual void getFields(set<CField*>& fields) {child-> getFields(fields);}
-    
+    virtual void getInstantFieldIds(set<string>& fieldIds) {child->  getInstantFieldIds(fieldIds) ;}
+    virtual void getAverageFieldIds(set<string>& fieldIds) {child->  getAverageFieldIds(fieldIds) ;}
+    virtual void getFields(set<CField*>& fields) { child-> getFields(fields) ;}
+    virtual void getInstantFields(set<CField*>& fields) {child-> getInstantFields(fields) ; } 
+    virtual void getAverageFields(set<CField*>& fields) {child-> getAverageFields(fields) ; }    
     virtual CArray<double,1> compute(void)
     {
@@ -303,8 +318,8 @@
     }
     
-    virtual void reduce(CField* thisField = NULL)
-    {
-      child1->reduce(thisField) ;
-      child2->reduce(thisField) ;
+    virtual void reduce(CField* thisField, map<string,CField*>& associatedInstantField, map<string,CField*>& associatedAverageField)
+    {
+      child1->reduce(thisField, associatedInstantField, associatedAverageField) ;
+      child2->reduce(thisField, associatedInstantField, associatedAverageField) ;
       op=operatorExpr.getOpFieldField(opId) ;
       reduced=true ;
@@ -312,5 +327,9 @@
 
     virtual void getFieldIds(set<string>& fieldIds) {child1-> getFieldIds(fieldIds); child2-> getFieldIds(fieldIds);}
+    virtual void getInstantFieldIds(set<string>& fieldIds) {child1-> getInstantFieldIds(fieldIds); child2-> getInstantFieldIds(fieldIds);}
+    virtual void getAverageFieldIds(set<string>& fieldIds) {child1-> getAverageFieldIds(fieldIds); child2-> getAverageFieldIds(fieldIds);}
     virtual void getFields(set<CField*>& fields) {child1-> getFields(fields); child2-> getFields(fields);}
+    virtual void getInstantFields(set<CField*>& fields) {child1-> getInstantFields(fields); child2-> getInstantFields(fields);}
+    virtual void getAverageFields(set<CField*>& fields) {child1-> getAverageFields(fields); child2-> getAverageFields(fields);}
 
     virtual CArray<double,1> compute(void)
@@ -344,8 +363,8 @@
     }
     
-    virtual void reduce(CField* thisField = NULL)
+    virtual void reduce(CField* thisField, map<string,CField*>& associatedInstantField, map<string,CField*>& associatedAverageField)
     {
       child1->reduce() ;
-      child2->reduce(thisField) ;
+      child2->reduce(thisField, associatedInstantField, associatedAverageField) ;
       op=operatorExpr.getOpScalarField(opId) ;
       reduced=true ;
@@ -353,5 +372,9 @@
    
     virtual void getFieldIds(set<string>& fieldIds) {child2-> getFieldIds(fieldIds);}
+    virtual void getInstantFieldIds(set<string>& fieldIds) {child2-> getInstantFieldIds(fieldIds);}
+    virtual void getAverageFieldIds(set<string>& fieldIds) {child2-> getAverageFieldIds(fieldIds);}
     virtual void getFields(set<CField*>& fields) {child2-> getFields(fields);}
+    virtual void getInstantFields(set<CField*>& fields) {child2-> getInstantFields(fields);}
+    virtual void getAverageFields(set<CField*>& fields) {child2-> getAverageFields(fields);}
 
     virtual CArray<double,1> compute(void)
@@ -385,7 +408,7 @@
     }
     
-    virtual void reduce(CField* thisField = NULL)
-    {
-      child1->reduce(thisField) ;
+    virtual void reduce(CField* thisField, map<string,CField*>& associatedInstantField, map<string,CField*>& associatedAverageField)
+    {
+      child1->reduce(thisField, associatedInstantField, associatedAverageField) ;
       child2->reduce() ;
       op=operatorExpr.getOpFieldScalar(opId) ;
@@ -399,5 +422,9 @@
     
     virtual void getFieldIds(set<string>& fieldIds) {child1-> getFieldIds(fieldIds);}
+    virtual void getInstantFieldIds(set<string>& fieldIds) {child1-> getInstantFieldIds(fieldIds);}
+    virtual void getAverageFieldIds(set<string>& fieldIds) {child1-> getAverageFieldIds(fieldIds);}
     virtual void getFields(set<CField*>& fields) {child1-> getFields(fields);}
+    virtual void getInstantFields(set<CField*>& fields) {child1-> getInstantFields(fields);}
+    virtual void getAverageFields(set<CField*>& fields) {child1-> getAverageFields(fields);}
 
     ~COperatorFieldScalarNode() {delete child1, delete child2; }
