Skip to content

Commit

Permalink
Merge commit '46609d6c3dc7f6588b1bd51247d8a59a2bb63b53'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Aug 13, 2024
2 parents b582098 + 46609d6 commit 08c1fa6
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 62 deletions.
3 changes: 2 additions & 1 deletion agrolib/criteriaModel/criteria1DCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ bool Crit1DCase::initializeNumericalFluxes(std::string &error)
double maxSurfaceWater = crop.getSurfaceWaterPonding() * 0.001; // [m]
double roughnessManning = 0.024; // [s m^-0.33]
int surfaceIndex = 0;
soilFluxes3D::setSurfaceProperties(surfaceIndex, roughnessManning, maxSurfaceWater);
soilFluxes3D::setSurfaceProperties(surfaceIndex, roughnessManning);

// center
float x0 = 0;
Expand All @@ -194,6 +194,7 @@ bool Crit1DCase::initializeNumericalFluxes(std::string &error)
int nodeIndex = 0;
soilFluxes3D::setNode(nodeIndex, x0, y0, z0, area, isSurface, true, BOUNDARY_RUNOFF, float(unit.slope), float(ly));
soilFluxes3D::setNodeSurface(nodeIndex, surfaceIndex);
soilFluxes3D::setNodePond(nodeIndex, maxSurfaceWater);
soilFluxes3D::setNodeLink(nodeIndex, nodeIndex + 1, DOWN, float(area));

// set soil nodes
Expand Down
2 changes: 1 addition & 1 deletion agrolib/dbMeteoGrid/dbMeteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4126,7 +4126,7 @@ bool Crit3DMeteoGridDbHandler::MeteoGridToRasterFlt(double cellSize, const gis::
{
myGrid.getXY(row, col, utmx, utmy);
gis::getLatLonFromUtm(gisSettings, utmx, utmy, &lat, &lon);
gis::getGridRowColFromLonLat (latlonHeader, lon, lat, &dataGridRow, &dataGridCol);
gis::getRowColFromLonLat (latlonHeader, lon, lat, &dataGridRow, &dataGridCol);
if (dataGridRow < 0 || dataGridRow >= latlonHeader.nrRows || dataGridCol < 0 || dataGridCol >= latlonHeader.nrCols)
{
myValue = NODATA;
Expand Down
1 change: 1 addition & 0 deletions agrolib/dbMeteoGrid/dbMeteoGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
std::vector<float> loadGridHourlyVar(QString *errorStr, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB);
std::vector<float> loadGridHourlyVarFixedFields(QString *errorStr, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB);
std::vector<float> exportAllDataVar(QString *errorStr, frequencyType freq, meteoVariable variable, QString id, QDateTime myFirstTime, QDateTime myLastTime, std::vector<QString> &dateStr);

bool getYearList(QString *errorStr, QString meteoPoint, QList<QString>* yearList);
bool idDailyList(QString *errorStr, QList<QString>* idMeteoList);

Expand Down
40 changes: 24 additions & 16 deletions agrolib/dbMeteoPoints/dbArkimet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,28 @@ QList<int> DbArkimet::getHourlyVar()



void DbArkimet::initStationsDailyTables(QDate startDate, QDate endDate, QList<QString> stations, QList<QString> idVar)
void DbArkimet::initStationsDailyTables(const QDate &startDate, const QDate &endDate,
const QList<QString> &stationList, const QList<QString> &idVarList)
{

for (short i=0; i<idVar.size(); i++)
QList<QString> varList;
for (int i=0; i < idVarList.size(); i++)
{
idVar[i].insert(0,"'");
idVar[i].insert(idVar[i].size(),"'");
varList.append("'" + idVarList[i] + "'");
}

for (int i = 0; i < stations.size(); i++)
for (int i = 0; i < stationList.size(); i++)
{
QString statement = QString("CREATE TABLE IF NOT EXISTS `%1_D` "
"(date_time TEXT, id_variable INTEGER, value REAL, PRIMARY KEY(date_time,id_variable))").arg(stations[i]);
"(date_time TEXT, id_variable INTEGER, value REAL, "
"PRIMARY KEY(date_time,id_variable))").arg(stationList[i]);

QSqlQuery qry(statement, _db);
qry.exec();

statement = QString("DELETE FROM `%1_D` WHERE date_time >= DATE('%2') AND date_time < DATE('%3', '+1 day') AND id_variable IN (%4)")
.arg(stations[i]).arg(startDate.toString("yyyy-MM-dd")).arg(endDate.toString("yyyy-MM-dd")).arg(idVar.join(","));
statement = QString("DELETE FROM `%1_D` WHERE date_time >= DATE('%2') "
"AND date_time < DATE('%3', '+1 day') AND id_variable IN (%4)")
.arg(stationList[i], startDate.toString("yyyy-MM-dd"), endDate.toString("yyyy-MM-dd"), varList.join(","));

qry = QSqlQuery(statement, _db);
qry.exec();
Expand All @@ -171,29 +174,34 @@ void DbArkimet::initStationsDailyTables(QDate startDate, QDate endDate, QList<QS
}


void DbArkimet::initStationsHourlyTables(QDate startDate, QDate endDate, QList<QString> stations, QList<QString> idVar)
void DbArkimet::initStationsHourlyTables(const QDate &startDate, const QDate &endDate,
const QList<QString> &stationList, const QList<QString> &idVarList)
{
// start from 01:00
QDateTime startTime(startDate, QTime(1,0,0), Qt::UTC);

QDateTime endTime(endDate, QTime(0,0,0), Qt::UTC);
endTime = endTime.addSecs(3600 * 24);

for (short i=0; i<idVar.size(); i++)
QList<QString> varList;
for (int i=0; i < idVarList.size(); i++)
{
idVar[i].insert(0,"'");
idVar[i].insert(idVar[i].size(),"'");
varList.append("'" + idVarList[i] + "'");
}

for (int i = 0; i < stations.size(); i++)
for (int i = 0; i < stationList.size(); i++)
{
QString statement = QString("CREATE TABLE IF NOT EXISTS `%1_H` (date_time TEXT, id_variable INTEGER, value REAL, PRIMARY KEY(date_time,id_variable))").arg(stations[i]);
QString statement = QString("CREATE TABLE IF NOT EXISTS `%1_H` "
"(date_time TEXT, id_variable INTEGER, value REAL, "
"PRIMARY KEY(date_time,id_variable))").arg(stationList[i]);

QSqlQuery qry(statement, _db);
qry.exec();

statement = QString("DELETE FROM `%1_H` WHERE date_time >= DATETIME('%2') AND date_time <= DATETIME('%3') AND id_variable IN (%4)")
.arg(stations[i]).arg(startTime.toString("yyyy-MM-dd hh:mm:ss")).arg(endTime.toString("yyyy-MM-dd hh:mm:ss")).arg(idVar.join(","));
statement = QString("DELETE FROM `%1_H` WHERE date_time >= DATETIME('%2') "
"AND date_time <= DATETIME('%3') AND id_variable IN (%4)")
.arg(stationList[i], startTime.toString("yyyy-MM-dd hh:mm:ss"),
endTime.toString("yyyy-MM-dd hh:mm:ss"), varList.join(","));

qry = QSqlQuery(statement, _db);
qry.exec();
Expand Down
6 changes: 4 additions & 2 deletions agrolib/dbMeteoPoints/dbArkimet.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
QList<int> getId(QString VarName);
QList<VariablesList> getVariableProperties(QList<int> id);

void initStationsDailyTables(QDate startDate, QDate endDate, QList<QString> stations, QList<QString> idVar);
void initStationsHourlyTables(QDate startDate, QDate endDate, QList<QString> stations, QList<QString> idVar);
void initStationsDailyTables(const QDate &startDate, const QDate &endDate,
const QList<QString> &stationList, const QList<QString> &idVarList);
void initStationsHourlyTables(const QDate &startDate, const QDate &endDate,
const QList<QString> &stationList, const QList<QString> &idVarList);

void createTmpTableHourly();
void deleteTmpTableHourly();
Expand Down
20 changes: 10 additions & 10 deletions agrolib/dbMeteoPoints/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,9 @@ bool Download::downloadDailyData(const QDate &startDate, const QDate &endDate, c


bool Download::downloadHourlyData(const QDate &startDate, const QDate &endDate, const QString &dataset,
QList<QString> &stations, QList<int> &variables, QString &errorString)
const QList<QString> &stationList, const QList<int> &varList, QString &errorString)
{
QList<VariablesList> variableList = _dbMeteo->getVariableProperties(variables);
QList<VariablesList> variableList = _dbMeteo->getVariableProperties(varList);
if (variableList.size() == 0)
return false;

Expand All @@ -557,13 +557,13 @@ bool Download::downloadHourlyData(const QDate &startDate, const QDate &endDate,
idVar.append(QString::number(variableList[i].id()));

// create station tables
_dbMeteo->initStationsHourlyTables(startDate, endDate, stations, idVar);
_dbMeteo->initStationsHourlyTables(startDate, endDate, stationList, idVar);

QString product = QString(";product: VM2,%1").arg(variables[0]);
QString product = QString(";product: VM2,%1").arg(varList[0]);

for (int i = 1; i < variables.size(); i++)
for (int i = 1; i < varList.size(); i++)
{
product = product % QString(" or VM2,%1").arg(variables[i]);
product = product % QString(" or VM2,%1").arg(varList[i]);
}

// start from 01:00
Expand All @@ -584,17 +584,17 @@ bool Download::downloadHourlyData(const QDate &startDate, const QDate &endDate,
QNetworkRequest request;
int countStation = 0;

while (countStation < stations.size())
while (countStation < stationList.size())
{
if (j == 0)
{
area = QString(";area: VM2,%1").arg(stations[countStation]);
area = QString(";area: VM2,%1").arg(stationList[countStation]);
j = j+1;
countStation = countStation+1;
}
while (countStation < stations.size() && j < maxStationSize)
while (countStation < stationList.size() && j < maxStationSize)
{
area = area % QString(" or VM2,%1").arg(stations[countStation]);
area = area % QString(" or VM2,%1").arg(stationList[countStation]);
countStation = countStation+1;
j = j+1;
}
Expand Down
2 changes: 1 addition & 1 deletion agrolib/dbMeteoPoints/download.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
QList<QString> &stations, QList<int> &variables, bool prec0024, QString &errorString);

bool downloadHourlyData(const QDate &startDate, const QDate &endDate, const QString &dataset,
QList<QString> &stations, QList<int> &variables, QString &errorString);
const QList<QString> &stationList, const QList<int> &varList, QString &errorString);

DbArkimet* getDbArkimet();

Expand Down
25 changes: 8 additions & 17 deletions agrolib/gdal.pri
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@
# How to compile on windows:
#
# win32-msvc (Microsoft Visual C)
# - install GDAL (32 or 64 bit) from OSGeo4W https://trac.osgeo.org/osgeo4w/
# - add GDAL_PATH to the system variables - example: GDAL_PATH = C:\OSGeo4W64
# - add GDAL_DATA to the system variables - example: GDAL_DATA = C:\OSGeo4W64\share\epsg_csv
# - add PROJ_LIB to the system variables - example: PROJ_LIB = C:\OSGeo4W64\share\proj
# - install GDAL from OSGeo4W https://trac.osgeo.org/osgeo4w/
# - add GDAL_PATH to the system variables - example: GDAL_PATH = C:\OSGeo4W
# - add GDAL_DATA to the system variables - example: GDAL_DATA = C:\OSGeo4W\share\epsg_csv
# - add PROJ_LIB to the system variables - example: PROJ_LIB = C:\OSGeo4W\share\proj
# - add OSGeo4W\bin to the system path
#
# win32-g++ (MinGW)
# Unfortunately it doesn't seem to work at the moment
# - install and update MSYS2 from https://www.msys2.org/
# - run MSYS2 shell and install GDAL package - example: pacman -S mingw-w64-x86_64-gdal
# - add MSYS_PATH to system variables - example: MSYS_PATH = C:\msys64\mingw64
# - add msys\mingw\bin to the system path
#
#------------------------------------------------------------------------------------------

unix:!macx {
Expand All @@ -28,21 +21,19 @@ unix:!macx {
}

win32-msvc {
LIBS += -L$$(GDAL_PATH)/lib/ -lgdal_i -lgeos_c
LIBS += -L$$(GDAL_PATH)/lib/ -lgdal_i

INCLUDEPATH += $$(GDAL_PATH)/include
DEPENDPATH += $$(GDAL_PATH)/include
}

win32-g++ {
LIBS += -L$$(MSYS_PATH)/lib/ -lgdal -lgeos -lgeos_c
LIBS += -L$$(GDAL_PATH)/lib/ -lgdal

INCLUDEPATH += $$(MSYS_PATH)/include
DEPENDPATH += $$(MSYS_PATH)/include
INCLUDEPATH += $$(GDAL_PATH)/include
DEPENDPATH += $$(GDAL_PATH)/include

PRE_TARGETDEPS += $$(MSYS_PATH)/lib/libgdal.a
PRE_TARGETDEPS += $$(MSYS_PATH)/lib/libgeos.dll.a
PRE_TARGETDEPS += $$(MSYS_PATH)/lib/libgeos_c.dll.a
}

mac {
Expand Down
2 changes: 0 additions & 2 deletions agrolib/gdalHandler/gdalHandler.pro
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ SOURCES += \
gdalExtensions.cpp \
gdalRasterFunctions.cpp \
gdalShapeFunctions.cpp \
# gdalShapeIntersection.cpp

HEADERS += \
gdalExtensions.h \
gdalRasterFunctions.h \
gdalShapeFunctions.h \
# gdalShapeIntersection.h


include(../gdal.pri)
6 changes: 3 additions & 3 deletions agrolib/gis/gis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,10 @@ namespace gis
v->col = int(floor((p.x - myHeader.llCorner.x) / myHeader.cellSize));
}

void getGridRowColFromLonLat(const Crit3DLatLonHeader& myHeader, double myX, double myY, int *row, int *col)
void getRowColFromLonLat(const Crit3DLatLonHeader& myHeader, double lon, double lat, int *row, int *col)
{
*row = int(floor((myY - myHeader.llCorner.latitude) / myHeader.dy));
*col = int(floor((myX - myHeader.llCorner.longitude) / myHeader.dx));
*row = int(floor((lat - myHeader.llCorner.latitude) / myHeader.dy));
*col = int(floor((lon - myHeader.llCorner.longitude) / myHeader.dx));
}

void getRowColFromLatLon(const Crit3DLatLonHeader& latLonHeader, const Crit3DGeoPoint& p, int* row, int* col)
Expand Down
2 changes: 1 addition & 1 deletion agrolib/gis/gis.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
void getRowColFromXY(const Crit3DRasterHeader& myHeader, double myX, double myY, int *row, int *col);
void getRowColFromXY(const Crit3DRasterHeader& myHeader, const Crit3DUtmPoint& p, int *row, int *col);
void getRowColFromXY(const Crit3DRasterHeader& myHeader, const Crit3DUtmPoint& p, Crit3DRasterCell* v);
void getGridRowColFromLonLat(const Crit3DLatLonHeader& myHeader, double myX, double myY, int *row, int *col);
void getRowColFromLonLat(const Crit3DLatLonHeader& myHeader, double lon, double lat, int *row, int *col);

void getRowColFromLatLon(const Crit3DLatLonHeader &latLonHeader, const Crit3DGeoPoint& p, int *myRow, int *myCol);
bool isOutOfGridRowCol(int myRow, int myCol, const Crit3DRasterGrid &rasterGrid);
Expand Down
8 changes: 4 additions & 4 deletions agrolib/meteo/meteoGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,19 +976,19 @@ void Crit3DMeteoGrid::saveRowColfromZone(gis::Crit3DRasterGrid* zoneGrid, std::v
int myRow, myCol;
for (int row = 0; row < zoneGrid->header->nrRows; row++)
{

for (int col = 0; col < zoneGrid->header->nrCols; col++)
{
value = zoneGrid->value[row][col];
if (value != zoneGrid->header->flag)
{
zoneGrid->getXY(row, col, x, y);
if (!_gridStructure.isUTM())
if (! _gridStructure.isUTM())
{
double utmX = x;
double utmY = y;
gis::getLatLonFromUtm(_gisSettings, utmX, utmY, &y, &x);
gis::getGridRowColFromLonLat(_gridStructure.header(), x, y, &myRow, &myCol);
double lat, lon;
gis::getLatLonFromUtm(_gisSettings, utmX, utmY, &lat, &lon);
gis::getRowColFromLonLat(_gridStructure.header(), lon, lat, &myRow, &myCol);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions agrolib/snow/snow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void Crit3DSnow::initialize()
}


void Crit3DSnow::setInputData(double temp, double prec, double relHum, double windInt, double globalRad,
void Crit3DSnow::setSnowInputData(double temp, double prec, double relHum, double windInt, double globalRad,
double beamRad, double transmissivity, double clearSkyTransmissivity, double waterContent)
{
_airT = temp;
Expand All @@ -100,7 +100,7 @@ void Crit3DSnow::setInputData(double temp, double prec, double relHum, double wi
_beamRadiation = beamRad;
_transmissivity = transmissivity;
_clearSkyTransmissivity = clearSkyTransmissivity;
_surfaceWaterContent = std::max(waterContent, 0.0);
_surfaceWaterContent = std::max(waterContent, 0.0); // [mm]
}


Expand Down Expand Up @@ -328,7 +328,7 @@ void Crit3DSnow::computeSnowBrooksModel()
QPrecipS = (HEAT_CAPACITY_SNOW / 1000.) * (_precSnow / 1000.) * (std::min(0., _airT) - prevSurfaceTemp);
QPrecip = QPrecipW + QPrecipS;

// temperatura dell'acqua: almeno 1 grado
// temperatura dell'acqua superficiale: almeno 1 grado
QWaterHeat = (HEAT_CAPACITY_WATER / 1000.) * (_surfaceWaterContent / 1000.)
* (std::max(1., (prevSurfaceTemp + _airT) / 2.) - prevSurfaceTemp);

Expand Down
2 changes: 1 addition & 1 deletion agrolib/snow/snow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

void initialize();

void setInputData(double temp, double prec, double relHum, double windInt, double globalRad,
void setSnowInputData(double temp, double prec, double relHum, double windInt, double globalRad,
double beamRad, double transmissivity, double clearSkyTransmissivity, double waterContent);

bool checkValidPoint();
Expand Down

0 comments on commit 08c1fa6

Please sign in to comment.