Skip to content

Commit 88f27a0

Browse files
committed
v513 - Demand opt parsing fixes
Improved QA/QC in parsing rvm file (PArseManagementFile.cpp) bug: fixed parse indices for :REservoirWaterDemand (ParseManagementFile.cpp) bug: fixed references for !Dxxx[-n] (DemandExpressionHandling.cpp)
1 parent 68ab732 commit 88f27a0

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/DemandExpressionHandling.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ bool CDemandOptimizer::ConvertToExpressionTerm(const string s, expressionTerm* t
361361
ExitGracefullyIf(n>=0, "ConvertToExpressionTerm:: term in square brackets must be <0 for historical variables.",BAD_DATA_WARN);
362362
ExitGracefullyIf(n<-_nHistoryItems, "ConvertToExpressionTerm:: term in square brackets exceeds the magnitude of the :LookbackDuration", BAD_DATA_WARN);
363363

364-
if ((s[1] == 'Q') || (s[1] == 'D') || (s[1]=='I') || (s[1] == 'h') || (s[1] == 'B') || (s[1] == 'E'))
364+
if ((s[1] == 'Q') || (s[1]=='I') || (s[1] == 'h') || (s[1] == 'B') || (s[1] == 'E'))//|| (s[1] == 'D') doesnt yet support 'D' because history is basin indexed, while GetDVIndexFromString !D is SB indexed
365365
{
366366
if (n<0)
367367
{
@@ -757,11 +757,13 @@ bool CDemandOptimizer::ConvertToExpressionTerm(const string s, expressionTerm* t
757757
size_t ie = s.find(",",is);
758758
size_t ip = s.find_last_of(")");
759759
if (ie == NPOS) {
760+
cout<<"bad string: "<<s<<endl;
760761
warn="ConvertToExpressionTerm: missing comma in @max expression"+warnstring;
761762
ExitGracefully(warn.c_str(),BAD_DATA_WARN);
762763
return false;
763764
}
764765
if (ip == NPOS) {
766+
cout<<"bad string: "<<s<<endl;
765767
warn="ConvertToExpressionTerm: missing end parentheses in @max expression"+warnstring;
766768
ExitGracefully(warn.c_str(), BAD_DATA_WARN);
767769
return false;

src/ParseManagementFile.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,14 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options)
574574
if (Options.noisy){cout<<" Use Stage Units Correction "<<endl; }
575575
CSubBasin *pSB=pModel->GetSubBasinByID(s_to_ll(s[1]));
576576

577-
ExitGracefullyIf(pSB->GetGlobalIndex()==DOESNT_EXIST,"ParseManagementFile: subbasin ID in :UseStageUnitsCorrection is invalid",BAD_DATA_WARN);
578-
577+
if (pSB==NULL){
578+
ExitGracefully("ParseManagementFile: subbasin ID in :UseStageUnitsCorrection is invalid",BAD_DATA_WARN);
579+
break;
580+
}
579581
if (pSB->GetReservoir()==NULL){
580582
string advice="ParseManagementFile:The reservoir in subbasin "+to_string(pSB->GetID()) + " doesnt exist and cannot be used to calculate a stage units correction.";
581583
ExitGracefully(advice.c_str(), BAD_DATA_WARN);
584+
break;
582585
}
583586
else{
584587
int k=pSB->GetReservoir()->GetHRUIndex();
@@ -759,11 +762,12 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options)
759762
}
760763
//----------------------------------------------
761764
else if (!strcmp(s[0], ":EndWorkflowVarDefinition")) {
762-
if (Options.noisy){cout<<endl; }
765+
if (Options.noisy){cout<<":EndWorkflowVarDefinition"<<endl; }
763766
break;
764767
}
765768
else {
766-
WriteWarning("ParseManagementFile: Unrecognized command in :WorkflowVarDefinition command block",Options.noisy);
769+
string warn="ParseManagementFile: Unrecognized command "+to_string(s[0])+"in :WorkflowVarDefinition command block at line "+to_string(pp->GetLineNumber())+" of "+pp->GetFilename();
770+
WriteWarning(warn.c_str(),Options.noisy);
767771
}
768772
firstword=pp->Peek();
769773
if (firstword == ":Expression") {pp->NextIsMathExp();}
@@ -1232,7 +1236,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options)
12321236
{/*:DemandExpression [expression]*/
12331237
if(Options.noisy) { cout <<"Demand expression"<<endl; }
12341238
if (pDemand==NULL){
1235-
ExitGracefully(":DemandExpression must be between :WaterDemand and :EndWaterDemand commands.",BAD_DATA_WARN);
1239+
ExitGracefully(":DemandExpression must be between :WaterDemand and :EndWaterDemand or :ReservoirWaterDemand and :EndReservoirWaterDemand commands.",BAD_DATA_WARN);
12361240
}
12371241
else {
12381242
expressionStruct *pExp;
@@ -1253,7 +1257,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options)
12531257
}
12541258
break;
12551259
}
1256-
case (63): //--------------------------------------------
1260+
case (64): //--------------------------------------------
12571261
{ /*
12581262
:ReservoirWaterDemand [SBID] [ID] [Name]
12591263
...
@@ -1289,13 +1293,13 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options)
12891293
}
12901294
break;
12911295
}
1292-
case (64): //--------------------------------------------
1296+
case (65): //--------------------------------------------
12931297
{/*:EndReservoirWaterDemand*/
12941298
if(Options.noisy) { cout <<"..end reservoir water demand object"<<endl; }
12951299
pDemand=NULL;
12961300
break;
12971301
}
1298-
case (65): //--------------------------------------------
1302+
case (66): //--------------------------------------------
12991303
{/*:IsUnrestricted*/
13001304
if(Options.noisy) { cout <<"Set demand as Unrestricted"<<endl; }
13011305
if (pDemand == NULL) {

0 commit comments

Comments
 (0)