Changeset 966 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 28, 2016, 5:48:26 PM (8 years ago)
Author:
lfita
Message:

Working version of `get_Variables'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r964 r966  
    88388838                found = True
    88398839                break
    8840         if not found and not searchInlist(dimnslice,vardims[idd]):
     8840        if not found and not gen.searchInlist(dimnslice,vardims[idd]):
    88418841            varvalsdim.append(slice(0,varobj.shape[idd]))
    88428842            dimnslice.append(vardims[idd])
     
    1636116361
    1636216362    onc = NetCDFFile(ncfile, 'r')
    16363     filevars = list(onc.varibles.keys)
     16363    filevars = list(onc.variables.keys())
    1636416364
    1636516365    for var in variables:
     
    1637416374        ovar = onc.variables[var]
    1637516375        varinf = variable_inf(ovar)
    16376         vardims = varind.dmns
    16377 
    16378         newfiledims = list(onewnc.dimensions.keys)
     16376        vardims = varinf.dimns
     16377
     16378        newfiledims = list(onewnc.dimensions.keys())
    1637916379
    1638016380        for vdim in vardims:
    1638116381            if not gen.searchInlist(newfiledims, vdim):
    1638216382                print '  ' + fname + ": including dimension '" + vdim + "'..."
    16383                 if onc.dimensions[vdim].isunlimted:
     16383                if onc.dimensions[vdim].isunlimited():
    1638416384                    newdim = onewnc.createDimension(vdim, None)
    1638516385                else:
    1638616386                    newdim = onewnc.createDimension(vdim, len(onc.dimensions[vdim]))
    1638716387
    16388        if varinf.FillValue is not None:
    16389            newvar = onewnc.creatrVariable(var, nctype(varinf.dtype), tuple(vardims), \
    16390              fillvalue = varinf.FillValue)
    16391        else:
    16392            newvar = onewnc.creatrVariable(var, nctype(varinf.dtype), tuple(vardims))
    16393 
    16394        for attrn in varinf.atttributes:
    16395            attrv = ovar.getattribute(attrn)
    16396            newattr = set_attribute(newvar, attrn, attrv)
    16397 
    16398        onewnc.sync()
     16388        if varinf.FillValue is not None:
     16389            newvar = onewnc.createVariable(var, nctype(varinf.dtype), tuple(vardims),\
     16390              fillvalue = varinf.FillValue)
     16391        else:
     16392            newvar = onewnc.createVariable(var, nctype(varinf.dtype), tuple(vardims))
     16393
     16394        for attrn in varinf.attributes:
     16395            attrv = ovar.getncattr(attrn)
     16396            newattr = set_attribute(newvar, attrn, attrv)
     16397
     16398        onewnc.sync()
    1639916399
    1640016400    # Global attributes
    16401     for attrn in onc.ncattrs:
    16402        attrv = ovar.getattribute(attrn)
    16403        newattr = set_attribute(newvar, attrn, attrv)
     16401    for attrn in onc.ncattrs():
     16402        attrv = onc.getncattr(attrn)
     16403        newattr = set_attribute(onewnc, attrn, attrv)
    1640416404   
    1640516405    onewnc.sync()
     
    1640816408    onewnc.close()
    1640916409
    16410     print fname + ": successful written of '" + ncfile + "' !!"
     16410    print fname + ": successful written of '" + ofile + "' !!"
    1641116411
    1641216412#quit()
Note: See TracChangeset for help on using the changeset viewer.