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