Skip to content

Commit

Permalink
catch if number of state variables gets too big
Browse files Browse the repository at this point in the history
Default value for nvars = -1 (rather than unset) in that state_var_type
  • Loading branch information
hkershaw-brown committed Feb 4, 2025
1 parent 120d83a commit a7bf0bf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion models/utilities/default_model_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module default_model_mod
MAX_STATE_VARIABLE_FIELDS_CLAMP

type :: state_var_type
integer :: nvars
integer :: nvars = -1
character(len=NF90_MAX_NAME), allocatable :: netcdf_var_names(:)
integer, allocatable :: qtys(:)
real(r8), allocatable :: clamp_values(:, :)
Expand Down Expand Up @@ -332,6 +332,11 @@ function parse_variables_clamp(vars_table) result(state_vars)
endif
enddo

if (state_vars%nvars >= MAX_STATE_VARIABLES -1) then
write(string1,*) 'nvars ', state_vars%nvars, ' >= MAX_STATE_VARIABLES-1', MAX_STATE_VARIABLES-1, 'increase MAX_STATE_VARIABLES'
call error_handler(E_ERR, string1, source)
endif

! Allocate the arrays in the var derived type
allocate(state_vars%netcdf_var_names(state_vars%nvars), state_vars%qtys(state_vars%nvars), state_vars%clamp_values(state_vars%nvars, 2), state_vars%updates(state_vars%nvars))

Expand Down Expand Up @@ -412,6 +417,11 @@ function parse_variables(vars_table) result(state_vars)
endif
enddo

if (state_vars%nvars >= MAX_STATE_VARIABLES -1) then
write(string1,*) 'nvars ', state_vars%nvars, ' >= MAX_STATE_VARIABLES-1', MAX_STATE_VARIABLES-1, 'increase MAX_STATE_VARIABLES'
call error_handler(E_ERR, string1, source)
endif

! Allocate the arrays in the var derived type
allocate(state_vars%netcdf_var_names(state_vars%nvars), state_vars%qtys(state_vars%nvars), state_vars%updates(state_vars%nvars))

Expand Down

0 comments on commit a7bf0bf

Please sign in to comment.