Skip to content

Commit

Permalink
Merge commit '0eb53a4661e71f10829df4de63531d7b1122570e'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Feb 21, 2024
2 parents 3ccec89 + 0eb53a4 commit 687612a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
58 changes: 54 additions & 4 deletions agrolib/criteriaModel/criteria1DProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void Crit1DProject::initialize()
outputString = "";

// specific outputs
isClimateOutput = false;
waterDeficitDepth.clear();
waterContentDepth.clear();
degreeOfSaturationDepth.clear();
Expand Down Expand Up @@ -253,60 +254,80 @@ bool Crit1DProject::readSettings()
// OUTPUT variables (optional)
QList<QString> depthList;
projectSettings->beginGroup("output");

isClimateOutput = projectSettings->value("isClimateOutput", false).toBool();

depthList = projectSettings->value("waterContent").toStringList();
if (! setVariableDepth(depthList, waterContentDepth))
{
projectError = "Wrong water content depth in " + configFileName;
return false;
}

depthList = projectSettings->value("degreeOfSaturation").toStringList();
if (! setVariableDepth(depthList, degreeOfSaturationDepth))
{
projectError = "Wrong degree of saturation depth in " + configFileName;
return false;
}

depthList = projectSettings->value("waterPotential").toStringList();
if (! setVariableDepth(depthList, waterPotentialDepth))
{
projectError = "Wrong water potential depth in " + configFileName;
return false;
}

depthList = projectSettings->value("waterDeficit").toStringList();
if (! setVariableDepth(depthList, waterDeficitDepth))
{
projectError = "Wrong water deficit depth in " + configFileName;
return false;
}

depthList = projectSettings->value("awc").toStringList();
if (! setVariableDepth(depthList, awcDepth))
{
projectError = "Wrong available water capacity depth in " + configFileName;
return false;
}

depthList = projectSettings->value("availableWater").toStringList();
if (depthList.size() == 0)
{
// alternative field name
depthList = projectSettings->value("aw").toStringList();
}
if (! setVariableDepth(depthList, availableWaterDepth))
{
projectError = "Wrong available water depth in " + configFileName;
return false;
}

depthList = projectSettings->value("fractionAvailableWater").toStringList();
if (depthList.size() == 0)
{
// alternative field name
depthList = projectSettings->value("faw").toStringList();
}
if (! setVariableDepth(depthList, fractionAvailableWaterDepth))
{
projectError = "Wrong fraction available water depth in " + configFileName;
return false;
}

depthList = projectSettings->value("factorOfSafety").toStringList();
if (depthList.size() == 0)
depthList = projectSettings->value("factorOfSafety").toStringList();
{
// alternative field name
depthList = projectSettings->value("fos").toStringList();
}
if (! setVariableDepth(depthList, factorOfSafetyDepth))
{
projectError = "Wrong slope stability depth in " + configFileName;
return false;
}

projectSettings->endGroup();

return true;
Expand Down Expand Up @@ -1542,12 +1563,21 @@ bool Crit1DProject::createOutputTable(QString &myError)
QString queryString = "DROP TABLE '" + myCase.unit.idCase + "'";
QSqlQuery myQuery = this->dbOutput.exec(queryString);

queryString = "CREATE TABLE '" + myCase.unit.idCase + "'"
if (isClimateOutput)
{
queryString = "CREATE TABLE '" + myCase.unit.idCase + "'"
+ " ( DATE TEXT, AVAILABLE_WATER REAL,"
+ " TRANSP_MAX, TRANSP REAL";
}
else
{
queryString = "CREATE TABLE '" + myCase.unit.idCase + "'"
+ " ( DATE TEXT, PREC REAL, IRRIGATION REAL, WATER_CONTENT REAL, SURFACE_WC REAL, "
+ " AVAILABLE_WATER REAL, READILY_AW REAL, FRACTION_AW REAL, "
+ " RUNOFF REAL, DRAINAGE REAL, LATERAL_DRAINAGE REAL, CAPILLARY_RISE REAL, "
+ " ET0 REAL, TRANSP_MAX, TRANSP REAL, EVAP_MAX REAL, EVAP REAL, "
+ " LAI REAL, ROOT_DEPTH REAL, BALANCE REAL";
}

// specific depth variables
for (unsigned int i = 0; i < waterContentDepth.size(); i++)
Expand Down Expand Up @@ -1591,6 +1621,7 @@ bool Crit1DProject::createOutputTable(QString &myError)
queryString += ", " + fieldName + " REAL";
}

// close query
queryString += ")";
myQuery = this->dbOutput.exec(queryString);

Expand All @@ -1608,11 +1639,20 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst)
{
if (isFirst)
{
outputString = "INSERT INTO '" + myCase.unit.idCase + "'"
if (isClimateOutput)
{
outputString = "INSERT INTO '" + myCase.unit.idCase + "'"
+ " (DATE, AVAILABLE_WATER,"
+ " TRANSP_MAX, TRANSP";
}
else
{
outputString = "INSERT INTO '" + myCase.unit.idCase + "'"
+ " (DATE, PREC, IRRIGATION, WATER_CONTENT, SURFACE_WC, "
+ " AVAILABLE_WATER, READILY_AW, FRACTION_AW, "
+ " RUNOFF, DRAINAGE, LATERAL_DRAINAGE, CAPILLARY_RISE, ET0, "
+ " TRANSP_MAX, TRANSP, EVAP_MAX, EVAP, LAI, ROOT_DEPTH, BALANCE";
}

// specific depth variables
for (unsigned int i = 0; i < waterContentDepth.size(); i++)
Expand Down Expand Up @@ -1663,7 +1703,16 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst)
outputString += ",";
}

outputString += "('" + QString::fromStdString(myDate.toStdString()) + "'"
if (isClimateOutput)
{
outputString += "('" + QString::fromStdString(myDate.toStdString()) + "'"
+ "," + QString::number(myCase.output.dailyAvailableWater, 'g', 4)
+ "," + QString::number(myCase.output.dailyMaxTranspiration, 'g', 3)
+ "," + QString::number(myCase.output.dailyTranspiration, 'g', 3);
}
else
{
outputString += "('" + QString::fromStdString(myDate.toStdString()) + "'"
+ "," + QString::number(myCase.output.dailyPrec)
+ "," + QString::number(myCase.output.dailyIrrigation)
+ "," + QString::number(myCase.output.dailySoilWaterContent, 'g', 4)
Expand All @@ -1683,6 +1732,7 @@ void Crit1DProject::updateOutput(Crit3DDate myDate, bool isFirst)
+ "," + getOutputStringNullZero(myCase.crop.LAI)
+ "," + getOutputStringNullZero(myCase.crop.roots.rootDepth)
+ "," + QString::number(myCase.output.dailyBalance, 'g', 3);
}

// specific depth variables
for (unsigned int i = 0; i < waterContentDepth.size(); i++)
Expand Down
1 change: 1 addition & 0 deletions agrolib/criteriaModel/criteria1DProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
bool addDateTimeLogFile;

// specific output
bool isClimateOutput;
std::vector<int> waterContentDepth;
std::vector<int> degreeOfSaturationDepth;
std::vector<int> waterPotentialDepth;
Expand Down

0 comments on commit 687612a

Please sign in to comment.