Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings to support -Werror in Github CI #35

Merged
merged 6 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion make_and_run_read_forcings.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
gcc ./src/main_read_forcing.c ./src/pet.c ./src/bmi_pet.c -lm -o run_bmi_forcings_read
gcc -Werror ./src/main_read_forcing.c ./src/pet.c ./src/bmi_pet.c -lm -o run_bmi_forcings_read
./run_bmi_forcings_read ./configs/pet_config_unit_test1.txt
./run_bmi_forcings_read ./configs/pet_config_unit_test2.txt
./run_bmi_forcings_read ./configs/pet_config_unit_test3.txt
Expand Down
23 changes: 16 additions & 7 deletions src/bmi_pet.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,20 @@ Initialize (Bmi *self, const char *cfg_file)
char line_str[max_forcing_line_length + 1];
long year, month, day, hour, minute;
double dsec;
char* ret = NULL;
// First read the header line
fgets(line_str, max_forcing_line_length + 1, ffp);

ret = fgets(line_str, max_forcing_line_length + 1, ffp);
if (ret == NULL)
return BMI_FAILURE;

if (pet->bmi.verbose > 2)
printf("the number of time steps from the forcing file is: %8.6e \n", pet->bmi.num_timesteps);
printf("the number of time steps from the forcing file is: %8.6e \n", (double)pet->bmi.num_timesteps);

aorc_forcing_data_pet forcings;
for (int i = 0; i < pet->bmi.num_timesteps; i++) {
fgets(line_str, max_forcing_line_length + 1, ffp); // read in a line of AORC data.
ret = fgets(line_str, max_forcing_line_length + 1, ffp); // read in a line of AORC data.
if (ret == NULL)
return BMI_FAILURE;
parse_aorc_line_pet(line_str, &year, &month, &day, &hour, &minute, &dsec, &forcings);
pet->forcing_data_precip_kg_per_m2[i] = forcings.precip_kg_per_m2 * ((double)pet->bmi.time_step_size_s);
if (pet->bmi.verbose >4)
Expand Down Expand Up @@ -514,7 +519,7 @@ static int Get_current_time (Bmi *self, double * time)
{
Get_start_time(self, time);
if (((pet_model *) self->data)->bmi.verbose > 2){
printf("Current model time step: '%ld'\n", ((pet_model *) self->data)->bmi.current_time_step);
printf("Current model time step: '%8.6e'\n", ((pet_model *) self->data)->bmi.current_time_step);
}
*time += (((pet_model *) self->data)->bmi.current_step *
((pet_model *) self->data)->bmi.time_step_size_s);
Expand Down Expand Up @@ -602,13 +607,17 @@ int read_init_config_pet(pet_model* model, const char* config_file)//,
if (fp == NULL)
return BMI_FAILURE;

char* ret = NULL;

// TODO: document config file format (<param_key>=<param_val>, where array values are comma delim strings)

char config_line[max_config_line_length + 1];

for (int i = 0; i < config_line_count; i++) {
char *param_key, *param_value;
fgets(config_line, max_config_line_length + 1, fp);
ret = fgets(config_line, max_config_line_length + 1, fp);
if (ret == NULL)
return BMI_FAILURE;
char* config_line_ptr = config_line;
config_line_ptr = strsep(&config_line_ptr, "\n");
param_key = strsep(&config_line_ptr, "=");
Expand Down Expand Up @@ -768,7 +777,7 @@ int read_init_config_pet(pet_model* model, const char* config_file)//,
model->bmi.num_timesteps = strtod(param_value, NULL);
if(model->bmi.verbose >=2){
printf("num_timesteps from config file \n");
printf("%d\n", model->bmi.num_timesteps);
printf("%ld\n", model->bmi.num_timesteps);
}
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions test/main_unit_test_bmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ main(int argc, const char *argv[]){
{
status = model->get_value_ptr(model, var_name, (void**)(&var));
if (status == BMI_FAILURE)return BMI_FAILURE;
printf(" get value ptr: %f\n",var);
printf(" get value ptr: %p\n",var);
}
// Go ahead and test set_value_*() for last time step here
if (n == test_nstep){
Expand Down Expand Up @@ -346,7 +346,7 @@ main(int argc, const char *argv[]){
{
status = model->get_value_ptr(model, var_name, (void**)(&var));
if (status == BMI_FAILURE)return BMI_FAILURE;
printf(" get value ptr: %f\n",var);
printf(" get value ptr: %p\n",var);
}
// Go ahead and test set_value_*() for last time step here
if (n == test_nstep){
Expand Down
2 changes: 1 addition & 1 deletion test/make_and_run_bmi_unit_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
gcc ./main_unit_test_bmi.c ../src/bmi_pet.c ../src/pet.c -lm -o run_pet_bmi_test
gcc -Werror ./main_unit_test_bmi.c ../src/bmi_pet.c ../src/pet.c -lm -o run_pet_bmi_test
./run_pet_bmi_test ../configs/pet_config_bmi_unit_test.txt
#./run_pet_bmi_test ../configs/pet_config_cat_67.txt
Loading