rb-grib 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8f3d0dfbd8bcdf02783485139224e0e0c151071
4
- data.tar.gz: 6fc49fc43aa1af1fd981803253b40281d2850350
3
+ metadata.gz: 4d18ea1987ea7a51327997b6217d551a007fbf70
4
+ data.tar.gz: 1c1e66d6f85bd72655c31a29d39bbf51240783e3
5
5
  SHA512:
6
- metadata.gz: 5c1a614dd1264329f35793a828cb074d7f5e4603ee21ee22ef5014a73a695b14871e4e3fb750693a5014820b380a31dd4603316fdebcd0d46c350bddd1773092
7
- data.tar.gz: c1d07b21d120b59563f2bce553676a8448d4179de0b90f7c8a5cdf3db59f9efd7613140978ccd64d062469a969f04b31fa4d1c707f4237b2cc92df85c7e8e111
6
+ metadata.gz: 87952a90b57f7d670d03515e6422df16a742d9467ff05dab50fff6206fba3492ca7b568437338576ade22f9c1d2e6bc387c63bc7ecb5598a8c849d82c5b27b01
7
+ data.tar.gz: a9c17bbc6050b4c0e66cadb2748dd742e08eff5ab86c69de8a1ca38dc1dda011711100038a07301d8cdeb811929eb14b9af7beb112a5afb81309a8b0a605b3e0
@@ -1,23 +1,57 @@
1
1
  require "mkmf"
2
2
 
3
+ na_path = RbConfig::CONFIG["sitearchdir"]
3
4
  begin
4
5
  require "rubygems"
6
+ gem = true
7
+ rescue LoadError
8
+ gem = false
9
+ end
10
+ if gem
11
+ if ( na_type = ENV["NARRAY_TYPE"] )
12
+ nas = [na_type]
13
+ else
14
+ nas = %w(narray numru-narray)
15
+ end
5
16
  if Gem::Specification.respond_to?(:find_by_name)
6
- if spec = ( Gem::Specification.find_by_name("numru-narray") || Gem::Specification.find_by_name("narray") )
7
- gem_path = spec.full_gem_path
17
+ nas.each do |na|
18
+ begin
19
+ if ( spec = Gem::Specification.find_by_name(na) )
20
+ na_type = na
21
+ na_path = spec.full_gem_path
22
+ case na_type
23
+ when "narray"
24
+ na_path = File.join(na_path, "src")
25
+ when "numru-narray"
26
+ na_path = File.join(na_path, "ext", "numru", "narray")
27
+ end
28
+ break
29
+ end
30
+ rescue LoadError
31
+ end
8
32
  end
9
33
  else
10
- if (spec = (Gem.source_index.find_name("numru-narray") || Gem.source_index.find_name("narray")) ).any?
11
- gem_path = spec.full_gem_path
34
+ nas.each do |na|
35
+ if ( spec = Gem.source_index.find_name(na) ).any?
36
+ na_type = na
37
+ na_path = spec[0].full_gem_path
38
+ case na_type
39
+ when "narray"
40
+ na_path = File.join(na_path, "src")
41
+ when "numru-narray"
42
+ na_path = File.join(na_path, "ext", "numru", "narray")
43
+ end
44
+ break
45
+ end
12
46
  end
13
47
  end
14
- gem_path = File.join(gem_path, "ext", "numru", "narray")
15
- rescue LoadError
16
- dir_config("narray", RbConfig::CONFIG["sitearchdir"])
17
48
  end
18
49
 
19
- unless find_header("narray.h", gem_path)
20
- find_header("narray.h", File.join(gem_path,"src"))
50
+ dir_config("narray", na_path, na_path)
51
+ unless have_header("narray.h")
52
+ $stderr.print "narray.h does not found. Specify the path.\n"
53
+ $stderr.print "e.g., gem install rb-grib -- --with-narray-include=path\n"
54
+ exit(-1)
21
55
  end
22
56
 
23
57
  dir_config("grib_api")
data/ext/grib.c CHANGED
@@ -10,11 +10,13 @@ typedef int na_shape_t;
10
10
 
11
11
  #define MAX_VALUE_LENGTH 1024
12
12
 
13
+ #define CHECK_ERROR(func) raise_error(func, #func)
14
+
13
15
  // error check
14
16
  static void
15
- check_error(int code)
17
+ raise_error(int code, const char* func)
16
18
  {
17
- if (code) rb_raise(rb_eRuntimeError, "%s", grib_get_error_message(code));
19
+ if (code) rb_raise(rb_eRuntimeError, "grib-api function failed:\n function: %s\n message: %s", func, grib_get_error_message(code));
18
20
  };
19
21
 
20
22
 
@@ -245,7 +247,7 @@ push_msg_var(var_list **pvar, grib_handle *handle, VALUE file)
245
247
 
246
248
  len = MAX_VALUE_LENGTH;
247
249
  bzero(vname, len);
248
- check_error(grib_get_string(handle, "typeOfLevel", vname, &len));
250
+ CHECK_ERROR(grib_get_string(handle, "typeOfLevel", vname, &len));
249
251
  if (strcmp(vname, "unknown")==0 || strcmp(vname,"isobaricInhPa")== 0 || strcmp(vname,"pl")==0)
250
252
  strcpy(var_new->ltype, vname);
251
253
  else {
@@ -405,7 +407,7 @@ rg_file_initialize(int argc, VALUE *argv, VALUE self)
405
407
  grib_handle *handle;
406
408
  var_list *var = NULL;
407
409
  while ((handle = grib_handle_new_from_file(0, file, &error))) {
408
- check_error(error);
410
+ raise_error(error, "grib_handle_new_from_file(0, file, &error)");
409
411
  if (handle == NULL)
410
412
  rb_raise(rb_eRuntimeError, "unable to create handle in %s", fname);
411
413
  push_msg_var(&var, handle, self);
@@ -673,14 +675,14 @@ rg_message_get_value(int argc, VALUE *argv, VALUE self)
673
675
  len = MAX_VALUE_LENGTH;
674
676
  bzero(value, len);
675
677
  if (grib_get_string(message->handle, name, value, &len) == GRIB_SUCCESS) {
676
- check_error(grib_get_long(message->handle, name, &l));
678
+ CHECK_ERROR(grib_get_long(message->handle, name, &l));
677
679
  if (atol(value) == l)
678
680
  ret = LONG2NUM(l);
679
681
  else
680
682
  ret = rb_str_new2(value);
681
683
  }
682
684
  } else {
683
- check_error(grib_get_long(message->handle, name, &l));
685
+ CHECK_ERROR(grib_get_long(message->handle, name, &l));
684
686
  ret = LONG2NUM(l);
685
687
  }
686
688
  } else {
@@ -727,9 +729,9 @@ rg_message_get_data(VALUE self)
727
729
  Data_Get_Struct(self, rg_message, message);
728
730
  int error;
729
731
  grib_iterator *iter = grib_iterator_new(message->handle, 0, &error);
730
- check_error(error);
732
+ raise_error(error, "grib_iterator_new(message->handle, 0, &error);");
731
733
  long np;
732
- check_error(grib_get_long(message->handle, "numberOfPoints", &np));
734
+ CHECK_ERROR(grib_get_long(message->handle, "numberOfPoints", &np));
733
735
  double *lon, *lat, *value;
734
736
  VALUE na_lon, na_lat, na_value;
735
737
  struct NARRAY *nary;
@@ -808,4 +810,10 @@ void Init_grib()
808
810
 
809
811
  rb_define_const(cGrib, "KEYS_ITERATOR_ALL_KEYS", ULONG2NUM(GRIB_KEYS_ITERATOR_ALL_KEYS));
810
812
  rb_define_const(cGrib, "KEYS_ITERATOR_SKIP_READ_ONLY", ULONG2NUM(GRIB_KEYS_ITERATOR_SKIP_READ_ONLY));
813
+
814
+ #ifdef NARRAY_BIGMEM
815
+ rb_define_const(cGrib, "SUPPORT_BIGMEM", Qtrue);
816
+ #else
817
+ rb_define_const(cGrib, "SUPPORT_BIGMEM", Qfalse);
818
+ #endif
811
819
  }
@@ -4,3 +4,21 @@ require "numru/grib/setenv.rb"
4
4
  require "numru/grib/version.rb"
5
5
  require "numru/grib.so"
6
6
  require "numru/grib/grib.rb"
7
+
8
+ if defined?(NumRu::NArray)
9
+ unless NumRu::Grib::SUPPORT_BIGMEM
10
+ $stderr.print <<EOM
11
+ rb-grib was compiled with NArray but NumRu::NArray is used.
12
+ Check and use consistent narray!
13
+ EOM
14
+ raise LoadError, "failed to load rb-grib"
15
+ end
16
+ else
17
+ if NumRu::Grib::SUPPORT_BIGMEM
18
+ $stderr.print <<EOM
19
+ rb-grib was compiled with NumRu::NArray but NArray is used.
20
+ Check and use consistent narray!
21
+ EOM
22
+ raise LoadError, "failed to load rb-grib"
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  module NumRu
2
2
  class Grib
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-grib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiya Nishizawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-22 00:00:00.000000000 Z
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec