From a3c282959055cb840ff9ab1876ac71320870c93a Mon Sep 17 00:00:00 2001 From: Joe Hamman Date: Thu, 22 Jan 2015 07:56:58 -0800 Subject: [PATCH 1/4] fix `make full` error that still references user_def.h and disagg --- src/Makefile | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Makefile b/src/Makefile index 410dda275..d597eda58 100644 --- a/src/Makefile +++ b/src/Makefile @@ -136,15 +136,6 @@ all: make depend make model -disagg: - sed -i.bak 's/OUTPUT_FORCE FALSE/OUTPUT_FORCE TRUE/' user_def.h - make clean - make depend - make vicDisagg - sed -i.bak 's/OUTPUT_FORCE TRUE/OUTPUT_FORCE FALSE/' user_def.h - make clean - make depend - default: make depend make model @@ -154,7 +145,6 @@ full: make depend make tags make model - make disagg clean:: /bin/rm -f *.o core log *~ From 875509f9c09e617431537bbcd81b030c331f2512 Mon Sep 17 00:00:00 2001 From: Joe Hamman Date: Thu, 22 Jan 2015 09:14:50 -0800 Subject: [PATCH 2/4] fix segfault in initialize_atmos from bad access to veg structures when OUTPUT_FORCE=TRUE --- src/ChangeLog | 22 ++++ src/global.h | 2 +- src/initialize_atmos.c | 261 +++++++++++++++++++++-------------------- 3 files changed, 155 insertions(+), 130 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f69cb9927..e75569dc0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -25,6 +25,28 @@ Usage: +------------------------------------------------------------------------------- +***** Description of changes between VIC 4.2.1 and VIC 4.2.2 ***** +------------------------------------------------------------------------------- + +Bug Fixes: +---------- + +Fixed memory error in initialize atmos when OUTPUT_FORCE = TRUE. + + Files Affected: + + initialize_atmos. + Makefile + + Description: + + Previously, access to unitialized elements of the veg_con and veg_hist + structure was attempted when OUTPUT_FORCE = TRUE, causing a memory error + and the model to crash. This fix sets these elements inside a + `if (!options.OUTPUT_FORCE)` block allowing the OUTPUT_FORCE option to work as expected. + + ------------------------------------------------------------------------------- ***** Description of changes between VIC 4.2.0 and VIC 4.2.1 ***** ------------------------------------------------------------------------------- diff --git a/src/global.h b/src/global.h index ba6fa9fd4..ea489db9b 100644 --- a/src/global.h +++ b/src/global.h @@ -22,7 +22,7 @@ 2013-Dec-27 Removed QUICK_FS option. TJB 2014-May-20 Added ref_veg_vegcover. TJB **********************************************************************/ -char *version = "4.2.1 2014-December-21"; +char *version = "4.2.2 2015-January-23"; char *optstring = "g:vo"; int flag; diff --git a/src/initialize_atmos.c b/src/initialize_atmos.c index ac64b41a3..a4af63d43 100644 --- a/src/initialize_atmos.c +++ b/src/initialize_atmos.c @@ -255,10 +255,11 @@ void initialize_atmos(atmos_data_struct *atmos, // nrerror("Input meteorological forcing files must contain either WIND (wind speed) or both WIND_N (north component of wind speed) and WIND_E (east component of wind speed); check input files\n"); /* Assign N_ELEM for veg-dependent forcings */ - param_set.TYPE[LAI_IN].N_ELEM = veg_con[0].vegetat_type_num; - param_set.TYPE[VEGCOVER].N_ELEM = veg_con[0].vegetat_type_num; - param_set.TYPE[ALBEDO].N_ELEM = veg_con[0].vegetat_type_num; - + if (!options.OUTPUT_FORCE) { + param_set.TYPE[LAI_IN].N_ELEM = veg_con[0].vegetat_type_num; + param_set.TYPE[VEGCOVER].N_ELEM = veg_con[0].vegetat_type_num; + param_set.TYPE[ALBEDO].N_ELEM = veg_con[0].vegetat_type_num; + } /* compute number of simulation days */ tmp_starthour = 0; tmp_endhour = 24 - global_param.dt; @@ -1421,172 +1422,174 @@ void initialize_atmos(atmos_data_struct *atmos, } } - /**************************************************** - Albedo - ****************************************************/ + if (!options.OUTPUT_FORCE) { - /* First, assign default climatology */ - for (rec = 0; rec < global_param.nrecs; rec++) { - for(v = 0; v < veg_con[0].vegetat_type_num; v++) { - for (j = 0; j < NF; j++) { - veg_hist[rec][v].albedo[j] = veg_lib[veg_con[v].veg_class].albedo[dmy[rec].month-1]; + /**************************************************** + Albedo + ****************************************************/ + + /* First, assign default climatology */ + for (rec = 0; rec < global_param.nrecs; rec++) { + for(v = 0; v < veg_con[0].vegetat_type_num; v++) { + for (j = 0; j < NF; j++) { + veg_hist[rec][v].albedo[j] = veg_lib[veg_con[v].veg_class].albedo[dmy[rec].month-1]; + } } } - } - if(param_set.TYPE[ALBEDO].SUPPLIED) { - if(param_set.FORCE_DT[param_set.TYPE[ALBEDO].SUPPLIED-1] == 24) { - /* daily albedo provided */ - for (rec = 0; rec < global_param.nrecs; rec++) { - for(v = 0; v < veg_con[0].vegetat_type_num; v++) { - sum = 0; - for (j = 0; j < NF; j++) { - hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int; - if (global_param.starthour - hour_offset_int < 0) hour += 24; - idx = (int)((float)hour/24.0); - if (local_veg_hist_data[ALBEDO][v][idx] != NODATA_VH) - veg_hist[rec][v].albedo[j] = local_veg_hist_data[ALBEDO][v][idx]; // assume constant over the day - sum += veg_hist[rec][v].albedo[j]; + if(param_set.TYPE[ALBEDO].SUPPLIED) { + if(param_set.FORCE_DT[param_set.TYPE[ALBEDO].SUPPLIED-1] == 24) { + /* daily albedo provided */ + for (rec = 0; rec < global_param.nrecs; rec++) { + for(v = 0; v < veg_con[0].vegetat_type_num; v++) { + sum = 0; + for (j = 0; j < NF; j++) { + hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int; + if (global_param.starthour - hour_offset_int < 0) hour += 24; + idx = (int)((float)hour/24.0); + if (local_veg_hist_data[ALBEDO][v][idx] != NODATA_VH) + veg_hist[rec][v].albedo[j] = local_veg_hist_data[ALBEDO][v][idx]; // assume constant over the day + sum += veg_hist[rec][v].albedo[j]; + } + if(NF>1) veg_hist[rec][v].albedo[NR] = sum / (float)NF; } - if(NF>1) veg_hist[rec][v].albedo[NR] = sum / (float)NF; } } - } - else { - /* sub-daily albedo provided */ - for(rec = 0; rec < global_param.nrecs; rec++) { - for(v = 0; v < veg_con[0].vegetat_type_num; v++) { - sum = 0; - for(i = 0; i < NF; i++) { - hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int; - veg_hist[rec][v].albedo[i] = 0; - while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) { - idx = hour; - if (idx < 0) idx += 24; - if (local_veg_hist_data[ALBEDO][v][idx] != NODATA_VH) - veg_hist[rec][v].albedo[i] = local_veg_hist_data[ALBEDO][v][idx]; - hour++; + else { + /* sub-daily albedo provided */ + for(rec = 0; rec < global_param.nrecs; rec++) { + for(v = 0; v < veg_con[0].vegetat_type_num; v++) { + sum = 0; + for(i = 0; i < NF; i++) { + hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int; + veg_hist[rec][v].albedo[i] = 0; + while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) { + idx = hour; + if (idx < 0) idx += 24; + if (local_veg_hist_data[ALBEDO][v][idx] != NODATA_VH) + veg_hist[rec][v].albedo[i] = local_veg_hist_data[ALBEDO][v][idx]; + hour++; + } + sum += veg_hist[rec][v].albedo[i]; } - sum += veg_hist[rec][v].albedo[i]; + if(NF>1) veg_hist[rec][v].albedo[NR] = sum / (float)NF; } - if(NF>1) veg_hist[rec][v].albedo[NR] = sum / (float)NF; } } } - } - /**************************************************** - Leaf Area Index (LAI) - ****************************************************/ + /**************************************************** + Leaf Area Index (LAI) + ****************************************************/ - /* First, assign default climatology */ - for (rec = 0; rec < global_param.nrecs; rec++) { - for(v = 0; v < veg_con[0].vegetat_type_num; v++) { - for (j = 0; j < NF; j++) { - veg_hist[rec][v].LAI[j] = veg_lib[veg_con[v].veg_class].LAI[dmy[rec].month-1]; + /* First, assign default climatology */ + for (rec = 0; rec < global_param.nrecs; rec++) { + for(v = 0; v < veg_con[0].vegetat_type_num; v++) { + for (j = 0; j < NF; j++) { + veg_hist[rec][v].LAI[j] = veg_lib[veg_con[v].veg_class].LAI[dmy[rec].month-1]; + } } } - } - if(param_set.TYPE[LAI_IN].SUPPLIED) { - if(param_set.FORCE_DT[param_set.TYPE[LAI_IN].SUPPLIED-1] == 24) { - /* daily LAI provided */ - for (rec = 0; rec < global_param.nrecs; rec++) { - for(v = 0; v < veg_con[0].vegetat_type_num; v++) { - sum = 0; - for (j = 0; j < NF; j++) { - hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int; - if (global_param.starthour - hour_offset_int < 0) hour += 24; - idx = (int)((float)hour/24.0); - if (local_veg_hist_data[LAI_IN][v][idx] != NODATA_VH) - veg_hist[rec][v].LAI[j] = local_veg_hist_data[LAI_IN][v][idx]; // assume constant over the day - sum += veg_hist[rec][v].LAI[j]; + if(param_set.TYPE[LAI_IN].SUPPLIED) { + if(param_set.FORCE_DT[param_set.TYPE[LAI_IN].SUPPLIED-1] == 24) { + /* daily LAI provided */ + for (rec = 0; rec < global_param.nrecs; rec++) { + for(v = 0; v < veg_con[0].vegetat_type_num; v++) { + sum = 0; + for (j = 0; j < NF; j++) { + hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int; + if (global_param.starthour - hour_offset_int < 0) hour += 24; + idx = (int)((float)hour/24.0); + if (local_veg_hist_data[LAI_IN][v][idx] != NODATA_VH) + veg_hist[rec][v].LAI[j] = local_veg_hist_data[LAI_IN][v][idx]; // assume constant over the day + sum += veg_hist[rec][v].LAI[j]; + } + if(NF>1) veg_hist[rec][v].LAI[NR] = sum / (float)NF; } - if(NF>1) veg_hist[rec][v].LAI[NR] = sum / (float)NF; } } - } - else { - /* sub-daily LAI provided */ - for(rec = 0; rec < global_param.nrecs; rec++) { - for(v = 0; v < veg_con[0].vegetat_type_num; v++) { - sum = 0; - for(i = 0; i < NF; i++) { - hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int; - veg_hist[rec][v].LAI[i] = 0; - while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) { - idx = hour; - if (idx < 0) idx += 24; - if (local_veg_hist_data[LAI_IN][v][idx] != NODATA_VH) - veg_hist[rec][v].LAI[i] = local_veg_hist_data[LAI_IN][v][idx]; - hour++; + else { + /* sub-daily LAI provided */ + for(rec = 0; rec < global_param.nrecs; rec++) { + for(v = 0; v < veg_con[0].vegetat_type_num; v++) { + sum = 0; + for(i = 0; i < NF; i++) { + hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int; + veg_hist[rec][v].LAI[i] = 0; + while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) { + idx = hour; + if (idx < 0) idx += 24; + if (local_veg_hist_data[LAI_IN][v][idx] != NODATA_VH) + veg_hist[rec][v].LAI[i] = local_veg_hist_data[LAI_IN][v][idx]; + hour++; + } + sum += veg_hist[rec][v].LAI[i]; } - sum += veg_hist[rec][v].LAI[i]; + if(NF>1) veg_hist[rec][v].LAI[NR] = sum / (float)NF; } - if(NF>1) veg_hist[rec][v].LAI[NR] = sum / (float)NF; } } } - } - /**************************************************** - Fractional Vegetation Cover - ****************************************************/ + /**************************************************** + Fractional Vegetation Cover + ****************************************************/ - /* First, assign default climatology */ - for (rec = 0; rec < global_param.nrecs; rec++) { - for(v = 0; v < veg_con[0].vegetat_type_num; v++) { - for (j = 0; j < NF; j++) { - veg_hist[rec][v].vegcover[j] = veg_lib[veg_con[v].veg_class].vegcover[dmy[rec].month-1]; + /* First, assign default climatology */ + for (rec = 0; rec < global_param.nrecs; rec++) { + for(v = 0; v < veg_con[0].vegetat_type_num; v++) { + for (j = 0; j < NF; j++) { + veg_hist[rec][v].vegcover[j] = veg_lib[veg_con[v].veg_class].vegcover[dmy[rec].month-1]; + } } } - } - if(param_set.TYPE[VEGCOVER].SUPPLIED) { - if(param_set.FORCE_DT[param_set.TYPE[VEGCOVER].SUPPLIED-1] == 24) { - /* daily vegcover provided */ - for (rec = 0; rec < global_param.nrecs; rec++) { - for(v = 0; v < veg_con[0].vegetat_type_num; v++) { - sum = 0; - for (j = 0; j < NF; j++) { - hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int; - if (global_param.starthour - hour_offset_int < 0) hour += 24; - idx = (int)((float)hour/24.0); - if (local_veg_hist_data[VEGCOVER][v][idx] != NODATA_VH) { - veg_hist[rec][v].vegcover[j] = local_veg_hist_data[VEGCOVER][v][idx]; // assume constant over the day - if (veg_hist[rec][v].vegcover[j] < MIN_VEGCOVER) veg_hist[rec][v].vegcover[j] = MIN_VEGCOVER; + if(param_set.TYPE[VEGCOVER].SUPPLIED) { + if(param_set.FORCE_DT[param_set.TYPE[VEGCOVER].SUPPLIED-1] == 24) { + /* daily vegcover provided */ + for (rec = 0; rec < global_param.nrecs; rec++) { + for(v = 0; v < veg_con[0].vegetat_type_num; v++) { + sum = 0; + for (j = 0; j < NF; j++) { + hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int; + if (global_param.starthour - hour_offset_int < 0) hour += 24; + idx = (int)((float)hour/24.0); + if (local_veg_hist_data[VEGCOVER][v][idx] != NODATA_VH) { + veg_hist[rec][v].vegcover[j] = local_veg_hist_data[VEGCOVER][v][idx]; // assume constant over the day + if (veg_hist[rec][v].vegcover[j] < MIN_VEGCOVER) veg_hist[rec][v].vegcover[j] = MIN_VEGCOVER; + } + sum += veg_hist[rec][v].vegcover[j]; } - sum += veg_hist[rec][v].vegcover[j]; + if(NF>1) veg_hist[rec][v].vegcover[NR] = sum / (float)NF; } - if(NF>1) veg_hist[rec][v].vegcover[NR] = sum / (float)NF; } } - } - else { - /* sub-daily vegcover provided */ - for(rec = 0; rec < global_param.nrecs; rec++) { - for(v = 0; v < veg_con[0].vegetat_type_num; v++) { - sum = 0; - for(i = 0; i < NF; i++) { - hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int; - veg_hist[rec][v].vegcover[i] = 0; - while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) { - idx = hour; - if (idx < 0) idx += 24; - if (local_veg_hist_data[VEGCOVER][v][idx] != NODATA_VH) { - veg_hist[rec][v].vegcover[i] = local_veg_hist_data[VEGCOVER][v][idx]; - if (veg_hist[rec][v].vegcover[i] < MIN_VEGCOVER) veg_hist[rec][v].vegcover[i] = MIN_VEGCOVER; + else { + /* sub-daily vegcover provided */ + for(rec = 0; rec < global_param.nrecs; rec++) { + for(v = 0; v < veg_con[0].vegetat_type_num; v++) { + sum = 0; + for(i = 0; i < NF; i++) { + hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int; + veg_hist[rec][v].vegcover[i] = 0; + while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) { + idx = hour; + if (idx < 0) idx += 24; + if (local_veg_hist_data[VEGCOVER][v][idx] != NODATA_VH) { + veg_hist[rec][v].vegcover[i] = local_veg_hist_data[VEGCOVER][v][idx]; + if (veg_hist[rec][v].vegcover[i] < MIN_VEGCOVER) veg_hist[rec][v].vegcover[i] = MIN_VEGCOVER; + } + hour++; } - hour++; + sum += veg_hist[rec][v].vegcover[i]; } - sum += veg_hist[rec][v].vegcover[i]; + if(NF>1) veg_hist[rec][v].vegcover[NR] = sum / (float)NF; } - if(NF>1) veg_hist[rec][v].vegcover[NR] = sum / (float)NF; } } } } - /************************************************* Cosine of Solar Zenith Angle *************************************************/ From 705b1d650eaacee5e9f0587bf28f8a7dcf11603f Mon Sep 17 00:00:00 2001 From: Joe Hamman Date: Thu, 22 Jan 2015 10:34:43 -0800 Subject: [PATCH 3/4] update release name and ChangeLog --- src/ChangeLog | 3 ++- src/global.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index e75569dc0..55568f4c5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -44,7 +44,8 @@ Fixed memory error in initialize atmos when OUTPUT_FORCE = TRUE. Previously, access to unitialized elements of the veg_con and veg_hist structure was attempted when OUTPUT_FORCE = TRUE, causing a memory error and the model to crash. This fix sets these elements inside a - `if (!options.OUTPUT_FORCE)` block allowing the OUTPUT_FORCE option to work as expected. + `if (!options.OUTPUT_FORCE)` block allowing the OUTPUT_FORCE option to + work as expected. ------------------------------------------------------------------------------- diff --git a/src/global.h b/src/global.h index ea489db9b..16c1a6757 100644 --- a/src/global.h +++ b/src/global.h @@ -22,7 +22,7 @@ 2013-Dec-27 Removed QUICK_FS option. TJB 2014-May-20 Added ref_veg_vegcover. TJB **********************************************************************/ -char *version = "4.2.2 2015-January-23"; +char *version = "4.2.b 2015-January-22"; char *optstring = "g:vo"; int flag; From 7aa73f57d07325ddccb4add0028c0cd85292f7bc Mon Sep 17 00:00:00 2001 From: Joe Hamman Date: Thu, 22 Jan 2015 10:37:50 -0800 Subject: [PATCH 4/4] Update ChageLog for new 4.2 version numbering. --- src/ChangeLog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 55568f4c5..9b6e69a34 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -26,7 +26,7 @@ Usage: ------------------------------------------------------------------------------- -***** Description of changes between VIC 4.2.1 and VIC 4.2.2 ***** +***** Description of changes between VIC 4.2.a and VIC 4.2.b ***** ------------------------------------------------------------------------------- Bug Fixes: @@ -49,7 +49,7 @@ Fixed memory error in initialize atmos when OUTPUT_FORCE = TRUE. ------------------------------------------------------------------------------- -***** Description of changes between VIC 4.2.0 and VIC 4.2.1 ***** +***** Description of changes between VIC 4.2 and VIC 4.2.a ***** ------------------------------------------------------------------------------- Bug Fixes: