Changeset 321


Ignore:
Timestamp:
02/23/12 14:57:50 (12 years ago)
Author:
ymipsl
Message:

Add splitting file functionality
new file attribut "split_freq" to put the frequency of splitting

YM

Location:
XIOS/trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/data_output.cpp

    r286 r321  
    4242      { 
    4343         this->writeFile_(file); 
     44      } 
     45  
     46      void CDataOutput::syncFile(void) 
     47      { 
     48         this->syncFile_(); 
    4449      } 
    4550 
  • XIOS/trunk/src/data_output.hpp

    r286 r321  
    2525            /// Ecriture /// 
    2626            void writeFile     (const boost::shared_ptr<tree::CFile>  file); 
     27            void syncFile     (void); 
    2728            void closeFile     (void); 
    2829            void writeField    (const boost::shared_ptr<tree::CField> field); 
     
    4546            virtual void writeFile_       (const boost::shared_ptr<tree::CFile>     file)   = 0; 
    4647            virtual void closeFile_       (void)                                            = 0; 
     48            virtual void syncFile_       (void)                                            = 0; 
    4749            virtual void writeField_      (const boost::shared_ptr<tree::CField>    field)  = 0; 
    4850            virtual void writeFieldData_  (const boost::shared_ptr<tree::CField>    field)  = 0; 
  • XIOS/trunk/src/date.cpp

    r316 r321  
    194194      //---------------------------------------------------------------- 
    195195       
     196      StdString CDate::getStryyyymmdd(void) const 
     197      {  
     198         std::streamsize s ;  
     199         char c ; 
     200 
     201         ostringstream oss ; 
     202 
     203         s = oss.width (4);  c = oss.fill ('0') ; oss << year ; 
     204         s = oss.width (2);  c = oss.fill ('0') ; oss << month; 
     205         s = oss.width (2);  c = oss.fill ('0') ; oss << day ; 
     206 
     207         return oss.str(); 
     208      } 
     209       
    196210       StdString CDate::toString(void) const 
    197211      {  
  • XIOS/trunk/src/date.hpp

    r219 r321  
    5757            /// Autres /// 
    5858            StdString toString(void) const; 
     59            StdString getStryyyymmdd(void) const; 
    5960 
    6061         public : /* static */ 
  • XIOS/trunk/src/node/context.cpp

    r314 r321  
    544544      for (it=enabledFiles.begin(); it != enabledFiles.end(); it++) 
    545545      { 
    546 /*         shared_ptr<CFile> file = *it; 
    547          StdString filename = (!file->name.isEmpty()) ?   file->name.getValue() : file->getId(); 
    548          StdOStringStream oss; 
    549          if (! output_dir.isEmpty()) oss << output_dir.getValue(); 
    550          oss << filename; 
    551          if (!file->name_suffix.isEmpty()) oss << file->name_suffix.getValue(); 
    552  
    553          bool multifile=true ; 
    554          if (!file->type.isEmpty()) 
    555          { 
    556            StdString str=file->type.getValue() ;  
    557            if (str.compare("one_file")==0) multifile=false ; 
    558            else if (str.compare("multi_file")==0) multifile=true ; 
    559            else ERROR("void Context::createDataOutput(void)", 
    560                       "incorrect file <type> attribut : must be <multi_file> or <one_file>, " 
    561                       <<"having : <"<<str<<">") ; 
    562          }  
    563          if (multifile)  
    564          { 
    565             if (server->intraCommSize > 1) oss << "_" << server->intraCommRank; 
    566          } 
    567          oss << ".nc"; 
    568  
    569          shared_ptr<io::CDataOutput> dout(new T(oss.str(), false,server->intraComm,multifile)); 
    570 */ 
    571          (*it)->createHeader(); 
     546         (*it)->initFile(); 
    572547      } 
    573548   }  
  • XIOS/trunk/src/node/field.cpp

    r314 r321  
    176176      } 
    177177       
    178       this->incrementNStep(); 
    179178      *last_Write_srv = writeDate; 
    180179      writeField() ; 
     
    184183  void CField::writeField(void) 
    185184  { 
    186     if (! grid->domain->isEmpty() || getRelFile()->type.getValue()=="one_file")  
     185    if (! grid->domain->isEmpty() || getRelFile()->type.getValue()=="one_file") 
     186    { 
     187      getRelFile()->checkFile(); 
     188      this->incrementNStep(); 
    187189      getRelFile()->getDataOutput()->writeFieldData(CObjectFactory::GetObject<CField>(this)); 
     190    } 
    188191  } 
    189192   //---------------------------------------------------------------- 
     
    222225   { 
    223226      this->nstep++; 
     227   } 
     228  
     229   void CField::resetNStep(void) 
     230   { 
     231      this->nstep=0; 
    224232   } 
    225233 
  • XIOS/trunk/src/node/field.hpp

    r310 r321  
    8888         void setRelFile(const boost::shared_ptr<CFile> _file); 
    8989         void incrementNStep(void); 
     90         void resetNStep() ; 
    9091 
    9192         template <StdSize N> bool updateData(const ARRAY(double, N)   data); 
  • XIOS/trunk/src/node/file.cpp

    r318 r321  
    141141      return false ; 
    142142    } 
    143        
     143     
     144   void CFile::initFile(void) 
     145   { 
     146      shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 
     147      date::CDate& currentDate=context->calendar->getCurrentDate() ; 
     148       
     149      if (! sync_freq.isEmpty()) syncFreq = date::CDuration::FromString(sync_freq.getValue()); 
     150      if (! split_freq.isEmpty()) splitFreq = date::CDuration::FromString(split_freq.getValue()); 
     151      if (! output_freq.isEmpty()) outputFreq = date::CDuration::FromString(output_freq.getValue()); 
     152      lastSync=new date::CDate(currentDate) ; 
     153      lastSplit=new date::CDate(currentDate) ; 
     154      isOpen=false ; 
     155    } 
     156     
     157    void CFile::checkFile(void) 
     158    { 
     159      if (!isOpen) createHeader() ; 
     160      checkSync() ; 
     161      checkSplit() ; 
     162    } 
     163       
     164      
     165   bool CFile::checkSync(void) 
     166   { 
     167     shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 
     168     date::CDate& currentDate=context->calendar->getCurrentDate() ; 
     169     if (! sync_freq.isEmpty()) 
     170     { 
     171       if (*lastSync+syncFreq < currentDate) 
     172       { 
     173         *lastSync=currentDate ; 
     174         data_out->syncFile() ; 
     175         return true ; 
     176        } 
     177      } 
     178      return false ; 
     179    } 
     180     
     181     
     182    bool CFile::checkSplit(void) 
     183    { 
     184      shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 
     185      date::CDate& currentDate=context->calendar->getCurrentDate() ; 
     186      if (! split_freq.isEmpty()) 
     187      { 
     188        if (*lastSplit+splitFreq < currentDate) 
     189        { 
     190          *lastSplit=currentDate-outputFreq ; 
     191         
     192          std::vector<boost::shared_ptr<CField> >::iterator it, end = this->enabledFields.end(); 
     193          for (it = this->enabledFields.begin() ;it != end; it++)  (*it)->resetNStep() ; 
     194          createHeader() ; 
     195          return true ; 
     196        } 
     197      } 
     198      return false ; 
     199    } 
     200     
    144201   void CFile::createHeader(void) 
    145202   { 
    146203      shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 
    147  
    148       if (! sync_freq.isEmpty()) syncFreq = date::CDuration::FromString(sync_freq.getValue()); 
    149       lastSync=new date::CDate(context->calendar->getCurrentDate()) ; 
     204      date::CDate& currentDate=context->calendar->getCurrentDate() ; 
    150205       
    151206      std::vector<boost::shared_ptr<CField> >::iterator it, end = this->enabledFields.end(); 
     
    168223         oss << filename; 
    169224         if (!name_suffix.isEmpty()) oss << name_suffix.getValue(); 
    170  
     225//         if (!split_freq.isEmpty()) oss<<"-["<<currentDate.toString()<<"]" ; 
     226         if (!split_freq.isEmpty()) oss<<"_"<<lastSplit->getStryyyymmdd()<<"-"<< (*lastSplit+(splitFreq-1*date::Second)).getStryyyymmdd(); 
    171227         bool multifile=true ; 
    172228         if (!type.isEmpty()) 
     
    187243         oss << ".nc"; 
    188244 
     245         if (isOpen) data_out->closeFile() ; 
     246          
    189247         data_out=shared_ptr<io::CDataOutput>(new io::CNc4DataOutput(oss.str(), false,server->intraComm,multifile)); 
     248         isOpen=true ; 
    190249 
    191250         data_out->writeFile(CObjectFactory::GetObject<CFile>(this)); 
     
    208267   void CFile::close(void) 
    209268   { 
     269     delete lastSync ; 
     270     delete lastSplit ; 
    210271     if (!AllDomainEmpty ||  type.getValue()=="one_file") 
    211        this->data_out->closeFile(); 
    212      delete lastSync ; 
     272       if (isOpen)  
     273       { 
     274         this->data_out->closeFile(); 
     275       } 
    213276   } 
    214277   //---------------------------------------------------------------- 
  • XIOS/trunk/src/node/file.hpp

    r318 r321  
    104104         static bool dispatchEvent(CEventServer& event) ; 
    105105         bool isSyncTime(void) ; 
     106         bool checkSplit(void) ; 
     107         bool checkSync(void) ; 
     108         void checkFile(void) ; 
     109         void initFile(void) ; 
    106110         date::CDate* lastSync ; 
     111         date::CDate* lastSplit ; 
    107112         date::CDuration syncFreq ; 
     113         date::CDuration splitFreq ; 
     114         date::CDuration outputFreq ; 
    108115         int nbDomain ; 
     116         bool isOpen ; 
    109117      private : 
    110118 
  • XIOS/trunk/src/output/nc4_data_output.cpp

    r318 r321  
    433433         else singleDomain=false ; 
    434434      } 
     435  
     436      void CNc4DataOutput::syncFile_ (void) 
     437      { 
     438         SuperClassWriter::sync() ; 
     439      } 
    435440 
    436441      void CNc4DataOutput::closeFile_ (void) 
     
    460465      { 
    461466         shared_ptr<CContext> context=CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()) ; 
    462           if (field->getRelFile()->isSyncTime()) SuperClassWriter::sync() ; 
     467//          if (field->getRelFile()->isSyncTime()) SuperClassWriter::sync() ; 
    463468 
    464469         boost::shared_ptr<CGrid> grid = field->grid ; 
  • XIOS/trunk/src/output/nc4_data_output.hpp

    r318 r321  
    4747            virtual void writeFile_      (const boost::shared_ptr<tree::CFile>     file); 
    4848            virtual void closeFile_      (void); 
     49            virtual void syncFile_      (void); 
    4950            virtual void writeTimeAxis_  (const boost::shared_ptr<tree::CField>    field, 
    5051                                          const boost::shared_ptr<date::CCalendar> cal); 
Note: See TracChangeset for help on using the changeset viewer.