1) wraps ncdf4::ncvar_put() so that the variable name is printed before any warnings it gives
2) changes behavior of an on.exit() to remove warnings about closing nc connection multiple times
(I also snuck in removing an incorrect usage of ...)
Motivation and Context
Currently model2netcdf.ED2() prints a lot of warnings of the form
"ncvar_put: warning: you asked to write xxx values, but the passed data array has yyy entries!"
These warnings are uninformative in this context because the variable name is not printed anywhere.
Before
```
> model2netcdf.ED2("completed_runs/MANDIFORE-PNW-4538/outdir/out/ENS-00001-1000020684/", settings = settings)
2022-12-19 21:40:29 INFO [model2netcdf.ED2] :
----- Processing year: 2002
2022-12-19 21:40:29 INFO [read_E_files] :
*** Reading -E- file ***
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
2022-12-19 21:40:38 INFO [model2netcdf.ED2] :
*** Writing netCDF file ***
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
[1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
2022-12-19 21:40:38 INFO [model2netcdf.ED2] :
----- Processing year: 2003
2022-12-19 21:40:38 INFO [read_E_files] :
*** Reading -E- file ***
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
Error in R_nc4_close: NetCDF: Not a valid ID
2022-12-19 21:40:46 INFO [model2netcdf.ED2] :
*** Writing netCDF file ***
```
After
```
model2netcdf.ED2("completed_runs/MANDIFORE-PNW-4538/outdir/out/ENS-00001-1000020684/", settings = settings)
2022-12-19 21:47:34 INFO [model2netcdf.ED2] :
----- Processing year: 2002
2022-12-19 21:47:34 INFO [read_E_files] :
*** Reading -E- file ***
2022-12-19 21:47:43 INFO [model2netcdf.ED2] :
*** Writing netCDF file ***
With 'AGB_PFT': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
With 'BSEEDS': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
With 'DBH': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
With 'DDBH': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
With var 'NPP_PFT': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
With 'TRANSP_PFT': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
With 'DENS': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!"
2022-12-19 21:47:43 INFO [model2netcdf.ED2] :
----- Processing year: 2003
2022-12-19 21:47:43 INFO [read_E_files] :
*** Reading -E- file ***
2022-12-19 21:47:50 INFO [model2netcdf.ED2] :
*** Writing netCDF file ***
```
Review Time Estimate
[ ] Immediately
[ ] Within one week
[ ] When possible
Types of changes
[x] Bug fix (non-breaking change which fixes an issue)
[x] New feature (non-breaking change which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
[ ] My change requires a change to the documentation.
Description
1) wraps
ncdf4::ncvar_put()
so that the variable name is printed before any warnings it gives 2) changes behavior of anon.exit()
to remove warnings about closing nc connection multiple times(I also snuck in removing an incorrect usage of
...
)Motivation and Context
Currently
model2netcdf.ED2()
prints a lot of warnings of the formThese warnings are uninformative in this context because the variable name is not printed anywhere.
Before
``` > model2netcdf.ED2("completed_runs/MANDIFORE-PNW-4538/outdir/out/ENS-00001-1000020684/", settings = settings) 2022-12-19 21:40:29 INFO [model2netcdf.ED2] : ----- Processing year: 2002 2022-12-19 21:40:29 INFO [read_E_files] : *** Reading -E- file *** Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID 2022-12-19 21:40:38 INFO [model2netcdf.ED2] : *** Writing netCDF file *** [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" 2022-12-19 21:40:38 INFO [model2netcdf.ED2] : ----- Processing year: 2003 2022-12-19 21:40:38 INFO [read_E_files] : *** Reading -E- file *** Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID Error in R_nc4_close: NetCDF: Not a valid ID 2022-12-19 21:40:46 INFO [model2netcdf.ED2] : *** Writing netCDF file *** ```After
``` model2netcdf.ED2("completed_runs/MANDIFORE-PNW-4538/outdir/out/ENS-00001-1000020684/", settings = settings) 2022-12-19 21:47:34 INFO [model2netcdf.ED2] : ----- Processing year: 2002 2022-12-19 21:47:34 INFO [read_E_files] : *** Reading -E- file *** 2022-12-19 21:47:43 INFO [model2netcdf.ED2] : *** Writing netCDF file *** With 'AGB_PFT': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" With 'BSEEDS': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" With 'DBH': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" With 'DDBH': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" With var 'NPP_PFT': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" With 'TRANSP_PFT': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" With 'DENS': [1] "ncvar_put: warning: you asked to write 22 values, but the passed data array has 24 entries!" 2022-12-19 21:47:43 INFO [model2netcdf.ED2] : ----- Processing year: 2003 2022-12-19 21:47:43 INFO [read_E_files] : *** Reading -E- file *** 2022-12-19 21:47:50 INFO [model2netcdf.ED2] : *** Writing netCDF file *** ```Review Time Estimate
Types of changes
Checklist: