[DRE-commits] [ruby-grib] 01/04: New upstream version 0.4.0

Youhei SASAKI uwabami-guest at moszumanska.debian.org
Mon Nov 7 08:23:02 UTC 2016


This is an automated email from the git hooks/post-receive script.

uwabami-guest pushed a commit to branch master
in repository ruby-grib.

commit ec4c452ea619efc71299e7a5ae2e4a52dad1c78a
Author: Youhei SASAKI <uwabami at gfd-dennou.org>
Date:   Mon Nov 7 16:17:46 2016 +0900

    New upstream version 0.4.0
---
 .gitignore                |  8 --------
 ext/extconf.rb            | 52 +++++++++++++++++++++++++++++++++++++++--------
 ext/grib.c                | 24 ++++++++++++++--------
 lib/numru/grib.rb         | 18 ++++++++++++++++
 lib/numru/grib/version.rb |  2 +-
 5 files changed, 78 insertions(+), 26 deletions(-)

diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index bf266aa..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-*.gem
-.bundle
-Gemfile.lock
-pkg/*
-ext/Makefile
-ext/mkmf.log
-ext/*.o
-ext/*.so
diff --git a/ext/extconf.rb b/ext/extconf.rb
index e8d9ee2..7609e5e 100644
--- a/ext/extconf.rb
+++ b/ext/extconf.rb
@@ -1,23 +1,57 @@
 require "mkmf"
 
+na_path = RbConfig::CONFIG["sitearchdir"]
 begin
   require "rubygems"
+  gem = true
+rescue LoadError
+  gem = false
+end
+if gem
+  if ( na_type = ENV["NARRAY_TYPE"] )
+    nas = [na_type]
+  else
+    nas = %w(narray numru-narray)
+  end
   if Gem::Specification.respond_to?(:find_by_name)
-    if spec = ( Gem::Specification.find_by_name("numru-narray") || Gem::Specification.find_by_name("narray") )
-      gem_path = spec.full_gem_path
+    nas.each do |na|
+      begin
+        if ( spec = Gem::Specification.find_by_name(na) )
+          na_type = na
+          na_path = spec.full_gem_path
+          case na_type
+          when "narray"
+            na_path = File.join(na_path, "src")
+          when "numru-narray"
+            na_path = File.join(na_path, "ext", "numru", "narray")
+          end
+          break
+        end
+      rescue LoadError
+      end
     end
   else
-    if (spec = (Gem.source_index.find_name("numru-narray") || Gem.source_index.find_name("narray")) ).any?
-      gem_path = spec.full_gem_path
+    nas.each do |na|
+      if ( spec = Gem.source_index.find_name(na) ).any?
+        na_type = na
+        na_path = spec[0].full_gem_path
+        case na_type
+        when "narray"
+          na_path = File.join(na_path, "src")
+        when "numru-narray"
+          na_path = File.join(na_path, "ext", "numru", "narray")
+        end
+        break
+      end
     end
   end
-  gem_path = File.join(gem_path, "ext", "numru", "narray")
-rescue LoadError
-  dir_config("narray", RbConfig::CONFIG["sitearchdir"])
 end
 
-unless find_header("narray.h", gem_path)
-  find_header("narray.h", File.join(gem_path,"src"))
+dir_config("narray", na_path, na_path)
+unless have_header("narray.h")
+  $stderr.print "narray.h does not found. Specify the path.\n"
+  $stderr.print "e.g., gem install rb-grib -- --with-narray-include=path\n"
+  exit(-1)
 end
 
 dir_config("grib_api")
diff --git a/ext/grib.c b/ext/grib.c
index 50d5fe9..574a7dd 100644
--- a/ext/grib.c
+++ b/ext/grib.c
@@ -10,11 +10,13 @@ typedef int na_shape_t;
 
 #define MAX_VALUE_LENGTH 1024
 
+#define CHECK_ERROR(func) raise_error(func, #func)
+
 // error check
 static void
-check_error(int code)
+raise_error(int code, const char* func)
 {
-  if (code) rb_raise(rb_eRuntimeError, "%s", grib_get_error_message(code));
+  if (code) rb_raise(rb_eRuntimeError, "grib-api function failed:\n  function: %s\n  message: %s", func, grib_get_error_message(code));
 };
 
 
@@ -245,7 +247,7 @@ push_msg_var(var_list **pvar, grib_handle *handle, VALUE file)
 
   len = MAX_VALUE_LENGTH;
   bzero(vname, len);
-  check_error(grib_get_string(handle, "typeOfLevel", vname, &len));
+  CHECK_ERROR(grib_get_string(handle, "typeOfLevel", vname, &len));
   if (strcmp(vname, "unknown")==0 || strcmp(vname,"isobaricInhPa")== 0 || strcmp(vname,"pl")==0)
     strcpy(var_new->ltype, vname);
   else {
@@ -405,7 +407,7 @@ rg_file_initialize(int argc, VALUE *argv, VALUE self)
   grib_handle *handle;
   var_list *var = NULL;
   while ((handle = grib_handle_new_from_file(0, file, &error))) {
-    check_error(error);
+    raise_error(error, "grib_handle_new_from_file(0, file, &error)");
     if (handle == NULL)
       rb_raise(rb_eRuntimeError, "unable to create handle in %s", fname);
     push_msg_var(&var, handle, self);
@@ -673,14 +675,14 @@ rg_message_get_value(int argc, VALUE *argv, VALUE self)
 	  len = MAX_VALUE_LENGTH;
 	  bzero(value, len);
 	  if (grib_get_string(message->handle, name, value, &len) == GRIB_SUCCESS) {
-	    check_error(grib_get_long(message->handle, name, &l));
+	    CHECK_ERROR(grib_get_long(message->handle, name, &l));
 	    if (atol(value) == l)
 	      ret = LONG2NUM(l);
 	    else
 	      ret = rb_str_new2(value);
 	  }
 	} else {
-	  check_error(grib_get_long(message->handle, name, &l));
+	  CHECK_ERROR(grib_get_long(message->handle, name, &l));
 	  ret = LONG2NUM(l);
 	}	  
       } else {
@@ -727,9 +729,9 @@ rg_message_get_data(VALUE self)
   Data_Get_Struct(self, rg_message, message);
   int error;
   grib_iterator *iter = grib_iterator_new(message->handle, 0, &error);
-  check_error(error);
+  raise_error(error, "grib_iterator_new(message->handle, 0, &error);");
   long np;
-  check_error(grib_get_long(message->handle, "numberOfPoints", &np));
+  CHECK_ERROR(grib_get_long(message->handle, "numberOfPoints", &np));
   double *lon, *lat, *value;
   VALUE na_lon, na_lat, na_value;
   struct NARRAY *nary;
@@ -808,4 +810,10 @@ void Init_grib()
 
   rb_define_const(cGrib, "KEYS_ITERATOR_ALL_KEYS", ULONG2NUM(GRIB_KEYS_ITERATOR_ALL_KEYS));
   rb_define_const(cGrib, "KEYS_ITERATOR_SKIP_READ_ONLY", ULONG2NUM(GRIB_KEYS_ITERATOR_SKIP_READ_ONLY));
+
+#ifdef NARRAY_BIGMEM
+  rb_define_const(cGrib, "SUPPORT_BIGMEM", Qtrue);
+#else
+  rb_define_const(cGrib, "SUPPORT_BIGMEM", Qfalse);
+#endif
 }
diff --git a/lib/numru/grib.rb b/lib/numru/grib.rb
index f1279e1..b26b864 100644
--- a/lib/numru/grib.rb
+++ b/lib/numru/grib.rb
@@ -4,3 +4,21 @@ require "numru/grib/setenv.rb"
 require "numru/grib/version.rb"
 require "numru/grib.so"
 require "numru/grib/grib.rb"
+
+if defined?(NumRu::NArray)
+  unless NumRu::Grib::SUPPORT_BIGMEM
+    $stderr.print <<EOM
+rb-grib was compiled with NArray but NumRu::NArray is used.
+Check and use consistent narray!
+EOM
+    raise LoadError, "failed to load rb-grib"
+  end
+else
+  if NumRu::Grib::SUPPORT_BIGMEM
+    $stderr.print <<EOM
+rb-grib was compiled with NumRu::NArray but NArray is used.
+Check and use consistent narray!
+EOM
+    raise LoadError, "failed to load rb-grib"
+  end
+end
diff --git a/lib/numru/grib/version.rb b/lib/numru/grib/version.rb
index a877c59..729bed3 100644
--- a/lib/numru/grib/version.rb
+++ b/lib/numru/grib/version.rb
@@ -1,5 +1,5 @@
 module NumRu
   class Grib
-    VERSION = "0.3.0"
+    VERSION = "0.4.0"
   end
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-grib.git



More information about the Pkg-ruby-extras-commits mailing list