diff --git a/src/Type_gcmarray.jl b/src/Type_gcmarray.jl index 72051c43..8e52c491 100644 --- a/src/Type_gcmarray.jl +++ b/src/Type_gcmarray.jl @@ -236,9 +236,9 @@ end function Base.similar(A::gcmarray;m::varmeta=defaultmeta) if ndims(A)==1 - B=gcmarray(A.grid,eltype(A),copy(A.fSize),copy(A.fIndex); meta=m) + B=gcmarray(similar(A.grid),eltype(A),copy(A.fSize),copy(A.fIndex); meta=m) else - B=gcmarray(A.grid,eltype(A),copy(A.fSize),copy(A.fIndex),size(A,2); meta=m) + B=gcmarray(similar(A.grid),eltype(A),copy(A.fSize),copy(A.fIndex),size(A,2); meta=m) end return B end @@ -252,9 +252,9 @@ function Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{gcmarray}}, A = find_gcmarray(bc) # Create the gcmarray output: if ndims(A)==1 - B=gcmarray(A.grid,ElType,A.fSize,A.fIndex) + B=gcmarray(similar(A.grid),ElType,copy(A.fSize),copy(A.fIndex)) else - B=gcmarray(A.grid,ElType,A.fSize,A.fIndex,size(A,2)) + B=gcmarray(similar(A.grid),ElType,copy(A.fSize),copy(A.fIndex),size(A,2)) end return B end diff --git a/src/Type_gcmvector.jl b/src/Type_gcmvector.jl index 5dd43bb1..b4b6c963 100644 --- a/src/Type_gcmvector.jl +++ b/src/Type_gcmvector.jl @@ -65,7 +65,7 @@ function Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{gcmvector}} # Scan the inputs for the gcmarray: A = find_gcmvector(bc) # Create the gcmvector output: - return gcmvector{ElType,ndims(A)}(A.grid,similar(A.f),A.fSize,A.fIndex) + return gcmvector{ElType,ndims(A)}(A.grid,similar(A.f),copy(A.fSize),copy(A.fIndex)) end find_gcmvector(bc::Base.Broadcast.Broadcasted) = find_gcmvector(bc.args) diff --git a/src/Types.jl b/src/Types.jl index 3c83b882..ce9e79b9 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -48,6 +48,10 @@ struct gcmgrid write::Function end +copy_if_isarray(x) = isa(x,Array) ? copy(x) : x + +Base.similar(g::gcmgrid)=gcmgrid(g.path, g.class, g.nFaces, copy(g.fSize), copy_if_isarray(g.ioSize), g.ioPrec, g.read, g.write) + """ varmeta