Index: /trunk/tools/model_graphics.py
===================================================================
--- /trunk/tools/model_graphics.py	(revision 1328)
+++ /trunk/tools/model_graphics.py	(revision 1329)
@@ -4378,4 +4378,50 @@
     return
 
+def figinf_figname(figname,config):
+    """ Function to retrieve figure information from its name
+      figname= name of the figure
+      config= configuration of `model_graphics.py'
+    >>> figinf_figname('2linesTime_wss_wrfout_xvar-ymean-tas_wrfout_xvar-ymean.pdf', cnf)
+    (2, '2linesTime', 'wss-tas', 'xvar-ymean@xvar-ymean')
+    >>> figinf_figname('Nlines_tas_wrfout_tturb-xmean-tmean.pdf', cnf)
+    (1, 'Nlines', 'tas', 'tturb-xmean-tmean')
+    >>> figinf_figname('2lines_wss_diffvar_WRF-micro1_WRF-current_tturb-xmean-last-tas_tturb-xmean-last.pdf',cnf)
+    (2, '2lines', 'wss-tas', 'tturb-xmean-last@tturb-xmean-last')
+    """
+    fname = 'figinf_figname'
+    plotsecs = figname.split('_')
+    plotk = plotsecs[0]
+
+    if gen.searchInlist(config['pairfigures'].split(':'), plotk):
+        Nvars = 2
+        varn1 = plotsecs[1]
+        if plotsecs[2] == 'diffvar' or plotsecs[2] == 'diffop':
+            statn1varn2 = plotsecs[5].split('-')
+            statn2 = plotsecs[6].split('.')[0]
+            Lstatn1varn2 = len(statn1varn2)
+            statn1 = '-'.join(statn1varn2[0:Lstatn1varn2-1])
+            varn2 = statn1varn2[Lstatn1varn2-1]
+        else:
+            statn1varn2 = plotsecs[3].split('-')
+            statn2 = plotsecs[5].split('.')[0]
+            Lstatn1varn2 = len(statn1varn2)
+            statn1 = '-'.join(statn1varn2[0:Lstatn1varn2-1])
+            varn2 = statn1varn2[Lstatn1varn2-1]
+        return Nvars, plotk, varn1+'-'+varn2, statn1+'@'+statn2
+    elif gen.searchInlist(config['Nsourcesfigures'].split(':'), plotk):
+        Nvars = 1
+        varn = plotsecs[1]
+        statn = plotsecs[3].split('.')[0]
+        return Nvars, plotk, varn, statn
+    else:
+        print errmsg
+        print '  ' + fname + ": kind of figure '" + plotk + "' not ready !!"
+        print '    ready ones _______'
+        print "    'pair_figures': figures of pair of variables: ",                  \
+          config['pairfigures'].split(':')
+        print "    'N-sources_figures': figures of pair of variables: ",                  \
+          config['Nsourcesfigures'].split(':')
+        quit(-1)
+    
 # Files with information about the configuration of the script
 inffiles = ['varcompute.inf', 'all_computevars.inf', 'all_statsvars.inf']
@@ -5342,7 +5388,5 @@
 lvars = []
 for plot in modexpimg:
-    plotk = plot.split('_')[0]
-    varn = plot.split('_')[1]
-    statn = plot.split('_')[3].split('.')[0]
+    Nvars, plotk, varn, statn = figinf_figname(plot,cnf)
     if not gen.searchInlist(lplots,plotk):
         lplots.append(plotk)
@@ -5366,36 +5410,40 @@
 print '      variables:', lvars
 
-for var in lvars:
+for dplot in dplots.keys():
+    plot = dplot.split('_')[0]
+    var = dplot.split('_')[1]
     otexf.write('% ' + var + '\n')
     otexf.write('\\modexp{' + gen.latex_text(var) + '}\n')
-    for plot in lplots:
-        if dplots.has_key(plot+'_'+varn):
-            for stn in dplots[plot+'_'+varn]:
-                plotvarfigs = []
-                caption = varn + ' ' + plot + ' ' + stn + ' ' 
-                flab = 'fig:' + varn + '_' + plot + '_' + stn + '_allmodexp'
-                for me in lmodexps:
-                    modexpn = expGC[me].label
-                    modn = me.split('/')[0]
-                    imgns = gen.files_folder_HMT(owdir+'/'+me, head=plot+'_'+varn,   \
-                      middle=stn, tail=cnf['kindfig'])
-                    caption = caption + ', ' + modexpn
-                    imgn = owdir+'/'+me+'/'+imgns[0]
-                    if os.path.isfile(imgn):
-                        plotvarfigs.append(imgn)
-                if dbg:
-                    print '      Grouping figures:', plotvarfigs
-                try:
-                    with gen.Capturing() as output:
-                        gen.latex_fig_array(plotvarfigs, otexf,                      \
-                          gen.latex_text(caption), flab, refsize=0.5, dist='sqr',    \
-                          dorest='center')
-                except:
-                    print errmsg
-                    print 'gen.latex_fig_array(',plotvarfigs,', '+otexf+', '+        \
-                          'gen.latex_text(' + caption + '), ' + flab +               \
-                          ", refsize=0.5, dist='sqr', dorest='center')"
-                    for s1out in output: print s1out
-                    quit(-1)
+    varn1 = var.split('-')[0]
+    varn2 = var.split('-')[1]
+    varn = varn1+'-'+varn2
+    for stn12 in dplots[dplot]:
+        stn1 = stn12.split('@')[0]
+        stn2 = stn12.split('@')[1]
+        stn = gen.lstring_values(stn12, '@',' & ')
+        plotvarfigs = []
+        caption = varn.replace('-',' & ') + ' ' + plot + ' ' + stn
+        flab = 'fig:' + varn + '_' + plot + '_' + stn12 + '_allmodexp'
+        for me in lmodexps:
+            modexpn = expGC[me].label
+            modn = me.split('/')[0]
+            imgns = gen.files_folder_HMT(owdir+'/'+me, head=plot+'_'+varn1,          \
+              middle=stn1+'-'+varn2, tail=stn2+'.'+cnf['kindfig'])
+            caption = caption + ', ' + modexpn
+            imgn = owdir+'/'+me+'/'+imgns[0]
+            if os.path.isfile(imgn):
+                plotvarfigs.append(imgn)
+        if dbg:
+            print '      Grouping figures:', plotvarfigs
+        try:
+            with gen.Capturing() as output:
+                gen.latex_fig_array(plotvarfigs, otexf, gen.latex_text(caption),     \
+                  flab, refsize=0.5, dist='sqr', dorest='center')
+        except:
+            print errmsg
+            print 'gen.latex_fig_array(',plotvarfigs,', '+otexf+', gen.latex_text(' +\
+               caption + '), ' + flab + ", refsize=0.5, dist='sqr', dorest='center')"
+            for s1out in output: print s1out
+            quit(-1)
 
 Nmods = len(mods)
@@ -5414,7 +5462,5 @@
 lvars = []
 for plot in modexpimg:
-    plotk = plot.split('_')[0]
-    varn = plot.split('_')[1]
-    statn = plot.split('_')[5].split('.')[0]
+    Nvars, plotk, varn, statn = figinf_figname(plot,cnf)
     if not gen.searchInlist(lplots,plotk):
         lplots.append(plotk)
@@ -5437,55 +5483,60 @@
 print '      plots:', lplots
 print '      variables:', lvars
-
-for var in lvars:
+print '      dplots:', dplots
+
+for dplot in dplots.keys():
+    plot = dplot.split('_')[0]
+    var = dplot.split('_')[1]
     otexf.write('% ' + var + '\n')
     otexf.write('\\modexp{diff ' + gen.latex_text(var) + '}\n')
-    for plot in lplots:
-        if dplots.has_key(plot+'_'+varn):
-            for stn in dplots[plot+'_'+varn]:
-                plotvarfigs = []
-                caption = varn + ' ' + plot + ' ' + stn + ' ' 
-                flab = 'fig:' + varn + '_' + plot + '_' + stn + '_alldiffmodexp'
-                for me in ldiffmodexps:
-                    mods = me.split('/')[0]
-                    exps = me.split('/')[1]
-                    if exps.find('-') != -1:
-                        expn1 = exps.split('-')[0]
-                        expn2 = exps.split('-')[1]
-                    else:
-                        expn1 = exps
-                        expn2 = exps
-
-                    if mods.find('-') != -1:
-                        modn1 = mods.split('-')[0]
-                        modn2 = mods.split('-')[1]
-                    else:
-                        modn1 = mods
-                        modn2 = mods
-                    modexpn1 = expGC[modn1 + '/' + expn1].label
-                    modexpn2 = expGC[modn2 + '/' + expn2].label
-                    modexpn = modexpn1 + '-' + modexpn2
-
-                    modn = me.split('/')[0]
-                    imgns = gen.files_folder_HMT(owdir+'/'+me, head=plot+'_'+varn,   \
-                      middle=stn, tail=cnf['kindfig'])
-                    caption = caption + ', ' + modexpn
-                    imgn = owdir+'/'+me+'/'+imgns[0]
-                    if os.path.isfile(imgn):
-                        plotvarfigs.append(imgn)
-                if dbg:
-                    print '      Grouping figures:', plotvarfigs
-                try:
-                    with gen.Capturing() as output:
-                        gen.latex_fig_array(plotvarfigs, otexf,                      \
-                          gen.latex_text(caption), flab, refsize=0.5, dist='sqr',    \
-                          dorest='center')
-                except:
-                    print errmsg
-                    print 'gen.latex_fig_array(',plotvarfigs,', '+otexf+', '+        \
-                          'gen.latex_text(' + caption + '), ' + flab +               \
-                          ", refsize=0.5, dist='sqr', dorest='center')"
-                    for s1out in output: print s1out
-                    quit(-1)
+    varn1 = var.split('-')[0]
+    varn2 = var.split('-')[1]
+    varn = varn1+'-'+varn2
+    for stn12 in dplots[dplot]:
+        stn1 = stn12.split('@')[0]
+        stn2 = stn12.split('@')[1]
+        stn = gen.lstring_values(stn12, '@',' & ')
+        plotvarfigs = []
+        caption = varn.replace('-',' & ') + ' ' + plot + ' ' + stn
+        flab = 'fig:' + varn + '_' + plot + '_' + stn12 + '_alldiffmodexp'
+        for me in ldiffmodexps:
+            mods = me.split('/')[0]
+            exps = me.split('/')[1]
+            if exps.find('-') != -1:
+                expn1 = exps.split('-')[0]
+                expn2 = exps.split('-')[1]
+            else:
+                expn1 = exps
+                expn2 = exps
+
+            if mods.find('-') != -1:
+                modn1 = mods.split('-')[0]
+                modn2 = mods.split('-')[1]
+            else:
+                modn1 = mods
+                modn2 = mods
+            modexpn1 = expGC[modn1 + '/' + expn1].label
+            modexpn2 = expGC[modn2 + '/' + expn2].label
+            modexpn = modexpn1 + '-' + modexpn2
+
+            modn = me.split('/')[0]
+            imgns = gen.files_folder_HMT(owdir+'/'+me, head=plot+'_'+varn1,          \
+              middle=stn1+'-'+varn2, tail=stn2+'.'+cnf['kindfig'])
+            caption = caption + ', ' + modexpn
+            imgn = owdir+'/'+me+'/'+imgns[0]
+            if os.path.isfile(imgn):
+                plotvarfigs.append(imgn)
+        if dbg:
+            print '      Grouping figures:', plotvarfigs
+        try:
+            with gen.Capturing() as output:
+                gen.latex_fig_array(plotvarfigs, otexf, gen.latex_text(caption),     \
+                  flab, refsize=0.5, dist='sqr', dorest='center')
+        except:
+            print errmsg
+            print 'gen.latex_fig_array(',plotvarfigs,', '+otexf+', gen.latex_text('+ \
+              caption + '), ' + flab + ", refsize=0.5, dist='sqr', dorest='center')"
+            for s1out in output: print s1out
+            quit(-1)
 
 otexf.write('\\end{document}\n')
