Commit c8c291b2 authored by Thomas Uram's avatar Thomas Uram
Browse files

Allow read of multiple variables with one call

parent dd569452
......@@ -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')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment