Ignore:
Timestamp:
12/03/14 17:54:33 (9 years ago)
Author:
rlacroix
Message:

Add the ability to append data to existing output file(s).

By default existing file(s) will still be overwritten. Set the new file attribute "append" to true if you wish to append data to existing NetCDF file(s).

Note that the append mode is currently not supported when file splitting is used and that the structure of the output file cannot be changed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/file.cpp

    r526 r528  
    322322         } 
    323323 
     324        bool append = !this->append.isEmpty() && this->append.getValue(); 
     325         
    324326         bool useClassicFormat = !format.isEmpty() && format == format_attr::netcdf4_classic; 
    325327 
     
    362364         if (isOpen) data_out->closeFile(); 
    363365 
    364          data_out=shared_ptr<CDataOutput>(new CNc4DataOutput(oss.str(), false, useClassicFormat, 
    365                                                              fileComm, multifile, isCollective)); 
    366          isOpen=true ; 
    367  
    368          data_out->writeFile(CFile::get(this)); 
    369          std::vector<CField*>::iterator it, end = this->enabledFields.end(); 
    370          for (it = this->enabledFields.begin() ;it != end; it++) 
    371          { 
     366        data_out = shared_ptr<CDataOutput>(new CNc4DataOutput(oss.str(), append, useClassicFormat, 
     367                                                              fileComm, multifile, isCollective)); 
     368        isOpen = true; 
     369 
     370        data_out->writeFile(CFile::get(this)); 
     371 
     372        // Do not recreate the file structure if opening an existing file 
     373        if (!data_out->IsInAppendMode()) 
     374        { 
     375          std::vector<CField*>::iterator it, end = this->enabledFields.end(); 
     376          for (it = this->enabledFields.begin(); it != end; it++) 
     377          { 
    372378            CField* field = *it; 
    373379            this->data_out->writeFieldGrid(field); 
    374          } 
    375          this->data_out->writeTimeDimension(); 
    376  
    377          for (it = this->enabledFields.begin() ;it != end; it++) 
    378          { 
     380          } 
     381          this->data_out->writeTimeDimension(); 
     382 
     383          for (it = this->enabledFields.begin(); it != end; it++) 
     384          { 
    379385            CField* field = *it; 
    380386            this->data_out->writeField(field); 
    381          } 
    382  
    383          vector<CVariable*> listVars = getAllVariables() ; 
    384          for (vector<CVariable*>::iterator it = listVars.begin() ;it != listVars.end(); it++) this-> data_out-> writeAttribute(*it) ; 
    385  
    386          this->data_out->definition_end(); 
     387          } 
     388 
     389          vector<CVariable*> listVars = getAllVariables() ; 
     390          for (vector<CVariable*>::iterator it = listVars.begin(); it != listVars.end(); it++) 
     391            this->data_out->writeAttribute(*it); 
     392 
     393          this->data_out->definition_end(); 
     394        } 
    387395      } 
    388396   } 
Note: See TracChangeset for help on using the changeset viewer.