Commit 71ff3cfe authored by Nicolau Manubens Gil's avatar Nicolau Manubens Gil
Browse files

Merge branch 'develop-global_attrs' into 'master'

Develop global attrs

See merge request !18
parents c0476862 50b46707
......@@ -23,7 +23,10 @@ ArrayToNc <- function(arrays, file_path) {
} else {
vars_info <- NULL
}
global_attrs[names(array_attrs)] <- array_attrs
#global_attrs[names(array_attrs)] <- array_attrs
if ('global_attrs' %in% names(array_attrs)) {
global_attrs <- c(global_attrs, array_attrs[['global_attrs']])
}
var_dim <- which(names(dim(arrays[[i]])) %in% c('var', 'variable'))
if (length(var_dim) > 0) {
var_dim <- var_dim[1]
......@@ -323,6 +326,12 @@ ArrayToNc <- function(arrays, file_path) {
var_counter <- var_counter + 1
}
}
# Adding global attributes
if (length(global_attrs) > 0) {
for (attr_name in names(global_attrs)) {
ncatt_put(ncdf_object, 0, attr_name, global_attrs[[attr_name]])
}
}
nc_close(ncdf_object)
invisible(NULL)
}
......
......@@ -155,6 +155,17 @@ attr(a, 'variables') <- metadata
names(dim(a)) <- c('lat', 'lon', 'time', 'var')
ArrayToNc(a, 'tmp.nc')
# Global attributes can be specified
a <- array(rnorm(10), dim = c(a = 5, b = 2))
attrs <- list(variables =
list(tas = list(var_attr_1 = 'test_1_var',
var_attr_2 = 2)),
global_attrs = list(global_attr_name_1 = 'test_1_global',
global_attr_name_2 = 2)
)
attributes(a) <- c(attributes(a), attrs)
ArrayToNc(a, 'tmp.nc')
# Unlimited dimensions can be manually created
a <- array(1:400, dim = c(5, 10, 4, 2))
metadata <- list(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment