Index: trunk/tools/generic_tools.py
===================================================================
--- trunk/tools/generic_tools.py	(revision 994)
+++ trunk/tools/generic_tools.py	(revision 995)
@@ -38,4 +38,5 @@
 # files_folder_HMT: Function to retrieve a list of files from a folder [fold] and files with [head]*[middle]*[tail]
 # get_configuration: Function to get the configuration from an ASCII external file
+# get_specdictionary_HMT: Function to get specific values from a dictionary by selcting that keys with H*M*T
 # ijlonlat: Function to provide the imin,jmin imax,jmax of a lon,lat box
 # incomming_flow: Function to determine if a fgrid-flow inflows to the central grid point
@@ -8120,4 +8121,98 @@
 
     return
+
+def get_specdictionary_HMT(dictv,H='',M='',T=''):
+    """ Function to get specific values from a dictionary by selcting that keys with H*M*T
+      dictv= dictionary with the values
+      H= head of the key (empty for nothing)
+      M= middle of the key (empty for nothing)
+      T= tail of the key (empty for nothing)
+    dictrom = {'i':1, 'ii':2, 'iii':3, 'iv':4, 'v':5, 'vi':6, 'vii':2, 'viii':8, 'ix':9, 'x':10, 'xi':11 }
+    >>> get_specdictionary_HTM(dictrom,H='i')
+    {'ii': 2, 'ix': 9, 'iii': 3, 'i': 1, 'iv': 4}
+    >>> get_specdictionary_HTM(dictrom,M='i')
+    {'vii': 2, 'iii': 3, 'viii': 8}
+    >>> get_specdictionary_HTM(dictrom,T='i')
+    {'xi': 11, 'i': 1, 'vi': 6, 'vii': 2, 'ii': 2, 'viii': 8, 'iii': 3}
+    >>> get_specdictionary_HMT(dictrom,H='v',M='i')
+    {'vii': 2, 'viii': 8}
+    >>> get_specdictionary_HMT(dictrom,H='x',T='i')
+    {'xi': 11}
+    >>> get_specdictionary_HMT(dictrom,M='i',T='x')
+    None
+    >>> get_specdictionary_HMT(dictrom,H='v',M='i',T='i')
+    {'vii': 2, 'viii': 8}
+    """
+    fname = 'get_specdictionary_HMT'
+    
+    LH = len(H)
+    LM = len(M)
+    LT = len(T)
+
+    dictkeys = dictv.keys()
+
+    #print '  ' + fname + ': H=',H,'M=',M,'T=',T,'_______'
+    # Looking for heads
+    if LH > 0:
+        Hkeys = []
+        for key in dictkeys:
+            if key[0:LH] == H: Hkeys.append(key)
+        #print '    Hkeys:', Hkeys
+    # Looking for middles
+    if LM > 0:
+        Mkeys = []
+        for key in dictkeys:
+            Lkey = len(key)
+            if len(key[1:Lkey-1]) < LM:
+                print warnmsg
+                print '  ' + fname + ": key '" + key + "' too short for M='" + M +   \
+                  "' !!"
+            if key[1:Lkey-1].find(M) != -1: Mkeys.append(key)
+        #print '    Mkeys:', Mkeys
+    # Looking for tails
+    if LT > 0:
+        Tkeys = []
+        for key in dictkeys:
+            Lkey = len(key)
+            if key[Lkey-LT:Lkey+1] == T: Tkeys.append(key)
+        #print '    Tkeys:', Tkeys
+
+    # Coincidences
+    if LH > 0:
+        if LM > 0:
+            coinlistA = list(set(Hkeys).intersection(set(Mkeys)))
+            if LT > 0:
+                coinlist = list(set(coinlistA).intersection(set(Tkeys)))
+            else:
+                coinlist = list(coinlistA)
+        elif LT > 0:
+            coinlist = list(set(Hkeys).intersection(set(Tkeys)))
+        else:
+            coinlist = list(Hkeys)
+    elif LM > 0:
+        if LT > 0:
+            coinlist = list(set(Mkeys).intersection(set(Tkeys)))
+        else:
+            coinlist = list(Mkeys)
+    elif LT > 0:
+        coinlist = list(Tkeys)
+
+    if len(coinlist) > 0:
+        newdictv = {}
+        for key in coinlist:
+            newdictv[key] = dictv[key]
+    else:
+        newdictv= None
+
+    return newdictv
+
+dictrom = {'i':1, 'ii':2, 'iii':3, 'iv':4, 'v':5, 'vi':6, 'vii':2, 'viii':8, 'ix':9, 'x':10, 'xi':11 }
+print get_specdictionary_HMT(dictrom,H='i')
+print get_specdictionary_HMT(dictrom,M='i')
+print get_specdictionary_HMT(dictrom,T='i')
+print get_specdictionary_HMT(dictrom,H='v',M='i')
+print get_specdictionary_HMT(dictrom,H='x',T='i')
+print get_specdictionary_HMT(dictrom,M='i',T='x')
+print get_specdictionary_HMT(dictrom,H='v',M='i',T='i')
 #quit()
 
