Index: XIOS/trunk/src/node/axis.cpp
===================================================================
--- XIOS/trunk/src/node/axis.cpp	(revision 566)
+++ XIOS/trunk/src/node/axis.cpp	(revision 567)
@@ -6,4 +6,6 @@
 #include "message.hpp"
 #include "type.hpp"
+#include "context.hpp"
+#include "context_client.hpp"
 #include "xmlioserver_spl.hpp"
 
@@ -14,10 +16,10 @@
    CAxis::CAxis(void)
       : CObjectTemplate<CAxis>()
-      , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject()
+      , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject(), areClientAttributesChecked_(false)
    { /* Ne rien faire de plus */ }
 
    CAxis::CAxis(const StdString & id)
       : CObjectTemplate<CAxis>(id)
-      , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject()
+      , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject(), areClientAttributesChecked_(false)
    { /* Ne rien faire de plus */ }
 
@@ -52,5 +54,4 @@
    void CAxis::checkAttributes(void)
    {
-      if (this->isChecked) return;
       if (this->size.isEmpty())
          ERROR("CAxis::checkAttributes(void)",
@@ -76,23 +77,5 @@
       else this->ni.setValue(size);
 
-      StdSize zoom_begin,zoom_end, zoom_size;
-
-      // Maybe index begins at 0 (zero)
-      zoom_begin = (this->zoom_begin.isEmpty()) ?  0 : this->zoom_begin.getValue();
-      zoom_end = (this->zoom_end.isEmpty()) ?  size-1 : this->zoom_end.getValue();
-      zoom_size = (this->zoom_size.isEmpty()) ?  size : this->zoom_size.getValue();
-
-      if (this->zoom_begin.isEmpty()) zoom_begin=zoom_end-zoom_size+1;
-      if (this->zoom_end.isEmpty()) zoom_end=zoom_begin+zoom_size-1;
-      if (this->zoom_size.isEmpty()) zoom_size=zoom_end-zoom_begin+1;
-
-      if ( (zoom_begin < 0) || (zoom_begin > size-1) || (zoom_end<0) || (zoom_end>size-1) || (zoom_size<1) || (zoom_size>size) || (zoom_begin>zoom_end))
-        ERROR("CAxis::checkAttributes(void)",
               << "One or more attributes among <zoom_begin>, <zoom_end>, <zoom_size> of axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] are not well specified");
-
-      this->zoom_begin.setValue(zoom_begin);
-      this->zoom_end.setValue(zoom_end);
-      this->zoom_size.setValue(zoom_size);
-
       StdSize true_size = value.numElements();
       if (size != true_size)
@@ -102,5 +85,5 @@
       this->checkData();
       this->checkMask();
-      this->isChecked = true;
+      this->checkZoom();
    }
 
@@ -122,4 +105,30 @@
         for (int i = 0; i < dn; ++i) data_index(i) = (i+1);
       }
+   }
+
+   void CAxis::checkZoom(void)
+   {
+      StdSize zoom_begin,zoom_end, zoom_size;
+
+      zoom_begin = (this->zoom_begin.isEmpty()) ?  0 : this->zoom_begin.getValue() ;
+      zoom_size  = (this->zoom_size.isEmpty()) ?  size.getValue() : this->zoom_size.getValue() ;
+      zoom_end   = (this->zoom_end.isEmpty()) ?  (size.getValue() - 1) : this->zoom_end.getValue() ;
+
+      if (this->zoom_begin.isEmpty()) zoom_begin=zoom_end-zoom_size+1 ;
+      if (this->zoom_end.isEmpty()) zoom_end=zoom_begin+zoom_size-1 ;
+      if (this->zoom_size.isEmpty()) zoom_size=zoom_end-zoom_begin+1 ;
+
+      if ( (zoom_begin < 0) || (zoom_begin > size-1) || (zoom_end<0) || (zoom_end>size-1) || (zoom_size<1) || (zoom_size>size) || (zoom_begin>zoom_end))
+        ERROR("CAxis::checkAttributes(void)",<< "One or more attribut of <zoom_begin>, <zoom_end>, <zoom_size>, are not well specified") ;
+
+      this->zoom_begin.setValue(zoom_begin) ;
+      this->zoom_end.setValue(zoom_end) ;
+      this->zoom_size.setValue(zoom_size) ;
+
+      // compute client zoom indices
+//      zoom_begin_client = ibegin_client > zoom_begin ? begin_client : zoom_begin ;
+//      zoom_end_client   = iend_client < zoom_end ? iend_client : zoom_end ;
+//      zoom_size_client  = zoom_end_client-zoom_begin_client+1 ;
+//      if (zoom_ni_client<0) zoom_ni_client=0 ;
    }
 
@@ -166,4 +175,116 @@
    }
 
+  bool CAxis::dispatchEvent(CEventServer& event)
+   {
+      if (SuperClass::dispatchEvent(event)) return true ;
+      else
+      {
+        switch(event.type)
+        {
+           case EVENT_ID_SERVER_ATTRIBUT :
+             recvServerAttribut(event) ;
+             return true ;
+             break ;
+           default :
+             ERROR("bool CContext::dispatchEvent(CEventServer& event)",
+                    <<"Unknown Event") ;
+           return false ;
+         }
+      }
+   }
+
+   void CAxis::checkAttributesOnClient(const std::vector<int>& globalDim, int orderPositionInGrid,
+                                       CServerDistributionDescription::ServerDistributionType distType)
+   {
+     if (this->areClientAttributesChecked_) return;
+     this->checkAttributes();
+
+     CContext* context=CContext::getCurrent() ;
+     if (context->hasClient)
+     {
+       computeServerIndex(globalDim, orderPositionInGrid, distType);
+     }
+
+     this->areClientAttributesChecked_ = true;
+   }
+
+   void CAxis::computeServerIndex(const std::vector<int>& globalDim, int orderPositionInGrid,
+                                  CServerDistributionDescription::ServerDistributionType distType)
+   {
+     CServerDistributionDescription serverDescription(globalDim);
+
+     CContext* context=CContext::getCurrent() ;
+     CContextClient* client=context->client ;
+     int nbServer=client->serverSize ;
+     int serverRank=client->getServerLeader() ;
+
+     serverDescription.computeServerDistribution(nbServer, false, distType);
+     std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin();
+     std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes();
+     begin_srv = (serverIndexBegin[serverRank])[orderPositionInGrid];
+     ni_srv = serverDimensionSizes[serverRank][orderPositionInGrid];
+     end_srv = begin_srv+ni_srv-1;
+   }
+
+   // Send all checked attributes to server
+   void CAxis::sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid,
+                                     CServerDistributionDescription::ServerDistributionType distType)
+   {
+     if (!this->areClientAttributesChecked_) checkAttributesOnClient(globalDim,
+                                                                     orderPositionInGrid,
+                                                                     distType);
+     CContext* context=CContext::getCurrent() ;
+
+     if (this->isChecked) return;
+     if (context->hasClient)
+     {
+       sendServerAttribut() ;
+     }
+
+     this->isChecked = true;
+   }
+
+  void CAxis::sendServerAttribut(void)
+  {
+    CContext* context=CContext::getCurrent();
+    CContextClient* client=context->client;
+
+    CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ;
+    if (client->isServerLeader())
+    {
+      CMessage msg ;
+      msg<<this->getId() ;
+      msg<<ni_srv<<begin_srv<<end_srv;
+      event.push(client->getServerLeader(),1,msg) ;
+      client->sendEvent(event) ;
+    }
+    else client->sendEvent(event) ;
+  }
+
+  void CAxis::recvServerAttribut(CEventServer& event)
+  {
+    CBufferIn* buffer=event.subEvents.begin()->buffer;
+    string axisId ;
+    *buffer>>axisId ;
+    get(axisId)->recvServerAttribut(*buffer) ;
+  }
+
+  void CAxis::recvServerAttribut(CBufferIn& buffer)
+  {
+    int zoom_end = zoom_begin.getValue()+zoom_size.getValue()-1;
+    int ni_srv, begin_srv, end_srv;
+
+    buffer>>ni_srv>>begin_srv>>end_srv;
+
+    zoom_begin_srv = zoom_begin.getValue() > begin_srv ? zoom_begin.getValue() : begin_srv ;
+    zoom_end_srv   = zoom_end < end_srv ? zoom_end : end_srv ;
+    zoom_size_srv  = zoom_end_srv-zoom_begin_srv+1 ;
+
+    if (zoom_size_srv<=0)
+    {
+      zoom_begin_srv=0 ; zoom_end_srv=0 ; zoom_size_srv=0 ;
+    }
+  }
+
    DEFINE_REF_FUNC(Axis,axis)
 
