1
1
using NCDatasets
2
2
using Test
3
-
3
+ import CommonDataModel as CDM
4
+ using DataStructures
4
5
5
6
fname = tempname ()
6
7
ds = NCDataset (fname," c" )
@@ -24,4 +25,65 @@ v.var[1,1] = 1
24
25
@test ismissing (v[2 ,2 ])
25
26
@test fillvalue (v) == fill_value
26
27
27
- close (ds)
28
+ @test collect (CDM. dimnames (v)) == [" lon" ," lat" ]
29
+
30
+ # @test CDM.dim(v,"lon") == 10
31
+
32
+ io = IOBuffer ()
33
+ CDM. show (io," text/plain" ,v)
34
+ @test occursin (" Attributes" ,String (take! (io)))
35
+
36
+ v = @test_warn " numeric" defVar (ds," temp2" ,data,(" lon" ," lat" ),attrib = Dict (
37
+ " missing_value" => " bad_idea" ))
38
+
39
+ struct MemoryVariable{T,N} <: CDM.AbstractVariable{T,N}
40
+ name:: String
41
+ dimnames:: Vector{String}
42
+ data:: Array{T,N}
43
+ attrib:: OrderedDict{String,Any}
44
+ end
45
+
46
+ struct MemoryDataset <: CDM.AbstractDataset
47
+ dim:: OrderedDict{String,Int}
48
+ variables:: OrderedDict{String,MemoryVariable}
49
+ attrib:: OrderedDict{String,Any}
50
+ unlimited:: Vector{String}
51
+ end
52
+
53
+ data = randn (30 ,31 )
54
+ mv = MemoryVariable (" data" ,[" lon" ," lat" ], data, OrderedDict {String,Any} (
55
+ " units" => " days since 2000-01-01" ))
56
+
57
+ CDM. name (v:: MemoryVariable ) = v. name
58
+ CDM. dimnames (v:: MemoryVariable ) = v. dimnames
59
+ Base. size (v:: MemoryVariable ) = size (v. data)
60
+
61
+ @test " lon" in CDM. dimnames (mv)
62
+ @test CDM. name (mv) == " data"
63
+
64
+ md = MemoryDataset (
65
+ OrderedDict {String,Int} (
66
+ " lon" => 30 ,
67
+ " lat" => 31 ),
68
+ OrderedDict {String,MemoryVariable} (
69
+ " data" => mv),
70
+ OrderedDict {String,Any} (
71
+ " history" => " lala" ),
72
+ String[])
73
+
74
+ import Base
75
+ Base. keys (md:: MemoryDataset ) = keys (md. variables)
76
+ CDM. variable (md:: MemoryDataset ,varname:: AbstractString ) = md. variables[varname]
77
+ Base. getindex (md:: MemoryDataset ,varname:: AbstractString ) = CDM. cfvariable (md,varname)
78
+ CDM. dimnames (md:: MemoryDataset ) = keys (md. dim)
79
+ CDM. dim (md:: MemoryDataset ,name:: AbstractString ) = md. dim[name]
80
+ CDM. attribnames (md:: Union{MemoryDataset,MemoryVariable} ) = keys (md. attrib)
81
+ CDM. attrib (md:: Union{MemoryDataset,MemoryVariable} ,name:: AbstractString ) = md. attrib[name]
82
+
83
+
84
+ io = IOBuffer ()
85
+ CDM. show (io,md)
86
+ @test occursin (" Attributes" ,String (take! (io)))
87
+
88
+
89
+ # close(ds)
0 commit comments