Skip to content

Commit

Permalink
Merge pull request #3078 from PecanProject/ncvar_put-debug
Browse files Browse the repository at this point in the history
Better debugging for `model2netcdf.ED2`
  • Loading branch information
dlebauer authored Jan 10, 2023
2 parents d027384 + bcc8fc8 commit 21184bb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ see if you need to change any of these:
- Initial LDNDC model coupling
- `PEcAn.settings::read.settings()` now strips comments so HTML style comments (e.g. `<!-- a comment -->`) are now allowed in pecan.xml files
- `PEcAn.logger::setLevel()` now invisibly returns the previously set logger level
- Warning messages for `model2netcdf.ed2()` coming from `ncdf4::ncvar_put()` now are prepended with the variable name for easier debugging (#3078)
- Added optional `process_partial` argument to `model2netcdf.ED2()` to allow it to process existing output from failed runs.

We are slowly change the license from NCSA opensource to BSD-3 to help with publishing PEcAn to CRAN.
Expand Down Expand Up @@ -64,9 +65,9 @@ convert data for a single PFT fixed (#1329, #2974, #2981)
the cdo_setup argument in the template job file. In detail, people will need
to specify cdosetup = "module load cdo/2.0.6" in the host section. More details
are in the Create_Multi_settings.R script. (#3052)
- Fixed a bug in `model2netcdf.ed2()` where .nc file connections were being closed multiple times, printing warnings (#3078)
- Fixed a bug causing the model2netcdf.ED2() step in jobs.sh to be incorrectly written (#3075)


### Changed

- Using R4.0 and R4.1 tags to build PEcAn. Default is now 4.1
Expand Down
7 changes: 5 additions & 2 deletions models/ed/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# PEcAn.ED2 (development version)

* Warning messages for `model2netcdf.ed2()` coming from `ncdf4::ncvar_put()` now are prepended with the variable name for easier debugging (#3078)
* Fixed a bug in `model2netcdf.ed2()` where .nc file connections were being closed multiple times, printing warnings (#3078)
* Fixed a bug affecting the generation of job.sh for runs with many PFTs (#3075)
* Added optional `process_partial` argument to `model2netcdf.ED2()` to allow it to process existing output from failed runs.

# PEcAn.ED2 1.7.2
# PEcAn.ED2 1.7.2.9000

* Added a `NEWS.md` file to track changes to the package. Prior to this point, PEcAn.ED2 development was tracked in the main PEcAn NEWS file.
* Added a `NEWS.md` file to track changes to the package. Prior to this point changes are tracked in the main CHANGELOG for the PEcAn repository.
* Added optional `process_partial` argument to `model2netcdf.ED2()` to allow it to process existing output from failed
15 changes: 13 additions & 2 deletions models/ed/R/model2netcdf.ED2.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ model2netcdf.ED2 <- function(outdir,
varfile <- file(file.path(outdir, paste(y, "nc", "var", sep = ".")), "w")
# fill nc file with data
for (i in seq_along(nc_var)) {
ncdf4::ncvar_put(nc, varid = nc_var[[i]], vals = out[[i]])
var_put(nc, varid = nc_var[[i]], vals = out[[i]])
cat(paste(nc_var[[i]]$name, nc_var[[i]]$longname), file = varfile,
sep = "\n")
}
Expand Down Expand Up @@ -1027,7 +1027,7 @@ read_E_files <- function(yr, yfiles, h5_files, outdir, start_date, end_date,
for(i in ysel) {

nc <- ncdf4::nc_open(file.path(outdir, h5_files[i]))
on.exit(ncdf4::nc_close(nc), add = TRUE)
on.exit(ncdf4::nc_close(nc), add = FALSE)
allvars <- names(nc$var)
if (!is.null(vars)) allvars <- allvars[ allvars %in% vars ]

Expand Down Expand Up @@ -1542,5 +1542,16 @@ extract_pfts <- function(pfts) {
pfts_out
}


# A version of ncvar_put that returns the varid in warning messages
var_put <- function(nc, varid, vals, start = NA, count = NA) {
output <- utils::capture.output(
ncdf4::ncvar_put(nc = nc, varid = varid, vals = vals, start = start, count = count)
)
if(length(output)!=0) {
cat(paste0("With '", varid$name, "':"), output, "\n")
}
}

##-------------------------------------------------------------------------------------------------#
### EOF
2 changes: 1 addition & 1 deletion models/ed/R/read_ed_veg.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ read_css <- function(filepath, check = TRUE, ...) {
read_pss <- function(filepath, check = TRUE) {
pss <- read.table(filepath, header = TRUE)
if (check) {
check_pss(pss, ...)
check_pss(pss)
}
pss
}
Expand Down

0 comments on commit 21184bb

Please sign in to comment.