Changeset 21251
- Timestamp:
- 10/10/16 06:50:35 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/contrib/defleurian/netCDF/export_netCDF.py
r21247 r21251 40 40 41 41 #get all model classes and create respective groups 42 typelist=[bool,str,unicode,int,float,complex,numpy.ndarray,collections.OrderedDict] 42 typelist=[bool,str,unicode,int,float,complex,dict, 43 collections.OrderedDict, 44 numpy.int64,numpy.ndarray,numpy.float64] 43 45 groups=dict.keys(md.__dict__) 44 46 for group in groups: … … 80 82 subfields=dict.keys(md.__dict__[group].__dict__[field].__getitem__(listindex)) 81 83 for subfield in subfields: 82 try: 83 Var=md.__dict__[group].__dict__[field].__getitem__(listindex).__dict__[subfield] 84 except AttributeError: 85 Var=md.__dict__[group].__dict__[field].__getitem__(listindex)[subfield] 86 DimDict=CreateVar(NCData,Var,subfield,Listgroup,DimDict,False,md.__dict__[group],field,listindex) 84 if subfield!='outlog': 85 try: 86 Var=md.__dict__[group].__dict__[field].__getitem__(listindex).__dict__[subfield] 87 except AttributeError: 88 Var=md.__dict__[group].__dict__[field].__getitem__(listindex)[subfield] 89 DimDict=CreateVar(NCData,Var,subfield,Listgroup,DimDict,False,md.__dict__[group],field,listindex) 87 90 #No subgroup, we directly treat the variable 88 91 elif type(md.__dict__[group].__dict__[field]) in typelist: … … 91 94 DimDict=CreateVar(NCData,Var,field,NCgroup,DimDict,False) 92 95 else: 96 print('treating {}.{} of type {}'.format(group,field,type(md.__dict__[group].__dict__[field]))) 93 97 NCgroup.__setattr__('classtype', str(group)) 94 98 Subgroup=NCgroup.createGroup(str(field)) … … 96 100 subfields=dict.keys(md.__dict__[group].__dict__[field].__dict__) 97 101 for subfield in subfields: 98 if str(subfield)!=' errlog' and str(subfield)!='outlog' and str(subfield)!='SolutionType':102 if str(subfield)!='outlog': 99 103 Var=md.__dict__[group].__dict__[field].__dict__[subfield] 100 104 DimDict=CreateVar(NCData,Var,subfield,Subgroup,DimDict,False) … … 118 122 TypeDict = {float:'f8', 119 123 'float64':'f8', 124 numpy.float64:'f8', 120 125 int:'i8', 121 126 'int64':'i8', 127 numpy.int64:'i8', 122 128 str:'str', 123 129 dict:'str'} … … 149 155 ncvar[elt] = str(var[elt]) 150 156 #treating dictionaries as tables of strings 151 elif val_type==collections.OrderedDict :157 elif val_type==collections.OrderedDict or val_type==dict: 152 158 dimensions,DimDict=GetDim(NCData,var,val_shape,DimDict,val_dim,istime) 153 159 ncvar = Group.createVariable(str(field),'str',dimensions,zlib=True) … … 195 201 DimDict[len(NewDim)]='DimNum'+str(index) 196 202 output=output+[str(DimDict[shape[dim]])] 197 elif type(shape[0])==str :#dealling with a dictionnary203 elif type(shape[0])==str or type(shape[0])==unicode:#dealling with a dictionnary 198 204 try: 199 205 #dimension5 is 2 to treat with dict
Note:
See TracChangeset
for help on using the changeset viewer.