Changeset 21257


Ignore:
Timestamp:
10/12/16 04:54:28 (8 years ago)
Author:
bdef
Message:

BUG:compatibility fix for netCDF4-1.2

Location:
issm/trunk-jpl/src/m
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/contrib/defleurian/netCDF/export_netCDF.py

    r21251 r21257  
    9494                                DimDict=CreateVar(NCData,Var,field,NCgroup,DimDict,False)
    9595                        else:
    96                                 print('treating {}.{} of type {}'.format(group,field,type(md.__dict__[group].__dict__[field])))
    9796                                NCgroup.__setattr__('classtype', str(group))
    9897                                Subgroup=NCgroup.createGroup(str(field))
     
    126125                                                        'int64':'i8',
    127126                                                        numpy.int64:'i8',
    128                                                         str:'str',
    129                                                         dict:'str'}
     127                                                        str:str,
     128                                                        dict:str}
    130129               
    131130        val_dim=np.shape(val_shape)[0]
     
    133132        #treating scalar string or bool as atribute
    134133        if val_type==str or val_type==unicode or val_type==bool:
    135                 Group.__setattr__(str(field), str(var))
     134                Group.__setattr__(str(field).capitalize(), str(var))
    136135        #treating list as string table
    137136        elif val_type==list:
     
    141140                        nctype=TypeDict[type(var[0])]
    142141                except IndexError:
    143                         nctype='str' #most probably an empty list take str for that
     142                        nctype=str #most probably an empty list take str for that
    144143                ncvar = Group.createVariable(str(field),nctype,dimensions,zlib=True)
    145144                if val_shape==0:
     
    151150        elif val_type=='bool':
    152151                dimensions,DimDict=GetDim(NCData,var,val_shape,DimDict,val_dim,istime)
    153                 ncvar = Group.createVariable(str(field),'str',dimensions,zlib=True)
     152                ncvar = Group.createVariable(str(field),str,dimensions,zlib=True)
    154153                for elt in range(0,val_shape[0]):
    155154                        ncvar[elt] = str(var[elt])
     
    157156        elif val_type==collections.OrderedDict or val_type==dict:
    158157                dimensions,DimDict=GetDim(NCData,var,val_shape,DimDict,val_dim,istime)
    159                 ncvar = Group.createVariable(str(field),'str',dimensions,zlib=True)
     158                ncvar = Group.createVariable(str(field),str,dimensions,zlib=True)
    160159                for elt in range(0,val_dim):
    161160                        ncvar[elt,0]=dict.keys(var)[elt]
  • issm/trunk-jpl/src/m/io/loadvars.py

    r21252 r21257  
    189189                                                        t=indexlist[i]
    190190                                                        if listtype=='dict':
    191                                                                 Tree[t][str(attr)]=str(listclass.getncattr(attr))
    192                                                         else:
    193                                                                 Tree[t].__dict__[str(attr)]=str(listclass.getncattr(attr))
     191                                                                Tree[t][str(attr).lower()]=str(listclass.getncattr(attr))
     192                                                        else:
     193                                                                Tree[t].__dict__[str(attr).lower()]=str(listclass.getncattr(attr))
    194194                                                else:
    195                                                         Tree.__dict__[str(attr)]=str(listclass.getncattr(attr))
     195                                                        Tree.__dict__[str(attr).lower()]=str(listclass.getncattr(attr))
    196196                                                        if listclass.getncattr(attr)=='True':
    197                                                                 Tree.__dict__[str(attr)]=True
     197                                                                Tree.__dict__[str(attr).lower()]=True
    198198                                                        elif listclass.getncattr(attr)=='False':
    199                                                                 Tree.__dict__[str(attr)]=False
     199                                                                Tree.__dict__[str(attr).lower()]=False
    200200                NCFile.close()
    201201        if   len(args) >= 2 and isinstance(args[1],(str,unicode)):    # (value)
     
    227227                else:
    228228                        classe=str(group)
    229                         class_dict[classe]=[str(getattr(NCData.groups[group],'classtype')),]
    230                         if class_dict[classe][0] not in ['dict','list']:
    231                                 class_dict[classe].append(__import__(class_dict[classe][0]))
    232                         class_tree[classe]=[group,]
    233        
     229                        try:
     230                                class_dict[classe]=[str(getattr(NCData.groups[group],'classtype')),]
     231                                if class_dict[classe][0] not in ['dict','list']:
     232                                        class_dict[classe].append(__import__(class_dict[classe][0]))
     233                                        class_tree[classe]=[group,]
     234                        except AttributeError:
     235                                print('group {} is empty'.format(group))
    234236        NCData.close()
    235237        return class_dict,class_tree
Note: See TracChangeset for help on using the changeset viewer.