Helper routine to store 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 | |||
| character(len=*), | intent(in) | :: | description | |||
| integer, | intent(out) | :: | ix |
Index of variable |
||
| logical, | intent(in), | optional | :: | dynamic_size |
subroutine prepare_store_var(cfg, var_name, var_type, var_size, description,& ix, dynamic_size) type(CFG_t), intent(inout) :: cfg character(len=*), intent(in) :: var_name, description integer, intent(in) :: var_type, var_size integer, intent(out) :: ix !< Index of variable logical, intent(in), optional :: dynamic_size ! Check if variable already exists call get_var_index(cfg, var_name, ix) if (ix == -1) then ! Create a new variable call ensure_free_storage(cfg) cfg%sorted = .false. ix = cfg%num_vars + 1 cfg%num_vars = cfg%num_vars + 1 cfg%vars(ix)%used = .false. cfg%vars(ix)%stored_data = "" else ! Only allowed when the variable is not yet created if (cfg%vars(ix)%var_type /= CFG_unknown_type) then call handle_error("prepare_store_var: variable [" // & & trim(var_name) // "] already exists") end if end if cfg%vars(ix)%var_name = var_name cfg%vars(ix)%description = description cfg%vars(ix)%var_type = var_type cfg%vars(ix)%var_size = var_size if (present(dynamic_size)) then cfg%vars(ix)%dynamic_size = dynamic_size else cfg%vars(ix)%dynamic_size = .false. end if select case (var_type) case (CFG_integer_type) allocate( cfg%vars(ix)%int_data(var_size) ) case (CFG_real_type) allocate( cfg%vars(ix)%real_data(var_size) ) case (CFG_string_type) allocate( cfg%vars(ix)%char_data(var_size) ) case (CFG_logic_type) allocate( cfg%vars(ix)%logic_data(var_size) ) end select end subroutine prepare_store_var