ruby-netcdf 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +389 -0
- data/INSTALL +62 -0
- data/LICENSE.txt +59 -0
- data/Rakefile +40 -0
- data/ToDo +1 -0
- data/demo/README +14 -0
- data/demo/demo1-create-alt.rb +35 -0
- data/demo/demo1-create.rb +35 -0
- data/demo/demo2-graphic.rb +67 -0
- data/demo/demo3-ncepclim.rb +178 -0
- data/demo/demo4-copy.rb +32 -0
- data/doc/README_JP.txt +152 -0
- data/doc/Ref_man.html +1482 -0
- data/doc/Ref_man.rd +1312 -0
- data/doc/Ref_man_jp.html +1445 -0
- data/doc/Ref_man_jp.rd +1276 -0
- data/doc/to_html +7 -0
- data/extconf.rb +137 -0
- data/extconf.rb.orig +124 -0
- data/extconf.rb.rej +16 -0
- data/lib/netcdf.rb +791 -0
- data/lib/netcdf_miss.rb +203 -0
- data/netcdfraw.c +4613 -0
- data/test/aref_aset.rb +37 -0
- data/test/char_var.rb +25 -0
- data/test/clone.rb +54 -0
- data/test/create_tmp.rb +15 -0
- data/test/def_var_with_dim.rb +14 -0
- data/test/factor_offset.rb +53 -0
- data/test/putatt.cdl +23 -0
- data/test/putatt.rb +56 -0
- data/test/test.cdl +31 -0
- data/test/test.rb +192 -0
- data/test/type.rb +13 -0
- metadata +140 -0
data/doc/Ref_man.rd
ADDED
@@ -0,0 +1,1312 @@
|
|
1
|
+
=begin
|
2
|
+
=RubyNetCDF Reference Manual
|
3
|
+
|
4
|
+
* ((<Method Index>))
|
5
|
+
|
6
|
+
---------------------------------------------
|
7
|
+
|
8
|
+
==Overview
|
9
|
+
|
10
|
+
RubyNetCDF is the Ruby interface of the NetCDF library. Ruby is a free
|
11
|
+
object-oriented scripting language and is freely available from
|
12
|
+
((<the Ruby homepage|URL:http://www.ruby-lang.org/>)).
|
13
|
+
To handle numeric data, RubyNetCDF uses
|
14
|
+
((<NArray|URL:http://www.ruby-lang.org/en/raa-list.rhtml?name=NArray>)), which is the standard numeric multi-dimensional array class
|
15
|
+
for Ruby. Thus, you have to have installed it before installing this library.
|
16
|
+
An NArray object holds numeric data in a consecutive memory area
|
17
|
+
pointed by a C pointer. Thus, it is computationally efficient.
|
18
|
+
NArray is similar to NumPy for Python, but results of some benchmark
|
19
|
+
tests suggests that NArray is more efficient than NumPy.
|
20
|
+
Optionally, RubyNetCDF offers methods to handle data missing
|
21
|
+
automatically. To use it, you will also
|
22
|
+
need ((<NArrayMiss|URL:http://ruby.gfd-dennou.org/products/narray_miss/>)).
|
23
|
+
See ((<Usage>)) for details.
|
24
|
+
|
25
|
+
===Structure
|
26
|
+
|
27
|
+
RubyNetCDF consists of the four classes in the following.
|
28
|
+
|
29
|
+
* ((<class NetCDF>)) -- the file class
|
30
|
+
|
31
|
+
An NetCDF object represents a NetCDF file
|
32
|
+
|
33
|
+
* ((<class NetCDFDim>)) -- the dimension class
|
34
|
+
|
35
|
+
Although in its C version a NetCDF dimension is represented by a
|
36
|
+
combination of a file ID and a dimension ID, it is represented by
|
37
|
+
only one NetCDFDim object in RubyNetCDF.
|
38
|
+
|
39
|
+
* ((<class NetCDFVar>)) -- the variable class
|
40
|
+
|
41
|
+
Although in its C version a NetCDF variable is represented by a
|
42
|
+
combination of a file ID and a variable ID, it is represented by
|
43
|
+
only one NetCDFVar object in RubyNetCDF.
|
44
|
+
|
45
|
+
* ((<class NetCDFAtt>)) -- the attribute class
|
46
|
+
|
47
|
+
Although in its C version a NetCDF attribute is represented by a
|
48
|
+
combination of file ID, variable ID, and its name, it is represented
|
49
|
+
by only one NetCDFAtt object in RubyNetCDF.
|
50
|
+
|
51
|
+
===Data type
|
52
|
+
|
53
|
+
All the NetCDF variable types char, byte, short, int, float, and
|
54
|
+
double are supported in this Ruby interface. These types are called,
|
55
|
+
however, differently in it to adhere to the convention of Ruby, or,
|
56
|
+
more specifically, of NArray. These types are named to as "char",
|
57
|
+
"byte", "sint", "int", "sfloat", and "float", respectively. Therefore,
|
58
|
+
the vartype (=ntype) method of the NetCDFVar class returns one of these
|
59
|
+
strings. The def_var method of the NetCDF class also accepts one of
|
60
|
+
them to define a variable. It should be noted especially that "float"
|
61
|
+
in this library means the double in the NetCDF terminology. This is
|
62
|
+
due to the convention of Ruby -- the predefined Float class
|
63
|
+
corresponds to the double in C, not the float.
|
64
|
+
|
65
|
+
The "get" method of NetCDFVar class reads a variable in a NArray of
|
66
|
+
the same type as in the file, except for the "char" type which is read
|
67
|
+
into a "byte". This is because NArray does not have a "char" type.
|
68
|
+
However, it not is not supposed to be a problem, since a byte NArray
|
69
|
+
can easily handle string data.
|
70
|
+
|
71
|
+
|
72
|
+
===Error handling
|
73
|
+
|
74
|
+
Errors are basically handled by raising exceptions. However, light
|
75
|
+
errors in value-returning methods are handled by returning nil (e.g.,
|
76
|
+
if a non-existent attribute name is specified in attribute reading).
|
77
|
+
Those methods that return nil on error are explicitly written as such
|
78
|
+
in the following.
|
79
|
+
|
80
|
+
===Security features
|
81
|
+
|
82
|
+
Security handling is done just as in the pre-defined File class.
|
83
|
+
|
84
|
+
===Usage
|
85
|
+
|
86
|
+
To use the RubyNetCDF library, load the library first by placing the
|
87
|
+
following line in your Ruby program to load the library:
|
88
|
+
|
89
|
+
require 'numru/netcdf'
|
90
|
+
|
91
|
+
If you want to use automatic data-missing-handling methods
|
92
|
+
(of NetCDFVar class), use the following:
|
93
|
+
|
94
|
+
require 'numru/netcdf_miss'
|
95
|
+
|
96
|
+
This will call (({require 'numru/netcdf'})) inside at the beginning, so
|
97
|
+
you do not have to call the both. The missing-data handling is done
|
98
|
+
with ((<NArrayMiss|URL:http://ruby.gfd-dennou.org/products/narray_miss/>)),
|
99
|
+
so you have have installed it. This is, however, not needed if you only
|
100
|
+
call (({require 'numru/netcdf'})).
|
101
|
+
|
102
|
+
Here, 'numru', which stands for "Numerical Ruby", is the name of
|
103
|
+
the subdirectory in the user's load path where the RubyNetCDF library
|
104
|
+
is placed. Then, it can be used as in the following:
|
105
|
+
|
106
|
+
file = NumRu::NetCDF.create('tmp.nc')
|
107
|
+
x = file.def_dim('x',10)
|
108
|
+
y = file.def_dim('y',10)
|
109
|
+
v = file.def_var('v','float',[x,y])
|
110
|
+
file.close
|
111
|
+
|
112
|
+
Here, NumRu is the module that has the library in it. The
|
113
|
+
reason why NetCDF library is wrapped in such a module is to avoid
|
114
|
+
conflicts in the name space. Without this kind of treatment,
|
115
|
+
problems happen if the user wants to use a library that happens to
|
116
|
+
have a class or module with the same name as even one of the classes
|
117
|
+
in this library.
|
118
|
+
|
119
|
+
If such a problem is not expected to happen, the prefix "NumRu::" can
|
120
|
+
be eliminated by "including" the NumRu module as in the following, so
|
121
|
+
that to place "NumRu::" is not needed anymore in the current scope:
|
122
|
+
|
123
|
+
include NumRu
|
124
|
+
file = NetCDF.create('tmp.nc')
|
125
|
+
...
|
126
|
+
|
127
|
+
For more examples, see demo and test programs included in the
|
128
|
+
distribution package.
|
129
|
+
|
130
|
+
---------------------------------------------
|
131
|
+
|
132
|
+
==How to read this manual
|
133
|
+
|
134
|
+
--- method_name(argument1, argument2, ...) -- arguments that can be omitted are expressed as Argument_name=Default_value
|
135
|
+
|
136
|
+
Explanation of its function
|
137
|
+
|
138
|
+
Arguments
|
139
|
+
* name of argument1 (its class or possible values): explanation
|
140
|
+
* name of argument2 (its class or possible values): explanation
|
141
|
+
* ...
|
142
|
+
|
143
|
+
Return value
|
144
|
+
* Explanation of the return value
|
145
|
+
|
146
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
147
|
+
* Name(s) in NetCDF ver 3. The function equivalent to the current
|
148
|
+
method, if not in parenthesis. If no direct correspondence,
|
149
|
+
dependent functions are listed in parentheses.
|
150
|
+
|
151
|
+
---------------------------------------------
|
152
|
+
|
153
|
+
==Method Index
|
154
|
+
* ((<class NetCDF>))
|
155
|
+
|
156
|
+
Class Methods
|
157
|
+
* ((<NetCDF.open>)) Opens a file (class method). If mode="w" and non-existent, a new
|
158
|
+
* ((<NetCDF.new>)) Aliased to NetCDF.open
|
159
|
+
* ((<NetCDF.create>)) Creates a NetCDF file (class method)
|
160
|
+
* ((<NetCDF.create_tmp>)) Creates a temporary NetCDF file (class method)
|
161
|
+
|
162
|
+
Instance Methods
|
163
|
+
* ((<close>)) Closes the file.
|
164
|
+
* ((<ndims>)) Returns the number of dimensions in the file
|
165
|
+
* ((<nvars>)) Returns the number of variables in the file
|
166
|
+
* ((<natts>)) Returns the number of global attributes in the file
|
167
|
+
* ((<unlimited>)) Returns the unlimited dimension in the file
|
168
|
+
* ((<path>)) Returns the path of the file (contents of the filename specified when opened/created)
|
169
|
+
* ((<redef>)) Switches to the define mode. Does nothing if already in it (nil returned).
|
170
|
+
* ((<enddef>)) Switches to the data mode. Does nothing if already in it (nil returned).
|
171
|
+
* ((<define_mode?>)) Inquire whether the file is in the define mode.
|
172
|
+
* ((<sync>)) Synchronizes the disk copy of a netCDF dataset with in-memory buffer
|
173
|
+
* ((<def_dim>)) Define a dimension
|
174
|
+
* ((<put_att>)) Sets a global attribute
|
175
|
+
* ((<def_var>)) Defines a variable
|
176
|
+
* ((<def_var_with_dim>)) Same as def_var but defines dimensions first if needed
|
177
|
+
* ((<var>)) Opens an existing variable in the file
|
178
|
+
* ((<vars>)) Opens existing variables in the file
|
179
|
+
* ((<dim>)) Opens an existing dimension in the file
|
180
|
+
* ((<dims>)) Opens existing dimensions in the file
|
181
|
+
* ((<att>)) Opens an existing global attribute in the file
|
182
|
+
* ((<fill=>)) Sets a fill mode. (Default behavior of NetCDF is FILL.)
|
183
|
+
* ((<each_dim>)) Iterator regarding the dimensions in the file.
|
184
|
+
* ((<each_var>)) Iterator regarding the variables in the file.
|
185
|
+
* ((<each_att>)) Iterator regarding the global attributes of the file.
|
186
|
+
* ((<dim_names>)) Returns the names of all dimensions in the file
|
187
|
+
* ((<var_names>)) Returns the names of all variables in the file
|
188
|
+
* ((<att_names>)) Returns the names of all the global attributes of the file
|
189
|
+
|
190
|
+
* ((<class NetCDFDim>))
|
191
|
+
|
192
|
+
Class Methods
|
193
|
+
|
194
|
+
Instance Methods
|
195
|
+
* ((<length>)) Returns the length of the dimension
|
196
|
+
* ((<length_ul0>)) Same as length but returns 0 for the unlimited dimension
|
197
|
+
* ((<name=>)) Rename the dimension
|
198
|
+
* ((<name>)) Returns the name of the dimension
|
199
|
+
* ((<unlimited?>)) Inquires whether the dimension is unlimited or not
|
200
|
+
|
201
|
+
* ((<class NetCDFVar>))
|
202
|
+
|
203
|
+
Class Methods
|
204
|
+
* ((<NetCDFVar.new>)) Combines NetCDF.open and NetCDF#Var to open a variable with one line (no need to use this).
|
205
|
+
* ((<NetCDFVar.unpack_type=>)) Fix the NArray type to be used
|
206
|
+
in ((<unpack>))
|
207
|
+
* ((<NetCDFVar.unpack_type>)) Returns the NArray type set by ((<NetCDFVar.unpack_type=>)).
|
208
|
+
|
209
|
+
Instance Methods
|
210
|
+
* ((<dim>)) Inquires the dim_num-th dimension of the variable (dim_num=0,1,2,..)
|
211
|
+
* ((<dims>)) Returns an array of all the dimensions of the variable
|
212
|
+
* ((<shape_ul0>)) Returns the shape of the variable, but the length of the unlimited dimension is set to zero.
|
213
|
+
* ((<shape_current>)) Returns the current shape of the variable.
|
214
|
+
## * ((<url>)) Returns a combination of filename (path) and variable name as path+'?var='+varname
|
215
|
+
* ((<each_att>)) Iterator regarding the global attributes of the variables.
|
216
|
+
* ((<dim_names>)) Returns the names of all the dimensions of the variable
|
217
|
+
* ((<att_names>)) Returns the names of all the attributes of the variable
|
218
|
+
* ((<name>)) Returns the name of the variable
|
219
|
+
* ((<name=>)) Rename the variable
|
220
|
+
* ((<ndims>)) Number of dimensions of the variable (which is rank of the variable).
|
221
|
+
* ((<rank>)) aliased to ndims
|
222
|
+
* ((<ntype>)) Aliased to vartype
|
223
|
+
* ((<vartype>)) Inquires the data value type of the variable
|
224
|
+
* ((<typecode>)) Inquires the data type of the variable (returns a typecode of NArray)
|
225
|
+
* ((<natts>)) Returns the number of the attributes of the variable
|
226
|
+
* ((<file>)) Inquires the file that the variable is in
|
227
|
+
* ((<att>)) Returns the attribute specified by its name
|
228
|
+
* ((<put_att>)) Sets an attribute
|
229
|
+
* ((<put>)) Aliased to ((<simple_put>))
|
230
|
+
* ((<simple_put>)) Set the values of the variable
|
231
|
+
* ((<pack>)) Pack a NArray (etc) using the attributes scale_factor and/or add_offset of self.
|
232
|
+
* ((<scaled_put>)) Same as ((<simple_put>)) but interprets the attributes scale_factor and/or add_offset using ((<pack>)).
|
233
|
+
* ((<get>)) Aliased to ((<simple_get>))
|
234
|
+
* ((<simple_get>)) Returns values of the variable
|
235
|
+
* ((<unpack>)) Unpack a NArray (etc) using the attributes scale_factor and/or add_offset of self.
|
236
|
+
* ((<scaled_get>)) Same as ((<simple_get>)) but interprets the attributes scale_factor and/or add_offset using ((<unpack>)).
|
237
|
+
* ((<[]>)) Same as NetCDFVar#get but a subset is specified as in the method [] of NArray.
|
238
|
+
* ((<[]=>)) Same as NetCDFVar#put but a subset is specified as in the method []= of NArray.
|
239
|
+
|
240
|
+
|
241
|
+
Instance Methods added by requiring "numru/netcdf_miss"
|
242
|
+
|
243
|
+
* ((<get_with_miss>)) Same as ((<get>)) but interprets data missing.
|
244
|
+
* ((<get_with_miss_and_scaling>)) Same as ((<get_with_miss>)) but handles data scaling too.
|
245
|
+
* ((<put_with_miss>)) Same as ((<put>)) but interprets data missing.
|
246
|
+
* ((<put_with_miss_and_scaling>)) Same as ((<put_with_miss>)) but handles data scaling too.
|
247
|
+
|
248
|
+
|
249
|
+
* ((<class NetCDFAtt>))
|
250
|
+
|
251
|
+
Class Methods
|
252
|
+
|
253
|
+
Instance Methods
|
254
|
+
* ((<name>)) Returns the name of the attribute
|
255
|
+
* ((<name=>)) Rename the attribute
|
256
|
+
* ((<copy>)) Copies an attribute to a variable or a file. If file, becomes an global attribute
|
257
|
+
* ((<delete>)) Delete an attribute
|
258
|
+
* ((<put>)) Sets the value of the attribute
|
259
|
+
* ((<get>)) Returns the values of the attribute
|
260
|
+
* ((<atttype>)) Inquires the type of attribute values
|
261
|
+
* ((<typecode>)) Inquires the type of attribute values (returns a NArray typecode)
|
262
|
+
|
263
|
+
---------------------------------------------
|
264
|
+
|
265
|
+
=class NetCDF
|
266
|
+
===Class Methods
|
267
|
+
---NetCDF.open(filename, mode="r", share=false)
|
268
|
+
Opens a file (class method). If mode="w" and the file does not
|
269
|
+
exist, a new file is created.
|
270
|
+
|
271
|
+
Arguments
|
272
|
+
* filename (String): file name (path)
|
273
|
+
* mode (String) : IO mode "r" (read only); "w","w+" (write --
|
274
|
+
current contents are overwritten (eliminated!)); "r+","a","a+"
|
275
|
+
(append -- writable while current contents are preserved).
|
276
|
+
All the options permit reading, unlike the predefined File class.
|
277
|
+
Note that to "append" will require extra time and disk
|
278
|
+
space due to the limitations of the original NetCDF library,
|
279
|
+
which is used in this library.
|
280
|
+
* share (true or false) : Whether to use the "shared" mode or not
|
281
|
+
(set true if a file being written may be read from other
|
282
|
+
processes. See nc_open in Ch.5 of users' guide of the C version)
|
283
|
+
|
284
|
+
Return value
|
285
|
+
* a NetCDF object
|
286
|
+
|
287
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
288
|
+
* nc_open, nc_create
|
289
|
+
|
290
|
+
---NetCDF.new
|
291
|
+
Aliased to NetCDF.open
|
292
|
+
|
293
|
+
---NetCDF.create(filename, noclobber=false, share=false)
|
294
|
+
Creates a NetCDF file (class method)
|
295
|
+
|
296
|
+
Arguments
|
297
|
+
* filename (String) : file name (path)
|
298
|
+
* noclobber (true or false) : overwrite or not if the file exists
|
299
|
+
* share (true or false) : Whether to use the shared mode or not
|
300
|
+
(set true if a file being written may be read from other
|
301
|
+
processes. See nc_open in Ch.5 of users' guide of the C version)
|
302
|
+
|
303
|
+
Return value
|
304
|
+
* a NetCDF object
|
305
|
+
|
306
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
307
|
+
* nc_create
|
308
|
+
|
309
|
+
---NetCDF.create_tmp(tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'.', share=false)
|
310
|
+
Creates a temporary NetCDF file (class method).
|
311
|
+
Its name is automatically generated, and it is deleted when closed.
|
312
|
+
|
313
|
+
Arguments
|
314
|
+
* tmpdir (String) : directory to place the temporary file.
|
315
|
+
By default, "." or a directory specified by an environmental
|
316
|
+
variable (TMPDIR or TMP or TEMP) is used. In a secure mode,
|
317
|
+
theses environmental variable is NOT used, and the default
|
318
|
+
value is '.'.
|
319
|
+
* share (true or false) : Whether to use the shared mode or not
|
320
|
+
|
321
|
+
Return value
|
322
|
+
* a NetCDF object
|
323
|
+
|
324
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
325
|
+
* nc_create
|
326
|
+
|
327
|
+
===Instance Methods
|
328
|
+
---close
|
329
|
+
Closes the file.
|
330
|
+
|
331
|
+
Arguments
|
332
|
+
* (none)
|
333
|
+
|
334
|
+
Return value
|
335
|
+
* nil
|
336
|
+
|
337
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
338
|
+
* nc_close
|
339
|
+
|
340
|
+
---ndims
|
341
|
+
Returns the number of dimensions in the file
|
342
|
+
|
343
|
+
Arguments
|
344
|
+
* (none)
|
345
|
+
|
346
|
+
Return value
|
347
|
+
* Integer
|
348
|
+
|
349
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
350
|
+
* nc_inq_ndims
|
351
|
+
|
352
|
+
---nvars
|
353
|
+
Returns the number of variables in the file
|
354
|
+
|
355
|
+
Arguments
|
356
|
+
* (none)
|
357
|
+
|
358
|
+
Return value
|
359
|
+
* Integer
|
360
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
361
|
+
* nc_inq_nvars
|
362
|
+
|
363
|
+
---natts
|
364
|
+
Returns the number of global attributes in the file
|
365
|
+
|
366
|
+
Arguments
|
367
|
+
* (none)
|
368
|
+
|
369
|
+
Return value
|
370
|
+
* Integer
|
371
|
+
|
372
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
373
|
+
* nc_inq_natts
|
374
|
+
|
375
|
+
---unlimited
|
376
|
+
Returns the unlimited dimension in the file
|
377
|
+
|
378
|
+
Arguments
|
379
|
+
* (none)
|
380
|
+
|
381
|
+
Return value
|
382
|
+
* a NetCDFDim if it exists; nil if not
|
383
|
+
|
384
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
385
|
+
* nc_inq_unlimdim
|
386
|
+
|
387
|
+
---path
|
388
|
+
Returns the path of the file (contents of the filename specified when opened/created)
|
389
|
+
|
390
|
+
Arguments
|
391
|
+
* (none)
|
392
|
+
|
393
|
+
Return value
|
394
|
+
* String
|
395
|
+
|
396
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
397
|
+
* (none)
|
398
|
+
|
399
|
+
---redef
|
400
|
+
Switches to the define mode. Does nothing if already in it (nil returned).
|
401
|
+
|
402
|
+
Arguments
|
403
|
+
* (none)
|
404
|
+
|
405
|
+
Return value
|
406
|
+
* true if successfully switched to the define mode;
|
407
|
+
nil if the file is already in the define mode.
|
408
|
+
Exception is raised if unsuccessful for other reasons.
|
409
|
+
|
410
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
411
|
+
* nc_redef
|
412
|
+
|
413
|
+
---enddef
|
414
|
+
Switches to the data mode. Does nothing if already in it (nil returned).
|
415
|
+
|
416
|
+
Arguments
|
417
|
+
* (none)
|
418
|
+
|
419
|
+
Return value
|
420
|
+
* true if successfully switched to the data mode;
|
421
|
+
nil if the file is already in the data mode.
|
422
|
+
Exception is raised if unsuccessful for other reasons.
|
423
|
+
|
424
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
425
|
+
* nc_enddef
|
426
|
+
|
427
|
+
---define_mode?
|
428
|
+
Inquire whether the file is in the define mode.
|
429
|
+
|
430
|
+
Arguments
|
431
|
+
* (none)
|
432
|
+
|
433
|
+
Return value
|
434
|
+
* true if the data is in the define mode;
|
435
|
+
false if the file is in the data mode;
|
436
|
+
nil otherwise (possibly the file is read-only).
|
437
|
+
|
438
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
439
|
+
* combination of nc_redef and nc_enddef
|
440
|
+
|
441
|
+
---sync
|
442
|
+
Synchronizes the disk copy of a netCDF dataset with in-memory buffer
|
443
|
+
|
444
|
+
Arguments
|
445
|
+
* (none)
|
446
|
+
|
447
|
+
Return value
|
448
|
+
* nil
|
449
|
+
|
450
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
451
|
+
* nc_sync
|
452
|
+
|
453
|
+
---def_dim(dimension_name, length)
|
454
|
+
Define a dimension
|
455
|
+
|
456
|
+
Arguments
|
457
|
+
* dimension_name (String) : Name of the dimension to be defined
|
458
|
+
* length (Integer) : length of the dimension. 0 for unlimited.
|
459
|
+
|
460
|
+
Return value
|
461
|
+
* defined dimension (NetCDFDim object)
|
462
|
+
|
463
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
464
|
+
* nc_def_dim
|
465
|
+
|
466
|
+
---put_att(attribute_name, value, atttype=nil)
|
467
|
+
Sets a global attribute
|
468
|
+
|
469
|
+
Arguments
|
470
|
+
* attribute_name (String) : name of the global attribute
|
471
|
+
* value (Numeric, String, Array of Numeric, or NArray) : value of the attribute
|
472
|
+
* atttype (nil or String) : data type of the attribute value.
|
473
|
+
nil lets it automatically determined from the value.
|
474
|
+
"char" (or "string"), "byte", "sint", "int", "sfloat", or "float"
|
475
|
+
specifies the type explicitly (1,1,2,4,4,8 bytes, respectively)
|
476
|
+
|
477
|
+
Return value
|
478
|
+
* created attribute (NetCDFAtt object)
|
479
|
+
|
480
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
481
|
+
* nc_put_att_<type>
|
482
|
+
|
483
|
+
---def_var(name, vartype, dimensions)
|
484
|
+
Defines a variable
|
485
|
+
|
486
|
+
Arguments
|
487
|
+
* name (String) : Name of the variable to define
|
488
|
+
* vartype (String or Fixnum) : data type of the variable ("char", "byte", "sint",
|
489
|
+
"sint", "int", "sfloat", or "float"), or a NArray typecodes(Fixnum)
|
490
|
+
* dimensions (Array) : Dimensions of the variable. An Array of
|
491
|
+
NetCDFDim, in the order from the fastest varying dimension to
|
492
|
+
the slowest varying one; its length becomes the rank of the
|
493
|
+
variable.
|
494
|
+
|
495
|
+
Return value
|
496
|
+
* defined variable (NetCDFVar object)
|
497
|
+
|
498
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
499
|
+
* nc_def_var
|
500
|
+
|
501
|
+
---def_var_with_dim(name, vartype, shape_ul0, dimnames)
|
502
|
+
Same as def_var but defines dimensions first if needed.
|
503
|
+
Raise exception if it conflicts with the lengths of existing dimensions.
|
504
|
+
|
505
|
+
Arguments
|
506
|
+
* name (String) : Name of the variable to define
|
507
|
+
* vartype (String) : data type of the variable ("char", "byte", "sint",
|
508
|
+
"sint", "int", "sfloat", or "float")
|
509
|
+
* shape_ul0 (Array of Integer) : Shape of the variable, i.e.,
|
510
|
+
lengths of dimensions. The unlimited dimension is specified by zero.
|
511
|
+
The length of shape_ul0 determines the rank of the variable.
|
512
|
+
* dimnames (Array of String) : Names of the dimensions. Its length
|
513
|
+
(=>rank) must be equal to that of shape_ul0
|
514
|
+
|
515
|
+
Return value
|
516
|
+
* defined variable (NetCDFVar object)
|
517
|
+
|
518
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
519
|
+
* (nc_def_var)
|
520
|
+
|
521
|
+
---var(var_name)
|
522
|
+
Opens an existing variable in the file
|
523
|
+
|
524
|
+
Arguments
|
525
|
+
* var_name (String) : Name of the variable to open
|
526
|
+
|
527
|
+
Return value
|
528
|
+
* a NetCDFVar object; nil if the variable does not exist
|
529
|
+
|
530
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
531
|
+
* nc_inq_varid
|
532
|
+
|
533
|
+
---vars(names)
|
534
|
+
Opens existing variables in the file
|
535
|
+
|
536
|
+
Arguments
|
537
|
+
* names (nil or Array of String): Names of the variables to open;
|
538
|
+
all variables are returned if nil (default).
|
539
|
+
|
540
|
+
Return value
|
541
|
+
* Array of NetCDFVar objects; exception is raised if names has a
|
542
|
+
non-existent name
|
543
|
+
|
544
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
545
|
+
* nc_inq_varid
|
546
|
+
|
547
|
+
---dim(dimension_name)
|
548
|
+
Opens an existing dimension in the file
|
549
|
+
|
550
|
+
Arguments
|
551
|
+
* dimension_name (String) : Name of the dimension to open
|
552
|
+
|
553
|
+
Return value
|
554
|
+
* a NetCDFDim object; nil if the dimension does not exist
|
555
|
+
|
556
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
557
|
+
* nc_inq_dimid
|
558
|
+
|
559
|
+
---dims(names)
|
560
|
+
Opens existing dimensions in the file
|
561
|
+
|
562
|
+
Arguments
|
563
|
+
* names (nil or Array of String): Names of the dimensions to open;
|
564
|
+
all dimensions are returned if nil (default).
|
565
|
+
|
566
|
+
Return value
|
567
|
+
* Array of NetCDFDim objects; exception is raised if names has a
|
568
|
+
non-existent name
|
569
|
+
|
570
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
571
|
+
* nc_inq_dimid
|
572
|
+
|
573
|
+
---att(attribute_name)
|
574
|
+
Opens an existing global attribute in the file
|
575
|
+
|
576
|
+
Arguments
|
577
|
+
* attribute_name (String) : Name of the global attribute to open
|
578
|
+
|
579
|
+
Return value
|
580
|
+
* a NetCDFAtt object if the attribute exists; nil if not
|
581
|
+
|
582
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
583
|
+
* (nc_inq_attid used for inquiry)
|
584
|
+
|
585
|
+
---fill=(filemode)
|
586
|
+
Sets a fill mode. (Default behavior of NetCDF is FILL.)
|
587
|
+
|
588
|
+
Arguments
|
589
|
+
* fillmode (true or false)
|
590
|
+
|
591
|
+
Return value
|
592
|
+
* nil
|
593
|
+
|
594
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
595
|
+
* nc_set_fill
|
596
|
+
|
597
|
+
---each_dim{ ... }
|
598
|
+
Iterator regarding the dimensions in the file.
|
599
|
+
Ex.: {|i| print i.name,"\n"} prints names of all dimensions
|
600
|
+
|
601
|
+
Arguments
|
602
|
+
* { ... } : Block for the iterator. A "do end" block is the alternative.
|
603
|
+
|
604
|
+
Return value
|
605
|
+
* self
|
606
|
+
|
607
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
608
|
+
* (dependent on nc_inq_ndims)
|
609
|
+
|
610
|
+
---each_var{ ... }
|
611
|
+
Iterator regarding the variables in the file.
|
612
|
+
Ex.: {|i| print i.name,"\n"} prints names of all variables
|
613
|
+
|
614
|
+
Arguments
|
615
|
+
* { ... } : Block for the iterator. A "do end" block is the alternative.
|
616
|
+
|
617
|
+
Return value
|
618
|
+
* self
|
619
|
+
|
620
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
621
|
+
* (dependent on nc_inq_nvars)
|
622
|
+
|
623
|
+
---each_att{ ... }
|
624
|
+
Iterator regarding the global attributes of the file.
|
625
|
+
Ex.: {|i| print i.name,"\n"} prints names of all of them.
|
626
|
+
|
627
|
+
Arguments
|
628
|
+
* { ... } : Block for the iterator. A "do end" block is the alternative.
|
629
|
+
|
630
|
+
Return value
|
631
|
+
* self
|
632
|
+
|
633
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
634
|
+
* (dependent on nc_inq_natts, nc_inq_attname)
|
635
|
+
|
636
|
+
---dim_names
|
637
|
+
Returns the names of all dimensions in the file
|
638
|
+
|
639
|
+
Arguments
|
640
|
+
* (none)
|
641
|
+
|
642
|
+
Return value
|
643
|
+
* Array of NetCDFDim
|
644
|
+
|
645
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
646
|
+
* (nc_inq_ndims, nc_inq_dimname)
|
647
|
+
|
648
|
+
---var_names
|
649
|
+
Returns the names of all variables in the file
|
650
|
+
|
651
|
+
Arguments
|
652
|
+
* (none)
|
653
|
+
|
654
|
+
Return value
|
655
|
+
* Array of String
|
656
|
+
|
657
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
658
|
+
* (dependent on nc_inq_nvars, nc_inq_varname)
|
659
|
+
|
660
|
+
---att_names
|
661
|
+
Returns the names of all the global attributes of the file
|
662
|
+
|
663
|
+
Arguments
|
664
|
+
* (none)
|
665
|
+
|
666
|
+
Return value
|
667
|
+
* Array of NetCDFAtt
|
668
|
+
|
669
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
670
|
+
* (dependent on nc_inq_natts, nc_inq_attname)
|
671
|
+
|
672
|
+
---------------------------------------------
|
673
|
+
|
674
|
+
=class NetCDFDim
|
675
|
+
===Class Methods
|
676
|
+
|
677
|
+
===Instance Methods
|
678
|
+
---length
|
679
|
+
Returns the length of the dimension
|
680
|
+
|
681
|
+
Arguments
|
682
|
+
* (none)
|
683
|
+
|
684
|
+
Return value
|
685
|
+
* Integer
|
686
|
+
|
687
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
688
|
+
* nc_inq_dimlen
|
689
|
+
|
690
|
+
---length_ul0
|
691
|
+
Same as length but returns 0 for the unlimited dimension
|
692
|
+
|
693
|
+
Arguments
|
694
|
+
* (none)
|
695
|
+
|
696
|
+
Return value
|
697
|
+
* Integer
|
698
|
+
|
699
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
700
|
+
* nc_inq_dimlen
|
701
|
+
|
702
|
+
---name=(dimension_newname)
|
703
|
+
Rename the dimension
|
704
|
+
|
705
|
+
Arguments
|
706
|
+
* dimension_newname (String) : new name
|
707
|
+
|
708
|
+
Return value
|
709
|
+
* nil
|
710
|
+
|
711
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
712
|
+
* nc_rename_dim
|
713
|
+
|
714
|
+
---name
|
715
|
+
Returns the name of the dimension
|
716
|
+
|
717
|
+
Arguments
|
718
|
+
* (none)
|
719
|
+
|
720
|
+
Return value
|
721
|
+
* String
|
722
|
+
|
723
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
724
|
+
* nc_inq_dimname
|
725
|
+
|
726
|
+
---unlimited?
|
727
|
+
Inquires whether the dimension is unlimited or not
|
728
|
+
|
729
|
+
Arguments
|
730
|
+
* (none)
|
731
|
+
|
732
|
+
Return value
|
733
|
+
* true or false
|
734
|
+
|
735
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
736
|
+
* (dependent on nc_inq_unlimdim)
|
737
|
+
|
738
|
+
---------------------------------------------
|
739
|
+
|
740
|
+
=class NetCDFVar
|
741
|
+
===Class Methods
|
742
|
+
---NetCDFVar.new(file,varname,mode="r",share=false)
|
743
|
+
open a NetCDF variable. This can also be done with NetCDF#var
|
744
|
+
(instance method of NetCDF class), which is recommended over
|
745
|
+
this method.
|
746
|
+
|
747
|
+
Arguments
|
748
|
+
* file (NetCDF or String) : a NetCDF file object (NetCDF)
|
749
|
+
or the path of a NetCDF file (String).
|
750
|
+
* varname (String) : name of the variable in the file
|
751
|
+
* mode (String) : IO mode -- used if file is a String (see NetCDF.open)
|
752
|
+
* share (true or false) : Whether to use the "shared" mode or
|
753
|
+
not -- used if file is a String (see NetCDF.open)
|
754
|
+
|
755
|
+
Return value
|
756
|
+
* a NetCDFVar object
|
757
|
+
|
758
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
759
|
+
* (dependent on nc_open, nc_create, nc_inq_varid etc.)
|
760
|
+
|
761
|
+
---NetCDFVar.unpack_type=(na_type)
|
762
|
+
Fix the NArray type to be used in ((<unpack>)).
|
763
|
+
|
764
|
+
Arguments
|
765
|
+
* na_type (Integer) : NArray::BYTE, NArray::SINT, NArray::INT,
|
766
|
+
NArray::SFLOAT, or NArray::FLOAT
|
767
|
+
|
768
|
+
Return value
|
769
|
+
* na_type (the argument)
|
770
|
+
|
771
|
+
---NetCDFVar.unpack_type
|
772
|
+
Returns the NArray type set by ((<NetCDFVar.unpack_type=>)).
|
773
|
+
|
774
|
+
Return value
|
775
|
+
* nil, NArray::BYTE, NArray::SINT, NArray::INT,
|
776
|
+
NArray::SFLOAT, or NArray::FLOAT
|
777
|
+
|
778
|
+
===Instance Methods
|
779
|
+
---dim(dim_num)
|
780
|
+
Inquires the dim_num-th dimension of the variable (dim_num=0,1,2,..)
|
781
|
+
|
782
|
+
Arguments
|
783
|
+
* dim_num (Fixnum) : 0,1,... 0 is the fastest varying dimension.
|
784
|
+
|
785
|
+
Return value
|
786
|
+
* a NetCDFDim object
|
787
|
+
|
788
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
789
|
+
* (dependent on nc_inq_vardimid)
|
790
|
+
|
791
|
+
---dims
|
792
|
+
Returns an array of all the dimensions of the variable
|
793
|
+
|
794
|
+
Arguments
|
795
|
+
* (none)
|
796
|
+
|
797
|
+
Return value
|
798
|
+
* Array of NetCDFDim objects.
|
799
|
+
|
800
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
801
|
+
* nc_inq_vardimid
|
802
|
+
|
803
|
+
---shape_ul0
|
804
|
+
Returns the shape of the variable, but the length of the unlimited dimension is set to zero.
|
805
|
+
Good to define another variable.
|
806
|
+
|
807
|
+
Arguments
|
808
|
+
* (none)
|
809
|
+
|
810
|
+
Return value
|
811
|
+
* Array. [length of 0th dim, length of 1st dim,.. ]
|
812
|
+
|
813
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
814
|
+
* (dependent on nc_inq_vardimid, nc_inq_unlimdim etc)
|
815
|
+
|
816
|
+
---shape_current
|
817
|
+
Returns the current shape of the variable.
|
818
|
+
|
819
|
+
Arguments
|
820
|
+
* (none)
|
821
|
+
|
822
|
+
Return value
|
823
|
+
* Array. [length of 0th dim, length of 1st dim,.. ]
|
824
|
+
|
825
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
826
|
+
* (dependent on nc_inq_vardimid etc)
|
827
|
+
|
828
|
+
---each_att{ ... }
|
829
|
+
Iterator regarding the global attributes of the variables.
|
830
|
+
Ex.: {|i| print i.name,"\n"} prints names of all of them.
|
831
|
+
|
832
|
+
Arguments
|
833
|
+
* { ... } : Block for the iterator. A "do end" block is the alternative.
|
834
|
+
|
835
|
+
Return value
|
836
|
+
* self
|
837
|
+
|
838
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
839
|
+
* (dependent on nc_inq_natts, nc_inq_attname)
|
840
|
+
|
841
|
+
---dim_names
|
842
|
+
Returns the names of all the dimensions of the variable
|
843
|
+
|
844
|
+
Arguments
|
845
|
+
* (none)
|
846
|
+
|
847
|
+
Return value
|
848
|
+
* Array of String
|
849
|
+
|
850
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
851
|
+
* (dependent on nc_inq_varndims, nc_inq_vardimid, nc_inq_dimname)
|
852
|
+
|
853
|
+
---att_names
|
854
|
+
Returns the names of all the attributes of the variable
|
855
|
+
|
856
|
+
Arguments
|
857
|
+
* (none)
|
858
|
+
|
859
|
+
Return value
|
860
|
+
* Array of String
|
861
|
+
|
862
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
863
|
+
* (dependent on nc_inq_natts, nc_inq_attname)
|
864
|
+
|
865
|
+
---name
|
866
|
+
Returns the name of the variable
|
867
|
+
|
868
|
+
Arguments
|
869
|
+
* (none)
|
870
|
+
|
871
|
+
Return value
|
872
|
+
* String
|
873
|
+
|
874
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
875
|
+
* nc_inq_varname
|
876
|
+
|
877
|
+
---name=(variable_newname)
|
878
|
+
Rename the variable
|
879
|
+
|
880
|
+
Arguments
|
881
|
+
* variable_newname (String) : new name
|
882
|
+
|
883
|
+
Return value
|
884
|
+
* nil
|
885
|
+
|
886
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
887
|
+
* nc_rename_var
|
888
|
+
|
889
|
+
---ndims
|
890
|
+
Number of dimensions of the variable (which is rank of the variable).
|
891
|
+
|
892
|
+
Arguments
|
893
|
+
* (none)
|
894
|
+
|
895
|
+
Return value
|
896
|
+
* Integer
|
897
|
+
|
898
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
899
|
+
* nc_inq_varndims
|
900
|
+
|
901
|
+
---rank
|
902
|
+
Aliased to ndims
|
903
|
+
|
904
|
+
---ntype
|
905
|
+
Aliased to vartype
|
906
|
+
|
907
|
+
---vartype
|
908
|
+
Inquires the data value type of the variable
|
909
|
+
|
910
|
+
Arguments
|
911
|
+
* (none)
|
912
|
+
|
913
|
+
Return value
|
914
|
+
* String ("char","byte","sint","int","sfloat", or "float")
|
915
|
+
|
916
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
917
|
+
* nc_inq_vartype
|
918
|
+
|
919
|
+
---typecode
|
920
|
+
Inquires the data type of the variable (returns a typecode of NArray)
|
921
|
+
|
922
|
+
Arguments
|
923
|
+
* (none)
|
924
|
+
|
925
|
+
Return value
|
926
|
+
* a Fixnum (NArray:BYTE, NArray:SINT, NArray:LINT, NArray:SFLOAT, NArray:SFLOAT, NArray:DFLOAT)
|
927
|
+
|
928
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
929
|
+
* nc_inq_vartype
|
930
|
+
|
931
|
+
---natts
|
932
|
+
Returns the number of the attributes of the variable
|
933
|
+
|
934
|
+
Arguments
|
935
|
+
* (none)
|
936
|
+
|
937
|
+
Return value
|
938
|
+
* Integer
|
939
|
+
|
940
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
941
|
+
* nc_inq_varnatts
|
942
|
+
|
943
|
+
---file
|
944
|
+
Inquires the file that the variable is in
|
945
|
+
|
946
|
+
Arguments
|
947
|
+
* (none)
|
948
|
+
|
949
|
+
Return value
|
950
|
+
* a NetCDF object
|
951
|
+
|
952
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
953
|
+
* (none)
|
954
|
+
|
955
|
+
---att(attribute_name)
|
956
|
+
Returns the attribute specified by its name
|
957
|
+
|
958
|
+
Arguments
|
959
|
+
* attribute_name (String) : Name of the attribute
|
960
|
+
|
961
|
+
Return value
|
962
|
+
* a NetCDFAtt object if the attribute exists; nil if not
|
963
|
+
|
964
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
965
|
+
* (nc_inq_attid is used for inquiry)
|
966
|
+
|
967
|
+
---put_att(attribute_name, value, atttype=nil)
|
968
|
+
Sets an attribute
|
969
|
+
|
970
|
+
Arguments
|
971
|
+
* attribute_name (String) : name of the attribute
|
972
|
+
* value (Numeric, String, Array of Numeric, or NArray) : value of the attribute
|
973
|
+
* atttype (nil or String) : data type of the attribute value.
|
974
|
+
nil lets it automatically determined from the value.
|
975
|
+
"char" (="string"), "byte", "sint", "int", "sfloat", or "float"
|
976
|
+
specifies the type explicitly (1,1,2,4,4,8 bytes, respectively)
|
977
|
+
|
978
|
+
Return value
|
979
|
+
* a NetCDFAtt object
|
980
|
+
|
981
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
982
|
+
* nc_put_att_<type>
|
983
|
+
|
984
|
+
---put(value, option=nil)
|
985
|
+
Aliased to ((<simple_put>))
|
986
|
+
|
987
|
+
---simple_put(value, option=nil)
|
988
|
+
Set the values of the variable
|
989
|
+
|
990
|
+
Arguments
|
991
|
+
* value : value to set (Numeric, Array of Numeric (1D only), or
|
992
|
+
NArray (possibly multi-D)). If it is a Numeric or length==1, the value
|
993
|
+
is set uniformly.
|
994
|
+
* option (Hash) : Optional argument to limit the portion of the
|
995
|
+
variable to output values. If omitted, the whole variable is
|
996
|
+
subject to the output. This argument accepts a Hash whose keys
|
997
|
+
contain either "index" or a combination of "start","end", and
|
998
|
+
"stride". The value of "index" points the index of a scalar
|
999
|
+
portion of the variable. The other case is used to designate a
|
1000
|
+
regularly ordered subset, where "start" and "end" specifies
|
1001
|
+
bounds in each dimension and "stride" specifies intervals in
|
1002
|
+
it. As in Array "start", "end", and "index" can take negative
|
1003
|
+
values to specify index backward from the end. However,
|
1004
|
+
"stride" has to be positive, so reversing the array must be
|
1005
|
+
done afterwards if you like.
|
1006
|
+
|
1007
|
+
Example: If the variable is 2D:
|
1008
|
+
|
1009
|
+
{"start"=>[2,5],"end"=>[6,-1],"stride"=>[2,4]} -- Specifies a
|
1010
|
+
subset made as follows: the 1st dimension from the element 2
|
1011
|
+
to the element 6 (note that the count starts with 0, so that
|
1012
|
+
the element 2 is the 3rd one) with an interval of 2;
|
1013
|
+
the 2nd dimension from the element 6 to the last element
|
1014
|
+
(designated by -1) with an interval of 5.
|
1015
|
+
|
1016
|
+
{"index"=>[0,0]}: Scalar of the fist element
|
1017
|
+
|
1018
|
+
{"index"=>[0,-2]}: Scalar from the 1st element of with
|
1019
|
+
respect to the 1st dimension and the 2nd element from the last
|
1020
|
+
with respect to the 2nd dimension
|
1021
|
+
|
1022
|
+
|
1023
|
+
Return value
|
1024
|
+
* nil
|
1025
|
+
|
1026
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1027
|
+
* nc_put_var_<type>, nc_put_vars_<type>, nc_put_var1_<type>
|
1028
|
+
|
1029
|
+
---pack(na)
|
1030
|
+
Pack a NArray (etc) using the attributes scale_factor and/or add_offset of self.
|
1031
|
+
|
1032
|
+
If scale_factor and/or add_offset is defined, returns
|
1033
|
+
(na-add_offset)/scale_factor. Returns na if not.
|
1034
|
+
|
1035
|
+
Arguments
|
1036
|
+
* na : a numeric array to pack (NArray, NArrayMiss, or Array)
|
1037
|
+
|
1038
|
+
Return value
|
1039
|
+
* a NArray or NArrayMiss
|
1040
|
+
|
1041
|
+
---scaled_put(value, option=nil)
|
1042
|
+
Same as ((<simple_put>)) but interprets the attributes scale_factor and/or add_offset using ((<pack>)).
|
1043
|
+
|
1044
|
+
See the document for ((<simple_put>)) for arguments etc.
|
1045
|
+
|
1046
|
+
---get(option=nil)
|
1047
|
+
Aliased to ((<simple_get>)).
|
1048
|
+
|
1049
|
+
---simple_get(option=nil)
|
1050
|
+
Returns values of the variable
|
1051
|
+
|
1052
|
+
Arguments
|
1053
|
+
* option (Hash) : Optional argument to limit the portion of the
|
1054
|
+
variable to get values. Its usage is the same as in the method
|
1055
|
+
put.
|
1056
|
+
|
1057
|
+
Return value
|
1058
|
+
* an NArray object
|
1059
|
+
|
1060
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1061
|
+
* nc_get_var_<type>, nc_get_vars_<type>, nc_get_var1_<type>
|
1062
|
+
|
1063
|
+
---unpack(na)
|
1064
|
+
Unpack a NArray (etc) using the attributes scale_factor and/or add_offset of self.
|
1065
|
+
|
1066
|
+
If scale_factor and/or add_offset is defined, returns
|
1067
|
+
na * scale_factor + add_offset. Returns na if not.
|
1068
|
+
Type conversion is made by the coercing -- for example
|
1069
|
+
if na is sint and scale_factor and add_offset is sfloat,
|
1070
|
+
return value is sfloat. The type of the return value can be specified
|
1071
|
+
explicitly with ((<NetCDFVar.unpack_type=>)).
|
1072
|
+
|
1073
|
+
Arguments
|
1074
|
+
* na : a numeric array to unpack (NArray, or NArrayMiss)
|
1075
|
+
|
1076
|
+
Return value
|
1077
|
+
* a NArray or NArrayMiss
|
1078
|
+
|
1079
|
+
---scaled_get(option=nil)
|
1080
|
+
Same as ((<simple_get>)) but interprets the attributes scale_factor and/or add_offset using ((<unpack>)).
|
1081
|
+
|
1082
|
+
See the document for ((<simple_get>)) for arguments etc.
|
1083
|
+
|
1084
|
+
---[]
|
1085
|
+
Same as NetCDFVar#get but a subset is specified as in the method [] of NArray.
|
1086
|
+
|
1087
|
+
In addition to the subset specifications supported by NArray,
|
1088
|
+
ranges with steps are supported, which is specified
|
1089
|
+
like {0..-1, 3}, i.e., a 1-element Hash with the key and value
|
1090
|
+
representing the range (Range) and the step (Integer), respectively.
|
1091
|
+
Unlike NArray, 1-dimensional indexing of multi-dimensional
|
1092
|
+
variables is not support.
|
1093
|
+
|
1094
|
+
---[]=
|
1095
|
+
Same as NetCDFVar#put but a subset is specified as in the method []= of NArray.
|
1096
|
+
|
1097
|
+
In addition to the subset specifications supported by NArray,
|
1098
|
+
ranges with steps are supported, which is specified
|
1099
|
+
like {0..-1, 3}, i.e., a 1-element Hash with the key and value
|
1100
|
+
representing the range (Range) and the step (Integer), respectively.
|
1101
|
+
Unlike NArray, 1-dimensional indexing of multi-dimensional
|
1102
|
+
variables is not support.
|
1103
|
+
|
1104
|
+
===Instance Methods added by requiring "numru/netcdf_miss"
|
1105
|
+
|
1106
|
+
---get_with_miss(option=nil)
|
1107
|
+
Same as ((<get>)) but interprets data missing.
|
1108
|
+
|
1109
|
+
Data missing is specified by the standard attributes valid_range,
|
1110
|
+
(valid_min and/or valid_max), or missing_value, with the precedence being
|
1111
|
+
this order. Unlike the
|
1112
|
+
recommendation in the NetCDF User's guide, missing_value is
|
1113
|
+
interpreted if present. If missing_value and valid_* present
|
1114
|
+
simultaneously, missing_value must be outside the valid range.
|
1115
|
+
Otherwise, exception is raised.
|
1116
|
+
|
1117
|
+
If data missing is specified as stated above, this method returns a NArrayMiss.
|
1118
|
+
If not, it returns a NArray. Thus, you can use this whether
|
1119
|
+
data missing is defined or not.
|
1120
|
+
|
1121
|
+
Arguments
|
1122
|
+
* See ((<get>)).
|
1123
|
+
|
1124
|
+
Return value
|
1125
|
+
* an NArrayMiss (if data missing is specified) or an NArray
|
1126
|
+
(if data missing is NOT specified)
|
1127
|
+
|
1128
|
+
Possible exception in addition to NetcdfError.
|
1129
|
+
* missing_value is in the valid range (see above).
|
1130
|
+
|
1131
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1132
|
+
* See ((<get>)). This method is written in Ruby.
|
1133
|
+
|
1134
|
+
EXAMPLE
|
1135
|
+
* The following is an example to replace ((<get>)) with ((<get_with_miss>)).
|
1136
|
+
It will also make ((<[]>)) interpret data missing,
|
1137
|
+
since it calls (({get})) internally.
|
1138
|
+
|
1139
|
+
file = NetCDF.open('hogehoge.nc')
|
1140
|
+
var = file.var('var')
|
1141
|
+
def var.get(*args); get_with_miss(*args); end
|
1142
|
+
p var.get # --> interprets data missing if defined
|
1143
|
+
p var[0..-1,0] # --> interprets data missing if defined (assumed 2D)
|
1144
|
+
|
1145
|
+
---get_with_miss_and_scaling(option=nil)
|
1146
|
+
Same as ((<get_with_miss>)) but handles data scaling too using ((<unpack>)).
|
1147
|
+
|
1148
|
+
Missing data handling using valid_* / missing_value is applied
|
1149
|
+
basically to packed data, which is consistent with most
|
1150
|
+
conventions. However, it is applied to unpacked data
|
1151
|
+
if and only if the type of valid_* / missing_value is not the same as
|
1152
|
+
the packed data and is the samed as the unpacked data.
|
1153
|
+
This treatment can handle all conventions.
|
1154
|
+
|
1155
|
+
EXAMPLE
|
1156
|
+
* See above. The same thing applies.
|
1157
|
+
|
1158
|
+
---put_with_miss(value, option=nil)
|
1159
|
+
Same as ((<put>)) but interprets data missing.
|
1160
|
+
|
1161
|
+
If (({value})) is an NArray, the methods behaves as ((<put>)).
|
1162
|
+
Data missing in (({value})) is interpreted if it is an NArrayMiss
|
1163
|
+
and data missing is specified by attributes in (({self}))
|
1164
|
+
(see ((<get_with_miss>)) ).
|
1165
|
+
Namely, the data which are "invalid" in the (({value})) is replaced
|
1166
|
+
with a missing value when written in the file.
|
1167
|
+
(missing_value or _FillValue or a value outside
|
1168
|
+
the valid range). No check is made whether "valid" values in the
|
1169
|
+
NArrayMiss is within the valid range of (({self})).
|
1170
|
+
|
1171
|
+
Arguments
|
1172
|
+
* value : NArrayMiss or what is allowed in ((<put>)).
|
1173
|
+
* option (Hash) : See ((<put>)).
|
1174
|
+
|
1175
|
+
Return value
|
1176
|
+
* nil
|
1177
|
+
|
1178
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1179
|
+
* See ((<put>)). This method is written in Ruby.
|
1180
|
+
|
1181
|
+
EXAMPLE
|
1182
|
+
* The following is an example to replace ((<put>)) with ((<put_with_miss>)).
|
1183
|
+
It will also make ((<[]=>)) interpret data missing,
|
1184
|
+
since it calls (({put})) internally.
|
1185
|
+
|
1186
|
+
file = NetCDF.open('hogehoge.nc')
|
1187
|
+
var = file.var('var')
|
1188
|
+
def var.put(*args); put_with_miss(*args); end
|
1189
|
+
var.put = narray_miss # --> interprets data missing if defined
|
1190
|
+
var[0..-1,0] = narray_miss # --> interprets data missing if defined (assumed 2D)
|
1191
|
+
|
1192
|
+
---put_with_miss_and_scaling(value, option=nil)
|
1193
|
+
Same as ((<put_with_miss>)) but handles data scaling too using ((<pack>)).
|
1194
|
+
|
1195
|
+
Missing data handling using valid_* / missing_value is applied
|
1196
|
+
basically to packed data, which is consistent with most
|
1197
|
+
conventions. However, it is applied to unpacked data
|
1198
|
+
if and only if the type of valid_* / missing_value is not the same as
|
1199
|
+
the packed data and is the samed as the unpacked data.
|
1200
|
+
This treatment can handle all conventions.
|
1201
|
+
|
1202
|
+
EXAMPLE
|
1203
|
+
* See above. The same thing applies.
|
1204
|
+
|
1205
|
+
---------------------------------------------
|
1206
|
+
|
1207
|
+
=class NetCDFAtt
|
1208
|
+
===Class Methods
|
1209
|
+
|
1210
|
+
===Instance Methods
|
1211
|
+
---name
|
1212
|
+
Returns the name of the attribute
|
1213
|
+
|
1214
|
+
Arguments
|
1215
|
+
* (none)
|
1216
|
+
|
1217
|
+
Return value
|
1218
|
+
* String
|
1219
|
+
|
1220
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1221
|
+
* (none)
|
1222
|
+
|
1223
|
+
---name=(attribute_newname)
|
1224
|
+
Rename the attribute
|
1225
|
+
|
1226
|
+
Arguments
|
1227
|
+
* attribute_newname (String) : New name
|
1228
|
+
|
1229
|
+
Return value
|
1230
|
+
* nil
|
1231
|
+
|
1232
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1233
|
+
* nc_rename_att
|
1234
|
+
|
1235
|
+
---copy(var_or_file)
|
1236
|
+
Copies an attribute to a variable or a file. If file, becomes an global attribute
|
1237
|
+
|
1238
|
+
Arguments
|
1239
|
+
* var_or_file (NetCDFVar or NetCDF)
|
1240
|
+
|
1241
|
+
Return value
|
1242
|
+
* Resultant new attribute (NetCDFAtt)
|
1243
|
+
|
1244
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1245
|
+
* nc_copy_att
|
1246
|
+
|
1247
|
+
---delete
|
1248
|
+
Delete an attribute
|
1249
|
+
|
1250
|
+
Arguments
|
1251
|
+
* (none)
|
1252
|
+
|
1253
|
+
Return value
|
1254
|
+
* nil
|
1255
|
+
|
1256
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1257
|
+
* nc_del_att
|
1258
|
+
|
1259
|
+
---put(value, atttype=nil)
|
1260
|
+
Sets the value of the attribute
|
1261
|
+
|
1262
|
+
Arguments
|
1263
|
+
* value (Numeric, String, Array of Numeric, or NArray) : value of the attribute
|
1264
|
+
* atttype (nil or String) : data type of the attribute value.
|
1265
|
+
nil lets it automatically determined from the value.
|
1266
|
+
"char" (="string"), "byte", "sint", "int", "sfloat", or "float"
|
1267
|
+
specifies the type explicitly (1,1,2,4,4,8 bytes, respectively)
|
1268
|
+
|
1269
|
+
Return value
|
1270
|
+
* nil
|
1271
|
+
|
1272
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1273
|
+
* nc_put_att_<type>
|
1274
|
+
|
1275
|
+
---get
|
1276
|
+
Returns the values of the attribute
|
1277
|
+
|
1278
|
+
Arguments
|
1279
|
+
* (none)
|
1280
|
+
|
1281
|
+
Return value
|
1282
|
+
* String or an NArray object (NOTE: even a scalar is returned as
|
1283
|
+
an NArray of length 1)
|
1284
|
+
|
1285
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1286
|
+
* nc_get_att_<type>
|
1287
|
+
|
1288
|
+
---atttype
|
1289
|
+
Inquires the type of attribute values
|
1290
|
+
|
1291
|
+
Arguments
|
1292
|
+
* (none)
|
1293
|
+
|
1294
|
+
Return value
|
1295
|
+
* "char","byte","sint","int","sfloat","float"
|
1296
|
+
|
1297
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1298
|
+
* nc_inq_atttype
|
1299
|
+
|
1300
|
+
---atttype
|
1301
|
+
Inquires the type of attribute values (returns a NArray typecode)
|
1302
|
+
|
1303
|
+
Arguments
|
1304
|
+
* (none)
|
1305
|
+
|
1306
|
+
Return value
|
1307
|
+
* a Fixnum (NArray:BYTE, NArray:SINT, NArray:LINT, NArray:SFLOAT, NArray:SFLOAT, NArray:DFLOAT)
|
1308
|
+
|
1309
|
+
Corresponding (dependent) function(s) in the C library of NetCDF
|
1310
|
+
* nc_inq_atttype
|
1311
|
+
|
1312
|
+
=end
|