PYTHON: Rewrite amun_compatible().
Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org>
This commit is contained in:
parent
ec6ea2cbf7
commit
325208559e
@ -37,6 +37,7 @@ import numpy as np
|
||||
import os.path as op
|
||||
import sys
|
||||
|
||||
|
||||
def amun_compatible(fname):
|
||||
'''
|
||||
Subroutine checks if the HDF5 file is AMUN compatible.
|
||||
@ -47,39 +48,28 @@ def amun_compatible(fname):
|
||||
|
||||
Return values:
|
||||
|
||||
ret - True or False;
|
||||
True or False;
|
||||
|
||||
Examples:
|
||||
|
||||
comp = amun_compatible('p000010_00000.h5')
|
||||
|
||||
'''
|
||||
try:
|
||||
f = h5.File(fname, 'r')
|
||||
|
||||
# check if the file is written in the AMUN format or at least contains
|
||||
# necessary groups
|
||||
#
|
||||
ret = True
|
||||
if 'code' in f.attrs:
|
||||
if f.attrs['code'].astype(str) != "AMUN":
|
||||
print("'%s' contains attribute 'code'", \
|
||||
" but it is not set to 'AMUN'!" % fname)
|
||||
ret = False
|
||||
elif not 'attributes' in f or \
|
||||
not 'coordinates' in f or \
|
||||
not 'variables' in f:
|
||||
print("'%s' misses one of these groups: ", \
|
||||
"'attributes', 'coordinates' or 'variables'!" % fname)
|
||||
ret = False
|
||||
|
||||
f.close()
|
||||
|
||||
except:
|
||||
print("It seems '%s' is not an HDF5 file!" % fname)
|
||||
ret = False
|
||||
|
||||
return ret
|
||||
with h5.File(fname, 'r') as f:
|
||||
if 'codes' in f.attrs:
|
||||
if f.attrs['code'].astype(str) == "AMUN":
|
||||
return True
|
||||
else:
|
||||
print("'%s' contains attribute 'code'," % fname, \
|
||||
" but it is not 'AMUN'!")
|
||||
return False
|
||||
elif 'attributes' in f and 'coordinates' in f and \
|
||||
'variables' in f:
|
||||
return True
|
||||
else:
|
||||
print("'%s' misses one of these groups:" % fname, \
|
||||
"'attributes', 'coordinates' or 'variables'!")
|
||||
return False
|
||||
|
||||
|
||||
def amun_attribute(fname, aname):
|
||||
|
Loading…
x
Reference in New Issue
Block a user