Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Earth Sciences
easyNCDF
Commits
71ff3cfe
Commit
71ff3cfe
authored
Feb 05, 2019
by
Nicolau Manubens Gil
Browse files
Merge branch 'develop-global_attrs' into 'master'
Develop global attrs See merge request
!18
parents
c0476862
50b46707
Changes
2
Hide whitespace changes
Inline
Side-by-side
R/ArrayToNc.R
View file @
71ff3cfe
...
...
@@ -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
)
}
...
...
man/ArrayToNc.Rd
View file @
71ff3cfe
...
...
@@ -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(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment