Helper routine to get variables. This is useful because a lot of the same code is executed for the different types of variables.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(CFG_t), | intent(inout) | :: | cfg | |||
| character(len=*), | intent(in) | :: | var_name | |||
| integer, | intent(in) | :: | var_type | |||
| integer, | intent(in) | :: | var_size | |||
| integer, | intent(out) | :: | ix |
subroutine prepare_get_var(cfg, var_name, var_type, var_size, ix) type(CFG_t), intent(inout) :: cfg character(len=*), intent(in) :: var_name integer, intent(in) :: var_type, var_size integer, intent(out) :: ix character(len=CFG_string_len) :: err_string call get_var_index(cfg, var_name, ix) if (ix == -1) then call handle_error("CFG_get: variable ["//var_name//"] not found") else if (cfg%vars(ix)%var_type /= var_type) then write(err_string, fmt="(A)") "CFG_get: variable [" & // var_name // "] has different type (" // & trim(CFG_type_names(cfg%vars(ix)%var_type)) // & ") than requested (" // trim(CFG_type_names(var_type)) // ")" call handle_error(err_string) else if (cfg%vars(ix)%var_size /= var_size) then write(err_string, fmt="(A,I0,A,I0,A)") "CFG_get: variable [" // & var_name // "] has different size (", cfg%vars(ix)%var_size,& ") than requested (", var_size, ")" call handle_error(err_string) else ! All good, variable will be used cfg%vars(ix)%used = .true. end if end subroutine prepare_get_var