Changeset 1881 in lmdz_wrf


Ignore:
Timestamp:
Apr 3, 2018, 8:04:03 PM (7 years ago)
Author:
lfita
Message:

Adding:

  • `ifile': Function to provide some information from a given file
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var.py

    r1879 r1881  
    2020## e.g. # nc_var.py -o nc_var.py -o CFmorzization -S 'X|west_east|XLONG,Y|south_north|XLAT,T|Time|WRFtime,Z|bottom_top|ZNU:GlobalAttr1995.inf:proj1995.inf' -f ~/PY/wrfout_d01_1995-01-01_00\:00\:00 -v QFX@instantaneous@None
    2121## e.g.# nc_var.py -o CFmorzization -S 'X|west_east|XLONG,Y|south_north|XLAT,T|Time|WRFtime,Z|bottom_top|ZNU:GlobalAttr1995.inf:proj1995.inf' -f ~/PY/wrfout_d01_1995-01-01_00\:00\:00 -v 'RAINC@time:!accumulation@WRFtime_bnds|h|3'
     22## e.g  # nc_var.py -o dimrm -S removevar -f wrfout_d01_1995-01-01_00:00:00 -v west_east
    2223
    2324## e.g. ccrc468-17 # ./nc_var.py -v time -f 123/CCRC_NARCliM_Sydney_All_1990-1999_pr10max.nc -o out -S 1:-1
     
    110111# grmattr: Removing a global attribute
    111112# idims: Give all the dimensions names of a file
     113# ifile: Function to provide some information from a given file
    112114# igattrs: Give all the global attributes of a file
    113115# increaseDimvar: Function to increase with 1 dimension an existing variable within a netcdf file. Values of
     
    191193  'get_namelist_vars', 'get_Variables',                                              \
    192194  'getvalues_lonlat', 'getvars_tofile', 'grattr',                                    \
    193   'grmattr', 'idims', 'igattrs', 'increaseDimvar', 'isgattrs',                       \
     195  'grmattr', 'idims', 'ifile', 'igattrs', 'increaseDimvar', 'isgattrs',              \
    194196  'isvattrs', 'ivars', 'ivattrs', 'LMDZ_toCF', 'lonlat_polygon', 'maskvar',          \
    195197  'merge_files', 'model_characteristics',                                            \
     
    379381elif oper == 'idims':
    380382    ncvar.idims(opts.ncfile)
     383elif oper == 'ifile':
     384    ncvar.ifile(opts.ncfile)
    381385elif oper == 'igattrs':
    382386    ncvar.igattrs(opts.ncfile)
  • trunk/tools/nc_var_tools.py

    r1880 r1881  
    8989# grmattr: Removing a global attribute
    9090# idims: Give all the dimensions names of a file
     91# ifile: Function to provide some information from a given file
    9192# igattrs: Give all the global attributes of a file
    9293# increaseDimvar: Function to increase with 1 dimension an existing variable within a netcdf file. Values of the variable will be repeated along the new dimension
     
    2402724028    return
    2402824029
     24030def ifile(ncfile):
     24031    """ Function to provide some information from a given file
     24032      ncfile= NetCDFFile from which provide the information
     24033    """
     24034    fname = 'ifile'
     24035
     24036    onc = NetCDFFile(ncfile,'r')
     24037
     24038    # dimensions
     24039    dimns = list(onc.dimensions)
     24040    dimns.sort()
     24041    for dimn in dimns:
     24042        odn = onc.dimensions[dimn]
     24043        if odn.isunlimited(): Ld = 'unlimited_' + str(len(odn))
     24044        else: Ld = len(odn)
     24045        print '  dim: @' + dimn + '@length= ', Ld
     24046
     24047    # variables
     24048    varns = list(onc.variables.keys())
     24049    varns.sort()
     24050    for varn in varns:
     24051        ovn = onc.variables[varn]
     24052        vardims = ':'.join(list(ovn.dimensions))
     24053        varshapel = []
     24054        for idim in ovn.shape: varshapel.append(str(idim))
     24055        varshape = ':'.join(varshapel)
     24056        print '  var: @' + varn + '@ dims= ' + vardims + ' shape= ' + varshape + ' type: ', ovn.dtype
     24057
     24058    onc.close
     24059
     24060    return
     24061
     24062
    2402924063#quit()
Note: See TracChangeset for help on using the changeset viewer.