diff --git a/python/genericio.py b/python/genericio.py index afbe437fc9f8f14122a6ca99dfaa02e9bbfa511f..8e7f7bbcc7378a3506d0a605640f4ad678ab13e5 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 26ea8e36999c1df7761b895c0523469fa870c35f..4d826bf3fe8e46230b5ebe86117dc732c563aa7f 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 2a150ce3f0934d0f0f80c255b4cbfa9d3ef58816..b179f708808445fd4fca01f289011676d64b5273 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 };