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
  • ../trunk-jpl/src/m/io/loadvars.py

     
    2929
    3030    filename = ''
    3131    nvdict = {}
    32     debug = False  #print messages if true
     32    debug = True  #print messages if true
    3333
    3434    if len(args) >= 1 and isinstance(args[0], str):
    3535        filename = args[0]
     
    5151    else:
    5252        raise TypeError("Unrecognized input arguments.")
    5353
    54     onlylast = False
     54    onlylast = True
    5555
    5656    for key, value in kwargs.items():
    5757        if key == 'onlylast':
     
    132132                            else:
    133133                                nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)() for i in range(max(1, len(NCFile.dimensions['Time'])))]
    134134                                Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
    135 
     135                elif classtype[mod][0] == 'list':  #Treating the old style of results
     136                    keylist = [key for key in curclass.groups]
     137                    # this is related to the old structure of NC files where every steps of results had its own group
     138                    if len(keylist) > 0:
     139                        #this is kept for compatibility
     140                        #and treatment of list of dicts??
     141                        try:
     142                            #group are named after their step
     143                            steplist = [int(key) for key in curclass.groups]
     144                        except ValueError:
     145                            #or a number is appended at the end of the name
     146                            steplist = [int(findall(r'\d + ', key)[0]) for key in keylist]
     147                        indexlist = [int(index * (len(curclass.groups) - 1) / max(1, max(steplist))) for index in steplist]
     148                        listtype = curclass.groups[keylist[0]].classtype
     149                        #discriminate between dict and results
     150                        if listtype == 'dict':
     151                            nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [OrderedDict() for i in range(max(1, len(curclass.groups)))]
     152                        else:
     153                            if onlylast:   #we load only the last result to save on time and memory
     154                                nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)()]
     155                                Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]]
     156                            else:
     157                                nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype), listtype)() for i in range(max(1, len(curclass.groups)))]
     158                                Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
     159                    else:
     160                        print("WARNING: we don't get the expected format, there might be an issue somewhere")
    136161                elif classtype[mod][0] == 'massfluxatgate':  #this is for output definitions
    137162                    defname = split('Output|[0-9]+', classtree[mod][1])[1] + 's'
    138163                    defindex = int(findall('[0-9]+', classtree[mod][1])[0])
Note: See TracBrowser for help on using the repository browser.