From 73a5eb7c60750a459a036a2ca86de56c4c9a91e0 Mon Sep 17 00:00:00 2001 From: ftomei Date: Thu, 23 May 2024 19:09:10 +0200 Subject: [PATCH] fix missing prec --- criteriaModel/criteria1DCase.cpp | 15 +++++++++++++-- criteriaModel/criteria1DCase.h | 1 + criteriaModel/criteria1DProject.cpp | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/criteriaModel/criteria1DCase.cpp b/criteriaModel/criteria1DCase.cpp index 62332266..cd529c15 100644 --- a/criteriaModel/criteria1DCase.cpp +++ b/criteriaModel/criteria1DCase.cpp @@ -77,6 +77,7 @@ Crit1DCase::Crit1DCase() soilLayers.clear(); prevWaterContent.clear(); + nrMissingPrec = 0; computeFactorOfSafety = false; } @@ -503,11 +504,21 @@ bool Crit1DCase::computeDailyModel(Crit3DDate &myDate, std::string &error) double tmin = double(meteoPoint.getMeteoPointValueD(myDate, dailyAirTemperatureMin)); double tmax = double(meteoPoint.getMeteoPointValueD(myDate, dailyAirTemperatureMax)); - if (isEqual(prec, NODATA) || isEqual(tmin, NODATA) || isEqual(tmax, NODATA)) + if (isEqual(tmin, NODATA) || isEqual(tmax, NODATA)) { - error = "Missing weather data: " + myDate.toStdString(); + error = "Missing temperature data: " + myDate.toStdString(); return false; } + if (isEqual(prec, NODATA)) + { + prec = 0; + nrMissingPrec++; + if ((nrMissingPrec / meteoPoint.nrObsDataDaysD) > 0.01) + { + error = "Too many precipitation data are missing (> 1%)"; + return false; + } + } // check on wrong data if (prec < 0) prec = 0; diff --git a/criteriaModel/criteria1DCase.h b/criteriaModel/criteria1DCase.h index dbd1910c..3ac543ee 100644 --- a/criteriaModel/criteria1DCase.h +++ b/criteriaModel/criteria1DCase.h @@ -56,6 +56,7 @@ public: Crit1DCompUnit unit; bool computeFactorOfSafety; + int nrMissingPrec; // SOIL soil::Crit3DSoil mySoil; diff --git a/criteriaModel/criteria1DProject.cpp b/criteriaModel/criteria1DProject.cpp index 20ac9716..68c6de56 100644 --- a/criteriaModel/criteria1DProject.cpp +++ b/criteriaModel/criteria1DProject.cpp @@ -935,6 +935,8 @@ bool Crit1DProject::computeUnit(unsigned int unitIndex, unsigned int memberNr) // use memberNr = 0 for deterministic run bool Crit1DProject::computeCase(unsigned int memberNr) { + // initialize + myCase.nrMissingPrec = 0; myCase.fittingOptions.useWaterRetentionData = myCase.unit.useWaterRetentionData; // the user wants to compute the factor of safety myCase.computeFactorOfSafety = (factorOfSafetyDepth.size() > 0); @@ -973,7 +975,7 @@ bool Crit1DProject::computeCase(unsigned int memberNr) { float irriRatio = getIrriRatioFromCropClass(dbCrop, "crop_class", "id_class", myCase.unit.idCropClass, projectError); - if (irriRatio < 0.001f) + if (irriRatio < 0.001) { // No irrigation: nothing to do return true;