Index: /issm/trunk-jpl/src/m/io/loadvars.py
===================================================================
--- /issm/trunk-jpl/src/m/io/loadvars.py	(revision 26126)
+++ /issm/trunk-jpl/src/m/io/loadvars.py	(revision 26127)
@@ -98,5 +98,4 @@
                 if classtype[mod][0] == 'results.solutionstep':  #Treating results {{{
                     keylist = [key for key in curclass.groups]
-                    # this is related to the old structure of NC files where every steps of results had its own group
                     #that is the current treatment
                     #here we have a more NC approach with time being a dimension
@@ -111,6 +110,4 @@
                             Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]]
                         else:
-                            #nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(classtype[mod][1], listtype)() for i in range(max(1, len(NCFile.dimensions['Time'])))]
-                            #Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
                             setattr(nvdict['md'].__dict__[classtree[mod][0]], classtree[mod][1], getattr(classtype[mod][1], 'solution')([]))
                             for i in range(max(1, len(NCFile.dimensions['Time']))):
@@ -118,4 +115,26 @@
                             Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
                 # }}}
+                elif "results" in mod and classtype[mod][0] == 'list':  #this is the old style of results where every step has a group{{{
+                    keylist = [key for key in curclass.groups]
+                    #one group per step so use that in place of time
+                    stepnum = len(NCFile.groups[classtree[mod][0]].groups[classtree[mod][1]].groups)
+                    #we need to redefine classtype from list to result
+                    listtype = 'results'
+                    classtype[mod].append(__import__(listtype))
+                    if stepnum == 1:
+                        nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = getattr(classtype[mod][1], listtype)()
+                        Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]]
+                    else:
+                        if onlylast:   #we load only the last result to save on time and memory
+                            nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(classtype[mod][1], listtype)()]
+                            Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]]
+                        else:
+                            #nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(classtype[mod][1], listtype)() for i in range(max(1, len(NCFile.dimensions['Time'])))]
+                            #Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
+                            setattr(nvdict['md'].__dict__[classtree[mod][0]], classtree[mod][1], getattr(classtype[mod][1], 'solution')([]))
+                            for i in range(max(1, stepnum)):
+                                nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]].steps.append(getattr(classtype[mod][1], 'solutionstep')())
+                            Tree = nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
+                    #}}}
                 elif classtype[mod][0] == 'massfluxatgate':  #this is for output definitions {{{
                     defname = split('Output|[0-9]+', classtree[mod][1])[1] + 's'
@@ -141,24 +160,28 @@
                 Tree = nvdict['md'].__dict__[classtree[mod][0]]
             if debug:
-                print("    for {} Tree is a {}".format(mod, Tree.__class__.__name__))
+                print("    for {} Tree is a {} with len {}".format(mod, Tree.__class__.__name__, len(curclass.groups)))
             # }}}
             #==== Then we populate it {{{
-            for i in range(0, max(1, len(curclass.groups))):
-                if len(curclass.groups) > 0:
-                    listclass = curclass.groups[keylist[i]]
+            #for i in range(0, max(1, len(curclass.groups))):
+            if len(curclass.groups) > 0:  #that is presumably only for old style NC where each result step had its own group
+                if onlylast:
+                    listclass = curclass.groups[keylist[len(curclass.groups) - 1]]
                 else:
-                    listclass = curclass
-                #==== We deal with Variables {{{
-                for var in listclass.variables:
-                    if debug:
-                        print("    ==> treating var {}".format(var))
-                    if var not in ['errlog', 'outlog']:
-                        varval = listclass.variables[str(var)]
-                        vardim = varval.ndim
-                        #There is a special treatment for results to account for its specific structure
-                        #that is the new export version where time is a named dimension
-                        NewFormat = 'Time' in NCFile.dimensions
-                        if type(Tree) == list and NewFormat:
-                            if onlylast:
+                    listclass = curclass.groups[keylist[0]]
+            else:
+                listclass = curclass
+            #==== We deal with Variables {{{
+            for var in listclass.variables:
+                if debug:
+                    print("    ==> treating var {}".format(var))
+                if var not in ['errlog', 'outlog']:
+                    varval = listclass.variables[str(var)]
+                    vardim = varval.ndim
+                    #There is a special treatment for results to account for its specific structure
+                    #that is the new export version where time is a named dimension
+                    NewFormat = 'Time' in NCFile.dimensions
+                    if type(Tree) == list:  # and NewFormat:
+                        if onlylast:
+                            if NewFormat:
                                 if vardim == 1:
                                     Tree[0].__dict__[str(var)] = varval[-1].data
@@ -169,130 +192,96 @@
                                 else:
                                     print('table dimension greater than 3 not implemented yet')
+                            else:  #old format had step sorted in difeerent group so last group is last time
+                                Tree[0].__dict__[str(var)] = varval[:].data
+                        else:
+                            incomplete = 'Time' not in varval.dimensions and NewFormat
+                            if incomplete:
+                                chosendim = varval.dimensions[0]
+                                timelist = np.arange(0, len(NCFile.dimensions[chosendim]))
+                                print('WARNING, {} is not present on every times, we chose {}({}) as the dimension to write it with'.format(var, chosendim, len(NCFile.dimensions[chosendim])))
+                            elif not NewFormat:
+                                timelist = len(curclass.groups)
                             else:
-                                incomplete = 'Time' not in varval.dimensions
-                                if incomplete:
-                                    chosendim = varval.dimensions[0]
-                                    timelist = np.arange(0, len(NCFile.dimensions[chosendim]))
-                                    print('WARNING, {} is not present on every times, we chose {}({}) as the dimension to write it with'.format(var, chosendim, len(NCFile.dimensions[chosendim])))
-                                else:
-                                    timelist = np.arange(0, len(NCFile.dimensions['Time']))
-                                for t in timelist:
-                                    print("filing step {} for {}".format(t, var))
-                                    if vardim == 0:
-                                        Tree[t].__dict__[str(var)] = varval[:].data
-                                    if vardim == 1:
-                                        Tree[t].__dict__[str(var)] = varval[t].data
-                                    elif vardim == 2:
-                                        Tree[t].__dict__[str(var)] = varval[t, :].data
-                                    elif vardim == 3:
-                                        Tree[t].__dict__[str(var)] = varval[t, :, :].data
-                                    else:
-                                        print('table dimension greater than 3 not implemented yet')
-                        else:
-                            if vardim == 0:  #that is a scalar
-                                if type(Tree) == list:
-                                    t = indexlist[i]
-                                    if listtype == 'dict':
-                                        Tree[t][str(var)] = varval[0].data
-                                    else:
-                                        Tree[t].__dict__[str(var)] = varval[0].data
-                                else:
-                                    if str(varval[0]) == '':  #no value
-                                        Tree.__dict__[str(var)] = []
-                                    elif varval[0] == 'True':  #treatin bool
-                                        Tree.__dict__[str(var)] = True
-                                    elif varval[0] == 'False':  #treatin bool
-                                        Tree.__dict__[str(var)] = False
-                                    else:
-                                        Tree.__dict__[str(var)] = varval[0].item()
-
-                            elif vardim == 1:  #that is a vector
-                                if varval.dtype == str:
-                                    if varval.shape[0] == 1:
-                                        Tree.__dict__[str(var)] = [str(varval[0]), ]
-                                    elif 'True' in varval[:] or 'False' in varval[:]:
-                                        Tree.__dict__[str(var)] = np.asarray([V == 'True' for V in varval[:]], dtype=bool)
-                                    else:
-                                        Tree.__dict__[str(var)] = [str(vallue) for vallue in varval[:]]
-                                else:
-                                    if type(Tree) == list:
-                                        t = indexlist[i]
-                                        if listtype == 'dict':
-                                            Tree[t][str(var)] = varval[:].data
-                                        else:
-                                            Tree[t].__dict__[str(var)] = varval[:].data
-                                    else:
-                                        try:
-                                            #some thing specifically require a list
-                                            mdtype = type(Tree.__dict__[str(var)])
-                                        except KeyError:
-                                            mdtype = float
-                                        if mdtype == list:
-                                            Tree.__dict__[str(var)] = [mdval for mdval in varval[:]]
-                                        else:
-                                            Tree.__dict__[str(var)] = varval[:].data
-
-                            elif vardim == 2:
-                                #dealling with dict
-                                if varval.dtype == str:  #that is for dictionaries
-                                    if any(varval[:, 0] == 'toolkit'):  #toolkit definition have to be first
-                                        Tree.__dict__[str(var)] = OrderedDict([('toolkit', str(varval[np.where(varval[:, 0] == 'toolkit')[0][0], 1]))])
-                                        strings1 = [str(arg[0]) for arg in varval if arg[0] != 'toolkits']
-                                        strings2 = [str(arg[1]) for arg in varval if arg[0] != 'toolkits']
-                                        Tree.__dict__[str(var)].update(list(zip(strings1, strings2)))
-                                    else:
-                                        strings1 = [str(arg[0]) for arg in varval]
-                                        strings2 = [str(arg[1]) for arg in varval]
-                                        Tree.__dict__[str(var)] = OrderedDict(list(zip(strings1, strings2)))
-                                else:
-                                    if type(Tree) == list:
-                                        t = indexlist[i]
-                                        if listtype == 'dict':
-                                            Tree[t][str(var)] = varval[:, :].data
-                                        else:
-                                            Tree[t].__dict__[str(var)] = varval[:, :].data
-                                    else:
-                                        Tree.__dict__[str(var)] = varval[:, :].data
-                            elif vardim == 3:
-                                if type(Tree) == list:
-                                    t = int(indexlist[i])
-                                    if listtype == 'dict':
-                                        Tree[t][str(var)] = varval[:, :, :].data
-                                    else:
-                                        Tree[t].__dict__[str(var)] = varval[:, :, :]
-                                else:
-                                    Tree.__dict__[str(var)] = varval[:, :, :].data
+                                timelist = np.arange(0, len(NCFile.dimensions['Time']))
+                            for t in timelist:
+                                print("filing step {} for {}".format(t, var))
+                                if vardim == 0:
+                                    Tree[t].__dict__[str(var)] = varval[:].data
+                                if vardim == 1:
+                                    Tree[t].__dict__[str(var)] = varval[t].data
+                                elif vardim == 2:
+                                    Tree[t].__dict__[str(var)] = varval[t, :].data
+                                elif vardim == 3:
+                                    Tree[t].__dict__[str(var)] = varval[t, :, :].data
+                                else:
+                                    print('table dimension greater than 3 not implemented yet')
+                    else:
+                        if vardim == 0:  #that is a scalar
+                            if str(varval[0]) == '':  #no value
+                                Tree.__dict__[str(var)] = []
+                            elif varval[0] == 'True':  #treatin bool
+                                Tree.__dict__[str(var)] = True
+                            elif varval[0] == 'False':  #treatin bool
+                                Tree.__dict__[str(var)] = False
                             else:
-                                print('table dimension greater than 3 not implemented yet')
-                    # }}}
-                #==== And with atribute {{{
-                for attr in listclass.ncattrs():
-                    if debug:
-                        print("      ==> treating attribute {}".format(attr))
-                    if attr != 'classtype':  #classtype is for treatment, don't get it back
-                        attribute = str(attr).swapcase()  #there is a reason for swapcase, no sure what it isanymore
-                        if attr == 'VARNAME':
-                            attribute = 'name'
-                        if type(Tree) == list and NewFormat:
-                            if debug:
-                                print("        printing with index 0")
-                            if listtype == 'dict':
-                                Tree[0][attribute] = str(listclass.getncattr(attr))
+                                Tree.__dict__[str(var)] = varval[0].item()
+
+                        elif vardim == 1:  #that is a vector
+                            if varval.dtype == str:
+                                if varval.shape[0] == 1:
+                                    Tree.__dict__[str(var)] = [str(varval[0]), ]
+                                elif 'True' in varval[:] or 'False' in varval[:]:
+                                    Tree.__dict__[str(var)] = np.asarray([V == 'True' for V in varval[:]], dtype=bool)
+                                else:
+                                    Tree.__dict__[str(var)] = [str(vallue) for vallue in varval[:]]
                             else:
-                                Tree[0].__dict__[attribute] = str(listclass.getncattr(attr))
-                        elif type(Tree) == list:
-                            t = int(indexlist[i])
-                            if debug:
-                                print("        printing with index {}".format(t))
-                            if listtype == 'dict':
-                                Tree[t][attribute] = str(listclass.getncattr(attr))
-                            else:
-                                Tree[t].__dict__[attribute] = str(listclass.getncattr(attr))
-                        else:
-                            Tree.__dict__[attribute] = str(listclass.getncattr(attr))
-                            if listclass.getncattr(attr) == 'True':
-                                Tree.__dict__[attribute] = True
-                            elif listclass.getncattr(attr) == 'False':
-                                Tree.__dict__[attribute] = False
+                                try:
+                                    #some thing specifically require a list
+                                    mdtype = type(Tree.__dict__[str(var)])
+                                except KeyError:
+                                    mdtype = float
+                                if mdtype == list:
+                                    Tree.__dict__[str(var)] = [mdval for mdval in varval[:]]
+                                else:
+                                    Tree.__dict__[str(var)] = varval[:].data
+
+                        elif vardim == 2:
+                            #dealling with dict
+                            if varval.dtype == str:  #that is for dictionaries
+                                if any(varval[:, 0] == 'toolkit'):  #toolkit definition have to be first
+                                    Tree.__dict__[str(var)] = OrderedDict([('toolkit', str(varval[np.where(varval[:, 0] == 'toolkit')[0][0], 1]))])
+                                    strings1 = [str(arg[0]) for arg in varval if arg[0] != 'toolkits']
+                                    strings2 = [str(arg[1]) for arg in varval if arg[0] != 'toolkits']
+                                    Tree.__dict__[str(var)].update(list(zip(strings1, strings2)))
+                                else:
+                                    strings1 = [str(arg[0]) for arg in varval]
+                                    strings2 = [str(arg[1]) for arg in varval]
+                                    Tree.__dict__[str(var)] = OrderedDict(list(zip(strings1, strings2)))
+                        elif vardim == 3:
+                            Tree.__dict__[str(var)] = varval[:, :, :].data
+                        else:
+                            print('table dimension greater than 3 not implemented yet')
+                # }}}
+            #==== And with atribute {{{
+            for attr in listclass.ncattrs():
+                if debug:
+                    print("      ==> treating attribute {}".format(attr))
+                if attr != 'classtype':  #classtype is for treatment, don't get it back
+                    attribute = str(attr).swapcase()  #there is a reason for swapcase, no sure what it isanymore
+                    if attr == 'VARNAME':
+                        attribute = 'name'
+                    if type(Tree) == list:
+                        if debug:
+                            print("        printing with index 0")
+                        if listtype == 'dict':
+                            Tree[0][attribute] = str(listclass.getncattr(attr))
+                        else:
+                            Tree[0].__dict__[attribute] = str(listclass.getncattr(attr))
+                    else:
+                        Tree.__dict__[attribute] = str(listclass.getncattr(attr))
+                        if listclass.getncattr(attr) == 'True':
+                            Tree.__dict__[attribute] = True
+                        elif listclass.getncattr(attr) == 'False':
+                            Tree.__dict__[attribute] = False
                 # }}}
             # }}}
@@ -322,8 +311,8 @@
                 grpclass = str(getattr(NCData.groups[group].groups[subgroup], 'classtype'))
                 class_dict[classe] = [grpclass, ]
+                print(class_dict[classe][0])
                 if class_dict[classe][0] not in ['dict', 'list', 'cell']:
                     try:
                         modulename = split(r'\.', class_dict[classe][0])[0]
-                        #class_dict[classe].append(__import__(class_dict[classe][0]))
                         class_dict[classe].append(__import__(modulename))
                     except ModuleNotFoundError:
