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
a421b8b5
Commit
a421b8b5
authored
Feb 01, 2019
by
Nicolau Manubens
Browse files
Updated MergeArrayDims.
parent
324a227e
Changes
2
Hide whitespace changes
Inline
Side-by-side
R/NcReadDims.R
View file @
a421b8b5
...
...
@@ -52,8 +52,7 @@ NcReadDims <- function(file_to_read, var_names = NULL) {
new_dim
<-
c
(
var
=
1
)
found_dims
<-
c
(
new_dim
,
found_dims
)
if
(
!
is.null
(
dims
))
{
dims
<-
.MergeArrayDims
(
dims
,
found_dims
)
dims
<-
pmax
(
dims
[[
1
]],
dims
[[
2
]])
dims
<-
.MergeArrayDims
(
dims
,
found_dims
)[[
3
]]
dims
[
'var'
]
<-
dims
[
'var'
]
+
1
}
else
{
dims
<-
found_dims
...
...
R/Utils.R
View file @
a421b8b5
...
...
@@ -131,9 +131,15 @@
# It expects as inputs two named numeric vectors, and it extends them
# with dimensions of length 1 until an ordered common dimension
# format is reached.
# The first output is dims1 extended with 1s.
# The second output is dims2 extended with 1s.
# The third output is a merged dimension vector. If dimensions with
# the same name are found in the two inputs, and they have a different
# length, the maximum is taken.
.MergeArrayDims
<-
function
(
dims1
,
dims2
)
{
new_dims1
<-
c
()
new_dims2
<-
c
()
new_dims3
<-
c
()
while
(
length
(
dims1
)
>
0
)
{
if
(
names
(
dims1
)[
1
]
%in%
names
(
dims2
))
{
pos
<-
which
(
names
(
dims2
)
==
names
(
dims1
)[
1
])
...
...
@@ -143,11 +149,13 @@
}
new_dims1
<-
c
(
new_dims1
,
dims_to_add
,
dims1
[
1
])
new_dims2
<-
c
(
new_dims2
,
dims2
[
1
:
pos
])
new_dims3
<-
c
(
new_dims3
,
dims2
[
1
:
pos
])
dims1
<-
dims1
[
-1
]
dims2
<-
dims2
[
-
c
(
1
:
pos
)]
}
else
{
new_dims1
<-
c
(
new_dims1
,
dims1
[
1
])
new_dims2
<-
c
(
new_dims2
,
1
)
new_dims3
<-
c
(
new_dims3
,
dims1
[
1
])
names
(
new_dims2
)[
length
(
new_dims2
)]
<-
names
(
dims1
)[
1
]
dims1
<-
dims1
[
-1
]
}
...
...
@@ -157,8 +165,9 @@
names
(
dims_to_add
)
<-
names
(
dims2
)
new_dims1
<-
c
(
new_dims1
,
dims_to_add
)
new_dims2
<-
c
(
new_dims2
,
dims2
)
new_dims3
<-
c
(
new_dims3
,
dims2
)
}
list
(
new_dims1
,
new_dims2
)
list
(
new_dims1
,
new_dims2
,
pmax
(
new_dims1
,
new_dims2
)
)
}
# This function takes two named arrays and merges them, filling with
...
...
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