Changeset 528 for XIOS/trunk/src/output


Ignore:
Timestamp:
12/03/14 17:54:33 (10 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.

Location:
XIOS/trunk/src/output
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/output/onetcdf4.cpp

    r517 r528  
     1#include <fstream> 
     2 
    13#include "onetcdf4.hpp" 
    24#include "group_template.hpp" 
     
    1113 
    1214      CONetCDF4::CONetCDF4 
    13          (const StdString & filename, bool exist, bool useClassicFormat, const MPI_Comm * comm, bool multifile) 
     15         (const StdString & filename, bool append, bool useClassicFormat, const MPI_Comm * comm, bool multifile) 
    1416            : path() 
    1517            , useClassicFormat(useClassicFormat) 
     18            , recordOffset(0) 
    1619      { 
    1720         this->wmpi = (comm != NULL) && !multifile; 
    18          this->initialize(filename, exist, useClassicFormat, comm,multifile); 
     21         this->initialize(filename, append, useClassicFormat, comm,multifile); 
    1922      } 
    2023 
     
    3033 
    3134      void CONetCDF4::initialize 
    32          (const StdString & filename, bool exist, bool useClassicFormat, const MPI_Comm * comm, bool multifile) 
     35         (const StdString & filename, bool append, bool useClassicFormat, const MPI_Comm * comm, bool multifile) 
    3336      { 
    3437         this->useClassicFormat = useClassicFormat; 
     
    3841            mode |= useClassicFormat ? NC_PNETCDF : NC_MPIIO; 
    3942 
    40          if (!exist) 
     43         // If the file does not exist, we always create it 
     44         if (!append || !std::ifstream(filename.c_str())) 
    4145         { 
    4246            if (comm != NULL) 
     
    4650            } 
    4751            else CNetCdfInterface::create(filename, mode, this->ncidp); 
     52 
     53            this->appendMode = false; 
     54            this->recordOffset = 0; 
    4855         } 
    4956         else 
    5057         { 
     58            mode |= NC_WRITE; 
    5159            if (comm != NULL) 
    5260            { 
     
    5563            } 
    5664            else CNetCdfInterface::open(filename, mode, this->ncidp); 
     65 
     66            this->appendMode = true; 
     67            // Find out how many temporal records have been written already to the file we are opening 
     68            int ncUnlimitedDimId; 
     69            CNetCdfInterface::inqUnLimDim(this->ncidp, ncUnlimitedDimId); 
     70            if (ncUnlimitedDimId != -1) 
     71               CNetCdfInterface::inqDimLen(this->ncidp, ncUnlimitedDimId, this->recordOffset); 
     72            else 
     73               this->recordOffset = 0; 
    5774         } 
    5875 
     
    424441         if (iddims.begin()->compare(this->getUnlimitedDimensionName()) == 0) 
    425442         { 
    426             sstart.push_back(record); 
     443            sstart.push_back(record + recordOffset); 
    427444            scount.push_back(1);  
    428445            if ((start == NULL) && 
  • XIOS/trunk/src/output/onetcdf4.hpp

    r517 r528  
    2626 
    2727            /// Constructeurs /// 
    28             CONetCDF4(const StdString & filename, bool exist, bool useClassicFormat = false, 
     28            CONetCDF4(const StdString & filename, bool append, bool useClassicFormat = false, 
    2929                      const MPI_Comm * comm = NULL, bool multifile = true); 
    3030 
     
    3434 
    3535            /// Initialisation /// 
    36             void initialize(const StdString & filename, bool exist, bool useClassicFormat, 
     36            void initialize(const StdString & filename, bool append, bool useClassicFormat, 
    3737                            const MPI_Comm * comm, bool multifile); 
    3838            void close(void) ; 
     
    118118            int ncidp; 
    119119            bool wmpi; 
     120            /*! Number of records already written when opening an existing file. 
     121             *  always 0 when creating a new file */ 
     122            size_t recordOffset; 
    120123            map<int,size_t> timeAxis ; 
    121124      }; // class CONetCDF4 
Note: See TracChangeset for help on using the changeset viewer.