Changeset 1961 for XIOS/dev/dev_ym/XIOS_COUPLING/src/filter
- Timestamp:
- 10/12/20 11:26:40 (4 years ago)
- Location:
- XIOS/dev/dev_ym/XIOS_COUPLING/src/filter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/file_writer_store_filter.cpp
r1935 r1961 2 2 #include "exception.hpp" 3 3 #include "field.hpp" 4 #include "file.hpp" 5 #include "context.hpp" 4 6 5 7 namespace xios … … 7 9 CFileWriterStoreFilter::CFileWriterStoreFilter(CGarbageCollector& gc, CField* field) 8 10 : CInputPin(gc, 1) 9 , field(field) 11 , field_(field) 12 10 13 { 11 if (!field) 12 ERROR("CFileWriterStoreFilter::CFileWriterStoreFilter(CField* field)", 13 "The field cannot be null."); 14 CContext* context = CContext::getCurrent(); 15 16 if (!field) ERROR("CFileWriterStoreFilter::CFileWriterStoreFilter(CField* field)", "The field cannot be null."); 17 file_ = field->getFileOut() ; 18 grid_= field->getGrid() ; 19 freqWrite_ = file_->output_freq ; 20 lastWrite_ = context->getCalendar()->getInitDate(); 21 if (!file_->isEmptyZone() && (field->getGrid()->doGridHaveDataToWrite() || file_->type == CFile::type_attr::one_file)) 22 needToWrite_=true ; 23 else needToWrite_=false; 24 lastFileSplit_ = file_->getLastSplit() ; 25 nstep_ = 0 ; 26 if (!field->scale_factor.isEmpty()) { scaleFactor_ = field->scale_factor ; hasScaleFactor_ = true ; } 27 if (!field->add_offset.isEmpty()) { addOffset_ = field->add_offset ; hasAddOffset_ = true ; } 28 if (!field->prec.isEmpty() && field->prec == 2) hasRounding_ = true ; 29 if (!field->default_value.isEmpty()) {hasDefaultValue_=true ; defaultValue_ = field->default_value ;} 14 30 } 15 31 16 32 void CFileWriterStoreFilter::onInputReady(std::vector<CDataPacketPtr> data) 17 33 { 18 field->writeUpdateData(data[0]->data); 34 const CDate currentWrite = lastWrite_ + freqWrite_; 35 if (needToWrite_) 36 { 37 file_->checkWriteFile(); 38 if (file_->getLastSplit() != lastFileSplit_) 39 { 40 nstep_ = 0 ; 41 lastFileSplit_ = file_->getLastSplit() ; 42 } 43 nstep_ = nstep_+1; 44 45 CArray<double,1> dataIn = data[0]->data ; 46 CArray<double,1> fieldData ; 47 48 if (hasAddOffset_ || hasScaleFactor_ || hasRounding_) dataIn = data[0]->data ; 49 else dataIn.reference(data[0]->data) ; 50 51 if (hasAddOffset_) dataIn = dataIn - addOffset_ ; 52 if (hasScaleFactor_) dataIn = dataIn / scaleFactor_; 53 if (hasRounding_) dataIn = round(dataIn); 54 55 if (hasDefaultValue_) 56 { 57 size_t nbData=dataIn.numElements() ; 58 for (size_t idx = 0; idx < nbData; ++idx) if ( NumTraits<double>::isNan(dataIn(idx)) ) dataIn(idx)=defaultValue_ ; 59 } 60 61 if (field_->getUseCompressedOutput()) fieldData.reference(dataIn) ; 62 else 63 { 64 fieldData.resize(grid_->getWorkflowToFullConnector()->getDstSize()); 65 if (hasDefaultValue_) grid_->getWorkflowToFullConnector()->transfer(dataIn, fieldData, defaultValue_ ) ; 66 else grid_->getWorkflowToFullConnector()->transfer(dataIn, fieldData ) ; 67 } 68 nstep_ = file_->getDataOutput()->writeFieldData(field_, fieldData, lastWrite_,currentWrite, nstep_); 69 } 70 71 lastWrite_ = currentWrite ; 72 19 73 } 20 74 -
XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/file_writer_store_filter.hpp
r1935 r1961 7 7 { 8 8 class CField; 9 class CFile; 10 class CGrid; 9 11 10 12 /*! … … 46 48 47 49 private: 48 CField* field; //<! The associated field 49 std::map<Time, CDataPacketPtr> packets; //<! The stored packets 50 CField* field_; //<! The associated field 51 CFile* file_ ; 52 CGrid* grid_ ; 53 CDate lastWrite_ ; 54 CDate lastFileSplit_ ; 55 CDuration freqWrite_ ; 56 int nstep_ ; 57 bool needToWrite_ ; 58 double scaleFactor_ = 1.0; 59 double addOffset_ = 0.0; 60 bool hasScaleFactor_ = false ; 61 bool hasAddOffset_ = false ; 62 double defaultValue_ ; 63 bool hasDefaultValue_=false; 64 bool hasRounding_=false ; 65 50 66 }; // class CFileWriterStoreFilter 51 67 } // namespace xios
Note: See TracChangeset
for help on using the changeset viewer.