From 72a2d4d8c339c8a5d4ba0b439ae0ee9714ae4223 Mon Sep 17 00:00:00 2001 From: Joe Hamman Date: Fri, 24 Feb 2017 10:27:17 -0800 Subject: [PATCH 1/4] add timers to vic_force and vic_write --- vic/drivers/image/src/vic_image.c | 7 +++++++ vic/drivers/shared_all/include/vic_driver_shared_all.h | 2 ++ vic/drivers/shared_image/src/vic_image_timing.c | 10 ++++++++++ vic/drivers/shared_image/src/vic_store.c | 1 - 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/vic/drivers/image/src/vic_image.c b/vic/drivers/image/src/vic_image.c index 20a4000d7..b7ee1d9a6 100644 --- a/vic/drivers/image/src/vic_image.c +++ b/vic/drivers/image/src/vic_image.c @@ -131,16 +131,23 @@ main(int argc, // start vic run timer timer_start(&(global_timers[TIMER_VIC_RUN])); + timer_init(&(global_timers[TIMER_VIC_FORCE])); + timer_init(&(global_timers[TIMER_VIC_WRITE])); + // loop over all timesteps for (current = 0; current < global_param.nrecs; current++) { // read forcing data + timer_continue(&(global_timers[TIMER_VIC_FORCE])); vic_force(); + timer_stop(&(global_timers[TIMER_VIC_FORCE])); // run vic over the domain vic_image_run(&(dmy[current])); // Write history files + timer_continue(&(global_timers[TIMER_VIC_WRITE])); vic_write_output(&(dmy[current])); + timer_stop(&(global_timers[TIMER_VIC_WRITE])); // Write state file if (check_save_state_flag(current, &dmy_state)) { diff --git a/vic/drivers/shared_all/include/vic_driver_shared_all.h b/vic/drivers/shared_all/include/vic_driver_shared_all.h index 5d53a9175..893df7a3a 100644 --- a/vic/drivers/shared_all/include/vic_driver_shared_all.h +++ b/vic/drivers/shared_all/include/vic_driver_shared_all.h @@ -451,6 +451,8 @@ enum timers TIMER_VIC_INIT, TIMER_VIC_RUN, TIMER_VIC_FINAL, + TIMER_VIC_FORCE, + TIMER_VIC_WRITE, N_TIMERS }; diff --git a/vic/drivers/shared_image/src/vic_image_timing.c b/vic/drivers/shared_image/src/vic_image_timing.c index 39cf8ff11..6b6fe1d9b 100644 --- a/vic/drivers/shared_image/src/vic_image_timing.c +++ b/vic/drivers/shared_image/src/vic_image_timing.c @@ -146,6 +146,16 @@ write_vic_timing_table(timer_struct *timers, timers[TIMER_VIC_ALL].delta_cpu / ndays); fprintf(LOG_DEST, "|------------|----------------------|----------------------|----------------------|----------------------|\n"); + fprintf(LOG_DEST, "| Force Time | %20g | %20g | %20g | %20g |\n", + timers[TIMER_VIC_FORCE].delta_wall, timers[TIMER_VIC_FORCE].delta_cpu, + timers[TIMER_VIC_FORCE].delta_wall / ndays, + timers[TIMER_VIC_FORCE].delta_cpu / ndays); + fprintf(LOG_DEST, "| Write Time | %20g | %20g | %20g | %20g |\n", + timers[TIMER_VIC_WRITE].delta_wall, timers[TIMER_VIC_WRITE].delta_cpu, + timers[TIMER_VIC_WRITE].delta_wall / ndays, + timers[TIMER_VIC_WRITE].delta_cpu / ndays); + fprintf(LOG_DEST, + "|------------|----------------------|----------------------|----------------------|----------------------|\n"); fprintf(LOG_DEST, "\n"); fprintf(LOG_DEST, diff --git a/vic/drivers/shared_image/src/vic_store.c b/vic/drivers/shared_image/src/vic_store.c index 2fe4cf0d2..40874561c 100644 --- a/vic/drivers/shared_image/src/vic_store.c +++ b/vic/drivers/shared_image/src/vic_store.c @@ -39,7 +39,6 @@ vic_store(dmy_struct *dmy_state, extern option_struct options; extern veg_con_map_struct *veg_con_map; extern int mpi_rank; - extern global_param_struct global_param; int status; int v; From a69490cf34d96aa94c42bf95f439cd9eb4333ce5 Mon Sep 17 00:00:00 2001 From: Joe Hamman Date: Thu, 16 Mar 2017 11:38:12 -0700 Subject: [PATCH 2/4] add release notes --- docs/Development/ReleaseNotes.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/Development/ReleaseNotes.md b/docs/Development/ReleaseNotes.md index 3e6452b54..30ea3f1db 100644 --- a/docs/Development/ReleaseNotes.md +++ b/docs/Development/ReleaseNotes.md @@ -25,11 +25,11 @@ To check which release of VIC you are running: Drainage from upper layer to adjacent lower layer is calculated according to Brook & Corey curve (where drainage rate is a function of upper-layer soil moisture). In previous versions, a simple numerical solution is applied which uses the timestep-beginning upper-layer soil moisture to calculate drainage rate, and assume this constant rate over the entire timestep. This can cause unreasonably large drainage if the curve has a steep shape and when soil moisture is high. Now, the current version uses exact integral (instead of numerical solution) for layer drainage calculation. -2. Fixes for the CESM driver +2. Fixes for the CESM driver [GH#642](https://github.com/UW-Hydro/VIC/pull/642) - 1. Using correct fill value datatypes in MPI Gather steps + 1. Using correct fill value datatypes in MPI Gather steps 2. Updated state file name time step to be period-ending rather than period-beginning 3. Set the state file name to the RASM case ID 4. Removed decimal point for missing values for unsigned integers @@ -45,11 +45,20 @@ To check which release of VIC you are running: [GH#696](https://github.com/UW-Hydro/VIC/pull/696) - 1. Changes names of CESM driver functions `trim` and `advance_time` to `trimstr` and `advance_vic_time`, respectively, to avoid conflicts with WRF functions with the same names when compiling RFR case. + 1. Changes names of CESM driver functions `trim` and `advance_time` to `trimstr` and `advance_vic_time`, respectively, to avoid conflicts with WRF functions with the same names when compiling RFR case. [GH#702] (https://github.com/UW-Hydro/VIC/pull/702) - 1. Fixes Julian day for the first timestep in the dmy struct for the CESM driver. + 1. Fixes Julian day for the first timestep in the dmy struct for the CESM driver. + +3. Speed up NetCDF operations in the image/CESM drivers ([GH#684](https://github.com/UW-Hydro/VIC/pull/684)) + + These changes speed up image driver initialization, forcing reads, and history writes by only opening and closing each input netCDF file once. + +4. Added two new timers to measure time in I/O operations ([GH#703](https://github.com/UW-Hydro/VIC/pull/703)) + + These two timers count the CPU and WALL time spent in ``vic_force`` and ``vic_write``. The accumulated time from these timers is printed out at the end of each simulation in the timing table. See also [GH#442](https://github.com/UW-Hydro/VIC/pull/442). + ## VIC 5.0.1 **Release date: (February 1, 2017)** @@ -65,7 +74,7 @@ To check which release of VIC you are running: After the fix, the `forceskip` variable in the global parameter structure (i.e., the number of timesteps to skip in the forcing data for the simulatin period) is rounded correctly (before the fix, rounding error might cause 1-timestep offset in the simulation results). 3. Fixed a problem with image restarts when using multiple processors ([GH#638](https://github.com/UW-Hydro/VIC/pull/638)) - + After the fix, only the master node is assigned the task of validating state file dimensions and coordinate variables. Multiprocessing was also added to the VIC testing framework. 4. Ensured that the mask variable in the input domain file must be integer type; otherwise an error is raised. ([GH#645](https://github.com/UW-Hydro/VIC/pull/645)) @@ -76,8 +85,8 @@ To check which release of VIC you are running: 6. Fixed a bug related to writing two-dimensional lat/lon variables to a state file ([GH#652](https://github.com/UW-Hydro/VIC/pull/652)) - Before the bug fix, two-dimensional lat/lon variables were not populated correctly and were written as fill values to a state file. Now two-dimensional lat/lon variables are correctly populated and written. - + Before the bug fix, two-dimensional lat/lon variables were not populated correctly and were written as fill values to a state file. Now two-dimensional lat/lon variables are correctly populated and written. + 7. Fixed a bug related to `dz_node` and `node_depth` variables in image driver output state file ([GH#657](https://github.com/UW-Hydro/VIC/pull/657)) Before the fix, `dz_node` and `node_depth` in image driver output state file were not spatially distributed, which was wrong. Now these two variables are spatially distributed in the output state file. @@ -94,7 +103,6 @@ To check which release of VIC you are running: Before the fix, there would be an error if the simulation start time is later than the forcing start time that year AND the simulation spans multiple years. Fixed this bug. - ------------------------------ ## VIC 5.0.0 [![DOI](https://zenodo.org/badge/doi/10.5281/zenodo.61422.svg)](http://dx.doi.org/10.5281/zenodo.61422) From fca3636060b3436c36e8bc6f955c74b1f7f210ca Mon Sep 17 00:00:00 2001 From: Joe Hamman Date: Thu, 16 Mar 2017 12:01:24 -0700 Subject: [PATCH 3/4] run uncrustify --- vic/drivers/cesm/src/cesm_interface_c.c | 2 +- vic/drivers/cesm/src/cesm_put_data.c | 8 +- .../cesm/src/display_current_settings.c | 3 +- vic/drivers/cesm/src/get_global_param.c | 22 +++--- vic/drivers/cesm/src/vic_cesm_start.c | 4 +- vic/drivers/cesm/src/vic_cesm_time.c | 1 - vic/drivers/cesm/src/vic_force.c | 16 ++-- vic/drivers/image/src/check_save_state_flag.c | 3 +- .../image/src/display_current_settings.c | 3 +- vic/drivers/image/src/get_global_param.c | 2 +- vic/drivers/image/src/vic_force.c | 10 ++- vic/drivers/image/src/vic_image_start.c | 6 +- vic/drivers/shared_all/src/make_dmy.c | 2 +- .../shared_all/src/set_output_defaults.c | 10 +-- vic/drivers/shared_all/src/vic_time.c | 4 +- .../include/vic_driver_shared_image.h | 2 +- .../shared_image/include/vic_image_log.h | 2 +- vic/drivers/shared_image/include/vic_mpi.h | 2 +- .../shared_image/src/get_global_domain.c | 9 ++- vic/drivers/shared_image/src/get_nc_field.c | 24 +++--- .../shared_image/src/get_nc_var_attr.c | 6 +- .../shared_image/src/get_nc_var_type.c | 9 ++- .../shared_image/src/get_nc_varndimensions.c | 2 +- .../shared_image/src/parse_output_info.c | 40 +++++----- .../shared_image/src/vic_image_timing.c | 3 +- vic/drivers/shared_image/src/vic_init.c | 3 +- .../shared_image/src/vic_mpi_support.c | 24 +++--- vic/drivers/shared_image/src/vic_restore.c | 47 +++++++---- vic/drivers/shared_image/src/vic_start.c | 3 +- vic/drivers/shared_image/src/vic_store.c | 78 ++++++++++++------- vic/vic_run/include/vic_log.h | 10 +-- vic/vic_run/src/func_canopy_energy_bal.c | 4 +- vic/vic_run/src/runoff.c | 13 ++-- vic/vic_run/src/snow_intercept.c | 2 +- 34 files changed, 216 insertions(+), 163 deletions(-) diff --git a/vic/drivers/cesm/src/cesm_interface_c.c b/vic/drivers/cesm/src/cesm_interface_c.c index da7445654..1f8382eb6 100644 --- a/vic/drivers/cesm/src/cesm_interface_c.c +++ b/vic/drivers/cesm/src/cesm_interface_c.c @@ -104,7 +104,7 @@ vic_cesm_init(vic_clock *vclock, // initialization is complete, print settings log_info( - "Initialization is complete, print global param and options structures"); + "Initialization is complete, print global param and options structures"); print_global_param(&global_param); print_option(&options); diff --git a/vic/drivers/cesm/src/cesm_put_data.c b/vic/drivers/cesm/src/cesm_put_data.c index 587b1b29d..da5f1d45f 100644 --- a/vic/drivers/cesm/src/cesm_put_data.c +++ b/vic/drivers/cesm/src/cesm_put_data.c @@ -140,12 +140,14 @@ vic_cesm_put_data() // 2m reference temperature // CESM units: K - l2x_vic[i].l2x_Sl_tref += AreaFactor * (force[i].air_temp[NR] + CONST_TKFRZ); + l2x_vic[i].l2x_Sl_tref += AreaFactor * + (force[i].air_temp[NR] + CONST_TKFRZ); // 2m reference specific humidity // CESM units: g/g l2x_vic[i].l2x_Sl_qref += AreaFactor * CONST_EPS * - force[i].vp[NR] / force[i].pressure[NR]; + force[i].vp[NR] / + force[i].pressure[NR]; // Albedo Note: VIC does not partition its albedo, all returned // values will be the same @@ -258,7 +260,7 @@ vic_cesm_put_data() // upward longwave heat flux // CESM units: W m-2 - l2x_vic[i].l2x_Fall_lwup += -1 * AreaFactor * + l2x_vic[i].l2x_Fall_lwup += -1 * AreaFactor * (force[i].longwave[NR] - energy.NetLongAtmos); diff --git a/vic/drivers/cesm/src/display_current_settings.c b/vic/drivers/cesm/src/display_current_settings.c index 123e954e3..029575613 100644 --- a/vic/drivers/cesm/src/display_current_settings.c +++ b/vic/drivers/cesm/src/display_current_settings.c @@ -361,7 +361,8 @@ display_current_settings(int mode) fprintf(LOG_DEST, "\n"); fprintf(LOG_DEST, "Input State File:\n"); if (options.INIT_STATE) { - fprintf(LOG_DEST, "INIT_STATE\t\tTRUE\t%s\n", filenames.init_state.nc_filename); + fprintf(LOG_DEST, "INIT_STATE\t\tTRUE\t%s\n", + filenames.init_state.nc_filename); if (options.STATE_FORMAT == NETCDF3_CLASSIC) { fprintf(LOG_DEST, "STATE_FORMAT\t\tNETCDF3_CLASSIC\n"); } diff --git a/vic/drivers/cesm/src/get_global_param.c b/vic/drivers/cesm/src/get_global_param.c index 26e01ea07..89ab7c3c4 100644 --- a/vic/drivers/cesm/src/get_global_param.c +++ b/vic/drivers/cesm/src/get_global_param.c @@ -72,14 +72,14 @@ get_global_param(FILE *gp) sscanf(cmdstr, "%*s %s", flgstr); global_param.time_units = str_to_timeunits(flgstr); } - else if (strcasecmp("FULL_ENERGY", optstr) == 0) { - sscanf(cmdstr, "%*s %s", flgstr); - options.FULL_ENERGY = str_to_bool(flgstr); - if (options.FULL_ENERGY == false) { - log_warn("FULL_ENERGY is set to FALSE. Please double check " - "that this is the setting you intended."); - } - } + else if (strcasecmp("FULL_ENERGY", optstr) == 0) { + sscanf(cmdstr, "%*s %s", flgstr); + options.FULL_ENERGY = str_to_bool(flgstr); + if (options.FULL_ENERGY == false) { + log_warn("FULL_ENERGY is set to FALSE. Please double check " + "that this is the setting you intended."); + } + } else if (strcasecmp("FROZEN_SOIL", optstr) == 0) { sscanf(cmdstr, "%*s %s", flgstr); options.FROZEN_SOIL = str_to_bool(flgstr); @@ -394,8 +394,8 @@ get_global_param(FILE *gp) } } else if (strcasecmp("SNOW_BAND", optstr) == 0) { - sscanf(cmdstr, "%*s %s", flgstr); - if (str_to_bool(flgstr)) { + sscanf(cmdstr, "%*s %s", flgstr); + if (str_to_bool(flgstr)) { options.SNOW_BAND = SNOW_BAND_TRUE_BUT_UNSET; } } @@ -430,7 +430,7 @@ get_global_param(FILE *gp) ; // do nothing } else if (strcasecmp("AGGFREQ", optstr) == 0) { - ; // do nothing + ; // do nothing } else if (strcasecmp("OUTPUT_STEPS_PER_DAY", optstr) == 0) { ; // do nothing diff --git a/vic/drivers/cesm/src/vic_cesm_start.c b/vic/drivers/cesm/src/vic_cesm_start.c index 635643cbc..e79ccb173 100644 --- a/vic/drivers/cesm/src/vic_cesm_start.c +++ b/vic/drivers/cesm/src/vic_cesm_start.c @@ -47,8 +47,8 @@ vic_cesm_start(vic_clock *vclock, if (mpi_rank == VIC_MPI_ROOT) { strcpy(filenames.global, GLOBALPARAM); - // assign case name to state file name - strncpy(filenames.statefile, trimstr(cmeta->caseid), + // assign case name to state file name + strncpy(filenames.statefile, trimstr(cmeta->caseid), sizeof(filenames.statefile)); // read global settings diff --git a/vic/drivers/cesm/src/vic_cesm_time.c b/vic/drivers/cesm/src/vic_cesm_time.c index 72c4ba384..ec46bd8c4 100644 --- a/vic/drivers/cesm/src/vic_cesm_time.c +++ b/vic/drivers/cesm/src/vic_cesm_time.c @@ -63,7 +63,6 @@ initialize_cesm_time(void) num2date(global_param.time_origin_num, numdate, 0., global_param.calendar, global_param.time_units, &dmy_current); - } /****************************************************************************** diff --git a/vic/drivers/cesm/src/vic_force.c b/vic/drivers/cesm/src/vic_force.c index 7b32f2a63..b6a8db94e 100644 --- a/vic/drivers/cesm/src/vic_force.c +++ b/vic/drivers/cesm/src/vic_force.c @@ -206,14 +206,14 @@ vic_force(void) for (j = 0; j < NF; j++) { // vapor pressure deficit force[i].vpd[j] = svp(force[i].air_temp[j]) - force[i].vp[j]; - if (force[i].vpd[j] < 0) { - log_warn("Vapor pressure deficit is %f which is < 0, " - "setting vapor pressure deficit to 0 and calculating " - "saturated vapor pressure using air temperature %f.", - force[i].vpd[j], force[i].air_temp[j]); - force[i].vpd[j] = 0; - force[i].vp[j] = svp(force[i].air_temp[j]); - } + if (force[i].vpd[j] < 0) { + log_warn("Vapor pressure deficit is %f which is < 0, " + "setting vapor pressure deficit to 0 and calculating " + "saturated vapor pressure using air temperature %f.", + force[i].vpd[j], force[i].air_temp[j]); + force[i].vpd[j] = 0; + force[i].vp[j] = svp(force[i].air_temp[j]); + } // photosynthetically active radiation // TODO: Add CARBON_SW2PAR back to the parameters structure // force[i].par[j] = param.CARBON_SW2PAR * force[i].shortwave[j]; diff --git a/vic/drivers/image/src/check_save_state_flag.c b/vic/drivers/image/src/check_save_state_flag.c index d71099719..3b046df35 100644 --- a/vic/drivers/image/src/check_save_state_flag.c +++ b/vic/drivers/image/src/check_save_state_flag.c @@ -32,7 +32,8 @@ * current time step *****************************************************************************/ bool -check_save_state_flag(size_t current, dmy_struct *dmy_offset) +check_save_state_flag(size_t current, + dmy_struct *dmy_offset) { extern global_param_struct global_param; extern dmy_struct *dmy; diff --git a/vic/drivers/image/src/display_current_settings.c b/vic/drivers/image/src/display_current_settings.c index d3994dceb..81173eebd 100644 --- a/vic/drivers/image/src/display_current_settings.c +++ b/vic/drivers/image/src/display_current_settings.c @@ -378,7 +378,8 @@ display_current_settings(int mode) fprintf(LOG_DEST, "\n"); fprintf(LOG_DEST, "Input State File:\n"); if (options.INIT_STATE) { - fprintf(LOG_DEST, "INIT_STATE\t\tTRUE\t%s\n", filenames.init_state.nc_filename); + fprintf(LOG_DEST, "INIT_STATE\t\tTRUE\t%s\n", + filenames.init_state.nc_filename); if (options.STATE_FORMAT == NETCDF3_CLASSIC) { fprintf(LOG_DEST, "STATE_FORMAT\t\tNETCDF3_CLASSIC\n"); } diff --git a/vic/drivers/image/src/get_global_param.c b/vic/drivers/image/src/get_global_param.c index 538ae1b55..2b5ed9390 100644 --- a/vic/drivers/image/src/get_global_param.c +++ b/vic/drivers/image/src/get_global_param.c @@ -800,7 +800,7 @@ get_global_param(FILE *gp) sprintf(filenames.forcing[1].nc_filename, "%s%4d.nc", filenames.f_path_pfx[1], global_param.startyear); status = nc_open(filenames.forcing[1].nc_filename, NC_NOWRITE, - &(filenames.forcing[1].nc_id)); + &(filenames.forcing[1].nc_id)); check_nc_status(status, "Error opening %s", filenames.forcing[1].nc_filename); get_forcing_file_info(¶m_set, 1); diff --git a/vic/drivers/image/src/vic_force.c b/vic/drivers/image/src/vic_force.c index be0c80017..104be14ab 100644 --- a/vic/drivers/image/src/vic_force.c +++ b/vic/drivers/image/src/vic_force.c @@ -282,7 +282,6 @@ vic_force(void) if (options.LAI_SRC == FROM_VEGHIST || options.FCAN_SRC == FROM_VEGHIST || options.ALB_SRC == FROM_VEGHIST) { - // global_param.forceoffset[1] resets every year since the met file restarts // every year // global_param.forceskip[1] should also reset to 0 after the first year @@ -527,9 +526,12 @@ get_forcing_file_info(param_set_struct *param_set, dmy_struct nc_start_dmy; // read time info from netcdf file - get_nc_field_double(&(filenames.forcing[file_num]), "time", &start, &count, nc_times); - get_nc_var_attr(&(filenames.forcing[file_num]), "time", "units", &nc_unit_chars); - get_nc_var_attr(&(filenames.forcing[file_num]), "time", "calendar", &calendar_char); + get_nc_field_double(&(filenames.forcing[file_num]), "time", &start, &count, + nc_times); + get_nc_var_attr(&(filenames.forcing[file_num]), "time", "units", + &nc_unit_chars); + get_nc_var_attr(&(filenames.forcing[file_num]), "time", "calendar", + &calendar_char); // parse the calendar string and check to make sure it matches the global clock calendar = str_to_calendar(calendar_char); diff --git a/vic/drivers/image/src/vic_image_start.c b/vic/drivers/image/src/vic_image_start.c index 401df8162..5a2ee4f12 100644 --- a/vic/drivers/image/src/vic_image_start.c +++ b/vic/drivers/image/src/vic_image_start.c @@ -32,9 +32,9 @@ void vic_image_start(void) { - extern filep_struct filep; - extern filenames_struct filenames; - extern int mpi_rank; + extern filep_struct filep; + extern filenames_struct filenames; + extern int mpi_rank; // Initialize structures initialize_global_structures(); diff --git a/vic/drivers/shared_all/src/make_dmy.c b/vic/drivers/shared_all/src/make_dmy.c index 1b48cbdf0..ea113fd79 100644 --- a/vic/drivers/shared_all/src/make_dmy.c +++ b/vic/drivers/shared_all/src/make_dmy.c @@ -97,7 +97,7 @@ make_dmy(global_param_struct *global) global->forceskip[i] = (unsigned int) round((start_num - force_num) * - (double) param_set.force_steps_per_day[i]); + (double) param_set.force_steps_per_day[i]); } } diff --git a/vic/drivers/shared_all/src/set_output_defaults.c b/vic/drivers/shared_all/src/set_output_defaults.c index 0b53d7a13..82c4769af 100644 --- a/vic/drivers/shared_all/src/set_output_defaults.c +++ b/vic/drivers/shared_all/src/set_output_defaults.c @@ -98,12 +98,12 @@ set_output_defaults(stream_struct **streams, dmy_struct *dmy_current, unsigned short default_file_format) { - extern option_struct options; + extern option_struct options; - size_t streamnum; - size_t varnum; - alarm_struct default_alarm; - int default_freq_n = 1; + size_t streamnum; + size_t varnum; + alarm_struct default_alarm; + int default_freq_n = 1; set_alarm(dmy_current, FREQ_NDAYS, &default_freq_n, &default_alarm); diff --git a/vic/drivers/shared_all/src/vic_time.c b/vic/drivers/shared_all/src/vic_time.c index 0e57407ae..144fe742f 100644 --- a/vic/drivers/shared_all/src/vic_time.c +++ b/vic/drivers/shared_all/src/vic_time.c @@ -859,8 +859,8 @@ time_delta(dmy_struct *dmy_current, // if dmy_next.year is not leap year but date is Feb 29 !) make_lastday(global_param.calendar, dmy_next.year, lastday); dmy_next.day_in_year = 0; - for ( i = 0; i < MONTHS_PER_YEAR; i++ ) { - if ( (i+1) == dmy_next.month ) { + for (i = 0; i < MONTHS_PER_YEAR; i++) { + if ((i + 1) == dmy_next.month) { dmy_next.day_in_year += dmy_next.day; break; } diff --git a/vic/drivers/shared_image/include/vic_driver_shared_image.h b/vic/drivers/shared_image/include/vic_driver_shared_image.h index fd6f4d66d..dc4766cce 100644 --- a/vic/drivers/shared_image/include/vic_driver_shared_image.h +++ b/vic/drivers/shared_image/include/vic_driver_shared_image.h @@ -171,7 +171,7 @@ typedef struct { typedef struct { nameid_struct forcing[MAX_FORCE_FILES]; /**< atmospheric forcing files */ char f_path_pfx[MAX_FORCE_FILES][MAXSTRING]; /**< path and prefix for - atmospheric forcing files */ + atmospheric forcing files */ char global[MAXSTRING]; /**< global control file name */ nameid_struct domain; /**< domain file name and nc_id*/ char constants[MAXSTRING]; /**< model constants file name */ diff --git a/vic/drivers/shared_image/include/vic_image_log.h b/vic/drivers/shared_image/include/vic_image_log.h index 151f2c191..2b650fbe8 100644 --- a/vic/drivers/shared_image/include/vic_image_log.h +++ b/vic/drivers/shared_image/include/vic_image_log.h @@ -66,7 +66,7 @@ #define check_nc_status(A, M, ...) if (A != NC_NOERR) {log_ncerr(A, M, \ ## __VA_ARGS__); \ errno = 0; exit( \ - EXIT_FAILURE); } + EXIT_FAILURE);} #define log_mpi_err(e, M, ...) print_trace(); \ print_mpi_error_str(e); fprintf(LOG_DEST, \ diff --git a/vic/drivers/shared_image/include/vic_mpi.h b/vic/drivers/shared_image/include/vic_mpi.h index e1f324d4a..b46a1741c 100644 --- a/vic/drivers/shared_image/include/vic_mpi.h +++ b/vic/drivers/shared_image/include/vic_mpi.h @@ -37,7 +37,7 @@ *****************************************************************************/ typedef struct { char nc_filename[MAXSTRING]; - int nc_id; + int nc_id; } nameid_struct; void create_MPI_filenames_struct_type(MPI_Datatype *mpi_type); diff --git a/vic/drivers/shared_image/src/get_global_domain.c b/vic/drivers/shared_image/src/get_global_domain.c index 4291b79d8..464bb5523 100644 --- a/vic/drivers/shared_image/src/get_global_domain.c +++ b/vic/drivers/shared_image/src/get_global_domain.c @@ -36,7 +36,7 @@ get_global_domain(nameid_struct *domain_nc_nameid, { int *run = NULL; int *mask = NULL; - int typeid; + int typeid; double *var = NULL; size_t i; size_t j; @@ -68,7 +68,8 @@ get_global_domain(nameid_struct *domain_nc_nameid, if (typeid != NC_INT) { log_err("Mask variable in the domain file must be integer type."); } - get_nc_field_int(domain_nc_nameid, global_domain->info.mask_var, d2start, d2count, + get_nc_field_int(domain_nc_nameid, global_domain->info.mask_var, d2start, + d2count, mask); // Get run_cell variable from the parameter file @@ -152,7 +153,6 @@ get_global_domain(nameid_struct *domain_nc_nameid, return global_domain->ncells_active; } - /****************************************************************************** * @brief Get lat and lon coordinates information from a netCDF file and store in nc_domain structure @@ -273,7 +273,8 @@ get_nc_latlon(nameid_struct *nc_nameid, * @brief Copy domain info from one domain structure to another *****************************************************************************/ void -copy_domain_info(domain_struct *domain_from, domain_struct *domain_to) +copy_domain_info(domain_struct *domain_from, + domain_struct *domain_to) { strcpy(domain_to->info.x_dim, domain_from->info.x_dim); strcpy(domain_to->info.y_dim, domain_from->info.y_dim); diff --git a/vic/drivers/shared_image/src/get_nc_field.c b/vic/drivers/shared_image/src/get_nc_field.c index 5b79f218e..cf3404122 100644 --- a/vic/drivers/shared_image/src/get_nc_field.c +++ b/vic/drivers/shared_image/src/get_nc_field.c @@ -31,10 +31,10 @@ *****************************************************************************/ int get_nc_field_double(nameid_struct *nc_nameid, - char *var_name, - size_t *start, - size_t *count, - double *var) + char *var_name, + size_t *start, + size_t *count, + double *var) { int status; int var_id; @@ -56,10 +56,10 @@ get_nc_field_double(nameid_struct *nc_nameid, *****************************************************************************/ int get_nc_field_float(nameid_struct *nc_nameid, - char *var_name, - size_t *start, - size_t *count, - float *var) + char *var_name, + size_t *start, + size_t *count, + float *var) { int status; int var_id; @@ -81,10 +81,10 @@ get_nc_field_float(nameid_struct *nc_nameid, *****************************************************************************/ int get_nc_field_int(nameid_struct *nc_nameid, - char *var_name, - size_t *start, - size_t *count, - int *var) + char *var_name, + size_t *start, + size_t *count, + int *var) { int status; int var_id; diff --git a/vic/drivers/shared_image/src/get_nc_var_attr.c b/vic/drivers/shared_image/src/get_nc_var_attr.c index c16d24b50..4e1c07839 100644 --- a/vic/drivers/shared_image/src/get_nc_var_attr.c +++ b/vic/drivers/shared_image/src/get_nc_var_attr.c @@ -31,9 +31,9 @@ *****************************************************************************/ void get_nc_var_attr(nameid_struct *nc_nameid, - char *var_name, - char *attr_name, - char **attr) + char *var_name, + char *attr_name, + char **attr) { int var_id; int status; diff --git a/vic/drivers/shared_image/src/get_nc_var_type.c b/vic/drivers/shared_image/src/get_nc_var_type.c index 67dc4d5ad..d75586a2f 100644 --- a/vic/drivers/shared_image/src/get_nc_var_type.c +++ b/vic/drivers/shared_image/src/get_nc_var_type.c @@ -33,9 +33,9 @@ int get_nc_var_type(nameid_struct *nc_nameid, char *var_name) { - int var_id; - int status; - int xtypep; + int var_id; + int status; + int xtypep; // get variable id status = nc_inq_varid(nc_nameid->nc_id, var_name, &var_id); @@ -43,7 +43,8 @@ get_nc_var_type(nameid_struct *nc_nameid, nc_nameid->nc_filename); // get type ID - status = nc_inq_var(nc_nameid->nc_id, var_id, NULL, &xtypep, NULL, NULL, NULL); + status = nc_inq_var(nc_nameid->nc_id, var_id, NULL, &xtypep, NULL, NULL, + NULL); check_nc_status(status, "Error getting variable type %s in %s", var_name, nc_nameid->nc_filename); diff --git a/vic/drivers/shared_image/src/get_nc_varndimensions.c b/vic/drivers/shared_image/src/get_nc_varndimensions.c index de2eb5959..1f70b1adc 100644 --- a/vic/drivers/shared_image/src/get_nc_varndimensions.c +++ b/vic/drivers/shared_image/src/get_nc_varndimensions.c @@ -31,7 +31,7 @@ *****************************************************************************/ int get_nc_varndimensions(nameid_struct *nc_nameid, - char *var_name) + char *var_name) { int var_id; int ndims; diff --git a/vic/drivers/shared_image/src/parse_output_info.c b/vic/drivers/shared_image/src/parse_output_info.c index a9f0749a0..8977eb605 100644 --- a/vic/drivers/shared_image/src/parse_output_info.c +++ b/vic/drivers/shared_image/src/parse_output_info.c @@ -35,27 +35,27 @@ parse_output_info(FILE *gp, stream_struct **streams, dmy_struct *dmy_current) { - extern option_struct options; + extern option_struct options; - char cmdstr[MAXSTRING]; - char optstr[MAXSTRING]; - char flgstr[MAXSTRING]; - short int streamnum; - char varname[MAXSTRING]; - int outvarnum; - char freq_type_str[MAXSTRING]; - char freq_value_str[MAXSTRING]; - char format[MAXSTRING]; - char typestr[MAXSTRING]; - int type; - char multstr[MAXSTRING]; - char aggstr[MAXSTRING]; - double mult; - unsigned short int freq; - int freq_n; - dmy_struct freq_dmy; - unsigned short int agg_type; - int found; + char cmdstr[MAXSTRING]; + char optstr[MAXSTRING]; + char flgstr[MAXSTRING]; + short int streamnum; + char varname[MAXSTRING]; + int outvarnum; + char freq_type_str[MAXSTRING]; + char freq_value_str[MAXSTRING]; + char format[MAXSTRING]; + char typestr[MAXSTRING]; + int type; + char multstr[MAXSTRING]; + char aggstr[MAXSTRING]; + double mult; + unsigned short int freq; + int freq_n; + dmy_struct freq_dmy; + unsigned short int agg_type; + int found; streamnum = -1; diff --git a/vic/drivers/shared_image/src/vic_image_timing.c b/vic/drivers/shared_image/src/vic_image_timing.c index 39cf8ff11..ebc0ae5d9 100644 --- a/vic/drivers/shared_image/src/vic_image_timing.c +++ b/vic/drivers/shared_image/src/vic_image_timing.c @@ -89,7 +89,8 @@ write_vic_timing_table(timer_struct *timers, fprintf(LOG_DEST, " VIC_DRIVER : %s\n", driver); fprintf(LOG_DEST, "\n"); fprintf(LOG_DEST, " Global Param File : %s\n", filenames.global); - fprintf(LOG_DEST, " Domain File : %s\n", filenames.domain.nc_filename); + fprintf(LOG_DEST, " Domain File : %s\n", + filenames.domain.nc_filename); fprintf(LOG_DEST, " Start Date : %04hu-%02hu-%02hu-%05u\n", global_param.startyear, global_param.startmonth, global_param.startday, global_param.startsec); diff --git a/vic/drivers/shared_image/src/vic_init.c b/vic/drivers/shared_image/src/vic_init.c index 44fef6f5a..fdfcc0a83 100644 --- a/vic/drivers/shared_image/src/vic_init.c +++ b/vic/drivers/shared_image/src/vic_init.c @@ -673,7 +673,8 @@ vic_init(void) // spatial snow if (options.SPATIAL_SNOW) { // max_snow_distrib_slope - get_scatter_nc_field_double(&(filenames.params), "max_snow_distrib_slope", + get_scatter_nc_field_double(&(filenames.params), + "max_snow_distrib_slope", d2start, d2count, dvar); for (i = 0; i < local_domain.ncells_active; i++) { soil_con[i].max_snow_distrib_slope = (double) dvar[i]; diff --git a/vic/drivers/shared_image/src/vic_mpi_support.c b/vic/drivers/shared_image/src/vic_mpi_support.c index 294131758..1cd8141f6 100644 --- a/vic/drivers/shared_image/src/vic_mpi_support.c +++ b/vic/drivers/shared_image/src/vic_mpi_support.c @@ -2043,10 +2043,10 @@ gather_put_nc_field_schar(int nc_id, *****************************************************************************/ void get_scatter_nc_field_double(nameid_struct *nc_nameid, - char *var_name, - size_t *start, - size_t *count, - double *var) + char *var_name, + size_t *start, + size_t *count, + double *var) { extern MPI_Comm MPI_COMM_VIC; extern domain_struct global_domain; @@ -2104,10 +2104,10 @@ get_scatter_nc_field_double(nameid_struct *nc_nameid, *****************************************************************************/ void get_scatter_nc_field_float(nameid_struct *nc_nameid, - char *var_name, - size_t *start, - size_t *count, - float *var) + char *var_name, + size_t *start, + size_t *count, + float *var) { extern MPI_Comm MPI_COMM_VIC; extern domain_struct global_domain; @@ -2167,10 +2167,10 @@ get_scatter_nc_field_float(nameid_struct *nc_nameid, *****************************************************************************/ void get_scatter_nc_field_int(nameid_struct *nc_nameid, - char *var_name, - size_t *start, - size_t *count, - int *var) + char *var_name, + size_t *start, + size_t *count, + int *var) { extern MPI_Comm MPI_COMM_VIC; extern domain_struct global_domain; diff --git a/vic/drivers/shared_image/src/vic_restore.c b/vic/drivers/shared_image/src/vic_restore.c index 46abea478..bf1b656ad 100644 --- a/vic/drivers/shared_image/src/vic_restore.c +++ b/vic/drivers/shared_image/src/vic_restore.c @@ -917,12 +917,14 @@ check_init_state_file(void) // read and validate dimension lengths if (mpi_rank == VIC_MPI_ROOT) { - dimlen = get_nc_dimension(&(filenames.init_state), global_domain.info.x_dim); + dimlen = get_nc_dimension(&(filenames.init_state), + global_domain.info.x_dim); if (dimlen != global_domain.n_nx) { log_err("Number of grid columns in state file does not " "match parameter file"); } - dimlen = get_nc_dimension(&(filenames.init_state), global_domain.info.y_dim); + dimlen = get_nc_dimension(&(filenames.init_state), + global_domain.info.y_dim); if (dimlen != global_domain.n_ny) { log_err("Number of grid rows in state file does not " "match parameter file"); @@ -965,47 +967,55 @@ check_init_state_file(void) // lat/lon if (mpi_rank == VIC_MPI_ROOT) { - status = nc_inq_varid(filenames.init_state.nc_id, global_domain.info.lon_var, &lon_var_id); + status = nc_inq_varid(filenames.init_state.nc_id, + global_domain.info.lon_var, &lon_var_id); check_nc_status(status, "Unable to find variable \"%s\" in %s", - global_domain.info.lon_var, filenames.init_state.nc_filename); - status = nc_inq_varid(filenames.init_state.nc_id, global_domain.info.lat_var, &lat_var_id); + global_domain.info.lon_var, + filenames.init_state.nc_filename); + status = nc_inq_varid(filenames.init_state.nc_id, + global_domain.info.lat_var, &lat_var_id); check_nc_status(status, "Unable to find variable \"%s\" in %s", - global_domain.info.lat_var, filenames.init_state.nc_filename); + global_domain.info.lat_var, + filenames.init_state.nc_filename); if (global_domain.info.n_coord_dims == 1) { d1start[0] = 0; dvar = calloc(global_domain.n_nx, sizeof(*dvar)); check_alloc_status(dvar, "Memory allocation error"); - + d1count[0] = global_domain.n_nx; status = nc_get_vara_double(filenames.init_state.nc_id, lon_var_id, d1start, d1count, dvar); check_nc_status(status, "Error reading data from \"%s\" in %s", - global_domain.info.lon_var, filenames.init_state.nc_filename); + global_domain.info.lon_var, + filenames.init_state.nc_filename); // implicitly nested loop over ni and nj with j set to 0 for (i = 0; i < global_domain.n_nx; i++) { if (!assert_close_double(dvar[i], - global_domain.locations[i].longitude, rtol, + global_domain.locations[i].longitude, + rtol, abs_tol)) { log_err("Longitudes in initial state file do not " "match parameter file"); } } free(dvar); - + dvar = calloc(global_domain.n_ny, sizeof(*dvar)); check_alloc_status(dvar, "Memory allocation error"); - + d1count[0] = global_domain.n_ny; status = nc_get_vara_double(filenames.init_state.nc_id, lat_var_id, d1start, d1count, dvar); check_nc_status(status, "Error reading data from \"%s\" in %s", - global_domain.info.lat_var, filenames.init_state.nc_filename); + global_domain.info.lat_var, + filenames.init_state.nc_filename); // implicitly nested loop over ni and nj with i set to 0; // j stride = n_nx for (j = 0; j < global_domain.n_ny; j++) { if (!assert_close_double(dvar[j], global_domain.locations[j * - global_domain.n_nx] + global_domain. + n_nx] .latitude, rtol, abs_tol)) { log_err("Latitudes in initial state file do not " @@ -1017,15 +1027,17 @@ check_init_state_file(void) else if (global_domain.info.n_coord_dims == 2) { d2start[0] = 0; d2start[1] = 0; - dvar = calloc(global_domain.n_ny * global_domain.n_nx, sizeof(*dvar)); + dvar = + calloc(global_domain.n_ny * global_domain.n_nx, sizeof(*dvar)); check_alloc_status(dvar, "Memory allocation error"); - + d2count[0] = global_domain.n_ny; d2count[1] = global_domain.n_nx; status = nc_get_vara_double(filenames.init_state.nc_id, lon_var_id, d2start, d2count, dvar); check_nc_status(status, "Error reading data from \"%s\" in %s", - global_domain.info.lon_var, filenames.init_state.nc_filename); + global_domain.info.lon_var, + filenames.init_state.nc_filename); for (i = 0; i < global_domain.n_ny * global_domain.n_nx; i++) { if (dvar[i] != (double) global_domain.locations[i].longitude) { log_err("Longitudes in initial state file do not " @@ -1035,7 +1047,8 @@ check_init_state_file(void) status = nc_get_vara_double(filenames.init_state.nc_id, lat_var_id, d2start, d2count, dvar); check_nc_status(status, "Error reading data from \"%s\" in %s", - global_domain.info.lat_var, filenames.init_state.nc_filename); + global_domain.info.lat_var, + filenames.init_state.nc_filename); for (i = 0; i < global_domain.n_ny * global_domain.n_nx; i++) { if (dvar[i] != (double) global_domain.locations[i].latitude) { log_err("Latitudes in initial state file do not " diff --git a/vic/drivers/shared_image/src/vic_start.c b/vic/drivers/shared_image/src/vic_start.c index 8c36b216f..32cbc2c57 100644 --- a/vic/drivers/shared_image/src/vic_start.c +++ b/vic/drivers/shared_image/src/vic_start.c @@ -118,7 +118,8 @@ vic_start(void) options.Nlayer = get_nc_dimension(&(filenames.params), "nlayer"); options.NVEGTYPES = get_nc_dimension(&(filenames.params), "veg_class"); if (options.SNOW_BAND == SNOW_BAND_TRUE_BUT_UNSET) { - options.SNOW_BAND = get_nc_dimension(&(filenames.params), "snow_band"); + options.SNOW_BAND = get_nc_dimension(&(filenames.params), + "snow_band"); } if (options.LAKES) { options.NLAKENODES = get_nc_dimension(&(filenames.params), diff --git a/vic/drivers/shared_image/src/vic_store.c b/vic/drivers/shared_image/src/vic_store.c index 2fe4cf0d2..6389468de 100644 --- a/vic/drivers/shared_image/src/vic_store.c +++ b/vic/drivers/shared_image/src/vic_store.c @@ -1571,16 +1571,19 @@ initialize_state_file(char *filename, check_nc_status(status, "Error setting fill value in %s", filename); // define the time dimension - status = nc_def_dim(nc_state_file->nc_id, "time", nc_state_file->time_size, + status = nc_def_dim(nc_state_file->nc_id, "time", + nc_state_file->time_size, &(nc_state_file->time_dimid)); - check_nc_status(status, "Error defining time dimenension in %s", filename); + check_nc_status(status, "Error defining time dimenension in %s", + filename); // define the variable time status = nc_def_var(nc_state_file->nc_id, "time", NC_DOUBLE, 1, &(nc_state_file->time_dimid), &(nc_state_file->time_varid)); check_nc_status(status, "Error defining time variable in %s", filename); - status = nc_put_att_text(nc_state_file->nc_id, nc_state_file->time_varid, + status = nc_put_att_text(nc_state_file->nc_id, + nc_state_file->time_varid, "standard_name", strlen("time"), "time"); check_nc_status(status, "Error adding attribute in %s", filename); @@ -1589,16 +1592,19 @@ initialize_state_file(char *filename, sprintf(str, "%s since %s", unit_str, global_param.time_origin_str); - status = nc_put_att_text(nc_state_file->nc_id, nc_state_file->time_varid, + status = nc_put_att_text(nc_state_file->nc_id, + nc_state_file->time_varid, "units", strlen(str), str); check_nc_status(status, "Error adding attribute in %s", filename); // adding calendar attribute to time variable str_from_calendar(global_param.calendar, str); - status = nc_put_att_text(nc_state_file->nc_id, nc_state_file->time_varid, + status = nc_put_att_text(nc_state_file->nc_id, + nc_state_file->time_varid, "calendar", strlen(str), str); - check_nc_status(status, "Error adding calendar attribute in %s", filename); + check_nc_status(status, "Error adding calendar attribute in %s", + filename); // define netcdf dimensions status = nc_def_dim(nc_state_file->nc_id, global_domain.info.x_dim, @@ -1614,7 +1620,8 @@ initialize_state_file(char *filename, filename); status = nc_def_dim(nc_state_file->nc_id, "veg_class", - nc_state_file->veg_size, &(nc_state_file->veg_dimid)); + nc_state_file->veg_size, + &(nc_state_file->veg_dimid)); check_nc_status(status, "Error defining veg_class in %s", filename); status = nc_def_dim(nc_state_file->nc_id, "snow_band", @@ -1729,7 +1736,8 @@ initialize_state_file(char *filename, strlen("veg_class"), "veg_class"); check_nc_status(status, "Error adding attribute in %s", filename); status = nc_put_att_text(nc_state_file->nc_id, veg_var_id, - "standard_name", strlen("vegetation_class_number"), + "standard_name", + strlen("vegetation_class_number"), "vegetation_class_number"); check_nc_status(status, "Error adding attribute in %s", filename); dimids[0] = -1; @@ -1756,8 +1764,10 @@ initialize_state_file(char *filename, status = nc_def_var(nc_state_file->nc_id, "layer", NC_INT, 1, dimids, &(layer_var_id)); - check_nc_status(status, "Error defining layer variable in %s", filename); - status = nc_put_att_text(nc_state_file->nc_id, layer_var_id, "long_name", + check_nc_status(status, "Error defining layer variable in %s", + filename); + status = nc_put_att_text(nc_state_file->nc_id, layer_var_id, + "long_name", strlen("layer"), "layer"); check_nc_status(status, "Error adding attribute in %s", filename); status = nc_put_att_text(nc_state_file->nc_id, layer_var_id, @@ -1789,7 +1799,8 @@ initialize_state_file(char *filename, status = nc_def_var(nc_state_file->nc_id, "dz_node", NC_DOUBLE, 3, dimids, &(dz_node_var_id)); check_nc_status(status, "Error defining node variable in %s", filename); - status = nc_put_att_text(nc_state_file->nc_id, dz_node_var_id, "long_name", + status = nc_put_att_text(nc_state_file->nc_id, dz_node_var_id, + "long_name", strlen("dz_node"), "dz_node"); check_nc_status(status, "Error adding attribute in %s", filename); status = nc_put_att_text(nc_state_file->nc_id, dz_node_var_id, @@ -1816,10 +1827,12 @@ initialize_state_file(char *filename, strlen("node_depth"), "node_depth"); check_nc_status(status, "Error adding attribute in %s", filename); status = nc_put_att_text(nc_state_file->nc_id, node_depth_var_id, - "standard_name", strlen("soil_thermal_node_depth"), + "standard_name", + strlen("soil_thermal_node_depth"), "soil_thermal_node_depth"); check_nc_status(status, "Error adding attribute in %s", filename); - status = nc_put_att_text(nc_state_file->nc_id, node_depth_var_id, "units", + status = nc_put_att_text(nc_state_file->nc_id, node_depth_var_id, + "units", strlen("m"), "m"); check_nc_status(status, "Error adding attribute in %s", filename); dimids[0] = -1; @@ -1831,13 +1844,15 @@ initialize_state_file(char *filename, dimids[0] = nc_state_file->lake_node_dimid; status = nc_def_var(nc_state_file->nc_id, "lake_node", NC_INT, 1, dimids, &(lake_node_var_id)); - check_nc_status(status, "Error defining node variable in %s", filename); + check_nc_status(status, "Error defining node variable in %s", + filename); status = nc_put_att_text(nc_state_file->nc_id, lake_node_var_id, "long_name", strlen("lake_node"), "lake_node"); check_nc_status(status, "Error adding attribute in %s", filename); status = nc_put_att_text(nc_state_file->nc_id, dz_node_var_id, - "standard_name", strlen("lake_node_number"), + "standard_name", strlen( + "lake_node_number"), "lake_node_number"); check_nc_status(status, "Error adding attribute in %s", filename); dimids[0] = -1; @@ -1883,13 +1898,17 @@ initialize_state_file(char *filename, state_metadata[i].varname, filename); // Set string attributes - put_nc_attr(nc_state_file->nc_id, nc_state_file->nc_vars[i].nc_varid, + put_nc_attr(nc_state_file->nc_id, + nc_state_file->nc_vars[i].nc_varid, "long_name", state_metadata[i].long_name); - put_nc_attr(nc_state_file->nc_id, nc_state_file->nc_vars[i].nc_varid, + put_nc_attr(nc_state_file->nc_id, + nc_state_file->nc_vars[i].nc_varid, "standard_name", state_metadata[i].standard_name); - put_nc_attr(nc_state_file->nc_id, nc_state_file->nc_vars[i].nc_varid, + put_nc_attr(nc_state_file->nc_id, + nc_state_file->nc_vars[i].nc_varid, "units", state_metadata[i].units); - put_nc_attr(nc_state_file->nc_id, nc_state_file->nc_vars[i].nc_varid, + put_nc_attr(nc_state_file->nc_id, + nc_state_file->nc_vars[i].nc_varid, "description", state_metadata[i].description); } @@ -1921,7 +1940,8 @@ initialize_state_file(char *filename, for (i = 0; i < nc_state_file->ni_size; i++) { dvar[i] = (double) global_domain.locations[i].longitude; } - status = nc_put_vara_double(nc_state_file->nc_id, lon_var_id, dstart, + status = nc_put_vara_double(nc_state_file->nc_id, lon_var_id, + dstart, dcount, dvar); check_nc_status(status, "Error adding data to lon in %s", filename); free(dvar); @@ -1938,7 +1958,8 @@ initialize_state_file(char *filename, latitude; } - status = nc_put_vara_double(nc_state_file->nc_id, lat_var_id, dstart, + status = nc_put_vara_double(nc_state_file->nc_id, lat_var_id, + dstart, dcount, dvar); check_nc_status(status, "Error adding data to lon in %s", filename); free(dvar); @@ -1952,7 +1973,8 @@ initialize_state_file(char *filename, for (i = 0; i < global_domain.ncells_total; i++) { dvar[i] = (double) global_domain.locations[i].longitude; } - status = nc_put_vara_double(nc_state_file->nc_id, lon_var_id, dstart, + status = nc_put_vara_double(nc_state_file->nc_id, lon_var_id, + dstart, dcount, dvar); check_nc_status(status, "Error adding data to lon in %s", filename); @@ -1960,7 +1982,8 @@ initialize_state_file(char *filename, i++) { dvar[i] = (double) global_domain.locations[i].latitude; } - status = nc_put_vara_double(nc_state_file->nc_id, lat_var_id, dstart, + status = nc_put_vara_double(nc_state_file->nc_id, lat_var_id, + dstart, dcount, dvar); check_nc_status(status, "Error adding data to lat in %s", filename); @@ -1984,7 +2007,8 @@ initialize_state_file(char *filename, for (j = 0; j < nc_state_file->veg_size; j++) { ivar[j] = (int) j + 1; } - status = nc_put_vara_int(nc_state_file->nc_id, veg_var_id, dstart, dcount, + status = nc_put_vara_int(nc_state_file->nc_id, veg_var_id, dstart, + dcount, ivar); check_nc_status(status, "Error writing veg var id"); for (i = 0; i < ndims; i++) { @@ -2020,7 +2044,8 @@ initialize_state_file(char *filename, for (j = 0; j < nc_state_file->layer_size; j++) { ivar[j] = (int) j; } - status = nc_put_vara_int(nc_state_file->nc_id, layer_var_id, dstart, dcount, + status = nc_put_vara_int(nc_state_file->nc_id, layer_var_id, dstart, + dcount, ivar); check_nc_status(status, "Error writing layer id"); for (i = 0; i < ndims; i++) { @@ -2038,7 +2063,8 @@ initialize_state_file(char *filename, for (j = 0; j < nc_state_file->frost_size; j++) { ivar[j] = (int) j; } - status = nc_put_vara_int(nc_state_file->nc_id, frost_area_var_id, dstart, + status = nc_put_vara_int(nc_state_file->nc_id, frost_area_var_id, + dstart, dcount, ivar); check_nc_status(status, "Error writing frost id"); for (i = 0; i < ndims; i++) { diff --git a/vic/vic_run/include/vic_log.h b/vic/vic_run/include/vic_log.h index 819e17457..cfaf4a174 100644 --- a/vic/vic_run/include/vic_log.h +++ b/vic/vic_run/include/vic_log.h @@ -126,17 +126,17 @@ void setup_logging(int id, char log_path[], FILE **logfile); // here means that it just doesn't print a message, it still does the // check. MKAY? #define check_debug(A, M, ...) if (!(A)) {debug(M, ## __VA_ARGS__); errno = 0; \ - exit(EXIT_FAILURE); } + exit(EXIT_FAILURE);} #define check(A, M, ...) if (!(A)) {log_err(M, ## __VA_ARGS__); errno = 0; exit( \ - EXIT_FAILURE); } + EXIT_FAILURE);} #define check_alloc_status(A, M, \ ...) if (A == NULL) {log_err(M, ## __VA_ARGS__); \ errno = 0; exit( \ - EXIT_FAILURE); } + EXIT_FAILURE);} #define sentinel(M, ...) {log_err(M, ## __VA_ARGS__); errno = 0; exit( \ - EXIT_FAILURE); } + EXIT_FAILURE);} #define check_mem(A) check((A), "Out of memory.") @@ -144,7 +144,7 @@ void setup_logging(int id, char log_path[], FILE **logfile); E), E, __FUNCTION__, __LINE__) #define error_response(F, C, M, ...) {Response_send_status(F, &HTTP_ ## C); \ - sentinel(M, ## __VA_ARGS__); } + sentinel(M, ## __VA_ARGS__);} #define error_unless(T, F, C, M, ...) if (!(T)) \ error_response(F, C, M, ## __VA_ARGS__) diff --git a/vic/vic_run/src/func_canopy_energy_bal.c b/vic/vic_run/src/func_canopy_energy_bal.c index 5f5a9d066..8aeea60e7 100644 --- a/vic/vic_run/src/func_canopy_energy_bal.c +++ b/vic/vic_run/src/func_canopy_energy_bal.c @@ -217,7 +217,7 @@ func_canopy_energy_bal(double Tfoliage, /* Calculate the latent heat flux */ Ls = calc_latent_heat_of_sublimation(Tfoliage); - *LatentHeatSub = Ls * *VaporMassFlux * CONST_RHOFW; + *LatentHeatSub = Ls **VaporMassFlux * CONST_RHOFW; *LatentHeat = 0; *Evap = 0; veg_var->throughfall = 0; @@ -246,7 +246,7 @@ func_canopy_energy_bal(double Tfoliage, root, dryFrac, shortwave, Catm, CanopLayerBnd); *Wdew /= MM_PER_M; - *LatentHeat = Le * *Evap * CONST_RHOFW; + *LatentHeat = Le **Evap * CONST_RHOFW; *LatentHeatSub = 0; } diff --git a/vic/vic_run/src/runoff.c b/vic/vic_run/src/runoff.c index 0466dc847..a72a988a0 100644 --- a/vic/vic_run/src/runoff.c +++ b/vic/vic_run/src/runoff.c @@ -490,15 +490,18 @@ compute_runoff_and_asat(soil_con_struct *soil_con, * @brief Calculate drainage between two layers ******************************************************************************/ double -calc_Q12(double Ksat, double init_moist, double resid_moist, - double max_moist, double expt) +calc_Q12(double Ksat, + double init_moist, + double resid_moist, + double max_moist, + double expt) { double Q12; Q12 = init_moist - pow(pow(init_moist - resid_moist, 1.0 - expt) - - Ksat / pow(max_moist - resid_moist, expt) * (1.0 - expt), - 1.0 / (1.0 - expt)) - resid_moist; + Ksat / + pow(max_moist - resid_moist, expt) * (1.0 - expt), + 1.0 / (1.0 - expt)) - resid_moist; return Q12; } - diff --git a/vic/vic_run/src/snow_intercept.c b/vic/vic_run/src/snow_intercept.c index ebc13174b..f803dbaab 100644 --- a/vic/vic_run/src/snow_intercept.c +++ b/vic/vic_run/src/snow_intercept.c @@ -518,7 +518,7 @@ snow_intercept(double Dt, /* Energy released by freezing of intercepted water is added to the MeltEnergy */ - *MeltEnergy += (CONST_LATICE * *IntRain * CONST_RHOFW) / (Dt); + *MeltEnergy += (CONST_LATICE **IntRain * CONST_RHOFW) / (Dt); *IntRain = 0.0; } From 37b606659d9296bd605f46cf67314d48525197e3 Mon Sep 17 00:00:00 2001 From: Joe Hamman Date: Thu, 16 Mar 2017 12:04:54 -0700 Subject: [PATCH 4/4] uncrustify timers --- vic/drivers/shared_image/src/vic_image_timing.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vic/drivers/shared_image/src/vic_image_timing.c b/vic/drivers/shared_image/src/vic_image_timing.c index 43d48515a..d5f0d41c6 100644 --- a/vic/drivers/shared_image/src/vic_image_timing.c +++ b/vic/drivers/shared_image/src/vic_image_timing.c @@ -148,11 +148,13 @@ write_vic_timing_table(timer_struct *timers, fprintf(LOG_DEST, "|------------|----------------------|----------------------|----------------------|----------------------|\n"); fprintf(LOG_DEST, "| Force Time | %20g | %20g | %20g | %20g |\n", - timers[TIMER_VIC_FORCE].delta_wall, timers[TIMER_VIC_FORCE].delta_cpu, + timers[TIMER_VIC_FORCE].delta_wall, + timers[TIMER_VIC_FORCE].delta_cpu, timers[TIMER_VIC_FORCE].delta_wall / ndays, timers[TIMER_VIC_FORCE].delta_cpu / ndays); fprintf(LOG_DEST, "| Write Time | %20g | %20g | %20g | %20g |\n", - timers[TIMER_VIC_WRITE].delta_wall, timers[TIMER_VIC_WRITE].delta_cpu, + timers[TIMER_VIC_WRITE].delta_wall, + timers[TIMER_VIC_WRITE].delta_cpu, timers[TIMER_VIC_WRITE].delta_wall / ndays, timers[TIMER_VIC_WRITE].delta_cpu / ndays); fprintf(LOG_DEST,