Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michael Buehlmann
GenericIO
Commits
be75350b
Commit
be75350b
authored
May 04, 2018
by
Thomas Uram
Browse files
Make genericio.py Python2/3-agnostic
parent
5e1952a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
python/genericio.py
View file @
be75350b
...
...
@@ -37,9 +37,10 @@
#
# *****************************************************************************
from
__future__
import
print_function
import
numpy
as
np
import
ctypes
as
ct
import
os
import
os
,
sys
#Define where the library is and load it
_path
=
os
.
path
.
dirname
(
__file__
)
...
...
@@ -71,14 +72,17 @@ libpygio.inspect_gio.restype=None
libpygio
.
inspect_gio
.
argtypes
=
[
ct
.
c_char_p
]
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'
)
var_size
=
libpygio
.
get_elem_num
(
file_name
)
var_type
=
libpygio
.
get_variable_type
(
file_name
,
var_name
)
field_count
=
libpygio
.
get_variable_field_count
(
file_name
,
var_name
)
if
(
var_type
==
10
):
print
"Variable not found"
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 int32/int64/float/double)"
)
elif
(
var_type
==
0
):
#float
result
=
np
.
ndarray
((
var_size
,
field_count
),
dtype
=
np
.
float32
)
...
...
@@ -101,10 +105,15 @@ def gio_read(file_name,var_name):
return
result
def
gio_has_variable
(
file_name
,
var_name
):
if
sys
.
version_info
[
0
]
==
3
:
file_name
=
bytes
(
file_name
,
'ascii'
)
var_name
=
bytes
(
var_name
,
'ascii'
)
var_size
=
libpygio
.
get_elem_num
(
file_name
)
var_type
=
libpygio
.
get_variable_type
(
file_name
,
var_name
)
return
var_type
!=
10
def
gio_inspect
(
file_name
):
if
sys
.
version_info
[
0
]
==
3
:
file_name
=
bytes
(
file_name
,
'ascii'
)
libpygio
.
inspect_gio
(
file_name
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment