Module for sentinel handling
We need a framework to check for uninitialized variables at run-time.
Scenario
Reading a namelist file, where required variable was left out.
Situations like these are typically handled by setting the respective variable to a sentinel value before reading the namelist. After reading the namelist, users can check whether the variable still holds the sentinel, which means, the variable was not present in the namelist.
Aim
Provide sentinal setters for all used variable kinds (i1
-i8
, sp
, dp
, qp
, spc
, dpc
, qpc
, character
).
sent = get_sentinel(value)
call set_sentinel(value)
check = check_sentinel(value)
! values
sentinel_i1 = -huge(1_i1)-1_i1 ! smallest possible value
sentinel_i2 = -huge(1_i2)-1_i2 ! smallest possible value
sentinel_i4 = -huge(1_i4)-1_i4 ! smallest possible value
sentinel_i8 = -huge(1_i8)-1_i8 ! smallest possible value
sentinel_sp = ieee_value(0._sp, ieee_quiet_nan) ! not a number
sentinel_dp = ieee_value(0._dp, ieee_quiet_nan) ! not a number
sentinel_qp = ieee_value(0._qp, ieee_quiet_nan) ! not a number
sentinel_spc = ieee_value(0._spc, ieee_quiet_nan) ! not a number
sentinel_dpc = ieee_value(0._dpc, ieee_quiet_nan) ! not a number
sentinel_qpc = ieee_value(0._qpc, ieee_quiet_nan) ! not a number
sentinel_char = achar(0) ! NULL character
Edited by Sebastian Müller