SUEWS API Site
Documentation of SUEWS source code
Functions/Subroutines
suews_ctrl_error.f95 File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine errorhint (errh, problemfile, value, value2, valuei)
 

Function/Subroutine Documentation

◆ errorhint()

subroutine errorhint ( integer errh,
character(len=*) problemfile,
real(kind(1d0)) value,
real(kind(1d0)) value2,
integer valuei )

Definition at line 1 of file suews_ctrl_error.f95.

2 !errh -- Create a numbered code for the situation so get a unique message to help solve the problem
3 !ProblemFile -- Filename where the problem occurs/error message
4 !value -- Error value (real number with correct type)
5 !value2 -- Second error value (real number with correct type)
6 !valueI -- Error value (integer)
7 ! Last modified -----------------------------------------------------
8 ! MH 12 Apr 2017: Error code for stability added
9 ! HCW 17 Feb 2017: Write (serious) errors to problems.txt; write warnings to warnings.txt (program continues)
10 ! HCW 13 Dec 2016: Tidied up and improved error hints
11 ! HCW 25 May 2016: Added warning/error labels to distinguish serious errors (that stop program)
12 ! LJ 02 Oct 2014: addition of comments
13 ! sg 29 Jul 2014: close (500)
14 ! LJ 08 Feb 2013
15 !--------------------------------------------------------------------
16
17 USE data_in
19 ! USE WhereWhen
20
21 IMPLICIT NONE
22
23 REAL(KIND(1D0)) :: VALUE, value2
24
25 CHARACTER(len=*) :: ProblemFile ! Name of the problem file
26 CHARACTER(len=150) :: text1 ! Initialization of text
27 ! CHARACTER(len=20)::filename !file name for writting out error info
28 INTEGER :: errh, ValueI, ValueI2, ValueI3 ! v7,v8 initialised as false, HCW 28/10/2014
29 INTEGER, DIMENSION(80) :: ErrhCount = 0 ! Counts each time a error hint is called. Initialise to zero
30 ! INTEGER:: WhichFile ! Used to switch between 500 for error file, 501 for warnings file
31#ifdef wrf
32 CHARACTER(len=1024) :: message ! Used to pass through function wrf_debug() by Zhenkun Li, 10/08/2018
33#endif
34 CHARACTER(len=1024) :: Errmessage
35 CHARACTER(len=1024) :: StopMessage ! used to pass error message to statement; useful to supy_driver, TS 19 Feb 2019
36
37 ! TS 16 Jul 2018:
38 ! these LOGICAL values should NOT be initialised as is implied
39 ! which will cause cross-assignment in parallel mode and thus subsequent unintentional STOP
40 LOGICAL :: v1, v2, v3, v4, v5, v6, v7, v8, v9
41 LOGICAL :: flag_continue_on_error
42
43 text1 = 'unknown problem' ! Initialization of text
44 ! WhichFile = 0 ! Initialization of file code
45
46 ! Initialise returnTrue as false (HCW 29/10/2014)
47 ! - need to do this in Fortran as values assigned in declarations are not applied
48 ! on subsequent calling of the subroutine
49 flag_continue_on_error = .false.
50 ! Initialise v1-v8 as false
51 v1 = .false.
52 v2 = .false.
53 v3 = .false.
54 v4 = .false.
55 v5 = .false.
56 v6 = .false.
57 v7 = .false.
58 v8 = .false.
59 v9 = .false.
60
61 !CALL gen_ProblemsText(ProblemFile) !Call the subroutine that opens the problem.txt file !Moved below, HCW 17 Feb 2017
62
63 !The list of knows possible problems of the code:
64 ! text1 is the error message written to the ProblemFile.
65 ! v1 -v7 are different possibilities for what numbers will be written out
66 ! flag_continue_on_error is true if the model run can continue. (Comment modified by HCW 17/10/2014)
67 IF (errh == 1) THEN
68 text1 = 'Check value in SUEWS_SiteSelect.txt.'
69 v5 = .true.
70 ELSEIF (errh == 2) THEN
71 text1 = 'Cannot perform disaggregation.'
72 v6 = .true.
73 ELSEIF (errh == 3) THEN
74 text1 = 'Met forcing file should contain only 1 year of data.'
75 v1 = .true.
76 ELSEIF (errh == 4) THEN
77 text1 = 'Rainfall in original met forcing file exceeds intensity threshold.'
78 v2 = .true.
79 flag_continue_on_error = .true.
80 !5
81 ELSEIF (errh == 6) THEN
82 text1 = 'Value obtained exceeds permitted range, setting to +/-9999 in output file.'
83 v1 = .true.
84 flag_continue_on_error = .true.
85 ELSEIF (errh == 7) THEN
86 text1 = 'RA value obtained exceeds permitted range.'
87 v1 = .true.
88 flag_continue_on_error = .true.
89 ELSEIF (errh == 8) THEN
90 text1 = 'Check values in SUEWS_WithinGridWaterDist.txt.'
91 v1 = .true.
92 ELSEIF (errh == 9) THEN
93 text1 = 'Check ToRunoff and ToSoilStore values in SUEWS_WithinGridWaterDist.txt.'
94 v2 = .true.
95 ELSEIF (errh == 10) THEN
96 text1 = 'Check values in SUEWS_SiteSelect.txt.'
97 v1 = .true.
98 ELSEIF (errh == 11) THEN
99 text1 = 'File not found.'
100 v3 = .true.
101 ! 12
102 ELSEIF (errh == 13) THEN
103 text1 = 'Check met forcing file.'
104 v8 = .true.
105 ELSEIF (errh == 14) THEN
106 text1 = 'Inappropriate value calculated.'
107 v1 = .true.
108 ELSEIF (errh == 15) THEN
109 text1 = 'Check H_Bldgs, H_EveTr and H_DecTr in SUEWS_SiteSelect.txt'
110 v2 = .true.
111 flag_continue_on_error = .true.
112 ! 16
113 ELSEIF (errh == 17) THEN
114 text1 = 'Problem with (z-zd) and/or z0.'
115 v2 = .true.
116 ELSEIF (errh == 18) THEN
117 text1 = 'Check soil depth relative to soil moisture and capacity.'
118 v4 = .true.
119 ELSEIF (errh == 19) THEN
120 text1 = 'Caution - check range.'
121 v4 = .true.
122 flag_continue_on_error = .true.
123 ELSEIF (errh == 20) THEN
124 text1 = ' skip lines, ios_out.'
125 v5 = .true.
126 ELSEIF (errh == 21) THEN
127 text1 = 'Bad input for OHM/AnOHM storage heat flux calculation. Check qn, qn_Sn, qf for issues.'
128 v1 = .true.
129 ELSEIF (errh == 22) THEN
130 text1 = ' QH_observed, QE_observed, QH_choice: '
131 v4 = .true.
132 flag_continue_on_error = .true.
133 ELSEIF (errh == 23) THEN
134 text1 = 'CBL-sonde -need to increase size of izm:zmax,izm'
135 v5 = .true.
136 ELSEIF (errh == 24) THEN
137 text1 = 'CBL file problem - opening'
138 v8 = .true.
139 ELSEIF (errh == 25) THEN
140 text1 = 'CBL file problem -- reading sonde data, line:'
141 v3 = .true.
142 ELSEIF (errh == 26) THEN
143 text1 = 'Check that FileCode, FileInputPath and FileOutputPath are specified correctly in RunControl.nml.'
144 v8 = .true.
145 ELSEIF (errh == 27) THEN
146 text1 = 'Problems with Met data -forcing data: variable value, dectime'
147 v2 = .true. ! 2 real
148 ELSEIF (errh == 28) THEN
149 text1 = 'Processing in subroutine indicated has a problem, variables'
150 flag_continue_on_error = .true.
151 v3 = .true. ! 1 integer
152 ELSEIF (errh == 29) THEN
153 text1 = 'Processing in subroutine indicated has a problem, time, variables'
154 flag_continue_on_error = .true.
155 v7 = .true. ! 1 real, 2 integers
156 ELSEIF (errh == 30) THEN
157 text1 = 'Processing in subroutine indicated has a problem, time, variables'
158 ! returntrue=.TRUE.
159 v2 = .true. ! 2 real
160 ELSEIF (errh == 31) THEN
161 text1 = 'Processing in subroutine indicated has a problem, time, variables'
162 flag_continue_on_error = .true.
163 v1 = .true. ! 1 real
164 ELSEIF (errh == 32) THEN
165 text1 = 'Model applicable to local scale, z<z0d'
166 v2 = .true. ! 2 real
167 ELSEIF (errh == 33) THEN
168 text1 = 'Number of snow layers too large.'
169 v1 = .true. ! 1 real
170 ELSEIF (errh == 34) THEN
171 text1 = 'Air temperature > 55 C -- will keep running'
172 v1 = .true. ! 1 real
173 flag_continue_on_error = .true.
174 ELSEIF (errh == 35) THEN
175 text1 = 'Problems with Met data -forcing data: doy, dectime'
176 v2 = .true. ! 2 real
177 ELSEIF (errh == 36) THEN
178 text1 = 'Problem found in InitialConditions file!'
179 v8 = .true.
180 ELSEIF (errh == 37) THEN
181 text1 = 'Check inputs in InitialConditions file!'
182 flag_continue_on_error = .true.
183 v2 = .true. !2 real
184 ELSEIF (errh == 38) THEN
185 text1 = 'H=(qn*0.2)/(avdens*avcp)'
186 flag_continue_on_error = .true.
187 v1 = .true. !2 real
188 ELSEIF (errh == 39) THEN
189 text1 = 'Different value of TSTEP needed (300 s recommended). Resolution of forcing data must match TSTEP set in RunControl.'
190 v4 = .true. !2 real, 1 int
191 ELSEIF (errh == 40) THEN
192 text1 = 'SOLWEIG file problem - opening'
193 v8 = .true.
194 ELSEIF (errh == 41) THEN
195 text1 = ' addwaterbody= Error1-- but watersurf= Error 2'
196 v2 = .true. !2 real
197 ELSEIF (errh == 42) THEN
198 text1 = .OR..OR.'abs(rho_d)<0.001000abs(rho_v)<0.001000abs(rho_d+rho_v)<0.001000) rho_v,rho_d, T'
199 flag_continue_on_error = .true.
200 v4 = .true. !2 real, temperature as an integer
201 ELSEIF (errh == 43) THEN
202 text1 = 'Switching Years - will keep running'
203 flag_continue_on_error = .true.
204 v8 = .true.
205 ELSEIF (errh == 44) THEN
206 text1 = 'Initial File Name - will keep going'
207 flag_continue_on_error = .true.
208 v8 = .true.
209 ELSEIF (errh == 45) THEN
210 text1 = 'Pressure < 900 hPa, Loop Number'
211 flag_continue_on_error = .true.
212 v5 = .true.
213 ELSEIF (errh == 46) THEN
214 text1 = 'Pressure < 900 hPa'
215 flag_continue_on_error = .true.
216 v1 = .true.
217 ELSEIF (errh == 47) THEN
218 text1 = 'File missing'
219 !returntrue = .TRUE.
220 ELSEIF (errh == 48) THEN
221 text1 = 'Something wrong in the rows of the file'
222 !returntrue = .TRUE.
223 ELSEIF (errh == 49) THEN
224 text1 = 'Problems in saving to InitialConditionsYYYY.nml'
225 ELSEIF (errh == 50) THEN
226 text1 = 'Wrong number of lines read: nsurf, [-1 EOF; -2 EOR]'
227 v1 = .true.
228 ELSEIF (errh == 51) THEN
229 text1 = 'Problems in opening the file'
230 WRITE (*, *) problemfile
231 ELSEIF (errh == 52) THEN
232 text1 = 'Problems opening the output file.'
233 ELSEIF (errh == 53) THEN
234 text1 = .and..and.'AH_min=0Ah_slope=0T_Critic=0, AnthropHeatMethod='
235 flag_continue_on_error = .true.
236 v3 = .true.
237 ELSEIF (errh == 54) THEN
238 text1 = .and..and.'QF_A=0QF_B=0QF_C=0, AnthropHeatMethod='
239 flag_continue_on_error = .true.
240 v3 = .true.
241 ELSEIF (errh == 55) THEN
242 text1 = 'InputmetFormat='
243 flag_continue_on_error = .true.
244 v3 = .true.
245 ELSEIF (errh == 56) THEN
246 text1 = 'Check input files against manual (N.B. Case sensitive).'
247 v8 = .true.
248 ELSEIF (errh == 57) THEN
249 text1 = 'not found. Check input files.'
250 v1 = .true.
251 ELSEIF (errh == 58) THEN
252 text1 = 'File header not specified in model code.'
253 v8 = .true.
254 ELSEIF (errh == 59) THEN
255 text1 = 'not found. Check SUEWS_SiteSelect.txt.'
256 v6 = .true.
257 ELSEIF (errh == 60) THEN
258 text1 = 'non-unique code.'
259 v1 = .true.
260 ELSEIF (errh == 61) THEN
261 text1 = 'Check coefficients and drainage equation specified in input files.'
262 v4 = .true.
263 flag_continue_on_error = .true.
264 ELSEIF (errh == 62) THEN
265 text1 = 'Problem with soil moisture calculation.'
266 v5 = .true.
267 ELSEIF (errh == 63) THEN
268 text1 = 'Problem with calculation.'
269 v1 = .true.
270 ELSEIF (errh == 64) THEN
271 text1 = 'SUEWS cannot currently handle this many grids.'
272 v6 = .true.
273 ELSEIF (errh == 65) THEN
274 text1 = 'Negative gs calculated! Check suitability of parameters in SUEWS_Conductance.txt.'
275 flag_continue_on_error = .true.
276 v7 = .true. ! 1 real, 2 integers
277 ELSEIF (errh == 66) THEN
278 text1 = 'Different number of lines in ESTM forcing and Met forcing files.'
279 v6 = .true.
280 ELSEIF (errh == 67) THEN
281 text1 = 'ESTMClass1 automatically set to 100%.'
282 flag_continue_on_error = .true.
283 v1 = .true.
284 ELSEIF (errh == 68) THEN
285 text1 = 'Initial Bowen ratio automatically set to 1.'
286 flag_continue_on_error = .true.
287 v1 = .true.
288 ELSEIF (errh == 69) THEN
289 text1 = 'Setting QF_traff to zero. Check input data.'
290 flag_continue_on_error = .true.
291 v2 = .true.
292 ELSEIF (errh == 70) THEN
293 text1 = 'Specify profile values between 1 (night) and 2 (day).'
294 v8 = .true.
295 ELSEIF (errh == 71) THEN
296 text1 = 'Check input file SUEWS_Conductance.txt.'
297 v3 = .true.
298 ELSEIF (errh == 72) THEN
299 text1 = 'RunControl.nml: ResolutionFilesOut must be an integer multiple of TSTEP'
300 v6 = .true.
301 ELSEIF (errh == 73) THEN
302 text1 = 'Iteration loop stopped for too stable conditions.'
303 ! returnTrue=.TRUE.
304 v2 = .true.
305 ELSEIF (errh == 74) THEN
306 text1 = 'Iteration loop stopped for too unstable conditions.'
307 ! returnTrue=.TRUE.
308 v2 = .true.
309 ELSEIF (errh == 75) THEN
310 text1 = 'Invalid value for !'
311 ! returnTrue=.TRUE.
312 v2 = .true.
313 ELSEIF (errh == 76) THEN
314 text1 = 'erroneous T2 by RSL!'
315 flag_continue_on_error = .false.
316 v4 = .true.
317 ELSEIF (errh == 77) THEN
318 text1 = 'CFL failure in ESTM_ext!' &
319 //' dz/k should be < 0.1; ' &
320 //'current value dz/k for facet i of surf j in group k is '
321
322 flag_continue_on_error = .false.
323 v7 = .true.
324 END IF
325
326 errhcount(errh) = errhcount(errh) + 1 ! Increase error count by 1
327 ! PRINT*, 'returnTrue',returnTrue
328
329 !---------------------------------------------------------------------
330 !This part of the code determines how the error/warning message is written out
331 IF (v1) THEN ! 1 real
332 WRITE (errmessage, '(a,f9.4)') ' Value: ', VALUE
333 ELSEIF (v2) THEN ! 2 real
334 WRITE (errmessage, '(a,2f9.4)') ' Values: ', VALUE, value2
335 ELSEIF (v3) THEN ! 1 integer
336 WRITE (errmessage, '(a,i10)') ' Value: ', valuei
337 ELSEIF (v4) THEN ! 2 real, 1 integer
338 WRITE (errmessage, '(a,2f12.4,i10)') ' Values: ', VALUE, value2, valuei
339 ELSEIF (v5) THEN ! 1 real 1 integer
340 WRITE (errmessage, '(a,f9.4,i10)') ' Values: ', VALUE, valuei
341 ELSEIF (v6) THEN ! 2 integer
342 valuei2 = int(VALUE)
343 WRITE (errmessage, '(a,2i10)') ' Values: ', valuei, valuei2
344 ELSEIF (v7) THEN ! 1 real, 2 integer
345 valuei2 = int(value2)
346 WRITE (errmessage, '(a,f9.4,2i10)') ' Values: ', VALUE, valuei2, valuei
347 ELSEIF (v8) THEN
348 ! no error values
349 END IF
350
351 ! Write errors (that stop the program) to problems.txt; warnings to warnings.txt
352 IF (flag_continue_on_error) THEN
353 IF (suppresswarnings == 0) THEN
354#ifdef wrf
355 WRITE (message, *) 'Warning: ', trim(problemfile)
356 CALL wrf_debug(100, message)
357 WRITE (message, *) trim(text1)
358 CALL wrf_debug(100, message)
359 CALL wrf_debug(100, errmessage)
360 WRITE (message, '(a,i14)') ' Count: ', errhcount(errh)
361 CALL wrf_debug(100, message)
362#else
363 IF (warningchoice == 0) THEN
364 OPEN (501, file='warnings.txt')
365 WRITE (*, *) '>>> See warnings.txt for possible issues in the run <<<'
366 warningchoice = 1
367 ELSE
368 OPEN (501, file='warnings.txt', position="append")
369 END IF
370
371 !Writing of the warnings file
372 WRITE (501, *) 'Warning: ', trim(problemfile)
373
374 ! write warning info
375 WRITE (501, *) trim(text1)
376
377 ! write warning codes
378 WRITE (501, *) trim(errmessage)
379
380 WRITE (501, '(a,i14)') ' Count: ', errhcount(errh)
381 CLOSE (501)
382#endif
383 END IF
384
385 ELSE
386
387#ifdef wrf
388 WRITE (message, *) 'Problem: ', trim(problemfile)
389 CALL wrf_debug(100, message)
390 WRITE (message, *) 'ERROR! Program stopped: ', trim(text1)
391 CALL wrf_debug(100, message)
392 CALL wrf_debug(100, errmessage)
393 WRITE (message, '(i3)') errh
394 CALL wrf_debug(100, message)
395 WRITE (message, *) 'ERROR! SUEWS run stopped.'
396 CALL wrf_debug(100, message)
397 WRITE (message, *) 'fatal error in SUEWS:', trim(text1)
398 CALL wrf_error_fatal(message)
399#else
400 IF (errorchoice == 0) THEN
401 OPEN (500, file='problems.txt')
402 WRITE (*, *) '>>> See problems.txt for serious issues in the run <<<'
403 errorchoice = 1
404 ELSE
405 OPEN (500, file='problems.txt', position="append")
406 END IF
407
408 !Writing of the problem file
409 WRITE (500, *) 'Problem: ', trim(problemfile)
410
411 WRITE (500, *) 'ERROR! Program stopped: ', trim(text1)
412
413 ! write error codes
414 WRITE (500, *) trim(errmessage)
415
416 WRITE (500, '(i3)') errh !Add error code to problems.txt
417 WRITE (*, *) 'ERROR! SUEWS run stopped.' !Print message to screen if program stopped
418 CLOSE (500)
419
420 WRITE (*, *) 'problem: ', trim(problemfile)
421 WRITE (*, *) 'See problems.txt for more info.'
422 WRITE (stopmessage, *) 'fatal error in SUEWS:'//new_line('A')//trim(text1)
423 stop 'Fatal error in SUEWS!'
424
425#endif
426 END IF
427
integer suppresswarnings

References defaultnotused::errorchoice, data_in::suppresswarnings, and defaultnotused::warningchoice.

Referenced by resist_module::aerodynamicresistance(), anohm_module::anohm(), anemsn_module::anthropogenicemissions(), atmmoiststab_module::cal_atmmoist(), atmmoiststab_module::cal_stab(), waterdist_module::cal_water_storage(), bluews_module::cbl(), bluews_module::cbl_initial(), bluews_module::cbl_readinputdata(), codematchanthropogenic(), codematchbiogen(), codematchconductance(), codematchdist(), codematchestm(), codematchestm_class(), codematchirrigation(), codematchnonveg(), codematchohm(), codematchprof(), codematchsnow(), codematchsoil(), codematchveg(), codematchwater(), bluews_module::diff(), metdisagg::disagg_lin(), metdisagg::disaggp_amongn(), metdisagg::disaggp_amongnmult(), metdisagg::disaggregateestm(), metdisagg::disaggregatemet(), waterdist_module::drainage(), inputheadercheck(), meteo::lat_vap(), metread(), bluews_module::nbl(), ohm(), meteo::psyc_const(), meteo::qsatf(), meteo::sat_vap_press_x(), meteo::sat_vap_pressice(), skipheader(), narp_module::smithlambda(), bluews_module::sonde(), meteo::spec_heat_beer(), suews_driver::suews_cal_anthropogenicemission(), suews_driver::suews_cal_anthropogenicemission_dts(), resist_module::suews_cal_roughnessparameters(), resist_module::suews_cal_roughnessparameters_dts(), waterdist_module::suews_cal_soilstate(), waterdist_module::suews_cal_soilstate_dts(), estm_module::suews_getestmdata(), suews_driver::suews_init_qh(), resist_module::surfaceresistance(), and dailystate_module::update_dailystate_day().