Changeset 707
- Timestamp:
- 09/24/15 15:55:17 (9 years ago)
- Location:
- XIOS/trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/io/nc4_data_output.cpp
r706 r707 1393 1393 void CNc4DataOutput::writeFieldData_ (CField* field) 1394 1394 { 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); 1425 1434 1426 1435 if (wtime) … … 1461 1470 } 1462 1471 1463 bool isRoot ; 1464 if (server->intraCommRank==0) isRoot=true ; 1465 else isRoot=false ; 1472 bool isRoot = (server->intraCommRank == 0); 1466 1473 1467 1474 if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty()) 1468 1475 { 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); 1474 1481 } 1475 1482 … … 1490 1497 field->outputField(fieldData); 1491 1498 1492 if (!field->prec.isEmpty() && field->prec ==2) fieldData=round(fieldData);1499 if (!field->prec.isEmpty() && field->prec == 2) fieldData = round(fieldData); 1493 1500 1494 1501 switch (SuperClass::type) … … 1508 1515 } 1509 1516 } 1510 break 1517 break; 1511 1518 } 1512 1519 case (ONE_FILE) : … … 1971 1978 ///-------------------------------------------------------------- 1972 1979 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 } 1973 2006 } // namespace xios -
XIOS/trunk/src/io/nc4_data_output.hpp
r705 r707 88 88 const StdString & nav_model); 89 89 90 StdSize getRecordFromTime(Time time); 91 90 92 private : 91 93 … … 96 98 MPI_Comm comm_file; 97 99 const StdString filename; 100 std::map<Time, StdSize> timeToRecordCache; 101 98 102 std::set<std::string> writtenDomains ; 99 103 std::set<std::string> writtenAxis ; 100 104 bool isWrittenDomain(const std::string& domainName) { return this->writtenDomains.find(domainName) != this->writtenDomains.end(); } 101 105 bool isWrittenAxis(const std::string& axisName) { return this->writtenAxis.find(axisName) != this->writtenAxis.end(); } 102 103 106 }; // class CNc4DataOutput 104 107 -
XIOS/trunk/src/io/onetcdf4.cpp
r686 r707 17 17 , wmpi(false) 18 18 , useClassicFormat(useClassicFormat) 19 , recordOffset(0)20 19 { 21 20 this->initialize(filename, append, useClassicFormat, comm,multifile); … … 23 22 24 23 //--------------------------------------------------------------- 25 26 24 27 25 CONetCDF4::~CONetCDF4(void) … … 60 58 61 59 this->appendMode = false; 62 this->recordOffset = 0;63 60 } 64 61 else … … 71 68 72 69 this->appendMode = true; 73 // Find out how many temporal records have been written already to the file we are opening74 int ncUnlimitedDimId;75 CNetCdfInterface::inqUnLimDim(this->ncidp, ncUnlimitedDimId);76 if (ncUnlimitedDimId != -1)77 CNetCdfInterface::inqDimLen(this->ncidp, ncUnlimitedDimId, this->recordOffset);78 else79 this->recordOffset = 0;80 70 } 81 71 … … 224 214 225 215 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()); 226 242 } 227 243 … … 430 446 if (iddims.begin()->compare(this->getUnlimitedDimensionName()) == 0) 431 447 { 432 sstart.push_back(record + recordOffset);448 sstart.push_back(record); 433 449 scount.push_back(1); 434 450 if ((start == NULL) && -
XIOS/trunk/src/io/onetcdf4.hpp
r686 r707 26 26 27 27 /// Constructeurs /// 28 CONetCDF4(const StdString 29 const MPI_Comm 28 CONetCDF4(const StdString& filename, bool append, bool useClassicFormat = false, 29 const MPI_Comm* comm = NULL, bool multifile = true); 30 30 31 CONetCDF4(const CONetCDF4 32 CONetCDF4(const CONetCDF4 31 CONetCDF4(const CONetCDF4& onetcdf4); // Not implemented. 32 CONetCDF4(const CONetCDF4* const onetcdf4); // Not implemented. 33 33 34 34 35 35 /// Initialisation /// 36 void initialize(const StdString 37 const MPI_Comm 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); 40 40 void definition_start(void); 41 41 void definition_end(void); 42 42 43 43 /// Mutateurs /// 44 void setCurrentPath(const CONetCDF4Path 44 void setCurrentPath(const CONetCDF4Path& path); 45 45 46 int addGroup(const StdString 46 int addGroup(const StdString& name); 47 47 int addDimension(const StdString& name, const StdSize size = UNLIMITED_DIM); 48 int addVariable(const StdString 49 const std::vector<StdString> 48 int addVariable(const StdString& name, nc_type type, 49 const std::vector<StdString>& dim); 50 50 51 51 //---------------------------------------------------------------- … … 53 53 54 54 template <class T> 55 void setDefaultValue(const StdString & varname, const T* value = NULL);55 void setDefaultValue(const StdString& varname, const T* value = NULL); 56 56 57 57 void setCompressionLevel(const StdString& varname, int compressionLevel); 58 58 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); 60 60 61 61 /// Ecriture des données /// 62 62 template <class T, int ndim> 63 void writeData(const CArray<T,ndim>& data, const StdString 63 void writeData(const CArray<T,ndim>& data, const StdString& name, 64 64 bool collective, StdSize record, 65 const std::vector<StdSize> 66 const std::vector<StdSize> 65 const std::vector<StdSize>* start = NULL, 66 const std::vector<StdSize>* count = NULL); 67 67 68 void writeData(const CArray<int, 2>& data, const StdString 69 void writeTimeAxisData(const CArray<double,1>& data, const StdString 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); 71 71 /// Accesseur /// 72 const CONetCDF4Path 72 const CONetCDF4Path& getCurrentPath(void) const; 73 73 74 74 /// Destructeur /// … … 86 86 /// Accesseurs /// 87 87 int getCurrentGroup(void); 88 int getGroup(const CONetCDF4Path 89 int getVariable(const StdString 90 int getDimension(const StdString 91 std::vector<StdSize> getDimensions (const StdString 92 std::vector<StdString> getDimensionsIdList (const StdString 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); 93 93 int getUnlimitedDimension(void); 94 94 StdString getUnlimitedDimensionName(void); 95 95 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); 97 99 98 100 bool useClassicFormat; //!< If true, NetCDF4 will use the classic NetCDF3 format … … 101 103 102 104 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); 103 109 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); 114 115 115 116 /// Propriétés privées /// … … 117 118 int ncidp; 118 119 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; 123 121 }; // class CONetCDF4 124 122 -
XIOS/trunk/src/node/field.cpp
r687 r707 32 32 , refObject(), baseRefObject() 33 33 , grid(), file() 34 , written(false) 34 35 , nstep(0), nstepMax(0) 35 36 , hasOutputFile(false) … … 43 44 , refObject(), baseRefObject() 44 45 , grid(), file() 46 , written(false) 45 47 , nstep(0), nstepMax(0) 46 48 , hasOutputFile(false) … … 442 444 } 443 445 444 void CField::resetNStep( void)445 { 446 this->nstep = 0;446 void CField::resetNStep(StdSize nstep /*= 0*/) 447 { 448 this->nstep = nstep; 447 449 } 448 450 … … 457 459 { 458 460 return !this->refObject.empty(); 461 } 462 463 //---------------------------------------------------------------- 464 465 bool CField::wasWritten() const 466 { 467 return written; 468 } 469 470 void CField::setWritten() 471 { 472 written = true; 459 473 } 460 474 -
XIOS/trunk/src/node/field.hpp
r687 r707 56 56 typedef CFieldAttributes SuperClassAttribute; 57 57 58 public 58 public: 59 59 60 60 typedef CFieldAttributes RelAttributes; … … 80 80 func::CFunctor::ETimeType getOperationTimeType() const; 81 81 82 public : 83 82 public: 84 83 StdSize getNStep(void) const; 85 84 … … 91 90 void setRelFile(CFile* _file); 92 91 void incrementNStep(void); 93 void resetNStep( );92 void resetNStep(StdSize nstep = 0); 94 93 void resetNStepMax(); 95 94 96 95 std::map<int, StdSize> getGridDataSize(); 97 96 98 public 97 public: 99 98 bool isActive(void) const; 100 99 bool hasOutputFile; 100 101 bool wasWritten() const; 102 void setWritten(); 101 103 102 104 bool getUseCompressedOutput() const; … … 170 172 const std::pair<StdString, StdString>& getRefDomainAxisIds(); 171 173 172 public 174 public: 173 175 /// Propriétés privées /// 174 176 CVariableGroup* vVariableGroup; … … 179 181 CDuration freq_operation_srv, freq_write_srv; 180 182 183 bool written; //<! Was the field written at least once 181 184 StdSize nstep, nstepMax; 182 185 bool isEOF;
Note: See TracChangeset
for help on using the changeset viewer.