-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix to state file i/o problems and refactoring of initialization #464
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f963693
Fix to state file i/o problems and refactoring of initialization into…
tbohn e379d32
Merge branch 'develop' into feature/state_refactor
tbohn 5521c0d
Fixed minor typos in comments and messages.
tbohn beb15b3
Miscellaneous updates in response to review comments.
tbohn 358ef70
Miscellaneous fixes in response to review comments.
tbohn e447bbe
Merge branch 'develop' into feature/state_refactor
tbohn 8b3cb99
Fixed remaining merge conflict.
tbohn 3b8c9c4
Fixed call to vic_store().
tbohn f056579
Changes in response to review comments.
tbohn b9fd38d
Merge branch 'develop' into feature/state_refactor
tbohn ec37a35
Moved initialization of frost fractions to read_soilparam() and vic_i…
tbohn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/****************************************************************************** | ||
* @section DESCRIPTION | ||
* | ||
* Function to check whether model state should be saved for the current | ||
* time step | ||
* | ||
* @section LICENSE | ||
* | ||
* The Variable Infiltration Capacity (VIC) macroscale hydrological model | ||
* Copyright (C) 2014 The Land Surface Hydrology Group, Department of Civil | ||
* and Environmental Engineering, University of Washington. | ||
* | ||
* The VIC model is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*****************************************************************************/ | ||
|
||
#include <vic_driver_classic.h> | ||
|
||
/****************************************************************************** | ||
* @brief Function to check whether model state should be saved for the | ||
* current time step | ||
*****************************************************************************/ | ||
bool | ||
check_save_state_flag(dmy_struct *dmy, | ||
size_t current) | ||
{ | ||
extern global_param_struct global_param; | ||
|
||
if (dmy[current].year == global_param.stateyear && | ||
dmy[current].month == global_param.statemonth && | ||
dmy[current].day == global_param.stateday && | ||
dmy[current].dayseconds == global_param.statesec) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -416,6 +416,9 @@ get_global_param(FILE *gp) | |
else if (strcasecmp("STATEDAY", optstr) == 0) { | ||
sscanf(cmdstr, "%*s %hu", &global_param.stateday); | ||
} | ||
else if (strcasecmp("STATESEC", optstr) == 0) { | ||
sscanf(cmdstr, "%*s %u", &global_param.statesec); | ||
} | ||
else if (strcasecmp("STATE_FORMAT", optstr) == 0) { | ||
sscanf(cmdstr, "%*s %s", flgstr); | ||
if (strcasecmp("BINARY", flgstr) == 0) { | ||
|
@@ -1397,32 +1400,36 @@ get_global_param(FILE *gp) | |
if (global_param.stateyear == 0 || global_param.statemonth == 0 || | ||
global_param.stateday == 0) { | ||
log_err("Incomplete specification of the date to save state " | ||
"for state file (%s). Specified date (yyyy-mm-dd): " | ||
"%04d-%02d-%02d Make sure STATEYEAR, STATEMONTH, and " | ||
"STATEDAY are set correctly in your global parameter " | ||
"for state file (%s).\nSpecified date (yyyy-mm-dd-sssss): " | ||
"%04d-%02d-%02d-%05u\nMake sure STATEYEAR, STATEMONTH, " | ||
"and STATEDAY are set correctly in your global parameter " | ||
"file.", filenames.statefile, global_param.stateyear, | ||
global_param.statemonth, global_param.stateday); | ||
global_param.statemonth, global_param.stateday, | ||
global_param.statesec); | ||
} | ||
// Check for month, day in range | ||
make_lastday(global_param.stateyear, global_param.calendar, | ||
lastday); | ||
if (global_param.stateday > lastday[global_param.statemonth - 1] || | ||
global_param.statemonth > MONTHS_PER_YEAR || | ||
global_param.statemonth < 1 || | ||
global_param.stateday < 1) { | ||
log_err("Unusual specification of the date to save state for " | ||
"state file (%s). Specified date (yyyy-mm-dd): " | ||
"%04d-%02d-%02d Make sure STATEYEAR, STATEMONTH, and " | ||
"STATEDAY are set correctly in your global parameter " | ||
"file.", filenames.statefile, global_param.stateyear, | ||
global_param.statemonth, global_param.stateday); | ||
global_param.statemonth > MONTHS_PER_YEAR || | ||
global_param.stateday < 1 || global_param.stateday > 31 || | ||
global_param.statesec > SEC_PER_DAY) { | ||
log_err("Unusual specification of the date to save state " | ||
"for state file (%s).\nSpecified date (yyyy-mm-dd-sssss): " | ||
"%04d-%02d-%02d-%05u\nMake sure STATEYEAR, STATEMONTH, " | ||
"STATEDAY and STATESEC are set correctly in your global " | ||
"parameter file.", filenames.statefile, | ||
global_param.stateyear, global_param.statemonth, | ||
global_param.stateday, global_param.statesec); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above on seconds vs. hours. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
} | ||
} | ||
// Set the statename here to be able to compare with INIT_STATE name | ||
if (options.SAVE_STATE) { | ||
sprintf(filenames.statefile, "%s_%04i%02i%02i", filenames.statefile, | ||
global_param.stateyear, global_param.statemonth, | ||
global_param.stateday); | ||
sprintf(filenames.statefile, "%s_%04i%02i%02i_%05u", | ||
filenames.statefile, global_param.stateyear, | ||
global_param.statemonth, global_param.stateday, | ||
global_param.statesec); | ||
} | ||
if (options.INIT_STATE && options.SAVE_STATE && | ||
(strcmp(filenames.init_state, filenames.statefile) == 0)) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have
-hh
but this is seconds here. Maybe-sssss
is better?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.