Index: XIOS3/trunk/src/node/context.cpp
===================================================================
--- XIOS3/trunk/src/node/context.cpp	(revision 2406)
+++ XIOS3/trunk/src/node/context.cpp	(revision 2407)
@@ -515,5 +515,5 @@
        hasServer=true ;
      }
-     else if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::OUT_SERVER)
+     else if (serviceType_==CServicesManager::WRITER || serviceType_==CServicesManager::READER)
      {
        hasClient=false ;
@@ -549,7 +549,15 @@
     client->setAssociatedServer(server) ;  
     server->setAssociatedClient(client) ;
-
-    writerServerIn_.push_back(server) ; 
-    writerClientIn_.push_back(client) ; 
+    
+    if (serviceType_ == CServicesManager::GATHERER || serviceType_ == CServicesManager::WRITER)
+    {  
+      writerServerIn_.push_back(server) ; 
+      writerClientIn_.push_back(client) ; 
+    }
+    else if (serviceType_ == CServicesManager::READER)
+    {
+      readerServerIn_.push_back(server) ; 
+      readerClientIn_.push_back(client) ; 
+    }
   }
   CATCH_DUMP_ATTR
@@ -592,4 +600,6 @@
       
       clientServers.push_back({fullServerId,{client,server}}) ;
+      clientsId_[client] = fullServerId ;
+      serversId_[server] = fullServerId ;
     }
   }
@@ -603,19 +613,25 @@
     if (serviceType_ == CServicesManager::CLIENT)
     {
-      if (attached_mode) createServerInterComm(CClient::getPoolRessource()->getId(), getContextId()+"_"+CXios::defaultServerId, clientServers) ;
+      if (attached_mode) createServerInterComm(CClient::getPoolRessource()->getId(), getContextId()+"_"+CXios::defaultWriterId, clientServers) ;
       else if (CXios::usingServer2) createServerInterComm(CXios::defaultPoolId, CXios::defaultGathererId, clientServers) ;
-      else createServerInterComm(CXios::defaultPoolId, CXios::defaultServerId, clientServers) ;
+      else createServerInterComm(CXios::defaultPoolId, CXios::defaultWriterId, clientServers) ;
       
       writerClientOut_.push_back(clientServers[0].second.first) ; 
       writerServerOut_.push_back(clientServers[0].second.second) ;
+
+      clientServers.clear() ;
+   
+      if (attached_mode) createServerInterComm(CClient::getPoolRessource()->getId(), getContextId()+"_"+CXios::defaultReaderId, clientServers) ;
+      else createServerInterComm(CXios::defaultPoolId, CXios::defaultReaderId, clientServers) ;
+      readerClientOut_.push_back(clientServers[0].second.first) ; 
+      readerServerOut_.push_back(clientServers[0].second.second) ;
+
+
     }
     else if (serviceType_ == CServicesManager::GATHERER)
     {
-      createServerInterComm(CXios::defaultPoolId, CXios::defaultServerId, clientServers) ;
+      createServerInterComm(CXios::defaultPoolId, CXios::defaultWriterId, clientServers) ;
       for(auto& clientServer : clientServers)
       {
-        primServerId_.push_back(clientServer.first) ;
-        clientPrimServer.push_back(clientServer.second.first);
-        serverPrimServer.push_back(clientServer.second.second);
         writerClientOut_.push_back(clientServer.second.first) ; 
         writerServerOut_.push_back(clientServer.second.second) ;
@@ -672,4 +688,8 @@
       for(auto client : writerClientIn_) client->eventLoop();
       for(auto server : writerServerIn_) finished &= server->eventLoop(enableEventsProcessing);
+      for(auto client : readerClientOut_) client->eventLoop();
+      for(auto server : readerServerOut_) finished &= server->eventLoop(enableEventsProcessing);
+      for(auto client : readerClientIn_) client->eventLoop();
+      for(auto server : readerServerIn_) finished &= server->eventLoop(enableEventsProcessing);
       for(auto couplerOut : couplerOutClient_) couplerOut.second->eventLoop();
       for(auto couplerIn : couplerInClient_) couplerIn.second->eventLoop();
@@ -756,22 +776,48 @@
         } while (!couplersInFinalized) ;
 
-
-        auto& client=writerClientOut_[0] ;
-        auto& server=writerServerOut_[0] ;
-
-        info(100)<<"DEBUG: context "<<getId()<<" Send client finalize"<<endl ;
-        client->finalize();
-        info(100)<<"DEBUG: context "<<getId()<<" Client finalize sent"<<endl ;
-        while (client->havePendingRequests()) client->eventLoop();
-        info(100)<<"DEBUG: context "<<getId()<<" no pending request ok"<<endl ;
-        bool notifiedFinalized=false ;
-        do
+        CContextClient* client ;
+        CContextServer* server ;
+
+        if (writerClientOut_.size()!=0)
         {
-          notifiedFinalized = client->isNotifiedFinalized() ;
-        } while (!notifiedFinalized) ;
-
-        server->releaseBuffers();
-        client->releaseBuffers();
-        info(100)<<"DEBUG: context "<<getId()<<" release client ok"<<endl ;
+          client=writerClientOut_[0] ;
+          server=writerServerOut_[0] ;
+
+          info(100)<<"DEBUG: context "<<getId()<<" Send client finalize to writer"<<endl ;
+          client->finalize();
+          info(100)<<"DEBUG: context "<<getId()<<" Client finalize sent to writer"<<endl ;
+          while (client->havePendingRequests()) client->eventLoop();
+          info(100)<<"DEBUG: context "<<getId()<<" no pending request on writer ok"<<endl ;
+          bool notifiedFinalized=false ;
+          do
+          {
+            notifiedFinalized = client->isNotifiedFinalized() ;
+          } while (!notifiedFinalized) ;
+
+          server->releaseBuffers();
+          client->releaseBuffers();
+          info(100)<<"DEBUG: context "<<getId()<<" release client writer ok"<<endl ;
+        }
+
+        if (readerClientOut_.size()!=0)
+        {
+          client=readerClientOut_[0] ;
+          server=readerServerOut_[0] ;
+
+          info(100)<<"DEBUG: context "<<getId()<<" Send client finalize to reader"<<endl ;
+          client->finalize();
+          info(100)<<"DEBUG: context "<<getId()<<" Client finalize sent to reader"<<endl ;
+          while (client->havePendingRequests()) client->eventLoop();
+          info(100)<<"DEBUG: context "<<getId()<<" no pending request on reader ok"<<endl ;
+          bool notifiedFinalized=false ;
+         do
+         {
+            notifiedFinalized = client->isNotifiedFinalized() ;
+         }   while (!notifiedFinalized) ;
+
+          server->releaseBuffers();
+          client->releaseBuffers();
+          info(100)<<"DEBUG: context "<<getId()<<" release client reader ok"<<endl ;
+        }
       }
       else if (serviceType_==CServicesManager::GATHERER)
@@ -797,9 +843,15 @@
          //ym writerClientIn & writerServerIn not released here ==> to check !!
       }
-      else if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::OUT_SERVER)
+      else if (serviceType_==CServicesManager::WRITER)
       {
         closeAllFile();
         writerClientIn_[0]->releaseBuffers();
         writerServerIn_[0]->releaseBuffers();
+      }
+      else if (serviceType_==CServicesManager::READER)
+      {
+        closeAllFile();
+        readerClientIn_[0]->releaseBuffers();
+        readerServerIn_[0]->releaseBuffers();
       }
 
@@ -969,9 +1021,8 @@
 
     // client side, assign context for file reading
-    if (serviceType_==CServicesManager::CLIENT) for(auto file : this->enabledReadModeFiles) file->setContextClient(writerClientOut_[0]) ;
+    if (serviceType_==CServicesManager::CLIENT) for(auto file : this->enabledReadModeFiles) file->setContextClient(readerClientOut_[0]) ;
     
     // server side, assign context where to send file data read
-    if (serviceType_==CServicesManager::CServicesManager::GATHERER || serviceType_==CServicesManager::IO_SERVER) 
-      for(auto file : this->enabledReadModeFiles) file->setContextClient(writerClientIn_[0]) ;
+    if (serviceType_==CServicesManager::READER) for(auto file : this->enabledReadModeFiles) file->setContextClient(readerClientIn_[0]) ;
    
 
@@ -1000,5 +1051,5 @@
 
     // workflow endpoint => write to file
-    if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::OUT_SERVER)
+    if (serviceType_==CServicesManager::WRITER)
     {
       for(auto field : fileOutField) 
@@ -1009,5 +1060,5 @@
     
     // workflow endpoint => Send data from server to client
-    if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::GATHERER)
+    if (serviceType_==CServicesManager::READER || serviceType_==CServicesManager::GATHERER)
     {
       for(auto field : fileInField) 
@@ -1035,5 +1086,5 @@
     
     // workflow startpoint => data from client on server side
-    if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::GATHERER || serviceType_==CServicesManager::OUT_SERVER)
+    if (serviceType_==CServicesManager::WRITER || serviceType_==CServicesManager::GATHERER)
     {
       for(auto field : fieldModelIn) 
@@ -1056,5 +1107,5 @@
 
     // workflow startpoint => data read from file on server side
-    if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::GATHERER)
+    if (serviceType_==CServicesManager::READER)
     {
       for(auto field : fileInField) 
@@ -1065,15 +1116,18 @@
     
     // construct slave server list
+    map<string, CContextClient*> slaves ; // need an ordered list ; 
     if (serviceType_==CServicesManager::CLIENT) 
     {
-      for(auto field : fileOutField) slaveServers_.insert(field->getContextClient()) ; 
-      for(auto field : fileInField) slaveServers_.insert(field->getContextClient()) ; 
+      for(auto field : fileOutField) slaves[clientsId_[field->getContextClient()]] = field->getContextClient() ; 
+      for(auto field : fileInField) slaves[clientsId_[field->getContextClient()]] = field->getContextClient() ; 
     }
     else if (serviceType_==CServicesManager::GATHERER) 
-      for(auto field : fileOutField) slaveServers_.insert(field->getContextClient()) ; 
+      for(auto field : fileOutField) slaves[clientsId_[field->getContextClient()]] = field->getContextClient() ;
+    for(auto& slave : slaves) slaveServers_.push_back(slave.second) ;   
+
 
     for(auto& slaveServer : slaveServers_) sendCloseDefinition(slaveServer) ;
 
-    if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::OUT_SERVER)  
+    if (serviceType_==CServicesManager::WRITER)  
     {
       createFileHeader();
Index: XIOS3/trunk/src/node/context.hpp
===================================================================
--- XIOS3/trunk/src/node/context.hpp	(revision 2406)
+++ XIOS3/trunk/src/node/context.hpp	(revision 2407)
@@ -308,10 +308,4 @@
          bool hasServer;
 
-      private:
-         std::vector<CContextServer*> serverPrimServer;
-         std::vector<CContextClient*> clientPrimServer;
-
-         // list of slave servers (IO server or others)
-         set<CContextClient*> slaveServers_ ;
 
       private:
@@ -333,14 +327,18 @@
         std::map<std::string, CContextClient*> clients_ ;
         std::map<std::string, CContextClient*> servers_ ;
-
-      private:
-         // the map containing context client associated to it string id for coupling out ;
-         std::map<std::string, CContextClient*> couplerOutClient_ ;
-         // the map containing context server associated to it string id for coupling out ;
-         std::map<std::string, CContextServer*> couplerOutServer_ ;
-         // the map containing context client associated to it string id for coupling in ;
-         std::map<std::string, CContextClient*> couplerInClient_ ;
-         // the map containing context server associated to it string id for coupling in ;
-         std::map<std::string, CContextServer*> couplerInServer_ ;
+        std::map<CContextClient*, std::string> clientsId_ ;
+        std::map<CContextServer*, std::string> serversId_ ;
+
+        // list of slave servers (IO server or others)
+        std::vector<CContextClient*> slaveServers_ ;
+
+        // the map containing context client associated to it string id for coupling out ;
+        std::map<std::string, CContextClient*> couplerOutClient_ ;
+        // the map containing context server associated to it string id for coupling out ;
+        std::map<std::string, CContextServer*> couplerOutServer_ ;
+        // the map containing context client associated to it string id for coupling in ;
+        std::map<std::string, CContextClient*> couplerInClient_ ;
+        // the map containing context server associated to it string id for coupling in ;
+        std::map<std::string, CContextServer*> couplerInServer_ ;
       public:
          CContextClient* getCouplerInClient(const string& contextId) { return couplerInClient_[contextId] ;}
@@ -348,7 +346,4 @@
          CContextClient* getCouplerOutClient(const string& contextId) { return couplerOutClient_[contextId] ;}
          CContextServer* getCouplerOutServer(const string& contextId) { return couplerOutServer_[contextId] ;}
-      
-  
-         std::vector<std::string> primServerId_;
 
          CRegistry* registryIn=nullptr ;    //!< input registry which is read from file
