From dd5694520387f29badcdcadad3464175fd982107 Mon Sep 17 00:00:00 2001
From: Hal Finkel <hfinkel@anl.gov>
Date: Tue, 30 Oct 2018 14:31:57 -0500
Subject: [PATCH] import uint16 fix by Biwer, Christopher Michael
 <cmbiwer@lanl.gov>

---
 python/genericio.py | 10 +++++++++-
 python/lib/gio.cxx  |  5 +++++
 python/lib/gio.h    |  2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/python/genericio.py b/python/genericio.py
index afbe437..8e7f7bb 100644
--- a/python/genericio.py
+++ b/python/genericio.py
@@ -56,6 +56,9 @@ libpygio.get_variable_type.argtypes=[ct.c_char_p,ct.c_char_p]
 libpygio.get_variable_field_count.restype=ct.c_int
 libpygio.get_variable_field_count.argtypes=[ct.c_char_p,ct.c_char_p]
 
+libpygio.read_gio_uint16.restype=None
+libpygio.read_gio_uint16.argtypes=[ct.c_char_p,ct.c_char_p,ct.POINTER(ct.c_uint16),ct.c_int]
+
 libpygio.read_gio_int32.restype=None
 libpygio.read_gio_int32.argtypes=[ct.c_char_p,ct.c_char_p,ct.POINTER(ct.c_int),ct.c_int]
 
@@ -82,7 +85,7 @@ def gio_read(file_name,var_name):
         print("Variable not found")
         return
     elif(var_type==9):
-        print("variable type not known (not int32/int64/float/double)")
+        print("variable type not known (not uint16/int32/int64/float/double)")
     elif(var_type==0):
         #float
         result = np.ndarray((var_size,field_count),dtype=np.float32)
@@ -103,6 +106,11 @@ def gio_read(file_name,var_name):
         result = np.ndarray((var_size,field_count),dtype=np.int64)
         libpygio.read_gio_int64(file_name,var_name,result.ctypes.data_as(ct.POINTER(ct.c_int64)),field_count)
         return result        
+    elif(var_type==4):
+        #uint16
+        result = np.ndarray((var_size,field_count),dtype=np.uint16)
+        libpygio.read_gio_uint16(file_name,var_name,result.ctypes.data_as(ct.POINTER(ct.c_uint16)),field_count)
+        return result
 
 def gio_has_variable(file_name,var_name):
     if sys.version_info[0] == 3:
diff --git a/python/lib/gio.cxx b/python/lib/gio.cxx
index 26ea8e3..4d826bf 100644
--- a/python/lib/gio.cxx
+++ b/python/lib/gio.cxx
@@ -48,6 +48,9 @@
   void read_gio_double(char* file_name, char* var_name, double* data, int field_count){
     read_gio<double>(file_name,var_name,data,field_count);
   }
+  void read_gio_uint16(char* file_name, char* var_name, uint16_t* data, int field_count){
+    read_gio<uint16_t>(file_name,var_name,data,field_count);
+  }
   void read_gio_int32(char* file_name, char* var_name, int* data, int field_count){
     read_gio<int>(file_name,var_name,data,field_count);
   }
@@ -80,6 +83,8 @@
 	  return float_type;
 	else if(vinfo.IsFloat && vinfo.ElementSize == 8)
 	  return double_type;
+        else if(!vinfo.IsFloat && vinfo.ElementSize == 2)
+          return uint16_type;
 	else if(!vinfo.IsFloat && vinfo.ElementSize == 4)
 	  return int32_type;
 	else if(!vinfo.IsFloat && vinfo.ElementSize == 8)
diff --git a/python/lib/gio.h b/python/lib/gio.h
index 2a150ce..b179f70 100644
--- a/python/lib/gio.h
+++ b/python/lib/gio.h
@@ -72,6 +72,7 @@ extern "C" int64_t get_elem_num(char* file_name);
 
 extern "C" void read_gio_float (char* file_name, char* var_name, float* data, int field_count);
 extern "C" void read_gio_double(char* file_name, char* var_name, double* data, int field_count);
+extern "C" void read_gio_uint16 (char* file_name, char* var_name, uint16_t* data, int field_count); 
 extern "C" void read_gio_int32 (char* file_name, char* var_name, int* data, int field_count); 
 extern "C" void read_gio_int64 (char* file_name, char* var_name, int64_t* data, int field_count);
 enum var_type{
@@ -79,6 +80,7 @@ enum var_type{
   double_type=1,
   int32_type=2,
   int64_type=3,
+  uint16_type=4,
   type_not_found=9,
   var_not_found=10
 };
-- 
GitLab