Changeset 840 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 16, 2016, 5:19:47 PM (9 years ago)
Author:
lfita
Message:

Adding:

  • `CFvar_DIAGvar': Function to provide which model diagnostic values can provide a CF-variable from ASCII file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r837 r840  
    1919
    2020####### Content
     21# CFvar_DIAGvar: Function to provide which model diagnostic values can provide a CF-variable from ASCII file
    2122# CFvar_MODvar: Function to provide which model values can provide a CF-variable from ASCII file
    2223# chainSnumHierarchy: Class to provide the structure of a `ChainStrNum' hierarchy
     
    569570    """ Function to provide which model values can provide a CF-variable from ASCII file
    570571      'variables_values.dat'
    571     CFvar_MODvar(varName)
    572       [varName]= name of the variable
     572    CFvar_MODvar(varn)
     573      [varn]= CF name of the variable
    573574    >>> CFvar_MODvar('hfss')
    574575    ['hfss', 'LSENS', 'sens', 'HFX', 'hfx']
     
    615616        return MODvars
    616617
    617 print CFvar_MODvar('hfss')
    618 print CFvar_MODvar('pr')
     618def CFvar_DIAGvar(varn):
     619    """ Function to provide which model diagnostic values can provide a CF-variable from ASCII file
     620      'diagnostics.inf' (reference for diagnostics.py')
     621       [CFname], [moddiag], [varcombo]
     622         [moddiag]: name of the diagnosted variable
     623         [varcombo]: combnination of variables to be used to compute diagnostic
     624    CFvar_DIAGvar(varn)
     625      [varn]= CF name of the variable
     626    >>> CFvar_MODvar('pr')
     627    [[' RAINC', 'RAINNC']]
     628    >>> CFvar_MODvar('hurs')
     629    [[' psol', 't2m', 'q2m'], [' psfc', 't', 'q'], [' PSFC', 'T2', 'Q2']]
     630    """
     631    import subprocess as sub
     632
     633    fname='CFvar_DIAGvar'
     634
     635    if varn == 'h':
     636        print fname + '_____________________________________________________________'
     637        print CFvar_DIAGvar.__doc__
     638        quit()
     639
     640    folder = os.path.dirname(os.path.realpath(__file__))
     641
     642    infile = folder + '/diagnostics.inf'
     643
     644    if not os.path.isfile(infile):
     645        print errormsg
     646        print '  ' + fname + ": File '" + infile + "' does not exist !!"
     647        quit(-1)
     648
     649    ncf = open(infile, 'r')
     650
     651    MODvars = []
     652    for line in ncf:
     653        if line[0:1] != '#':
     654            values = line.replace('\n','').split(',')
     655            varvals = [values[0], values[1], values[2]]
     656            if varvals[0] == varn: MODvars.append(values[2].split('@'))
     657
     658    if len(MODvars) == 0:
     659        print errormsg
     660        print '  ' + fname + ": variable '" + varn + "' not defined !!!"
     661        ncf.close()
     662        return None
     663    else:
     664        return MODvars
     665
     666print CFvar_DIAGvar('pr')
     667print CFvar_DIAGvar('hurs')
    619668
    620669quit()
Note: See TracChangeset for help on using the changeset viewer.