Skip to content

Commit a9a202b

Browse files
committed
Merge branch 'hotfix/5.0.1' of github.com:UW-Hydro/VIC into hotfix/5.0.1
2 parents bbf7d9a + ef269dd commit a9a202b

18 files changed

+180
-24
lines changed

docs/Development/ReleaseNotes.md

+25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ To check which release of VIC you are running:
1313
- For VIC 4, type `vicNl -v`
1414
- For VIC 5 and later, type `vic_{classic,image}.exe -v`
1515

16+
------------------------------
17+
## VIC 5.0.1
18+
19+
**Release date: (Unreleased)**
20+
21+
#### Bug Fixes:
22+
23+
1. Fixed image driver history file name timestamp ([GH#635](https://github.com/UW-Hydro/VIC/pull/635))
24+
25+
After the fix, the timestamp appeared in the image driver output history filename is the beginning time of the time period in the file.
26+
27+
2. Fixed forceskip rounding bug ([GH#639](https://github.com/UW-Hydro/VIC/pull/639))
28+
29+
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).
30+
31+
3. Fixed a problem with image restarts when using multiple processors ([GH#638](https://github.com/UW-Hydro/VIC/pull/638))
32+
33+
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.
34+
35+
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))
36+
37+
5. Fixed a bug related to `make_lastday` function ([GH#647](https://github.com/UW-Hydro/VIC/pull/647))
38+
39+
Before the fix, the input arguments to function `make_lastday` are sometimes in a wrong order. The bug caused error when trying to write state file on a leap day.
40+
1641
------------------------------
1742

1843
## VIC 5.0.1

docs/Documentation/Drivers/Classic/RunVIC.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- Clang (`clang` version 3+)
1010

1111
VIC has also been compiled using these compilers:
12-
12+
1313
- Intel (`icc`)
1414
- PGI (`pgcc`)
1515

@@ -28,7 +28,7 @@
2828

2929
At the command prompt, type:
3030

31-
vic_classic.exe -g global_parameter_filename
31+
./vic_classic.exe -g global_parameter_filename
3232

3333
where `global_parameter_filename` = name of the global parameter file corresponding to your project.
3434

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# VIC Domain file
2+
3+
The Image Driver uses the [NetCDF](http://www.unidata.ucar.edu/software/netcdf/) file format to define model running domain.
4+
5+
Below is a list of variables in the domain netCDF file. The dimensions of the netCDF file are `lat` and `lon`. Note that here only the type of variables (i.e., MASK, AREA, FRAC, LAT and LON) is listed; corresponding variable names in the input netCDF file are specified by user in the [Global Parameter File](GlobalParam.md). All the listed variables are required.
6+
7+
| Variable | Dimension | Units | Type | Description |
8+
|------------|-------------|----------|--------|-------------|
9+
| LAT | [lat] | degree | double | Latitudes |
10+
| LON | [lon] | degree | double | Longitues |
11+
| MASK | [lat, lon] | N/A | integer | Mask of VIC run. 1 for active cells for VIC run; 0 indicates inactive grid cells. VIC will not run at grid cells with MASK = 0 or missing value. |
12+
| AREA | [lat, lon] | m2 | double | Area of grid cells. |
13+
| FRAC | [lat, lon] | N/A | double | Fraction of grid cells that is land. |
14+
15+
# Example netCDF format VIC 5 image driver domain file
16+
17+
```shell
18+
ncdump -h /ArkRed.domain.nc
19+
netcdf ArkRed.domain {
20+
dimensions:
21+
lat = 66 ;
22+
lon = 125 ;
23+
variables:
24+
int mask(lat, lon) ;
25+
mask:comment = "0 indicates grid cell is not active" ;
26+
mask:long_name = "domain mask" ;
27+
double lon(lon) ;
28+
lon:long_name = "longitude coordinate" ;
29+
lon:units = "degrees_east" ;
30+
double lat(lat) ;
31+
lat:long_name = "latitude coordinate" ;
32+
lat:units = "degrees_north" ;
33+
double frac(lat, lon) ;
34+
frac:long_name = "fraction of grid cell that is active" ;
35+
frac:units = "1" ;
36+
double area(lat, lon) ;
37+
area:standard_name = "area" ;
38+
area:long_name = "area of grid cell" ;
39+
area:units = "m2" ;
40+
41+
// global attributes:
42+
:title = "VIC domain data" ;
43+
:Conventions = "CF-1.6" ;
44+
:history = "Wed Oct 12 15:48:42 2016: ncap2 -s mask=int(mask) ArkRed.domain.nc.float_mask ArkRed.domain.nc\n",
45+
"created by ymao, 2016-09-23 18:17:58.761256" ;
46+
:user_comment = "VIC domain data" ;
47+
:source = "generated from VIC CONUS 1.8 deg model parameters, see Maurer et al. (2002) for more information" ;
48+
:nco_openmp_thread_number = 1 ;
49+
}
50+
```
51+

docs/Documentation/Drivers/Image/GlobalParam.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ See the [example file](#example-global-parameter-file) at the end of this page f
157157

158158
# Define Domain file
159159

160-
The folloiwng options describe the input domain file information.
160+
The folloiwng options describe the input domain file information. See [Domain File](Domain.md) for details about the domain file.
161161

162162
| Name | Type | Units | Description |
163163
|-------------|---------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------|

docs/Documentation/Drivers/Image/Inputs.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ To run VIC, several sets of input data are necessary:
77
* [Global Parameter File](GlobalParam.md): This is the main input file for VIC. It points VIC to the locations of the other input/output files and sets parameters that govern the simulation (e.g., start/end dates, modes of operation).
88
* [Meteorological Forcing Files](ForcingData.md): Gridded, sub-daily timeseries of meteorological variables as inputs.
99
* [Parameters File](Params.md): Spatially distributed parameters describing the land surface.
10+
* [Domain File](Domain.md): Domain information of VIC run.
1011

1112
And a few more are optional:
1213

docs/Documentation/Drivers/Image/RunVIC.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ In some versions of the MPI library (e.g. OPEN-MPI with Intel), you may also nee
4444

4545
At the command prompt, type:
4646

47-
`vic_image.exe -g global_parameter_filename.txt`
47+
./vic_image.exe -g global_parameter_filename.txt
4848

4949
where `global_parameter_filename` = name of the global parameter file corresponding to your project.
5050

5151
To run VIC image driver using multiple processors, type the following instead:
5252

53-
`mpiexec -np n_proc vic_image.exe -g global_parameter_filename.txt`
53+
mpiexec -np $n_proc ./vic_image.exe -g global_parameter_filename.txt
5454

5555
where `n_proc` = number of processors to be used
5656

5757
## Other Command Line Options
5858

5959
VIC has a few other command line options:
6060

61-
- `vic_image.exe -v`: says which version of VIC this is
62-
- `vic_image.exe -h`: prints a list of all the VIC command-line options
63-
- `vic_image.exe -o`: prints a list of all of the current compile-time settings in this executable; to change these settings, you must edit the appropriate header files (e.g. `vic_def.h` or `vic_driver_shared.h`) and recompile using `make full`.
61+
- `./vic_image.exe -v`: says which version of VIC this is
62+
- `./vic_image.exe -h`: prints a list of all the VIC command-line options
63+
- `./vic_image.exe -o`: prints a list of all of the current compile-time settings in this executable; to change these settings, you must edit the appropriate header files (e.g. `vic_def.h` or `vic_driver_shared.h`) and recompile using `make full`.

docs/Documentation/References.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Primary Historical Reference
44

5-
Liang, X., D. P. Lettenmaier, E. F. Wood, and S. J. Burges, 1994: A Simple hydrologically Based Model of Land Surface Water and Energy Fluxes for GSMs, _J. Geophys. Res._, **99**(D7), 14415-14428, [doi:10.1029/94JD00483](http://dx.doi.org/10.1029/94JD00483).
5+
Liang, X., D. P. Lettenmaier, E. F. Wood, and S. J. Burges (1994), A simple hydrologically based model of land surface water and energy fluxes for general circulation models, _J. Geophys. Res._, **99**(D7), 1441514428, [doi:10.1029/94JD00483](http://dx.doi.org/10.1029/94JD00483).
66

77
### Other Historical References
88

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pages:
6464
- 'Inputs': 'Documentation/Drivers/Image/Inputs.md'
6565
- 'Outputs': 'Documentation/Drivers/Image/Outputs.md'
6666
- 'Params': 'Documentation/Drivers/Image/Params.md'
67+
- 'Domain': 'Documentation/Drivers/Image/Domain.md'
6768
- 'RunVIC': 'Documentation/Drivers/Image/RunVIC.md'
6869
- 'Lake Param': 'Documentation/Drivers/Image/LakeParam.md'
6970
- 'StateFile': 'Documentation/Drivers/Image/StateFile.md'

tests/system/system_tests.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ STATE_FORMAT=BINARY
144144
test_description = Exact restart (falseFULL_ENERGY flaseFROZEN_SOIL) - image driver
145145
driver = image
146146
global_parameter_file = global.image.STEHE.restart.txt
147+
mpi_proc = 4
147148
expected_retval = 0
148149
check = exact_restart
149150
[[restart]]
@@ -158,6 +159,7 @@ FROZEN_SOIL=FALSE
158159
test_description = Exact restart (trueFULL_ENERGY flaseFROZEN_SOIL) - image driver
159160
driver = image
160161
global_parameter_file = global.image.STEHE.restart.txt
162+
mpi_proc = 4
161163
expected_retval = 0
162164
check = exact_restart
163165
[[restart]]
@@ -172,6 +174,7 @@ FROZEN_SOIL=FALSE
172174
test_description = Exact restart (falseFULL_ENERGY trueFROZEN_SOIL) - image driver
173175
driver = image
174176
global_parameter_file = global.image.STEHE.restart.FROZEN_SOIL.txt
177+
mpi_proc = 4
175178
expected_retval = 0
176179
check = exact_restart
177180
[[restart]]
@@ -187,6 +190,7 @@ NODES=10
187190
test_description = Exact restart (trueFULL_ENERGY trueFROZEN_SOIL) - image driver
188191
driver = image
189192
global_parameter_file = global.image.STEHE.restart.FROZEN_SOIL.txt
193+
mpi_proc = 4
190194
expected_retval = 0
191195
check = exact_restart
192196
[[restart]]

vic/drivers/classic/src/get_global_param.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ get_global_param(FILE *gp)
891891

892892

893893
// Validate simulation end date and/or number of timesteps
894-
make_lastday(global_param.endyear, global_param.calendar, lastday);
894+
make_lastday(global_param.calendar, global_param.endyear, lastday);
895895

896896
if (global_param.nrecs == 0 && global_param.endyear == 0 &&
897897
global_param.endmonth == 0 && global_param.endday == 0) {
@@ -1204,7 +1204,7 @@ get_global_param(FILE *gp)
12041204
global_param.statesec);
12051205
}
12061206
// Check for month, day in range
1207-
make_lastday(global_param.stateyear, global_param.calendar,
1207+
make_lastday(global_param.calendar, global_param.stateyear,
12081208
lastday);
12091209
if (global_param.stateday > lastday[global_param.statemonth - 1] ||
12101210
global_param.statemonth < 1 ||

vic/drivers/image/src/get_global_param.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ get_global_param(FILE *gp)
727727
}
728728

729729
// Validate simulation end date and/or number of timesteps
730-
make_lastday(global_param.endyear, global_param.calendar, lastday);
730+
make_lastday(global_param.calendar, global_param.endyear, lastday);
731731

732732
if (global_param.nrecs == 0 && global_param.endyear == 0 &&
733733
global_param.endmonth == 0 && global_param.endday == 0) {
@@ -895,7 +895,7 @@ get_global_param(FILE *gp)
895895
global_param.statesec);
896896
}
897897
// Check for month, day in range
898-
make_lastday(global_param.stateyear, global_param.calendar,
898+
make_lastday(global_param.calendar, global_param.stateyear,
899899
lastday);
900900
if (global_param.stateday > lastday[global_param.statemonth - 1] ||
901901
global_param.statemonth < 1 ||

vic/drivers/shared_all/src/make_dmy.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ make_dmy(global_param_struct *global)
9898
global->calendar, global->time_units);
9999

100100
global->forceskip[i] =
101-
(unsigned int) ((start_num - force_num) *
102-
(double) param_set.force_steps_per_day[i]);
101+
(unsigned int) round((start_num - force_num) *
102+
(double) param_set.force_steps_per_day[i]);
103103
}
104104
}
105105

vic/drivers/shared_image/include/vic_driver_shared_image.h

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ size_t get_global_domain(char *fname, domain_struct *global_domain,
201201
size_t get_nc_dimension(char *nc_name, char *dim_name);
202202
void get_nc_var_attr(char *nc_name, char *var_name, char *attr_name,
203203
char **attr);
204+
int get_nc_var_type(char *nc_name, char *var_name);
204205
int get_nc_varndimensions(char *nc_name, char *var_name);
205206
int get_nc_field_double(char *nc_name, char *var_name, size_t *start,
206207
size_t *count, double *var);

vic/drivers/shared_image/src/get_global_domain.c

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ get_global_domain(char *nc_name,
3535
bool coords_only)
3636
{
3737
int *run = NULL;
38+
int typeid;
3839
double *var = NULL;
3940
double *var_lon = NULL;
4041
double *var_lat = NULL;
@@ -60,6 +61,12 @@ get_global_domain(char *nc_name,
6061
run = malloc(global_domain->ncells_total * sizeof(*run));
6162
check_alloc_status(run, "Memory allocation error.");
6263

64+
// Check whether mask variable is int type
65+
typeid = get_nc_var_type(nc_name, global_domain->info.mask_var);
66+
if (typeid != NC_INT) {
67+
log_err("Mask variable in the domain file must be integer type.");
68+
}
69+
6370
get_nc_field_int(nc_name, global_domain->info.mask_var, d2start, d2count,
6471
run);
6572

vic/drivers/shared_image/src/get_nc_var_attr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <vic_driver_shared_image.h>
2828

2929
/******************************************************************************
30-
* @brief Get netCDF dimension.
30+
* @brief Get netCDF variable attributes.
3131
*****************************************************************************/
3232
void
3333
get_nc_var_attr(char *nc_name,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/******************************************************************************
2+
* @section DESCRIPTION
3+
*
4+
* Get netCDF variable type.
5+
*
6+
* @section LICENSE
7+
*
8+
* The Variable Infiltration Capacity (VIC) macroscale hydrological model
9+
* Copyright (C) 2016 The Computational Hydrology Group, Department of Civil
10+
* and Environmental Engineering, University of Washington.
11+
*
12+
* The VIC model is free software; you can redistribute it and/or
13+
* modify it under the terms of the GNU General Public License
14+
* as published by the Free Software Foundation; either version 2
15+
* of the License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License along with
23+
* this program; if not, write to the Free Software Foundation, Inc.,
24+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25+
*****************************************************************************/
26+
27+
#include <vic_driver_shared_image.h>
28+
29+
/******************************************************************************
30+
* @brief Get netCDF variable type.
31+
*****************************************************************************/
32+
int
33+
get_nc_var_type(char *nc_name,
34+
char *var_name)
35+
{
36+
int nc_id;
37+
int var_id;
38+
int status;
39+
int xtypep;
40+
41+
// open the netcdf file
42+
status = nc_open(nc_name, NC_NOWRITE, &nc_id);
43+
check_nc_status(status, "Error opening %s", nc_name);
44+
45+
// get variable id
46+
status = nc_inq_varid(nc_id, var_name, &var_id);
47+
check_nc_status(status, "Error getting variable id %s in %s", var_name,
48+
nc_name);
49+
50+
// get type ID
51+
status = nc_inq_var(nc_id, var_id, NULL, &xtypep, NULL, NULL, NULL);
52+
check_nc_status(status, "Error getting variable type %s in %s", var_name,
53+
nc_name);
54+
55+
// close the netcdf file
56+
status = nc_close(nc_id);
57+
check_nc_status(status, "Error closing %s", nc_name);
58+
59+
return(xtypep);
60+
}

vic/drivers/shared_image/src/vic_init_output.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -231,25 +231,29 @@ initialize_history_file(nc_file_struct *nc,
231231
case FREQ_NDAYS:
232232
sprintf(stream->filename, "%s/%s.%04d-%02d-%02d.nc",
233233
filenames.result_dir,
234-
stream->prefix, ref_dmy->year, ref_dmy->month,
235-
ref_dmy->day);
234+
stream->prefix, stream->time_bounds[0].year,
235+
stream->time_bounds[0].month,
236+
stream->time_bounds[0].day);
236237
break;
237238
case FREQ_NMONTHS:
238239
// If FREQ_NMONTHS -- filename = result_dir/prefix.YYYY-MM.nc
239240
sprintf(stream->filename, "%s/%s.%04d-%02d.nc", filenames.result_dir,
240-
stream->prefix, ref_dmy->year, ref_dmy->month);
241+
stream->prefix, stream->time_bounds[0].year,
242+
stream->time_bounds[0].month);
241243
break;
242244
case FREQ_NYEARS:
243245
// If FREQ_NYEARS -- filename = result_dir/prefix.YYYY.nc
244246
sprintf(stream->filename, "%s/%s.%04d.nc", filenames.result_dir,
245-
stream->prefix, ref_dmy->year);
247+
stream->prefix, stream->time_bounds[0].year);
246248
break;
247249
default:
248250
// For all other cases -- filename = result_dir/prefix.YYYY-MM-DD-SSSSS.nc
249251
sprintf(stream->filename, "%s/%s.%04d-%02d-%02d-%05u.nc",
250252
filenames.result_dir,
251-
stream->prefix, ref_dmy->year, ref_dmy->month,
252-
ref_dmy->day, ref_dmy->dayseconds);
253+
stream->prefix, stream->time_bounds[0].year,
254+
stream->time_bounds[0].month,
255+
stream->time_bounds[0].day,
256+
stream->time_bounds[0].dayseconds);
253257
}
254258

255259
// open the netcdf file

vic/drivers/shared_image/src/vic_restore.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ vic_restore(void)
3939
extern veg_con_map_struct *veg_con_map;
4040
extern filenames_struct filenames;
4141
extern metadata_struct state_metadata[N_STATE_VARS];
42+
extern int mpi_rank;
4243

4344
int v;
4445
size_t i;
@@ -60,8 +61,9 @@ vic_restore(void)
6061
size_t d6start[6];
6162

6263
// validate state file dimensions and coordinate variables
63-
check_init_state_file();
64-
64+
if (mpi_rank == VIC_MPI_ROOT) {
65+
check_init_state_file();
66+
}
6567
// read state variables
6668

6769
// allocate memory for variables to be stored

0 commit comments

Comments
 (0)