Changeset 1552 in lmdz_wrf


Ignore:
Timestamp:
May 1, 2017, 8:54:53 PM (8 years ago)
Author:
lfita
Message:

Adding: `str_list_rep': Function to obtain a list from a string givin a split character and a total number of values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1535 r1552  
    126126# str_list: Function to obtain a list from a string givin a split character
    127127# str_list_k: Function to obtain a list of types of values from a string giving a split character
     128# str_list_rep: Function to obtain a list from a string givin a split character and a total number of values
    128129# stringS_dictvar: Function to provide a dictionary from a Srting which list of DVs separated [key] [value] couples
    129130# stringList_dictKeysVals: Function to provide a dictionary with keys which contain values of lists from a string
     
    88218822    return listv
    88228823
     8824
    88238825def str_list_k(string, cdiv, kind):
    88248826    """ Function to obtain a list of types of values from a string giving a split character
     
    88498851
    88508852    return finalist
     8853
     8854def str_list_rep(string, cdiv, Nvals):
     8855    """ Function to obtain a list from a string givin a split character and a total number of values
     8856      string= String from which to obtain a list ('None' for None)
     8857      cdiv= character to use to split the string
     8858      Nvals= number of values (if [string] only provides 1 value, list will be completed with the first value)
     8859    >>> str_list('1:@#:$', ':', 3)
     8860    ['1', '@#', '$']
     8861    >>> str_list('1@#$56', ':', 3)
     8862    ['1@#$56', '1@#$56', '1@#$56']
     8863    >>> str_list('--:-.'', ':', 3)
     8864    ['--', '-.', '--']
     8865    """
     8866    fname = 'str_list_rep'
     8867
     8868    if string.find(cdiv) != -1:
     8869        listv = string.split(cdiv)
     8870    else:
     8871        if string == 'None':
     8872            listv = None
     8873        else:
     8874            listv = [string]
     8875
     8876    if len(listv) < Nvals:
     8877        for iv in range(Nvals-len(listv)):
     8878            listv.append(listv[0])
     8879    elif len(listv) > Nvals:
     8880        print errormsg
     8881        print '  ' +fname+ ': number of obtained values:', len(listv), 'is larger' + \
     8882          ' than the desired ones:', Nvals, '!!'
     8883        print "    check string: '" + string + "' "
     8884        quit(-1)
     8885
     8886    return listv
    88518887
    88528888def stagger_unstagger(varv, dndims, udims):
Note: See TracChangeset for help on using the changeset viewer.