-
Notifications
You must be signed in to change notification settings - Fork 2
/
LSDCatchmentModel.cpp
5091 lines (4479 loc) · 164 KB
/
LSDCatchmentModel.cpp
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
/// LSDCatchmentModel.cpp
/*
* SUMMARY
*
* LSDCatchmentModel is a 2.5D numerical model of landscape evolution that
* simulates the processes and evolution of catchments (river basins) and
* their hydrological and sedimentological process over timescales of days
* to thousands of years.
*
* Background
*
* This is a C++ implementation of the CAESAR-Lisflood model (Coulthard et al, 2013).
* It is essentially a light, fast, and somewhat stripped-down non-GUI version
* of the CASESAR-Lisflood model.
*
* The main additions where it differs are the inclusion of a separate
* rainfall-runoff module (see LSDRainfallRunoff.cpp) and a separate grain-size
* module (see LSDGrainmatrix.cpp)
*
* Not all the functionallity of CL is implemented in this model. There is
* no intention to maintain this code in parallel with CAESAR-Lisflood at this
* stage. Its development is separate from hereon. It was forked from the
* CL version 1.8a. (The updates in 1.9 were mirrored here too - DAV 2016)
*
* It is integrated with the LSDTopoTools package and makes use of several
* of the LSDTopoTools objects, such as LSDRaster in particular, for reading
* and writing raster data to and from the model. You might wish to use some
* of the topographic analysis tools to analyse your model output.
*
* The hydrological component of the model is based on the Bates et al (2010)
* algorithm of non-steady surface water flow, to represent the variation
* in hydrological flow in a landscape under non-steady state hydrological
* inputs. This is different to most Landscape Evolution Models, which tend
* to use some approximation of steady-state discharge based on contributing
* drainage area.
*
*
* @author Declan Valters
* @date 2014, 2015, 2016
* University of Manchester
* @contact [email protected]
* @version 0.01
*
* Released under the GNU v2 Public License
*
*/
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <iterator> // For the printing vector method
#include <sys/stat.h> // For errors
#include <cstdio> // Only for the debug macro
#include "LSDCatchmentModel.hpp"
// DV - One day, I'd like to integrate this more into the LSDTopoTools,
// particulalrly the LSDBasin object using it to 'cut out' basins,
// run hydrology sims for the catchment (hundreds - thousands yrs).
// and then perform topo analysis on the model run output
#ifndef LSDCatchmentModel_CPP
#define LSDCatchmentModel_CPP
#define ENABLE_PREFETCH
// ingest data tools
// DAV: I've copied these here for now to make the model self-contained for testing purposes
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Line parser for parameter files - JAJ 08/01/2014
// This might be better off somewhere else
//
// To be used on a parameter file of the format:
// Name: 100 comments etc.
// Which sets parameter as "Name" and value as "100"
//
// This just does one line at a time; you need a wrapper function to get all
// the information out of the file
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void LSDCatchmentModel::parse_line(std::ifstream &infile, string ¶meter, string &value)
{
char c;
char buff[256];
int pos = 0;
int word = 0;
while ( infile.get(c) )
{
if (pos >= 256)
{
std::cout << "Buffer overrun, word too long in parameter line: " << std::endl;
std::string line;
getline(infile, line);
std::cout << "\t" << buff << " ! \n" << line << std::endl;
exit(1);
}
// preceeding whitespace
if (c == '#')
{
if (word == 0)
{
parameter = "NULL";
value = "NULL";
}
if (word == 1)
value = "NULL";
word = 2;
}
if ((c == ' ' || c == '\t') && pos == 0)
continue;
else if ( (c == ':' && word == 0) || ( (c == ' ' || c == '\n' || c == '\t') && word == 1))
{
while (buff[pos-1] == ' ' || buff[pos-1] == '\t')
--pos; // Trailing whitespace
buff[pos] = '\0'; // Append Null char
if (word == 0)
parameter = buff; // Assign buffer contents
else if (word == 1)
value = buff;
++word;
pos = 0; // Rewind buffer
}
else if ( c == '\n' && word == 0 )
{
parameter = "NULL";
buff[pos] = '\0';
value = buff;
++word;
}
else if (word < 2)
{
buff[pos] = c;
++pos;
}
if (c == '\n')
break;
}
if (word == 0)
{
parameter = "NULL";
value = "NULL";
}
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--==
// This function removes control characters from the end of a string
// These get introduced if you use the DOS format in your parameter file
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--==
std::string LSDCatchmentModel::RemoveControlCharactersFromEndOfString(std::string toRemove)
{
int len = toRemove.length();
if(len != 0)
{
if (iscntrl(toRemove[len-1]))
{
//cout << "Bloody hell, here is another control character! Why Microsoft? Why?" << endl;
toRemove.erase(len-1);
}
}
return toRemove;
}
// Wee function to check if file exists
// Not sure if this works in Windows...must test sometime
inline bool LSDCatchmentModel::does_file_exist(const std::string &filename)
{
struct stat buffer;
return (stat(filename.c_str(), &buffer) ==0);
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// CREATE FUCNTIONS
// These define what happens when an LSDCatchmentModel object is created
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void LSDCatchmentModel::create()
{
std::cout << "You are trying to create an LSDCatchmentModel object with no supplied files or parameters." << std::endl << "Exiting..." << std::endl;
exit(EXIT_FAILURE);
}
void LSDCatchmentModel::create(string pname, string pfname)
{
std::cout << "Creating an instance of LSDCatchmentModel.." << std::endl;
// Using the parameter file
initialise_variables(pname, pfname);
std::cout << "The user-defined parameters have been ingested from the param file." << std::endl;
}
void LSDCatchmentModel::initialise_model_domain_extents()
{
std::string FILENAME = read_path + "/" + read_fname + "." + dem_read_extension;
if (!does_file_exist(FILENAME))
{
std::cout << "No terrain DEM found by name of: " << FILENAME << std::endl
<< "You must supply a correct path and filename in the input parameter file" << std::endl;
std::cout << "The model domain cannot be intitialised for real topography\n \
without a valid DEM to read from" << std::endl;
exit(EXIT_FAILURE);
}
try
{
std::cout << "\n\nLoading DEM header info, the filename is " << FILENAME << std::endl;
// open the data file
std::ifstream data_in(FILENAME.c_str());
//Read in raster data
std::string str; // a temporary string for discarding text
// read the georeferencing data and metadata
data_in >> str >> jmax;
std::cout << "NCols: " << jmax << " str: " << std::endl;
data_in >> str >> imax;
std::cout << "NRows: " << imax << " str: " << std::endl;
data_in >> str >> xll
>> str >> yll
>> str >> DX // cell size or grid resolution
>> str >> no_data_value;
}
catch(...)
{
std::cout << "Something is wrong with your initial elevation raster file." << std::endl
<< "Common causes are: " << std::endl << "1) Data type is not correct" <<
std::endl << "2) Non standard raster format" << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "The model domain has been set from reading the elevation DEM header." << std::endl;
}
void LSDCatchmentModel::load_data()
{
LSDRaster elevR;
/// Hydroindex LSDRaster: tells rainfall input where to be distributed
LSDRaster hydroindexR;
/// Bedrock LSDRaster object
LSDRaster bedrockR;
std::string DEM_FILENAME = read_path + "/" + read_fname + "." + dem_read_extension;
if (!does_file_exist(DEM_FILENAME))
{
std::cout << "No terrain DEM found by name of: " << DEM_FILENAME << std::endl
<< "You must supply a correct path and filename in the input parameter file" << std::endl;
exit(EXIT_FAILURE);
}
// Read in the elevation raster data from file, setting the elevation LSDRaster
// object, 'elevR'
try
{
elevR.read_ascii_raster(DEM_FILENAME);
// You have now read in all the headers and the raster data
// Headers are accessed by elevR.get_Ncols(), elevR.get_NRows() etc
// Raster is accessed by elevR.get_RasterData_dbl() (type: TNT::Array2D<double>)
// Load the raw ascii raster data
TNT::Array2D<double> raw_elev = elevR.get_RasterData_dbl();
// We want an edge pixel of zeros surrounding the raster data
// So start the counters at one, rather than zero, this
// will ensure that elev[0][n] is not written to and left set to zero.
// remember this data member is set with dim size equal to jmax + 2 to
// allow the border of zeros
for (unsigned i=0; i<imax; i++)
{
for (unsigned j=0; j<jmax; j++)
{
elev[i+1][j+1] = raw_elev[i][j];
}
}
// Check that there is an outlet for the catchment water
check_DEM_edge_condition();
// deep copy needed? -- DAV 2/12/2015
init_elevs = elev;
}
catch(...)
{
std::cout << "Something is wrong with your initial elevation raster file." << std::endl
<< "Common causes are: " << std::endl << "1) Data type is not correct" <<
std::endl << "2) Non standard raster format" << std::endl;
exit(EXIT_FAILURE);
}
// Load the HYDROINDEX DEM
if (spatially_var_rainfall == true)
{
std::string HYDROINDEX_FILENAME = read_path + "/" + hydroindex_fname;
// Check for the file first of all
if (!does_file_exist(HYDROINDEX_FILENAME))
{
std::cout << "No hydroindex DEM found by name of: " << HYDROINDEX_FILENAME << std::endl << "You specified the spatially variable rainfall option, \
\n but no matching file was found. Try again." << std::endl;
exit(EXIT_FAILURE);
}
try
{
hydroindexR.read_ascii_raster_integers(HYDROINDEX_FILENAME);
// wrong, becuase rfarea is bigger than the raster data in hydroindexR by 1 pixel around the array
// DAV fix 30/08/16
TNT::Array2D<int> raw_rfarea = hydroindexR.get_RasterData_int();
// Solves padding issues(?)
for (unsigned i=0; i<imax; i++)
{
for (unsigned j=0; j<jmax; j++)
{
rfarea[i+1][j+1] = raw_rfarea[i][j];
}
}
std::cout << "The hydroindex: " << HYDROINDEX_FILENAME << " was successfully read." << std::endl;
}
catch (...)
{
std::cout << "Something is wrong with your hydroindex file." << std::endl
<< "Common causes are: " << std::endl << "1) Data type is not integer" <<
std::endl << "2) Non standard ASCII data format" << std::endl;
exit(EXIT_FAILURE);
}
}
std::cout << "The terrain array and supplementary input data has been loaded." << std::endl;
// This has to go after the loading of the hydroindex,
// otherwise your rfareas will all be 1!
count_catchment_gridcells();
// Load the BEDROCK DEM
if (bedrock_layer_on == true)
{
std::string BEDROCK_FILENAME = read_path + "/" + bedrock_data_file;
// Check for the file first of all
if (!does_file_exist(BEDROCK_FILENAME))
{
std::cout << "No bedrock DEM found by name of: " << BEDROCK_FILENAME << std::endl << "You specified to use a separate bedrock layer option, \
\n but no matching file was found. Try again." << std::endl;
exit(EXIT_FAILURE);
}
try
{
bedrockR.read_ascii_raster(BEDROCK_FILENAME);
bedrock = bedrockR.get_RasterData_dbl();
std::cout << "The bedrock file: " << BEDROCK_FILENAME << " was successfully read." << std::endl;
}
catch (...)
{
std::cout << "Something is wrong with your bedrock file." << std::endl
<< "Common causes are: " << std::endl << "1) Data type is not correct" <<
std::endl << "2) Non standard ASCII data format" << std::endl;
exit(EXIT_FAILURE);
}
}
// Load the RAINDATA file
// Remember the format is not the same as a standard ASCII DEM...
if (rainfall_data_on==true)
{
std::string RAINFALL_FILENAME = read_path + "/" + rainfall_data_file;
// Check for the file first of all
if (!does_file_exist(RAINFALL_FILENAME))
{
std::cout << "No rainfall data file found by name of: " << RAINFALL_FILENAME << std::endl << "You specified to use a rainfall input file, \
\n but no matching file was found. Try again." << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Ingesting rainfall data file: " << RAINFALL_FILENAME << " into hourly_rain_data" << std::endl;
hourly_rain_data = read_rainfalldata(RAINFALL_FILENAME);
// debug
#ifdef DEBUG
print_rainfall_data();
#endif
}
// TO DO
// Read grainsize data for restart runs
if (graindata_from_file == true)
{
std::string GRAINDATA_FILENAME = read_path + "/" + grain_data_file;
if (does_file_exist(GRAINDATA_FILENAME))
{
ingest_graindata_from_file(GRAINDATA_FILENAME);
}
else
{
std::cout << "No grain data file found by name of: " << GRAINDATA_FILENAME << std::endl << \
"You specified to use a graindata input file, \
\n but no matching file was found. Try again." << std::endl;
exit(EXIT_FAILURE);
}
}
}
// Reads in grain data from the grain data file, and initialises the grain_array_tot variable,
// the index, grain, and strata arrays
void LSDCatchmentModel::ingest_graindata_from_file(std::string GRAINDATA_FILENAME)
{
std::cout << "\n Loading graindata from the the graindata file: " <<
GRAINDATA_FILENAME << std::endl;
//open the data file
// Note that c_str() will return a const char* whereas, strip function expects char*...
std::ifstream infile(GRAINDATA_FILENAME);
// Index coordinates
unsigned x1=0, y1=0;
grain_array_tot = 0;
std::string line;
// read a line at a time from infile
while(std::getline(infile, line))
{
// check not an empty string (getline can return '' if
// first character of line is \n or similar)
// A string to hold each line of the text file as we iterate
std::vector<std::string> line_vector;
// Strip using the function in LSDStatsTools
split_delimited_string(line, ' ', line_vector);
unsigned col_counter = 1;
grain_array_tot++;
for (unsigned x=0; x<=line_vector.size()-1; x++ )
{
//std::cout << "LINE VECTOR IS: " << line_vector[x] << std::endl;
if (col_counter==1) x1 = std::stoi(line_vector[x]);
if (col_counter==2) y1 = std::stoi(line_vector[x]);
// Prevent grains being added that are outside the grid.
if (x1 > imax) x1 = imax;
if (y1 > jmax) y1 = jmax;
if (col_counter == 3)
{
index[x1][y1] = grain_array_tot;
}
// Next bunch of columns are grain fractions (surface). Update them.
for(unsigned n=0; n<=G_MAX; n++)
{
if (col_counter==4+n)
{
grain[grain_array_tot][n] = std::stod(line_vector[x]);
}
}
// Now the fractions for the subsuface strata, note that this is currently hard coded as 10 layers
// so when you update to have user-defined no. of strata this will becom a TO DO.
for(int z=0; z<=9; z++)
{
for (unsigned n=0; n<=(G_MAX-2); n++)
{
if (col_counter == (4+G_MAX+n+1) + (z*9))
{
strata[grain_array_tot][z][n] = std::stod(line_vector[x]);
}
}
}
col_counter++; // move on to the next column (this seems really inefficient...)
}
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Load the rainfall data from the rainfall text file
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Generic function for reading rainfal data
// This is used by the LSDCatchmentModel.
// Need to think about this...the number of rows and cols are not known beforehand
std::vector< std::vector<float> > LSDCatchmentModel::read_rainfalldata(string FILENAME)
{
std::cout << "\n\n Loading Spatially Distributed Rainfall File, the filename is "
<< FILENAME << std::endl;
// open the data file
std::ifstream infile(FILENAME.c_str());
std::string line;
int i = 0;
while (std::getline(infile, line))
{
float value;
std::stringstream ss(line);
raingrid.push_back(std::vector<float>());
while (ss >> value)
{
raingrid[i].push_back(value);
}
++i;
}
return raingrid;
}
// This is just for sanity checking the rainfall input really
void LSDCatchmentModel::print_rainfall_data()
{
std::vector< std::vector<float> > vector2d = hourly_rain_data;
std::vector<std::vector<float> >::iterator itr = vector2d.begin();
std::vector<std::vector<float> >::iterator end = vector2d.end();
while (itr!=end)
{
std::vector<float>::iterator it1=itr->begin(),end1=itr->end();
std::copy(it1,end1,std::ostream_iterator<float>(std::cout, " "));
std::cout << std::endl;
++itr;
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// This function gets all the data from a parameter file
//
// Update: It also intialises the other params that are set internally (hard coded)
// Some functions have been taken out of mainloop()
//
// DAV - this is a bit of a clunky method - perhaps replace it with the
// paramter ingestion method used in CHILD one day?
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void LSDCatchmentModel::initialise_variables(std::string pname, std::string pfname)
{
std::cout << "Initialising the model parameters..." << std::endl;
// Concatenate the path and paramter file name to get the full file address
string full_name = pname+pfname;
std::ifstream infile;
// Open the parameter file
infile.open(full_name.c_str());
string parameter, value, lower, lower_val;
string bc;
std::cout << "Parameter filename is: " << full_name << std::endl;
// now ingest parameters
while (infile.good())
{
parse_line(infile, parameter, value);
lower = parameter;
if (parameter == "NULL")
continue;
for (unsigned int i=0; i<parameter.length(); ++i)
{
lower[i] = std::tolower(parameter[i]); // converts to lowercase
}
//std::cout << "parameter is: " << lower << " and value is: " << value << std::endl;
// get rid of control characters
value = RemoveControlCharactersFromEndOfString(value);
if (lower == "dem_read_extension")
{
dem_read_extension = value;
dem_read_extension = RemoveControlCharactersFromEndOfString(dem_read_extension);
std::cout << "dem_read_extension: " << dem_read_extension << std::endl;
}
else if (lower == "dem_write_extension")
{
dem_write_extension = value;
dem_write_extension = RemoveControlCharactersFromEndOfString(dem_write_extension);
std::cout << "dem_write_extension: " << dem_write_extension << std::endl;
}
else if (lower == "write_path")
{
write_path = value;
write_path = RemoveControlCharactersFromEndOfString(write_path);
std::cout << "output write path: " << write_path << std::endl;
}
else if (lower == "write_fname")
{
write_fname = value;
write_fname = RemoveControlCharactersFromEndOfString(write_fname);
std::cout << "write_fname: " << write_fname << std::endl;
}
else if (lower == "read_path")
{
read_path = value;
read_path = RemoveControlCharactersFromEndOfString(read_path);
std::cout << "read_path: " << read_path << std::endl;
}
else if (lower == "read_fname")
{
read_fname = value;
read_fname = RemoveControlCharactersFromEndOfString(read_fname);
std::cout << "read_fname: " << read_fname << std::endl;
}
//=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// parameters for landscape numerical modelling
// (LSDCatchmentModel: DAV 2015-01-14)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Supplementary Input Files
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
else if (lower == "hydroindex_file")
{
hydroindex_fname = value;
std::cout << "hydroindex_file: " << hydroindex_fname << std::endl;
}
else if (lower == "rainfall_data_file")
{
rainfall_data_file = value;
std::cout << "rainfall_data_file: " << rainfall_data_file << std::endl;
}
else if (lower == "grain_data_file")
{
grain_data_file = value;
std::cout << "grain data file: " << grain_data_file << std::endl;
}
else if (lower == "bedrock_data_file")
{
bedrock_data_file = value;
std::cout << "bedrock data file: " << bedrock_data_file << std::endl;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Numerical
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
else if (lower == "no_of_iterations")
{
no_of_iterations = atoi(value.c_str());
std::cout << "no of iterations: " << no_of_iterations << std::endl;
}
else if (lower == "min_time_step")
{
min_time_step = atoi(value.c_str());
std::cout << "min time step: " << min_time_step << std::endl;
}
else if (lower == "max_time_step")
{
max_time_step = atoi(value.c_str());
std::cout << "max time step: " << max_time_step << std::endl;
}
else if (lower == "run_time_start")
{
run_time_start = atof(value.c_str()); //?
std::cout << "run time start: " << run_time_start << std::endl;
}
else if (lower == "max_run_duration")
{
maxcycle = atoi(value.c_str()); //?
std::cout << "max_run_duration: " << maxcycle << std::endl;
}
else if (lower == "memory_limit")
{
LIMIT = atoi(value.c_str());
std::cout << "memory LIMIT: " << LIMIT << std::endl;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Output and Save Options
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
else if (lower == "timeseries_save_interval")
{
output_file_save_interval = atoi(value.c_str());
std::cout << "timeseries save interval: " << output_file_save_interval << std::endl;
}
else if (lower == "raster_output_interval")
{
saveinterval = atof(value.c_str());
std::cout << "raster_output_interval: " << saveinterval << std::endl;
}
else if (lower == "write_elevation_file")
{
elev_fname = value;
std::cout << "write_elev_fname: " << elev_fname << std::endl;
}
else if (lower == "write_elev_file")
{
write_elev_file = (value == "yes") ? true : false;
std::cout << "write_elev_file_on: " << write_elev_file << std::endl;
}
else if (lower == "grainsize_file")
{
grainsize_fname = value;
std::cout << "grainsize_fname: " << grainsize_fname << std::endl;
}
else if (lower == "write_grainsize_file")
{
write_grainsz_file = (value == "yes") ? true : false;
std::cout << "write_grainsz_file: " << write_grainsz_file << std::endl;
}
else if (lower == "parameters_file")
{
params_fname = value;
std::cout << "params_fname: " << params_fname << std::endl;
}
else if (lower == "write_parameters_file")
{
write_params_file = (value == "yes") ? true : false;
std::cout << "write_params_file: " << write_params_file << std::endl;
}
else if (lower == "flowvelocity_file")
{
flowvel_fname = value;
std::cout << "flowvel_fname: " << flowvel_fname << std::endl;
}
else if (lower == "write_flowvelocity_file")
{
write_flowvel_file = (value == "yes") ? true : false;
std::cout << "write_flowvel_file: " << write_flowvel_file << std::endl;
}
else if (lower == "waterdepth_outfile_name")
{
waterdepth_fname = value;
std::cout << "waterdepth_outfile_name: " << waterdepth_fname << std::endl;
}
else if (lower == "write_waterdepth_file")
{
write_waterd_file = (value == "yes") ? true : false;
std::cout << "write_waterd_file: " << write_waterd_file << std::endl;
}
else if (lower == "timeseries_file")
{
timeseries_fname = value;
std::cout << "timeseries_fname: " << timeseries_fname << std::endl;
}
else if (lower == "elevdiff_outfile_name")
{
elevdiff_fname = value;
std::cout << "elevdiff_outfile_name: " << elevdiff_fname << std::endl;
}
else if (lower == "write_elevdiff_file")
{
write_elevdiff_file = (value == "yes") ? true : false;
std::cout << "write_elevdiff_file_on: " << write_elevdiff_file << std::endl;
}
else if (lower == "raingrid_fname_out")
{
raingrid_fname = value;
std::cout << "raingrid_outfile_name: " << raingrid_fname << std::endl;
}
else if (lower == "runoffgrid_fname")
{
runoffgrid_fname = value;
std::cout << "runoffgrid_outfile_name: " << runoffgrid_fname << std::endl;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Sediment
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
else if (lower == "read_in_graindata_from_file")
{
graindata_from_file = (value == "yes") ? true : false;
std::cout << "read in grain data from file: " << graindata_from_file << std::endl;
}
else if (lower == "bedrock_layer_on")
{
bedrock_layer_on = (value == "yes") ? true : false;
std::cout << "bedrock_layer_on: " << bedrock_layer_on << std::endl;
}
else if (lower == "transport_law")
{
if (value == "wilcock")
{
wilcock = true;
einstein = false;
}
else if (value == "einstein")
{
einstein = true;
wilcock = false;
}
else
{
std::cout << "WARNING!: No sediment transport law specified in parameter file..." << std::endl;
std::cout << "You must specify a transport law: either 'einstein' or 'wilcock'" << std::endl;
std::cout << "Exiting..." << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "wilcock: " << wilcock << std::endl;
std::cout << "einstein: " << einstein << std::endl;
}
else if (lower == "max_tau_velocity")
{
max_vel = atof(value.c_str());
std::cout << "max_vel (to calculate tau): " << max_vel << std::endl;
}
// max velocity used to calculate tau
else if (lower == "active_layer_thickness")
{
active = atof(value.c_str());
std::cout << "active: " << active << std::endl;
}
else if (lower == "recirculate_proportion")
{
recirculate_proportion = atof(value.c_str());
std::cout << "recirculate_proportion: " << recirculate_proportion << std::endl;
}
else if (lower == "chann_lateral_erosion")
{
chann_lateral_erosion = atof(value.c_str());
std::cout << "In channel lateral erosion proportion: " << chann_lateral_erosion << std::endl;
}
else if (lower == "erosion_limit")
{
ERODEFACTOR = atof(value.c_str());
std::cout << "erosion limit per timestep: " << ERODEFACTOR << std::endl;
}
/// LATERAL EROSION ROUTINE PARAMETERS
else if (lower == "lateral_erosion_on")
{
lateral_erosion_on = (value == "yes") ? true : false;
std::cout << "lateral_erosion_on: " << lateral_erosion_on << std::endl;
}
else if (lower == "edge_smoothing_passes")
{
edge_smoothing_passes = atof(value.c_str());
std::cout << "smoothing_times: " << edge_smoothing_passes << std::endl;
}
else if (lower == "lateral_erosion_const")
{
lateral_constant = atof(value.c_str());
std::cout << "Lateral erosion constant: " << lateral_constant << std::endl;
}
else if (lower == "downstream_cell_shift")
{
downstream_shift = atof(value.c_str());
std::cout << "downstream_shift: " << downstream_shift << std::endl;
}
else if (lower == "lateral_cross_chan_smoothing")
{
lateral_cross_channel_smoothing = atof(value.c_str());
std::cout << "lateral_cross_channel_smoothing: " << lateral_cross_channel_smoothing << std::endl;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Grain Size Options
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
else if (lower == "suspended_sediment_on")
{
suspended_opt = (value == "yes") ? true : false;
std::cout << "suspended_opt: " << suspended_opt << std::endl;
}
// This is a vector of values and needs some thought (different grainsize fractions)
//else if (lower == "fall_velocity") fall_velocity = atof(value.c_str());
else if (lower == "grain_size_frac_file")
{
grain_data_file = value;
std::cout << "grain_data_file: " << grain_data_file << std::endl;
}
// else if (lower == "num_of_grainsizes")
// {
// G_MAX = atoi(value.c_str()) + 1;
// std::cout << "num_of_grainsizes: " << G_MAX << std::endl;
// }
//=-=-=-=-=-=-=-=-=-=-=-=
// Bedrock Erosion
//=-=-=-=-=-=-=-=-=-=-=-=
else if (lower == "bedrock_erosion_threshold")
{
bedrock_erosion_threshold = atof(value.c_str());
std::cout << "bedrock erode threshold (Pa): " << bedrock_erosion_threshold << std::endl;
}
else if (lower == "stream_power_pb")
{
p_b = atof(value.c_str());
std::cout << "bedrock stream power p_b: " << p_b << std::endl;
}
else if (lower == "stream_power_ke")
{
bedrock_erodibility_coeff_ke = atof(value.c_str());
std::cout << "bedrock stream power k_e: " << bedrock_erodibility_coeff_ke << std::endl;
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Hydrology and Flow
//=-=-=-=-=-=-=-=-=-=-=-=-=-=
else if (lower == "hydro_model_only")
{
hydro_only = (value == "yes") ? true : false;
std::cout << "run hydro model only (NO EROSION): " << hydro_only << std::endl;
}
else if (lower == "rainfall_data_on")
{
rainfall_data_on = (value == "yes") ? true : false;
std::cout << "rainfall_data_on: " << rainfall_data_on << std::endl;
}
else if (lower == "topmodel_m_value")
{
M = atof(value.c_str());
std::cout << "topmodel m value: " << M << std::endl;
}
else if (lower == "num_unique_rain_cells")
{
rfnum = atoi(value.c_str());
std::cout << "Number of unique rain cells: " << rfnum << std::endl;
}
else if (lower == "rain_data_time_step")
{
rain_data_time_step = atof(value.c_str());
std::cout << "rainfall data time step: " << rain_data_time_step << std::endl;
}
else if (lower == "spatial_var_rain")
{
spatially_var_rainfall = (value == "yes") ? true : false;
std::cout << "Spatially variable rainfall: " << spatially_var_rainfall << std::endl;
}
else if (lower == "in_out_difference")
{
in_out_difference_allowed = atof(value.c_str());
std::cout << "in-output difference allowed (cumecs): " << in_out_difference_allowed << std::endl;
}
else if (lower == "min_q_for_depth_calc")
{
MIN_Q = atof(value.c_str());
std::cout << "minimum discharge for depth calculation: " << MIN_Q << std::endl;
}
else if (lower == "max_q_for_depth_calc")
{
MIN_Q_MAXVAL = atof(value.c_str());
std::cout << "max discharge for depth calc: " << MIN_Q_MAXVAL << std::endl;
}
else if (lower == "hflow_threshold")
{
hflow_threshold = atof(value.c_str());
std::cout << "Horizontal flow threshold: " << hflow_threshold << std::endl;
}
else if (lower == "water_depth_erosion_threshold")
{
hflow_threshold = atof(value.c_str());
std::cout << "Water depth for erosion threshold: " << water_depth_erosion_threshold << std::endl;
}
else if (lower == "slope_on_edge_cell")
{
edgeslope = atof(value.c_str());
std::cout << "Slope on model domain edge: " << edgeslope << std::endl;
}
else if (lower == "evaporation_rate")
{
k_evap = atof(value.c_str());
std::cout << "Evaporation rate: " << k_evap << std::endl;
}
else if (lower == "courant_number")
{
courant_number = atof(value.c_str());
std::cout << "Courant number: " << courant_number << std::endl;
}
else if (lower == "froude_num_limit")
{
froude_limit = atof(value.c_str());
std::cout << "Froude number limit: " << froude_limit << std::endl;
}
else if (lower == "mannings_n")
{