Checking for invalid switch selections?
Opened this issue · 2 comments
In ERSEM, switches are often used to select which bits of code are actually run. For example, when computing oxygen saturation concentrations, there is a choice between "legacy ERSEM" and "Weiss 1970". The former can be selected using a value of 1 and the latter a value of 2 according to the module documentation. If a value other than 1 or 2 is specified, it would be reasonable to expect the model to halt with an error message stating that an incorrect selection has been made. In-fact, this doesn't happen. Rather, nearly all this switches are implemented with if - elseif - else syntax, with the else catching the final option. However, the user has no way of knowing this, and it would be better if ERSEM did indeed check for invalid configuration options. It looks like FABM includes a procedure for invoking fatal errors. Is there an overhead/issue with invoking this when selecting between cases? Even if there is, I figure one could implement a workaround (e.g. only perform the check during module initialisation).
Indeed, e.g. carbonate_chemistry raises an error at initialization, if alkalinity type is not within correct range:
if (self%iswtalk<1.or.self%iswtalk>5) call self%fatal_error('initialize','iswtalk takes values between 1 and 5 only'). Similar should be applied elsewhere. Are you happy to look at this in further detail?
FABM v1.5 will add an options
argument to the integer version of get_parameter
. That provides a mechanism to annotate each allowed option value with a short and long name, and also gives FABM the information it needs to validate that the user-provided value is acceptable. It will work similar to the GOTM's setting manager (in fact, underneath it will share the same infrastructure).
Should you adopt this syntax, there is no need anymore to check option values with the ERSEM code itself. However, the code would then require FABM >= 1.5.