source: issm/oecreview/Archive/24684-25833/ISSM-25531-25532.diff

Last change on this file was 25834, checked in by Mathieu Morlighem, 4 years ago

CHG: added 24684-25833

File size: 3.3 KB
RevLine 
[25834]1Index: ../trunk-jpl/src/m/io/loadvars.py
2===================================================================
3--- ../trunk-jpl/src/m/io/loadvars.py (revision 25531)
4+++ ../trunk-jpl/src/m/io/loadvars.py (revision 25532)
5@@ -29,7 +29,7 @@
6
7 filename = ''
8 nvdict = {}
9- debug = False #print messages if true
10+ debug = True #print messages if true
11
12 if len(args) >= 1 and isinstance(args[0], str):
13 filename = args[0]
14@@ -51,7 +51,7 @@
15 else:
16 raise TypeError("Unrecognized input arguments.")
17
18- onlylast = False
19+ onlylast = True
20
21 for key, value in kwargs.items():
22 if key == 'onlylast':
23@@ -132,7 +132,32 @@
24 else:
25 nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)() for i in range(max(1, len(NCFile.dimensions['Time'])))]
26 Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
27-
28+ elif classtype[mod][0] == 'list': #Treating the old style of results
29+ keylist = [key for key in curclass.groups]
30+ # this is related to the old structure of NC files where every steps of results had its own group
31+ if len(keylist) > 0:
32+ #this is kept for compatibility
33+ #and treatment of list of dicts??
34+ try:
35+ #group are named after their step
36+ steplist = [int(key) for key in curclass.groups]
37+ except ValueError:
38+ #or a number is appended at the end of the name
39+ steplist = [int(findall(r'\d + ', key)[0]) for key in keylist]
40+ indexlist = [int(index * (len(curclass.groups) - 1) / max(1, max(steplist))) for index in steplist]
41+ listtype = curclass.groups[keylist[0]].classtype
42+ #discriminate between dict and results
43+ if listtype == 'dict':
44+ nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [OrderedDict() for i in range(max(1, len(curclass.groups)))]
45+ else:
46+ if onlylast: #we load only the last result to save on time and memory
47+ nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)()]
48+ Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]]
49+ else:
50+ nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)() for i in range(max(1, len(curclass.groups)))]
51+ Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
52+ else:
53+ print("WARNING: we don't get the expected format, there might be an issue somewhere")
54 elif classtype[mod][0] == 'massfluxatgate': #this is for output definitions
55 defname = split('Output|[0-9]+', classtree[mod][1])[1] + 's'
56 defindex = int(findall('[0-9]+', classtree[mod][1])[0])
Note: See TracBrowser for help on using the repository browser.