@@ -143,6 +143,8 @@ void LSDCatchmentModel::load_data()
143143 LSDRaster elevR;
144144 // / Hydroindex LSDRaster: tells rainfall input where to be distributed
145145 LSDRaster hydroindexR;
146+ // / Holds the initial water depths if oading from file
147+ LSDRaster waterinitR;
146148 // / Bedrock LSDRaster object
147149 LSDRaster bedrockR;
148150 std::string DEM_FILENAME = read_path + " /" + read_fname + " ." \
@@ -276,6 +278,52 @@ void LSDCatchmentModel::load_data()
276278 }
277279 }
278280
281+ // LOAD THE WATERDEPTHS FILE
282+ if (water_init_from_raster==true )
283+ {
284+ std::string WATER_INIT_RASTER_FILENAME = read_path + " /" + water_init_raster_file;
285+ // Check for the file first of all
286+ if (!does_file_exist (WATER_INIT_RASTER_FILENAME))
287+ {
288+ std::cout << " No surface water level initialisation DEM found by name of: "
289+ << WATER_INIT_RASTER_FILENAME
290+ << std::endl
291+ << " You specified to intialise the model with initial water depths, \
292+ \n but no matching water DEM file was found. Try again." << std::endl;
293+ exit (EXIT_FAILURE);
294+ }
295+ try
296+ {
297+ waterinitR.read_ascii_raster (WATER_INIT_RASTER_FILENAME);
298+ // Load the raw ascii raster data
299+ TNT::Array2D<double > waterinit_raw = waterinitR.get_RasterData_dbl ();
300+ std::cout << " The water depth initialisation file: " << WATER_INIT_RASTER_FILENAME
301+ << " was successfully read." << std::endl;
302+
303+ // We want an edge pixel of zeros surrounding the raster data
304+ // So start the counters at one, rather than zero, this
305+ // will ensure that elev[0][n] is not written to and left set to zero.
306+ // remember this data member is set with dim size equal to jmax + 2 to
307+ // allow the border of zeros
308+ for (unsigned i=0 ; i<imax; i++)
309+ {
310+ for (unsigned j=0 ; j<jmax; j++)
311+ {
312+ water_depth[i+1 ][j+1 ] = waterinit_raw[i][j];
313+ }
314+ }
315+ }
316+ catch (...)
317+ {
318+ std::cout << " Something is wrong with your water initialisation file." << std::endl
319+ << " Common causes are: " << std::endl
320+ << " 1) Data type is not correct" <<
321+ std::endl << " 2) Non standard ASCII data format" << std::endl;
322+ exit (EXIT_FAILURE);
323+ }
324+ }
325+
326+
279327 // Load the RAINDATA file
280328 // Remember the format is not the same as a standard ASCII DEM...
281329 if (rainfall_data_on==true )
@@ -659,6 +707,15 @@ void LSDCatchmentModel::initialise_variables(std::string pname,
659707 RemoveControlCharactersFromEndOfString (bedrock_data_file);
660708 std::cout << " bedrock data file: " << bedrock_data_file << std::endl;
661709 }
710+ else if (lower == " water_init_raster_file" )
711+ {
712+ std::cout << value << " VALUE " << lower << " LOWER" ;
713+ water_init_raster_file = value;
714+ RemoveControlCharactersFromEndOfString (water_init_raster_file);
715+ std::cout << " water depth initialistion file: " << water_init_raster_file << std::endl;
716+ }
717+
718+
662719
663720 // =-=-=-=-=-=-=-=-=-=-=-=-=-=
664721 // Numerical
@@ -935,6 +992,12 @@ void LSDCatchmentModel::initialise_variables(std::string pname,
935992 std::cout << " rainfall_data_on: " << rainfall_data_on << std::endl;
936993 }
937994
995+ else if (lower == " water_init_from_raster_on" )
996+ {
997+ water_init_from_raster = (value == " yes" ) ? true : false ;
998+ std::cout << " Initialise the water depths from raster file: " << water_init_from_raster << std::endl;
999+ }
1000+
9381001 else if (lower == " topmodel_m_value" )
9391002 {
9401003 M = atof (value.c_str ());
0 commit comments