Changeset 967 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 28, 2016, 7:47:51 PM (8 years ago)
Author:
lfita
Message:

Addding novar' as a value in function get_Variables'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var.py

    r965 r967  
    180180    ncvar.get_namelist_vars(opts.values, opts.ncfile)
    181181elif oper == 'get_Variables':
    182     ncvar.get_Variables(opts.values, opts.ncfile)
     182    ncvar.get_Variables(opts.values, opts.ncfile, opts.varname)
    183183elif oper == 'getvalues_lonlat':
    184184    ncvar.getvalues_lonlat(opts.values, opts.ncfile)
  • trunk/tools/nc_var_tools.py

    r966 r967  
    1634216342    return
    1634316343
    16344 def get_Variables(values, ncfile):
     16344def get_Variables(values, ncfile, variables):
    1634516345    """ Function to get a list of variables from an existing file
    16346       values = ',' separated list of names of variables to get
     16346      novar= behaviour when no variable is found
     16347        'error': an error messages arise and program stops
     16348        'warn': a warning messages arise and program continues
    1634716349      ncfile= WRF file to use
     16350      variables = ',' separated list of names of variables to get
    1634816351    """
    1634916352    fname = 'get_Variables'
     
    1635416357        quit()
    1635516358
    16356     variables = values.split(',')
     16359    novar = values
     16360    variables = variables.split(',')
    1635716361
    1635816362    ofile = 'get_Variables.nc'
     
    1636516369    for var in variables:
    1636616370        if not gen.searchInlist(filevars, var):
    16367             print errormsg
    16368             print '  ' + fname + ": file '" + ncfile + "' does not have variable '" +\
    16369               var + "' !!"
    16370             print '    variables in file:', filevars
    16371             quit(-1)
     16371            if novar == 'error':
     16372                print errormsg
     16373                print '  ' + fname + ": file '" + ncfile + "' does not have " +      \
     16374                  "variable '" + var + "' !!"
     16375                print '    variables in file:', filevars
     16376                quit(-1)
     16377            elif novar == 'warn':
     16378                print warnmsg
     16379                print '  ' + fname + ": file '" + ncfile + "' does not have " +      \
     16380                  "variable '" + var + "' !!"
     16381                print '    variables in file:', filevars
     16382                continue
     16383            else:
     16384                print errormsg
     16385                print '  ' + fname + ": novar '" + novar + "' not ready !!"
     16386                quit(-1)
    1637216387
    1637316388        print '  ' + fname + ": getting variable '" + var + "'..."
     
    1639116406        else:
    1639216407            newvar = onewnc.createVariable(var, nctype(varinf.dtype), tuple(vardims))
    16393 
     16408        newvar[:] = ovar[:]
    1639416409        for attrn in varinf.attributes:
    1639516410            attrv = ovar.getncattr(attrn)
Note: See TracChangeset for help on using the changeset viewer.