Skip to content

Commit d2b2b07

Browse files
committed
Merge pull request #202 from UW-Hydro/hotfix/4.2.2
Hotfix/4.2.b
2 parents 850701a + 7aa73f5 commit d2b2b07

File tree

4 files changed

+157
-141
lines changed

4 files changed

+157
-141
lines changed

src/ChangeLog

+24-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,30 @@ Usage:
2626

2727

2828
-------------------------------------------------------------------------------
29-
***** Description of changes between VIC 4.2.0 and VIC 4.2.1 *****
29+
***** Description of changes between VIC 4.2.a and VIC 4.2.b *****
30+
-------------------------------------------------------------------------------
31+
32+
Bug Fixes:
33+
----------
34+
35+
Fixed memory error in initialize atmos when OUTPUT_FORCE = TRUE.
36+
37+
Files Affected:
38+
39+
initialize_atmos.
40+
Makefile
41+
42+
Description:
43+
44+
Previously, access to unitialized elements of the veg_con and veg_hist
45+
structure was attempted when OUTPUT_FORCE = TRUE, causing a memory error
46+
and the model to crash. This fix sets these elements inside a
47+
`if (!options.OUTPUT_FORCE)` block allowing the OUTPUT_FORCE option to
48+
work as expected.
49+
50+
51+
-------------------------------------------------------------------------------
52+
***** Description of changes between VIC 4.2 and VIC 4.2.a *****
3053
-------------------------------------------------------------------------------
3154

3255
Bug Fixes:

src/Makefile

-10
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,6 @@ all:
136136
make depend
137137
make model
138138

139-
disagg:
140-
sed -i.bak 's/OUTPUT_FORCE FALSE/OUTPUT_FORCE TRUE/' user_def.h
141-
make clean
142-
make depend
143-
make vicDisagg
144-
sed -i.bak 's/OUTPUT_FORCE TRUE/OUTPUT_FORCE FALSE/' user_def.h
145-
make clean
146-
make depend
147-
148139
default:
149140
make depend
150141
make model
@@ -154,7 +145,6 @@ full:
154145
make depend
155146
make tags
156147
make model
157-
make disagg
158148

159149
clean::
160150
/bin/rm -f *.o core log *~

src/global.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
2013-Dec-27 Removed QUICK_FS option. TJB
2323
2014-May-20 Added ref_veg_vegcover. TJB
2424
**********************************************************************/
25-
char *version = "4.2.1 2014-December-21";
25+
char *version = "4.2.b 2015-January-22";
2626
char *optstring = "g:vo";
2727
int flag;
2828

src/initialize_atmos.c

+132-129
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,11 @@ void initialize_atmos(atmos_data_struct *atmos,
255255
// 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");
256256

257257
/* Assign N_ELEM for veg-dependent forcings */
258-
param_set.TYPE[LAI_IN].N_ELEM = veg_con[0].vegetat_type_num;
259-
param_set.TYPE[VEGCOVER].N_ELEM = veg_con[0].vegetat_type_num;
260-
param_set.TYPE[ALBEDO].N_ELEM = veg_con[0].vegetat_type_num;
261-
258+
if (!options.OUTPUT_FORCE) {
259+
param_set.TYPE[LAI_IN].N_ELEM = veg_con[0].vegetat_type_num;
260+
param_set.TYPE[VEGCOVER].N_ELEM = veg_con[0].vegetat_type_num;
261+
param_set.TYPE[ALBEDO].N_ELEM = veg_con[0].vegetat_type_num;
262+
}
262263
/* compute number of simulation days */
263264
tmp_starthour = 0;
264265
tmp_endhour = 24 - global_param.dt;
@@ -1421,172 +1422,174 @@ void initialize_atmos(atmos_data_struct *atmos,
14211422
}
14221423
}
14231424

1424-
/****************************************************
1425-
Albedo
1426-
****************************************************/
1425+
if (!options.OUTPUT_FORCE) {
14271426

1428-
/* First, assign default climatology */
1429-
for (rec = 0; rec < global_param.nrecs; rec++) {
1430-
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1431-
for (j = 0; j < NF; j++) {
1432-
veg_hist[rec][v].albedo[j] = veg_lib[veg_con[v].veg_class].albedo[dmy[rec].month-1];
1427+
/****************************************************
1428+
Albedo
1429+
****************************************************/
1430+
1431+
/* First, assign default climatology */
1432+
for (rec = 0; rec < global_param.nrecs; rec++) {
1433+
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1434+
for (j = 0; j < NF; j++) {
1435+
veg_hist[rec][v].albedo[j] = veg_lib[veg_con[v].veg_class].albedo[dmy[rec].month-1];
1436+
}
14331437
}
14341438
}
1435-
}
14361439

1437-
if(param_set.TYPE[ALBEDO].SUPPLIED) {
1438-
if(param_set.FORCE_DT[param_set.TYPE[ALBEDO].SUPPLIED-1] == 24) {
1439-
/* daily albedo provided */
1440-
for (rec = 0; rec < global_param.nrecs; rec++) {
1441-
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1442-
sum = 0;
1443-
for (j = 0; j < NF; j++) {
1444-
hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1445-
if (global_param.starthour - hour_offset_int < 0) hour += 24;
1446-
idx = (int)((float)hour/24.0);
1447-
if (local_veg_hist_data[ALBEDO][v][idx] != NODATA_VH)
1448-
veg_hist[rec][v].albedo[j] = local_veg_hist_data[ALBEDO][v][idx]; // assume constant over the day
1449-
sum += veg_hist[rec][v].albedo[j];
1440+
if(param_set.TYPE[ALBEDO].SUPPLIED) {
1441+
if(param_set.FORCE_DT[param_set.TYPE[ALBEDO].SUPPLIED-1] == 24) {
1442+
/* daily albedo provided */
1443+
for (rec = 0; rec < global_param.nrecs; rec++) {
1444+
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1445+
sum = 0;
1446+
for (j = 0; j < NF; j++) {
1447+
hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1448+
if (global_param.starthour - hour_offset_int < 0) hour += 24;
1449+
idx = (int)((float)hour/24.0);
1450+
if (local_veg_hist_data[ALBEDO][v][idx] != NODATA_VH)
1451+
veg_hist[rec][v].albedo[j] = local_veg_hist_data[ALBEDO][v][idx]; // assume constant over the day
1452+
sum += veg_hist[rec][v].albedo[j];
1453+
}
1454+
if(NF>1) veg_hist[rec][v].albedo[NR] = sum / (float)NF;
14501455
}
1451-
if(NF>1) veg_hist[rec][v].albedo[NR] = sum / (float)NF;
14521456
}
14531457
}
1454-
}
1455-
else {
1456-
/* sub-daily albedo provided */
1457-
for(rec = 0; rec < global_param.nrecs; rec++) {
1458-
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1459-
sum = 0;
1460-
for(i = 0; i < NF; i++) {
1461-
hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1462-
veg_hist[rec][v].albedo[i] = 0;
1463-
while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) {
1464-
idx = hour;
1465-
if (idx < 0) idx += 24;
1466-
if (local_veg_hist_data[ALBEDO][v][idx] != NODATA_VH)
1467-
veg_hist[rec][v].albedo[i] = local_veg_hist_data[ALBEDO][v][idx];
1468-
hour++;
1458+
else {
1459+
/* sub-daily albedo provided */
1460+
for(rec = 0; rec < global_param.nrecs; rec++) {
1461+
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1462+
sum = 0;
1463+
for(i = 0; i < NF; i++) {
1464+
hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1465+
veg_hist[rec][v].albedo[i] = 0;
1466+
while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) {
1467+
idx = hour;
1468+
if (idx < 0) idx += 24;
1469+
if (local_veg_hist_data[ALBEDO][v][idx] != NODATA_VH)
1470+
veg_hist[rec][v].albedo[i] = local_veg_hist_data[ALBEDO][v][idx];
1471+
hour++;
1472+
}
1473+
sum += veg_hist[rec][v].albedo[i];
14691474
}
1470-
sum += veg_hist[rec][v].albedo[i];
1475+
if(NF>1) veg_hist[rec][v].albedo[NR] = sum / (float)NF;
14711476
}
1472-
if(NF>1) veg_hist[rec][v].albedo[NR] = sum / (float)NF;
14731477
}
14741478
}
14751479
}
1476-
}
14771480

1478-
/****************************************************
1479-
Leaf Area Index (LAI)
1480-
****************************************************/
1481+
/****************************************************
1482+
Leaf Area Index (LAI)
1483+
****************************************************/
14811484

1482-
/* First, assign default climatology */
1483-
for (rec = 0; rec < global_param.nrecs; rec++) {
1484-
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1485-
for (j = 0; j < NF; j++) {
1486-
veg_hist[rec][v].LAI[j] = veg_lib[veg_con[v].veg_class].LAI[dmy[rec].month-1];
1485+
/* First, assign default climatology */
1486+
for (rec = 0; rec < global_param.nrecs; rec++) {
1487+
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1488+
for (j = 0; j < NF; j++) {
1489+
veg_hist[rec][v].LAI[j] = veg_lib[veg_con[v].veg_class].LAI[dmy[rec].month-1];
1490+
}
14871491
}
14881492
}
1489-
}
14901493

1491-
if(param_set.TYPE[LAI_IN].SUPPLIED) {
1492-
if(param_set.FORCE_DT[param_set.TYPE[LAI_IN].SUPPLIED-1] == 24) {
1493-
/* daily LAI provided */
1494-
for (rec = 0; rec < global_param.nrecs; rec++) {
1495-
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1496-
sum = 0;
1497-
for (j = 0; j < NF; j++) {
1498-
hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1499-
if (global_param.starthour - hour_offset_int < 0) hour += 24;
1500-
idx = (int)((float)hour/24.0);
1501-
if (local_veg_hist_data[LAI_IN][v][idx] != NODATA_VH)
1502-
veg_hist[rec][v].LAI[j] = local_veg_hist_data[LAI_IN][v][idx]; // assume constant over the day
1503-
sum += veg_hist[rec][v].LAI[j];
1494+
if(param_set.TYPE[LAI_IN].SUPPLIED) {
1495+
if(param_set.FORCE_DT[param_set.TYPE[LAI_IN].SUPPLIED-1] == 24) {
1496+
/* daily LAI provided */
1497+
for (rec = 0; rec < global_param.nrecs; rec++) {
1498+
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1499+
sum = 0;
1500+
for (j = 0; j < NF; j++) {
1501+
hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1502+
if (global_param.starthour - hour_offset_int < 0) hour += 24;
1503+
idx = (int)((float)hour/24.0);
1504+
if (local_veg_hist_data[LAI_IN][v][idx] != NODATA_VH)
1505+
veg_hist[rec][v].LAI[j] = local_veg_hist_data[LAI_IN][v][idx]; // assume constant over the day
1506+
sum += veg_hist[rec][v].LAI[j];
1507+
}
1508+
if(NF>1) veg_hist[rec][v].LAI[NR] = sum / (float)NF;
15041509
}
1505-
if(NF>1) veg_hist[rec][v].LAI[NR] = sum / (float)NF;
15061510
}
15071511
}
1508-
}
1509-
else {
1510-
/* sub-daily LAI provided */
1511-
for(rec = 0; rec < global_param.nrecs; rec++) {
1512-
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1513-
sum = 0;
1514-
for(i = 0; i < NF; i++) {
1515-
hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1516-
veg_hist[rec][v].LAI[i] = 0;
1517-
while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) {
1518-
idx = hour;
1519-
if (idx < 0) idx += 24;
1520-
if (local_veg_hist_data[LAI_IN][v][idx] != NODATA_VH)
1521-
veg_hist[rec][v].LAI[i] = local_veg_hist_data[LAI_IN][v][idx];
1522-
hour++;
1512+
else {
1513+
/* sub-daily LAI provided */
1514+
for(rec = 0; rec < global_param.nrecs; rec++) {
1515+
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1516+
sum = 0;
1517+
for(i = 0; i < NF; i++) {
1518+
hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1519+
veg_hist[rec][v].LAI[i] = 0;
1520+
while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) {
1521+
idx = hour;
1522+
if (idx < 0) idx += 24;
1523+
if (local_veg_hist_data[LAI_IN][v][idx] != NODATA_VH)
1524+
veg_hist[rec][v].LAI[i] = local_veg_hist_data[LAI_IN][v][idx];
1525+
hour++;
1526+
}
1527+
sum += veg_hist[rec][v].LAI[i];
15231528
}
1524-
sum += veg_hist[rec][v].LAI[i];
1529+
if(NF>1) veg_hist[rec][v].LAI[NR] = sum / (float)NF;
15251530
}
1526-
if(NF>1) veg_hist[rec][v].LAI[NR] = sum / (float)NF;
15271531
}
15281532
}
15291533
}
1530-
}
15311534

1532-
/****************************************************
1533-
Fractional Vegetation Cover
1534-
****************************************************/
1535+
/****************************************************
1536+
Fractional Vegetation Cover
1537+
****************************************************/
15351538

1536-
/* First, assign default climatology */
1537-
for (rec = 0; rec < global_param.nrecs; rec++) {
1538-
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1539-
for (j = 0; j < NF; j++) {
1540-
veg_hist[rec][v].vegcover[j] = veg_lib[veg_con[v].veg_class].vegcover[dmy[rec].month-1];
1539+
/* First, assign default climatology */
1540+
for (rec = 0; rec < global_param.nrecs; rec++) {
1541+
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1542+
for (j = 0; j < NF; j++) {
1543+
veg_hist[rec][v].vegcover[j] = veg_lib[veg_con[v].veg_class].vegcover[dmy[rec].month-1];
1544+
}
15411545
}
15421546
}
1543-
}
15441547

1545-
if(param_set.TYPE[VEGCOVER].SUPPLIED) {
1546-
if(param_set.FORCE_DT[param_set.TYPE[VEGCOVER].SUPPLIED-1] == 24) {
1547-
/* daily vegcover provided */
1548-
for (rec = 0; rec < global_param.nrecs; rec++) {
1549-
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1550-
sum = 0;
1551-
for (j = 0; j < NF; j++) {
1552-
hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1553-
if (global_param.starthour - hour_offset_int < 0) hour += 24;
1554-
idx = (int)((float)hour/24.0);
1555-
if (local_veg_hist_data[VEGCOVER][v][idx] != NODATA_VH) {
1556-
veg_hist[rec][v].vegcover[j] = local_veg_hist_data[VEGCOVER][v][idx]; // assume constant over the day
1557-
if (veg_hist[rec][v].vegcover[j] < MIN_VEGCOVER) veg_hist[rec][v].vegcover[j] = MIN_VEGCOVER;
1548+
if(param_set.TYPE[VEGCOVER].SUPPLIED) {
1549+
if(param_set.FORCE_DT[param_set.TYPE[VEGCOVER].SUPPLIED-1] == 24) {
1550+
/* daily vegcover provided */
1551+
for (rec = 0; rec < global_param.nrecs; rec++) {
1552+
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1553+
sum = 0;
1554+
for (j = 0; j < NF; j++) {
1555+
hour = rec*global_param.dt + j*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1556+
if (global_param.starthour - hour_offset_int < 0) hour += 24;
1557+
idx = (int)((float)hour/24.0);
1558+
if (local_veg_hist_data[VEGCOVER][v][idx] != NODATA_VH) {
1559+
veg_hist[rec][v].vegcover[j] = local_veg_hist_data[VEGCOVER][v][idx]; // assume constant over the day
1560+
if (veg_hist[rec][v].vegcover[j] < MIN_VEGCOVER) veg_hist[rec][v].vegcover[j] = MIN_VEGCOVER;
1561+
}
1562+
sum += veg_hist[rec][v].vegcover[j];
15581563
}
1559-
sum += veg_hist[rec][v].vegcover[j];
1564+
if(NF>1) veg_hist[rec][v].vegcover[NR] = sum / (float)NF;
15601565
}
1561-
if(NF>1) veg_hist[rec][v].vegcover[NR] = sum / (float)NF;
15621566
}
15631567
}
1564-
}
1565-
else {
1566-
/* sub-daily vegcover provided */
1567-
for(rec = 0; rec < global_param.nrecs; rec++) {
1568-
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1569-
sum = 0;
1570-
for(i = 0; i < NF; i++) {
1571-
hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1572-
veg_hist[rec][v].vegcover[i] = 0;
1573-
while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) {
1574-
idx = hour;
1575-
if (idx < 0) idx += 24;
1576-
if (local_veg_hist_data[VEGCOVER][v][idx] != NODATA_VH) {
1577-
veg_hist[rec][v].vegcover[i] = local_veg_hist_data[VEGCOVER][v][idx];
1578-
if (veg_hist[rec][v].vegcover[i] < MIN_VEGCOVER) veg_hist[rec][v].vegcover[i] = MIN_VEGCOVER;
1568+
else {
1569+
/* sub-daily vegcover provided */
1570+
for(rec = 0; rec < global_param.nrecs; rec++) {
1571+
for(v = 0; v < veg_con[0].vegetat_type_num; v++) {
1572+
sum = 0;
1573+
for(i = 0; i < NF; i++) {
1574+
hour = rec*global_param.dt + i*options.SNOW_STEP + global_param.starthour - hour_offset_int;
1575+
veg_hist[rec][v].vegcover[i] = 0;
1576+
while (hour < rec*global_param.dt + (i+1)*options.SNOW_STEP + global_param.starthour - hour_offset_int) {
1577+
idx = hour;
1578+
if (idx < 0) idx += 24;
1579+
if (local_veg_hist_data[VEGCOVER][v][idx] != NODATA_VH) {
1580+
veg_hist[rec][v].vegcover[i] = local_veg_hist_data[VEGCOVER][v][idx];
1581+
if (veg_hist[rec][v].vegcover[i] < MIN_VEGCOVER) veg_hist[rec][v].vegcover[i] = MIN_VEGCOVER;
1582+
}
1583+
hour++;
15791584
}
1580-
hour++;
1585+
sum += veg_hist[rec][v].vegcover[i];
15811586
}
1582-
sum += veg_hist[rec][v].vegcover[i];
1587+
if(NF>1) veg_hist[rec][v].vegcover[NR] = sum / (float)NF;
15831588
}
1584-
if(NF>1) veg_hist[rec][v].vegcover[NR] = sum / (float)NF;
15851589
}
15861590
}
15871591
}
15881592
}
1589-
15901593
/*************************************************
15911594
Cosine of Solar Zenith Angle
15921595
*************************************************/

0 commit comments

Comments
 (0)