Index: XIOS/dev/dev_olga/arch/arch-GCC_LINUX.env
===================================================================
--- XIOS/trunk/arch/arch-GCC_LINUX.env	(revision 981)
+++ XIOS/dev/dev_olga/arch/arch-GCC_LINUX.env	(revision 983)
@@ -1,4 +1,4 @@
-export HDF5_INC_DIR=$HOME/hdf5/include
-export HDF5_LIB_DIR=$HOME/hdf5/lib
+export HDF5_INC_DIR=$HOME/hdf5/hdf5/include
+export HDF5_LIB_DIR=$HOME/hdf5/hdf5/lib
 
 export NETCDF_INC_DIR=$HOME/netcdf4/include
Index: XIOS/dev/dev_olga/arch/arch-GCC_LINUX.fcm
===================================================================
--- XIOS/trunk/arch/arch-GCC_LINUX.fcm	(revision 981)
+++ XIOS/dev/dev_olga/arch/arch-GCC_LINUX.fcm	(revision 983)
@@ -12,5 +12,5 @@
 %DEBUG_CFLAGS   -g 
 
-%BASE_FFLAGS    -D__NONE__ 
+%BASE_FFLAGS    -D__NONE__ -ffree-line-length-none 
 %PROD_FFLAGS    -O3
 %DEV_FFLAGS     -g -O2
Index: XIOS/dev/dev_olga/arch/arch-GCC_LINUX.path
===================================================================
--- XIOS/trunk/arch/arch-GCC_LINUX.path	(revision 981)
+++ XIOS/dev/dev_olga/arch/arch-GCC_LINUX.path	(revision 983)
@@ -5,5 +5,5 @@
 MPI_INCDIR=""
 MPI_LIBDIR=""
-MPI_LIB=""
+MPI_LIB="-lcurl"
 
 HDF5_INCDIR="-I $HDF5_INC_DIR"
Index: XIOS/dev/dev_olga/arch/arch-X64_CURIE.fcm
===================================================================
--- XIOS/trunk/arch/arch-X64_CURIE.fcm	(revision 981)
+++ XIOS/dev/dev_olga/arch/arch-X64_CURIE.fcm	(revision 983)
@@ -14,5 +14,5 @@
 %BASE_FFLAGS    -D__NONE__ 
 %PROD_FFLAGS    -O3
-%DEV_FFLAGS     -g -O2 -traceback
+%DEV_FFLAGS     -g -traceback
 %DEBUG_FFLAGS   -g -traceback
 
Index: XIOS/dev/dev_olga/bld.cfg
===================================================================
--- XIOS/trunk/bld.cfg	(revision 981)
+++ XIOS/dev/dev_olga/bld.cfg	(revision 983)
@@ -32,7 +32,10 @@
 bld::target libxios.a 
 #bld::target generate_fortran_interface.exe 
-bld::target xios_server.exe test_remap.exe
-bld::target test_new_features.exe test_unstruct_complete.exe 
-bld::target test_client.exe test_complete.exe
+#bld::target xios_server.exe #test_remap.exe
+bld::target xios_server.exe 
+bld::target xios_server1.exe xios_server2.exe
+#bld::target test_new_features.exe test_unstruct_complete.exe 
+#bld::target test_client.exe test_complete.exe
+bld::target test_client.exe
 bld::exe_dep
 
Index: XIOS/dev/dev_olga/inputs/iodef.xml
===================================================================
--- XIOS/trunk/inputs/iodef.xml	(revision 981)
+++ XIOS/dev/dev_olga/inputs/iodef.xml	(revision 983)
@@ -14,5 +14,5 @@
    <file_definition type="multiple_file" par_access="collective" output_freq="6h" output_level="10" enabled=".TRUE.">
      <file id="output" name="output">
-        <field field_ref="field_A_zoom" name="field_A" />
+        <field field_ref="field_A" name="field_A" />
      </file>
    </file_definition>
Index: XIOS/dev/dev_olga/src/buffer_client.cpp
===================================================================
--- XIOS/trunk/src/buffer_client.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/buffer_client.cpp	(revision 983)
@@ -86,5 +86,10 @@
       if (count > 0)
       {
-        MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
+        MPI_Comm_test_inter(interComm, &flag);
+//        if (flag)
+          MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
+//        else
+//          ERROR("bool CClientBuffer::checkBuffer(void)",
+//                << "Invalid intercommunicator");
         pending = true;
         if (current == 1) current = 0;
Index: XIOS/dev/dev_olga/src/client.cpp
===================================================================
--- XIOS/trunk/src/client.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/client.cpp	(revision 983)
@@ -18,5 +18,5 @@
     MPI_Comm CClient::interComm ;
     std::list<MPI_Comm> CClient::contextInterComms;
-    int CClient::serverLeader ;
+    int CClient::serverLeader;
     bool CClient::is_MPI_Initialized ;
     int CClient::rank = INVALID_RANK;
@@ -24,5 +24,14 @@
     StdOFStream CClient::m_errorStream;
 
-    void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm)
+///---------------------------------------------------------------
+/*!
+ * \fn void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
+ * Function creates intraComm (CClient::intraComm) for client group with id=codeId and interComm (CClient::interComm) between client and server groups.
+ * \param [in] codeId identity of context.
+ * \param [in/out] localComm local communicator.
+ * \param [in/out] returnComm (intra)communicator of client group.
+ */
+
+    void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm)
     {
       int initialized ;
@@ -34,5 +43,5 @@
       if (!CXios::usingOasis)
       {
-// localComm doesn't given
+// localComm isn't given
         if (localComm == MPI_COMM_NULL)
         {
@@ -45,6 +54,6 @@
           boost::hash<string> hashString ;
 
-          unsigned long hashClient=hashString(codeId) ;
-          unsigned long hashServer=hashString(CXios::xiosCodeId) ;
+          unsigned long hashClient = hashString(codeId) ;
+          unsigned long hashServer = hashString(CXios::xiosCodeIdPrm);
           unsigned long* hashAll ;
           int size ;
@@ -58,5 +67,5 @@
           hashAll=new unsigned long[size] ;
 
-          MPI_Allgather(&hashClient,1,MPI_LONG,hashAll,1,MPI_LONG,CXios::globalComm) ;
+          MPI_Allgather(&hashClient, 1, MPI_LONG, hashAll, 1, MPI_LONG, CXios::globalComm) ;
 
           map<unsigned long, int> colors ;
@@ -77,5 +86,7 @@
           for (i=0; i < size; ++i)
           {
-            if (hashServer == hashAll[i])
+            if ((hashAll[i] == hashString(CXios::xiosCodeId))
+                || (hashAll[i] == hashString(CXios::xiosCodeIdPrm))
+                || (hashAll[i] == hashString(CXios::xiosCodeIdSnd)))
             {
               CXios::setUsingServer();
@@ -85,5 +96,4 @@
 
           myColor=colors[hashClient] ;
-
           MPI_Comm_split(CXios::globalComm,myColor,rank,&intraComm) ;
 
@@ -92,11 +102,10 @@
             int clientLeader=leaders[hashClient] ;
             serverLeader=leaders[hashServer] ;
-
             int intraCommSize, intraCommRank ;
             MPI_Comm_size(intraComm,&intraCommSize) ;
             MPI_Comm_rank(intraComm,&intraCommRank) ;
             info(50)<<"intercommCreate::client "<<rank<<" intraCommSize : "<<intraCommSize
-                 <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< serverLeader<<endl ;
-            MPI_Intercomm_create(intraComm,0,CXios::globalComm,serverLeader,0,&interComm) ;
+                   <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< serverLeader<<endl ;
+             MPI_Intercomm_create(intraComm,0,CXios::globalComm,serverLeader,0,&interComm) ;
           }
           else
@@ -123,5 +132,5 @@
       else
       {
-        // localComm doesn't given
+        // localComm isn't given
         if (localComm == MPI_COMM_NULL)
         {
@@ -150,6 +159,24 @@
     }
 
-
-    void CClient::registerContext(const string& id,MPI_Comm contextComm)
+    void CClient::initializeClientOnServer(const int rank, MPI_Comm& intraCommPrmSrv, const int srvSndLeader)
+    {
+      MPI_Comm_dup(intraCommPrmSrv, &intraComm) ;
+      serverLeader = srvSndLeader;
+      int intraCommSize, intraCommRank ;
+      MPI_Comm_size(intraComm,&intraCommSize) ;
+      MPI_Comm_rank(intraComm,&intraCommRank) ;
+      info(50)<<"intercommCreate::client "<<rank<<" intraCommSize : "<<intraCommSize
+          <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< serverLeader<<endl ;
+      MPI_Intercomm_create(intraComm, 0, CXios::globalComm, serverLeader, 0, &interComm) ;
+    }
+
+///---------------------------------------------------------------
+/*!
+ * \fn void CClient::registerContext(const string& id, MPI_Comm contextComm)
+ * Function creates intraComm (CClient::intraComm) for client group with id=codeId and interComm (CClient::interComm) between client and server groups.
+ * \param [in] id id of context.
+ * \param [in] contextComm.
+ */
+    void CClient::registerContext(const string& id, MPI_Comm contextComm)
     {
       CContext::setCurrent(id) ;
@@ -158,5 +185,23 @@
       idServer += "_server";
 
-      if (!CXios::isServer)
+      if (CXios::isServer && !context->hasServer)
+      // Attached mode
+      {
+        MPI_Comm contextInterComm ;
+        MPI_Comm_dup(contextComm,&contextInterComm) ;
+        CContext* contextServer = CContext::create(idServer);
+
+        // Firstly, initialize context on client side
+        context->initClient(contextComm,contextInterComm, contextServer);
+
+        // Secondly, initialize context on server side
+        contextServer->initServer(contextComm,contextInterComm, context);
+
+        // Finally, we should return current context to context client
+        CContext::setCurrent(id);
+
+        contextInterComms.push_back(contextInterComm);
+      }
+      else
       {
         int size,rank,globalRank ;
@@ -170,5 +215,4 @@
         if (rank!=0) globalRank=0 ;
 
-
         CMessage msg ;
         msg<<idServer<<size<<globalRank ;
@@ -180,8 +224,8 @@
         buffer<<msg ;
 
-        MPI_Send(buff,buffer.count(),MPI_CHAR,serverLeader,1,CXios::globalComm) ;
+        MPI_Send(buff, buffer.count(), MPI_CHAR, serverLeader, 1, CXios::globalComm) ;
         delete [] buff ;
 
-        MPI_Intercomm_create(contextComm,0,CXios::globalComm,serverLeader,10+globalRank,&contextInterComm) ;
+        MPI_Intercomm_create(contextComm, 0, CXios::globalComm, serverLeader, 10+globalRank, &contextInterComm) ;
         info(10)<<"Register new Context : "<<id<<endl ;
 
@@ -195,21 +239,4 @@
         MPI_Comm_free(&inter);
       }
-      else
-      {
-        MPI_Comm contextInterComm ;
-        MPI_Comm_dup(contextComm,&contextInterComm) ;
-        CContext* contextServer = CContext::create(idServer);
-
-        // Firstly, initialize context on client side
-        context->initClient(contextComm,contextInterComm, contextServer);
-
-        // Secondly, initialize context on server side
-        contextServer->initServer(contextComm,contextInterComm, context);
-
-        // Finally, we should return current context to context client
-        CContext::setCurrent(id);
-
-        contextInterComms.push_back(contextInterComm);
-      }
     }
 
@@ -221,5 +248,5 @@
       MPI_Comm_rank(intraComm,&rank) ;
  
-      if (!CXios::isServer)
+      if ((!CXios::isServer) || (CXios::serverLevel == 1))
       {
         MPI_Comm_rank(intraComm,&rank) ;
@@ -252,4 +279,5 @@
       report(0)<< " Memory report : Minimum buffer size required : " << CClientBuffer::maxRequestSize << " bytes" << endl ;
       report(0)<< " Memory report : increasing it by a factor will increase performance, depending of the volume of data wrote in file at each time step of the file"<<endl ;
+
    }
 
Index: XIOS/dev/dev_olga/src/client.hpp
===================================================================
--- XIOS/trunk/src/client.hpp	(revision 981)
+++ XIOS/dev/dev_olga/src/client.hpp	(revision 983)
@@ -11,4 +11,5 @@
       public:
         static void initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm);
+        static void initializeClientOnServer(const int rank, MPI_Comm& localComm, const int srvSndLeader);
         static void finalize(void);
         static void registerContext(const string& id, MPI_Comm contextComm);
Index: XIOS/dev/dev_olga/src/config/file_attribute.conf
===================================================================
--- XIOS/trunk/src/config/file_attribute.conf	(revision 981)
+++ XIOS/dev/dev_olga/src/config/file_attribute.conf	(revision 983)
@@ -20,7 +20,8 @@
 DECLARE_ATTRIBUTE(StdString, time_counter_name)
 DECLARE_ATTRIBUTE(int,       record_offset)
-DECLARE_ATTRIBUTE(bool,       cyclic)
+DECLARE_ATTRIBUTE(bool,      cyclic)
 
 DECLARE_ATTRIBUTE(int,       compression_level)
+DECLARE_ATTRIBUTE(bool,      coupler)
 
 DECLARE_ENUM4(timeseries,    none, only, both, exclusive)
Index: XIOS/dev/dev_olga/src/context_client.cpp
===================================================================
--- XIOS/trunk/src/context_client.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/context_client.cpp	(revision 983)
@@ -18,5 +18,5 @@
     \param [in] intraComm_ communicator of group client
     \param [in] interComm_ communicator of group server
-    \cxtSer [in] cxtSer Pointer to context of server side. (It is only used on case of attached mode)
+    \cxtSer [in] cxtSer Pointer to context of server side. (It is only used in case of attached mode).
     */
     CContextClient::CContextClient(CContext* parent, MPI_Comm intraComm_, MPI_Comm interComm_, CContext* cxtSer)
Index: XIOS/dev/dev_olga/src/context_server.cpp
===================================================================
--- XIOS/trunk/src/context_server.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/context_server.cpp	(revision 983)
@@ -34,4 +34,5 @@
     if (flag) MPI_Comm_remote_size(interComm,&commSize);
     else  MPI_Comm_size(interComm,&commSize);
+
     currentTimeLine=0;
     scheduled=false;
@@ -159,5 +160,4 @@
       count=buffer.remain();
     }
-
   }
 
@@ -220,10 +220,10 @@
       info(20)<<"Server Side context <"<<context->getId()<<"> finalized"<<endl;
       std::map<int, StdSize>::const_iterator itbMap = mapBufferSize_.begin(),
-                                             iteMap = mapBufferSize_.end(), itMap;
+                           iteMap = mapBufferSize_.end(), itMap;
       StdSize totalBuf = 0;
       for (itMap = itbMap; itMap != iteMap; ++itMap)
       {
         report(10)<< " Memory report : Context <"<<context->getId()<<"> : server side : memory used for buffer of each connection to client" << endl
-                  << "  +) With client of rank " << itMap->first << " : " << itMap->second << " bytes " << endl;
+            << "  +) With client of rank " << itMap->first << " : " << itMap->second << " bytes " << endl;
         totalBuf += itMap->second;
       }
Index: XIOS/dev/dev_olga/src/context_server.hpp
===================================================================
--- XIOS/trunk/src/context_server.hpp	(revision 981)
+++ XIOS/dev/dev_olga/src/context_server.hpp	(revision 983)
@@ -48,4 +48,5 @@
     private:
       std::map<int, StdSize> mapBufferSize_;
+
   } ;
 
Index: XIOS/dev/dev_olga/src/cxios.cpp
===================================================================
--- XIOS/trunk/src/cxios.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/cxios.cpp	(revision 983)
@@ -16,9 +16,14 @@
   string CXios::rootFile="./iodef.xml" ;
   string CXios::xiosCodeId="xios.x" ;
+  string CXios::xiosCodeIdPrm="xios.x.1" ;
+  string CXios::xiosCodeIdSnd="xios.x.2" ;
   string CXios::clientFile="./xios_client";
   string CXios::serverFile="./xios_server";
+  string CXios::serverPrimFile="./xios_server1";
+  string CXios::serverScndFile="./xios_server2";
 
   bool CXios::isClient ;
   bool CXios::isServer ;
+  int CXios::serverLevel = 0 ;
   MPI_Comm CXios::globalComm ;
   bool CXios::usingOasis ;
@@ -127,9 +132,14 @@
 
   //! Initialize server then put it into listening state
-  void CXios::initServerSide(void)
+  void CXios::initServerSide(int serverLvl)
   {
     initServer();
-    isClient = false;
+    if (serverLvl == 1)
+      isClient = true;
+    else
+      isClient = false;
+
     isServer = true;
+    serverLevel = serverLvl;
 
     // Initialize all aspects MPI
@@ -139,6 +149,19 @@
     if (printLogs2Files)
     {
-      CServer::openInfoStream(serverFile);
-      CServer::openErrorStream(serverFile);
+      if (CXios::serverLevel == 0)
+      {
+        CServer::openInfoStream(serverFile);
+        CServer::openErrorStream(serverFile);
+      }
+      else if (CXios::serverLevel == 1)
+      {
+        CServer::openInfoStream(serverPrimFile);
+        CServer::openErrorStream(serverPrimFile);
+      }
+      else
+      {
+        CServer::openInfoStream(serverScndFile);
+        CServer::openErrorStream(serverScndFile);
+      }
     }
     else
@@ -174,4 +197,10 @@
   }
 
+  //! Set using secondary server
+//  void CXios::setUsingSecondaryServer()
+//  {
+//    usingSecondaryServer = true;
+//  }
+
   //! Unset using server
   void CXios::setNotUsingServer()
Index: XIOS/dev/dev_olga/src/cxios.hpp
===================================================================
--- XIOS/trunk/src/cxios.hpp	(revision 981)
+++ XIOS/dev/dev_olga/src/cxios.hpp	(revision 983)
@@ -16,5 +16,5 @@
      static void initialize(void) ;
      static void initClientSide(const string & codeId, MPI_Comm& localComm, MPI_Comm& returnComm) ;
-     static void initServerSide(void) ;
+     static void initServerSide(int serverLevel) ;
      static void clientFinalize(void) ;
      static void parseFile(const string& filename) ;
@@ -29,9 +29,15 @@
      static string rootFile ; //!< Configuration filename
      static string xiosCodeId ; //!< Identity for XIOS
-     static string clientFile; //!< Filename template for client
-     static string serverFile; //!< Filename template for server
+     static string xiosCodeIdPrm ; //!< Identity for XIOS primary server
+     static string xiosCodeIdSnd ; //!< Identity for XIOS secondary server
+     static string clientFile;        //!< Filename template for client
+     static string serverFile;        //!< Filename template for server
+     static string serverPrimFile;  //!< Filename template for primary server in case of two server groups
+     static string serverScndFile;  //!< Filename template for secondary server in case of two server groups
 
      static bool isClient ; //!< Check if xios is client
-     static bool isServer ; //!< Check if xios is server
+     static bool isServer ; //!< Check if xios is primary server
+
+     static int serverLevel ; //
 
      static MPI_Comm globalComm ; //!< Global communicator
@@ -50,4 +56,7 @@
      static void setUsingServer();
 
+     //! Setting xios to use secondary server mode
+//     static void setUsingSecondaryServer();
+
      //! Setting xios NOT to use server mode
      static void setNotUsingServer();
Index: XIOS/dev/dev_olga/src/distribution_client.cpp
===================================================================
--- XIOS/trunk/src/distribution_client.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/distribution_client.cpp	(revision 983)
@@ -10,4 +10,32 @@
 
 namespace xios {
+
+CDistributionClient::CDistributionClient(int rank, const GlobalLocalDataMap& globalLocalIndex)
+  : CDistribution(rank, 0)
+   , axisDomainOrder_()
+   , nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_()
+   , dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_()
+   , gridMask_(), indexMap_()
+   , isDataDistributed_(true), axisNum_(0), domainNum_(0)
+   , localDataIndex_(), localMaskIndex_()
+   , globalLocalDataSendToServerMap_(globalLocalIndex)
+   , infoIndex_(), isComputed_(false)
+   , elementLocalIndex_(), elementGlobalIndex_(), elementIndexData_()
+   , elementZoomMask_(), elementNLocal_(), elementNGlobal_()
+{
+//  numElement_ = globalLocalIndex.size();    !!! numElement_ should be calculated !!!!
+  isComputed_ = true;  // my changes
+
+
+  localDataIndex_.resize(globalLocalIndex.size());
+  localMaskIndex_.resize(globalLocalIndex.size());
+  GlobalLocalDataMap::const_iterator it = globalLocalIndex.begin(), ite = globalLocalIndex.end();
+  int idx = 0;
+  for (; it!=ite; ++it)
+  {
+    localMaskIndex_[idx] = localDataIndex_[idx] = it->second;
+    ++idx;
+  }
+}
 
 CDistributionClient::CDistributionClient(int rank, int dims, const CArray<size_t,1>& globalIndex)
Index: XIOS/dev/dev_olga/src/distribution_client.hpp
===================================================================
--- XIOS/trunk/src/distribution_client.hpp	(revision 981)
+++ XIOS/dev/dev_olga/src/distribution_client.hpp	(revision 983)
@@ -34,4 +34,5 @@
   public:
     /** Default constructor */
+    CDistributionClient(int rank, const GlobalLocalDataMap& globalLocalIndex);
     CDistributionClient(int rank, int dims, const CArray<size_t,1>& globalIndex = CArray<size_t,1>());
     CDistributionClient(int rank, CGrid* grid);
Index: XIOS/dev/dev_olga/src/distribution_server.hpp
===================================================================
--- XIOS/trunk/src/distribution_server.hpp	(revision 981)
+++ XIOS/dev/dev_olga/src/distribution_server.hpp	(revision 983)
@@ -37,4 +37,5 @@
     const std::vector<int>& getZoomBeginServer() const;
     const std::vector<int>& getZoomSizeServer() const;
+    const GlobalLocalMap& getGlobalLocalIndex() const { return globalLocalIndexMap_; }
 
     virtual CArray<size_t,1> computeLocalIndex(const CArray<size_t,1>& globalIndex);
Index: XIOS/dev/dev_olga/src/interface/c/icdata.cpp
===================================================================
--- XIOS/trunk/src/interface/c/icdata.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/interface/c/icdata.cpp	(revision 983)
@@ -47,7 +47,7 @@
    }
 
-   void cxios_init_server(void)
-   {
-     CXios::initServerSide();
+   void cxios_init_server(int server_level)
+   {
+     CXios::initServerSide(server_level);
    }
 
Index: XIOS/dev/dev_olga/src/interface/fortran/idata.F90
===================================================================
--- XIOS/trunk/src/interface/fortran/idata.F90	(revision 981)
+++ XIOS/dev/dev_olga/src/interface/fortran/idata.F90	(revision 983)
@@ -7,5 +7,7 @@
    INTERFACE ! Ne pas appeler directement/Interface FORTRAN 2003 <-> C99
 
-      SUBROUTINE  cxios_init_server() BIND(C)
+      SUBROUTINE  cxios_init_server(server_level) BIND(C)
+         USE ISO_C_BINDING
+         INTEGER  (kind = C_INT)    , VALUE         :: server_level
       END SUBROUTINE cxios_init_server
 
@@ -451,7 +453,8 @@
    CONTAINS ! Fonctions disponibles pour les utilisateurs.
 
-   SUBROUTINE  xios(init_server)()
-   IMPLICIT NONE
-     CALL cxios_init_server()
+   SUBROUTINE  xios(init_server)(server_level)
+   IMPLICIT NONE
+       INTEGER  (kind = C_INT), INTENT(IN)         :: server_level
+       CALL cxios_init_server(server_level)
    END SUBROUTINE xios(init_server)
 
Index: XIOS/dev/dev_olga/src/node/calendar_wrapper.cpp
===================================================================
--- XIOS/trunk/src/node/calendar_wrapper.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/node/calendar_wrapper.cpp	(revision 983)
@@ -7,5 +7,5 @@
 namespace xios {
 
-  /// ////////////////////// DÃ©finitions ////////////////////// ///
+  /// ////////////////////// Dfinitions ////////////////////// ///
 
   CCalendarWrapper::CCalendarWrapper(void)
@@ -83,5 +83,5 @@
   {
     // Create the calendar if possible
-    if (calendar)
+    if (0 != calendar)
     {
       ERROR("CCalendarWrapper::createCalendar(void)",
Index: XIOS/dev/dev_olga/src/node/context.cpp
===================================================================
--- XIOS/trunk/src/node/context.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/node/context.cpp	(revision 983)
@@ -24,12 +24,14 @@
    CContext::CContext(void)
       : CObjectTemplate<CContext>(), CContextAttributes()
-      , calendar(), hasClient(false), hasServer(false), isPostProcessed(false), finalized(false)
-      , idServer_(), client(0), server(0)
+      , calendar(), hasClient(false), hasServer(false)
+      , isPostProcessed(false), finalized(false)
+      , idServer_(), client(0), server(0), clientPrimServer(0), serverPrimServer(0)
    { /* Ne rien faire de plus */ }
 
    CContext::CContext(const StdString & id)
       : CObjectTemplate<CContext>(id), CContextAttributes()
-      , calendar(), hasClient(false), hasServer(false), isPostProcessed(false), finalized(false)
-      , idServer_(), client(0), server(0)
+      , calendar(), hasClient(false), hasServer(false)
+      , isPostProcessed(false), finalized(false)
+      , idServer_(), client(0), server(0), clientPrimServer(0), serverPrimServer(0)
    { /* Ne rien faire de plus */ }
 
@@ -38,4 +40,6 @@
      delete client;
      delete server;
+     delete clientPrimServer;
+     delete serverPrimServer;
    }
 
@@ -238,6 +242,17 @@
    void CContext::initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer /*= 0*/)
    {
-     hasClient=true;
-     client = new CContextClient(this,intraComm, interComm, cxtServer);
+
+     hasClient = true;
+     if (CXios::serverLevel != 1)  // initClient is called by client pool
+     {
+       client = new CContextClient(this, intraComm, interComm, cxtServer);
+       server = new CContextServer(this, intraComm, interComm);
+     }
+     else                         // initClient is called by primary server pool
+     {
+       clientPrimServer = new CContextClient(this, intraComm, interComm);
+       serverPrimServer = new CContextServer(this, intraComm, interComm);
+     }
+
      registryIn=new CRegistry(intraComm);
      registryIn->setPath(getId()) ;
@@ -261,5 +276,4 @@
        comms.push_back(interCommServer);
      }
-     server = new CContextServer(this,intraCommServer,interCommServer);
    }
 
@@ -300,6 +314,18 @@
          if (!bufferSize.count(*itRank)) bufferSize[*itRank] = maxEventSize[*itRank] = minBufferSize;
      }
-
      client->setBufferSize(bufferSize, maxEventSize);
+
+     // If it is primary server pool, also set buffer for clientPrimServer.
+     if (hasClient && hasServer)
+     {
+       if (clientPrimServer->isServerLeader())
+       {
+         const std::list<int>& ranks = clientPrimServer->getRanksServerLeader();
+         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+           if (!bufferSize.count(*itRank)) bufferSize[*itRank] = maxEventSize[*itRank] = minBufferSize;
+       }
+       clientPrimServer->setBufferSize(bufferSize, maxEventSize);
+     }
+
    }
 
@@ -310,9 +336,10 @@
    }
 
-   //! Initialize server
-   void CContext::initServer(MPI_Comm intraComm,MPI_Comm interComm, CContext* cxtClient /*= 0*/)
+   void CContext::initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient /*= 0*/)
    {
      hasServer=true;
      server = new CContextServer(this,intraComm,interComm);
+     client = new CContextClient(this,intraComm,interComm);
+//     client = new CContextClient(this,intraComm,interComm, cxtClient);
 
      registryIn=new CRegistry(intraComm);
@@ -336,5 +363,5 @@
        comms.push_back(interCommClient);
      }
-     client = new CContextClient(this,intraCommClient,interCommClient, cxtClient);
+
    }
 
@@ -342,5 +369,18 @@
    bool CContext::eventLoop(void)
    {
-     return server->eventLoop();
+     if (CXios::serverLevel == 0)
+     {
+       return server->eventLoop();
+     }
+     else if (CXios::serverLevel == 1)
+     {
+       bool serverFinished = server->eventLoop();
+       bool serverPrimFinished = serverPrimServer->eventLoop();
+       return ( serverFinished && serverPrimFinished);
+     }
+     else
+     {
+       return server->eventLoop();
+     }
    }
 
@@ -348,6 +388,22 @@
    bool CContext::checkBuffersAndListen(void)
    {
-     client->checkBuffers();
-     return server->eventLoop();
+     if (CXios::serverLevel == 0)
+     {
+       client->checkBuffers();
+       return server->eventLoop();
+     }
+     else if (CXios::serverLevel == 1)
+     {
+       client->checkBuffers();
+       clientPrimServer->checkBuffers();
+       bool serverFinished = server->eventLoop();
+       bool serverPrimFinished = serverPrimServer->eventLoop();
+       return ( serverFinished && serverPrimFinished);
+     }
+     else if (CXios::serverLevel == 2)
+     {
+       client->checkBuffers();
+       return server->eventLoop();
+     }
    }
 
@@ -359,8 +415,48 @@
         finalized = true;
         if (hasClient) sendRegistry() ;
+
+/*        if (CXios::serverLevel == 0)
+        {
+          client->finalize();
+          while (!server->hasFinished())
+          {
+            server->eventLoop();
+          }
+        }
+        else if (CXios::serverLevel == 1)
+        {
+          clientPrimServer->finalize();
+          while (!serverPrimServer->hasFinished())
+          {
+            serverPrimServer->eventLoop();
+          }
+          client->finalize();
+          while (!server->hasFinished())
+          {
+            server->eventLoop();
+          }
+        }
+        else if (CXios::serverLevel == 2)
+        {
+          client->finalize();
+          while (!server->hasFinished())
+          {
+            server->eventLoop();
+          }
+        }*/
+
         client->finalize();
         while (!server->hasFinished())
         {
           server->eventLoop();
+        }
+
+        if ((hasClient) && (hasServer))
+        {
+          clientPrimServer->finalize();
+          while (!serverPrimServer->hasFinished())
+          {
+            serverPrimServer->eventLoop();
+          }
         }
 
@@ -391,11 +487,14 @@
      // There is nothing client need to send to server
      if (hasClient)
+//     if (hasClient && !hasServer)
      {
        // After xml is parsed, there are some more works with post processing
        postProcessing();
      }
+
      setClientServerBuffer();
 
-     if (hasClient && !hasServer)
+//     if (hasClient && !hasServer)
+     if (hasClient)
      {
       // Send all attributes of current context to server
@@ -417,28 +516,37 @@
       // After that, send all grid (if any)
        sendRefGrid();
-    }
+
+       // We have a xml tree on the server side and now, it should be also processed
+       sendPostProcessing();
+     }
+
+//     // Now tell server that it can process all messages from client
+// //    if (hasClient && !hasServer) this->sendCloseDefinition();
+     if (hasClient) this->sendCloseDefinition();
 
     // We have a xml tree on the server side and now, it should be also processed
-    if (hasClient && !hasServer) sendPostProcessing();
+//    if (hasClient && !hasServer) sendPostProcessing();
 
     // There are some processings that should be done after all of above. For example: check mask or index
-    if (hasClient)
+     if (hasClient && !hasServer)
+//    if (hasClient)
     {
-      this->buildFilterGraphOfEnabledFields();
+      this->buildFilterGraphOfEnabledFields();  // references are resolved here (access xml file)
       buildFilterGraphOfFieldsWithReadAccess();
       this->solveAllRefOfEnabledFields(true);
     }
 
-    // Now tell server that it can process all messages from client
-    if (hasClient && !hasServer) this->sendCloseDefinition();
+//    // Now tell server that it can process all messages from client
+////    if (hasClient && !hasServer) this->sendCloseDefinition();
+//    if (hasClient) this->sendCloseDefinition();
 
     // Nettoyage de l'arborescence
-    if (hasClient && !hasServer) CleanTree(); // Only on client side??
+//    if (hasClient && !hasServer) CleanTree(); // Only on client side??
+    if (hasClient) CleanTree(); // Only on client side??
 
     if (hasClient)
     {
       sendCreateFileHeader();
-
-      startPrefetchingOfEnabledReadModeFiles();
+      if (!hasServer) startPrefetchingOfEnabledReadModeFiles();
     }
    }
@@ -549,6 +657,6 @@
       const vector<CGrid*> allGrids= CGrid::getAll();
 
-     //if (hasClient && !hasServer)
-      if (hasClient)
+      if (hasClient && !hasServer)
+      //if (hasClient)
       {
         for (unsigned int i = 0; i < allFiles.size(); i++)
@@ -646,18 +754,41 @@
    }
 
+//   // Only send close definition from process having hasClient
+//   void CContext::sendCloseDefinitionToServer(void)
+//   {
+//     CEventClient event(getType(),EVENT_ID_CLOSE_DEFINITION);
+//   }
+
    //! Client side: Send a message to server to make it close
    void CContext::sendCloseDefinition(void)
    {
      CEventClient event(getType(),EVENT_ID_CLOSE_DEFINITION);
-     if (client->isServerLeader())
-     {
-       CMessage msg;
-       msg<<this->getIdServer();
-       const std::list<int>& ranks = client->getRanksServerLeader();
-       for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
-         event.push(*itRank,1,msg);
-       client->sendEvent(event);
-     }
-     else client->sendEvent(event);
+     if (!hasServer)
+     {
+       if (client->isServerLeader())
+       {
+         CMessage msg;
+         msg<<this->getIdServer();
+         const std::list<int>& ranks = client->getRanksServerLeader();
+         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+           event.push(*itRank,1,msg);
+         client->sendEvent(event);
+       }
+       else client->sendEvent(event);
+     }
+     else
+     {
+       if (clientPrimServer->isServerLeader())
+       {
+         CMessage msg;
+         msg<<this->getIdServer();
+         const std::list<int>& ranks = clientPrimServer->getRanksServerLeader();
+         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+           event.push(*itRank,1,msg);
+         clientPrimServer->sendEvent(event);
+       }
+       else clientPrimServer->sendEvent(event);
+
+     }
    }
 
@@ -675,7 +806,7 @@
    void CContext::sendUpdateCalendar(int step)
    {
+     CEventClient event(getType(),EVENT_ID_UPDATE_CALENDAR);
      if (!hasServer)
      {
-       CEventClient event(getType(),EVENT_ID_UPDATE_CALENDAR);
        if (client->isServerLeader())
        {
@@ -689,4 +820,17 @@
        else client->sendEvent(event);
      }
+     else
+     {
+       if (clientPrimServer->isServerLeader())
+       {
+         CMessage msg;
+         msg<<this->getIdServer()<<step;
+         const std::list<int>& ranks = clientPrimServer->getRanksServerLeader();
+         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+           event.push(*itRank,1,msg);
+         clientPrimServer->sendEvent(event);
+       }
+       else clientPrimServer->sendEvent(event);
+     }
    }
 
@@ -712,14 +856,31 @@
    {
      CEventClient event(getType(),EVENT_ID_CREATE_FILE_HEADER);
-     if (client->isServerLeader())
-     {
-       CMessage msg;
-       msg<<this->getIdServer();
-       const std::list<int>& ranks = client->getRanksServerLeader();
-       for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
-         event.push(*itRank,1,msg) ;
-       client->sendEvent(event);
-     }
-     else client->sendEvent(event);
+
+     if (!hasServer)
+     {
+       if (client->isServerLeader())
+       {
+         CMessage msg;
+         msg<<this->getIdServer();
+         const std::list<int>& ranks = client->getRanksServerLeader();
+         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+           event.push(*itRank,1,msg) ;
+         client->sendEvent(event);
+       }
+       else client->sendEvent(event);
+     }
+     else
+     {
+       if (clientPrimServer->isServerLeader())
+       {
+         CMessage msg;
+         msg<<this->getIdServer();
+         const std::list<int>& ranks = clientPrimServer->getRanksServerLeader();
+         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+           event.push(*itRank,1,msg) ;
+         clientPrimServer->sendEvent(event);
+       }
+       else clientPrimServer->sendEvent(event);
+     }
    }
 
@@ -742,17 +903,34 @@
    void CContext::sendPostProcessing()
    {
-     if (!hasServer)
-     {
-       CEventClient event(getType(),EVENT_ID_POST_PROCESS);
-       if (client->isServerLeader())
-       {
-         CMessage msg;
-         msg<<this->getIdServer();
-         const std::list<int>& ranks = client->getRanksServerLeader();
-         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
-           event.push(*itRank,1,msg);
-         client->sendEvent(event);
-       }
-       else client->sendEvent(event);
+     if (hasClient)
+     {
+       if (!hasServer)
+       {
+         CEventClient event(getType(),EVENT_ID_POST_PROCESS);
+         if (client->isServerLeader())
+         {
+           CMessage msg;
+           msg<<this->getIdServer();
+           const std::list<int>& ranks = client->getRanksServerLeader();
+           for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+             event.push(*itRank,1,msg);
+           client->sendEvent(event);
+         }
+         else client->sendEvent(event);
+       }
+       else
+       {
+         CEventClient event(getType(),EVENT_ID_POST_PROCESS);
+         if (clientPrimServer->isServerLeader())
+         {
+           CMessage msg;
+           msg<<this->getIdServer();
+           const std::list<int>& ranks = clientPrimServer->getRanksServerLeader();
+           for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+             event.push(*itRank,1,msg);
+           clientPrimServer->sendEvent(event);
+         }
+         else clientPrimServer->sendEvent(event);
+       }
      }
    }
@@ -806,4 +984,6 @@
       this->solveAllInheritance();
 
+      ShowTree(info(10));
+
       // Check if some axis, domains or grids are eligible to for compressed indexed output.
       // Warning: This must be done after solving the inheritance and before the rest of post-processing
@@ -822,4 +1002,5 @@
       this->findAllEnabledFieldsInReadModeFiles();
 
+//     if (hasClient)
      if (hasClient && !hasServer)
      {
@@ -1187,5 +1368,4 @@
 
 
-
      //! Server side: Receive a message to do some post processing
   void CContext::recvRegistry(CEventServer& event)
@@ -1212,15 +1392,33 @@
 
     CEventClient event(CContext::GetType(), CContext::EVENT_ID_SEND_REGISTRY);
-    if (client->isServerLeader())
+    if (!hasServer)
     {
-       CMessage msg ;
-       msg<<this->getIdServer();
-       if (client->clientRank==0) msg<<*registryOut ;
-       const std::list<int>& ranks = client->getRanksServerLeader();
-       for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
-         event.push(*itRank,1,msg);
-       client->sendEvent(event);
-     }
-     else client->sendEvent(event);
+      if (client->isServerLeader())
+      {
+         CMessage msg ;
+         msg<<this->getIdServer();
+         if (client->clientRank==0) msg<<*registryOut ;
+         const std::list<int>& ranks = client->getRanksServerLeader();
+         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+           event.push(*itRank,1,msg);
+         client->sendEvent(event);
+       }
+       else client->sendEvent(event);
+    }
+    else
+    {
+      if (clientPrimServer->isServerLeader())
+      {
+         CMessage msg ;
+         msg<<this->getIdServer();
+         if (clientPrimServer->clientRank==0) msg<<*registryOut ;
+         const std::list<int>& ranks = clientPrimServer->getRanksServerLeader();
+         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+           event.push(*itRank,1,msg);
+         clientPrimServer->sendEvent(event);
+       }
+       else clientPrimServer->sendEvent(event);
+
+    }
   }
 
Index: XIOS/dev/dev_olga/src/node/context.hpp
===================================================================
--- XIOS/trunk/src/node/context.hpp	(revision 981)
+++ XIOS/dev/dev_olga/src/node/context.hpp	(revision 983)
@@ -88,6 +88,6 @@
       public :
          // Initialize server or client
+         void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0);
          void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
-         void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0);
          bool isInitialized(void);
 
@@ -137,5 +137,7 @@
          void sendRefGrid();
          void sendPostProcessing();
-         void sendRegistry(void) ; //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
+         //!< after be gathered to the root process of the context, merged registry is sent to the root process of the servers
+         void sendRegistry(void) ;
+
          const StdString& getIdServer();
 
@@ -151,5 +153,5 @@
          void recvPostProcessing(CBufferIn& buffer);
          static void recvRegistry(CEventServer& event) ;
-         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the root process of the servers
+         void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
 
          // dispatch event
@@ -216,11 +218,15 @@
          bool hasServer;
 
-         // Concrete context server
-         CContextServer* server;
-
          // Concrete contex client
          CContextClient* client;
          CRegistry* registryIn ;  //!< input registry which is read from file
          CRegistry* registryOut ; //!< output registry which will be wrote on file at the finalize
+
+         // Concrete context server
+         CContextServer* server;
+
+         // Client-server pair in case of secondary server pool
+         CContextClient* clientPrimServer;
+         CContextServer* serverPrimServer;
 
       private:
Index: XIOS/dev/dev_olga/src/node/field.cpp
===================================================================
--- XIOS/trunk/src/node/field.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/node/field.cpp	(revision 983)
@@ -122,5 +122,6 @@
 
     CContext* context = CContext::getCurrent();
-    CContextClient* client = context->client;
+//    CContextClient* client = context->client;
+    CContextClient* client = (!context->hasServer) ? context->client : context->clientPrimServer;
 
     CEventClient event(getType(), EVENT_ID_UPDATE_DATA);
@@ -195,4 +196,6 @@
   void  CField::recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers)
   {
+    CContext* context = CContext::getCurrent();
+
     if (data_srv.empty())
     {
@@ -205,5 +208,4 @@
     }
 
-    CContext* context = CContext::getCurrent();
     const CDate& currDate = context->getCalendar()->getCurrentDate();
     const CDate opeDate      = last_operation_srv +freq_op + freq_operation_srv - freq_op;
@@ -229,7 +231,30 @@
 
       last_Write_srv = writeDate;
+    }
+
+    if (context->hasClient && context->hasServer)
+    {
+      size_t writtenSize;
+//      if (field->getUseCompressedOutput())
+//        writtenSize = grid->getNumberWrittenIndexes();
+//      else
+        writtenSize = grid->getWrittenDataSize();
+
+      CArray<double,1> fieldData(writtenSize);
+//      if (!field->default_value.isEmpty()) fieldData = field->default_value;
+
+//      if (field->getUseCompressedOutput())
+//        field->outputCompressedField(fieldData);
+//      else
+        this->outputField(fieldData);
+      sendUpdateData(fieldData);
+    }
+    if (!context->hasClient && context->hasServer)
+    {
       writeField();
-      lastlast_Write_srv = last_Write_srv;
-    }
+    }
+
+    lastlast_Write_srv = last_Write_srv;
+
   }
 
@@ -503,15 +528,18 @@
         isReferenceSolved = true;
 
-        if (context->hasClient)
+        if (context->hasClient && !context->hasServer)
+//        if (context->hasClient)
         {
           solveRefInheritance(true);
           if (hasDirectFieldReference()) getDirectFieldReference()->solveOnlyReferenceEnabledField(false);
         }
-        else if (context->hasServer)
+//        else if (context->hasServer)
+        if (context->hasServer)
           solveServerOperation();
 
         solveGridReference();
 
-       if (context->hasClient)
+        if (context->hasClient && !context->hasServer)
+//       if (context->hasClient)
        {
          solveGenerateGrid();
@@ -528,5 +556,6 @@
    {
      CContext* context = CContext::getCurrent();
-     if (context->hasClient)
+     if (context->hasClient && !context->hasServer)
+//     if (context->hasClient)
      {
        if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid)
@@ -543,5 +572,6 @@
    {
      CContext* context = CContext::getCurrent();
-     if (context->hasClient)
+     if (context->hasClient && !context->hasServer)
+//     if (context->hasClient)
      {
        std::map<CGrid*,std::pair<bool,StdString> >& gridSrcMap = grid->getTransGridSource();
@@ -628,10 +658,12 @@
         areAllReferenceSolved = true;
 
-        if (context->hasClient)
+//        if (context->hasClient)
+        if (context->hasClient && !context->hasServer)
         {
           solveRefInheritance(true);
           if (hasDirectFieldReference()) getDirectFieldReference()->solveAllReferenceEnabledField(false);
         }
-        else if (context->hasServer)
+//        else if (context->hasServer)
+        if (context->hasServer && !context->hasClient)
           solveServerOperation();
 
@@ -641,5 +673,5 @@
      solveGridDomainAxisRef(doSending2Server);
 
-     if (context->hasClient)
+     if (context->hasClient && !context->hasClient)
      {
        solveTransformedGrid();
Index: XIOS/dev/dev_olga/src/node/grid.cpp
===================================================================
--- XIOS/trunk/src/node/grid.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/node/grid.cpp	(revision 983)
@@ -273,13 +273,15 @@
    {
      CContext* context = CContext::getCurrent();
-     CContextClient* client=context->client;
+     CContextClient* client= context->hasServer ? context->clientPrimServer : context->client;
 
      if (isScalarGrid())
      {
-       if (context->hasClient)
+       if (context->hasClient && !context->hasServer)
+//         if (context->hasClient)
           if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndexScalarGrid(); this->isIndexSent = true; }
 
        if (this->isChecked) return;
-       if (context->hasClient)
+       if (context->hasClient && !context->hasServer)
+//       if (context->hasClient)
        {
           this->computeIndexScalarGrid();
@@ -290,10 +292,12 @@
      }
 
-     if (context->hasClient)
+     if (context->hasClient && !context->hasServer)
+//     if (context->hasClient)
       if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndex(); this->isIndexSent = true; }
 
      if (this->isChecked) return;
 
-     if (context->hasClient)
+     if (context->hasClient && !context->hasServer)
+//     if (context->hasClient)
      {
         this->checkAttributesAfterTransformation();
@@ -497,9 +501,16 @@
    {
      CContext* context = CContext::getCurrent();
-     CContextClient* client = context->client;
+//     CContextClient* client = context->client;
+     CContextClient* client = (context->hasServer) ? context->clientPrimServer : context->client;
+
 
      // First of all, compute distribution on client side
-     clientDistribution_ = new CDistributionClient(client->clientRank, this);
+     if (0 != serverDistribution_)
+       clientDistribution_ = new CDistributionClient(client->clientRank, serverDistribution_->getGlobalLocalIndex());
+     else
+       clientDistribution_ = new CDistributionClient(client->clientRank, this);
+
      // Get local data index on client
+     int tmp = clientDistribution_->getLocalDataIndexOnClient().size();
      storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().size());
      int nbStoreIndex = storeIndex_client.numElements();
@@ -577,5 +588,5 @@
    {
      CContext* context = CContext::getCurrent();
-     CContextClient* client = context->client;
+     CContextClient* client = context->hasServer ? context->clientPrimServer : context->client;
      int serverSize = client->serverSize;
      std::vector<CDomain*> domList = getDomains();
@@ -975,5 +986,5 @@
   {
     CContext* context = CContext::getCurrent();
-    CContextClient* client=context->client;
+    CContextClient* client = context->hasServer ? context->clientPrimServer : context->client;
 
     storeIndex_client.resize(1);
@@ -1031,5 +1042,5 @@
   {
     CContext* context = CContext::getCurrent();
-    CContextClient* client = context->client;
+    CContextClient* client = context->hasServer ? context->clientPrimServer : context->client;
 
     CEventClient event(getType(), EVENT_ID_INDEX);
@@ -1070,5 +1081,6 @@
   {
     CContext* context = CContext::getCurrent();
-    CContextClient* client = context->client;
+//    CContextClient* client = context->client;
+    CContextClient* client = context->hasServer ? context->clientPrimServer : context->client ;
 
     CEventClient event(getType(), EVENT_ID_INDEX);
@@ -1178,4 +1190,11 @@
     }
     get(gridId)->recvIndex(ranks, buffers);
+
+    CContext* context = CContext::getCurrent();
+    if (context->hasClient && context->hasServer)
+    {
+      get(gridId)->computeIndex();
+      get(gridId)->sendIndex();
+    }
   }
 
@@ -1183,5 +1202,6 @@
   {
     CContext* context = CContext::getCurrent();
-    CContextServer* server = context->server;
+    CContextServer* server = (context->hasServer) ? context->server : context->serverPrimServer;
+    CContextClient* client = (context->hasServer) ? context->client : context->clientPrimServer;
     numberWrittenIndexes_ = totalNumberWrittenIndexes_ = offsetWrittenIndexes_ = 0;
     connectedServerRank_ = ranks;
@@ -1283,5 +1303,5 @@
       totalNumberWrittenIndexes_ = numberWrittenIndexes_;
 
-    nbSenders = CClientServerMappingDistributed::computeConnectedClients(context->client->serverSize, context->client->clientSize, context->client->intraComm, ranks);
+    nbSenders = CClientServerMappingDistributed::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, ranks);
   }
 
@@ -1657,5 +1677,6 @@
     {
       CDomain* pDom = CDomain::get(*it);
-      if (context->hasClient)
+      if (context->hasClient && !context->hasServer)
+//      if (context->hasClient)
       {
         pDom->solveRefInheritance(apply);
@@ -1669,5 +1690,6 @@
     {
       CAxis* pAxis = CAxis::get(*it);
-      if (context->hasClient)
+      if (context->hasClient && !context->hasServer)
+//      if (context->hasClient)
       {
         pAxis->solveRefInheritance(apply);
@@ -1681,5 +1703,6 @@
     {
       CScalar* pScalar = CScalar::get(*it);
-      if (context->hasClient)
+      if (context->hasClient && !context->hasServer)
+//      if (context->hasClient)
       {
         pScalar->solveRefInheritance(apply);
Index: XIOS/dev/dev_olga/src/server.cpp
===================================================================
--- XIOS/trunk/src/server.cpp	(revision 981)
+++ XIOS/dev/dev_olga/src/server.cpp	(revision 983)
@@ -3,4 +3,5 @@
 #include "cxios.hpp"
 #include "server.hpp"
+#include "client.hpp"
 #include "type.hpp"
 #include "context.hpp"
@@ -19,5 +20,5 @@
     list<MPI_Comm> CServer::interComm ;
     std::list<MPI_Comm> CServer::contextInterComms;
-    bool CServer::isRoot ;
+    bool CServer::isRoot = false ;
     int CServer::rank = INVALID_RANK;
     StdOFStream CServer::m_infoStream;
@@ -27,5 +28,10 @@
     bool CServer::is_MPI_Initialized ;
     CEventScheduler* CServer::eventScheduler = 0;
-   
+
+//---------------------------------------------------------------
+/*!
+ * \fn void CServer::initialize(void)
+ * Function creates intra and inter comm for each initialized server pool
+ */
     void CServer::initialize(void)
     {
@@ -45,7 +51,11 @@
         CTimer::get("XIOS").resume() ;
 
+        int nbSrvLevels = 2;
+
         boost::hash<string> hashString ;
-
-        unsigned long hashServer=hashString(CXios::xiosCodeId) ;
+        unsigned long hashServer1 = hashString(CXios::xiosCodeIdPrm);
+        unsigned long hashServer2 = hashString(CXios::xiosCodeIdSnd);
+        unsigned long hashServer = (CXios::serverLevel < 2)  ? hashServer1 : hashServer2;
+
         unsigned long* hashAll ;
 
@@ -56,9 +66,8 @@
         MPI_Comm newComm ;
 
-        MPI_Comm_size(CXios::globalComm,&size) ;
-        MPI_Comm_rank(CXios::globalComm,&rank);
+        MPI_Comm_size(CXios::globalComm, &size) ;
+        MPI_Comm_rank(CXios::globalComm, &rank);
         hashAll=new unsigned long[size] ;
-
-        MPI_Allgather(&hashServer,1,MPI_LONG,hashAll,1,MPI_LONG,CXios::globalComm) ;
+        MPI_Allgather(&hashServer, 1, MPI_LONG, hashAll, 1, MPI_LONG, CXios::globalComm) ;
 
         map<unsigned long, int> colors ;
@@ -77,27 +86,80 @@
 
         myColor=colors[hashServer] ;
-        MPI_Comm_split(MPI_COMM_WORLD,myColor,rank,&intraComm) ;
-
-        int serverLeader=leaders[hashServer] ;
-        int clientLeader;
-
-         serverLeader=leaders[hashServer] ;
-         for(it=leaders.begin();it!=leaders.end();it++)
-         {
-           if (it->first!=hashServer)
-           {
-             clientLeader=it->second ;
-             int intraCommSize, intraCommRank ;
-             MPI_Comm_size(intraComm,&intraCommSize) ;
-             MPI_Comm_rank(intraComm,&intraCommRank) ;
-             info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize
-                     <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ;
-
-             MPI_Intercomm_create(intraComm,0,CXios::globalComm,clientLeader,0,&newComm) ;
-             interComm.push_back(newComm) ;
-           }
-         }
-
-         delete [] hashAll ;
+        MPI_Comm_split(MPI_COMM_WORLD, myColor, rank, &intraComm) ;
+
+        if (CXios::serverLevel == 0)
+        {
+          int clientLeader;
+          for(it=leaders.begin();it!=leaders.end();it++)
+          {
+            if (it->first!=hashServer)
+            {
+              clientLeader=it->second ;
+              int intraCommSize, intraCommRank ;
+              MPI_Comm_size(intraComm,&intraCommSize) ;
+              MPI_Comm_rank(intraComm,&intraCommRank) ;
+              info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize
+                       <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ;
+
+               MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ;
+               interComm.push_back(newComm) ;
+            }
+          }
+        }
+
+        else if ((CXios::serverLevel == 1))
+        {
+          int clientLeader;
+          int srvSndLeader;
+          for(it=leaders.begin();it!=leaders.end();it++)
+          {
+            if (it->first != hashServer2)
+            {
+              if (it->first != hashServer1)
+              {
+                clientLeader=it->second ;
+                int intraCommSize, intraCommRank ;
+                MPI_Comm_size(intraComm,&intraCommSize) ;
+                MPI_Comm_rank(intraComm,&intraCommRank) ;
+                info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize
+                         <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ;
+                MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ;
+                interComm.push_back(newComm) ;
+              }
+            }
+            else
+            {
+              srvSndLeader = it->second;
+            }
+          }
+
+        CClient::initializeClientOnServer(rank, intraComm, srvSndLeader);
+        }
+
+        else // secondary server pool
+        {
+          int clientLeader;
+          for(it=leaders.begin();it!=leaders.end();it++)
+          {
+            if (it->first == hashServer1)
+            {
+              // no changes needed here to create one context per process of the secondary server pool
+              clientLeader=it->second ;
+              int intraCommSize, intraCommRank ;
+              MPI_Comm_size(intraComm,&intraCommSize) ;
+              MPI_Comm_rank(intraComm,&intraCommRank) ;
+              info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize
+                       <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ;
+
+              MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ;
+              interComm.push_back(newComm) ;
+
+              break;
+            }
+          }
+        }
+
+        delete [] hashAll ;
+
       }
       // using OASIS
@@ -145,4 +207,9 @@
     void CServer::finalize(void)
     {
+      if (CXios::serverLevel == 1)
+      {
+        CClient::finalize();
+      }
+
       CTimer::get("XIOS").suspend() ;
      
@@ -151,6 +218,8 @@
       for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++)
         MPI_Comm_free(&(*it));
+
       for (std::list<MPI_Comm>::iterator it = interComm.begin(); it != interComm.end(); it++)
         MPI_Comm_free(&(*it));
+
       MPI_Comm_free(&intraComm);
 
@@ -172,4 +241,5 @@
        while(!stop)
        {
+
          if (isRoot)
          {
@@ -186,4 +256,5 @@
          if (finished && contextList.empty()) stop=true ;
          eventScheduler->checkEvent() ;
+
        }
        CTimer::get("XIOS server").suspend() ;
@@ -288,5 +359,6 @@
      void CServer::recvContextMessage(void* buff,int count)
      {
-       static map<string,contextMessage> recvContextId ;
+       static map<string,contextMessage> recvContextId;
+
        map<string,contextMessage>::iterator it ;
 
@@ -362,4 +434,5 @@
            MPI_Get_count(&status,MPI_CHAR,&count) ;
            registerContext(buffer,count) ;
+
            delete [] buffer ;
            recept=false ;
@@ -373,4 +446,5 @@
        CBufferIn buffer(buff, count);
        buffer >> contextId;
+       CContext* context;
 
        info(20) << "CServer : Register new Context : " << contextId << endl;
@@ -380,17 +454,23 @@
                << "Context '" << contextId << "' has already been registred");
 
-       MPI_Comm contextIntercomm;
-       MPI_Intercomm_create(intraComm,0,CXios::globalComm,leaderRank,10+leaderRank,&contextIntercomm);
+       MPI_Comm contextInterComm;
+       MPI_Intercomm_create(intraComm,0,CXios::globalComm,leaderRank,10+leaderRank,&contextInterComm);
 
        MPI_Comm inter;
-       MPI_Intercomm_merge(contextIntercomm,1,&inter);
+       MPI_Intercomm_merge(contextInterComm,1,&inter);
        MPI_Barrier(inter);
 
-       CContext* context=CContext::create(contextId);
+       context=CContext::create(contextId);
        contextList[contextId]=context;
-       context->initServer(intraComm,contextIntercomm);
-
-       contextInterComms.push_back(contextIntercomm);
+       context->initServer(intraComm,contextInterComm);
+       contextInterComms.push_back(contextInterComm);
+
+       if (CXios::serverLevel == 1)
+       {
+         CClient::registerContext(contextId, intraComm);
+       }
+
        MPI_Comm_free(&inter);
+
      }
 
@@ -399,4 +479,5 @@
        bool finished ;
        map<string,CContext*>::iterator it ;
+
        for(it=contextList.begin();it!=contextList.end();it++)
        {
@@ -408,5 +489,4 @@
          }
        }
-
      }
 
Index: XIOS/dev/dev_olga/src/server.hpp
===================================================================
--- XIOS/trunk/src/server.hpp	(revision 981)
+++ XIOS/dev/dev_olga/src/server.hpp	(revision 983)
@@ -22,11 +22,12 @@
         static void listenRootContext(void);
         static void listenRootFinalize(void);
-        static void registerContext(void* buff,int count, int leaderRank=0);
+        static void registerContext(void* buff,int count, int leaderRank=0);        // context registered by the primary server
 
+        // Communicators for the primary group of servers
         static MPI_Comm intraComm;
         static list<MPI_Comm> interComm;
         static std::list<MPI_Comm> contextInterComms;
         static CEventScheduler* eventScheduler;
-        
+
         struct contextMessage
         {
@@ -37,5 +38,5 @@
         static bool isRoot;
 
-        static map<string,CContext*> contextList;
+        static map<string,CContext*> contextList;       // contexts on the primary server
         static bool finished;
         static bool is_MPI_Initialized;
Index: XIOS/dev/dev_olga/src/test/test_client.f90
===================================================================
--- XIOS/trunk/src/test/test_client.f90	(revision 981)
+++ XIOS/dev/dev_olga/src/test/test_client.f90	(revision 983)
@@ -17,7 +17,7 @@
   CHARACTER(len=15) :: calendar_type
   TYPE(xios_context) :: ctx_hdl
-  INTEGER,PARAMETER :: ni_glo=100
-  INTEGER,PARAMETER :: nj_glo=100
-  INTEGER,PARAMETER :: llm=5
+  INTEGER,PARAMETER :: ni_glo=2
+  INTEGER,PARAMETER :: nj_glo=2
+  INTEGER,PARAMETER :: llm=1
   DOUBLE PRECISION  :: lval(llm)=1
   TYPE(xios_field) :: field_hdl
@@ -84,11 +84,11 @@
   CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.)
 
-  CALL xios_get_handle("field_definition",fieldgroup_hdl)
-  CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B")
-  CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B")
+  !CALL xios_get_handle("field_definition",fieldgroup_hdl)
+  !CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B")
+  !CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B")
 
-  CALL xios_get_handle("output",file_hdl)
-  CALL xios_add_child(file_hdl,field_hdl)
-  CALL xios_set_attr(field_hdl,field_ref="field_A_zoom",name="field_C")
+  !CALL xios_get_handle("output",file_hdl)
+  !CALL xios_add_child(file_hdl,field_hdl)
+  !CALL xios_set_attr(field_hdl,field_ref="field_A_zoom",name="field_C")
 
   dtime%second = 3600
Index: XIOS/dev/dev_olga/src/xios_server.f90
===================================================================
--- XIOS/trunk/src/xios_server.f90	(revision 981)
+++ XIOS/dev/dev_olga/src/xios_server.f90	(revision 983)
@@ -4,6 +4,10 @@
   INCLUDE "mpif.h"
   INTEGER :: ierr
-  
-    CALL xios_init_server
+  INTEGER            :: server_level = 0  
+  ! 0 in case of a single server pool 
+  ! 1 for primary server in case of two server pools
+  ! 2 for secondary server in case of two server pools
 
-  END PROGRAM server_main
+  CALL xios_init_server(server_level)
+
+END PROGRAM server_main
