Changeset 707 for XIOS/trunk/src/io


Ignore:
Timestamp:
09/24/15 15:55:17 (9 years ago)
Author:
rlacroix
Message:

Append mode: Detect the correct restart point and erase some records if need be.

Location:
XIOS/trunk/src/io
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/io/nc4_data_output.cpp

    r706 r707  
    13931393      void CNc4DataOutput::writeFieldData_ (CField*  field) 
    13941394      { 
    1395          CContext* context = CContext::getCurrent() ; 
    1396 //          if (field->getRelFile()->isSyncTime()) SuperClassWriter::sync() ; 
    1397          CContextServer* server=context->server ; 
    1398  
    1399          CGrid* grid = field->grid ; 
    1400  
    1401          if (!grid->doGridHaveDataToWrite()) 
    1402           if (SuperClass::type==MULTI_FILE || !isCollective) return ; 
    1403  
    1404          StdString fieldid   = (!field->name.isEmpty()) 
    1405                              ? field->name.getValue() 
    1406                              : field->getBaseFieldReference()->getId(); 
    1407  
    1408          StdOStringStream oss; 
    1409          string timeAxisId ; 
    1410          if (field->getOperationTimeType() == func::CFunctor::instant)  timeAxisId="time_instant" ; 
    1411          else if (field->getOperationTimeType() == func::CFunctor::centered)  timeAxisId="time_centered" ; 
    1412  
    1413          StdString timeBoundId("time_counter_bounds"); 
    1414  
    1415          StdString timeAxisBoundId; 
    1416          if (field->getOperationTimeType() == func::CFunctor::instant)  timeAxisBoundId="time_instant_bounds" ; 
    1417          else if (field->getOperationTimeType() == func::CFunctor::centered)  timeAxisBoundId="time_centered_bounds" ; 
    1418  
    1419          CArray<double,1> time_data(1) ; 
    1420          CArray<double,1> time_data_bound(2); 
    1421          CArray<double,1> time_counter(1) ; 
    1422          CArray<double,1> time_counter_bound(2); 
    1423  
    1424         bool wtime   = !(!field->operation.isEmpty() && (field->getOperationTimeType() == func::CFunctor::once)); 
     1395        CContext* context = CContext::getCurrent(); 
     1396        CContextServer* server = context->server; 
     1397        CGrid* grid = field->grid; 
     1398 
     1399        if (!grid->doGridHaveDataToWrite()) 
     1400          if (SuperClass::type == MULTI_FILE || !isCollective) return; 
     1401 
     1402        StdString fieldid = !field->name.isEmpty() 
     1403                          ? field->name.getValue() 
     1404                          : field->getBaseFieldReference()->getId(); 
     1405 
     1406        StdOStringStream oss; 
     1407        string timeAxisId; 
     1408        if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisId = "time_instant"; 
     1409        else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisId = "time_centered"; 
     1410 
     1411        StdString timeBoundId("time_counter_bounds"); 
     1412 
     1413        StdString timeAxisBoundId; 
     1414        if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisBoundId = "time_instant_bounds"; 
     1415        else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisBoundId = "time_centered_bounds"; 
     1416 
     1417        if (!field->wasWritten()) 
     1418        { 
     1419          if (appendMode) 
     1420          { 
     1421            field->resetNStep(getRecordFromTime(field->last_Write_srv) + 1); 
     1422          } 
     1423 
     1424          field->setWritten(); 
     1425        } 
     1426 
     1427 
     1428        CArray<double,1> time_data(1); 
     1429        CArray<double,1> time_data_bound(2); 
     1430        CArray<double,1> time_counter(1); 
     1431        CArray<double,1> time_counter_bound(2); 
     1432 
     1433        bool wtime = (field->getOperationTimeType() != func::CFunctor::once); 
    14251434 
    14261435        if (wtime) 
     
    14611470        } 
    14621471 
    1463          bool isRoot ; 
    1464          if (server->intraCommRank==0) isRoot=true ; 
    1465          else isRoot=false ; 
     1472         bool isRoot = (server->intraCommRank == 0); 
    14661473 
    14671474         if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty()) 
    14681475         { 
    1469            double scaleFactor=1. ; 
    1470            double addOffset=0. ; 
    1471            if (!field->scale_factor.isEmpty()) scaleFactor=field->scale_factor ; 
    1472            if (!field->add_offset.isEmpty()) addOffset=field->add_offset ; 
    1473            field->scaleFactorAddOffset(scaleFactor,addOffset) ; 
     1476           double scaleFactor = 1.0; 
     1477           double addOffset = 0.0; 
     1478           if (!field->scale_factor.isEmpty()) scaleFactor = field->scale_factor; 
     1479           if (!field->add_offset.isEmpty()) addOffset = field->add_offset; 
     1480           field->scaleFactorAddOffset(scaleFactor, addOffset); 
    14741481         } 
    14751482 
     
    14901497             field->outputField(fieldData); 
    14911498 
    1492            if (!field->prec.isEmpty() && field->prec==2) fieldData=round(fieldData) ; 
     1499           if (!field->prec.isEmpty() && field->prec == 2) fieldData = round(fieldData); 
    14931500 
    14941501           switch (SuperClass::type) 
     
    15081515                   } 
    15091516                 } 
    1510                  break ; 
     1517                 break; 
    15111518              } 
    15121519              case (ONE_FILE) : 
     
    19711978      ///-------------------------------------------------------------- 
    19721979 
     1980      StdSize CNc4DataOutput::getRecordFromTime(Time time) 
     1981      { 
     1982        std::map<Time, StdSize>::const_iterator it = timeToRecordCache.find(time); 
     1983        if (it == timeToRecordCache.end()) 
     1984        { 
     1985          StdString timeAxisBoundsId("time_counter_bounds"); 
     1986          if (!SuperClassWriter::varExist(timeAxisBoundsId)) 
     1987            timeAxisBoundsId = "time_instant_bounds"; 
     1988 
     1989          CArray<double,2> timeAxisBounds; 
     1990          SuperClassWriter::getTimeAxisBounds(timeAxisBounds, timeAxisBoundsId, isCollective); 
     1991 
     1992          StdSize record = 0; 
     1993          double dtime(time); 
     1994          for (int n = timeAxisBounds.extent(1) - 1; n >= 0; n--) 
     1995          { 
     1996            if (timeAxisBounds(1, n) < dtime) 
     1997            { 
     1998              record = n + 1; 
     1999              break; 
     2000            } 
     2001          } 
     2002          it = timeToRecordCache.insert(std::make_pair(time, record)).first; 
     2003        } 
     2004        return it->second; 
     2005      } 
    19732006} // namespace xios 
  • XIOS/trunk/src/io/nc4_data_output.hpp

    r705 r707  
    8888                                     const StdString & nav_model); 
    8989 
     90            StdSize getRecordFromTime(Time time); 
     91 
    9092         private : 
    9193 
     
    9698            MPI_Comm comm_file; 
    9799            const StdString filename; 
     100            std::map<Time, StdSize> timeToRecordCache; 
     101 
    98102            std::set<std::string> writtenDomains ;  
    99103            std::set<std::string> writtenAxis ; 
    100104            bool isWrittenDomain(const std::string& domainName) { return this->writtenDomains.find(domainName) != this->writtenDomains.end(); } 
    101105            bool isWrittenAxis(const std::string& axisName) { return this->writtenAxis.find(axisName) != this->writtenAxis.end(); } 
    102  
    103106      }; // class CNc4DataOutput 
    104107 
  • XIOS/trunk/src/io/onetcdf4.cpp

    r686 r707  
    1717        , wmpi(false) 
    1818        , useClassicFormat(useClassicFormat) 
    19         , recordOffset(0) 
    2019      { 
    2120         this->initialize(filename, append, useClassicFormat, comm,multifile); 
     
    2322 
    2423      //--------------------------------------------------------------- 
    25  
    2624 
    2725      CONetCDF4::~CONetCDF4(void) 
     
    6058 
    6159            this->appendMode = false; 
    62             this->recordOffset = 0; 
    6360         } 
    6461         else 
     
    7168 
    7269            this->appendMode = true; 
    73             // Find out how many temporal records have been written already to the file we are opening 
    74             int ncUnlimitedDimId; 
    75             CNetCdfInterface::inqUnLimDim(this->ncidp, ncUnlimitedDimId); 
    76             if (ncUnlimitedDimId != -1) 
    77                CNetCdfInterface::inqDimLen(this->ncidp, ncUnlimitedDimId, this->recordOffset); 
    78             else 
    79                this->recordOffset = 0; 
    8070         } 
    8171 
     
    224214 
    225215         return retvalue; 
     216      } 
     217 
     218      //--------------------------------------------------------------- 
     219 
     220      void CONetCDF4::getTimeAxisBounds(CArray<double,2>& timeAxisBounds, const StdString& name, bool collective) 
     221      { 
     222        int grpid = this->getCurrentGroup(); 
     223        int varid = this->getVariable(name); 
     224 
     225        std::vector<StdSize> start(2), count(2); 
     226        start[0] = 0; 
     227        // Find out how many temporal records have been written already to the file we are opening 
     228        int ncUnlimitedDimId; 
     229        CNetCdfInterface::inqUnLimDim(this->ncidp, ncUnlimitedDimId); 
     230        CNetCdfInterface::inqDimLen(this->ncidp, ncUnlimitedDimId, count[0]); 
     231        start[1] = 0; 
     232        count[1] = 2; 
     233 
     234        timeAxisBounds.resize(count[1], count[0]); 
     235 
     236        if (this->wmpi && collective) 
     237          CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE); 
     238        if (this->wmpi && !collective) 
     239          CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT); 
     240 
     241        CNetCdfInterface::getVaraType(grpid, varid, &start[0], &count[0], timeAxisBounds.dataFirst()); 
    226242      } 
    227243 
     
    430446         if (iddims.begin()->compare(this->getUnlimitedDimensionName()) == 0) 
    431447         { 
    432             sstart.push_back(record + recordOffset); 
     448            sstart.push_back(record); 
    433449            scount.push_back(1); 
    434450            if ((start == NULL) && 
  • XIOS/trunk/src/io/onetcdf4.hpp

    r686 r707  
    2626 
    2727            /// Constructeurs /// 
    28             CONetCDF4(const StdString & filename, bool append, bool useClassicFormat = false, 
    29                       const MPI_Comm * comm = NULL, bool multifile = true); 
     28            CONetCDF4(const StdString& filename, bool append, bool useClassicFormat = false, 
     29                      const MPI_Comm* comm = NULL, bool multifile = true); 
    3030 
    31             CONetCDF4(const CONetCDF4 & onetcdf4);       // Not implemented. 
    32             CONetCDF4(const CONetCDF4 * const onetcdf4); // Not implemented. 
     31            CONetCDF4(const CONetCDF4& onetcdf4);       // Not implemented. 
     32            CONetCDF4(const CONetCDF4* const onetcdf4); // Not implemented. 
    3333 
    3434 
    3535            /// Initialisation /// 
    36             void initialize(const StdString & filename, bool append, bool useClassicFormat, 
    37                             const MPI_Comm * comm, bool multifile); 
    38             void close(void) ; 
    39             void sync(void) ; 
     36            void initialize(const StdString& filename, bool append, bool useClassicFormat, 
     37                            const MPI_Comm* comm, bool multifile); 
     38            void close(void); 
     39            void sync(void); 
    4040            void definition_start(void); 
    4141            void definition_end(void); 
    4242 
    4343            /// Mutateurs /// 
    44             void setCurrentPath(const CONetCDF4Path & path); 
     44            void setCurrentPath(const CONetCDF4Path& path); 
    4545 
    46             int addGroup(const StdString & name); 
     46            int addGroup(const StdString& name); 
    4747            int addDimension(const StdString& name, const StdSize size = UNLIMITED_DIM); 
    48             int addVariable(const StdString & name, nc_type type, 
    49                             const std::vector<StdString> & dim); 
     48            int addVariable(const StdString& name, nc_type type, 
     49                            const std::vector<StdString>& dim); 
    5050 
    5151      //---------------------------------------------------------------- 
     
    5353 
    5454            template <class T> 
    55                void setDefaultValue(const StdString & varname, const T * value = NULL); 
     55               void setDefaultValue(const StdString& varname, const T* value = NULL); 
    5656 
    5757            void setCompressionLevel(const StdString& varname, int compressionLevel); 
    5858 
    59             template <class T>  void addAttribute (const StdString & name, const T & value, const StdString * varname = NULL); 
     59            template <class T>  void addAttribute (const StdString& name, const T& value, const StdString* varname = NULL); 
    6060 
    6161            /// Ecriture des données /// 
    6262            template <class T, int ndim> 
    63                void writeData(const CArray<T,ndim>& data, const StdString & name, 
     63               void writeData(const CArray<T,ndim>& data, const StdString& name, 
    6464                              bool collective, StdSize record, 
    65                               const std::vector<StdSize> * start = NULL, 
    66                               const std::vector<StdSize> * count = NULL); 
     65                              const std::vector<StdSize>* start = NULL, 
     66                              const std::vector<StdSize>* count = NULL); 
    6767 
    68             void writeData(const CArray<int, 2>& data, const StdString & name); 
    69             void writeTimeAxisData(const CArray<double,1>& data, const StdString & name, 
    70                                    bool collective, StdSize record, bool Isroot) ; 
     68            void writeData(const CArray<int, 2>& data, const StdString& name); 
     69            void writeTimeAxisData(const CArray<double,1>& data, const StdString& name, 
     70                                   bool collective, StdSize record, bool Isroot); 
    7171            /// Accesseur /// 
    72             const CONetCDF4Path & getCurrentPath(void) const; 
     72            const CONetCDF4Path& getCurrentPath(void) const; 
    7373 
    7474            /// Destructeur /// 
     
    8686            /// Accesseurs /// 
    8787            int getCurrentGroup(void); 
    88             int getGroup(const CONetCDF4Path & path); 
    89             int getVariable(const StdString & varname); 
    90             int getDimension(const StdString & dimname); 
    91             std::vector<StdSize>   getDimensions       (const StdString & varname); 
    92             std::vector<StdString> getDimensionsIdList (const StdString * varname); 
     88            int getGroup(const CONetCDF4Path& path); 
     89            int getVariable(const StdString& varname); 
     90            int getDimension(const StdString& dimname); 
     91            std::vector<StdSize>   getDimensions       (const StdString& varname); 
     92            std::vector<StdString> getDimensionsIdList (const StdString* varname); 
    9393            int       getUnlimitedDimension(void); 
    9494            StdString getUnlimitedDimensionName(void); 
    9595 
    96             bool varExist(const StdString & varname); 
     96            void getTimeAxisBounds(CArray<double,2>& timeAxisBounds, const StdString& name, bool collective); 
     97 
     98            bool varExist(const StdString& varname); 
    9799 
    98100            bool useClassicFormat; //!< If true, NetCDF4 will use the classic NetCDF3 format 
     
    101103 
    102104         private : 
     105            template <class T> 
     106            void writeData_(int grpid, int varid, 
     107                            const std::vector<StdSize>& sstart, 
     108                            const std::vector<StdSize>& scount, T* data); 
    103109 
    104             template <class T> 
    105                void writeData_(int grpid, int varid, 
    106                                const std::vector<StdSize> & sstart, 
    107                                const std::vector<StdSize> & scount, T * data); 
    108  
    109             void getWriteDataInfos(const StdString & name, StdSize record, StdSize & array_size, 
    110                                    std::vector<StdSize> & sstart, 
    111                                    std::vector<StdSize> & scount, 
    112                                    const std::vector<StdSize> * start, 
    113                                    const std::vector<StdSize> * count); 
     110            void getWriteDataInfos(const StdString& name, StdSize record, StdSize& array_size, 
     111                                   std::vector<StdSize>& sstart, 
     112                                   std::vector<StdSize>& scount, 
     113                                   const std::vector<StdSize>* start, 
     114                                   const std::vector<StdSize>* count); 
    114115 
    115116            /// Propriétés privées /// 
     
    117118            int ncidp; 
    118119            bool wmpi; 
    119             /*! Number of records already written when opening an existing file. 
    120              *  always 0 when creating a new file */ 
    121             size_t recordOffset; 
    122             map<int,size_t> timeAxis ; 
     120            map<int,size_t> timeAxis; 
    123121      }; // class CONetCDF4 
    124122 
Note: See TracChangeset for help on using the changeset viewer.