Index: trunk/tools/generic_tools.py
===================================================================
--- trunk/tools/generic_tools.py	(revision 1985)
+++ trunk/tools/generic_tools.py	(revision 1990)
@@ -75,4 +75,5 @@
 # color_deg: Function to generate a degradation of colors in rgb base
 # contflow: Function to bring back the increment in j,i grid points according to a trip: (inflow directions)
+# create_LateX_figs: Function to create a LaTeX from a folder with multiple plots from different values
 # crossingpoint_2Dlines: Function to determinant the crossing point between two lines in a plane
 # curvelocalize_2D: Function to provide the localization a curve in a 2D field of positions via the equivalent
@@ -13424,4 +13425,114 @@
 #ASCIIfile_stats('times_NOCDXWRF2.dat')
 
+def create_LateX_figs(folder, plots, values, kfig):
+    """ Function to create a LaTeX from a folder with multiple plots from different 
+      values
+      plots: list of names of plots
+      values: list of values for each plot to guess sort of plots
+      kfig: kind of figure
+    """
+    fname = 'create_LaTeX_figs'
+
+    texfn = 'LaTeX_figs.tex'
+    
+    otex = open(texfn, 'w')
+    otex.write('\\documentclass{article}\n')
+    otex.write('\\usepackage{graphicx}\n')
+    otex.write('\n')
+    otex.write('\\textheight=23cm\n')
+    otex.write('\\textwidth=18cm\n')
+    otex.write('\\oddsidemargin=-1cm\n')
+    otex.write('\\evensidemargin=-1cm\n')
+    otex.write('\\topmargin=-1cm\n')
+
+    otex.write('\n')
+    otex.write('\\begin{document}\n')
+
+    for plotn in plots:
+        print plotn + ' ...'
+        figs = files_folder_HMT(folder, head='', middle=plotn, tail=kfig)
+        unsortfigs = figs + []
+        Nfigs = len(figs)
+        # grouping figures
+        for valn in values:
+            print '  ' + valn + ' ...'
+            valfigs = []
+            for fign in figs:
+                if fign.find(valn) != -1: 
+                    valfigs.append(fign)
+                    unsortfigs.remove(fign)
+
+            Nvalfig = len(valfigs)
+            if Nvalfig > 0:
+                Ncol = int(np.sqrt(Nvalfig))
+                cs = Ntchar('c', Ncol)
+                frcwth = 0.9/Ncol
+
+                otex.write('\\begin{figure}\n')
+                otex.write('\\begin{center}\n')
+                
+                otex.write('\\begin{tabular}{' + cs + '}\n')
+
+                ifig = 1
+                for valfn in valfigs:
+                    if ifig != 0 and np.mod(ifig,Ncol) == 0: endchar = ' \\\\\n'
+                    else: endchar = ' &\n'
+
+                    otex.write('\\includegraphics[width=' + str(frcwth) +            \
+                       '\\textwidth]{' + valfigs[ifig-1] + '}' + endchar + '\n')
+                    ifig = ifig + 1
+
+                print 'Lluis ifig:', ifig-1, 'Ncol:', Ncol, 'mod:', np.mod(ifig-1,Ncol)
+                if Nvalfig - ifig + 1 != 0:
+                    endrow = Ntchar(' & ', Nvalfig - ifig + 1)
+                    otex.write(endrow + '\n')
+                otex.write('\\end{tabular}\n')
+                otex.write('\\end{center}\n')
+                otex.write('\\end{figure}\n')
+
+        if len(unsortfigs) != 0: 
+            Nunsortfig = len(unsortfigs)
+            Ncol = int(np.sqrt(Nunsortfig))
+            cs = Ntchar('c', Ncol)
+            frcwth = 0.9/Ncol
+
+            otex.write('\\begin{figure}\n')
+            otex.write('\\begin{center}\n')
+              
+            otex.write('\\begin{tabular}{' + cs + '}\n')
+
+            ifig = 1
+            for valfn in unsortfigs:
+                if ifig != 0 and np.mod(ifig,Ncol) == 0: endchar = ' \\\\\n'
+                else: endchar = ' &\n'
+
+                otex.write('\\includegraphics[width=' + str(frcwth) +            \
+                   '\\textwidth]{' + valfigs[ifig-1] + '}' + endchar + '\n')
+                ifig = ifig + 1
+
+            if np.mod(ifig-1,Ncol) != 0:
+                endrow = Ntchar(' & ', np.mod(ifig-1,Ncol))
+                otex.write(endrow + '\n')
+            otex.write('\\end{tabular}\n')
+            otex.write('\\end{center}\n')
+            otex.write('\\end{figure}\n')
+            otex.write('\n')
+            otex.write('\\clearpage\n')
+
+    otex.write('\\end{document}\n')
+
+    otex.close()
+    print fname + ": LaTeX file '" + texfn + "' succesfully written !!"
+
+    sub.process('pdflatex ' + texfn.split('.')[0], shell=True)
+    sub.process('pdflatex ' + texfn.split('.')[0], shell=True)
+    sub.process('pdflatex ' + texfn.split('.')[0], shell=True)
+
+    return
+
+#pltns = ['WindRose_', 'SkewT-logP_obs-sim_', 'SkewT-logP_']
+#sts = ['10868', '16080', '16144', '16546']
+#create_LateX_figs('/home/lluis/estudios/FPS_ALPS/additional/IOP/analysis/figs', pltns, sts, 'png')
+
 #quit()
 
