Changeset 2380 in lmdz_wrf for trunk


Ignore:
Timestamp:
Mar 7, 2019, 7:53:54 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `stringS_dictvark': Function to provide a dictionary from a String which list of DVs separated [key] [value] couples and assigning a variable-type to the value
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2373 r2380  
    193193# str_list_k: Function to obtain a list of types of values from a string giving a split character
    194194# str_list_rep: Function to obtain a list from a string givin a split character and a total number of values
    195 # stringS_dictvar: Function to provide a dictionary from a Srting which list of DVs separated [key] [value] couples
     195# stringS_dictvar: Function to provide a dictionary from a String which list of DVs separated
     196#   [key] [value] couples
     197# stringS_dictvark: Function to provide a dictionary from a String which list of DVs separated
     198#   [key] [value] couples and assigning a variable-type to the value
    196199# stringList_dictKeysVals: Function to provide a dictionary with keys which contain values of lists from a string
    197200# subbasin_point: Function to provide sub-basins given a grid point following a matrix of trips
     
    97449747
    97459748def stringS_dictvar(stringv, Dc=',', DVs=':'):
    9746     """ Function to provide a dictionary from a Srting which list of DVs separated [key] [value] couples
     9749    """ Function to provide a dictionary from a String which list of DVs separated
     9750          [key] [value] couples
    97479751      stringv: String with a dictionary content as [key1][DVs][val1][Dc][key2][DVs][Val2][Dc]...
    97489752      Sc: character to separate key values
     
    97579761        valn = Svals.split(DVs)[1]
    97589762        dictv[keyn] = valn
     9763
     9764    return dictv
     9765
     9766def stringS_dictvark(stringv, Dc=',', DVs=':', kind='np.float'):
     9767    """ Function to provide a dictionary from a String which list of DVs separated
     9768          [key] [value] couples and assigning a variable-type to the value
     9769      stringv: String with a dictionary content as [key1][DVs][val1][Dc][key2][DVs][Val2][Dc]...
     9770      Sc: character to separate key values
     9771      DVs: character to separate key-value couples
     9772      kind: ind of value to assign to all the values
     9773    >>> stringS_dictvark('i:1,iv:4,vii:7',',',':')
     9774    {'i': 1.0, 'vii': 7.0, 'iv': 4.0}
     9775    """
     9776    fname = 'stringS_dictvark'
     9777    dictv = {}
     9778    for Svals in stringv.split(Dc):
     9779        keyn = Svals.split(DVs)[0]
     9780        valn = Svals.split(DVs)[1]
     9781        dictv[keyn] = typemod(valn, kind)
    97599782
    97609783    return dictv
Note: See TracChangeset for help on using the changeset viewer.