Changeset 2175 in lmdz_wrf for trunk


Ignore:
Timestamp:
Oct 10, 2018, 2:39:21 PM (7 years ago)
Author:
lfita
Message:

Adding:

  • `maskedStrvar_list': Function to provide a list of filled strings from a masked string 2D variable (Nvalues, Lstring)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r2174 r2175  
    110110# lonlatProj: Function to compute longitudes and latitudes for a given projection following subroutine calc_resolution_in from ORCHIDEE/src_global/module_InterpWeight
    111111# lonlat_polygon: Function to define a lon/lat region giving the coordinates of the vertexs of a given polygon
     112# maskedStrvar_list: Function to provide a list of filled strings from a masked string 2D variable (Nvalues, Lstring)
    112113# maskvar: Function to mask a variable using a mask. It is assumed that mask[...,dimM,dimJ,dimK] and var[...,dimM,dimJ,dimK] share the last dimensions
    113114# merge_files: Function to merge variables from two files
     
    2612726128#retrieve_stations(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2')
    2612826129
     26130def maskedStrvar_list(maskedStr, encodingn='latin_1'):
     26131    """ Function to provide a list of filled strings from a masked string 2D variable (Nvalues, Lstring)
     26132      maskedStr: masked 2D string variable
     26133      encoding: unicde encoding to use ('latin_1' default)
     26134    """
     26135    fname = 'maskedStrvar_list'
     26136
     26137    filledstrings = []
     26138    Lstring = maskedStr.shape[1]
     26139
     26140    for ist in range(maskedStr.shape[0]):
     26141        stnl = maskedStr[ist,:]
     26142        stnn = ''.encode('latin_1')
     26143        for ic in range(Lsrting):
     26144            char = unicode(stnl[ic:ic+1][0], errors='replace')
     26145            if not maskedStr.mask[ist,ic]:
     26146                stnn = stnn + char
     26147            else:
     26148                break
     26149        filledstrings.append(stnn)
     26150    filledstrings.remove('')
     26151
     26152    return filledstrings
     26153
    2612926154#quit()
Note: See TracChangeset for help on using the changeset viewer.