forked from CSHS-CWRA/RavenHydroFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseHRUFile.cpp
More file actions
2079 lines (1964 loc) · 85.3 KB
/
Copy pathParseHRUFile.cpp
File metadata and controls
2079 lines (1964 loc) · 85.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*----------------------------------------------------------------
Raven Library Source Code
Copyright (c) 2008-2023 the Raven Development Team
----------------------------------------------------------------*/
#include "RavenInclude.h"
#include "Model.h"
#include "StateVariables.h"
#include "HydroUnits.h"
#include "ParseLib.h"
#include "ControlStructures.h"
#include "LatConnect.h"
CReservoir *ReservoirParse(CParser *p,string name,const CModel *pModel,long long int &HRUID,const optStruct &Options);
//////////////////////////////////////////////////////////////////
/// \brief Parses HRU properties file
/// \details model.rvh: input file that defines HRU, subbasin properties, number of HRUs \n
/// Rules: \n
/// - SubBasins command before HRUs command
/// - SubBasins command before SubBasinProperties, etc.
/// - HRUs command before HRUInitialConditions
///
/// \param *&pModel [out] Reference to model object
/// \param &Options [out] Global model options information
/// \return True if operation is successful
//
bool ParseHRUPropsFile(CModel *&pModel, const optStruct &Options, bool terrain_required)
{
int i; //counters
long long SBID; //subbasin ID
CHydroUnit *pHRU; //temp pointers
CSubBasin *pSB;
bool ended=false;
bool in_ifmode_statement=false;
bool is_conduit=false;
ifstream HRU;
HRU.open(Options.rvh_filename.c_str());
if (HRU.fail()){
cout << "ERROR opening file: "<<Options.rvh_filename<<endl; return false;}
int Len,line(0),code;
char *s[MAXINPUTITEMS];
CParser *pp=new CParser(HRU,Options.rvh_filename,line);
string aParamStrings[MAXINPUTITEMS];
int nParamStrings=0;
ifstream INPUT2; //For Secondary input
CParser* pMainParser=NULL; //for storage of main parser while reading secondary files
ifstream INPUT3; //For tertiary input
CParser *pSecondaryParser=NULL; //for storage of secondary parser while reading tertiary files
if (Options.noisy){
cout <<"======================================================"<<endl;
cout <<"Parsing RVH Input File "<< Options.rvh_filename <<"..."<<endl;
cout <<"======================================================"<<endl;
}
//--Sift through file-----------------------------------------------
bool end_of_file=pp->Tokenize(s,Len);
while (!end_of_file)
{
if (ended){break;}
if (Options.noisy){ cout << "reading line " << pp->GetLineNumber() << ": ";}
/*assign code for switch statement
------------------------------------------------------------------
<100 : ignored/special
0 thru 100 : All other
------------------------------------------------------------------
*/
code=0;
//---------------------SPECIAL -----------------------------
if (Len==0) {code=-1; }//blank line
else if (IsComment(s[0],Len)) {code=-2; }//comment
else if (!strcmp(s[0],":End" )){code=-4; }//stop reading
else if (!strcmp(s[0],":IfModeEquals" )){code=-5; }
else if (in_ifmode_statement) {code=-6; }
else if (!strcmp(s[0],":EndIfModeEquals" )){code=-2; }//treat as comment - unused mode
else if (!strcmp(s[0],":RedirectToFile" )){code=-3; }//redirect to secondary file
//--------------------MODEL OPTIONS ------------------------
else if (!strcmp(s[0],":SubBasins" )){code=1; is_conduit=false;}
else if (!strcmp(s[0],":Conduits" )){code=1; is_conduit=true;}
else if (!strcmp(s[0],":HRUs" )){code=2; }
else if (!strcmp(s[0],":Reservoir" )){code=3; }
else if (!strcmp(s[0],":SubBasinProperties" )){code=7; }
else if (!strcmp(s[0],":HRUGroup" )){code=8; }
else if (!strcmp(s[0],":PopulateHRUGroup" )){code=9; }
else if (!strcmp(s[0],":SubBasinGroup" )){code=10; }
else if (!strcmp(s[0],":SBGroupPropertyMultiplier")){code=11; }
else if (!strcmp(s[0],":SBGroupPropertyOverride" )){code=12; }
else if (!strcmp(s[0],":DisableHRUGroup" )){code=13; }
else if (!strcmp(s[0],":DisableSubBasinGroup" )){code=14; }
else if (!strcmp(s[0],":PopulateSubBasinGroup" )){code=15; }
else if (!strcmp(s[0],":IntersectHRUGroups" )){code=16; }
else if (!strcmp(s[0],":IntersectSubBasinGroups" )){code=17; }
else if (!strcmp(s[0],":MergeHRUGroups" )){code=18; }
else if (!strcmp(s[0],":MergeSubBasinGroups" )){code=19; }
else if (!strcmp(s[0],":GaugedSubBasinGroup" )){code=20; }
else if (!strcmp(s[0],":LateralConnections" )){code=21; }
switch(code)
{
case(-1): //----------------------------------------------
{/*Blank Line*/
if (Options.noisy) {cout <<""<<endl;}break;
}
case(-2): //----------------------------------------------
{/*Comment*/
if (Options.noisy) {cout <<"*"<<endl;} break;
}
case(-3): //----------------------------------------------
{/*:RedirectToFile*/
string filename="";
for (int i=1;i<Len;i++){filename+=s[i]; if(i<Len-1){filename+=' ';}}
if (Options.noisy) {cout <<"Redirect to file: "<<filename<<endl;}
filename=CorrectForRelativePath(filename,Options.rvt_filename);
if (pSecondaryParser != NULL){
ExitGracefully("ParseEnsembleFile::nested :RedirectToFile commands are not allowed to be nested more than two levels (e.g., rvm file to rvm file to rvm file to rvm file)",BAD_DATA);
}
if (pMainParser == NULL) { //from base .rvh file
INPUT2.open(filename.c_str());
if(INPUT2.fail()) {
string warn;
warn=":RedirectToFile (from .rvh): Cannot find file "+filename;
ExitGracefully(warn.c_str(),BAD_DATA);
}
pMainParser=pp;
pp=new CParser(INPUT2,filename,line);//open new parser
}
else { //from already redirected .rvh file
INPUT3.open(filename.c_str());
if(INPUT3.fail()) {
string warn;
warn=":RedirectToFile (from .rvh): Cannot find file "+filename;
ExitGracefully(warn.c_str(),BAD_DATA);
}
pSecondaryParser=pp;
pp=new CParser(INPUT3,filename,line);//open new parser
}
break;
}
case(-4): //----------------------------------------------
{/*:End*/
if (Options.noisy) {cout <<"EOF"<<endl;} ended=true; break;
}
case(-5): //----------------------------------------------
{/*:IfModeEquals [mode] {mode2} {mode3}*/
if(Len>1) {
if(Options.noisy) { cout <<"Mode statement start..."<<endl; }
bool mode_match=false;
for(int i=1; i<Len; i++) {
if(s[i][0]==Options.run_mode) { mode_match=true; }
}
if(!mode_match) { in_ifmode_statement=true; }
}
break;
}
case(-6): //----------------------------------------------
{/*in_ifmode_statement*/
if(Options.noisy) { cout <<"* skip"<<endl; }
if(!strcmp(s[0],":EndIfModeEquals"))
{
if(Options.noisy) { cout <<"...Mode statement end"<<endl; }
in_ifmode_statement=false;
}
break;
}
case(1): //----------------------------------------------
{ /*
":SubBasins" or ":Conduits"
{int ID , string (no spaces) name, int down_ID, string profile, double length [km], bool gauged,{optional double Qref}}x nSubBasins
:EndSubBasins
-down_ID=-1 for basins/conduits not draining into other modeled basins
-profile can be 'NONE' for ROUTE_NONE or ROUTE_EXTERNAL option, but must be linked to actual profile otherwise
*/
if (Options.noisy) {cout <<"Subbasin or conduit data..."<<endl;}
bool done=false;
if (Len!=1){pp->ImproperFormat(s);}
else{
//while (((Len==0) || (strcmp(s[0],":EndSubBasins"))) && (!end_of_file))
while ( (!done) && (!end_of_file) )
{
end_of_file=pp->Tokenize(s,Len);
if (IsComment(s[0],Len)) {}//comment line
else if (!strcmp(s[0],":Attributes" )){}//ignored by Raven - needed for GUIs
else if (!strcmp(s[0],":Units" )){}//ignored by Raven - needed for GUIs
else if (!strcmp(s[0],":EndSubBasins")){done=true;}
else if (!strcmp(s[0],":EndConduits" )){done=true;}
else
{
if (Len<6){pp->ImproperFormat(s);}
CChannelXSect const *pChan=NULL;
pChan = pModel->StringToChannelXSect(string(s[3]));
string error,error2;
error="Parse RVH File: Unrecognized Channel profile code ("+string(s[3])+") in :SubBasins or :Conduits command";
error2="Parse RVH File: NONE cannot be used as channel code if routing method is anything other than ROUTE_NONE or ROUTE_EXTERNAL";
ExitGracefullyIf((pChan==NULL) && (string(s[3])!="NONE") && (Options.routing!=ROUTE_NONE),error.c_str() ,BAD_DATA_WARN);
ExitGracefullyIf((pChan==NULL) && (string(s[3])=="NONE") && (Options.routing!=ROUTE_NONE) && (Options.routing!=ROUTE_EXTERNAL),error2.c_str(),BAD_DATA_WARN);
if(!StringIsLong(s[0])){
error="Parse RVH File: Subbasin ID \""+string(s[0])+"\" must be unique integer or long integer";
ExitGracefully(error.c_str(),BAD_DATA_WARN);
}
double length;
length=AutoOrDouble(s[4]);
ExitGracefullyIf((length>2000) && (!is_conduit),
"ParseHRUPropsFile: length of river greater than 2000km in :SubBasins command block. Units issue? Reach length should be provided in km.",BAD_DATA_WARN);
ExitGracefullyIf((length>2000) && (!is_conduit),
"ParseHRUPropsFile: length of conduit greater than 2000km in :Conduits command block. Units issue? Conduit length should be provided in km.",BAD_DATA_WARN);
if (length!=AUTO_COMPUTE){length*=M_PER_KM;}//convert to m from km
bool gaged;
gaged=s_to_b(s[5]);
double Qref;
if (Len==7){Qref=AutoOrDouble(s[6]);}
else {Qref=AUTO_COMPUTE;}
pSB=NULL;
pSB=new CSubBasin(s_to_ll(s[0]),s[1], pModel,s_to_ll(s[2]),pChan,length,Qref,gaged,is_conduit);
ExitGracefullyIf(pSB==NULL,"ParseHRUPropsFile",OUT_OF_MEMORY);
pModel->AddSubBasin(pSB);
pSB->SetGlobalIndex(pModel->GetNumSubBasins()-1);
}
}
}
break;
}
case(2): //----------------------------------------------
{ /*
":HRUs"
{ID, area, avg_elevation, lat, long, basinID, ..
LU class,veg class, soil profile, aquifer profile, terrain class, slope[deg], aspect[deg from N]}x nHRUs
:EndHRUs
*/
if (Options.noisy) {cout <<"HRU data..."<<endl;}
while (((Len==0) || (strcmp(s[0],":EndHRUs"))) && (!end_of_file))
{
end_of_file=pp->Tokenize(s,Len);
if (IsComment(s[0],Len)) {}//comment line
else if (!strcmp(s[0],":Attributes" )){}//ignored by Raven - needed for GUIs
else if (!strcmp(s[0],":Units" )){}//ignored by Raven - needed for GUIs
else if (!strcmp(s[0],":EndHRUs")){}//done
else
{
if (Len<13){pp->ImproperFormat(s);}
string error;
SBID =s_to_ll(s[5]);//index must exist (in file, from 1 to nSB)
if(!StringIsLong(s[0])){
error="Parse HRU File: HRU ID \""+string(s[0])+"\" in :HRUs table must be unique integer or long integer";
ExitGracefully(error.c_str(),BAD_DATA_WARN);
}
if(!StringIsLong(s[5])){
error="Parse HRU File: Subbasin ID \""+string(s[5])+"\" in :HRUs table must be unique integer or long integer ";
ExitGracefully(error.c_str(),BAD_DATA_WARN);
}
if((fabs(s_to_d(s[3]))>90) || (fabs(s_to_d(s[4]))>180)){
error="Parse HRU File: longitude and latitude in :HRUs table (HRU "+to_string(s[0])+") must be valid (-90<lat<90; -180<lon<180)";
ExitGracefully(error.c_str(),BAD_DATA_WARN);
}
if((s_to_d(s[11])>90) || (s_to_d(s[11])<0)){
error="Parse HRU File: slope in :HRUs table (HRU "+to_string(s[0])+") must be valid (0<slope<90)";
ExitGracefully(error.c_str(),BAD_DATA_WARN);
}
if((s_to_d(s[12])>360) || (s_to_d(s[12])<0)){
error="Parse HRU File: aspect in :HRUs table (HRU "+to_string(s[0])+") must be valid (0<slope<360)";
ExitGracefully(error.c_str(),BAD_DATA_WARN);
}
CLandUseClass const *pLULT=NULL;
pLULT = pModel->StringToLUClass(string(s[6]));
if (pLULT==NULL){
error="Parse HRU File: Unrecognized Land Use Code/index: \""+string(s[6])+"\"";
ExitGracefully(error.c_str(),BAD_DATA);
}
CVegetationClass const *pVegetation=NULL;
pVegetation = pModel->StringToVegClass(string(s[7]));
if (pVegetation==NULL){
error="Parse HRU File: Unrecognized Vegetation Code/index: \""+string(s[7])+"\"";
ExitGracefully(error.c_str(),BAD_DATA);
}
CSoilProfile const *pSoilProfile=NULL;
pSoilProfile = pModel->StringToSoilProfile(string(s[8]));
if (pSoilProfile==NULL) {
error="Parse HRU File: Unrecognized Soil Profile Code/index: \""+string(s[8])+"\"";
ExitGracefully(error.c_str(), BAD_DATA);
}
CTerrainClass const *pTerrain=NULL;
if (string(s[10])!="[NONE]") //Terrain class can be NULL
{
pTerrain = pModel->StringToTerrainClass(string(s[10]));
if (pTerrain==NULL){
error="Parse HRU File: Unrecognized Terrain Code/index: \""+string(s[10])+"\"";
ExitGracefully(error.c_str(),BAD_DATA_WARN);
}
}
HRU_type HRUtype=HRU_STANDARD;
if (!pSoilProfile->GetTag().substr(0,4).compare("LAKE" )){HRUtype=HRU_LAKE; }
if (!pSoilProfile->GetTag().substr(0,5).compare("WATER" )){HRUtype=HRU_WATER; }
if (!pSoilProfile->GetTag().substr(0,7).compare("GLACIER" )){HRUtype=HRU_GLACIER;}
if (!pSoilProfile->GetTag().substr(0,4).compare("ROCK" )){HRUtype=HRU_ROCK; }
if (!pSoilProfile->GetTag().substr(0,8).compare("PAVEMENT")){HRUtype=HRU_ROCK; }
if (!pSoilProfile->GetTag().substr(0,7).compare("WETLAND" )){HRUtype=HRU_WETLAND;}
if (!pSoilProfile->GetTag().substr(0,14).compare("MASKED_GLACIER")) { HRUtype=HRU_MASKED_GLACIER; }
pHRU=new CHydroUnit( pModel,
s_to_ll(s[0]),//ID
pModel->GetNumHRUs(),//k - global model index
s_to_d(s[1]),//area
pModel->GetSubBasinIndex(SBID),
s_to_d(s[2]),//elev
s_to_d(s[3]),//lat
s_to_d(s[4]),//long
s_to_d(s[11])*DEGREES_TO_RADIANS,//slope (deg->radians)
s_to_d(s[12])*DEGREES_TO_RADIANS,//aspect (deg->radians)
HRUtype,
pSoilProfile,
pVegetation,
NULL, // PLACEHOLDER see HydroUnits.cpp line 41
pTerrain,
pLULT);
ExitGracefullyIf(pHRU==NULL,"ParseHRUPropsFile",OUT_OF_MEMORY);
pModel->AddHRU(pHRU);
pSB=pModel->GetSubBasinByID(SBID);
if (pSB!=NULL){pSB->AddHRU(pHRU);}
else {
ExitGracefully("ParseHRUProps: Bad Sub-basin index in :HRUs command",BAD_DATA);
}
}
}//end while
break;
}
case(3): //----------------------------------------------
{
/*
:Reservoir [name]
:SubBasin [SBID]
:HRUID [HRUID]
:VolumeHeightRelation
[DATA BLOCK]
:EndVolumeHeightRelation
:OutflowHeightRelation
:EndOutflowHeightRelation
...
:EndReservoir
(and other formats - see ReservoirParse code)
*/
if (Options.noisy) {cout <<":Reservoir"<<endl;}
CReservoir *pRes;
long long int HRUID;
if (Len < 2) {
ExitGracefully("ParseHRUProps: No reservoir name provided in :Reservoir command ",BAD_DATA_WARN);
}
pRes=ReservoirParse(pp,s[1],pModel,HRUID,Options);
pSB=pModel->GetSubBasinByID(pRes->GetSubbasinID());
if ((HRUID!=DOESNT_EXIST) && (pModel->GetHRUByID(HRUID)!=NULL)){
pRes->SetHRU(pModel->GetHRUByID(HRUID));
}
if (pSB!=NULL){pSB->AddReservoir(pRes);}
else {
ExitGracefully("ParseHRUProps: Bad Sub-basin index in :Reservoir command",BAD_DATA);
}
break;
}
case(7): //----------------------------------------------
{ /*
":SubBasinProperties"
:Parameters, paramname1,paramname2,...,paramnameN
:Units , units1, units2, ..., unitsN
{ID,param1, param2,...,paramN} x nSubBasins (or a subset of SBs)
:EndSubBasinProperties
*/
if (Options.noisy) {cout <<" Reading Basin Properties..."<<endl;}
bool done;
done=false;
while (!done)
{
pp->Tokenize(s,Len);
if (IsComment(s[0], Len)){}//comment line
else if (!strcmp(s[0],":Parameters")){
for (int i=0;i<Len;i++){
aParamStrings[i]=s[i];
}
nParamStrings=Len;
done=true;
}
else {pp->ImproperFormat(s); break;}
}
if (Options.noisy){for (i=1;i<nParamStrings;i++){cout<<" "<<aParamStrings[i]<<endl;}}
bool good_string;
while ((Len==0) || (strcmp(s[0],":EndSubBasinProperties")))
{
pp->Tokenize(s,Len);
if (IsComment(s[0],Len)) {}//comment line
else if (!strcmp(s[0],":RedirectToFile")){
ExitGracefully("Parse HRU File: :RedirectToFile cannot be inside a :SubBasinProperties block.",BAD_DATA_WARN);
}//done
else if (!strcmp(s[0],":EndSubBasinProperties")){}//done
else if (!strcmp(s[0],":Units")){}//do nothing
else
{
ExitGracefullyIf(Len<nParamStrings,
"Parse HRU File: incorrect number of terms in SubBasin properties",BAD_DATA);
SBID=s_to_ll(s[0]);
pSB=pModel->GetSubBasinByID(SBID);
if (pSB!=NULL){
for (i=1;i<nParamStrings;i++){
double in=AutoOrDouble(s[i]);
//special handling of some parameters
if(!aParamStrings[i].compare("TIME_CONC") && (in!=AUTO_COMPUTE) && (in!=USE_TEMPLATE_VALUE)){
in *= pModel->GetGlobalParams()->GetParameter("TOC_MULTIPLIER");
}
if(!aParamStrings[i].compare("TIME_TO_PEAK") && (in!=AUTO_COMPUTE) && (in!=USE_TEMPLATE_VALUE)){
//in*=CGlobalParams::GetParameter("TOC_MULTIPLIER"); // use to be this; but has its own multiplier now; maybe set default to TOC_MULTIPLIER??
in *= pModel->GetGlobalParams()->GetParameter("TIME_TO_PEAK_MULTIPLIER");
}
if(!aParamStrings[i].compare("GAMMA_SHAPE") && (in!=AUTO_COMPUTE) && (in!=USE_TEMPLATE_VALUE)){
in *= pModel->GetGlobalParams()->GetParameter("GAMMA_SHAPE_MULTIPLIER");
}
if(!aParamStrings[i].compare("GAMMA_SCALE") && (in!=AUTO_COMPUTE) && (in!=USE_TEMPLATE_VALUE)){
in *= pModel->GetGlobalParams()->GetParameter("GAMMA_SCALE_MULTIPLIER");
}
if(!aParamStrings[i].compare("REACH_HRU_ID")) {
if(pModel->GetHRUByID((long long int)in)!=NULL) {
in=pModel->GetHRUByID((long long int)in)->GetGlobalIndex(); //Convert ID to index
}
else {
ExitGracefully("ParseHRUPropsFile::invalid REACH_HRU_ID in :SubBasinProperties command",BAD_DATA_WARN);
}
}
//end special handling
good_string=pSB->SetBasinProperties(aParamStrings[i],in);
if (!good_string)
{
string err;
err="Unknown parameter \""+aParamStrings[i]+"\" in :SubBasinProperties command";
ExitGracefully(err.c_str(),BAD_DATA_WARN);
}
}
}
else{
string warn;
warn="Subbasin "+to_string(SBID)+" not in model, cannot set subbasin properties";
WriteWarning(warn,Options.noisy);
}
}
}
break;
}
case(8): //----------------------------------------------
{ /*
":HRUGroup" {name}
{ID1,ID2,ID3,...} x nHRUs in group
:EndHRUGroup
*/
if (Options.noisy) {cout <<" HRU Group..."<<endl;}
if (Len!=2){pp->ImproperFormat(s);}
CHRUGroup *pHRUGrp=NULL;
pHRUGrp=pModel->GetHRUGroup(s[1]);
if (pHRUGrp==NULL){//group not yet defined
WriteAdvisory("HRU groups should ideally be defined in .rvi file (using :DefineHRUGroup(s) commands) before being populated in .rvh file",Options.noisy);
pHRUGrp=new CHRUGroup(s[1],pModel->GetNumHRUGroups());
pModel->AddHRUGroup(pHRUGrp);
}
bool eof=false;
while (((Len==0) || (strcmp(s[0],":EndHRUGroup"))) && (!eof))
{
eof=pp->Tokenize(s,Len);
if (IsComment(s[0], Len)){}//comment line
else if (!strcmp(s[0],":EndHRUGroup")){}//done
else if (s[0][0] == ':') {
string warn="ParseHRUPropsFile: Command found between :HRUGroup...:EndHRUGroup commands at line "+to_string(pp->GetLineNumber())+" of .rvh file. ONly HRU IDs should be in this command block.";
ExitGracefully(warn.c_str(),BAD_DATA_WARN);
}
else
{
int k;
int nHRUs=pModel->GetNumHRUs();
for (i=0;i<Len;i++)
{
long long int ind1,ind2;
s_to_range(s[i],ind1,ind2);
bool found=false;
ExitGracefullyIf((ind2-ind1)>10000,"Parsing :HRUGroup command: invalid range of HRU indices",BAD_DATA);
bool gaps(false);
for (long long int ii=ind1;ii<=ind2;ii++)
{
found=false;
for (k=0;k<nHRUs;k++)
{
if (pModel->GetHydroUnit(k)->GetHRUID()==ii)
{
pHRUGrp->AddHRU(pModel->GetHydroUnit(k));found=true; break;
}
}
if ((!found) && (ind2-ind1>1)){gaps=true;}
if((!found) && (ind1==ind2)) {
string warn="HRU ID "+to_string(ii)+" specified in :HRUGroup command for group "+pHRUGrp->GetName()+ " does not exist";
WriteWarning(warn.c_str(),Options.noisy);
}
}
if (gaps){
WriteWarning("Range specified in :HRUGroup command has gaps",Options.noisy);
}
}
}
}
break;
}
case(9): //----------------------------------------------
{ /*
":PopulateHRUGroup" {name} "With" {conditionbase} {condition} {conditiondata}
e.g.,
:PopulateHRUGroup NotRock With HRUS NOTWITHIN RockHRUGroup
:PopulateHRUGroup LowBand With ELEVATION BETWEEN 0 500
:PopulateHRUGroup CroplandHRUs With LANDUSE EQUALS CROPLAND
:PopulateHRUGroup NonCroplandHRUs With LANDUSE NOTEQUALS CROPLAND
:PopulateHRUGroup BroadleafHRUs With VEGETATION EQUALS BROADLEAF
:PopulateHRUGroup UpperWigwamHRUs With HRUS WITHIN_SBGROUP UpperWigwamSBs
[not in here yet] :PopulateHRUGroup Rocks With HRUTYPE EQUALS ROCK
*/
if (Options.noisy) {cout <<" Populate HRU Group..."<<endl;}
if (Len<6){pp->ImproperFormat(s);}
CHRUGroup *pHRUGrp=NULL;
pHRUGrp=pModel->GetHRUGroup(s[1]);
if (pHRUGrp==NULL){//group not yet defined
WriteWarning("HRU groups should ideally be defined in .rvi file (using :DefineHRUGroup(s) commands) before being populated in .rvh file (2)",Options.noisy);
pHRUGrp=new CHRUGroup(s[1],pModel->GetNumHRUGroups());
pModel->AddHRUGroup(pHRUGrp);
}
int k;
if(!strcmp(s[3],"HRUS"))
{
if(!strcmp(s[4],"NOTWITHIN")){
CHRUGroup* pHRUGrp2=NULL;
pHRUGrp2=pModel->GetHRUGroup(s[5]);
if(pHRUGrp2==NULL) {
ExitGracefully(":PopulateHRUGroup: invalid HRU group reference used in command",BAD_DATA_WARN);
}
else {
for(k=0;k<pModel->GetNumHRUs();k++)
{
if(!pHRUGrp2->IsInGroup(k)) { pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
}
}
}
else if (!strcmp(s[4],"WITHIN_SBGROUP"))
{
CSubbasinGroup *pSBGrp=NULL;
pSBGrp=pModel->GetSubBasinGroup(s[5]);
if(pSBGrp==NULL) {
ExitGracefully(":PopulateHRUGroup: invalid Subbasin group reference used in command",BAD_DATA_WARN);
}
else {
for(int p=0;p<pSBGrp->GetNumSubbasins();p++)
{
for(k=0;k<pSBGrp->GetSubBasin(p)->GetNumHRUs();k++)
{
pHRU=pModel->GetHRUByID(pSBGrp->GetSubBasin(p)->GetHRU(k)->GetHRUID());
pHRUGrp->AddHRU(pHRU);
}
}
}
}
}
else if(!strcmp(s[3],"LANDUSE"))
{
if(!strcmp(s[4],"EQUALS")){
for(k=0;k<pModel->GetNumHRUs();k++)
{
if(pModel->GetHydroUnit(k)->GetSurfaceProps()->landuse_name==to_string(s[5])){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
}
}
if(!strcmp(s[4],"DOESNTEQUAL")){
for(k=0;k<pModel->GetNumHRUs();k++)
{
if(pModel->GetHydroUnit(k)->GetSurfaceProps()->landuse_name!=to_string(s[5])){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
}
}
}
else if(!strcmp(s[3],"VEGETATION"))
{
if(!strcmp(s[4],"EQUALS")){
for(k=0;k<pModel->GetNumHRUs();k++)
{
if(pModel->GetHydroUnit(k)->GetVegetationProps()->vegetation_name==to_string(s[5])){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
}
}
if(!strcmp(s[4],"DOESNTEQUAL")){
for(k=0;k<pModel->GetNumHRUs();k++)
{
if(pModel->GetHydroUnit(k)->GetVegetationProps()->vegetation_name!=to_string(s[5])){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
}
}
}
else if(!strcmp(s[3],"ELEVATION"))
{
if(!strcmp(s[4],"BETWEEN")){
for(k=0;k<pModel->GetNumHRUs();k++)
{
if((pModel->GetHydroUnit(k)->GetElevation()>=s_to_d(s[5])) &&
(pModel->GetHydroUnit(k)->GetElevation()<s_to_d(s[6]))){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
}
}
}
else if(!strcmp(s[3],"HRUTYPE"))
{
if(!strcmp(s[4],"EQUALS")){
for(k=0;k<pModel->GetNumHRUs();k++)
{
if((pModel->GetHydroUnit(k)->GetHRUType()==HRU_ROCK) && (!strcmp(s[4],"ROCK"))){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()==HRU_ROCK) && (!strcmp(s[4],"PAVEMENT"))) { pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()==HRU_GLACIER) && (!strcmp(s[4],"GLACIER"))){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()==HRU_LAKE ) && (!strcmp(s[4],"LAKE"))){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()==HRU_WATER ) && (!strcmp(s[4],"WATER"))){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()==HRU_WETLAND) && (!strcmp(s[4],"WETLAND"))){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()==HRU_MASKED_GLACIER) && (!strcmp(s[4],"MASKED_GLACIER"))) { pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
}
}
if(!strcmp(s[4],"DOESNTEQUAL")){
for(k=0;k<pModel->GetNumHRUs();k++)
{
if((pModel->GetHydroUnit(k)->GetHRUType()!=HRU_ROCK) && (!strcmp(s[4],"ROCK"))){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()!=HRU_ROCK) && (!strcmp(s[4],"PAVEMENT"))) { pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()!=HRU_GLACIER) && (!strcmp(s[4],"GLACIER"))){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()!=HRU_LAKE) && (!strcmp(s[4],"LAKE"))){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()!=HRU_WATER) && (!strcmp(s[4],"WATER"))){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()!=HRU_WETLAND) && (!strcmp(s[4],"WETLAND"))){ pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
if((pModel->GetHydroUnit(k)->GetHRUType()!=HRU_MASKED_GLACIER) && (!strcmp(s[4],"MASKED_GLACIER"))) { pHRUGrp->AddHRU(pModel->GetHydroUnit(k)); }
}
}
}
string advice = "HRUGroup " + pHRUGrp->GetName() + " was populated with " + to_string(pHRUGrp->GetNumHRUs()) + " HRUs(s).";
WriteAdvisory(advice, Options.noisy);
break;
}
case(10): //----------------------------------------------
{ /*
":SubBasinGroup" {name}
{SBID1,SBID2,SBID3,...} x nBasins in group
:EndSubBasinGroup
*/
if (Options.noisy) {cout <<" SubBasin Group..."<<endl;}
if (Len!=2){pp->ImproperFormat(s);}
CSubbasinGroup *pSBGrp=NULL;
pSBGrp=pModel->GetSubBasinGroup(s[1]);
if (pSBGrp==NULL){//group not yet defined
// WriteAdvisory("HRU groups should ideally be defined in .rvi file (using :DefineHRUGroup(s) commands) before being populated in .rvh file",Options.noisy);
pSBGrp=new CSubbasinGroup(s[1],pModel->GetNumSubBasinGroups());
pModel->AddSubBasinGroup(pSBGrp);
}
bool eof=false;
while ( (Len==0) || (strcmp(s[0],":EndSubBasinGroup")) )
{
eof=pp->Tokenize(s,Len);
if(eof) { break; }
if (IsComment(s[0], Len)){}//comment line
else if (!strcmp(s[0],":EndSubBasinGroup")){}//done
else if (s[0][0] == ':') {
string warn="ParseHRUPropsFile: Command found between :SubBasinGroup...:EndSubBasinGroup commands at line "+to_string(pp->GetLineNumber())+" of .rvh file. ONly subbasin IDs should be between these two commands";
ExitGracefully(warn.c_str(),BAD_DATA_WARN);
}
else
{
int p;
int nSBs=pModel->GetNumSubBasins();
for(i=0;i<Len;i++)
{
SBID=s_to_ll(s[i]);
for(p=0;p<nSBs;p++)
{
if(pModel->GetSubBasin(p)->GetID()==SBID)
{
pSBGrp->AddSubbasin(pModel->GetSubBasin(p));break;
}
}
}
}
}
break;
}
case(11): //----------------------------------------------
{ /*
:SBGroupPropertyMultiplier [SBGROUP] [PROPERTY] [multiplier]
*/
CSubbasinGroup *pSBGrp;
bool valid;
if(Len>=4) {
pSBGrp=pModel->GetSubBasinGroup(s[1]);
if(pSBGrp==NULL) {
WriteWarning(":SBGroupPropertyMultiplier: invalid subbasin group ("+to_string(s[1])+") specified",Options.noisy);
break;
}
for(int p=0;p<pSBGrp->GetNumSubbasins();p++) {
double val=pSBGrp->GetSubBasin(p)->GetBasinProperties(s[2]);
if(val!=AUTO_COMPUTE) {
valid=pSBGrp->GetSubBasin(p)->SetBasinProperties(s[2],s_to_d(s[3])*val);
if (!valid) {
WriteWarning(":SBGroupPropertyMultiplier: invalid subbasin property (" + to_string(s[2]) + ") specified", Options.noisy);
}
}
else {
string warn=":SBGroupPropertyMultiplier: because subbasin property (" + to_string(s[2]) + ") set to be computed by Raven (rather than user-supplied in :SubBasinProperties command), it cannot be adjusted with the multiplier.";
WriteWarning(warn.c_str(), Options.noisy);
}
}
}
else {
WriteWarning(":SBGroupPropertyMultiplier: improper syntax",Options.noisy);
}
break;
}
case(12): //----------------------------------------------
{ /*
:SBGroupPropertyOverride [SBGROUP] [PROPERTY] [value]
*/
CSubbasinGroup *pSBGrp;
bool valid;
if(Len>=4) {
pSBGrp=pModel->GetSubBasinGroup(s[1]);
if(pSBGrp==NULL) {
WriteWarning(":SBGroupPropertyOverride: invalid subbasin group ("+to_string(s[1])+") specified",Options.noisy);
break;
}
for(int p=0;p<pSBGrp->GetNumSubbasins();p++) {
valid=pSBGrp->GetSubBasin(p)->SetBasinProperties(s[2],s_to_d(s[3]));
if (!valid) {
WriteWarning(":SBGroupPropertyMultiplier: invalid subbasin property (" + to_string(s[2]) + ") specified", Options.noisy);
}
}
}
else {
WriteWarning(":SBGroupPropertyOverride: improper syntax",Options.noisy);
}
break;
}
case(13): //----------------------------------------------
{ /*
:DisableHRUGroup [HRUGROUP]
*/
if(Options.noisy) { cout <<"Disabling HRU Group"<<endl; }
if(Len>=2) {
CHRUGroup *pHRUGrp=NULL;
pHRUGrp=pModel->GetHRUGroup(s[1]);
if(pHRUGrp==NULL) {
ExitGracefully("Invalid HRU Group name supplied in :DisableHRUGroup command in .rvh file. Group must be defined first.",BAD_DATA_WARN);
break;
}
else {
pHRUGrp->DisableGroup();
}
}
else {
WriteWarning(":DisableHRUGroup: improper syntax",Options.noisy);
}
break;
}
case(14): //----------------------------------------------
{ /*
:DisableSubBasinGroup [SB_GROUP]
*/
if(Options.noisy) { cout <<"Disabling HRU Group"<<endl; }
if(Len>=2) {
CSubbasinGroup *pSBGrp=NULL;
pSBGrp=pModel->GetSubBasinGroup(s[1]);
if(pSBGrp==NULL) {
ExitGracefully("Invalid Subbasin Group name supplied in :DisableSubBasinGroup command in .rvh file. Group must be defined first.",BAD_DATA_WARN);
break;
}
else {
pSBGrp->DisableGroup();
}
}
else {
WriteWarning(":DisableSubBasinGroup: improper syntax",Options.noisy);
}
break;
}
case(15): //----------------------------------------------
{ /*
":PopulateSubBasinGroup" {name} "With" {conditionbase} {condition} {conditiondata}
e.g.,
:PopulateSubBasinGroup NotRock With SUBBASINS NOTWITHIN RockSBGroup
:PopulateSubBasinGroup UpstreamOfBasin2 With SUBBASINS UPSTREAM_OF 2
:PopulateSubBasinGroup DownstreamOfBasin35 With SUBBASINS DOWNSTREAM_OF 35
// since calls are additive, can also build up the same group with successive calls and WITHIN condtion
:PopulateSubBasinGroup BigSubgroup With SUBBASINS WITHIN SmallGroup1
:PopulateSubBasinGroup BigSubgroup With SUBBASINS WITHIN SmallGroup2
*/
if(Options.noisy) { cout <<" Populate SubBasin Group..."<<endl; }
if(Len<6) { pp->ImproperFormat(s); }
CSubbasinGroup *pSBGroup=NULL;
pSBGroup=pModel->GetSubBasinGroup(s[1]);
string advice="SubBasinGroup "+to_string(s[1])+" was populated with these basins: ";
if(pSBGroup==NULL) {//group not yet defined
pSBGroup=new CSubbasinGroup(s[1],pModel->GetNumSubBasinGroups());
pModel->AddSubBasinGroup(pSBGroup);
}
if(!strcmp(s[3],"SUBBASINS"))
{
if(!strcmp(s[4],"NOTWITHIN"))
{
CSubbasinGroup *pSBGroup2=NULL;
pSBGroup2=pModel->GetSubBasinGroup(s[5]);
if(pSBGroup2==NULL) {
ExitGracefully(":PopulateSubBasinGroup: invalid SB group reference used in command",BAD_DATA_WARN);
}
else {
int iter=0;
for(int p=0;p<pModel->GetNumSubBasins();p++)
{
if(!pSBGroup2->IsInGroup(pModel->GetSubBasin(p)->GetID())) {
pSBGroup->AddSubbasin(pModel->GetSubBasin(p));
advice=advice+to_string(pModel->GetSubBasin(p)->GetID())+" ";
iter++;
if(iter%40==0) { advice=advice+"\n "; }
}
}
}
}
else if (!strcmp(s[4], "WITHIN"))
{
CSubbasinGroup* pSBGroup2 = NULL;
pSBGroup2 = pModel->GetSubBasinGroup(s[5]);
if (pSBGroup2 == NULL) {
ExitGracefully(":PopulateSubBasinGroup: invalid SB group reference used in command", BAD_DATA_WARN);
}
else {
int iter=0;
for (int p = 0; p < pModel->GetNumSubBasins(); p++)
{
if (pSBGroup2->IsInGroup(pModel->GetSubBasin(p)->GetID())) {
pSBGroup->AddSubbasin(pModel->GetSubBasin(p));
advice=advice+to_string(pModel->GetSubBasin(p)->GetID())+" ";
iter++;
if(iter%40==0) { advice=advice+"\n "; }
}
}
}
}
else if ( (!strcmp(s[4],"UPSTREAM_OF")) || (!strcmp(s[4],"UPSTREAM_OF_INCLUSIVE")) )/*inclusive of basin*/
{
SBID=s_to_ll(s[5]);
int iter=0;
for(int p=0;p<pModel->GetNumSubBasins();p++)
{
if ((pModel->IsSubBasinUpstream(pModel->GetSubBasin(p)->GetID(),SBID)) ||
(pModel->GetSubBasin(p)->GetID() == SBID) ) {
pSBGroup->AddSubbasin(pModel->GetSubBasin(p));
advice=advice+to_string(pModel->GetSubBasin(p)->GetID())+" ";
iter++;
if(iter%40==0) { advice=advice+"\n "; }
}
}
}
else if (!strcmp(s[4],"NOT_UPSTREAM_OF"))/*useful for disabling everything but one watershed*/
{
SBID=s_to_ll(s[5]);
int iter=0;
for(int p=0;p<pModel->GetNumSubBasins();p++)
{
if ((!pModel->IsSubBasinUpstream(pModel->GetSubBasin(p)->GetID(),SBID)) ||
(!(pModel->GetSubBasin(p)->GetID() == SBID)) ) {
pSBGroup->AddSubbasin(pModel->GetSubBasin(p));
advice=advice+to_string(pModel->GetSubBasin(p)->GetID())+" ";
iter++;
if(iter%40==0) { advice=advice+"\n "; }
}
}
}
else if(!strcmp(s[4],"DOWNSTREAM_OF"))/*not inclusive of basin*/
{
CSubBasin *pBasin=pModel->GetSubBasinByID(s_to_ll(s[5]));
if(pBasin==NULL) {
ExitGracefully(":PopulateSubBasinGroup : invalid subbasin ID specified",BAD_DATA_WARN);
}
else {
int iter=0;
while ((pBasin->GetDownstreamID()!=DOESNT_EXIST) && (iter<1000)){
pBasin=pModel->GetSubBasinByID(pBasin->GetDownstreamID());
pSBGroup->AddSubbasin(pBasin);
advice=advice+to_string(pBasin->GetID())+" ";
iter++;
if(iter%40==0){advice=advice+"\n "; }
}
if(iter==1000) {
ExitGracefully(":PopulateSubBasinGroup: cyclical downstream references in :SubBasins list",BAD_DATA_WARN);
}
}
}
else {
WriteWarning("Parse RVH File: Incorrect formatting of :PopulateSubBasinGroup command",Options.noisy);
}
}
WriteAdvisory(advice,Options.noisy);
break;
}
case(16): //----------------------------------------------
{ /*
:IntersectHRUGroups {NewGroup} From {HRUGroup1} And {HRUGroup2}
e.g.,
:IntersectHRUGroups LowElevCrops From LowBand And Crops
*/
if (Options.noisy) {cout <<" Intersect HRU Groups..."<<endl;}
if (Len<6){pp->ImproperFormat(s);}
CHRUGroup *pHRUGrp=NULL;
CHRUGroup *pHRUGrp1=NULL;
CHRUGroup *pHRUGrp2=NULL;
pHRUGrp=pModel->GetHRUGroup(s[1]);
if (pHRUGrp==NULL){//group not yet defined
WriteWarning(":IntersectHRUGroups: HRU groups should ideally be defined in .rvi file (using :DefineHRUGroup(s) commands) before being populated in .rvh file (2)",Options.noisy);
pHRUGrp=new CHRUGroup(s[1],pModel->GetNumHRUGroups());
pModel->AddHRUGroup(pHRUGrp);
}
pHRUGrp1=pModel->GetHRUGroup(s[3]);
pHRUGrp2=pModel->GetHRUGroup(s[3]);
if ((pHRUGrp1 == NULL) || (pHRUGrp2==NULL)){
WriteWarning("ParseHRUFile: Invalid HRU Group used in :IntersectHRUGroups command. Command ignored",Options.noisy);
break;
}
for(int k=0;k<pHRUGrp1->GetNumHRUs();k++){
for (int k2 = 0; k2 < pHRUGrp2->GetNumHRUs(); k2++) {
if (pHRUGrp1->GetHRU(k)->GetHRUID() == pHRUGrp2->GetHRU(k2)->GetHRUID()) {
pHRUGrp->AddHRU(pHRUGrp1->GetHRU(k));
break;
}
}
}
break;
}
case(17): //----------------------------------------------
{ /*
:IntersectSubBasinGroups {NewGroup} From {SubBasinGroup1} And {conditionbase} {SubBasinGroup2}
e.g.,
:IntersectSubBasinGroups SelectSubbasins From subGroup1 And NOTWITHIN subGroup2
:IntersectSubBasinGroups SelectSubbasins From subGroup1 And WITHIN subGroup2
*/
if (Options.noisy) { cout << " Intersect SubBasin Groups..." << endl; }
if (Len != 7) {
// char advice = ':IntersectSubBasinGroups: invalid syntax used in attempting to construct SubBasinGroup `' + to_string(s[1]) + "`.";
ExitGracefully(":IntersectSubBasinGroups: invalid syntax used in attempting to construct new subbasin group", BAD_DATA_WARN);
}
CSubbasinGroup* pSBGroup = NULL;
CSubbasinGroup* pSBGroup1 = NULL;
CSubbasinGroup* pSBGroup2 = NULL;
pSBGroup = pModel->GetSubBasinGroup(s[1]);
if (pSBGroup == NULL) {//group not yet defined
pSBGroup = new CSubbasinGroup(s[1], pModel->GetNumSubBasinGroups());
pModel->AddSubBasinGroup(pSBGroup);
}
pSBGroup1 = pModel->GetSubBasinGroup(s[3]);
pSBGroup2 = pModel->GetSubBasinGroup(s[6]);
if (pSBGroup1 == NULL || pSBGroup2 == NULL) {
WriteWarning("ParseHRUFile: Invalid SubBasin Group used in :IntersectSubBasinGroups command. Command ignored", Options.noisy);
break;
}
if (!strcmp(s[5], "NOTWITHIN")) {
/*for (int p = 0; p < pModel->GetNumSubBasins(); p++) {
if (pSBGroup1->IsInGroup(pModel->GetSubBasin(p)->GetID()) & !pSBGroup2->IsInGroup(pModel->GetSubBasin(p)->GetID())) {
pSBGroup->AddSubbasin(pModel->GetSubBasin(p));
}
}
more efficient version below just iterates subbasins in group 1 for this logic
*/
for (int p = 0; p < pSBGroup1->GetNumSubbasins(); p++) {
if (!pSBGroup2->IsInGroup(pSBGroup1->GetSubBasin(p)->GetID())) {
pSBGroup->AddSubbasin(pModel->GetSubBasin(p));
}
}