diff --git a/agrolib/grapevine/grapevine.cpp b/agrolib/grapevine/grapevine.cpp index 3e112e07e..22125020c 100644 --- a/agrolib/grapevine/grapevine.cpp +++ b/agrolib/grapevine/grapevine.cpp @@ -113,11 +113,6 @@ void Vine3D_Grapevine::resetLayers() { for (int i=0 ; i < nrMaxLayers ; i++) { - //psiSoilProfile[i] = NODATA ; - //soilWaterContentProfile[i]= NODATA ; - //soilWaterContentProfileFC[i]= NODATA; - //soilWaterContentProfileWP[i]= NODATA; - //soilFieldCapacity[i] = NODATA; fractionTranspirableSoilWaterProfile[i]= NODATA; stressCoefficientProfile[i] = NODATA; transpirationInstantLayer[i] = NODATA; @@ -126,15 +121,10 @@ void Vine3D_Grapevine::resetLayers() } } -bool Vine3D_Grapevine::initializeLayers(int myMaxLayers) +void Vine3D_Grapevine::initializeLayers(int myMaxLayers) { nrMaxLayers = myMaxLayers; - //psiSoilProfile = (double *) calloc(nrLayers, sizeof(double)); - //soilWaterContentProfile = (double *) calloc(nrLayers, sizeof(double)); - //soilWaterContentProfileFC = (double *) calloc(nrLayers, sizeof(double)); - //soilWaterContentProfileWP = (double *) calloc(nrLayers, sizeof(double)); - //soilFieldCapacity = (double *) calloc (nrLayers, sizeof(double)); fractionTranspirableSoilWaterProfile = static_cast (calloc(size_t(nrMaxLayers), sizeof(double))); stressCoefficientProfile = static_cast (calloc(size_t(nrMaxLayers), sizeof(double))); transpirationInstantLayer = static_cast (calloc(size_t(nrMaxLayers), sizeof(double))); @@ -143,10 +133,9 @@ bool Vine3D_Grapevine::initializeLayers(int myMaxLayers) currentProfile = static_cast (calloc(size_t(nrMaxLayers), sizeof(double))); resetLayers(); - - return true; } + void Vine3D_Grapevine::setDate (Crit3DTime myTime) { myDoy = getDoyFromDate(myTime.date); diff --git a/agrolib/grapevine/grapevine.h b/agrolib/grapevine/grapevine.h index 12a4eb76a..a0d18faa1 100644 --- a/agrolib/grapevine/grapevine.h +++ b/agrolib/grapevine/grapevine.h @@ -192,13 +192,13 @@ struct Crit3DModelCase { int id; Crit3DLanduse landuse; - //int soilIndex; + int soilIndex; float shootsPerPlant; float plantDensity; float maxLAIGrass; int trainingSystem; - float maxIrrigationRate; //[mm/h] + float maxIrrigationRate; // [mm h-1] int soilLayersNr; double soilTotalDepth; @@ -393,7 +393,7 @@ Vine3D_Grapevine(); //void initializeGrapevineModel(TVineCultivar* cultivar, double secondsPerStep); - bool initializeLayers(int myMaxLayers); + void initializeLayers(int myMaxLayers); bool initializeStatePlant(int doy, Crit3DModelCase *vineField); void resetLayers(); diff --git a/bin/VINE3D/main.cpp b/bin/VINE3D/main.cpp index 86c6d2e16..5875a97f1 100644 --- a/bin/VINE3D/main.cpp +++ b/bin/VINE3D/main.cpp @@ -36,9 +36,6 @@ int main(int argc, char *argv[]) if (! myProject.loadParameters("parameters.ini")) return -1; - if (! myProject.loadVine3DSettings()) - return -1; - if (myProject.modality == MODE_GUI) { QApplication::setOverrideCursor(Qt::ArrowCursor); diff --git a/bin/VINE3D/vine3DProject.cpp b/bin/VINE3D/vine3DProject.cpp index 76af532a0..a2ce89291 100644 --- a/bin/VINE3D/vine3DProject.cpp +++ b/bin/VINE3D/vine3DProject.cpp @@ -56,13 +56,6 @@ void Vine3DProject::initializeVine3DProject() } -bool Vine3DProject::loadVine3DSettings() -{ - //eventually put Vine3D generic settings - return true; -} - - void Vine3DProject::clearVine3DProject() { if (isProjectLoaded) @@ -79,7 +72,8 @@ void Vine3DProject::clearVine3DProject() } } -bool Vine3DProject::loadVine3DProjectSettings() + +void Vine3DProject::loadVine3DSettings() { projectSettings->beginGroup("project"); @@ -93,22 +87,21 @@ bool Vine3DProject::loadVine3DProjectSettings() computeDiseases = projectSettings->value("compute_diseases").toBool(); projectSettings->endGroup(); - - return true; } + bool Vine3DProject::openVine3DDatabase(QString fileName) { if (fileName == "") { - logError("Missing VINE3D DB filename"); + logError("Missing VINE3D db filename (field db_vine3d)"); return false; } dbVine3D = QSqlDatabase::addDatabase("QSQLITE", QUuid::createUuid().toString()); dbVine3D.setDatabaseName(getCompleteFileName(fileName, "")); - if (!dbVine3D.open()) + if (! dbVine3D.open()) { errorString = "Connection with database fail"; return false; @@ -118,7 +111,8 @@ bool Vine3DProject::openVine3DDatabase(QString fileName) return true; } -bool Vine3DProject::loadVine3DProject(QString myFileName) + +bool Vine3DProject::loadVine3DProject(QString projectFileName) { clearVine3DProject(); @@ -126,16 +120,16 @@ bool Vine3DProject::loadVine3DProject(QString myFileName) initializeProject3D(); initializeVine3DProject(); - if (myFileName == "") return(false); + if (projectFileName == "") + return false; - if (! loadProjectSettings(myFileName)) + if (! loadProjectSettings(projectFileName)) return false; if (! loadProject3DSettings()) return false; - if (! loadVine3DProjectSettings()) - return false; + loadVine3DSettings(); if (dbVine3DFileName != "") openVine3DDatabase(dbVine3DFileName); @@ -161,13 +155,15 @@ bool Vine3DProject::loadVine3DProject(QString myFileName) return false; } - if (! loadFieldShape()) + QString fileName = getCompleteFileName(landUseMapFileName, PATH_GEO); + if (! loadFieldMap(fileName)) { - myFileName = getCompleteFileName(landUseMapFileName, PATH_GEO); - if (! loadFieldMap(myFileName)) return false; + logError(); + return false; } - if (! loadSoilMap(soilMapFileName)) + fileName = getCompleteFileName(soilMapFileName, PATH_GEO); + if (! loadSoilMap(fileName)) { logError(); return false; @@ -184,6 +180,7 @@ bool Vine3DProject::loadVine3DProject(QString myFileName) logError(); return false; } + processes.setComputeWater(true); outputWaterBalanceMaps = new Crit3DWaterBalanceMaps(DEM); @@ -414,64 +411,6 @@ int Vine3DProject::queryFieldPoint(double x, double y) } -bool Vine3DProject::loadFieldShape() -{ - return false; - /* to be revised - this->logInfo ("Read Fields..."); - int dim = 1; - int i, j, id; - double x0, y0; - std::vector valuesList; - - QString myQueryString = "SELECT id_field FROM fields_shp"; - - QSqlQuery myQuery; - myQuery = this->dbConnection.exec(myQueryString); - if (myQuery.size() == -1) - { - this->errorString = myQuery.lastError().text(); - return(false); - } - myQuery.clear(); - - this->modelCaseIndexMap.initializeGrid(this->DEM); - - double step = this->modelCaseIndexMap.header->cellSize / (2*dim+1); - - for (long row = 0; row < this->modelCaseIndexMap.header->nrRows ; row++) - for (long col = 0; col < this->modelCaseIndexMap.header->nrCols; col++) - if (this->DEM.value[row][col] != this->DEM.header->flag) - { - //center - gis::getUtmXYFromRowCol(this->modelCaseIndexMap, row, col, &x0, &y0); - id = queryFieldPoint(x0, y0); - if (id != NODATA) - this->modelCaseIndexMap.value[row][col] = id; - else - { - valuesList.resize(0); - for (i = -dim; i <= dim; i++) - for (j = -dim; j <= dim; j++) - if ((i != 0)|| (j != 0)) - { - id = queryFieldPoint(x0+(i*step), y0+(j*step)); - if (id != NODATA) - valuesList.push_back(id); - } - if (valuesList.size() == 0) - this->modelCaseIndexMap.value[row][col] = this->modelCaseIndexMap.header->flag; - else - this->modelCaseIndexMap.value[row][col] = gis::prevailingValue(valuesList); - } - } - - gis::updateMinMaxRasterGrid(&(this->modelCaseIndexMap)); - this->nrModelCases = int(this->modelCaseIndexMap.maximum); - return true; - */ -} - int getCaseIndexFromId(int caseId, std::vector modelCases) { if (modelCases.size() == 0) @@ -1152,42 +1091,6 @@ float Vine3DProject::getTimeStep() } -/* -bool Vine3DProject::loadObsDataFilled(QDateTime firstTime, QDateTime lastTime) -{ - QDate d1 = firstTime.date().addDays(-30); - QDate d2 = lastTime.date().addDays(30); - - if (! this->loadObsDataAllPoints(d1, d2, false)) return(false); - - // Replace missing data - long nrReplacedData = 0; - Crit3DTime myTime = getCrit3DTime(firstTime); - long nrHours = firstTime.secsTo(lastTime) / 3600; - for (int i = 0; i <=nrHours; i++) - { - if (!checkLackOfData(this, airTemperature, myTime, &nrReplacedData) - || !checkLackOfData(this, precipitation, myTime, &nrReplacedData) - || !checkLackOfData(this, airRelHumidity, myTime, &nrReplacedData)) - { - this->logError("Weather data missing: " + getQDateTime(myTime).toString("yyyyMMdd hh:mm")); - return(false); - } - checkLackOfData(this, windScalarIntensity, myTime, &nrReplacedData); - myTime = myTime.addSeconds(3600); - } - - if(nrReplacedData > 0) - { - this->logInfo("\nWarning! "+ QString::number(nrReplacedData)+ " hourly data are missing."); - this->logInfo("They was replaced by mean values.\n"); - } - - return true; -} -*/ - - bool Vine3DProject::runModels(QDateTime firstTime, QDateTime lastTime, bool saveOutput) { if (! isProjectLoaded) @@ -1196,7 +1099,6 @@ bool Vine3DProject::runModels(QDateTime firstTime, QDateTime lastTime, bool save return false; } - //if (!loadObsDataFilled(dateTime1, dateTime2)) logInfoGUI("Loading meteo data..."); if (! loadMeteoPointsData(firstTime.date().addDays(-1), lastTime.date().addDays(+1), true, false, false)) { @@ -1589,26 +1491,26 @@ bool Vine3DProject::initializeGrapevine() { outputPlantMaps = new Crit3DOutputPlantMaps(DEM, nrLayers); - if (! grapevine.initializeLayers(nrLayers)) - return false; + grapevine.initializeLayers(nrLayers); int nrSoilLayersWithoutRoots = 2; int soilLayerWithRoot; - double depthModeRootDensity; //[m] depth of mode of root density - double depthMeanRootDensity; //[m] depth of mean of root density + double depthModeRootDensity; // [m] depth of mode of root density + double depthMeanRootDensity; // [m] depth of mean of root density + - for (int i = 0 ; i < modelCases.size(); i++) + for (int i = 0; i < modelCases.size(); i++) { // TODO - int soilIndex = 0; + int soilIndex = soilIndexList[0]; int nrHorizons = soilList[soilIndex].nrHorizons; soil::Crit3DHorizon myHorizon = soilList[soilIndex].horizon[nrHorizons - 1]; - unsigned int j=0; - while (j < nrLayers - 1 && layerDepth.at(size_t(j)) <= myHorizon.lowerDepth) - j++; + unsigned int layer=0; + while (layer < nrLayers - 1 && layerDepth.at(size_t(layer)) <= myHorizon.lowerDepth) + layer++; - modelCases[i].soilLayersNr = j; + modelCases[i].soilLayersNr = layer; modelCases[i].soilTotalDepth = myHorizon.lowerDepth; soilLayerWithRoot = modelCases[i].soilLayersNr - nrSoilLayersWithoutRoots; diff --git a/bin/VINE3D/vine3DProject.h b/bin/VINE3D/vine3DProject.h index 35b01bb31..a70691e96 100644 --- a/bin/VINE3D/vine3DProject.h +++ b/bin/VINE3D/vine3DProject.h @@ -87,8 +87,7 @@ Vine3DProject(); - bool loadVine3DSettings(); - bool loadVine3DProjectSettings(); + void loadVine3DSettings(); bool loadFieldsProperties(); bool loadDBPoints(); @@ -102,13 +101,12 @@ void initializeVine3DProject(); void clearVine3DProject(); - bool loadVine3DProject(QString myFileName); + bool loadVine3DProject(QString projectFileName); bool openVine3DDatabase(QString fileName); bool initializeGrapevine(); int queryFieldPoint(double x, double y); - bool loadFieldShape(); bool loadFieldMap(QString myFileName); bool readFieldQuery(QSqlQuery &myQuery, int &idField, Crit3DLanduse &landuse, int &vineIndex, int &trainingIndex, float &maxLaiGrass, float &maxIrrigationRate);