CoastalME (Coastal Modelling Environment)
Simulates the long-term behaviour of complex coastlines
Loading...
Searching...
No Matches
utils.cpp
Go to the documentation of this file.
1
10
11/* ==============================================================================================================================
12 This file is part of CoastalME, the Coastal Modelling Environment.
13
14 CoastalME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19==============================================================================================================================*/
20#include <assert.h>
21
22#ifdef _WIN32
23#include <windows.h> // Needed for CalcProcessStats()
24#include <psapi.h>
25#include <io.h> // For isatty()
26#elif defined __GNUG__
27#include <sys/resource.h> // Needed for CalcProcessStats()
28#include <unistd.h> // For isatty()
29#include <sys/wait.h>
30#endif
31
32#ifdef _OPENMP
33#include <omp.h>
34#endif
35
36#include <stdio.h>
37
38#include <cstdlib>
39
40#include <float.h>
41
42#include <cctype>
43using std::tolower;
44
45#include <cmath>
46using std::floor;
47
48#include <ctime>
49using std::clock;
50using std::clock_t;
51using std::difftime;
52using std::localtime;
53using std::time;
54
55#include <ios>
56using std::fixed;
57
58#include <iostream>
59using std::cerr;
60using std::cout;
61using std::endl;
62using std::ios;
63
64#include <iomanip>
65using std::put_time;
66using std::setprecision;
67using std::setw;
68
69#include <string>
70using std::to_string;
71
72#include <sstream>
73using std::stringstream;
74
75#include <algorithm>
76using std::transform;
77
78#include <gdal.h>
79
80#include "cme.h"
81#include "simulation.h"
82#include "coast.h"
83#include "2di_point.h"
84
85//===============================================================================================================================
87//===============================================================================================================================
89{
90 return m_dMissingValue;
91}
92
93//===============================================================================================================================
95//===============================================================================================================================
97{
98 return m_dThisIterSWL;
99}
100
101//===============================================================================================================================
103//===============================================================================================================================
108
109// //===============================================================================================================================
110// //! Returns the max elevation of the beach above SWL
111// //===============================================================================================================================
112// double CSimulation::dGetMaxBeachElevAboveSWL (void) const
113// {
114// return m_dMaxBeachElevAboveSWL;
115// }
116
117//===============================================================================================================================
118// Returns the cell side length
119//===============================================================================================================================
120// double CSimulation::dGetCellSide(void) const
121// {
122// return m_dCellSide;
123// }
124
125//===============================================================================================================================
127//===============================================================================================================================
129{
130 return m_nXGridSize;
131}
132
133//===============================================================================================================================
135//===============================================================================================================================
137{
138 return m_nYGridSize;
139}
140
141//===============================================================================================================================
143//===============================================================================================================================
144double CSimulation::dGetD50Fine(void) const
145{
146 return m_dD50Fine;
147}
148
149//===============================================================================================================================
151//===============================================================================================================================
152double CSimulation::dGetD50Sand(void) const
153{
154 return m_dD50Sand;
155}
156
157//===============================================================================================================================
159//===============================================================================================================================
161{
162 return m_dD50Coarse;
163}
164
165//===============================================================================================================================
167//===============================================================================================================================
168int CSimulation::nHandleCommandLineParams(int nArg, char const* pcArgv[])
169{
170 if ((!isatty(fileno(stdout))) || (!isatty(fileno(stderr))))
171 // Running with stdout or stderr not a tty, so either redirected or running as a background job. Ignore all command line parameters
172 return RTN_OK;
173
174 // Process the parameters following the name of the executable
175 for (int i = 1; i < nArg; i++)
176 {
177 string strArg = pcArgv[i];
178 strArg = strTrim(&strArg);
179
180#ifdef _WIN32
181 // Swap any forward slashes to backslashes
182 strArg = pstrChangeToBackslash(&strArg);
183#endif
184
185 if (strArg.find("--gdal") != string::npos)
186 {
187 // User wants to know what GDAL raster drivers are available
188 cout << GDAL_DRIVERS << endl
189 << endl;
190
191 for (int j = 0; j < GDALGetDriverCount(); j++)
192 {
193 GDALDriverH hDriver = GDALGetDriver(j);
194
195 string strTmp(GDALGetDriverShortName(hDriver));
196 strTmp.append(" ");
197 strTmp.append(GDALGetDriverLongName(hDriver));
198
199 cout << strTmp << endl;
200 }
201
202 return (RTN_HELP_ONLY);
203 }
204
205 else
206 {
207 if (strArg.find("--about") != string::npos)
208 {
209 // User wants information about CoastalME
210 cout << ABOUT << endl;
211 cout << THANKS << endl;
212
213 return (RTN_HELP_ONLY);
214 }
215
216 else
217 {
218 if (strArg.find("--yaml") != string::npos)
219 {
220 // User wants to use YAML format for input datafile
221 m_bYamlInputFormat = true;
222 }
223
224 else if (strArg.find("--home") != string::npos)
225 {
226 // Read in user defined runtime directory
227 // string strTmp;
228
229 // Find the position of '='
230 size_t const pos = strArg.find('=');
231
232 // Was '=' found?
233 if (pos != string::npos)
234 {
235 // Yes, so get the substring after '=' and assign it to the global variable
236 m_strCMEIni = strArg.substr(pos + 1);
237 }
238
239 else
240 {
241 // No
242 cout << "No '=' found in the input string" << endl;
243 }
244
245 return (RTN_OK);
246 }
247
248 // TODO 049 Handle other command line parameters e.g. path to .ini file, path to datafile
249 else
250 {
251 // Display usage information
252 cout << USAGE << endl;
253 cout << USAGE1 << endl;
254 cout << USAGE2 << endl;
255 cout << USAGE3 << endl;
256 cout << USAGE4 << endl;
257 cout << USAGE5 << endl;
258 cout << USAGE6 << endl;
259
260 return (RTN_HELP_ONLY);
261 }
262 }
263 }
264 }
265
266 return RTN_OK;
267}
268
269//===============================================================================================================================
271//===============================================================================================================================
273{
274 cout << endl
275 << PROGRAM_NAME << " for " << PLATFORM << " " << strGetBuild() << endl;
276 #ifdef _OPENMP
277 cout << "OpenMP is ENABLED" << endl;
278 cout << "Max threads available: " << omp_get_max_threads() << endl;
279 #pragma omp parallel
280 {
281 #pragma omp single
282 std::cout << "Actually running with " << omp_get_num_threads() << " threads" << std::endl;
283 }
284 #else
285 std::cout << "OpenMP is NOT ENABLED - code will run serially!" << std::endl;
286 #endif // !_OPENMP
287}
288
289//===============================================================================================================================
291//===============================================================================================================================
293{
294 // First start the 'CPU time' clock ticking
295 if (static_cast<clock_t>(-1) == clock())
296 {
297 // There's a problem with the clock, but continue anyway
298 LogStream << NOTE << "CPU time not available" << endl;
299 m_dCPUClock = -1;
300 }
301
302 else
303 {
304 // All OK, so get the time in m_dClkLast (this is needed to check for clock rollover on long runs)
305 m_dClkLast = static_cast<double>(clock());
306 m_dClkLast -= CLOCK_T_MIN; // necessary if clock_t is signed to make m_dClkLast unsigned
307 }
308
309 // And now get the actual time we started
310 m_tSysStartTime = time(nullptr);
311}
312
313//===============================================================================================================================
315//===============================================================================================================================
316bool CSimulation::bFindExeDir(char const* pcArg)
317{
318 string strTmp;
319 char szBuf[BUF_SIZE] = "";
320
321#ifdef _WIN32
322
323 if (0 != GetModuleFileName(NULL, szBuf, BUF_SIZE))
324 strTmp = szBuf;
325
326 else
327 // It failed, so try another approach
328 strTmp = pcArg;
329
330#else
331 // char* pResult = getcwd(szBuf, BUF_SIZE); // Used to use this, but what if cwd is not the same as the CoastalME dir?
332
333 if (-1 != readlink("/proc/self/exe", szBuf, BUF_SIZE))
334 strTmp = szBuf;
335
336 else
337 // It failed, so try another approach
338 strTmp = pcArg;
339
340#endif
341
342 // Neither approach has worked, so give up
343 if (strTmp.empty())
344 return false;
345
346 // It's OK, so trim off the executable's name
347 int const nPos = static_cast<int>(strTmp.find_last_of(PATH_SEPARATOR));
348 m_strCMEDir = strTmp.substr(0, nPos + 1); // Note that this must be terminated with a backslash
349
350 return true;
351}
352//===============================================================================================================================
354//===============================================================================================================================
356{
357 cout << COPYRIGHT << endl
358 << endl;
359 cout << LINE << endl;
360 cout << DISCLAIMER1 << endl;
361 cout << DISCLAIMER2 << endl;
362 cout << DISCLAIMER3 << endl;
363 cout << DISCLAIMER4 << endl;
364 cout << DISCLAIMER5 << endl;
365 cout << DISCLAIMER6 << endl;
366 cout << LINE << endl
367 << endl;
368
369 cout << START_NOTICE << strGetComputerName() << " at " << put_time(localtime(&m_tSysStartTime), "%T on %A %d %B %Y") << endl;
370 cout << INITIALIZING_NOTICE << endl;
371}
372
373//===============================================================================================================================
375//===============================================================================================================================
376double CSimulation::dGetTimeMultiplier(string const* strIn)
377{
378 // First decide what the time units are
379 int const nTimeUnits = nDoTimeUnits(strIn);
380
381 // Then return the correct multiplier, since m_dTimeStep is in hours
382 switch (nTimeUnits)
383 {
384 case TIME_UNKNOWN:
385 return TIME_UNKNOWN;
386 break;
387
388 case TIME_HOURS:
389 return 1; // Multiplier for hours
390 break;
391
392 case TIME_DAYS:
393 return 24; // Multiplier for days -> hours
394 break;
395
396 case TIME_MONTHS:
397 return 24 * 30.416667; // Multiplier for months -> hours (assume 30 + 5/12 day months, no leap years)
398 break;
399
400 case TIME_YEARS:
401 return 24 * 365.25; // Multiplier for years -> hours
402 break;
403 }
404
405 return 0;
406}
407
408//===============================================================================================================================
410//===============================================================================================================================
412{
413 // First decide what the time units are
414 int const nTimeUnits = nDoTimeUnits(strIn);
415
416 // Next set up the correct multiplier, since m_dTimeStep is in hours
417 switch (nTimeUnits)
418 {
419 case TIME_UNKNOWN:
420 return RTN_ERR_TIME_UNITS;
421 break;
422
423 case TIME_HOURS:
424 m_dDurationUnitsMult = 1; // Multiplier for hours
425 m_strDurationUnits = "hours";
426 break;
427
428 case TIME_DAYS:
429 m_dDurationUnitsMult = 24; // Multiplier for days -> hours
430 m_strDurationUnits = "days";
431 break;
432
433 case TIME_MONTHS:
434 m_dDurationUnitsMult = 24 * 30.416667; // Multiplier for months -> hours (assume 30 + 5/12 day months, no leap years)
435 m_strDurationUnits = "months";
436 break;
437
438 case TIME_YEARS:
439 m_dDurationUnitsMult = 24 * 365.25; // Multiplier for years -> hours
440 m_strDurationUnits = "years";
441 break;
442 }
443
444 return RTN_OK;
445}
446
447//===============================================================================================================================
449//===============================================================================================================================
450int CSimulation::nDoTimeUnits(string const* strIn)
451{
452 if (strIn->find("hour") != string::npos)
453 return TIME_HOURS;
454
455 else if (strIn->find("day") != string::npos)
456 return TIME_DAYS;
457
458 else if (strIn->find("month") != string::npos)
459 return TIME_MONTHS;
460
461 else if (strIn->find("year") != string::npos)
462 return TIME_YEARS;
463
464 else
465 return TIME_UNKNOWN;
466}
467
468//===============================================================================================================================
470//===============================================================================================================================
472{
473 if (m_nLogFileDetail == 0)
474 {
475 LogStream.open("/dev/null", ios::out | ios::trunc);
476 cout << "Warning: log file is not writting" << endl;
477 }
478
479 else
480 LogStream.open(m_strLogFile.c_str(), ios::out | ios::trunc);
481
482 if (!LogStream)
483 {
484 // Error, cannot open log file
485 cerr << ERR << "cannot open " << m_strLogFile << " for output" << endl;
486 return false;
487 }
488
489 return true;
490}
491
492//===============================================================================================================================
494//===============================================================================================================================
496{
497 // Tell the user what is happening
498#ifdef _WIN32
500#else
502#endif
503}
504
505//===============================================================================================================================
507//===============================================================================================================================
509{
510 cout << ALLOCATE_MEMORY << endl;
511}
512
513//===============================================================================================================================
515//===============================================================================================================================
517{
518 // Tell the user what is happening
519 cout << ADD_LAYERS << endl;
520}
521
522//===============================================================================================================================
524//===============================================================================================================================
526{
527 cout << READING_RASTER_FILES << endl;
528}
529
530//===============================================================================================================================
532//===============================================================================================================================
534{
535 cout << READING_VECTOR_FILES << endl;
536}
537
538//===============================================================================================================================
540//===============================================================================================================================
542{
543 // Tell the user what is happening
544 if (! m_strInitialLandformFile.empty())
545#ifdef _WIN32
547
548#else
550#endif
551}
552
553//===============================================================================================================================
555//===============================================================================================================================
557{
558 // Tell the user what is happening
559 if (! m_strInterventionClassFile.empty())
560#ifdef _WIN32
562
563#else
565#endif
566}
567
568//===============================================================================================================================
570//===============================================================================================================================
572{
573 // Tell the user what is happening
574 if (! m_strInterventionHeightFile.empty())
575#ifdef _WIN32
577
578#else
580#endif
581}
582
583//===============================================================================================================================
585//===============================================================================================================================
587{
588 // Tell the user what is happening
589 if (! m_strDeepWaterWavesInputFile.empty())
590#ifdef _WIN32
592
593#else
595#endif
596}
597
598//===============================================================================================================================
600//===============================================================================================================================
602{
603 // Tell the user what is happening
604 if (! m_strSedimentInputEventFile.empty())
605#ifdef _WIN32
607
608#else
610#endif
611}
612
613//===============================================================================================================================
615//===============================================================================================================================
617{
618 // Tell the user what is happening
619 if (! m_strFloodLocationShapefile.empty())
620#ifdef _WIN32
622
623#else
625#endif
626}
627
628//===============================================================================================================================
630//===============================================================================================================================
632{
633 // Tell the user what is happening
634#ifdef _WIN32
636#else
638#endif
639}
640
641//===============================================================================================================================
643//===============================================================================================================================
645{
646 // Tell the user what is happening
647#ifdef _WIN32
649#else
650 cout << READING_UNCONS_FINE_SEDIMENT_FILE << nLayer + 1 << "): " << m_VstrInitialFineUnconsSedimentFile[nLayer] << endl;
651#endif
652}
653
654//===============================================================================================================================
656//===============================================================================================================================
658{
659 // Tell the user what is happening
660#ifdef _WIN32
662#else
663 cout << READING_UNCONS_SAND_SEDIMENT_FILE << nLayer + 1 << "): " << m_VstrInitialSandUnconsSedimentFile[nLayer] << endl;
664#endif
665}
666
667//===============================================================================================================================
669//===============================================================================================================================
671{
672 // Tell the user what is happening
673#ifdef _WIN32
675#else
676 cout << READING_UNCONS_COARSE_SEDIMENT_FILE << nLayer + 1 << "): " << m_VstrInitialCoarseUnconsSedimentFile[nLayer] << endl;
677#endif
678}
679
680//===============================================================================================================================
682//===============================================================================================================================
684{
685 // Tell the user what is happening
686#ifdef _WIN32
687 cout << READING_CONS_FINE_SEDIMENT_FILE << nLayer + 1 << "): " << pstrChangeToForwardSlash(&m_VstrInitialFineConsSedimentFile[nLayer]) << endl;
688#else
689 cout << READING_CONS_FINE_SEDIMENT_FILE << nLayer + 1 << "): " << m_VstrInitialFineConsSedimentFile[nLayer] << endl;
690#endif
691}
692
693//===============================================================================================================================
695//===============================================================================================================================
697{
698 // Tell the user what is happening
699#ifdef _WIN32
700 cout << READING_CONS_SAND_SEDIMENT_FILE << nLayer + 1 << "): " << pstrChangeToForwardSlash(&m_VstrInitialSandConsSedimentFile[nLayer]) << endl;
701#else
702 cout << READING_CONS_SAND_SEDIMENT_FILE << nLayer + 1 << "): " << m_VstrInitialSandConsSedimentFile[nLayer] << endl;
703#endif
704}
705
706//===============================================================================================================================
708//===============================================================================================================================
710{
711 // Tell the user what is happening
712#ifdef _WIN32
714#else
715 cout << READING_CONS_COARSE_SEDIMENT_FILE << nLayer + 1 << "): " << m_VstrInitialCoarseConsSedimentFile[nLayer] << endl;
716#endif
717}
718
719//===============================================================================================================================
721//===============================================================================================================================
723{
724#ifdef _WIN32
726#else
727 cout << READING_TIDE_DATA_FILE << m_strTideDataFile << endl;
728#endif
729}
730
731//===============================================================================================================================
733//===============================================================================================================================
738
739//===============================================================================================================================
741//===============================================================================================================================
743{
744 // Tell the user what is happening
745 cout << INITIALIZING_FINAL << endl;
746}
747
748//===============================================================================================================================
750//===============================================================================================================================
752{
753 cout << RUN_NOTICE << endl;
754}
755
756//===============================================================================================================================
758//===============================================================================================================================
760{
761 string strTmp;
762
764 {
765 strTmp.append(RASTER_BASEMENT_ELEVATION_CODE);
766 strTmp.append(", ");
767 }
768
770 {
771 strTmp.append(RASTER_SEDIMENT_TOP_CODE);
772 strTmp.append(", ");
773 }
774
776 {
778 strTmp.append(", ");
779 }
780
781 if (m_bTalusSave)
782 {
783 strTmp.append(RASTER_TALUS_CODE);
784 strTmp.append(", ");
785 }
786
787 if (m_bSeaDepthSave)
788 {
789 strTmp.append(RASTER_SEA_DEPTH_CODE);
790 strTmp.append(", ");
791 }
792
794 {
795 strTmp.append(RASTER_AVG_SEA_DEPTH_CODE);
796 strTmp.append(", ");
797 }
798
799 if (m_bSeaMaskSave)
800 {
801 strTmp.append(RASTER_INUNDATION_MASK_CODE);
802 strTmp.append(", ");
803 }
804
806 {
807 strTmp.append(RASTER_WAVE_HEIGHT_CODE);
808 strTmp.append(", ");
809 }
810
812 {
813 strTmp.append(RASTER_WAVE_ORIENTATION_CODE);
814 strTmp.append(", ");
815 }
816
818 {
819 strTmp.append(RASTER_AVG_WAVE_HEIGHT_CODE);
820 strTmp.append(", ");
821 }
822
824 {
825 strTmp.append(RASTER_BEACH_PROTECTION_CODE);
826 strTmp.append(", ");
827 }
828
830 {
832 strTmp.append(", ");
833 }
834
836 {
838 strTmp.append(", ");
839 }
840
842 {
843 strTmp.append(RASTER_BEACH_DEPOSITION_CODE);
844 strTmp.append(", ");
845 }
846
848 {
850 strTmp.append(", ");
851 }
852
854 {
855 strTmp.append(RASTER_BEACH_MASK_CODE);
856 strTmp.append(", ");
857 }
858
860 {
862 strTmp.append(", ");
863 }
864
866 {
868 strTmp.append(", ");
869 }
870
872 {
874 strTmp.append(", ");
875 }
876
878 {
880 strTmp.append(", ");
881 }
882
884 {
886 strTmp.append(", ");
887 }
888
890 {
892 strTmp.append(", ");
893 }
894
896 {
898 strTmp.append(", ");
899 }
900
901 if (m_bLandformSave)
902 {
903 strTmp.append(RASTER_LANDFORM_CODE);
904 strTmp.append(", ");
905 }
906
908 {
910 strTmp.append(", ");
911 }
912
914 {
915 strTmp.append(RASTER_INTERVENTION_CLASS_CODE);
916 strTmp.append(", ");
917 }
918
920 {
921 strTmp.append(RASTER_INTERVENTION_HEIGHT_CODE);
922 strTmp.append(", ");
923 }
924
926 {
927 strTmp.append(RASTER_SUSP_SED_CODE);
928 strTmp.append(", ");
929 }
930
932 {
933 strTmp.append(RASTER_AVG_SUSP_SED_CODE);
934 strTmp.append(", ");
935 }
936
938 {
939 strTmp.append(RASTER_FINE_UNCONS_CODE);
940 strTmp.append(", ");
941 }
942
944 {
945 strTmp.append(RASTER_SAND_UNCONS_CODE);
946 strTmp.append(", ");
947 }
948
950 {
951 strTmp.append(RASTER_COARSE_UNCONS_CODE);
952 strTmp.append(", ");
953 }
954
956 {
957 strTmp.append(RASTER_FINE_CONS_CODE);
958 strTmp.append(", ");
959 }
960
962 {
963 strTmp.append(RASTER_SAND_CONS_CODE);
964 strTmp.append(", ");
965 }
966
968 {
969 strTmp.append(RASTER_COARSE_CONS_CODE);
970 strTmp.append(", ");
971 }
972
974 {
975 strTmp.append(RASTER_COAST_CODE);
976 strTmp.append(", ");
977 }
978
980 {
981 strTmp.append(RASTER_COAST_NORMAL_CODE);
982 strTmp.append(", ");
983 }
984
986 {
987 strTmp.append(RASTER_ACTIVE_ZONE_CODE);
988 strTmp.append(", ");
989 }
990
992 {
993 strTmp.append(RASTER_POLYGON_CODE);
994 strTmp.append(", ");
995 }
996
998 {
1000 strTmp.append(", ");
1001 }
1002
1004 {
1005 strTmp.append(RASTER_SEDIMENT_INPUT_EVENT_CODE);
1006 strTmp.append(", ");
1007 }
1008
1009 // Remove the trailing comma and space
1010 if (strTmp.size() > 2)
1011 strTmp.resize(strTmp.size() - 2);
1012
1013 return strTmp;
1014}
1015
1016//===============================================================================================================================
1018//===============================================================================================================================
1020{
1021 string strTmp;
1022
1023 if (m_bCoastSave)
1024 {
1025 strTmp.append(VECTOR_COAST_CODE);
1026 strTmp.append(", ");
1027 }
1028
1029 if (m_bNormalsSave)
1030 {
1031 strTmp.append(VECTOR_NORMALS_CODE);
1032 strTmp.append(", ");
1033 }
1034
1036 {
1037 strTmp.append(VECTOR_INVALID_NORMALS_CODE);
1038 strTmp.append(", ");
1039 }
1040
1042 {
1043 strTmp.append(VECTOR_WAVE_ANGLE_AND_HEIGHT_CODE);
1044 strTmp.append(", ");
1045 }
1046
1048 {
1050 strTmp.append(", ");
1051 }
1052
1054 {
1055 strTmp.append(VECTOR_COAST_CURVATURE_CODE);
1056 strTmp.append(", ");
1057 }
1058
1060 {
1062 strTmp.append(", ");
1063 }
1064
1066 {
1067 strTmp.append(VECTOR_MEAN_WAVE_ENERGY_CODE);
1068 strTmp.append(", ");
1069 }
1070
1072 {
1073 strTmp.append(VECTOR_BREAKING_WAVE_HEIGHT_CODE);
1074 strTmp.append(", ");
1075 }
1076
1078 {
1079 strTmp.append(VECTOR_POLYGON_NODE_CODE);
1080 strTmp.append(", ");
1081 }
1082
1084 {
1085 strTmp.append(VECTOR_POLYGON_BOUNDARY_CODE);
1086 strTmp.append(", ");
1087 }
1088
1090 {
1091 strTmp.append(VECTOR_CLIFF_NOTCH_ACTIVE_CODE);
1092 strTmp.append(", ");
1093 }
1094
1096 {
1097 strTmp.append(VECTOR_SHADOW_ZONE_BOUNDARY_CODE);
1098 strTmp.append(", ");
1099 }
1100
1102 {
1104 strTmp.append(", ");
1105 }
1106
1108 {
1110 strTmp.append(", ");
1111 }
1112
1113 // Remove the trailing comma and space
1114 if (strTmp.size() > 2)
1115 strTmp.resize(strTmp.size() - 2);
1116
1117 return strTmp;
1118}
1119
1120//===============================================================================================================================
1122//===============================================================================================================================
1124{
1125 string strTmp;
1126
1127 if (m_bSeaAreaTSSave)
1128 {
1129 strTmp.append(TIME_SERIES_SEA_AREA_CODE);
1130 strTmp.append(", ");
1131 }
1132
1133 if (m_bSWLTSSave)
1134 {
1135 strTmp.append(TIME_SERIES_SWL_CODE);
1136 strTmp.append(", ");
1137 }
1138
1140 {
1141 strTmp.append(TIME_SERIES_PLATFORM_EROSION_CODE);
1142 strTmp.append(", ");
1143 }
1144
1146 {
1148 strTmp.append(", ");
1149 }
1150
1152 {
1154 strTmp.append(", ");
1155 }
1156
1158 {
1160 strTmp.append(", ");
1161 }
1162
1164 {
1165 strTmp.append(TIME_SERIES_BEACH_EROSION_CODE);
1166 strTmp.append(", ");
1167 }
1168
1170 {
1171 strTmp.append(TIME_SERIES_BEACH_DEPOSITION_CODE);
1172 strTmp.append(", ");
1173 }
1174
1176 {
1177 strTmp.append(TIME_SERIES_BEACH_CHANGE_NET_CODE);
1178 strTmp.append(", ");
1179 }
1180
1181 if (m_bSuspSedTSSave)
1182 {
1184 strTmp.append(", ");
1185 }
1186
1188 {
1190 strTmp.append(", ");
1191 }
1192
1194 {
1196 strTmp.append(", ");
1197 }
1198
1200 {
1201 strTmp.append(TIME_SERIES_CLIFF_NOTCH_ELEV_CODE);
1202 strTmp.append(", ");
1203 }
1204
1205 // Remove the trailing comma and space
1206 if (strTmp.size() > 2)
1207 strTmp.resize(strTmp.size() - 2);
1208
1209 return strTmp;
1210}
1211
1212//===============================================================================================================================
1214//===============================================================================================================================
1216{
1217 string strTSFile;
1218
1219 if (m_bSeaAreaTSSave)
1220 {
1221 // Start with wetted area
1222 strTSFile = m_strOutPath;
1223 strTSFile.append(TIME_SERIES_SEA_AREA_NAME);
1224 strTSFile.append(CSVEXT);
1225
1226 // Open sea area time-series CSV file
1227 SeaAreaTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1228 if (! SeaAreaTSStream)
1229 {
1230 // Error, cannot open wetted area time-series file
1231 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1232 return false;
1233 }
1234 }
1235
1236 if (m_bSWLTSSave)
1237 {
1238 // Now SWL
1239 strTSFile = m_strOutPath;
1240 strTSFile.append(TIME_SERIES_SWL_NAME);
1241 strTSFile.append(CSVEXT);
1242
1243 // Open SWL time-series CSV file
1244 SWLTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1245 if (! SWLTSStream)
1246 {
1247 // Error, cannot open SWL time-series file
1248 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1249 return false;
1250 }
1251 }
1252
1254 {
1255 // Erosion (fine, sand, coarse)
1256 strTSFile = m_strOutPath;
1257 strTSFile.append(TIME_SERIES_PLATFORM_EROSION_NAME);
1258 strTSFile.append(CSVEXT);
1259
1260 // Open erosion time-series CSV file
1261 PlatformErosionTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1263 {
1264 // Error, cannot open erosion time-series file
1265 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1266 return false;
1267 }
1268 }
1269
1271 {
1272 // Erosion due to cliff collapse
1273 strTSFile = m_strOutPath;
1275 strTSFile.append(CSVEXT);
1276
1277 // Open cliff collapse erosion time-series CSV file
1278 CliffCollapseErosionTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1280 {
1281 // Error, cannot open cliff collapse erosion time-series file
1282 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1283 return false;
1284 }
1285 }
1286
1288 {
1289 // Deposition due to cliff collapse
1290 strTSFile = m_strOutPath;
1292 strTSFile.append(CSVEXT);
1293
1294 // Open cliff collapse deposition time-series CSV file
1295 CliffCollapseDepositionTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1297 {
1298 // Error, cannot open cliff collapse deposition time-series file
1299 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1300 return false;
1301 }
1302 }
1303
1305 {
1306 // Net change in unconsolidated sediment due to cliff collapse
1307 strTSFile = m_strOutPath;
1308 strTSFile.append(TIME_SERIES_CLIFF_COLLAPSE_NET_NAME);
1309 strTSFile.append(CSVEXT);
1310
1311 // Open net cliff collapse time-series CSV file
1312 CliffCollapseNetChangeTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1314 {
1315 // Error, cannot open net cliff collapse time-series file
1316 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1317 return false;
1318 }
1319 }
1320
1322 {
1323 // Beach erosion
1324 strTSFile = m_strOutPath;
1325 strTSFile.append(TIME_SERIES_BEACH_EROSION_NAME);
1326 strTSFile.append(CSVEXT);
1327
1328 // Open beach erosion time-series CSV file
1329 BeachErosionTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1331 {
1332 // Error, cannot open beach erosion time-series file
1333 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1334 return false;
1335 }
1336 }
1337
1339 {
1340 // Beach deposition
1341 strTSFile = m_strOutPath;
1342 strTSFile.append(TIME_SERIES_BEACH_DEPOSITION_NAME);
1343 strTSFile.append(CSVEXT);
1344
1345 // Open beach deposition time-series CSV file
1346 BeachDepositionTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1348 {
1349 // Error, cannot open beach deposition time-series file
1350 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1351 return false;
1352 }
1353 }
1354
1356 {
1357 // Beach sediment change
1358 strTSFile = m_strOutPath;
1359 strTSFile.append(TIME_SERIES_BEACH_CHANGE_NET_NAME);
1360 strTSFile.append(CSVEXT);
1361
1362 // Open net beach sediment change time-series CSV file
1363 BeachSedimentNetChangeTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1365 {
1366 // Error, cannot open beach sediment change time-series file
1367 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1368 return false;
1369 }
1370 }
1371
1372 if (m_bSuspSedTSSave)
1373 {
1374 // Sediment load
1375 strTSFile = m_strOutPath;
1376 strTSFile.append(TIME_SERIES_SUSPENDED_SEDIMENT_NAME);
1377 strTSFile.append(CSVEXT);
1378
1379 // Open sediment load time-series CSV file
1380 FineSedSuspensionTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1382 {
1383 // Error, cannot open sediment load time-series file
1384 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1385 return false;
1386 }
1387 }
1388
1390 {
1391 // Sediment load
1392 strTSFile = m_strOutPath;
1393 strTSFile.append(TIME_SERIES_FLOOD_SETUP_SURGE_CODE);
1394 strTSFile.append(CSVEXT);
1395
1396 // Open sediment load time-series CSV file
1397 FloodSetupSurgeTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1399 {
1400 // Error, cannot open sediment load time-series file
1401 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1402 return false;
1403 }
1404 }
1405
1407 {
1408 // Sediment load
1409 strTSFile = m_strOutPath;
1411 strTSFile.append(CSVEXT);
1412
1413 // Open sediment load time-series CSV file
1414 FloodSetupSurgeRunupTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1416 {
1417 // Error, cannot open sediment load time-series file
1418 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1419 return false;
1420 }
1421 }
1422
1424 {
1425 // Elevation of cliff notch
1426 strTSFile = m_strOutPath;
1427 strTSFile.append(TIME_SERIES_CLIFF_NOTCH_ELEV_NAME);
1428 strTSFile.append(CSVEXT);
1429
1430 // Open cliff notch elevation time-series CSV file
1431 CliffNotchElevTSStream.open(strTSFile.c_str(), ios::out | ios::trunc);
1433 {
1434 // Error, cannot open cliff notch elevation time-series file
1435 cerr << ERR << "cannot open " << strTSFile << " for output" << endl;
1436 return false;
1437 }
1438 }
1439
1440 return true;
1441}
1442
1443//===============================================================================================================================
1445//===============================================================================================================================
1447{
1448 // Add timestep to the total time simulated so far
1450
1452 {
1453 // It is time to quit
1456 return true;
1457 }
1458
1459 // Not quitting, so increment the timestep count, and recalc total timesteps
1460 m_ulIter++;
1461 m_ulTotTimestep = static_cast<unsigned long>(dRound(m_dSimDuration / m_dTimeStep));
1462
1463 // Check to see if we have done CLOCK_CHECK_ITERATION timesteps: if so, it is time to reset the CPU time running total in case the clock() function later rolls over
1466
1467 // Not yet time to quit
1468 return false;
1469}
1470
1471//===============================================================================================================================
1473//===============================================================================================================================
1475{
1476 string strComputerName;
1477
1478#ifdef _WIN32
1479 // Being compiled to run under Windows, either by MS VC++, Borland C++, or Cygwin
1480 strComputerName = getenv("COMPUTERNAME");
1481#else
1482 // Being compiled for another platform; assume for Linux-Unix
1483 char szHostName[BUF_SIZE] = "";
1484 gethostname(szHostName, BUF_SIZE);
1485
1486 strComputerName = szHostName;
1487
1488 if (strComputerName.empty())
1489 strComputerName = "Unknown Computer";
1490
1491#endif
1492
1493 return strComputerName;
1494}
1495
1496//===============================================================================================================================
1498//===============================================================================================================================
1500{
1501 if (static_cast<clock_t>(-1) == clock())
1502 {
1503 // Error
1504 LogStream << "CPU time not available" << endl;
1505 m_dCPUClock = -1;
1506 return;
1507 }
1508
1509 // OK, so carry on
1510 double dClkThis = static_cast<double>(clock());
1511 dClkThis -= CLOCK_T_MIN; // necessary when clock_t is signed, to make dClkThis unsigned
1512
1513 if (dClkThis < m_dClkLast)
1514 {
1515 // Clock has 'rolled over'
1516 m_dCPUClock += (CLOCK_T_RANGE + 1 - m_dClkLast); // this elapsed before rollover
1517 m_dCPUClock += dClkThis; // this elapsed after rollover
1518
1519#ifdef CLOCKCHECK
1520 // For debug purposes
1521 LogStream << "Rolled over: dClkThis=" << dClkThis << " m_dClkLast=" << m_dClkLast << endl
1522 << "\t"
1523 << " before rollover=" << (CLOCK_T_RANGE + 1 - m_dClkLast) << endl
1524 << "\t"
1525 << " after rollover=" << dClkThis << endl
1526 << "\t"
1527 << " ADDED=" << (CLOCK_T_RANGE + 1 - m_dClkLast + dClkThis) << endl;
1528#endif
1529 }
1530
1531 else
1532 {
1533 // No rollover
1534 m_dCPUClock += (dClkThis - m_dClkLast);
1535
1536#ifdef CLOCKCHECK
1537 // For debug purposes
1538 LogStream << "No rollover: dClkThis=" << dClkThis << " m_dClkLast=" << m_dClkLast << " ADDED=" << dClkThis - m_dClkLast << endl;
1539#endif
1540 }
1541
1542 // Reset for next time
1543 m_dClkLast = dClkThis;
1544}
1545
1546//===============================================================================================================================
1548//===============================================================================================================================
1550{
1551 cout << endl << FINAL_OUTPUT << endl;
1552}
1553
1554// //===============================================================================================================================
1555// //! Calculates and displays time elapsed in terms of CPU time and real time, also calculates time per timestep in terms of both CPU time and real time
1556// //===============================================================================================================================
1557// void CSimulation::CalcTime(double const dRunLength)
1558// {
1559// // Reset CPU count for last time
1560// DoCPUClockReset();
1561//
1562// if (! bFPIsEqual(m_dCPUClock, -1.0, TOLERANCE))
1563// {
1564// // Calculate CPU time in secs
1565// double const dDuration = m_dCPUClock / CLOCKS_PER_SEC;
1566//
1567// // And write CPU time out to OutStream and LogStream
1568// OutStream << "CPU time elapsed: " << strDispTime(dDuration, false, true);
1569// LogStream << "CPU time elapsed: " << strDispTime(dDuration, false, true);
1570//
1571// // Calculate CPU time per timestep
1572// double const dPerTimestep = dDuration / static_cast<double>(m_ulTotTimestep);
1573//
1574// // And write CPU time per timestep to OutStream and LogStream
1575// OutStream << fixed << setprecision(4) << " (" << dPerTimestep << " per timestep)" << endl;
1576// LogStream << fixed << setprecision(4) << " (" << dPerTimestep << " per timestep)" << endl;
1577//
1578// // Calculate ratio of CPU time to time simulated
1579// OutStream << resetiosflags(ios::floatfield);
1580// OutStream << fixed << setprecision(0) << "In terms of CPU time, this is ";
1581// LogStream << resetiosflags(ios::floatfield);
1582// LogStream << fixed << setprecision(0) << "In terms of CPU time, this is ";
1583//
1584// if (dDuration > dRunLength)
1585// {
1586// OutStream << dDuration / dRunLength << " x slower than reality" << endl;
1587// LogStream << dDuration / dRunLength << " x slower than reality" << endl;
1588// }
1589//
1590// else
1591// {
1592// OutStream << dRunLength / dDuration << " x faster than reality" << endl;
1593// LogStream << dRunLength / dDuration << " x faster than reality" << endl;
1594// }
1595// }
1596//
1597// // Calculate run time
1598// double const dDuration = difftime(m_tSysEndTime, m_tSysStartTime);
1599//
1600// // And write run time out to OutStream and LogStream
1601// OutStream << "Run time elapsed: " << strDispTime(dDuration, false, false);
1602// LogStream << "Run time elapsed: " << strDispTime(dDuration, false, false);
1603//
1604// // Calculate run time per timestep
1605// double const dPerTimestep = dDuration / static_cast<double>(m_ulTotTimestep);
1606//
1607// // And write run time per timestep to OutStream and LogStream
1608// OutStream << resetiosflags(ios::floatfield);
1609// OutStream << " (" << fixed << setprecision(4) << dPerTimestep << " per timestep)" << endl;
1610// LogStream << resetiosflags(ios::floatfield);
1611// LogStream << " (" << fixed << setprecision(4) << dPerTimestep << " per timestep)" << endl;
1612//
1613// // Calculate ratio of run time to time simulated
1614// OutStream << fixed << setprecision(0) << "In terms of run time, this is ";
1615// LogStream << fixed << setprecision(0) << "In terms of run time, this is ";
1616//
1617// if (dDuration > dRunLength)
1618// {
1619// OutStream << dDuration / dRunLength << " x slower than reality" << endl;
1620// LogStream << dDuration / dRunLength << " x slower than reality" << endl;
1621// }
1622//
1623// else
1624// {
1625// OutStream << dRunLength / dDuration << " x faster than reality" << endl;
1626// LogStream << dRunLength / dDuration << " x faster than reality" << endl;
1627// }
1628// }
1629
1630//===============================================================================================================================
1632//===============================================================================================================================
1633string CSimulation::strDispSimTime(const double dTimeIn)
1634{
1635 // Make sure no negative times
1636 double dTmpTime = tMax(dTimeIn, 0.0);
1637
1638 string strTime;
1639
1640 // Constants
1641 double const dHoursInYear = 24 * 365; // it was 365.25
1642 double const dHoursInDay = 24;
1643
1644 // Display years
1645 if (dTmpTime >= dHoursInYear)
1646 {
1647 double const dYears = floor(dTmpTime / dHoursInYear);
1648 dTmpTime -= (dYears * dHoursInYear);
1649
1650 strTime = to_string(static_cast<int>(dYears));
1651 strTime.append("y ");
1652 }
1653 else
1654 strTime = "0y ";
1655
1656 // Display Julian days
1657 if (dTmpTime >= dHoursInDay)
1658 {
1659 double const dJDays = floor(dTmpTime / dHoursInDay);
1660 dTmpTime -= (dJDays * dHoursInDay);
1661
1662 stringstream ststrTmp;
1663 ststrTmp << FillToWidth('0', 3) << static_cast<int>(dJDays);
1664 strTime.append(ststrTmp.str());
1665 strTime.append("d ");
1666 }
1667 else
1668 strTime.append("000d ");
1669
1670 // Display hours
1671 stringstream ststrTmp;
1672 ststrTmp << FillToWidth('0', 2) << static_cast<int>(dTmpTime);
1673 strTime.append(ststrTmp.str());
1674 strTime.append("h");
1675
1676 return strTime;
1677}
1678
1679//===============================================================================================================================
1681//===============================================================================================================================
1682string CSimulation::strDispTime(const double dTimeIn, const bool bRound, const bool bFrac)
1683{
1684 // Make sure no negative times
1685 double dTime = tMax(dTimeIn, 0.0);
1686
1687 string strTime;
1688
1689 if (bRound)
1690 dTime = dRound(dTime);
1691
1692 unsigned long ulTimeIn = static_cast<unsigned long>(floor(dTime));
1693 dTime -= static_cast<double>(ulTimeIn);
1694
1695 // Hours
1696 if (ulTimeIn >= 3600)
1697 {
1698 // Display some hours
1699 unsigned long const ulHours = ulTimeIn / 3600ul;
1700 ulTimeIn -= (ulHours * 3600ul);
1701
1702 strTime = to_string(ulHours);
1703 strTime.append(":");
1704 }
1705 else
1706 strTime = "0:";
1707
1708 // Minutes
1709 if (ulTimeIn >= 60)
1710 {
1711 // display some minutes
1712 unsigned long const ulMins = ulTimeIn / 60ul;
1713 ulTimeIn -= (ulMins * 60ul);
1714
1715 stringstream ststrTmp;
1716 ststrTmp << FillToWidth('0', 2) << ulMins;
1717 strTime.append(ststrTmp.str());
1718 strTime.append(":");
1719 }
1720 else
1721 strTime.append("00:");
1722
1723 // Seconds
1724 stringstream ststrTmp;
1725 ststrTmp << FillToWidth('0', 2) << ulTimeIn;
1726 strTime.append(ststrTmp.str());
1727
1728 if (bFrac)
1729 {
1730 // Fractions of a second
1731 strTime.append(".");
1732 ststrTmp.clear();
1733 ststrTmp.str(string());
1734 ststrTmp << FillToWidth('0', 2) << static_cast<unsigned long>(dTime * 100);
1735 strTime.append(ststrTmp.str());
1736 }
1737
1738 return strTime;
1739}
1740
1741//===============================================================================================================================
1743//===============================================================================================================================
1745{
1746 string strBuild("(");
1747 strBuild.append(__TIME__);
1748 strBuild.append(" ");
1749 strBuild.append(__DATE__);
1750#ifdef _DEBUG
1751 strBuild.append(" DEBUG");
1752#endif
1753 strBuild.append(" build)");
1754
1755 return strBuild;
1756}
1757
1758//===============================================================================================================================
1760//===============================================================================================================================
1762{
1763 if (isatty(fileno(stdout)))
1764 {
1765 // Stdout is connected to a tty, so not running as a background job
1766 static double sdElapsed = 0;
1767 static double sdToGo = 0;
1768 time_t const tNow = time(nullptr);
1769
1770 // Calculate time elapsed and remaining
1771 sdElapsed = difftime(tNow, m_tSysStartTime);
1772 sdToGo = (sdElapsed * m_dSimDuration / m_dSimElapsed) - sdElapsed;
1773
1774 // Tell the user about progress (note need to make several separate calls to cout here, or MS VC++ compiler appears to get confused)
1776 cout << fixed << setprecision(3) << setw(9) << 100 * m_dSimElapsed / m_dSimDuration;
1777 cout << "% (elapsed " << strDispTime(sdElapsed, false, false) << " remaining ";
1778
1779 cout << strDispTime(sdToGo, false, false) << ") ";
1780
1781 // Add a 'marker' for GIS saves etc.
1783 cout << setw(9) << "GIS" + to_string(m_nGISSave);
1784 else if (m_bSedimentInputThisIter)
1785 cout << setw(9) << "SED INPUT";
1786 else
1787 cout << setw(9) << SPACE;
1788
1789 cout.flush();
1790 }
1791}
1792
1793//===============================================================================================================================
1795//===============================================================================================================================
1797{
1798 string const NA = "Not available";
1799
1800 OutStream << endl;
1801 OutStream << "Process statistics" << endl;
1802 OutStream << "------------------" << endl;
1803
1804#ifdef _WIN32
1805 // First, find out which version of Windows we are running under
1806 OSVERSIONINFOEX osvi;
1807 BOOL bOsVersionInfoEx;
1808
1809 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); // fill this much memory with zeros
1810 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
1811
1812 if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*)&osvi)))
1813 {
1814 // OSVERSIONINFOEX didn't work so try OSVERSIONINFO instead
1815 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
1816
1817 if (!GetVersionEx((OSVERSIONINFO*)&osvi))
1818 {
1819 // That didn't work either, too risky to proceed so give up
1820 OutStream << NA << endl;
1821 return;
1822 }
1823 }
1824
1825 // OK, we have Windows version so display it
1826 OutStream << "Running under \t: ";
1827
1828 switch (osvi.dwPlatformId)
1829 {
1830 case VER_PLATFORM_WIN32_NT:
1831 if (osvi.dwMajorVersion <= 4)
1832 OutStream << "Windows NT ";
1833
1834 else if (5 == osvi.dwMajorVersion && 0 == osvi.dwMinorVersion)
1835 OutStream << "Windows 2000 ";
1836
1837 else if (5 == osvi.dwMajorVersion && 1 == osvi.dwMinorVersion)
1838 OutStream << "Windows XP ";
1839
1840 else if (6 == osvi.dwMajorVersion && 0 == osvi.dwMinorVersion)
1841 OutStream << "Windows Vista ";
1842
1843 else if (6 == osvi.dwMajorVersion && 1 == osvi.dwMinorVersion)
1844 OutStream << "Windows 7 ";
1845
1846 else if (6 == osvi.dwMajorVersion && 2 == osvi.dwMinorVersion)
1847 OutStream << "Windows 8 ";
1848
1849 else if (6 == osvi.dwMajorVersion && 3 == osvi.dwMinorVersion)
1850 OutStream << "Windows 8.1 ";
1851
1852 else if (10 == osvi.dwMajorVersion && 0 == osvi.dwMinorVersion)
1853 OutStream << "Windows 10 ";
1854
1855 else if (11 == osvi.dwMajorVersion && 0 == osvi.dwMinorVersion)
1856 OutStream << "Windows 11 ";
1857
1858 else
1859 OutStream << "unknown Windows version ";
1860
1861 // Display version, service pack (if any), and build number
1862 if (osvi.dwMajorVersion <= 4)
1863 OutStream << "version " << osvi.dwMajorVersion << "." << osvi.dwMinorVersion << " " << osvi.szCSDVersion << " (Build " << (osvi.dwBuildNumber & 0xFFFF) << ")" << endl;
1864
1865 else
1866 OutStream << osvi.szCSDVersion << " (Build " << (osvi.dwBuildNumber & 0xFFFF) << ")" << endl;
1867
1868 break;
1869
1870 case VER_PLATFORM_WIN32_WINDOWS:
1871 if (4 == osvi.dwMajorVersion && 0 == osvi.dwMinorVersion)
1872 {
1873 OutStream << "Windows 95";
1874
1875 if ('C' == osvi.szCSDVersion[1] || 'B' == osvi.szCSDVersion[1])
1876 OutStream << " OSR2";
1877
1878 OutStream << endl;
1879 }
1880
1881 else if (4 == osvi.dwMajorVersion && 10 == osvi.dwMinorVersion)
1882 {
1883 OutStream << "Windows 98";
1884
1885 if ('A' == osvi.szCSDVersion[1])
1886 OutStream << "SE";
1887
1888 OutStream << endl;
1889 }
1890
1891 else if (4 == osvi.dwMajorVersion && 90 == osvi.dwMinorVersion)
1892 OutStream << "Windows Me" << endl;
1893
1894 else
1895 OutStream << "unknown 16-bit Windows version " << endl;
1896
1897 break;
1898
1899 case VER_PLATFORM_WIN32s:
1900 OutStream << "Win32s" << endl;
1901 break;
1902 }
1903
1904 // Now get process timimgs: this only works under 32-bit windows
1905 if (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId)
1906 {
1907 FILETIME ftCreate, ftExit, ftKernel, ftUser;
1908
1909 if (GetProcessTimes(GetCurrentProcess(), &ftCreate, &ftExit, &ftKernel, &ftUser))
1910 {
1911 ULARGE_INTEGER ul;
1912 ul.LowPart = ftUser.dwLowDateTime;
1913 ul.HighPart = ftUser.dwHighDateTime;
1914 OutStream << "Time spent executing user code \t: " << strDispTime(static_cast<double>(ul.QuadPart) * 1e-7, false) << endl;
1915 ul.LowPart = ftKernel.dwLowDateTime;
1916 ul.HighPart = ftKernel.dwHighDateTime;
1917 OutStream << "Time spent executing kernel code \t: " << strDispTime(static_cast<double>(ul.QuadPart) * 1e-7, false) << endl;
1918 }
1919 }
1920
1921 else
1922 OutStream << "Process timings \t: " << NA << endl;
1923
1924 // Finally get more process statistics: this needs psapi.dll, so only proceed if it is present on this system
1925 HINSTANCE hDLL = LoadLibrary("psapi.dll");
1926
1927 if (hDLL != NULL)
1928 {
1929 // The dll has been found
1930 typedef BOOL(__stdcall * DLLPROC)(HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);
1931 DLLPROC ProcAdd;
1932
1933 // Try to get the address of the function we will call
1934 ProcAdd = (DLLPROC)GetProcAddress(hDLL, "GetProcessMemoryInfo");
1935
1936 if (ProcAdd)
1937 {
1938 // Address was found
1939 PROCESS_MEMORY_COUNTERS pmc;
1940
1941 // Now call the function
1942 if ((ProcAdd)(GetCurrentProcess(), &pmc, sizeof(pmc)))
1943 {
1944 OutStream << "Peak working set size \t: " << pmc.PeakWorkingSetSize / (1024.0 * 1024.0) << " Mb" << endl;
1945 OutStream << "Current working set size \t: " << pmc.WorkingSetSize / (1024.0 * 1024.0) << " Mb" << endl;
1946 OutStream << "Peak paged pool usage \t: " << pmc.QuotaPeakPagedPoolUsage / (1024.0 * 1024.0) << " Mb" << endl;
1947 OutStream << "Current paged pool usage \t: " << pmc.QuotaPagedPoolUsage / (1024.0 * 1024.0) << " Mb" << endl;
1948 OutStream << "Peak non-paged pool usage \t: " << pmc.QuotaPeakNonPagedPoolUsage / (1024.0 * 1024.0) << " Mb" << endl;
1949 OutStream << "Current non-paged pool usage \t: " << pmc.QuotaNonPagedPoolUsage / (1024.0 * 1024.0) << " Mb" << endl;
1950 OutStream << "Peak pagefile usage \t: " << pmc.PeakPagefileUsage / (1024.0 * 1024.0) << " Mb" << endl;
1951 OutStream << "Current pagefile usage \t: " << pmc.PagefileUsage / (1024.0 * 1024.0) << " Mb" << endl;
1952 OutStream << "No. of page faults \t: " << pmc.PageFaultCount << endl;
1953 }
1954 }
1955
1956 // Free the memory used by the dll
1957 FreeLibrary(hDLL);
1958 }
1959
1960#elif defined __GNUG__
1961 rusage ru;
1962
1963 if (getrusage(RUSAGE_SELF, &ru) >= 0)
1964 {
1965 OutStream << "Time spent executing user code \t: " << strDispTime(static_cast<double>(ru.ru_utime.tv_sec), false, true) << endl;
1966 // OutStream << "ru_utime.tv_usec \t: " << ru.ru_utime.tv_usec << endl;
1967 OutStream << "Time spent executing kernel code \t: " << strDispTime(static_cast<double>(ru.ru_stime.tv_sec), false, true) << endl;
1968 // OutStream << "ru_stime.tv_usec \t: " << ru.ru_stime.tv_usec << endl;
1969 // OutStream << "Maximum resident set size \t: " << ru.ru_maxrss/1024.0 << " Mb" << endl;
1970 // OutStream << "ixrss (???) \t: " << ru.ru_ixrss << endl;
1971 // OutStream << "Sum of rm_asrss (???) \t: " << ru.ru_idrss << endl;
1972 // OutStream << "isrss (???) \t: " << ru.ru_isrss << endl;
1973 OutStream << "No. of page faults not requiring physical I/O\t: " << ru.ru_minflt << endl;
1974 OutStream << "No. of page faults requiring physical I/O \t: " << ru.ru_majflt << endl;
1975 // OutStream << "No. of times swapped out of main memory \t: " << ru.ru_nswap << endl;
1976 // OutStream << "No. of times performed input (read request) \t: " << ru.ru_inblock << endl;
1977 // OutStream << "No. of times performed output (write request)\t: " << ru.ru_oublock << endl;
1978 // OutStream << "No. of signals received \t: " << ru.ru_nsignals << endl;
1979 OutStream << "No. of voluntary context switches \t: " << ru.ru_nvcsw << endl;
1980 OutStream << "No. of involuntary context switches \t: " << ru.ru_nivcsw << endl;
1981 }
1982
1983 else
1984 OutStream << NA << endl;
1985
1986#else
1987 OutStream << NA << endl;
1988#endif
1989
1990 OutStream << endl;
1991
1992#ifdef _OPENMP
1993#pragma omp parallel
1994 {
1995 if (0 == omp_get_thread_num())
1996 {
1997 OutStream << "Number of OpenMP threads \t: " << omp_get_num_threads() << endl;
1998 OutStream << "Number of OpenMP processors \t: " << omp_get_num_procs() << endl;
1999
2000 LogStream << "Number of OpenMP threads \t: " << omp_get_num_threads() << endl;
2001 LogStream << "Number of OpenMP processors \t: " << omp_get_num_procs() << endl;
2002 }
2003 }
2004#endif
2005
2006 time_t const tRunTime = m_tSysEndTime - m_tSysStartTime;
2007 struct tm* ptmRunTime = gmtime(&tRunTime);
2008
2009 OutStream << "Time required for simulation \t: " << put_time(ptmRunTime, "%T") << endl;
2010 LogStream << "Time required for simulation \t: " << put_time(ptmRunTime, "%T") << endl;
2011
2012 double const dSpeedUp = m_dSimDuration * 3600 / static_cast<double>(tRunTime);
2013 OutStream << setprecision(0);
2014 OutStream << "Time simulated / time required for simulation\t: " << dSpeedUp << " x faster than reality" << endl;
2015
2016 LogStream << setprecision(0);
2017 LogStream << "Time simulated / time required for simulation\t: " << dSpeedUp << " x faster than reality" << endl;
2018}
2019
2020//===============================================================================================================================
2022//===============================================================================================================================
2023string CSimulation::strGetErrorText(int const nErr)
2024{
2025 string strErr;
2026
2027 switch (nErr)
2028 {
2029 case RTN_USER_ABORT:
2030 strErr = "run ended by user";
2031 break;
2032
2033 case RTN_ERR_BADPARAM:
2034 strErr = "error in command-line parameter";
2035 break;
2036
2037 case RTN_ERR_INI:
2038 strErr = "error reading initialisation file";
2039 break;
2040
2041 case RTN_ERR_CMEDIR:
2042 strErr = "error in directory name";
2043 break;
2044
2045 case RTN_ERR_RUNDATA:
2046 strErr = "error reading run details file";
2047 break;
2048
2050 strErr = "error reading SCAPE shape function file";
2051 break;
2052
2054 strErr = "error reading tide data file";
2055 break;
2056
2057 case RTN_ERR_LOGFILE:
2058 strErr = "error creating log file";
2059 break;
2060
2061 case RTN_ERR_OUTFILE:
2062 strErr = "error creating text output file";
2063 break;
2064
2065 case RTN_ERR_TSFILE:
2066 strErr = "error creating time series file";
2067 break;
2068
2069 case RTN_ERR_DEMFILE:
2070 strErr = "error reading initial DEM file";
2071 break;
2072
2074 strErr = "error reading raster GIS file";
2075 break;
2076
2078 strErr = "error reading vector GIS file";
2079 break;
2080
2081 case RTN_ERR_MEMALLOC:
2082 strErr = "error allocating memory";
2083 break;
2084
2086 strErr = "problem with raster GIS output format";
2087 break;
2088
2090 strErr = "problem with vector GIS output format";
2091 break;
2092
2094 strErr = "error writing text output file";
2095 break;
2096
2098 strErr = "error writing raster GIS output file";
2099 break;
2100
2102 strErr = "error writing vector GIS output file";
2103 break;
2104
2106 strErr = "error writing time series output file";
2107 break;
2108
2109 case RTN_ERR_LINETOGRID:
2110 strErr = "error putting linear feature onto raster grid";
2111 break;
2112
2113 case RTN_ERR_NOSEACELLS:
2114 strErr = "no sea cells found";
2115 break;
2116
2118 strErr = "error when searching grid for linear feature";
2119 break;
2120
2121 case RTN_ERR_NO_COAST:
2122 strErr = "no coastlines found. Is the SWL correct?";
2123 break;
2124
2126 strErr = "error writing coastline-normal profiles";
2127 break;
2128
2129 case RTN_ERR_TIME_UNITS:
2130 strErr = "error in time units";
2131 break;
2132
2134 strErr = "no solution when finding end point for coastline-normal line";
2135 break;
2136
2138 strErr = "end point for coastline-normal line is not in the contiguous sea";
2139 break;
2140
2142 strErr = "cliff notch is above sediment top elevation";
2143 break;
2144
2146 strErr = "unable to deposit enough unconsolidated sediment (talus) from cliff collapse";
2147 break;
2148
2150 strErr = "coastline-normal profiles are too closely spaced";
2151 break;
2152
2154 strErr = "no coastline-normal profiles created, check the SWL";
2155 break;
2156
2158 strErr = "no coastline-normal profiles created during rasterization";
2159 break;
2160
2162 strErr = "hit grid edge when eroding beach";
2163 break;
2164
2166 strErr = "could not locate seaward end of profile when creating Dean profile for beach erosion";
2167 break;
2168
2170 strErr = "could not locate seaward end of profile when creating Dean profile for up-coast beach deposition";
2171 break;
2172
2174 strErr = "could not locate seaward end of profile when creating Dean profile for down-coast beach deposition";
2175 break;
2176
2178 strErr = "updating grid with landforms";
2179 break;
2180
2182 strErr = "no top layer of sediment";
2183 break;
2184
2186 strErr = "problem with polygon-to-polygon sediment routing sequence";
2187 break;
2188
2190 strErr = "inconsistent multiline";
2191 break;
2192
2194 strErr = "cannot insert point into multiline";
2195 break;
2196
2198 strErr = "cannot assign coastal landform";
2199 break;
2200
2202 strErr = "start point for cell-by-cell fill of wave shadow zone is outside grid";
2203 break;
2204
2206 strErr = "could not find start point for cell-by-cell fill of wave shadow zone";
2207 break;
2208
2210 strErr = "empty profile during during CShore wave propagation";
2211 break;
2212
2214 strErr = "creating file for CShore input";
2215 break;
2216
2218 strErr = "reading CShore output file";
2219 break;
2220
2222 strErr = "during wave interpolation lookup";
2223 break;
2224
2225 case RTN_ERR_GRIDCREATE:
2226 strErr = "while running GDALGridCreate()";
2227 break;
2228
2230 strErr = "cannot find edge cell while constructing grid-edge profile";
2231 break;
2232
2234 strErr = "CShore did not finish correctly";
2235 break;
2236
2238 strErr = "Could not find cell under coastline";
2239 break;
2240
2242 strErr = "opening deep sea wave time series file";
2243 break;
2244
2246 strErr = "reading deep sea wave time series file";
2247 break;
2248
2250 strErr = "finding edges of the bounding box";
2251 break;
2252
2254 strErr = "reading sediment input event time series file";
2255 break;
2256
2258 strErr = "simulating sediment input event";
2259 break;
2260
2262 strErr = "location of sediment input event is outside grod";
2263 break;
2264
2266 strErr = "location of wavestation is outside grid";
2267 break;
2268
2270 strErr = "cliff not in polygon";
2271 break;
2272
2274 strErr = "Cell marked as profile coast but not as profile";
2275 break;
2276
2278 strErr = "error tracing flood line on grid";
2279 break;
2280
2282 strErr = "error tracing coastline on grid, no coast start-finish points found";
2283 break;
2284
2286 strErr = "error tracing coastline on grid, no valid coast found";
2287 break;
2288
2290 strErr = "error tracing coastline on grid, coast search just repeats";
2291 break;
2292
2294 strErr = "error tracing coastline on grid, zero-length coast found";
2295 break;
2296
2298 strErr = "error tracing coastline on grid, coast below minimum permitted length";
2299 break;
2300
2302 strErr = "error tracing coastline on grid, coast ignored";
2303 break;
2304
2306 strErr = "error tracing coastline on grid, too many times round tracing loop";
2307 break;
2308
2310 strErr = "intersection cell not found in hit profile";
2311 break;
2312
2314 strErr = "point not found when truncating multiline for different coasts";
2315 break;
2316
2318 strErr = "cell not found in hit profile";
2319 break;
2320
2322 strErr = "cell marked as in polygon, but does not have polygon's coast";
2323 break;
2324
2326 strErr = "cannot find closest point to coast when moving talus to unconsolidated sediment";
2327 break;
2328
2329 case RTN_ERR_UNKNOWN:
2330 strErr = "unknown error";
2331 break;
2332
2333 default:
2334 // should never get here
2335 strErr = " error";
2336 }
2337
2338 return strErr;
2339}
2340
2341//===============================================================================================================================
2343//===============================================================================================================================
2345{
2346 // If we don't know the time that the run ended (e.g. because it did not finish correctly), then get it now
2347 if (m_tSysEndTime == 0)
2348 m_tSysEndTime = time(nullptr);
2349
2350 switch (nRtn)
2351 {
2352 case (RTN_OK):
2353 // normal ending
2354 cout << RUN_END_NOTICE << put_time(localtime(&m_tSysEndTime), "%T %A %d %B %Y") << endl;
2355 break;
2356
2357 case (RTN_HELP_ONLY):
2358 case (RTN_CHECK_ONLY):
2359 return;
2360
2361 default:
2362 // Aborting because of some error
2363 cerr << RUN_END_NOTICE << "iteration " << m_ulIter << ERROR_NOTICE << nRtn << ": \"" << strGetErrorText(nRtn) << "\", " << put_time(localtime(&m_tSysEndTime), "%T %A %d %B %Y") << endl;
2364
2365 if (m_ulIter > 1)
2366 {
2367 // If the run has actually started, then output all GIS files: this is very helpful in tracking down problems
2368 m_bSaveGISThisIter = true;
2369 m_nGISSave = 998; // Will get incremented to 999 when we write the files
2372 }
2373
2374 // Write the error message to the logfile and to stdout
2375 if (LogStream && LogStream.is_open())
2376 {
2377 LogStream << ERR << strGetErrorText(nRtn) << " (error code " << nRtn << ") on " << put_time(localtime(&m_tSysEndTime), "%T %A %d %B %Y") << endl;
2378 LogStream.flush();
2379 }
2380
2381 if (OutStream && OutStream.is_open())
2382 {
2383 OutStream << ERR << strGetErrorText(nRtn) << " (error code " << nRtn << ") on " << put_time(localtime(&m_tSysEndTime), "%T %A %d %B %Y") << endl;
2384 OutStream.flush();
2385 }
2386 }
2387
2388#ifdef __GNUG__
2389 if (isatty(fileno(stdout)))
2390 {
2391 // Stdout is connected to a tty, so not running as a background job
2392 // cout << endl
2393 // << PRESS_KEY;
2394 // cout.flush();
2395 // getchar();
2396 }
2397 else
2398 {
2399 // Stdout is not connected to a tty, so must be running in the background; if we have something entered for the email address, then send an email
2400 if (! m_strMailAddress.empty())
2401 {
2402 cout << SEND_EMAIL << m_strMailAddress << endl;
2403
2404 string strCmd("echo \"");
2405
2406 stringstream ststrTmp;
2407 ststrTmp << put_time(localtime(&m_tSysEndTime), "%T on %A %d %B %Y") << endl;
2408
2409 // Send an email using Linux/Unix mail command
2410 if (RTN_OK == nRtn)
2411 {
2412 // Finished normally
2413 strCmd.append("Simulation ");
2414 strCmd.append(m_strRunName);
2415 strCmd.append(", running on ");
2416 strCmd.append(strGetComputerName());
2417 strCmd.append(", completed normally at ");
2418 strCmd.append(ststrTmp.str());
2419 strCmd.append("\" | mail -s \"");
2420 strCmd.append(PROGRAM_NAME);
2421 strCmd.append(": normal completion\" ");
2422 strCmd.append(m_strMailAddress);
2423 }
2424 else
2425 {
2426 // Error, so give some information to help debugging
2427 strCmd.append("Simulation ");
2428 strCmd.append(m_strRunName);
2429 strCmd.append(", running on ");
2430 strCmd.append(strGetComputerName());
2431 strCmd.append(", aborted with error code ");
2432 strCmd.append(to_string(nRtn));
2433 strCmd.append(": ");
2434 strCmd.append(strGetErrorText(nRtn));
2435 strCmd.append(" at timestep ");
2436 strCmd.append(to_string(m_ulIter));
2437 strCmd.append(" (");
2438 strCmd.append(strDispSimTime(m_dSimElapsed));
2439 strCmd.append(").\n\nThis message sent at ");
2440 strCmd.append(ststrTmp.str());
2441 strCmd.append("\" | mail -s \"");
2442 strCmd.append(PROGRAM_NAME);
2443 strCmd.append(": ERROR\" ");
2444 strCmd.append(m_strMailAddress);
2445 }
2446
2447 int const nRet = system(strCmd.c_str());
2448
2449 if (WEXITSTATUS(nRet) != 0)
2450 cerr << ERR << EMAIL_ERROR << endl;
2451 }
2452 }
2453#endif
2454}
2455
2456//===============================================================================================================================
2458//===============================================================================================================================
2459string CSimulation::pstrChangeToBackslash(string const* strIn)
2460{
2461 string strOut(*strIn);
2462 strOut.replace(strOut.begin(), strOut.end(), '/', '\\');
2463 return strOut;
2464}
2465
2466//===============================================================================================================================
2468//===============================================================================================================================
2469string CSimulation::pstrChangeToForwardSlash(string const* strIn)
2470{
2471 string strOut(*strIn);
2472 strOut.replace(strOut.begin(), strOut.end(), '\\', '/');
2473 return strOut;
2474}
2475
2476//===============================================================================================================================
2478//===============================================================================================================================
2479string CSimulation::strTrimLeft(string const* strIn)
2480{
2481 // Trim leading spaces
2482 size_t const nStartpos = strIn->find_first_not_of(" \t");
2483
2484 if (nStartpos == string::npos)
2485 return *strIn;
2486
2487 else
2488 return strIn->substr(nStartpos);
2489}
2490
2491//===============================================================================================================================
2493//===============================================================================================================================
2494string CSimulation::strTrimRight(string const* strIn)
2495{
2496 string strTmp(*strIn);
2497
2498 // Remove any stray carriage returns (can happen if file was edited in Windows)
2499 strTmp.erase(remove(strTmp.begin(), strTmp.end(), '\r'), strTmp.end());
2500
2501 // Trim trailing spaces
2502 size_t const nEndpos = strTmp.find_last_not_of(" \t");
2503
2504 if (nEndpos == string::npos)
2505 return strTmp;
2506
2507 else
2508 return strTmp.substr(0, nEndpos + 1);
2509}
2510
2511//===============================================================================================================================
2513//===============================================================================================================================
2514string CSimulation::strTrim(string const* strIn)
2515{
2516 string strTmp = *strIn;
2517
2518 // Remove any stray carriage returns (can happen if file was edited in Windows)
2519 strTmp.erase(remove(strTmp.begin(), strTmp.end(), '\r'), strTmp.end());
2520
2521 // Trim trailing spaces
2522 size_t nPos = strTmp.find_last_not_of(" \t");
2523
2524 if (nPos != string::npos)
2525 strTmp.resize(nPos + 1);
2526
2527 // Trim leading spaces
2528 nPos = strTmp.find_first_not_of(" \t");
2529
2530 if (nPos != string::npos)
2531 strTmp = strTmp.substr(nPos);
2532
2533 return strTmp;
2534}
2535
2536//===============================================================================================================================
2538//===============================================================================================================================
2539string CSimulation::strToLower(string const* strIn)
2540{
2541 string strOut = *strIn;
2542 transform(strIn->begin(), strIn->end(), strOut.begin(), tolower);
2543 return strOut;
2544}
2545
2546//===============================================================================================================================
2547// Returns the upper case version of an string, leaving the original unchanged
2548//===============================================================================================================================
2549// string CSimulation::strToUpper(string const* strIn)
2550// {
2551// string strOut = *strIn;
2552// transform(strIn->begin(), strIn->end(), strOut.begin(), toupper);
2553// return strOut;
2554// }
2555
2556//===============================================================================================================================
2558//===============================================================================================================================
2559string CSimulation::strRemoveSubstr(string* pStrIn, string const* pStrSub)
2560{
2561 size_t const nPos = pStrIn->find(*pStrSub);
2562
2563 if (nPos != string::npos)
2564 {
2565 // OK, found the substring
2566 pStrIn->replace(nPos, pStrSub->size(), "");
2567 return strTrim(pStrIn);
2568 }
2569
2570 else
2571 {
2572 // If not found, return the string unchanged
2573 return *pStrIn;
2574 }
2575}
2576
2577//===============================================================================================================================
2579//===============================================================================================================================
2580vector<string>* CSimulation::VstrSplit(string const* s, char const delim, vector<string>* elems)
2581{
2582 stringstream ss(*s);
2583 string item;
2584
2585 while (getline(ss, item, delim))
2586 {
2587 if (!item.empty())
2588 elems->push_back(item);
2589 }
2590
2591 return elems;
2592}
2593
2594//===============================================================================================================================
2596//===============================================================================================================================
2597vector<string> CSimulation::VstrSplit(string const* s, char const delim)
2598{
2599 vector<string> elems;
2600 VstrSplit(s, delim, &elems);
2601 return elems;
2602}
2603
2604// //===============================================================================================================================
2605// //! Calculates the vector cross product of three points
2606// //===============================================================================================================================
2607// double CSimulation::dCrossProduct(double const dX1, double const dY1, double const dX2, double const dY2, double const dX3, double const dY3)
2608// {
2609// // Based on code at http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/clockwise.htm
2610// return (dX2 - dX1) * (dY3 - dY2) - ((dY2 - dY1) * (dX3 - dX2));
2611// }
2612
2613// //===============================================================================================================================
2614// //! Calculates the mean of a pointer to a vector of doubles
2615// //===============================================================================================================================
2616// double CSimulation::dGetMean(vector<double> const* pV)
2617// {
2618// double dSum = accumulate(pV->begin(), pV->end(), 0.0);
2619// double dMean = dSum / static_cast<double>(pV->size());
2620// return dMean;
2621// }
2622
2623// //===============================================================================================================================
2624// //! Calculates the standard deviation of a pointer to a vector of doubles. From http://stackoverflow.com/questions/7616511/calculate-mean-and-standard-deviation-from-a-vector-of-samples-in-c-using-boos
2625// //===============================================================================================================================
2626// double CSimulation::dGetStdDev(vector<double> const* pV)
2627// {
2628// double dSum = accumulate(pV->begin(), pV->end(), 0.0);
2629// double dMean = dSum / static_cast<double>(pV->size());
2630//
2631// double dSqSum = inner_product(pV->begin(), pV->end(), pV->begin(), 0.0);
2632// double dStdDev = sqrt(dSqSum / static_cast<double>(pV->size()) - dMean * dMean);
2633//
2634// return dStdDev;
2635// }
2636
2637//===============================================================================================================================
2639//===============================================================================================================================
2640void CSimulation::AppendEnsureNoGap(vector<CGeom2DIPoint>* pVPtiPoints, CGeom2DIPoint const* pPti)
2641{
2642 int const nX = pPti->nGetX();
2643 int const nY = pPti->nGetY();
2644 int const nXLast = pVPtiPoints->back().nGetX();
2645 int const nYLast = pVPtiPoints->back().nGetY();
2646 int const nXDiff = nX - nXLast;
2647 int const nYDiff = nY - nYLast;
2648 int const nXDiffA = tAbs(nXDiff);
2649 int const nYDiffA = tAbs(nYDiff);
2650 int const nDiff = tMax(nXDiffA, nYDiffA);
2651
2652 if (nDiff > 1)
2653 {
2654 // We have a gap
2655 double
2656 dXInc = 0,
2657 dYInc = 0;
2658
2659 if (nXDiffA > 1)
2660 dXInc = static_cast<double>(nXDiff) / nDiff;
2661
2662 if (nYDiffA > 1)
2663 dYInc = static_cast<double>(nYDiff) / nDiff;
2664
2665 for (int n = 1; n < nDiff; n++)
2666 {
2667 CGeom2DIPoint const Pti(nXLast + nRound(n * dXInc), nYLast + nRound(n * dYInc));
2668 pVPtiPoints->push_back(Pti);
2669 }
2670 }
2671
2672 pVPtiPoints->push_back(CGeom2DIPoint(nX, nY));
2673}
2674
2675//===============================================================================================================================
2677//===============================================================================================================================
2678void CSimulation::CalcDeanProfile(vector<double>* pdVDeanProfile, double const dInc, double const dDeanTopElev, double const dA, bool const bDeposition, int const nSeawardOffset, double const dStartCellElev)
2679{
2680 double dDistFromProfileStart = 0;
2681
2682 if (bDeposition)
2683 {
2684 // This Dean profile is for deposition i.e. seaward displacement of the profile
2685 pdVDeanProfile->at(0) = dStartCellElev; // Is coast elevation
2686
2687 for (int n = 1; n < static_cast<int>(pdVDeanProfile->size()); n++)
2688 {
2689 if (n <= nSeawardOffset)
2690 // As we extend the profile seaward, the elevation of any points coastward of the new coast point of the Dean profile are set to the elevation of the original coast point
2691 pdVDeanProfile->at(n) = dStartCellElev;
2692 else
2693 {
2694 double const dDistBelowTop = dA * pow(dDistFromProfileStart, DEAN_POWER);
2695 pdVDeanProfile->at(n) = dDeanTopElev - dDistBelowTop;
2696
2697 dDistFromProfileStart += dInc;
2698 }
2699 }
2700 }
2701 else
2702 {
2703 // This Dean profile is for erosion i.e. landward displacement of the profile
2704 for (int n = 0; n < static_cast<int>(pdVDeanProfile->size()); n++)
2705 {
2706 double const dDistBelowTop = dA * pow(dDistFromProfileStart, DEAN_POWER);
2707 pdVDeanProfile->at(n) = dDeanTopElev - dDistBelowTop;
2708
2709 dDistFromProfileStart += dInc;
2710 }
2711 }
2712}
2713
2714//===============================================================================================================================
2716//===============================================================================================================================
2717double CSimulation::dSubtractProfiles(vector<double> const* pdVFirstProfile, vector<double> const* pdVSecondProfile, vector<bool> const* pbVIsValid)
2718{
2719 double dTotElevDiff = 0;
2720
2721 // Note that this assumes that all three vectors are of equal length, should really check this
2722 for (int n = 0; n < static_cast<int>(pdVFirstProfile->size()); n++)
2723 {
2724 if (pbVIsValid->at(n))
2725 {
2726 double const dProfileDiff = pdVFirstProfile->at(n) - pdVSecondProfile->at(n);
2727
2728 dTotElevDiff += dProfileDiff;
2729 }
2730 }
2731
2732 // // DEBUG CODE -----------------------------------------------------
2733 // LogStream << endl;
2734 // LogStream << "First profile = ";
2735 // for (int n = 0; n < static_cast<int>(pdVFirstProfile->size()); n++)
2736 // {
2737 // LogStream << pdVFirstProfile->at(n) << " ";
2738 // }
2739 // LogStream << endl;
2740 // LogStream << "Second profile = ";
2741 // for (int n = 0; n < static_cast<int>(pdVFirstProfile->size()); n++)
2742 // {
2743 // LogStream << pdVSecondProfile->at(n) << " ";
2744 // }
2745 // LogStream << endl;
2746 // LogStream << "Difference = ";
2747 // for (int n = 0; n < static_cast<int>(pdVFirstProfile->size()); n++)
2748 // {
2749 // LogStream << pdVFirstProfile->at(n) - pdVSecondProfile->at(n) << " ";
2750 // }
2751 // LogStream << endl;
2752 // // DEBUG CODE -----------------------------------------------------
2753
2754 return dTotElevDiff;
2755}
2756
2757//===============================================================================================================================
2759//===============================================================================================================================
2761{
2762 double
2763 dDeepWaterWaveHeight,
2764 dDeepWaterPeriod;
2765
2767 {
2768 dDeepWaterWaveHeight = m_dAllCellsDeepWaterWaveHeight;
2769 dDeepWaterPeriod = m_dAllCellsDeepWaterWavePeriod;
2770 }
2771
2772 else
2773 {
2774 dDeepWaterWaveHeight = m_dMaxUserInputWaveHeight;
2775 dDeepWaterPeriod = m_dMaxUserInputWavePeriod;
2776 }
2777
2778 // TODO 051 Calculate depth of closure using 'average of the maximum values observed during a typical year'
2779 // dL = 2.28 * Hsx − (68.5 * Hsx^2 / (g * Tsx^2))
2780 // where:
2781 // Hsx is the nearshore storm wave height that is exceeded only 12 hours each year
2782 // Tsx is the associated wave period
2783 // from Hallermeier, R.J. (1978). Uses for a calculated limit depth to beach erosion. Proc. 16th Coastal Engineering Conf., ASCE, New York. Pp 1493 - 1512
2784 //
2785 // For the time being, and since we assume wave height and period constant just use the actual wave height and period to calculate the depth of closure
2786 // m_dDepthOfClosure = (2.28 * dDeepWaterWaveHeight) - (68.5 * dDeepWaterWaveHeight * dDeepWaterWaveHeight / (m_dG * dDeepWaterPeriod * dDeepWaterPeriod));
2787
2788 // An alternative (which produces smaller depth of closure estimates) is Birkemeier (1985) TODO 007 Full reference needed
2789 // dL = 1.75 * Hsx - (57.9 * Hsx^2/ (g * Tsx^2))
2790 m_dDepthOfClosure = (1.75 * dDeepWaterWaveHeight) - (57.9 * dDeepWaterWaveHeight * dDeepWaterWaveHeight / (m_dG * dDeepWaterPeriod * dDeepWaterPeriod));
2791}
2792
2793// //===============================================================================================================================
2794// //! Tests a reference to a string to see if it is numeric (modified from https://tfetimes.com/c-determine-if-a-string-is-numeric/)
2795// //===============================================================================================================================
2796// bool CSimulation::bIsNumeric(string const*strIn)
2797// {
2798// return all_of(strIn->begin(), strIn->end(), isdigit);
2799// }
2800
2801//===============================================================================================================================
2803//===============================================================================================================================
2804bool CSimulation::bParseDate(string const* strDate, int& nDay, int& nMonth, int& nYear)
2805{
2806 vector<string> VstrTmp = VstrSplit(strDate, SLASH);
2807
2808 if (VstrTmp.size() < 3)
2809 {
2810 cerr << "date string must include day, month, and year '" << strDate << "'" << endl;
2811 return false;
2812 }
2813
2814 // Sort out day
2815 if (! bIsStringValidInt(VstrTmp[0]))
2816 {
2817 cerr << "invalid integer for day in date '" << strDate << "'" << endl;
2818 return false;
2819 }
2820
2821 nDay = stoi(VstrTmp[0]);
2822
2823 if ((nDay < 1) || (nDay > 31))
2824 {
2825 cerr << "day must be between 1 and 31 in date '" << strDate << "'" << endl;
2826 return false;
2827 }
2828
2829 // Sort out month
2830 if (! bIsStringValidInt(VstrTmp[1]))
2831 {
2832 cerr << "invalid integer for month in date '" << strDate << "'" << endl;
2833 return false;
2834 }
2835
2836 nMonth = stoi(VstrTmp[1]);
2837
2838 if ((nMonth < 1) || (nMonth > 12))
2839 {
2840 cerr << "month must be between 1 and 12 in date '" << strDate << "'" << endl;
2841 return false;
2842 }
2843
2844 // Sort out year
2845 if (! bIsStringValidInt(VstrTmp[2]))
2846 {
2847 cerr << "invalid integer for year in date '" << strDate << "'" << endl;
2848 return false;
2849 }
2850
2851 nYear = stoi(VstrTmp[2]);
2852
2853 if (nYear < 0)
2854 {
2855 cerr << "year must be > 0 in date '" << strDate << "'" << endl;
2856 return false;
2857 }
2858
2859 return true;
2860}
2861
2862//===============================================================================================================================
2864//===============================================================================================================================
2865bool CSimulation::bParseTime(string const* strTime, int& nHour, int& nMin, int& nSec)
2866{
2867 vector<string> VstrTmp = VstrSplit(strTime, DASH);
2868
2869 if (VstrTmp.size() < 3)
2870 {
2871 cerr << "time string must include hours, minutes, and seconds '" << strTime << "'" << endl;
2872 return false;
2873 }
2874
2875 // Sort out hour
2876 if (! bIsStringValidInt(VstrTmp[0]))
2877 {
2878 cerr << "invalid integer for hours in time '" << strTime << "'" << endl;
2879 return false;
2880 }
2881
2882 nHour = stoi(VstrTmp[0]);
2883
2884 if ((nHour < 0) || (nHour > 23))
2885 {
2886 cerr << "hour must be between 0 and 23 in time '" << strTime << "'" << endl;
2887 return false;
2888 }
2889
2890 // Sort out minutes
2891 if (! bIsStringValidInt(VstrTmp[1]))
2892 {
2893 cerr << "invalid integer for minutes in time '" << strTime << "'" << endl;
2894 return false;
2895 }
2896
2897 nMin = stoi(VstrTmp[1]);
2898
2899 if ((nMin < 0) || (nMin > 59))
2900 {
2901 cerr << "minutes must be betwen 0 and 59 in time '" << strTime << "'" << endl;
2902 return false;
2903 }
2904
2905 // Sort out seconds
2906 if (! bIsStringValidInt(VstrTmp[2]))
2907 {
2908 cerr << "invalid integer for seconds in time '" << strTime << "'" << endl;
2909 return false;
2910 }
2911
2912 nSec = stoi(VstrTmp[2]);
2913
2914 if ((nSec < 0) || (nSec > 59))
2915 {
2916 cerr << "seconds must be between 0 and 59 in time '" << strTime << "'" << endl;
2917 return false;
2918 }
2919
2920 return true;
2921}
2922
2923//===============================================================================================================================
2925//===============================================================================================================================
2926unsigned long CSimulation::ulConvertToTimestep(string const* pstrIn) const
2927{
2928 unsigned long ulTimeStep = 0;
2929
2930 // Convert to lower case, remove leading and trailing whitespace
2931 string strDate = strToLower(pstrIn);
2932 strDate = strTrim(&strDate);
2933
2934 if (strDate.find("hour") != string::npos)
2935 {
2936 // OK, this is a number of hours (a relative time, from the start of simulation)
2937 vector<string> VstrTmp = VstrSplit(&strDate, SPACE);
2938
2939 if ((VstrTmp.size() < 2) || (! bIsStringValidInt(VstrTmp[0])))
2940 {
2941 cerr << "Error in number of hours '" + strDate + "' for sediment input event" << endl;
2943 }
2944
2945 double const dHours = stod(strTrim(&VstrTmp[0]));
2946
2947 if (dHours > m_dSimDuration)
2948 {
2949 cerr << "Sediment input event '" + strDate + "' occurs after end of simulation" << endl;
2951 }
2952
2953 ulTimeStep = static_cast<unsigned long>(dRound(dHours / m_dTimeStep));
2954 }
2955
2956 else if (strDate.find("day") != string::npos)
2957 {
2958 // OK, this is a number of days (a relative time, from the start of simulation)
2959 vector<string> VstrTmp = VstrSplit(&strDate, SPACE);
2960
2961 if ((VstrTmp.size() < 2) || (! bIsStringValidInt(VstrTmp[0])))
2962 {
2963 cerr << "Error in number of days '" + strDate + "' for sediment input event" << endl;
2965 }
2966
2967 double const dHours = stod(strTrim(&VstrTmp[0])) * 24;
2968
2969 if (dHours > m_dSimDuration)
2970 {
2971 cerr << "Sediment input event '" + strDate + "' occurs after end of simulation" << endl;
2973 }
2974
2975 ulTimeStep = static_cast<unsigned long>(dRound(dHours / m_dTimeStep));
2976 }
2977
2978 else
2979 {
2980 // This is an absolute time/date in the format hh-mm-ss dd/mm/yyyy
2981 vector<string> VstrTmp = VstrSplit(&strDate, SPACE);
2982
2983 if (VstrTmp.size() < 2)
2984 {
2985 cerr << "Error in time/date '" + strDate + "' of sediment input event" << endl;
2987 }
2988
2989 int nHour = 0;
2990 int nMin = 0;
2991 int nSec = 0;
2992
2993 // OK, first sort out the time
2994 if (! bParseTime(&VstrTmp[0], nHour, nMin, nSec))
2995 {
2996 cerr << "Error in time '" + VstrTmp[0] + "' of sediment input event" << endl;
2998 }
2999
3000 int nDay = 0;
3001 int nMonth = 0;
3002 int nYear = 0;
3003
3004 // Now sort out the time
3005 if (! bParseDate(&VstrTmp[1], nDay, nMonth, nYear))
3006 {
3007 cerr << "Error in date '" + VstrTmp[1] + "' of sediment input event" << endl;
3009 }
3010
3011 // This is modified from https://stackoverflow.com/questions/14218894/number-of-days-between-two-dates-c
3012 struct tm tmSimStart = {};
3013 tmSimStart.tm_sec = m_nSimStartSec;
3014 tmSimStart.tm_min = m_nSimStartMin;
3015 tmSimStart.tm_hour = m_nSimStartHour;
3016 tmSimStart.tm_mday = m_nSimStartDay;
3017 tmSimStart.tm_mon = m_nSimStartMonth - 1;
3018 tmSimStart.tm_year = m_nSimStartYear - 1900;
3019
3020 struct tm tmSimEvent = {};
3021 tmSimEvent.tm_sec = nSec;
3022 tmSimEvent.tm_min = nMin;
3023 tmSimEvent.tm_hour = nHour;
3024 tmSimEvent.tm_mday = nDay;
3025 tmSimEvent.tm_mon = nMonth - 1;
3026 tmSimEvent.tm_year = nYear - 1900;
3027
3028 time_t const tStart = mktime(&tmSimStart);
3029 time_t const tEvent = mktime(&tmSimEvent);
3030
3031 if (tStart == (time_t)(-1))
3032 {
3033 cerr << "Error in simulation start time/date" << endl;
3035 }
3036
3037 if (tEvent == (time_t)(-1))
3038 {
3039 cerr << "Error in time/date '" + strDate + "' of sediment input event" << endl;
3041 }
3042
3043 double const dHours = difftime(tEvent, tStart) / (60 * 60);
3044
3045 if (dHours < 0)
3046 {
3047 cerr << "Sediment input event '" + strDate + "' occurs before start of simulation" << endl;
3049 }
3050
3051 if (dHours > m_dSimDuration)
3052 {
3053 cerr << "Sediment input event '" + strDate + "' occurs after end of simulation" << endl;
3055 }
3056
3057 ulTimeStep = static_cast<unsigned long>(dHours / m_dTimeStep);
3058 }
3059
3060 return ulTimeStep;
3061}
3062
3063//===============================================================================================================================
3065//===============================================================================================================================
3066bool CSimulation::bIsInterventionCell(int const nX, int const nY) const
3067{
3068 int const nCat = m_pRasterGrid->m_Cell[nX][nY].pGetLandform()->nGetLFCategory();
3069 if ((nCat == LF_INTERVENTION_STRUCT) || (nCat == LF_INTERVENTION_NON_STRUCT))
3070 return true;
3071
3072 return false;
3073}
3074
3075//===============================================================================================================================
3077//===============================================================================================================================
3079{
3080 // Clear all vector coastlines, profiles, and polygons
3081 m_VCoast.clear();
3082
3083 // m_VFloodWaveSetup.clear();
3084 m_VFloodWaveSetupSurge.clear();
3086}
3087
3088//===============================================================================================================================
3090//===============================================================================================================================
3091void CSimulation::CalcMHWElevation(int const nTideDataCount)
3092{
3093 // Calculate the number of tide values to read
3094 int const nTidevaluesPerDay = tMax(nRound(24 / m_dTimeStep), 1);
3095 int const nTideValuesToRead = nTidevaluesPerDay * NUM_DAYS_FOR_MEAN_HIGH_WATER_CALC;
3096
3097 int const nNumTideValues = static_cast<int>(m_VdTideData.size());
3098
3099 // Now read the tide data (note that this assumes that the first line of the tide data is the first tide reading of the day)
3100 int nThisCount = nTideDataCount;
3101 double dTotMaxTide = 0;
3102 for (int n = 0; n < nTideValuesToRead; n++)
3103 {
3104 // Read in this days's tide data
3105 double dDayMaxTide = -DBL_MAX;
3106 for (int m = 0; m < nTidevaluesPerDay; m++)
3107 {
3108 // If necessary, wrap the tide data, i.e. start again with the first line of the tide data if we do not have enough
3109 if (nThisCount > nNumTideValues - 1)
3110 nThisCount = 0;
3111
3112 double const dThisTideData = m_VdTideData[nThisCount];
3113
3114 if (dThisTideData > dDayMaxTide)
3115 dDayMaxTide = dThisTideData;
3116
3117 nThisCount++;
3118 }
3119
3120 // We have the max tide for the day, so increment the total of highest daily tides
3121 dTotMaxTide += dDayMaxTide;
3122 }
3123
3124 // Now calculate the average max tide for the next NUM_DAYS_FOR_MEAN_HIGH_WATER_CALC days
3125 double const dMaxTideAvg = dTotMaxTide / nTideValuesToRead;
3126
3127 // Finally, calculate MHW for this iteration (includes long-term SWL change)
3128 m_dThisIterMHWElev = m_dThisIterMeanSWL + dMaxTideAvg;
3129
3130 // And set the apex elevation of any new cliff notches (i.e. cliff notches which will be created during this timestep) to be at or slightly above MHW level
3132
3133 // LogStream << m_ulIter << ": this-iteration MHW elevation = " << m_dThisIterMHWElev << " elevation of apex of new cliff notches = " << m_dThisIterNewNotchApexElev << endl;
3134}
Contains CGeom2DIPoint definitions.
Geometry class used to represent 2D point objects with integer coordinates.
Definition 2di_point.h:25
int nGetY(void) const
Returns the CGeom2DIPoint object's integer Y coordinate.
Definition 2di_point.cpp:51
int nGetX(void) const
Returns the CGeom2DIPoint object's integer X coordinate.
Definition 2di_point.cpp:45
void CalcDepthOfClosure(void)
Calculate the depth of closure.
Definition utils.cpp:2760
int m_nLogFileDetail
The level of detail in the log file output. Can be LOG_FILE_LOW_DETAIL, LOG_FILE_MIDDLE_DETAIL,...
Definition simulation.h:588
bool m_bAvgSeaDepthSave
Save average sea depth raster GIS files?
Definition simulation.h:105
vector< string > m_VstrInitialSandConsSedimentFile
The name of the initial sand-sized consolidated sediment GIS file.
double m_dAllCellsDeepWaterWaveHeight
Deep water wave height (m) for all sea cells.
Definition simulation.h:768
static void AnnounceReadSCAPEShapeFunctionFile(void)
Now reading the SCAPE shape function file.
Definition utils.cpp:734
string m_strInitialSuspSedimentFile
Name of initial suspended sediment file.
bool m_bSlopeConsSedSave
Save slope of consolidated sediment raster GIS files?
Definition simulation.h:174
static void AnnounceIsRunning(void)
Tell the user that the simulation is now running.
Definition utils.cpp:751
void DoCPUClockReset(void)
Resets the CPU clock timer to prevent it 'rolling over', as can happen during long runs....
Definition utils.cpp:1499
bool m_bFineUnconsSedSave
Save fine unconsolidated sediment raster GIS files?
Definition simulation.h:189
string m_strSedimentInputEventFile
The name of the sediment input events time series file.
time_t m_tSysEndTime
System finish-simulation time.
string m_strCMEIni
Folder for the CME .ini file.
double m_dG
Gravitational acceleration (m**2/sec)
Definition simulation.h:825
vector< string > m_VstrInitialCoarseUnconsSedimentFile
The name of the initial coarse-sized unconsolidated sediment GIS file.
void AnnounceReadDeepWaterWaveValuesGIS(void) const
Tells the user that we are now reading the deep water wave values GIS file.
Definition utils.cpp:586
double m_dThisIterSWL
The still water level for this timestep (this includes tidal changes and any long-term SWL change)
Definition simulation.h:726
ofstream CliffCollapseNetChangeTSStream
Cliff collapse net change (erosion - deposition) time series file output stream.
bool m_bCoastSave
Save coastline as vector GIS file?
Definition simulation.h:261
bool m_bBeachDepositionTSSave
Save the beach (unconsolidated sediment) deposition time series file?
Definition simulation.h:315
static string strRemoveSubstr(string *, string const *)
Returns a string with a substring removed, and with whitespace trimmed.
Definition utils.cpp:2559
CGeomRasterGrid * m_pRasterGrid
Pointer to the raster grid object.
static bool bParseTime(string const *, int &, int &, int &)
Parses a time string into hours, minutes, and seconds, and checks each of them.
Definition utils.cpp:2865
double dGetThisIterTotWaterLevel(void) const
Returns this timestep's total water level TODO 007 Finish surge and runup stuff.
Definition utils.cpp:104
void AnnounceReadInitialSandConsSedGIS(int const) const
Tells the user that we are now reading the initial sand consolidated sediment depth GIS file.
Definition utils.cpp:696
int m_nXGridSize
The size of the grid in the x direction.
Definition simulation.h:477
string strListRasterFiles(void) const
Return a space-separated string containing the names of the raster GIS output files.
Definition utils.cpp:759
void AnnounceReadInitialSandUnconsSedGIS(int const) const
Tells the user that we are now reading the initial sand unconsolidated sediment depth GIS file.
Definition utils.cpp:657
string strListVectorFiles(void) const
Return a space-separated string containing the names of the vector GIS output files.
Definition utils.cpp:1019
double m_dMaxUserInputWavePeriod
Used to constrain depth of closure.
Definition simulation.h:780
bool m_bFloodSetupSurgeRunupTSSave
Save the flood setup surge runup time series file? TODO 007 Finish surge and runup stuff.
Definition simulation.h:327
bool m_bTopSurfIncSeaSave
Save top surface (sediment, talus, and sea) raster DEMs?
Definition simulation.h:87
bool bSetUpTSFiles(void)
This member function intialises the time series files.
Definition utils.cpp:1215
ofstream LogStream
void AnnounceReadInitialFineUnconsSedGIS(int const) const
Tells the user that we are now reading the initial fine unconsolidated sediment depth GIS file.
Definition utils.cpp:644
bool m_bSedIncTalusTopSurfSave
Save sediment (inc talus) top surface raster DEMs?
Definition simulation.h:84
vector< CRWCoast > m_VFloodWaveSetupSurgeRunup
TODO 007 Finish surge and runup stuff.
vector< CRWCoast > m_VCoast
The coastline objects.
static string pstrChangeToForwardSlash(string const *)
Swaps all backslashes in the input string to forward slashes, leaving the original unchanged.
Definition utils.cpp:2469
bool m_bSaveGISThisIter
Save GIS files this iteration?
Definition simulation.h:333
void DoSimulationEnd(int const)
Carries out end-of-simulation tidying (error messages etc.)
Definition utils.cpp:2344
double m_dCPUClock
Total elapsed CPU time.
Definition simulation.h:708
bool bSaveAllVectorGISFiles(void)
The bSaveAllvectorGISFiles member function saves the vector GIS files TODO 081 Choose more files to o...
bool m_bSingleDeepWaterWaveValues
Do we have just a point source for (i.e. only a single measurement of) deep water wave values.
Definition simulation.h:387
string m_strRunName
The name of this simulation.
static string strGetComputerName(void)
Returns a string, hopefully giving the name of the computer on which the simulation is running.
Definition utils.cpp:1474
static string strDispSimTime(double const)
strDispSimTime returns a string formatted as year Julian_day hour, given a parameter in hours
Definition utils.cpp:1633
bool m_bAvgWaveAngleAndHeightSave
Save average wave angle and average wave height raster GIS files?
Definition simulation.h:123
bool m_bInvalidNormalsSave
Save invalid coastline-normal vector GIS files?
Definition simulation.h:270
bool m_bShadowBoundarySave
Save wave shadow boundary vector GIS files?
Definition simulation.h:288
int nDoSimulationTimeMultiplier(string const *)
Given a string containing time units, this sets up the appropriate multiplier and display units for t...
Definition utils.cpp:411
bool m_bActualBeachErosionSave
Save actual (supply-limited) beach (unconsolidated sediment) erosion raster GIS files?
Definition simulation.h:156
int m_nYGridSize
The size of the grid in the y direction.
Definition simulation.h:480
vector< double > m_VdTideData
Tide data: one record per timestep, is the change (m) from still water level for that timestep.
bool m_bYamlInputFormat
Use YAML format for input datafile instead of .dat format?
Definition simulation.h:348
bool m_bTotalActualPlatformErosionSave
Save total actual (supply-limited) shore platform erosion raster GIS files?
Definition simulation.h:150
static string strTrimLeft(string const *)
Trims whitespace from the left side of a string, does not change the original string.
Definition utils.cpp:2479
vector< string > m_VstrInitialFineConsSedimentFile
The name of the initial fine-sized consolidated sediment GIS file.
double m_dMissingValue
Used by CoastalME for floating-point missing values.
Definition simulation.h:981
bool m_bBasementElevSave
Save basement raster DEMs?
Definition simulation.h:81
int m_nSimStartHour
Start time of the simulation (hours)
Definition simulation.h:573
bool m_bCoarseUnconsSedSave
Save coarse unconsolidated sediment raster GIS files?
Definition simulation.h:195
bool m_bSuspSedTSSave
Save the suspended sediment time series file?
Definition simulation.h:321
bool m_bCliffCollapseNetTSSave
Save the cliff collapse net change time series file?
Definition simulation.h:309
bool m_bPotentialPlatformErosionMaskSave
Save potential platform erosion mask raster GIS files?
Definition simulation.h:231
static void AnnounceSimEnd(void)
Announce the end of the simulation.
Definition utils.cpp:1549
int nGetGridYMax(void) const
Returns the size of the grid in the Y direction.
Definition utils.cpp:136
void AnnounceReadICGIS(void) const
Tells the user that we are now reading the Intervention class GIS file.
Definition utils.cpp:556
bool m_bWaveHeightSave
Save wave height raster GIS files?
Definition simulation.h:108
bool m_bLandformSave
Save coast landform raster GIS files?
Definition simulation.h:171
ofstream CliffCollapseDepositionTSStream
Cliff collapse deposition time series file output stream.
vector< CRWCoast > m_VFloodWaveSetupSurge
TODO 007 Finish surge and runup stuff.
static string strTrim(string const *)
Trims whitespace from both sides of a string, does not change the original string.
Definition utils.cpp:2514
bool m_bTotalBeachDepositionSave
Save total beach (unconsolidated sediment) deposition raster GIS files?
Definition simulation.h:168
double dGetMissingValue(void) const
Returns the NODATA value.
Definition utils.cpp:88
static void AnnounceFinalInitialization(void)
Tells the user that we are now initializing.
Definition utils.cpp:742
int m_nSimStartSec
Start time of the simulation (seconds)
Definition simulation.h:567
int m_nSimStartDay
Start date of the simulation (day)
Definition simulation.h:576
bool m_bSandUnconsSedSave
Save sand unconsolidated sediment raster GIS files?
Definition simulation.h:192
bool m_bActualPlatformErosionTSSave
Save the actual (supply-limited) shore platform erosion time series file?
Definition simulation.h:300
unsigned long ulConvertToTimestep(string const *) const
For sediment input events, parses a string that may be relative (a number of hours or days after the ...
Definition utils.cpp:2926
double dGetD50Coarse(void) const
Returns the global d50 value for coarse sediment.
Definition utils.cpp:160
static void AnnounceAddLayers(void)
Tells the user that we are now adding layers.
Definition utils.cpp:516
bool m_bRasterPolygonSave
Save raster polygon raster GIS files?
Definition simulation.h:228
bool m_bBeachDepositionSave
Save beach (unconsolidated sediment) deposition raster GIS files?
Definition simulation.h:165
double m_dThisIterNewNotchApexElev
Elevation (m) of the apex of any cliff notches created during this iteration.
Definition simulation.h:930
bool bFindExeDir(char const *)
Finds the folder (directory) in which the CoastalME executable is located.
Definition utils.cpp:316
static double dSubtractProfiles(vector< double > const *, vector< double > const *, vector< bool > const *)
Calculate the total elevation difference between every point in two elevation profiles (first profile...
Definition utils.cpp:2717
bool m_bNormalsSave
Save coastline-normal vector GIS files?
Definition simulation.h:267
bool m_bAvgWaveHeightSave
Save wave height raster GIS files?
Definition simulation.h:111
static string strToLower(string const *)
Returns the lower case version of an string, leaving the original unchanged.
Definition utils.cpp:2539
bool m_bHaveSandSediment
Does this simulation consider sand-sized sediment?
Definition simulation.h:75
bool m_bSeaDepthSave
Save sea depth raster GIS files?
Definition simulation.h:102
bool m_bWaveAngleAndHeightSave
Save wave angle and wave height raster GIS files?
Definition simulation.h:120
ofstream BeachDepositionTSStream
Beach sediment deposition time series file output stream.
string m_strInitialBasementDEMFile
Name of initial basement DEM file.
static string strTrimRight(string const *)
Trims whitespace from the right side of a string, does not change the original string.
Definition utils.cpp:2494
void AnnounceReadSedimentEventInputValuesGIS(void) const
Tells the user that we are now reading the sediment input events GIS file.
Definition utils.cpp:601
double dGetD50Fine(void) const
Returns the global d50 value for fine sediment.
Definition utils.cpp:144
string m_strLogFile
Name of output log file.
time_t m_tSysStartTime
System start-simulation time.
void AnnounceReadFloodLocationGIS(void) const
Tells the user that we are now reading the flood location GIS file.
Definition utils.cpp:616
void StartClock(void)
Starts the clock ticking.
Definition utils.cpp:292
bool m_bRasterNormalProfileSave
Save rasterized coastline-normal profiles GIS files?
Definition simulation.h:210
bool m_bActiveZoneSave
Save active zone raster GIS files?
Definition simulation.h:213
void AnnounceReadInitialSuspSedGIS(void) const
Tells the user that we are now reading the initial suspended sediment depth GIS file.
Definition utils.cpp:631
void DoEndOfRunDeletes(void)
Do end-of-run memory clearance.
Definition utils.cpp:3078
vector< string > m_VstrInitialSandUnconsSedimentFile
The name of the initial sand-sized unconsolidated sediment GIS file.
static int nDoTimeUnits(string const *)
This finds time units in a string.
Definition utils.cpp:450
static void AnnounceReadRasterFiles(void)
Now reading raster GIS files.
Definition utils.cpp:525
double m_dD50Sand
The D50 for sand sediment.
Definition simulation.h:789
string m_strCMEDir
The CME folder.
bool m_bMeanWaveEnergySave
Save mean wave energy raster GIS files?
Definition simulation.h:132
ofstream BeachSedimentNetChangeTSStream
Beach sediment net change (erosion - deposition) time series file output stream.
double m_dSimElapsed
Time simulated so far, in hours.
Definition simulation.h:693
static double dGetTimeMultiplier(string const *)
Given a string containing time units, this returns the appropriate multiplier.
Definition utils.cpp:376
bool m_bCoastCurvatureSave
Save coastline-curvature vector GIS files?
Definition simulation.h:273
int nGetGridXMax(void) const
Returns the cell size.
Definition utils.cpp:128
void AnnounceReadBasementDEM(void) const
Tells the user that we are now reading the DEM file.
Definition utils.cpp:495
bool m_bSWLTSSave
Save the SWL (still water level) time series file?
Definition simulation.h:297
bool m_bBreakingWaveHeightSave
Save breaking wave height raster GIS files?
Definition simulation.h:135
string m_strMailAddress
An email addresx to which to send end-of-simulation messages.
bool m_bPolygonNodeSave
Save polygon node vector GIS files?
Definition simulation.h:276
string strListTSFiles(void) const
Return a space-separated string containing the names of the time series output files.
Definition utils.cpp:1123
bool m_bFloodSetupSurgeTSSave
Save the flood setup surge time series file? TODO 007 Finish surge and runup stuff.
Definition simulation.h:324
bool m_bTotalPotentialPlatformErosionSave
Save total potential shore platform erosion raster GIS files?
Definition simulation.h:147
bool m_bWaveEnergySinceCollapseSave
Save wave energy since cliff collapse raster GIS files?
Definition simulation.h:129
double m_dD50Coarse
The D50 for coarse sediment.
Definition simulation.h:792
static void AnnounceStart(void)
Tells the user that we have started the simulation.
Definition utils.cpp:272
ofstream SWLTSStream
SWL time series file output stream.
ofstream CliffCollapseErosionTSStream
Cliff collapse erosion time series file output stream.
bool m_bPotentialBeachErosionSave
Save potential beach (unconsolidated sediment) erosion raster GIS files?
Definition simulation.h:153
static bool bParseDate(string const *, int &, int &, int &)
Parses a date string into days, months, and years, and checks each of them.
Definition utils.cpp:2804
string m_strFloodLocationShapefile
The name of the flood loction events shape file.
int m_nSimStartMonth
Start date of the simulation (month)
Definition simulation.h:579
bool m_bSuspSedSave
Save suspended sediment raster GIS files?
Definition simulation.h:183
string m_strDurationUnits
The duration units for this simulation.
bool m_bPolygonBoundarySave
Save polygon boundary vector GIS files?
Definition simulation.h:279
vector< string > m_VstrInitialFineUnconsSedimentFile
The name of the initial fine-sized unconsolidated sediment GIS file.
bool m_bActualPlatformErosionSave
Save actual (supply-limited) shore platform erosion raster GIS files?
Definition simulation.h:144
double m_dNotchApexAboveMHW
Distance of notch base below SWL (m)
Definition simulation.h:933
int m_nSimStartMin
Start time of the simulation (minutes)
Definition simulation.h:570
bool bSaveAllRasterGISFiles(void)
The bSaveAllRasterGISFiles member function saves the raster GIS files using values from the RasterGri...
bool m_bHaveFineSediment
Does this simulation consider fine-sized sediment?
Definition simulation.h:72
string m_strOutPath
Path for all output files.
bool m_bBeachErosionTSSave
Save the beach (unconsolidated sediment) erosion time series file?
Definition simulation.h:312
static string strGetBuild(void)
Returns the date and time on which the program was compiled.
Definition utils.cpp:1744
string m_strTideDataFile
Name of tide data file.
bool m_bTotalPotentialBeachErosionSave
Save total potential beach (unconsolidated sediment) erosion raster GIS files?
Definition simulation.h:159
int m_nGISSave
The save number for GIS files (can be sequential, or the iteration number)
Definition simulation.h:519
string m_strInterventionClassFile
Name of intervention class file.
bool m_bSeaMaskSave
Save sea mask raster GIS files?
Definition simulation.h:234
bool m_bInterventionClassSave
Save intervention class raster GIS files?
Definition simulation.h:177
int m_nSimStartYear
Start date of the simulation (year)
Definition simulation.h:582
bool m_bTotalActualBeachErosionSave
Save total actual (supply-limited) beach (unconsolidated sediment) erosion raster GIS files?
Definition simulation.h:162
bool m_bRasterCoastlineSave
Save rasterized coastline GIS files?
Definition simulation.h:207
string m_strDeepWaterWavesInputFile
The name of the deep water wave stations time series file.
static string pstrChangeToBackslash(string const *)
Changes all forward slashes in the input string to backslashes, leaving the original unchanged.
Definition utils.cpp:2459
bool m_bInterventionHeightSave
Save intervention height raster GIS files?
Definition simulation.h:180
ofstream SeaAreaTSStream
Sea area time series file output stream.
void AnnounceReadIHGIS(void) const
Tells the user that we are now reading the Intervention height GIS file.
Definition utils.cpp:571
void AnnounceReadInitialCoarseConsSedGIS(int const) const
Tells the user that we are now reading the initial coarse consolidated sediment depth GIS file.
Definition utils.cpp:709
static string strGetErrorText(int const)
Returns an error message given an error code.
Definition utils.cpp:2023
bool m_bSandConsSedSave
Save sand consolidated sediment raster GIS files?
Definition simulation.h:201
bool m_bSedimentInputEventSave
Save sediment inut data?
Definition simulation.h:405
double m_dThisIterMHWElev
This iteration's Mean High Water (MHW) elevation, calculated using a moving time window....
bool m_bHaveCoarseSediment
Does this simulation consider coarse-sized sediment?
Definition simulation.h:78
double m_dTimeStep
The length of an iteration (a timestep) in hours.
Definition simulation.h:690
static void AnnounceAllocateMemory(void)
Tells the user that we are now allocating memory.
Definition utils.cpp:508
bool m_bCliffCollapseDepositionTSSave
Save the cliff collapse deposition time series file?
Definition simulation.h:306
double dGetD50Sand(void) const
Returns the global d50 value for sand sediment.
Definition utils.cpp:152
void CalcMHWElevation(int const)
Calculate Mean High Water (MHW) elevation for a given duration (in days). This is a tidal datum deter...
Definition utils.cpp:3091
ofstream PlatformErosionTSStream
Shore platform erosion time series file output stream.
bool m_bDeepWaterWaveAngleAndHeightSave
Save deep water wave angle and wave height raster GIS files?
Definition simulation.h:126
double m_dMaxUserInputWaveHeight
Maximum deep water wave height.
Definition simulation.h:777
void AnnounceReadInitialFineConsSedGIS(int const) const
Tells the user that we are now reading the initial fine consolidated sediment depth GIS file.
Definition utils.cpp:683
bool m_bBeachProtectionSave
Save beach protection raster GIS files>
Definition simulation.h:138
ofstream CliffNotchElevTSStream
Cliff notch elevation time series file output stream.
static string strDispTime(double const, bool const, bool const)
strDispTime returns a string formatted as h:mm:ss, given a parameter in seconds, with rounding and fr...
Definition utils.cpp:1682
bool m_bFineConsSedSave
Save fine consolidated sediment raster GIS files?
Definition simulation.h:198
bool m_bShadowDowndriftBoundarySave
Save wave shadow downdrift boundary vector GIS files?
Definition simulation.h:291
bool m_bCliffNotchElevTSSave
Save the cliff notch elevation time series file?
Definition simulation.h:330
string m_strInitialLandformFile
Name of initial landform file.
string m_strInterventionHeightFile
Name of intervention height file.
bool m_bBeachSedimentChangeNetTSSave
Save the beach (unconsolidated sediment) net change time series file?
Definition simulation.h:318
bool m_bCoarseConsSedSave
Save coarse consolidated sediment raster GIS files?
Definition simulation.h:204
bool m_bSeaAreaTSSave
Save the sea area time series file?
Definition simulation.h:294
double dGetThisIterSWL(void) const
Returns this timestep's SWL.
Definition utils.cpp:96
void CalcProcessStats(void)
This calculates and displays process statistics.
Definition utils.cpp:1796
double m_dD50Fine
The D50 for fine sediment.
Definition simulation.h:786
bool m_bBeachMaskSave
Save beach mask raster GIS files?
Definition simulation.h:237
bool bOpenLogFile(void)
Opens the log file.
Definition utils.cpp:471
static void AppendEnsureNoGap(vector< CGeom2DIPoint > *, CGeom2DIPoint const *)
Appends a CGeom2DIPoint to a vector<CGeom2DIPoint>, making sure that the new end point touches the pr...
Definition utils.cpp:2640
unsigned long m_ulIter
The number of the current iteration (time step)
Definition simulation.h:609
void AnnounceLicence(void)
Tells the user about the licence.
Definition utils.cpp:355
bool m_bAvgSuspSedSave
Save average suspended sediment raster GIS files?
Definition simulation.h:186
vector< string > m_VstrInitialCoarseConsSedimentFile
The name of the initial coarse-sized consolidated sediment GIS file.
double m_dSimDuration
Duration of simulation, in hours.
Definition simulation.h:687
bool m_bTalusSave
Save talus depth?
Definition simulation.h:90
ofstream FloodSetupSurgeTSStream
Flood setup surge time series file output stream.
bool bTimeToQuit(void)
Checks to see if the simulation has gone on too long, amongst other things.
Definition utils.cpp:1446
bool bIsInterventionCell(int const, int const) const
Returns true if the cell is an intervention.
Definition utils.cpp:3066
void AnnounceProgress(void)
Displays information regarding the progress of the simulation.
Definition utils.cpp:1761
double m_dAllCellsDeepWaterWavePeriod
Deep water wave period for all sea cells.
Definition simulation.h:774
void AnnounceReadLGIS(void) const
Tells the user that we are now reading the Landscape category GIS file.
Definition utils.cpp:541
static void AnnounceReadVectorFiles(void)
Now reading vector GIS files.
Definition utils.cpp:533
double m_dDepthOfClosure
Depth of closure (in m) TODO 007 can be calculated using Hallermeier, R.J. (1978) or Birkemeier (1985...
Definition simulation.h:831
static void CalcDeanProfile(vector< double > *, double const, double const, double const, bool const, int const, double const)
Calculates a Dean equilibrium profile h(y) = A * y^(2/3) where h(y) is the distance below the highest...
Definition utils.cpp:2678
double m_dThisIterDiffTotWaterLevel
TODO 007 Finish surge and runup stuff.
Definition simulation.h:741
ofstream FineSedSuspensionTSStream
Fine sediment in suspension time series file output stream.
ofstream FloodSetupSurgeRunupTSStream
Flood setup surge runup time series file output stream.
void AnnounceReadTideData(void) const
Now reading tide data file.
Definition utils.cpp:722
double m_dClkLast
Last value returned by clock()
Definition simulation.h:705
double m_dThisIterMeanSWL
The mean still water level for this timestep (does not include tidal changes, but includes any long-t...
Definition simulation.h:729
bool m_bCliffCollapseErosionTSSave
Save the cliff collapse erosion time series file?
Definition simulation.h:303
bool m_bPotentialPlatformErosionSave
Save potential shore platform erosion raster GIS files?
Definition simulation.h:141
ofstream BeachErosionTSStream
Beach sediment erosion time series file output stream.
void AnnounceReadInitialCoarseUnconsSedGIS(int const) const
Tells the user that we are now reading the initial coarse unconsolidated sediment depth GIS file.
Definition utils.cpp:670
int nHandleCommandLineParams(int, char const *[])
Handles command-line parameters.
Definition utils.cpp:168
ofstream OutStream
The main output file stream.
double m_dDurationUnitsMult
Multiplier for duration units, to convert to hours.
Definition simulation.h:654
unsigned long m_ulTotTimestep
The target number of iterations.
Definition simulation.h:612
static vector< string > * VstrSplit(string const *, char const, vector< string > *)
From http://stackoverflow.com/questions/236129/split-a-string-in-c They implement (approximately) Pyt...
Definition utils.cpp:2580
bool m_bSedimentInputThisIter
Do we have a sediment input event this iteration?
Definition simulation.h:408
bool m_bCliffNotchSave
Save cliff notch incision depth vector GIS files?
Definition simulation.h:282
bool m_bWaveAngleSave
Save wave angle raster GIS files?
Definition simulation.h:114
This file contains global definitions for CoastalME.
string const TIME_SERIES_CLIFF_COLLAPSE_DEPOSITION_CODE
Definition cme.h:1133
string const READING_UNCONS_SAND_SEDIMENT_FILE
Definition cme.h:774
string const TIME_SERIES_SUSPENDED_SEDIMENT_CODE
Definition cme.h:1149
char const SLASH
Definition cme.h:356
string const RASTER_POTENTIAL_PLATFORM_EROSION_MASK_CODE
Definition cme.h:911
string const USAGE3
Definition cme.h:758
int const RTN_ERR_READING_SEDIMENT_INPUT_EVENT
Definition cme.h:647
int const RTN_ERR_POINT_NOT_FOUND_IN_MULTILINE_DIFFERENT_COASTS
Definition cme.h:663
string const TIME_SERIES_PLATFORM_EROSION_CODE
Definition cme.h:1145
int const RTN_ERR_NO_TOP_LAYER
Definition cme.h:629
string const DISCLAIMER4
Definition cme.h:747
string const RASTER_COARSE_CONS_CODE
Definition cme.h:876
string const VECTOR_POLYGON_NODE_CODE
Definition cme.h:1080
int const LF_INTERVENTION_STRUCT
Definition cme.h:442
string const COPYRIGHT
Definition cme.h:742
string const USAGE1
Definition cme.h:756
string const TIME_SERIES_FLOOD_SETUP_SURGE_RUNUP_CODE
Definition cme.h:1143
string const READING_VECTOR_FILES
Definition cme.h:779
string const READING_CONS_FINE_SEDIMENT_FILE
Definition cme.h:776
int const RTN_ERR_DEMFILE
Definition cme.h:598
string const READING_BASEMENT
Definition cme.h:767
string const RASTER_ACTIVE_ZONE_CODE
Definition cme.h:838
int const RTN_HELP_ONLY
Definition cme.h:586
int const RTN_ERR_COAST_CANT_FIND_EDGE_CELL
Definition cme.h:641
int const RTN_ERR_CSHORE_FILE_INPUT
Definition cme.h:637
string const RASTER_SAND_CONS_CODE
Definition cme.h:914
string const USAGE6
Definition cme.h:761
string const TIME_SERIES_FLOOD_SETUP_SURGE_CODE
Definition cme.h:1141
int const RTN_ERR_MEMALLOC
Definition cme.h:601
string const DISCLAIMER5
Definition cme.h:748
string const TIME_SERIES_CLIFF_NOTCH_ELEV_CODE
Definition cme.h:1139
int const RTN_ERR_SCAPE_SHAPE_FUNCTION_FILE
Definition cme.h:593
int const RTN_CHECK_ONLY
Definition cme.h:587
string const ERR
Definition cme.h:805
int const RTN_ERR_WAVESTATION_LOCATION
Definition cme.h:650
int const RTN_ERR_LOGFILE
Definition cme.h:595
string const RASTER_COAST_NORMAL_CODE
Definition cme.h:882
string const RASTER_AVG_SUSP_SED_CODE
Definition cme.h:847
string const TIME_SERIES_CLIFF_NOTCH_ELEV_NAME
Definition cme.h:1140
string const RASTER_COAST_CODE
Definition cme.h:880
int const RTN_ERR_NO_COAST
Definition cme.h:618
int const RTN_ERR_SHADOW_ZONE_FLOOD_START_POINT
Definition cme.h:635
string const RASTER_SEDIMENT_INPUT_EVENT_CODE
Definition cme.h:920
string const VECTOR_WAVE_ENERGY_SINCE_COLLAPSE_CODE
Definition cme.h:1091
string const USAGE4
Definition cme.h:759
string const RASTER_WAVE_ORIENTATION_CODE
Definition cme.h:968
int const RTN_ERR_EDGE_OF_GRID
Definition cme.h:624
string const ABOUT
Definition cme.h:751
string const READING_CONS_SAND_SEDIMENT_FILE
Definition cme.h:777
int const RTN_ERR_GRIDCREATE
Definition cme.h:640
int const RTN_ERR_PROFILE_WRITE
Definition cme.h:619
int const RTN_ERR_RASTER_GIS_OUT_FORMAT
Definition cme.h:602
string const TIME_SERIES_BEACH_EROSION_NAME
Definition cme.h:1132
int const RTN_ERR_LANDFORM_TO_GRID
Definition cme.h:628
int const RTN_ERR_RASTER_FILE_WRITE
Definition cme.h:605
int const LF_INTERVENTION_NON_STRUCT
Definition cme.h:443
string const INITIALIZING_NOTICE
Definition cme.h:764
string const RASTER_COARSE_UNCONS_CODE
Definition cme.h:878
int const RTN_ERR_BADPARAM
Definition cme.h:589
string const READING_RASTER_FILES
Definition cme.h:768
string const USAGE2
Definition cme.h:757
char const PATH_SEPARATOR
Definition cme.h:353
int const RTN_ERR_SHADOW_ZONE_FLOOD_FILL_NOGRID
Definition cme.h:634
string const VECTOR_INVALID_NORMALS_CODE
Definition cme.h:1072
int const RTN_ERR_TOO_LONG_TRACING_COAST
Definition cme.h:661
string const VECTOR_CLIFF_NOTCH_ACTIVE_CODE
Definition cme.h:1052
string const RASTER_BASEMENT_ELEVATION_CODE
Definition cme.h:853
string const RASTER_WAVE_HEIGHT_CODE
Definition cme.h:966
string const RASTER_INTERVENTION_CLASS_CODE
Definition cme.h:894
string const TIME_SERIES_SWL_NAME
Definition cme.h:1152
int const RTN_ERR_IGNORING_COAST
Definition cme.h:660
string const EMAIL_ERROR
Definition cme.h:796
string const RASTER_POTENTIAL_PLATFORM_EROSION_CODE
Definition cme.h:910
int const RTN_ERR_WAVE_INTERPOLATION_LOOKUP
Definition cme.h:639
string const RASTER_POTENTIAL_BEACH_EROSION_CODE
Definition cme.h:908
string const READING_CONS_COARSE_SEDIMENT_FILE
Definition cme.h:778
int const RTN_ERR_CELL_NOT_FOUND_IN_HIT_PROFILE
Definition cme.h:664
string const READING_TIDE_DATA_FILE
Definition cme.h:784
int const RTN_ERR_RASTER_FILE_READ
Definition cme.h:599
string const VECTOR_MEAN_WAVE_ENERGY_CODE
Definition cme.h:1074
int const TIME_UNKNOWN
Definition cme.h:422
int const RTN_ERR_CELL_IN_POLY_BUT_NO_POLY_COAST
Definition cme.h:665
string const READING_SCAPE_SHAPE_FUNCTION_FILE
Definition cme.h:783
int const RTN_ERR_CSHORE_ERROR
Definition cme.h:642
string const TIME_SERIES_BEACH_DEPOSITION_NAME
Definition cme.h:1130
string const READING_INTERVENTION_CLASS_FILE
Definition cme.h:770
string const DISCLAIMER3
Definition cme.h:746
string const READING_UNCONS_COARSE_SEDIMENT_FILE
Definition cme.h:775
int const TIME_HOURS
Definition cme.h:423
string const READING_DEEP_WATER_WAVE_FILE
Definition cme.h:780
string const CSVEXT
Definition cme.h:831
int const RTN_ERR_BOUNDING_BOX
Definition cme.h:646
int const RTN_ERR_NO_SEAWARD_END_OF_PROFILE_DOWNCOAST_BEACH_DEPOSITION
Definition cme.h:627
string const TIME_SERIES_CLIFF_COLLAPSE_NET_CODE
Definition cme.h:1137
int const RTN_ERR_OPEN_DEEP_WATER_WAVE_DATA
Definition cme.h:644
int const RTN_ERR_RUNDATA
Definition cme.h:592
int const RTN_ERR_SEDIMENT_INPUT_EVENT_LOCATION
Definition cme.h:649
string const RASTER_TOTAL_ACTUAL_BEACH_EROSION_CODE
Definition cme.h:943
string const VECTOR_NORMALS_CODE
Definition cme.h:1076
int const CLOCK_CHECK_ITERATION
Definition cme.h:371
string const RASTER_BEACH_DEPOSITION_CODE
Definition cme.h:855
string const FINAL_OUTPUT
Definition cme.h:790
string const RASTER_TOTAL_BEACH_DEPOSITION_CODE
Definition cme.h:947
string const USAGE
Definition cme.h:755
T tMax(T a, T b)
Definition cme.h:1162
int const RTN_ERR_GRID_TO_LINE
Definition cme.h:617
string const SIMULATING
Definition cme.h:789
int const NUM_DAYS_FOR_MEAN_HIGH_WATER_CALC
Definition cme.h:696
string const TIME_SERIES_BEACH_CHANGE_NET_NAME
Definition cme.h:1128
int const RTN_ERR_NO_ADJACENT_POLYGON
Definition cme.h:630
string const USAGE5
Definition cme.h:760
string const DISCLAIMER1
Definition cme.h:744
string const VECTOR_DEEP_WATER_WAVE_ANGLE_AND_HEIGHT_CODE
Definition cme.h:1060
int const RTN_ERR_PROFILE_SPACING
Definition cme.h:609
int const RTN_ERR_TSFILE
Definition cme.h:597
string const READING_LANDFORM_FILE
Definition cme.h:769
int const RTN_ERR_READING_CSHORE_FILE_OUTPUT
Definition cme.h:638
string const RUN_NOTICE
Definition cme.h:788
string const RASTER_BEACH_PROTECTION_CODE
Definition cme.h:859
string const RASTER_TOTAL_POTENTIAL_PLATFORM_EROSION_CODE
Definition cme.h:961
string const VECTOR_SHADOW_ZONE_BOUNDARY_CODE
Definition cme.h:1084
int const RTN_ERR_CLIFF_NOT_IN_POLYGON
Definition cme.h:652
int const TIME_MONTHS
Definition cme.h:425
string const TIME_SERIES_CLIFF_COLLAPSE_EROSION_CODE
Definition cme.h:1135
string const PROGRAM_NAME
Definition cme.h:738
int const RTN_ERR_VECTOR_FILE_READ
Definition cme.h:600
string const RASTER_BEACH_MASK_CODE
Definition cme.h:857
int const RTN_ERR_NOSEACELLS
Definition cme.h:616
int const RTN_ERR_VECTOR_GIS_OUT_FORMAT
Definition cme.h:603
string const RASTER_AVG_WAVE_HEIGHT_CODE
Definition cme.h:849
string const READING_INTERVENTION_HEIGHT_FILE
Definition cme.h:771
int const RTN_USER_ABORT
Definition cme.h:588
string const TIME_SERIES_BEACH_EROSION_CODE
Definition cme.h:1131
int const RTN_ERR_NO_START_FINISH_POINTS_TRACING_COAST
Definition cme.h:655
int const RTN_ERR_TRACING_FLOOD
Definition cme.h:654
string const RASTER_TOTAL_POTENTIAL_BEACH_EROSION_CODE
Definition cme.h:959
int const RTN_ERR_CMEDIR
Definition cme.h:591
string const RASTER_AVG_SEA_DEPTH_CODE
Definition cme.h:845
int const RTN_ERR_NO_PROFILES_2
Definition cme.h:615
int const RTN_ERR_PROFILE_ENDPOINT_IS_INLAND
Definition cme.h:611
string const RASTER_SAND_UNCONS_CODE
Definition cme.h:916
string const RUN_END_NOTICE
Definition cme.h:792
string const TIME_SERIES_SWL_CODE
Definition cme.h:1151
string const TIME_SERIES_PLATFORM_EROSION_NAME
Definition cme.h:1146
int const RTN_ERR_INI
Definition cme.h:590
int const RTN_ERR_BAD_MULTILINE
Definition cme.h:631
string const READING_SED_INPUT_EVENT_FILE
Definition cme.h:781
int const RTN_OK
Definition cme.h:585
int const RTN_ERR_COAST_TOO_SMALL
Definition cme.h:659
int const RTN_ERR_TEXT_FILE_WRITE
Definition cme.h:604
string const RASTER_LANDFORM_CODE
Definition cme.h:900
int const RTN_ERR_VECTOR_FILE_WRITE
Definition cme.h:606
string const TIME_SERIES_CLIFF_COLLAPSE_NET_NAME
Definition cme.h:1138
string const RASTER_TOTAL_ACTUAL_PLATFORM_EROSION_CODE
Definition cme.h:945
string const DISCLAIMER6
Definition cme.h:749
int const RTN_ERR_READING_DEEP_WATER_WAVE_DATA
Definition cme.h:645
string const RASTER_ACTUAL_PLATFORM_EROSION_CODE
Definition cme.h:842
string const VECTOR_BREAKING_WAVE_HEIGHT_CODE
Definition cme.h:1048
int const RTN_ERR_CELL_MARKED_PROFILE_COAST_BUT_NOT_PROFILE
Definition cme.h:653
string const TIME_SERIES_CLIFF_COLLAPSE_EROSION_NAME
Definition cme.h:1136
int const RTN_ERR_NO_PROFILES_1
Definition cme.h:614
unsigned long const SEDIMENT_INPUT_EVENT_ERROR
Definition cme.h:704
int const TIME_YEARS
Definition cme.h:426
int const RTN_ERR_TIDEDATAFILE
Definition cme.h:594
string const RASTER_SLOPE_OF_CONSOLIDATED_SEDIMENT_CODE
Definition cme.h:935
int const TIME_DAYS
Definition cme.h:424
string const THANKS
Definition cme.h:752
string const RASTER_SUSP_SED_CODE
Definition cme.h:937
int const RTN_ERR_CANNOT_INSERT_POINT
Definition cme.h:632
int const RTN_ERR_NO_VALID_COAST
Definition cme.h:656
string const VECTOR_COAST_CURVATURE_CODE
Definition cme.h:1055
int const RTN_ERR_CLIFF_NOTCH
Definition cme.h:621
string const TIME_SERIES_SEA_AREA_NAME
Definition cme.h:1148
int const RTN_ERR_UNKNOWN
Definition cme.h:667
double const DEAN_POWER
Definition cme.h:719
int const RTN_ERR_ZERO_LENGTH_COAST
Definition cme.h:658
string const INITIALIZING_FINAL
Definition cme.h:787
string const NOTE
Definition cme.h:807
string const READING_SUSPENDED_SEDIMENT_FILE
Definition cme.h:772
int const RTN_ERR_CANNOT_ASSIGN_COASTAL_LANDFORM
Definition cme.h:633
string const READING_FLOOD_LOCATION
Definition cme.h:782
int const RTN_ERR_REPEATING_WHEN_TRACING_COAST
Definition cme.h:657
string const RASTER_SEA_DEPTH_CODE
Definition cme.h:918
int const RTN_ERR_OUTFILE
Definition cme.h:596
string const ALLOCATE_MEMORY
Definition cme.h:785
string const TIME_SERIES_SUSPENDED_SEDIMENT_NAME
Definition cme.h:1150
int const RTN_ERR_NO_SOLUTION_FOR_ENDPOINT
Definition cme.h:612
string const TIME_SERIES_CLIFF_COLLAPSE_DEPOSITION_NAME
Definition cme.h:1134
string const RASTER_FINE_CONS_CODE
Definition cme.h:890
string const LINE
Definition cme.h:743
string const VECTOR_POLYGON_BOUNDARY_CODE
Definition cme.h:1078
string const DISCLAIMER2
Definition cme.h:745
string const RASTER_FINE_UNCONS_CODE
Definition cme.h:892
string const VECTOR_DOWNDRIFT_ZONE_BOUNDARY_CODE
Definition cme.h:1062
string const RASTER_SEDIMENT_TOP_CODE
Definition cme.h:922
int const RTN_ERR_TIME_UNITS
Definition cme.h:620
int const BUF_SIZE
Definition cme.h:369
int const RTN_ERR_CELL_NOT_FOUND_IN_HIT_PROFILE_DIFFERENT_COASTS
Definition cme.h:662
string const VECTOR_WAVE_ANGLE_AND_HEIGHT_CODE
Definition cme.h:1089
string const SEND_EMAIL
Definition cme.h:791
int const RTN_ERR_CLIFF_TALUS_TO_UNCONS
Definition cme.h:666
string const RASTER_TOP_ELEVATION_INC_SEA_CODE
Definition cme.h:941
T tAbs(T a)
Definition cme.h:1187
int const RTN_ERR_SEDIMENT_INPUT_EVENT
Definition cme.h:648
int const RTN_ERR_CSHORE_EMPTY_PROFILE
Definition cme.h:636
string const VECTOR_AVG_WAVE_ANGLE_AND_HEIGHT_CODE
Definition cme.h:1046
string const TIME_SERIES_BEACH_CHANGE_NET_CODE
Definition cme.h:1127
string const RASTER_INTERVENTION_HEIGHT_CODE
Definition cme.h:896
string const TIME_SERIES_BEACH_DEPOSITION_CODE
Definition cme.h:1129
int const RTN_ERR_NO_SEAWARD_END_OF_PROFILE_BEACH_EROSION
Definition cme.h:625
string const READING_UNCONS_FINE_SEDIMENT_FILE
Definition cme.h:773
string const START_NOTICE
Definition cme.h:763
string const ADD_LAYERS
Definition cme.h:786
string const RASTER_POLYGON_CODE
Definition cme.h:902
string const RASTER_ACTUAL_BEACH_EROSION_CODE
Definition cme.h:840
string const RASTER_INUNDATION_MASK_CODE
Definition cme.h:898
string const VECTOR_COAST_CODE
Definition cme.h:1054
string const TIME_SERIES_SEA_AREA_CODE
Definition cme.h:1147
int const RTN_ERR_NO_SEAWARD_END_OF_PROFILE_UPCOAST_BEACH_DEPOSITION
Definition cme.h:626
int const RTN_ERR_LINETOGRID
Definition cme.h:608
string const RASTER_TALUS_CODE
Definition cme.h:939
string const GDAL_DRIVERS
Definition cme.h:753
char const DASH
Definition cme.h:352
string const ERROR_NOTICE
Definition cme.h:795
int const RTN_ERR_CLIFF_CANNOT_DEPOSIT_ALL
Definition cme.h:622
int const RTN_ERR_NO_CELL_UNDER_COASTLINE
Definition cme.h:643
int const RTN_ERR_TIMESERIES_FILE_WRITE
Definition cme.h:607
char const SPACE
Definition cme.h:357
Contains CRWCoast definitions.
Contains CSimulation definitions.
double dRound(double const d)
Correctly rounds doubles.
bool bIsStringValidInt(string &str)
Checks to see if a string can be read as a valid integer, from https://stackoverflow....
int nRound(double const d)
Correctly rounds doubles, returns an int.