From 5b784eae315dedfa58c800df222d38d58c233788 Mon Sep 17 00:00:00 2001 From: Tomas Kalibera Date: Wed, 18 Oct 2023 13:37:03 +0200 Subject: [PATCH] Avoid re-opening already opened NetCDF file. --- R/netCDFwriteCD.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/netCDFwriteCD.R b/R/netCDFwriteCD.R index ecfff799..b35d5d9f 100644 --- a/R/netCDFwriteCD.R +++ b/R/netCDFwriteCD.R @@ -160,12 +160,18 @@ } -.stopWriteCDF <- function(x) { +.writeRangeCDF <- function(x) { + nc <- ncdf4::nc_open(x@file@name, write=TRUE) on.exit( ncdf4::nc_close(nc) ) ncdf4::ncatt_put(nc, x@title, 'min', as.numeric(x@data@min)) ncdf4::ncatt_put(nc, x@title, 'max', as.numeric(x@data@max)) +} + + +.stopWriteCDF <- function(x) { + .writeRangeCDF(x) if (inherits(x, 'RasterBrick')) { r <- brick(x@file@name) } else {