ruby-netcdf 0.6.6.1 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/ChangeLog +51 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -40
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/demo/demo5-netcdf4.rb +44 -0
- data/doc/Ref_man.html +340 -239
- data/doc/Ref_man.rd +91 -0
- data/doc/Ref_man_jp.html +940 -835
- data/doc/Ref_man_jp.rd +95 -0
- data/doc/to_html +3 -3
- data/extconf.rb +113 -78
- data/lib/netcdf.rb +89 -73
- data/lib/version.rb +5 -0
- data/netcdfraw.c +276 -169
- data/ruby-netcdf.gemspec +34 -0
- metadata +92 -97
data/doc/Ref_man_jp.rd
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
=begin
|
2
2
|
=RubyNetCDF ��ե���ޥ˥奢��
|
3
3
|
|
4
|
+
RubyNetCDF version : 0.7.1
|
5
|
+
|
4
6
|
* ((<��åɥ���ǥå���>))
|
5
7
|
|
6
8
|
---------------------------------------------
|
@@ -23,6 +25,8 @@ NumPy
|
|
23
25
|
((<NArrayMiss|URL:http://ruby.gfd-dennou.org/products/narray_miss/>))
|
24
26
|
��ɬ�פǤ��롣�ܤ�����((<����ˡ>))�衣
|
25
27
|
|
28
|
+
���� NetCDF-4 �Υ��ݡ��Ȥ���ʬŪ�Ǥ���(�������ǡ�����ǥ�ϥ��ݡ��Ȥ��Ƥʤ�)��
|
29
|
+
|
26
30
|
===����
|
27
31
|
|
28
32
|
RubyNetCDF �ϰʲ��Σ��ĤΥ��饹���鹽������롣
|
@@ -146,6 +150,9 @@ RubyNetCDF
|
|
146
150
|
* ((<���饹 NetCDF>))
|
147
151
|
|
148
152
|
���饹��å�
|
153
|
+
* ((<NetCDF.nc4?>)) ����줿 NetCDF �� version 4 ���ɤ����֤�
|
154
|
+
* ((<NetCDF.creation_format=>)) NetCDF.create�Ǻ����ե�����ե����ޥåȤ����ꤹ�� (NetCDF-4 ����).
|
155
|
+
* ((<NetCDF.creation_format>)) NetCDF.create�Ǻ����ե�����ե����ޥåȤ�������֤�. (NetCDF-4 ����).
|
149
156
|
* ((<NetCDF.open>)) �ե����륪���ץ�ʥ��饹��åɡ�mode="w" �ǥե����뤬¸�ߤ��ʤ���п�������
|
150
157
|
* ((<NetCDF.new>)) NetCDF.open��åɤΥ����ꥢ���Ǥ���
|
151
158
|
* ((<NetCDF.create>)) NetCDF�ե��������ʥ��饹��å�)
|
@@ -199,6 +206,10 @@ RubyNetCDF
|
|
199
206
|
|
200
207
|
|
201
208
|
������å�
|
209
|
+
* ((<deflate>)) ���� (deflation) ������. (netCDF-4 only)
|
210
|
+
* ((<deflate_params>)) ���ߤΰ���������礻. (netCDF-4 only)
|
211
|
+
* ((<endian=>)) ����ǥ���������� (netCDF-4 only)
|
212
|
+
* ((<endian>)) ����ǥ�����������֤�. (netCDF-4 only)
|
202
213
|
* ((<dim>)) �����ѿ��ˤ����� dim_num ����(0���������)�μ��������碌�롣
|
203
214
|
* ((<dims>)) �����ѿ���������������ˤ�����֤�
|
204
215
|
* ((<shape_ul0>)) �ѿ��η����֤�. â��̵���¼�����Ĺ���ϥ���.
|
@@ -254,7 +265,36 @@ RubyNetCDF
|
|
254
265
|
---------------------------------------------
|
255
266
|
|
256
267
|
=���饹 NetCDF
|
268
|
+
===���
|
269
|
+
* NC_NOWRITE, NC_WRITE, NC_SHARE, NC_CLOBBER, NC_NOCLOBBER, NC_64BIT_OFFSET, NC_NETCDF4, NC_CLASSIC_MODEL, NCVERSION, SUPPORT_BIGMEM : ������ NumRu::NetCDF::NC_NOWRITE �ʤɥ����������롣
|
270
|
+
|
257
271
|
===���饹��å�
|
272
|
+
---NetCDF.nc4?
|
273
|
+
���Υ饤�֥�꤬ NetCDF version 4 ��Ȥ��褦�ˤʤäƤ����
|
274
|
+
�ʥ����Ƥ� NetCDF �饤�֥�꤬ver 4�ʤ��true ��
|
275
|
+
�����Ǥʤ���� (NetCDF 3�ʤ�) false ���֤���
|
276
|
+
|
277
|
+
---NetCDF.creation_format=(cmode)
|
278
|
+
(���Υ�åɤ� NetCDF-4 ���Ȥ��Ƥ�Ȥ��Τ��Ѳ�ǽ�������Ǥʤ����
|
279
|
+
�㳰��ȯ������). NetCDF.create �Ǻ����ե�����Υե����ޥåȤ���ꤹ��.
|
280
|
+
�������� "classic".
|
281
|
+
|
282
|
+
����
|
283
|
+
* cmode : �ʲ��Τ����줫��
|
284
|
+
* 0, nil, or NetCDF::NC_CLASSIC_MODEL : classic format
|
285
|
+
(��������� NetCDF-3 �Υե����ޥå�). ���줬�������.
|
286
|
+
* NetCDF::NC_64BIT_OFFSET : classic �������ѿ��Υ��������礭�������
|
287
|
+
* NetCDF::NC_NETCDF4 : HDF5 �١����� NetCDF-4 ���ե����ޥå�
|
288
|
+
* ( NetCDF::NC_NETCDF4 | NetCDF::NC_CLASSIC_MODEL) [�����
|
289
|
+
NetCDF::NC_NETCDF4 �� NetCDF::NC_CLASSIC_MODEL �� bit "or"]:
|
290
|
+
NetCDF-4 ���ե����ޥåȤ������������ǡ�����ǥ�ϻȤ��ʤ��褦����.
|
291
|
+
|
292
|
+
|
293
|
+
---NetCDF.creation_format
|
294
|
+
(���Υ�åɤ� NetCDF-4 ���Ȥ��Ƥ�Ȥ��Τ��Ѳ�ǽ�������Ǥʤ����
|
295
|
+
�㳰��ȯ������).
|
296
|
+
NetCDF.create �Ǻ����ե�����Υե����ޥåȤθ��ߤ�������֤�.
|
297
|
+
|
258
298
|
---NetCDF.open(filename, mode="r", share=false)
|
259
299
|
�ե����륪���ץ�ʥ��饹��åɡ�mode="w" �ǥե����뤬¸�ߤ��ʤ���п�������
|
260
300
|
|
@@ -757,6 +797,61 @@ RubyNetCDF
|
|
757
797
|
NArray::SFLOAT, or NArray::FLOAT
|
758
798
|
|
759
799
|
===������å�
|
800
|
+
---deflate(deflate_level, shuffle=false)
|
801
|
+
(���Υ�åɤ� NetCDF-4 ���Ȥ��Ƥ�Ȥ��Τ��Ѳ�ǽ�������Ǥʤ����
|
802
|
+
�㳰��ȯ������).
|
803
|
+
(�������������줿)�ѿ�������(deflate)�����褦�ˤ���. ���Υ�åɤϡ�
|
804
|
+
�ѿ������ (NetCDF#((<def_var>))) �����塤NetCDF#((<enddef>))
|
805
|
+
��Ƥ����˸ƤФʤ���Фʤ�ʤ�.
|
806
|
+
|
807
|
+
����
|
808
|
+
* deflate_level (Integer) :: 0 to 9. (0: no compression; 9:
|
809
|
+
highest compression; recommended: 1 or 2).
|
810
|
+
* shuffle (optional; true or false; default: false) if true,
|
811
|
+
turn on the shuffle filter.
|
812
|
+
* ((<URL:http://www.unidata.ucar.edu/software/netcdf/papers/AMS_2008.pdf>)):
|
813
|
+
``The shuffle algorithm changes the byte order in the data stream;
|
814
|
+
when used with integers that are all close together, this
|
815
|
+
results in a better compression ratio. There is no benefit
|
816
|
+
from using the shuffle filter without also using
|
817
|
+
compression.''
|
818
|
+
* Note: shuffle is effective for float variables too (tested by horinouchi).
|
819
|
+
|
820
|
+
�����
|
821
|
+
* self
|
822
|
+
|
823
|
+
---deflate_params
|
824
|
+
(���Υ�åɤ� NetCDF-4 ���Ȥ��Ƥ�Ȥ��Τ��Ѳ�ǽ�������Ǥʤ����
|
825
|
+
�㳰��ȯ������).
|
826
|
+
���ߤΰ���(deflation)�ѥ������֤���
|
827
|
+
|
828
|
+
�����
|
829
|
+
* [shuffle, deflate, deflate_level] (a 3-element Array).
|
830
|
+
shuffle �� deflate �� true �ޤ��� false. deflate_level ������(0-9).
|
831
|
+
|
832
|
+
---endian=(endian)
|
833
|
+
(���Υ�åɤ� NetCDF-4 ���Ȥ��Ƥ�Ȥ��Τ��Ѳ�ǽ�������Ǥʤ����
|
834
|
+
�㳰��ȯ������).
|
835
|
+
����ǥ���������ꤹ�롣���ѥ����ߥ� ((<deflate>)) ��Ʊ����
|
836
|
+
|
837
|
+
Arguments
|
838
|
+
* endian : ���Τ����줫:
|
839
|
+
NetCDF::NC_ENDIAN_NATIVE (=0) (default),
|
840
|
+
NetCDF::NC_ENDIAN_LITTLE (=1), or NetCDF::NC_ENDIAN_BIG (=2).
|
841
|
+
|
842
|
+
Return value
|
843
|
+
* self
|
844
|
+
|
845
|
+
---endian
|
846
|
+
(���Υ�åɤ� NetCDF-4 ���Ȥ��Ƥ�Ȥ��Τ��Ѳ�ǽ�������Ǥʤ����
|
847
|
+
�㳰��ȯ������).
|
848
|
+
���ߤΥ���ǥ�����������֤�.
|
849
|
+
|
850
|
+
Return value
|
851
|
+
* ���Τ����줫:
|
852
|
+
NetCDF::NC_ENDIAN_NATIVE (=0) (default),
|
853
|
+
NetCDF::NC_ENDIAN_LITTLE (=1), or NetCDF::NC_ENDIAN_BIG (=2).
|
854
|
+
|
760
855
|
---dim(dim_num)
|
761
856
|
�����ѿ��ˤ����� dim_num ����(0���������)�μ��������碌�롣
|
762
857
|
|
data/doc/to_html
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/bin/csh
|
2
|
-
nkf -
|
2
|
+
nkf -m Ref_man_jp.rd | rd2 --out-code=utf-8 | \
|
3
3
|
sed -e 's/<dt>/<dt><h4>/' -e 's/<\/dt>/<\/h4><\/dt>/' \
|
4
|
-
|
4
|
+
> Ref_man_jp.html
|
5
5
|
rd2 Ref_man.rd | \
|
6
6
|
sed -e 's/<dt>/<dt><h4>/' -e 's/<\/dt>/<\/h4><\/dt>/' \
|
7
|
-
|
7
|
+
> Ref_man.html
|
data/extconf.rb
CHANGED
@@ -1,14 +1,30 @@
|
|
1
|
-
require "rubygems" unless defined?(Gem)
|
2
1
|
require "mkmf"
|
2
|
+
require "rubygems" unless defined?(Gem)
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
ar = ARGV.grep( /^--with-netcdf-version=/ )
|
5
|
+
if ar.length > 0
|
6
|
+
ncversion = ar[0].sub(/^--with-netcdf-version=/,"")
|
7
|
+
else
|
8
|
+
ncversion = nil
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
if Gem.respond_to?(:find_files)
|
12
|
+
require "rbconfig"
|
13
|
+
so = RbConfig::CONFIG["DLEXT"]
|
14
|
+
narray_include = File.expand_path(File.dirname(Gem.find_files("narray.h")[0]))
|
15
|
+
narray_lib = File.expand_path(File.dirname(Gem.find_files("narray." + so)[0]))
|
16
|
+
else
|
17
|
+
gem_home=(`gem environment GEM_HOME`).chomp
|
18
|
+
narray_dir = Dir.glob("#{gem_home}/gems/narray-*").sort[-1]
|
19
|
+
if narray_dir
|
20
|
+
narray_include = narray_lib = narray_dir
|
21
|
+
else
|
22
|
+
narray_include = narray_lib = [ $sitearchdir, $vendorarchdir]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
dir_config('narray', narray_include, narray_lib)
|
26
|
+
|
27
|
+
dir_config('netcdf', '/usr/local')
|
12
28
|
|
13
29
|
if ( ! ( have_header("narray.h") && have_header("narray_config.h") ) ) then
|
14
30
|
print <<EOS
|
@@ -22,66 +38,26 @@ EOS
|
|
22
38
|
exit(-1)
|
23
39
|
end
|
24
40
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
prefix_dods = `opendap-config --prefix`.gsub(/\n/, "")
|
41
|
+
unless ncversion
|
42
|
+
# configure netcdf version
|
43
|
+
if xsystem("nc-config --version")
|
44
|
+
ncversion = `nc-config --version`.chomp!.sub!(/^n.* /i,"") # rm "netCDF "
|
45
|
+
ncversion.sub!(/^([^\.]+\.[^\.]+\.[^\.]+).+$/,'\1') # e.g. 4.2.1.1 -> 4.2.1
|
46
|
+
else
|
47
|
+
ncversion = "3.0.0" # assume version 3 (only for compilation)
|
48
|
+
# For compilation, there is no difference among subversions of netcdf 3
|
49
|
+
end
|
35
50
|
end
|
36
51
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
$LOCAL_LIBS += ' ' + libs
|
52
|
+
ncver0 = ncversion[0..0] # "3" or "4"
|
53
|
+
ncver = ncversion.gsub(/\./,'')
|
54
|
+
unless /^\d\d\d$/ =~ ncver # 3 digits
|
55
|
+
raise("Invalid netcdf version: #{ncversion}. Use --with-netcdf-version=")
|
42
56
|
end
|
43
|
-
|
44
|
-
if (enable_config('opendap',true) && ( xsystem("opendap-config --libs") ||
|
45
|
-
xsystem("ncdap-config --libs") ) )
|
46
|
-
|
47
|
-
dir_config(libncdods,prefix_dods)
|
57
|
+
$CFLAGS += ' -DNCVER='+ncver
|
48
58
|
|
49
|
-
|
50
|
-
|
51
|
-
** ERROR ** Library not found: nc-dods (OPeNDAP/DODS-enabled NetCDF lib)
|
52
|
-
Install it, or run extconf.rb with option --disable-opendap.
|
53
|
-
^^^^^^^^^^^^^^^^^
|
54
|
-
EOS
|
55
|
-
exit(-1)
|
56
|
-
else
|
57
|
-
print <<-EOS
|
58
|
-
** Message ** Compiling with OPeNDAP/DODS-enabled NetCDF library.
|
59
|
-
|
60
|
-
This is because the command opendap-config is found in your system.
|
61
|
-
If you want to use the ordinary (non-DODS) version of NetCDF,
|
62
|
-
run extconf.rb with option --disable-opendap.
|
63
|
-
^^^^^^^^^^^^^^^^^
|
64
|
-
EOS
|
65
|
-
end
|
66
|
-
|
67
|
-
$CFLAGS += ' '+cflags
|
68
|
-
$LOCAL_LIBS += ' ' + libs
|
69
|
-
|
70
|
-
# non portable treatments: should be improved (by Horinouchi)
|
71
|
-
CONFIG['LDSHARED'].sub!(/gcc/,'g++')
|
72
|
-
$LIBS.sub!(/-lc\s/,'') ; $LIBS.sub!(/-lc$/,'')
|
73
|
-
print <<-EOS
|
74
|
-
** Warning ** non-portable treatments are made,
|
75
|
-
which was sucessfull redhat linux 9:
|
76
|
-
* gcc was replaced with g++ in CONFIG['LDSHARED']
|
77
|
-
* -lc library was removed if in $LIBS
|
78
|
-
|
79
|
-
EOS
|
80
|
-
# p '@@@'
|
81
|
-
# ary = []
|
82
|
-
# CONFIG.each{|k,v| ary.push([k,v])}
|
83
|
-
# ary.sort.each{|x| p x}
|
84
|
-
else
|
59
|
+
case ncver0
|
60
|
+
when "4"
|
85
61
|
if xsystem("nc-config --libs") # for NetCDF 4
|
86
62
|
cflags = `nc-config --cflags`.gsub(/\n/, " ")
|
87
63
|
libs = `nc-config --libs`.gsub(/\n/, " ")
|
@@ -91,23 +67,82 @@ else
|
|
91
67
|
$CFLAGS += ' ' + cflags
|
92
68
|
$LOCAL_LIBS += ' ' + libs
|
93
69
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
70
|
+
when "3"
|
71
|
+
# for NetCDF 3, which needs external libraries for OpenDAP
|
72
|
+
if xsystem("ncdap-config --libs")
|
73
|
+
libncdods = "nc-dap"
|
74
|
+
cflags = `ncdap-config --cflags`.gsub(/\n/, " ")
|
75
|
+
libs = `ncdap-config --libs`.gsub(/\n/, " ")
|
76
|
+
prefix_dods = `ncdap-config --prefix`.gsub(/\n/, "")
|
77
|
+
elsif xsystem("opendap-config --libs")
|
78
|
+
libncdods = "nc-dods"
|
79
|
+
cflags = `opendap-config --cflags`.gsub(/\n/, " ")
|
80
|
+
libs = `opendap-config --libs-nc`.gsub(/\n/, " ")
|
81
|
+
prefix_dods = `opendap-config --prefix`.gsub(/\n/, "")
|
82
|
+
end
|
83
|
+
if (enable_config('opendap',true) && ( xsystem("opendap-config --libs") ||
|
84
|
+
xsystem("ncdap-config --libs") ) )
|
85
|
+
|
86
|
+
dir_config(libncdods,prefix_dods)
|
87
|
+
|
88
|
+
if (!have_library(libncdods))
|
89
|
+
print <<-EOS
|
90
|
+
** ERROR ** Library not found: nc-dods (OPeNDAP/DODS-enabled NetCDF lib)
|
91
|
+
Install it, or run extconf.rb with option --disable-opendap.
|
92
|
+
^^^^^^^^^^^^^^^^^
|
93
|
+
EOS
|
94
|
+
exit(-1)
|
95
|
+
else
|
96
|
+
print <<-EOS
|
97
|
+
** Message ** Compiling with OPeNDAP/DODS-enabled NetCDF library.
|
98
|
+
|
99
|
+
This is because the command opendap-config is found in your system.
|
100
|
+
If you want to use the ordinary (non-DODS) version of NetCDF,
|
101
|
+
run extconf.rb with option --disable-opendap.
|
102
|
+
^^^^^^^^^^^^^^^^^
|
103
|
+
EOS
|
104
|
+
end
|
105
|
+
|
106
|
+
$CFLAGS += ' '+cflags
|
107
|
+
$LOCAL_LIBS += ' ' + libs
|
101
108
|
|
102
|
-
|
109
|
+
# non portable treatments: should be improved (by Horinouchi)
|
110
|
+
CONFIG['LDSHARED'].sub!(/gcc/,'g++')
|
111
|
+
$LIBS.sub!(/-lc\s/,'') ; $LIBS.sub!(/-lc$/,'')
|
112
|
+
print <<-EOS
|
113
|
+
** Warning ** non-portable treatments are made,
|
114
|
+
which was sucessfull redhat linux 9:
|
115
|
+
* gcc was replaced with g++ in CONFIG['LDSHARED']
|
116
|
+
* -lc library was removed if in $LIBS
|
103
117
|
|
104
|
-
Alternatively, you can specify the two directory separately
|
105
|
-
with --with-netcdf-include and --with-netcdf-lib.
|
106
118
|
EOS
|
107
|
-
|
119
|
+
# p '@@@'
|
120
|
+
# ary = []
|
121
|
+
# CONFIG.each{|k,v| ary.push([k,v])}
|
122
|
+
# ary.sort.each{|x| p x}
|
123
|
+
else
|
124
|
+
if ( ! ( have_header("netcdf.h") && have_library("netcdf") ) )then
|
125
|
+
print <<-EOS
|
126
|
+
** configure error **
|
127
|
+
Header netcdf.h or the compiled netcdf library is not found.
|
128
|
+
If you have the library installed under /netcdfdir (that is, netcdf.h is
|
129
|
+
in /netcdfdir/include and the library in /netcdfdir/lib/),
|
130
|
+
try the following:
|
131
|
+
|
132
|
+
% ruby extconf.rb --with-netcdf-dir=/netcdfdir
|
133
|
+
|
134
|
+
Alternatively, you can specify the two directory separately
|
135
|
+
with --with-netcdf-include and --with-netcdf-lib.
|
136
|
+
EOS
|
137
|
+
exit(-1)
|
138
|
+
end
|
108
139
|
end
|
140
|
+
else
|
141
|
+
raise "Netcdf version #{ncver0} is not supported"
|
109
142
|
end
|
110
143
|
|
144
|
+
|
145
|
+
|
111
146
|
if /cygwin|mingw/ =~ RUBY_PLATFORM
|
112
147
|
have_library("narray") || raise("ERROR: narray library is not found")
|
113
148
|
end
|
@@ -128,9 +163,9 @@ oldmkfl.each_line{ |line|
|
|
128
163
|
newmkfl.puts("")
|
129
164
|
newmkfl.puts("test: all") # insert the "test" target
|
130
165
|
newmkfl.puts("\t\t@cd test && ruby test.rb && echo 'test did not fail :-p (please ignore the warnings)' && cd ..")
|
131
|
-
when /lib\/netcdf/
|
132
|
-
line = line.chomp! + "/"
|
133
|
-
newmkfl.puts(line)
|
166
|
+
# when /lib\/netcdf/
|
167
|
+
# line = line.chomp! + "/"
|
168
|
+
# newmkfl.puts(line)
|
134
169
|
else
|
135
170
|
newmkfl.puts(line)
|
136
171
|
end
|
data/lib/netcdf.rb
CHANGED
@@ -1,12 +1,67 @@
|
|
1
1
|
require 'narray'
|
2
2
|
require 'numru/netcdfraw'
|
3
3
|
|
4
|
-
|
4
|
+
if NArray.const_defined?(:SUPPORT_BIGMEM) && NArray::SUPPORT_BIGMEM
|
5
|
+
unless NumRu::NetCDF::SUPPORT_BIGMEM
|
6
|
+
raise "Ruby-NetCDF was compiled with NArray with big memory supoort " +
|
7
|
+
"(NArray-bigmem). However the NArray loaded is not NArray-bigmem."
|
8
|
+
end
|
9
|
+
else
|
10
|
+
if NumRu::NetCDF::SUPPORT_BIGMEM
|
11
|
+
raise "Ruby-NetCDF was compiled with NArray without big memory support. " +
|
12
|
+
"However the NArray loaded is with the support (NArray-bigmem)."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
5
16
|
module NumRu
|
6
17
|
class NetCDF
|
7
18
|
|
8
19
|
Max_Try = 100
|
9
20
|
|
21
|
+
NCVERSION = NetCDF.libvers
|
22
|
+
|
23
|
+
if NCVERSION[0..0] >= "4"
|
24
|
+
@@nc4 = true
|
25
|
+
else
|
26
|
+
@@nc4 = false
|
27
|
+
end
|
28
|
+
def NetCDF.nc4?
|
29
|
+
@@nc4
|
30
|
+
end
|
31
|
+
|
32
|
+
@@cr_format = 0
|
33
|
+
|
34
|
+
def NetCDF.creation_format=(cmode)
|
35
|
+
raise("This method is available only for NetCDF >= 4") unless @@nc4
|
36
|
+
case cmode
|
37
|
+
when 0, nil, NC_CLASSIC_MODEL, /^CLASSIC$/i # classic netcdf ver 3 fmt
|
38
|
+
@@cr_format = 0
|
39
|
+
when NC_64BIT_OFFSET, /^64BIT_OFFSET$/i
|
40
|
+
@@cr_format = NC_64BIT_OFFSET
|
41
|
+
when NC_NETCDF4, /^NETCDF4$/i
|
42
|
+
@@cr_format = NC_NETCDF4
|
43
|
+
when ( NC_NETCDF4 | NC_CLASSIC_MODEL), /^NETCDF4_CLASSIC$/i
|
44
|
+
# NetCDF4 but disabling new data models
|
45
|
+
@@cr_format = NC_NETCDF4 | NC_CLASSIC_MODEL
|
46
|
+
else
|
47
|
+
raise ArgumentError, "Unsupported creation mode: #{cmod.to_s}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def NetCDF.creation_format
|
52
|
+
raise("This method is available only for NetCDF >= 4") unless @@nc4
|
53
|
+
case @@cr_format
|
54
|
+
when 0
|
55
|
+
"TRADITIONAL"
|
56
|
+
when NC_64BIT_OFFSET
|
57
|
+
"64BIT_OFFSET"
|
58
|
+
when NC_NETCDF4
|
59
|
+
"NETCDF4"
|
60
|
+
when NC_NETCDF4 | NC_CLASSIC_MODEL
|
61
|
+
"NETCDF4_CLASSIC"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
10
65
|
def NetCDF.open(filename,mode="r",share=false)
|
11
66
|
call_create=false # false-> nc_open; true->nc_create
|
12
67
|
case(mode)
|
@@ -64,7 +119,7 @@ module NumRu
|
|
64
119
|
raise NetcdfError,"share (3rd argument) must be true or false"
|
65
120
|
end
|
66
121
|
|
67
|
-
cmode=noclobber | share
|
122
|
+
cmode=noclobber | share | @@cr_format
|
68
123
|
nc_create(filename,cmode)
|
69
124
|
end
|
70
125
|
|
@@ -218,7 +273,6 @@ module NumRu
|
|
218
273
|
|
219
274
|
end
|
220
275
|
|
221
|
-
#NetCDFVar class $B$K4X$7$F(B
|
222
276
|
class NetCDFVar
|
223
277
|
|
224
278
|
class << NetCDFVar
|
@@ -522,77 +576,39 @@ module NumRu
|
|
522
576
|
end
|
523
577
|
elsif hash.key?("start")==true
|
524
578
|
h_sta = hash["start"]
|
525
|
-
|
526
|
-
|
527
|
-
if
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
elsif
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
get_vars_float(h_sta,h_end,nil)
|
557
|
-
else
|
558
|
-
raise NetcdfError, "variable type #{t_var} isn't supported in netCDF"
|
559
|
-
end
|
560
|
-
elsif endq == false && strq == true
|
561
|
-
h_str = hash["stride"]
|
562
|
-
if t_var == "char"
|
563
|
-
get_vars_char(h_sta,nil,h_str)
|
564
|
-
elsif t_var == "byte"
|
565
|
-
get_vars_byte(h_sta,nil,h_str)
|
566
|
-
elsif t_var == "sint"
|
567
|
-
get_vars_sint(h_sta,nil,h_str)
|
568
|
-
elsif t_var == "int"
|
569
|
-
get_vars_int(h_sta,nil,h_str)
|
570
|
-
elsif t_var == "sfloat"
|
571
|
-
get_vars_sfloat(h_sta,nil,h_str)
|
572
|
-
elsif t_var == "float"
|
573
|
-
get_vars_float(h_sta,nil,h_str)
|
574
|
-
else
|
575
|
-
raise NetcdfError, "variable type #{t_var} isn't supported in netCDF"
|
576
|
-
end
|
577
|
-
else endq == true && strq == true
|
578
|
-
h_end = hash["end"]
|
579
|
-
h_str = hash["stride"]
|
580
|
-
if t_var == "char"
|
581
|
-
get_vars_char(h_sta,h_end,h_str)
|
582
|
-
elsif t_var == "byte"
|
583
|
-
get_vars_byte(h_sta,h_end,h_str)
|
584
|
-
elsif t_var == "sint"
|
585
|
-
get_vars_sint(h_sta,h_end,h_str)
|
586
|
-
elsif t_var == "int"
|
587
|
-
get_vars_int(h_sta,h_end,h_str)
|
588
|
-
elsif t_var == "sfloat"
|
589
|
-
get_vars_sfloat(h_sta,h_end,h_str)
|
590
|
-
elsif t_var == "float"
|
591
|
-
get_vars_float(h_sta,h_end,h_str)
|
592
|
-
else
|
593
|
-
raise NetcdfError, "variable type #{t_var} isn't supported in netCDF"
|
594
|
-
end
|
579
|
+
h_end = hash["end"] # can be nill
|
580
|
+
h_str = hash["stride"] # can be nill
|
581
|
+
if NetCDF.nc4? && h_str && ((xstr=h_str[0]) != 1)
|
582
|
+
# Tentative treatment for the very slow netcdf-4 reading with step.
|
583
|
+
# Reading with step is generally slow with NetCDF 4, but it is
|
584
|
+
# particularly so for the first dimension.
|
585
|
+
# Ref: http://www.unidata.ucar.edu/mailing_lists/archives/netcdfgroup/2013/msg00311.html
|
586
|
+
h_str[0] = 1
|
587
|
+
nc4remedy = true
|
588
|
+
else
|
589
|
+
nc4remedy = false
|
590
|
+
end
|
591
|
+
if t_var == "char"
|
592
|
+
v = get_vars_char(h_sta,h_end,h_str)
|
593
|
+
elsif t_var == "byte"
|
594
|
+
v = get_vars_byte(h_sta,h_end,h_str)
|
595
|
+
elsif t_var == "sint"
|
596
|
+
v = get_vars_sint(h_sta,h_end,h_str)
|
597
|
+
elsif t_var == "int"
|
598
|
+
v = get_vars_int(h_sta,h_end,h_str)
|
599
|
+
elsif t_var == "sfloat"
|
600
|
+
v = get_vars_sfloat(h_sta,h_end,h_str)
|
601
|
+
elsif t_var == "float"
|
602
|
+
v = get_vars_float(h_sta,h_end,h_str)
|
603
|
+
else
|
604
|
+
raise NetcdfError, "variable type #{t_var} isn't supported in netCDF"
|
605
|
+
end
|
606
|
+
if nc4remedy
|
607
|
+
idx = []
|
608
|
+
(0...v.shape[0]).step(xstr){|k| idx.push(k)}
|
609
|
+
v = v[idx,false]
|
595
610
|
end
|
611
|
+
v
|
596
612
|
else
|
597
613
|
raise ArgumentError,"{'start'}=>{ARRAY} or {'index'}=>{ARRAY} is needed"
|
598
614
|
end
|