Description
Summary:
-
default
key -
optional
key - simplified error handling.
Detailed description:
In my code FiNeR usage looks to have a lot of boilerplate code and still no good error handling. Probably FiNeR can be improved some way to make the life of end users a bit easier. Now I have:
call fini%get(section_name='cylinder', option_name='rl_min',
& val=double, error=error)
rl_min = -1_dp
if (error==0) rl_min = double
call fini%get(section_name='cylinder', option_name='rl_max',
& val=double, error=error)
rl_max = -1_dp
if (error==0) rl_max = double
call fini%get(section_name='cylinder', option_name='rl_steps',
& val=num, error=error)
ndefp = 0
if (error==0) ndefp = num
call fini%get(section_name='cylinder', option_name='radius',
& val=double, error=error)
rsnm = -1_dp
if (error==0) rsnm = double
call fini%get(section_name='cylinder', option_name='alpha',
& val=double, error=error)
alpha = 0_dp
if (error==0) alpha = double
So, you can see a simple pattern: for every option in my INI file I use some default value, which I set before setting the one I get from FiNeR just to avoid the case of uninitialized variables. So it would be nice, if get() function had a default parameter, so I could reference to real argument only once and be sure that in case of any parsing error the variable would still be initialized with default value.
call fini%get(section_name='cylinder', option_name='rl_min',
& val=rl_min, default = -1_dp, error=error)
call fini%get(section_name='cylinder', option_name='rl_max',
& val=rl_max, default = -1_dp, error=error)
call fini%get(section_name='cylinder', option_name='rl_steps',
& val=ndefp, default = 0, error=error)
call fini%get(section_name='cylinder', option_name='radius',
& val=rsnm, default = -1_dp, error=error)
call fini%get(section_name='cylinder', option_name='alpha',
& val=alpha, default = 0_dp, error=error)
So, what about error handling? My code has no one at the moment to keep it maintainable. It would be nice if FiNeR can accumulate different types of error and just provide the report at the end. So at the end of calls to fini%get(...)
I would like to do something like
if (fini%get_number_of_errors(type='parse') > 0) then
fini%print_error_log(type='parse', unit=6)
stop 'Parse error'
end if
Finally, it would be nice to separate required and optional options in INI file. E.g. if I call
call fini%get(section_name='cylinder', option_name='rl_min',
& val=rl_min, default = -1_dp, optional=.true., error=error)
it should not count an error if there is no rl_min
option in cylinder
section. However, it should count an error, if there was such an option and FiNeR could not parse it to requested variable type.