Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/bmi_cfe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,8 @@ int read_init_config_cfe(const char* config_file, cfe_state_struct* model)
else {
model->soil_reservoir.is_aet_rootzone = FALSE;
model->soil_reservoir.n_soil_layers = 1;
model->soil_reservoir.soil_layer_depths_m = NULL;
model->soil_reservoir.delta_soil_layer_depth_m = NULL;
}

/*--------------------END OF ROOT ZONE ADJUSTED AET DEVELOPMENT -rlm ------------------------------*/
Expand Down Expand Up @@ -1484,6 +1486,11 @@ static int Initialize (Bmi *self, const char *file)
cfe_bmi_data_ptr->gw_reservoir.coeff_secondary = 0.0; // 0.0 means that secondary outlet is not applied
cfe_bmi_data_ptr->gw_reservoir.exponent_secondary = 1.0; // linear

// Not used in gw reservoir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment, nothing to change. We should really move this and a lot of the code that directly precedes this into the init_soil_reservoir function that is called right after this. The initialization code is littered all over the place.

cfe_bmi_data_ptr->gw_reservoir.smc_profile = NULL;
cfe_bmi_data_ptr->gw_reservoir.soil_layer_depths_m = NULL;
cfe_bmi_data_ptr->gw_reservoir.delta_soil_layer_depth_m = NULL;

// Initialize soil conceptual reservoirs
//LKC Remove alpha_fc
init_soil_reservoir(cfe_bmi_data_ptr);
Expand Down Expand Up @@ -1626,6 +1633,9 @@ static int Finalize (Bmi *self)
free(model->forcing_data_precip_kg_per_m2);
if( model->forcing_data_time != NULL )
free(model->forcing_data_time);
if( model->forcing_file != NULL ){
free(model->forcing_file);
}

if( model->giuh_ordinates != NULL )
free(model->giuh_ordinates);
Expand All @@ -1636,6 +1646,9 @@ static int Finalize (Bmi *self)
if( model->flux_Qout_m != NULL )
free(model->flux_Qout_m);

if( model->soil_reservoir.smc_profile != NULL )
free(model->soil_reservoir.smc_profile);

/* xinanjiang_dev: changing name to the more general "direct runoff"
if( model->flux_Schaake_output_runoff_m != NULL )
free(model->flux_Schaake_output_runoff_m);*/
Expand Down Expand Up @@ -3026,6 +3039,15 @@ cfe_state_struct *new_bmi_cfe(void)
data = (cfe_state_struct *) malloc(sizeof(cfe_state_struct));
data->time_step_size = 3600;
data->time_step_fraction = 1.0;
// NJF Ensure that all "optional" pointers are initialized to NULL
// Should probabably ensure that *all* pointers are initialized to NULL
// but that would require some more significant refactoring...
data->soil_reservoir.smc_profile = NULL;
data->soil_reservoir.soil_layer_depths_m = NULL;
data->soil_reservoir.delta_soil_layer_depth_m = NULL;
data->nash_surface_params.nash_storage = NULL;
data->forcing_file = NULL;

data->forcing_data_precip_kg_per_m2 = NULL;
data->forcing_data_time = NULL;
data->giuh_ordinates = NULL;
Expand Down
Loading