Index: XIOS3/dev/XIOS_ATTACHED/src/node/context.cpp
===================================================================
--- XIOS3/dev/XIOS_ATTACHED/src/node/context.cpp	(revision 2459)
+++ XIOS3/dev/XIOS_ATTACHED/src/node/context.cpp	(revision 2482)
@@ -7,4 +7,5 @@
 #include "duration.hpp"
 
+#include "online_context_client.hpp"
 #include "legacy_context_client.hpp"
 #include "legacy_context_server.hpp"
@@ -678,8 +679,13 @@
   vector<CContextClient*> CContext::getContextClient(const string& poolId, const string& serviceId)
   {
-    vector<pair<CContextClient*,CContextServer*>> clientServers ;
-    getServerInterComm(poolId, serviceId, clientServers ) ;
-    vector<CContextClient*> ret ;
-    for(auto& clientServer : clientServers) ret.push_back(clientServer.first) ;
+     vector<CContextClient*> ret ;
+    
+    if (serviceId=="attached") ret.push_back(onlineContextClient_) ;
+    else
+    {
+      vector<pair<CContextClient*,CContextServer*>> clientServers ;
+      getServerInterComm(poolId, serviceId, clientServers ) ;
+      for(auto& clientServer : clientServers) ret.push_back(clientServer.first) ;
+    }
     return ret ;
   }
@@ -807,5 +813,4 @@
       if (serviceType_==CServicesManager::CLIENT)
       {
-//ym        doPreTimestepOperationsForEnabledReadModeFiles(); // For now we only use server level 1 to read data
         triggerLateFields() ;
 
@@ -985,4 +990,6 @@
 
      CTimer::get("Context : close definition").resume() ;
+
+     onlineContextClient_=CContextClient::getNew<CContextClient::online>(this,intraComm_, intraComm_);
           
      // create intercommunicator with servers. 
@@ -1145,7 +1152,10 @@
     {
       for(auto field : fileInField) 
-      {
-        field->sendFieldToInputFileServer() ;
-        field->connectToServerInput(garbageCollector) ; // connect the field to server filter
+        if (field->getContextClient()->getType() != CContextClient::online) field->sendFieldToInputFileServer() ;
+
+      for(auto field : fileInField) 
+      {
+        if (field->getContextClient()->getType() == CContextClient::online) field->connectToOnlineReader(garbageCollector) ;
+        else field->connectToServerInput(garbageCollector) ; // connect the field to server filter
         fileInFields_.push_back(field) ;
       }
@@ -1157,7 +1167,9 @@
       for(auto field : fileOutField) 
       {
-        field->connectToFileServer(garbageCollector) ; // connect the field to server filter
-      }
-      for(auto field : fileOutField) field->sendFieldToFileServer() ;
+        if (field->getContextClient()->getType() == CContextClient::online)  field->connectToOnlineWriter(garbageCollector) ;
+        else  field->connectToFileServer(garbageCollector) ; // connect the field to server filter
+      }
+      for(auto field : fileOutField) 
+        if (field->getContextClient()->getType() != CContextClient::online) field->sendFieldToFileServer() ;
     }
 
@@ -1176,5 +1188,6 @@
       for(auto field : fileInField) 
       {
-        field->connectToServerToClient(garbageCollector) ;
+        if (field->getContextClient()->getType() == CContextClient::online) field->connectToOnlineReader(garbageCollector) ;
+        else field->connectToServerToClient(garbageCollector) ;
       }
     }
@@ -1231,6 +1244,8 @@
     if (serviceType_==CServicesManager::CLIENT) 
     {
-      for(auto field : fileOutField) slaves[clientsId_[field->getContextClient()]] = field->getContextClient() ; 
-      for(auto field : fileInField) slaves[clientsId_[field->getContextClient()]] = field->getContextClient() ; 
+      for(auto field : fileOutField)
+        if (field->getContextClient()->getType()!=CContextClient::online)  slaves[clientsId_[field->getContextClient()]] = field->getContextClient() ; 
+      for(auto field : fileInField) 
+        if (field->getContextClient()->getType()!=CContextClient::online)  slaves[clientsId_[field->getContextClient()]] = field->getContextClient() ; 
     }
     else if (serviceType_==CServicesManager::GATHERER) 
@@ -1241,10 +1256,9 @@
     for(auto& slaveServer : slaveServers_) sendCloseDefinition(slaveServer) ;
 
-    if (serviceType_==CServicesManager::WRITER)  
-    {
-      createFileHeader();
-    }
-
-    if (serviceType_==CServicesManager::CLIENT) startPrefetchingOfEnabledReadModeFiles();
+    createFileHeader();
+   
+    //if (serviceType_==CServicesManager::CLIENT) startPrefetchingOfEnabledReadModeFiles();
+    if (serviceType_==CServicesManager::CLIENT) 
+       for(auto field : fileInField) field->sendReadDataRequest(getCalendar()->getCurrentDate());  
    
     // send signal to couplerIn context that definition phasis is done
@@ -1355,16 +1369,4 @@
    CATCH_DUMP_ATTR
 
-
-   void CContext::postProcessFilterGraph()
-   TRY
-   {
-     int size = enabledFiles.size();
-     for (int i = 0; i < size; ++i)
-     {
-        enabledFiles[i]->postProcessFilterGraph();
-     }
-   }
-   CATCH_DUMP_ATTR
-
    void CContext::startPrefetchingOfEnabledReadModeFiles()
    TRY
@@ -1374,15 +1376,4 @@
      {
         enabledReadModeFiles[i]->prefetchEnabledReadModeFields();
-     }
-   }
-   CATCH_DUMP_ATTR
-
-   void CContext::doPreTimestepOperationsForEnabledReadModeFiles()
-   TRY
-   {
-     int size = enabledReadModeFiles.size();
-     for (int i = 0; i < size; ++i)
-     {
-        enabledReadModeFiles[i]->doPreTimestepOperationsForEnabledReadModeFields();
      }
    }
@@ -2176,5 +2167,6 @@
         if (serviceType_==CServicesManager::CLIENT) // For now we only use server level 1 to read data
         {
-          doPostTimestepOperationsForEnabledReadModeFiles();
+         // doPostTimestepOperationsForEnabledReadModeFiles();
+          for(auto& field : fileInFields_) field->sendReadDataRequestIfNeeded() ;
           garbageCollector.invalidate(calendar->getCurrentDate());
         }
@@ -2201,15 +2193,9 @@
    CATCH_DUMP_ATTR
 
-   //! Server side: Create header of netcdf file
+   //! Create header of netcdf file
    void CContext::createFileHeader(void)
    TRY
    {
-      vector<CFile*>::const_iterator it;
-
-      //for (it=enabledFiles.begin(); it != enabledFiles.end(); it++)
-      for (it=enabledWriteModeFiles.begin(); it != enabledWriteModeFiles.end(); it++)
-      {
-         (*it)->initWrite();
-      }
+      for(auto& file : filesToWrite_) file->initWrite();
    }
    CATCH_DUMP_ATTR
