Skip to content
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

'sw_inputDataFromFiles' does not correctly read CO2 information from siteparam.in #77

Closed
dschlaep opened this issue Nov 18, 2017 · 4 comments

Comments

@dschlaep
Copy link
Member

path_demo3 <- system.file("extdata", "example3", package = "rSOILWAT2")
sw_in6 <- sw_inputDataFromFiles(dir = path_demo3, files.in = "files_v31.in")

swCarbon_Scenario(sw_in6)
[1] "Default"
swCarbon_Use_Bio(sw_in6)
[1] 0
swCarbon_Use_WUE(sw_in6)
[1] 0

Even though the input file has these flags set to 1 and the scenario is "RCP85":

readLines(system.file("extdata", "example3", "Input", "siteparam_v26.in", package = "rSOILWAT2"))[65:71]
[1] "# ---- CO2 Settings ----"               
[2] "# Use biomass multiplier"               
[3] "1"                                      
[4] "# Use water-usage efficiency multiplier"
[5] "1"                                      
[6] "# Scenario"                             
[7] "RCP85"       
@dschlaep
Copy link
Member Author

sw_in6 <- sw_inputDataFromFiles(dir = path_demo3, files.in = "files_v31.in")

'SW_SIT_read': use_bio_mult = 1
'SW_SIT_read': use_wue_mult = 1
'SW_SIT_read': scenario = RCP85
'onSet_swCarbon': both flags turned off (use_bio_mult = 0; use_wue_mult = 0)

==> 'SW_SIT_read' reads the correct values, but they are lost by the time function onSet_swCarbon is reached

@dschlaep
Copy link
Member Author

The values are lost because of the order functions are called:
The function onGetInputDataFromFiles has the following order of calls

  1. SW_CTL_read_inputs_from_disk() --> SW_SIT_read() // reads values from file into C variable SW_Carbon
  2. PROTECT(SW_DataList = NEW_OBJECT(swInputData)) // create S4 class rSOILWAT2 input object
  3. onGet_SW_CARBON() // create S4 class variable swCarbon
  4. onSet_swCarbon() // copy values of just defined (and empty) variable swCarbon into C variable SW_Carbon thereby overwriting any values that were read in from files on disk

@dschlaep
Copy link
Member Author

No other onSet_*/onGet_* pair of function is coded such that onGet_* calls onSet_* except the onGet_SW_CARBON.

@dschlaep
Copy link
Member Author

The onGet_* functions copy the values of a C variable into the R-typed (S4-classed rSOILWAT2) variable.
The onSet_* functions copy the values of a R-typed (S4-classed rSOILWAT2) variable into the C variable.

dschlaep added a commit to DrylandEcology/SOILWAT2 that referenced this issue Nov 18, 2017
- close DrylandEcology/rSOILWAT2#77
- The function 'onGet_SW_CARBON' did not copy the values of the C
variable `SW_Carbon` into a new created R-typed (S4-classed rSOILWAT2)
variable representation.

- fix condition of loop to copy CO2 values in function 'onSet_swCarbon'
dschlaep added a commit that referenced this issue Nov 18, 2017
- all unit tests pass except 3 in scope "rSOILWAT2 annual aggregation"
    --> close #42, close #74, close #75, close #76, close #77
- the unit test errors are because the values of the output slot
"CO2EFFECTS" are not calculated with aggregation function that is
specified --> see new issue #78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant