Skip to content

Commit

Permalink
fix locale decimal separator
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Oct 28, 2023
1 parent 89087a4 commit c809208
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 183 deletions.
319 changes: 162 additions & 157 deletions agrolib/criteria1DWidget/criteria1DWidget.cpp

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions agrolib/criteria1DWidget/criteria1DWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
void updateTabCarbonNitrogen();

void tabChanged(int index);
bool checkIfCropIsChanged();
bool checkCropIsChanged();
void irrigationVolumeChanged();

private:
Expand All @@ -69,9 +69,9 @@
Crit3DCrop cropFromDB;

QString meteoTableName;
bool cropChanged;
bool isCropChanged;
QList<QString> yearList;
bool onlyOneYear;
bool isOnlyOneYear;

Crit3DMeteoSettings meteoSettings;

Expand Down Expand Up @@ -106,16 +106,16 @@
QLineEdit* thermalThresholdValue;
QLineEdit* upperThermalThresholdValue;
QLineEdit* degreeDaysEmergenceValue;
QLineEdit* degreeDaysLAIincValue;
QLineEdit* degreeDaysLAIdecValue;
QLineEdit* degreeDaysLaiIncreaseValue;
QLineEdit* degreeDaysLaiDecreaseValue;
QLineEdit* LAIcurveAValue;
QLineEdit* LAIcurveBValue;
QLineEdit* rootDepthZeroValue;
QLineEdit* rootDepthMaxValue;
QComboBox* rootShapeComboBox;
QDoubleSpinBox* shapeDeformationValue;
QLabel *rootDegreeDaysInc;
QLineEdit* rootDegreeDaysIncValue;
QLabel *rootDegreeDaysGrowth;
QLineEdit* rootDegreeDaysGrowthValue;
QLineEdit* irrigationVolumeValue;
QSpinBox* irrigationShiftValue;
QLineEdit* degreeDaysStartValue;
Expand Down
14 changes: 7 additions & 7 deletions agrolib/criteriaModel/criteria1DMeteo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,11 +696,11 @@ bool checkYearMeteoGrid(QSqlDatabase dbMeteo, QString tableD, QString fieldTime,
}


bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMeteoPoint *meteoPoint, QString validYear, QString *error)
bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMeteoPoint *meteoPoint, int validYear, QString *error)
{
*error = "";

QString queryString = "SELECT * FROM '" + table +"'" + " WHERE strftime('%Y',date) = '" + validYear +"'";
QString queryString = "SELECT * FROM '" + table +"'" + " WHERE strftime('%Y',date) = '" + QString::number(validYear) +"'";
QSqlQuery query = dbMeteo->exec(queryString);

query.first();
Expand All @@ -711,8 +711,8 @@ bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMet
}

QDate date;
QDate previousDate(validYear.toInt()-1, 12, 31);
QDate lastDate(validYear.toInt(), 12, 31);
QDate previousDate(validYear-1, 12, 31);
QDate lastDate(validYear, 12, 31);
float tmin = NODATA;
float tmax = NODATA;
float tavg = NODATA;
Expand All @@ -725,7 +725,6 @@ bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMet
const float tmax_min = -40;
const float tmax_max = 60;


do
{
getValue(query.value("date"), &date);
Expand Down Expand Up @@ -767,7 +766,7 @@ bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMet
}
while(query.next());

QDate firstDate(validYear.toInt(), 1, 1);
QDate firstDate(validYear, 1, 1);
int daysInYear = firstDate.daysInYear();
float prevTmin = NODATA;
float prevTmax = NODATA;
Expand Down Expand Up @@ -846,6 +845,7 @@ bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMet
* \details date format: "yyyy-mm-dd"
* \return true if data are correctly loaded
* \note meteoPoint have to be initialized BEFORE function
* \note maxNrDays = NODATA: read all data
*/
bool readDailyDataCriteria1D(QSqlQuery &query, Crit3DMeteoPoint &meteoPoint, int maxNrDays, QString &error)
{
Expand Down Expand Up @@ -884,7 +884,7 @@ bool readDailyDataCriteria1D(QSqlQuery &query, Crit3DMeteoPoint &meteoPoint, int

if (! myDate.isValid())
{
if (currentIndex < (maxNrDays-1))
if (maxNrDays != NODATA && currentIndex < (maxNrDays-1))
{
error = meteoID + "Wrong date format: " + query.value("date").toString();
return false;
Expand Down
2 changes: 1 addition & 1 deletion agrolib/criteriaModel/criteria1DMeteo.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
bool getLastDate(QSqlDatabase* dbMeteo, QString table, QString year, QDate* date, QString *error);
bool getLastDateGrid(QSqlDatabase dbMeteo, QString table, QString fieldTime, QString year, QDate* date, QString *error);

bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMeteoPoint *meteoPoint, QString validYear, QString *error);
bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMeteoPoint *meteoPoint, int validYear, QString *error);
bool readDailyDataCriteria1D(QSqlQuery &query, Crit3DMeteoPoint &meteoPoint, int maxNrDays, QString &error);


Expand Down
14 changes: 7 additions & 7 deletions agrolib/crop/crop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,13 @@ bool Crit3DCrop::dailyUpdate(const Crit3DDate &myDate, double latitude, const st
int currentDoy = getDoyFromDate(myDate);

// update degree days
degreeDays += computeDegreeDays(tmin, tmax, thermalThreshold, upperThermalThreshold);
double dailyDD = getDailyDegreeIncrease(tmin, tmax, currentDoy);
if (isEqual(dailyDD, NODATA))
{
myError = "Error in computing degree dyas for " + myDate.toStdString();
return false;
}
degreeDays += dailyDD;

// update LAI
if ( !updateLAI(latitude, nrLayers, currentDoy))
Expand Down Expand Up @@ -755,9 +761,3 @@ std::string getCropTypeString(speciesType cropType)
return "No crop type";
}

double computeDegreeDays(double myTmin, double myTmax, double myLowerThreshold, double myUpperThreshold)
{
return MAXVALUE((myTmin + MINVALUE(myTmax, myUpperThreshold)) / 2. - myLowerThreshold, 0);
}


2 changes: 0 additions & 2 deletions agrolib/crop/crop.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,5 @@
speciesType getCropType(std::string cropType);
std::string getCropTypeString(speciesType cropType);

double computeDegreeDays(double myTmin, double myTmax, double myLowerThreshold, double myUpperThreshold);


#endif // CROP_H
5 changes: 3 additions & 2 deletions agrolib/crop/root.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
class Crit3DCrop;

enum rootDistributionType {CYLINDRICAL_DISTRIBUTION, CARDIOID_DISTRIBUTION, GAMMA_DISTRIBUTION};
const int numRootDistributionType = 3;
const int nrRootDistributionType = 3;

enum rootGrowthType {LINEAR, EXPONENTIAL, LOGISTIC};

/*!
Expand All @@ -22,7 +23,7 @@
rootGrowthType growth;

/*! parameters */
double degreeDaysRootGrowth; /*!< [°D] */
int degreeDaysRootGrowth; /*!< [°D] */
double rootDepthMin; /*!< [m] */
double rootDepthMax; /*!< [m] */
double shapeDeformation; /*!< [-] */
Expand Down

0 comments on commit c809208

Please sign in to comment.