/** * @file ClimoState.cc * @brief Source for ClimoState class */ #include #include #include #include #include #include #include using std::string; const double ClimoState::_climoMeanMissing = -9999.0; //------------------------------------------------------------------------- ClimoState::ClimoState(bool isCloudTop) : _ok(false), _isCloudTop(isCloudTop) { } //------------------------------------------------------------------------- ClimoState::ClimoState(const time_t &inputGenTime, int inputLeadTime, const MultiFcstGrid &inputData, bool isCloudTop) : _ok(true), _isCloudTop(isCloudTop), _data(inputData) { // for cloud top want everything, for non-cloud top want at least one // gen time bool needGen=true; _metadata = MdvMetadata(_data.getMetadataXml().getFreeformXml(), needGen, _isCloudTop); } //------------------------------------------------------------------------- ClimoState::~ClimoState() { } //------------------------------------------------------------------------- std::vector ClimoState::tooOld(const time_t &genTime, int daysInClimo) const { return _metadata.tooOld(genTime, daysInClimo); } //------------------------------------------------------------------------- void ClimoState::purgeForecast(const time_t &genTime, int leadTime, const MultiFcstGrid &data) { // remove this data from state, decrementing some counters and sums _remove(genTime, data); // erase gentime from metadata too _metadata.erase(genTime); } //------------------------------------------------------------------------- bool ClimoState::addToState(const time_t &genTime, const MultiFcstGrid &mdata, Grid::Encoding_t encoding) { bool isFirst = false; if (!_ok) { // need to initialize using this data, this is the first addition _initNew(mdata, encoding); isFirst = true; _ok = true; } bool didSomething = false; // for each field for (int i=0; igetNx(), data->getNy(), _climoMeanMissing); climoGrid.setEncoding(encoding); // load the counts and sums for that field ClimoStateGrids state(name, _data); if (state.normalize(climoGrid)) { _data.append(climoGrid); } } MetaDataXml xml; xml.addFreeformXml(_metadata.getXml()); return xml; } //------------------------------------------------------------------------- void ClimoState::_remove(const time_t &genTime, const MultiFcstGrid &data) { LOG(DEBUG) << "Removing data for gen time = " << DateTime::strn(genTime) << " from state"; // for each field for (int i=0; i countSumNames = CountSumNames::countSumNames(inputData.fieldNames()); const Grid *g = inputData.ithConstGrid(0); for (size_t i=0; i