@@ -43,7 +43,7 @@ function defVar(ds::AbstractDataset,
43
43
name:: SymbolOrString ,
44
44
data:: AbstractArray{Union{Missing,T},N} ,
45
45
dimnames;
46
- kwargs... ) where T <: Union{Int8,UInt8,Int16,Int32,Int64,Float32,Float64} where N
46
+ kwargs... ) where T <: Union{Int8,UInt8,Int16,Int32,Int64,Float32,Float64,Char,String } where N
47
47
_defVar (ds:: AbstractDataset ,name,data,T,dimnames; kwargs... )
48
48
end
49
49
@@ -55,7 +55,7 @@ function defVar(ds::AbstractDataset,
55
55
data:: AbstractArray{<:Union{Missing,T},N} ,
56
56
dimnames;
57
57
kwargs... ) where T <: Union{DateTime,AbstractCFDateTime} where N
58
- _defVar (ds:: AbstractDataset ,name,data,Float64,dimnames; kwargs... )
58
+ _defVar (ds,name,data,Float64,dimnames; kwargs... )
59
59
end
60
60
61
61
function defVar (ds:: AbstractDataset ,name:: SymbolOrString ,data,dimnames; kwargs... )
@@ -65,15 +65,16 @@ function defVar(ds::AbstractDataset,name::SymbolOrString,data,dimnames; kwargs..
65
65
else
66
66
nctype = eltype (data)
67
67
end
68
- _defVar (ds:: AbstractDataset ,name,data,nctype,dimnames; kwargs... )
68
+
69
+ _defVar (ds,name,data,nctype,dimnames; kwargs... )
69
70
end
70
71
71
72
function _defVar (ds:: AbstractDataset ,name:: SymbolOrString ,data,nctype,vardimnames; attrib = [], kwargs... )
72
73
# define the dimensions if necessary
73
74
for (i,dimname) in enumerate (vardimnames)
74
75
if ! (dimname in dimnames (ds))
75
76
defDim (ds,dimname,size (data,i))
76
- elseif ! (dimname in unlimited (ds. dim ))
77
+ elseif ! (dimname in unlimited (ds))
77
78
dimlen = dim (ds,dimname)
78
79
79
80
if (dimlen != size (data,i))
@@ -84,14 +85,15 @@ function _defVar(ds::AbstractDataset,name::SymbolOrString,data,nctype,vardimname
84
85
end
85
86
86
87
T = eltype (data)
87
- attrib = collect (attrib)
88
+ # we should preserve the order
89
+ # value type is promoted to Any as we add values of different type
90
+ attrib = convert (OrderedDict{String,Any},OrderedDict (attrib))
88
91
89
92
if T <: Union{TimeType,Missing}
90
- dattrib = Dict (attrib)
91
- if ! haskey (dattrib," units" )
93
+ if ! haskey (attrib," units" )
92
94
push! (attrib," units" => CFTime. DEFAULT_TIME_UNITS)
93
95
end
94
- if ! haskey (dattrib ," calendar" )
96
+ if ! haskey (attrib ," calendar" )
95
97
# these dates cannot be converted to the standard calendar
96
98
if T <: Union{DateTime360Day,Missing}
97
99
push! (attrib," calendar" => " 360_day" )
@@ -103,18 +105,14 @@ function _defVar(ds::AbstractDataset,name::SymbolOrString,data,nctype,vardimname
103
105
end
104
106
end
105
107
106
- v =
107
- if Missing <: T
108
- # make sure a fill value is set (it might be overwritten by kwargs...)
109
- defVar (ds,name,nctype,vardimnames;
110
- fillvalue = fillvalue (nctype),
111
- attrib = attrib,
112
- kwargs... )
113
- else
114
- defVar (ds,name,nctype,vardimnames;
108
+ # make sure a fill value is set
109
+ if (Missing <: T ) && ! haskey (attrib," _FillValue" )
110
+ push! (attrib," _FillValue" => fillvalue (nctype))
111
+ end
112
+
113
+ v = defVar (ds,name,nctype,vardimnames;
115
114
attrib = attrib,
116
115
kwargs... )
117
- end
118
116
119
117
v[:] = data
120
118
return v
0 commit comments