From c8c291b2f7e96d7138e99251a8aff59a4b07217c Mon Sep 17 00:00:00 2001
From: Thomas Uram <turam@mcs.anl.gov>
Date: Fri, 11 Jan 2019 20:01:29 -0600
Subject: [PATCH] Allow read of multiple variables with one call

---
 python/genericio.py | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/python/genericio.py b/python/genericio.py
index 8e7f7bb..3284739 100644
--- a/python/genericio.py
+++ b/python/genericio.py
@@ -74,7 +74,7 @@ libpygio.read_gio_double.argtypes=[ct.c_char_p,ct.c_char_p,ct.POINTER(ct.c_doubl
 libpygio.inspect_gio.restype=None
 libpygio.inspect_gio.argtypes=[ct.c_char_p]
 
-def gio_read(file_name,var_name):
+def gio_read_(file_name,var_name):
     if sys.version_info[0] == 3:
         file_name = bytes(file_name,'ascii')
         var_name = bytes(var_name,'ascii')
@@ -88,22 +88,22 @@ def gio_read(file_name,var_name):
         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)
+        result = np.ndarray((var_size),dtype=np.float32)
         libpygio.read_gio_float(file_name,var_name,result.ctypes.data_as(ct.POINTER(ct.c_float)),field_count)
         return result
     elif(var_type==1):
         #double
-        result = np.ndarray((var_size,field_count),dtype=np.float64)
+        result = np.ndarray((var_size),dtype=np.float64)
         libpygio.read_gio_double(file_name,var_name,result.ctypes.data_as(ct.POINTER(ct.c_double)),field_count)
         return result
     elif(var_type==2):
         #int32
-        result = np.ndarray((var_size,field_count),dtype=np.int32)
+        result = np.ndarray((var_size),dtype=np.int32)
         libpygio.read_gio_int32(file_name,var_name,result.ctypes.data_as(ct.POINTER(ct.c_int32)),field_count)
         return result
     elif(var_type==3):
         #int64
-        result = np.ndarray((var_size,field_count),dtype=np.int64)
+        result = np.ndarray((var_size),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):
@@ -112,6 +112,14 @@ def gio_read(file_name,var_name):
         libpygio.read_gio_uint16(file_name,var_name,result.ctypes.data_as(ct.POINTER(ct.c_uint16)),field_count)
         return result
 
+def gio_read(file_name,var_names):
+    ret = []
+    if not isinstance(var_names,list):
+        var_names = [ var_names ]
+    for var_name in var_names:
+        ret.append( gio_read_(file_name,var_name) )
+    return np.array( ret )
+
 def gio_has_variable(file_name,var_name):
     if sys.version_info[0] == 3:
         file_name=bytes(file_name,'ascii')
-- 
GitLab