Skip to content
Snippets Groups Projects
Commit 411385fc authored by Peters, Wouter's avatar Peters, Wouter
Browse files

inquiring the unlimited length is made possible by adding a variable with the same name

parent 80962d6b
Branches
No related tags found
No related merge requests found
......@@ -192,16 +192,17 @@ class CT_CDF(object):
return var
def inquire_unlimited(self):
""" Get the index of the unlimited dimension"""
""" Get the index and name of the unlimited dimension"""
try:
index = self.file.dimensions.values().index(None)
unlimname = self.file.dimensions.keys()[index]
unlimlen = ncf.file.variables[unlimname].shape[0]
unlimlen = self.file.variables[unlimname].shape[0]
except:
unlimlen = -1
unlimname = 'None'
return unlimlen
return (unlimname,unlimlen,)
def AddData(self,datadict,silent=True):
"""
......@@ -225,7 +226,7 @@ class CT_CDF(object):
we don't want the unlimited counter to increase everytime. To get the value of the counter (needed when appending data for instance)
use
unlim_count = ncf.inquire_unlimited()
unlimname,unlim_count = ncf.inquire_unlimited()
where an integer value is returned for the length, and -1 indicates there is no unlimited dimension
......@@ -296,18 +297,12 @@ class CT_CDF(object):
# Now that the variable instance is returned, start to add the data. First figure out if we are dealing with an unlimited dimension
dimlens = self.file.dimensions.values()
dimnames = self.file.dimensions.keys()
try:
index = self.file.dimensions.values().index(None)
except:
index = -1
has_unlimited_dim = (index > 0)
unlimname,unlimlen = self.inquire_unlimited()
has_unlimited_dim = (unlimname != 'None')
# If so, check if the first dimension of the passed dataset corresponds to the unlimited dimension
if has_unlimited_dim and var.dimensions[0] == dimnames[index]:
if has_unlimited_dim and var.dimensions[0] == unlimname:
# Add the data to the unlimited dim, note the special occassion for passing only one value (a record)
......@@ -361,7 +356,7 @@ if __name__ == '__main__':
#dimlag=ncf.AddLagDim(unlimited=True)
#dimidate=ncf.AddDateDimFormat()
unlimlen = ncf.inquire_unlimited()
unlimname,unlimlen = ncf.inquire_unlimited()
if unlimlen < 0: unlimlen=0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment