Index: issm/trunk-jpl/src/m/io/loadvars.py
===================================================================
--- issm/trunk-jpl/src/m/io/loadvars.py	(revision 21236)
+++ issm/trunk-jpl/src/m/io/loadvars.py	(revision 21247)
@@ -78,86 +78,123 @@
 			NCFile=Dataset(filename,mode='r')
 			NCFile.close()
-			classtype,classtree=netCDFread(filename)
-			nvdict['md']=model()
-			module=map(__import__,dict.values(classtype))
-			for i,mod in enumerate(dict.keys(classtype)):
-#				print('treating md.{}'.format(mod))
-				if np.size(classtree[mod])>1:
-					if classtree[mod][0]=='results':
-						#treating results (Dimension4 is time)
-						resdim=len(NCFile.dimensions['Dimension4'])
-						curclass=NCFile.groups[classtree[mod][0]].groups[classtree[mod][1]]
-						nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(module[i],classtype[mod])()]
-						if resdim>1:
-							for t in range(1,resdim):
-								nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]].append(getattr(module[i],classtype[mod])())
-						Tree=nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]][:]
-					else:
-						curclass=NCFile.groups[classtree[mod][0]].groups[classtree[mod][1]]
-						nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = getattr(module[i],classtype[mod])()
-						Tree=nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]]
-				else:
-					curclass=NCFile.groups[classtree[mod][0]]
-					nvdict['md'].__dict__[mod] = getattr(module[i],classtype[mod])()
-					Tree=nvdict['md'].__dict__[classtree[mod][0]]
-				for var in curclass.variables:
-					#print('    treating {}'.format(var))
-					varval=curclass.variables[str(var)]
-					vardim=varval.ndim
-					try:
-						val_type=str(varval.dtype)
-					except AttributeError:
-						val_type=type(varval)
-					if vardim==0:
-						try:
-							Tree.__dict__[str(var)]=varval.getValue()
-							if varval.getValue()=='True':
-								Tree.__dict__[str(var)]=True
-							elif varval.getValue()=='False':
-								Tree.__dict__[str(var)]=False
-						except IndexError:
-							Tree.__dict__[str(var)]=[]
-					elif vardim==1:
-						if varval.dtype==str:
-							if varval.shape==1:
-								Tree.__dict__[str(var)]=str(varval[0])
-							if 'True' in varval[:] or 'False' in varval[:]:
-								Tree.__dict__[str(var)]=np.asarray(varval[:],dtype=bool)
-						else:
-							if classtree[mod][0]=='results' and resdim>1:
-								for t in range(0,resdim):
-									Tree[t].__dict__[str(var)]=varval[t]
-							else:
-								Tree.__dict__[str(var)]=varval[:]
-					elif vardim==2:
-						#dealling with dict
-						if varval.dtype==str:
-							Tree.__dict__[str(var)]=dict(zip(varval[:,0], varval[:,1]))
-						else:
-							if classtree[mod][0]=='results' and resdim>1:
-								for t in range(0,resdim):
-									Tree[t].__dict__[str(var)]=varval[:,t]
-							else:
-								Tree.__dict__[str(var)]=varval[:,:]
-					elif vardim==3:
-						if classtree[mod][0]=='results' and resdim>1:
-							for t in range(0,resdim):
-								Tree[t].__dict__[str(var)]=varval[:,:,t]
-						else:
-							Tree.__dict__[str(var)]=varval[:,:,:]
-					else:
-						print 'table dimension greater than 3 not implemented yet'
-				for attr in curclass.ncattrs():
-					#print('    treating {}'.format(attr))
-					if classtree[mod][0]!='results' and attr!='classtype': #no attributes in results
-						Tree.__dict__[str(attr)]=str(curclass.getncattr(attr))
-						if curclass.getncattr(attr)=='True':
-							Tree.__dict__[str(attr)]=True
-						elif curclass.getncattr(attr)=='False':
-							Tree.__dict__[str(attr)]=False
-
 		except RuntimeError:
 			raise IOError("File '%s' not found." % filename)
 
+		classtype,classtree=netCDFread(filename)
+		nvdict['md']=model()
+		NCFile=Dataset(filename,mode='r')
+		for mod in dict.keys(classtype):
+			if np.size(classtree[mod])>1:
+				curclass=NCFile.groups[classtree[mod][0]].groups[classtree[mod][1]]
+				if classtype[mod][0]=='list':
+					keylist=[key for key in curclass.groups]
+					listtype=curclass.groups[keylist[0]].classtype
+					if listtype=='dict':
+						nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [{} for i in range(max(1,len(curclass.groups)))]
+					else:
+						nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]] = [getattr(__import__(listtype),listtype)() for i in range(max(1,len(curclass.groups)))]
+					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],classtype[mod][0])()
+					Tree=nvdict['md'].__dict__[classtree[mod][0]].__dict__[classtree[mod][1]]
+			else:
+				curclass=NCFile.groups[classtree[mod][0]]
+				nvdict['md'].__dict__[mod] = getattr(classtype[mod][1],classtype[mod][0])()
+				Tree=nvdict['md'].__dict__[classtree[mod][0]]
+			#treating groups that are lists
+			for i in range(0,max(1,len(curclass.groups))):
+				if len(curclass.groups)>0:
+					listclass=curclass.groups[keylist[i]]
+				else:
+					listclass=curclass
+				for var in listclass.variables:
+					if var not in ['errlog','outlog']:
+						varval=listclass.variables[str(var)]
+						vardim=varval.ndim
+						try:
+							val_type=str(varval.dtype)
+						except AttributeError:
+							val_type=type(varval)
+						if vardim==0:
+							if type(Tree)==list:
+								t=int(keylist[i][-1])-1
+								if listtype=='dict':
+									Tree[t][str(var)]=varval.getValue()
+								else:
+									Tree[t].__dict__[str(var)]=varval.getValue()
+							else:
+								try:
+									Tree.__dict__[str(var)]=varval.getValue()
+									if varval.getValue()=='True':
+										Tree.__dict__[str(var)]=True
+									elif varval.getValue()=='False':
+										Tree.__dict__[str(var)]=False
+								except IndexError:
+									Tree.__dict__[str(var)]=[]
+						elif vardim==1:
+							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=int(keylist[i][-1])-1
+									if listtype=='dict':
+										Tree[t][str(var)]=varval[:]
+									else:
+										Tree[t].__dict__[str(var)]=varval[:]
+								else:
+									try:
+										#some thing specifically require a list
+										mdtype=type(Tree.__dict__[str(var)])
+									except KeyError:
+										print 'not defined yet'
+										mdtype=float
+									if mdtype==list:
+										Tree.__dict__[str(var)]=[mdval for mdval in varval[:]]
+									else:
+										Tree.__dict__[str(var)]=varval[:]
+						elif vardim==2:
+							#dealling with dict
+							if varval.dtype==str:
+								Tree.__dict__[str(var)]=dict(zip(varval[:,0], varval[:,1]))
+							else:
+								if type(Tree)==list:
+									t=int(keylist[i][-1])-1
+									if listtype=='dict':
+										Tree[t][str(var)]=varval[:,:]
+									else:
+										Tree[t].__dict__[str(var)]=varval[:,:]
+								else:
+									Tree.__dict__[str(var)]=varval[:,:]
+						elif vardim==3:
+							if type(Tree)==list:
+								t=int(keylist[i][-1])-1
+								if listtype=='dict':
+									Tree[t][str(var)]=varval[:,:,:]
+								else:
+									Tree[t].__dict__[str(var)]=varval[:,:,:]
+							else:
+								Tree.__dict__[str(var)]=varval[:,:,:]
+						else:
+							print 'table dimension greater than 3 not implemented yet'
+				for attr in listclass.ncattrs():
+					if  attr!='classtype': #classtype is for treatment, don't get it back
+						if type(Tree)==list:
+							t=int(keylist[i][-1])-1
+							if listtype=='dict':
+								Tree[t][str(attr)]=str(listclass.getncattr(attr))
+							else:
+								Tree[t].__dict__[str(attr)]=str(listclass.getncattr(attr))
+						else:
+							Tree.__dict__[str(attr)]=str(listclass.getncattr(attr))
+							if listclass.getncattr(attr)=='True':
+								Tree.__dict__[str(attr)]=True
+							elif listclass.getncattr(attr)=='False':
+								Tree.__dict__[str(attr)]=False
+		NCFile.close()
 	if   len(args) >= 2 and isinstance(args[1],(str,unicode)):    # (value)
 		value=[nvdict[name] for name in args[1:]]
@@ -173,26 +210,24 @@
 
 def netCDFread(filename):
-	def walktree(data):
-		keys = data.groups.keys()
-		for key in keys:
-			yield [str(key)]
-			for children in walktree(data.groups[str(key)]):
-				child=[str(key)]
-				child.append(str(children[0]))
-				yield child
 	print ('Opening {} for reading '.format(filename))
 	NCData=Dataset(filename, 'r')
 	class_dict={}
 	class_tree={}
+
+	for group in NCData.groups:
+		if len(NCData.groups[group].groups)>0:
+			for subgroup in NCData.groups[group].groups:
+				classe=str(group)+'.'+str(subgroup)
+				class_dict[classe]=[str(getattr(NCData.groups[group].groups[subgroup],'classtype')),]
+				if class_dict[classe][0] not in ['dict','list']:
+					class_dict[classe].append(__import__(class_dict[classe][0]))
+				class_tree[classe]=[group,subgroup]
+		else:
+			classe=str(group)
+			class_dict[classe]=[str(getattr(NCData.groups[group],'classtype')),]
+			if class_dict[classe][0] not in ['dict','list']:
+				class_dict[classe].append(__import__(class_dict[classe][0]))
+			class_tree[classe]=[group,]
 	
-	for children in walktree(NCData):
-		classe=str(children[0])
-		if np.size(children)>1:
-			for name in children[1:]:
-				classe=classe+'.'+name
-			class_dict[classe]=str(getattr(NCData.groups[children[0]].groups[children[1]],'classtype'))
-		else:
-			class_dict[classe]=str(getattr(NCData.groups[classe],'classtype'))
-		class_tree[classe]=children
-
+	NCData.close()
 	return class_dict,class_tree
