Index: /trunk/tools/documentation/plotting/gallery.html
===================================================================
--- /trunk/tools/documentation/plotting/gallery.html	(revision 1541)
+++ /trunk/tools/documentation/plotting/gallery.html	(revision 1542)
@@ -19,4 +19,5 @@
       <A HREF="2Dshad_line_time.html"><IMG SRC="figs/hus-ps_vert-sec_shad-line_time.png" ALT="2D shadow line time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
       <A HREF="draw_bar.html"><IMG SRC="figs/bar_rain_CRU-NCEP_norm.png" ALT="bar char plot" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
+      <A HREF="bar_time.html"><IMG SRC="figs/bar_time_rain_CRU-NCEP_DJFmean_norm.png" ALT="bar char plot time" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
       <A HREF="barbs.html"><IMG SRC="figs/wind_barbs_2001111003_wss.png" ALT="wind-barbs" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
       <A HREF="barbs.html"><IMG SRC="figs/wind_barbs_2001111003_uw.png" ALT="wind-barbs" STYLE="float:left;width:200px;height:200px" TARGET="value"></IMG></A>
Index: /trunk/tools/documentation/plotting/plotting.html
===================================================================
--- /trunk/tools/documentation/plotting/plotting.html	(revision 1541)
+++ /trunk/tools/documentation/plotting/plotting.html	(revision 1542)
@@ -15,4 +15,5 @@
       <A CLASS="lc" HREF="2Dshad_line_time.html" TARGET="value">2D shadow line time</A><BR>
       <A CLASS="lc" HREF="draw_bar.html" TARGET="value">bar</A><BR>
+      <A CLASS="lc" HREF="bar_time.html" TARGET="value">bar_time</A><BR>
       <A CLASS="lc" HREF="barbs.html" TARGET="value">barbs</A><BR>
       <A CLASS="lc" HREF="basins.html" TARGET="value">ORCHIDEE's basins</A><BR>
Index: /trunk/tools/drawing.py
===================================================================
--- /trunk/tools/drawing.py	(revision 1541)
+++ /trunk/tools/drawing.py	(revision 1542)
@@ -44,6 +44,8 @@
 ## e.g. # drawing.py -o draw_basins -f routing.nc -S '-5,5,42.,52.:l:rainbow,auto,auto:1,1000:True:True:True:ORCDHIEE|river-basins:png:basins_named:True' -v nav_lon,nav_lat,trip,basins
 ## e.g. # drawing.py -o draw_river_desc -f river_desc.nc -S 'Y|lat|lat|-1,X|lon|lon|-1:red,green:Blues:cyl,l:ORCDHIEE|rivers:png:0:or_rivers:True' -v Amazon,Parana
-## e.g. #drawing.py -f forcing_Amazonia.nc,forcing_Amazonia.nc -o draw_2lines_time -S 'tstep:Excts:Excts:exct,5,y;%Y:x:tas,wss:r,b:2.:-,-:None:,;,:WFD!forcing!evolution!at!Amazonia:year:0|12:../LaTeX/figs/forcing_Amazonia_tas-wss:png:yes' -v Tair,Wind
-## e.g. #drawing.py -o draw_bar -f 'Forcing_rainstats_OKstomate_CRUNCEP_spinup_SESA_norm_meanstd_stat2.nc;time_counter,0@12@1;time_counter;rainnorm:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SACZ_norm_meanstd_stat2.nc;time_counter,0@12@1;time_counter;rainnorm' -S 'Stringlist,%s,January@Feburary@March@Arpil@May@June@July@August@September@October@November@December,25,pretty,auto,auto,auto:time!since!1958-01-01:pr:y:seconds:mmd-1:SESA,SACZ:#AA0000,#0000AA:1000000.:normalized!evolution!of!precipitaion!with!CRU-NCEP!forcing:0|10:png:bar_rain_CRU-NCEP_norm:yes'
+## e.g. # drawing.py -f forcing_Amazonia.nc,forcing_Amazonia.nc -o draw_2lines_time -S 'tstep:Excts:Excts:exct,5,y;%Y:x:tas,wss:r,b:2.:-,-:None:,;,:WFD!forcing!evolution!at!Amazonia:year:0|12:../LaTeX/figs/forcing_Amazonia_tas-wss:png:yes' -v Tair,Wind
+## e.g. # drawing.py -o draw_bar -f 'Forcing_rainstats_OKstomate_CRUNCEP_spinup_SESA_norm_meanstd_stat2.nc;time_counter,0@12@1;time_counter;rainnorm:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SACZ_norm_meanstd_stat2.nc;time_counter,0@12@1;time_counter;rainnorm' -S 'Stringlist,%s,January@Feburary@March@Arpil@May@June@July@August@September@October@November@December,25,pretty,auto,auto,auto:time!since!1958-01-01:pr:y:seconds:mmd-1:SESA,SACZ:#AA0000,#0000AA:1000000.:normalized!evolution!of!precipitaion!with!CRU-NCEP!forcing:0|10:png:bar_rain_CRU-NCEP_norm:yes'
+## e.g. # drawing.py -o draw_bar_time -f 'Forcing_rainstats_OKstomate_CRUNCEP_spinup_SESA_DJFmean_norm_meanstd_stat2.nc;time_centered,-1;time_centered;rainnorm:Forcing_rainstats_OKstomate_CRUNCEP_spinup_SACZ_DJFmean_norm_meanstd_stat2.nc;time_centered,-1;time_centered;rainnorm' -S 'auto;pr;1;y;None;year|seconds!since!1958-01-01!00:00:00|exct,5,y|%Y;SESA,SACZ;#AA0000,#0000AA;10000000.;normalized!evolution!of!DJFmean!of!precipitaion!with!CRU-NCEP!forcing;0|10;png;bar_time_rain_CRU-NCEP_DJFmean_norm;yes'
+
 
 
@@ -81,4 +83,5 @@
 # draw_2lines_time: Function to plot two time-lines in different axes (x/x2 or y/y2)
 # draw_bar: Function to plot a bar char figure with multiple sources
+# draw_bar_time: Function to plot a bar char figure with multiple sources and time axis
 # draw_barbs: Function to plot wind barbs
 # draw_basins: Function to plot river basins with their discharge vector and basins id (from 'routing.nc')
@@ -112,5 +115,6 @@
   'draw_2D_shad_cont', 'draw_2D_shad_2cont', 'draw_2D_shad_cont_time',               \
   'draw_2D_shad_line',                                                               \
-  'draw_2D_shad_line_time', 'draw_bar', 'draw_barbs', 'draw_basins',                 \
+  'draw_2D_shad_line_time', 'draw_bar', 'draw_bar_time', 'draw_barbs',               \
+   'draw_basins',                                                                    \
   'draw_2lines', 'draw_2lines_time', 'draw_lines', 'draw_lines_time',                \
   'draw_Neighbourghood_evol',                                                        \
@@ -6576,4 +6580,212 @@
     return
 
+def draw_bar_time(ncfile, values):
+    """ Function to plot a bar char figure with multiple sources and time-axis
+      ncfile = ':' list of [filen];[dimslice];[tvarn];[yvarn]
+        [filen]: name of the file
+        [dimslice]: '|' list of [dimn],[dimrange]
+          [dimn]: name of the dimension
+          [dimrange]: range for the slice
+            * [integer]: which value of the dimension
+            * -1: all along the dimension
+            * -9: last value of the dimension
+            * [beg]@[end]@[inc] slice from [beg] to [end] every [inc]
+            * NOTE, no dim name all the dimension size
+        [tvarn]: name of the variable time
+        [yvarn]: name of the variable to use for the values
+      values = [dimxyfmt];[yaxislab];[yunits];[aval];[rangevals];[timevals];
+          [labels];[colors];[wdth];[graphtit];[legvalues];[kindfig];[fign];[close]
+        [dimxyfmt]=[dxs],[dxf],[Ndx],[ordx],[dys],[dyf],[Ndy],[ordy]: format of the values at each 
+            axis (or single 'auto' for 'auto','auto')
+          [dxs]: style of x-axis ('auto' for 'pretty')
+            'Nfix', values computed at even 'Ndx'
+            'Stringlist', a given list of strings
+            'Vfix', values computed at even 'Ndx' increments
+            'pretty', values computed following aprox. 'Ndx' at 'pretty' intervals (2.,2.5,4,5,10)
+          [dxf]: format of the labels at the x-axis
+          [Ndx]: Number of ticks at the x-axis (for 'Stringlist', '@' list of labels)
+          [ordx]: angle of orientation of ticks at the x-axis ('auto' for horizontal)
+          [dys]: style of y-axis ('auto' for 'pretty')
+          [dyf]: format of the labels at the y-axis
+          [Ndy]: Number of ticks at the y-axis
+          [ordy]: angle of orientation of ticks at the y-axis ('auto' for horizontal)
+        [yaxislab]: Label for the y-axis ('!' for spaces)
+        [yunits]: units of the y-label
+        [aval]: which acis should be used for the values ('x' or 'y')
+        [rangevals]: Range of the axis with the values (singel 'None' for 'auto','auto')
+         [vmin],[vmax]: minimum and maximum values
+           'auto': the computed minimumm or maximum of the values  
+        [timevals]: [timen]|[units]|[kind]|[tfmt] time labels characteristics
+          [timen]; name of the time variable
+          [units]; units string according to CF conventions ([tunits] since 
+            [YYYY]-[MM]-[DD] [[HH]:[MI]:[SS]], '!' for spaces)
+          [kind]; kind of output
+            'Nval': according to a given number of values as 'Nval',[Nval]
+            'exct': according to an exact time unit as 'exct',[tunit]; 
+              tunit= [Nunits],[tu]; [tu]= 'c': centuries, 'y': year, 'm': month,
+               'w': week, 'd': day, 'h': hour, 'i': minute, 's': second, 
+               'l': milisecond
+          [tfmt]; desired format
+        [labels]: ',' list of labels for the legend ('None' for no-labels)
+        [colors]: ',' list of colors (single value same color, 'auto' automatic)
+        [wdth]: width of the bars
+        [graphtit]: title of the figure '!' for spaces
+        [legvalues]=[locleg]|[fontsize]: 
+          [locleg]: location of the legend (0, autmoatic)
+            1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
+            5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
+            9: 'upper center', 10: 'center'
+          [fontsize]: font size for the legend (auto for 12)
+        [kindfig]: kind of output figure (png, pdf, ps)
+        [fign]: name of the figure (without extension)
+        [close]: whether figure should be close or not
+    """
+    fname = 'draw_bar_time'
+
+    if values == 'h':
+        print fname + '____________________________________________________________'
+        print draw_bar_time.__doc__
+        quit()
+
+    expectargs = '[dimxyfmt];[yaxislab];[yunits];[aval];[rangevals];[timevals];' +   \
+      '[labels];[colors];[wdth];[graphtit];[legvalues];[kindfig];[fign];[close]'
+    drw.check_arguments(fname,values,expectargs,';')
+
+    dimxyfmt = values.split(';')[0]
+    yaxislab = values.split(';')[1].replace('!',' ')
+    yunits = values.split(';')[2]
+    aval = values.split(';')[3]
+    rangevals = values.split(';')[4]
+    timevals = values.split(';')[5]
+    labels = gen.str_list(values.split(';')[6], ',')
+    colors = gen.str_list(values.split(';')[7], ',')
+    wdth = np.float(values.split(';')[8])
+    graphtit = values.split(';')[9].replace('!',' ')
+    legvalues = values.split(';')[10]
+    kindfig = values.split(';')[11]
+    fign = values.split(';')[12]
+    close = gen.Str_Bool(values.split(';')[13])
+
+    # files and values
+    filedvs = ncfile.split(':')
+    tvals = []
+    yvals = []
+
+    # time-values
+    expectargs = '[timen]|[units]|[kind]|[tfmt]'
+    drw.check_arguments('timevals: '+fname,timevals,expectargs,'|')
+
+    timen = timevals.split('|')[0].replace('!',' ')
+    timeunit = timevals.split('|')[1].replace('!',' ')
+    timekind = timevals.split('|')[2]
+    timefmt = timevals.split('|')[3]
+
+    for fdv in filedvs:
+        filen = fdv.split(';')[0]
+        dimrange = fdv.split(';')[1]
+        tvarn = fdv.split(';')[2]
+        yvarn = fdv.split(';')[3]
+
+        if not os.path.isfile(filen):
+            print errormsg
+            print '  ' + fname + ': file "' + filen + '" does not exist !!'
+            quit(-1)
+
+        onc = NetCDFFile(filen, 'r')
+        if not onc.variables.has_key(tvarn):
+            print errormsg
+            print '  ' + fname + ': file "' + filen + "' does not have variable '" + \
+              tvarn + "' for the time-values !!"
+            print '    available ones:', onc.variables.keys()
+            onc.close()
+            quit(-1)
+        if not onc.variables.has_key(yvarn):
+            print errormsg
+            print '  ' + fname + ': file "' + filen + "' does not have variable '" + \
+              yvarn + "' for the y-values !!"
+            print '    available ones:', onc.variables.keys()
+            onc.close()
+            quit(-1)
+
+        otvar = onc.variables[tvarn]
+        oyvar = onc.variables[yvarn]
+        tvs, tdims = ncvar.slice_variable(otvar, dimrange.replace(',',':'))
+        yvs, ydims = ncvar.slice_variable(oyvar, dimrange.replace(',',':'))
+        tunitsvar = otvar.units
+
+        if len(tvs.shape) != 1:
+            print errormsg
+            print '  ' + fname + ': provided slice:', dimrange, "for variable '" +   \
+              tvarn + "' does not provide a rank-1 value !!"
+            print '    resultant shape:', tvs.shape, 'dimensions:', tdims, 'fix it!!'
+            quit(-1)
+        if len(yvs.shape) != 1:
+            print errormsg
+            print '  ' + fname + ': provided slice:', dimrange, "for variable '" +   \
+              yvarn + "' does not provide a rank-1 value !!"
+            print '    resultant shape:', yvs.shape, 'dimensions:', ydims, 'fix it!!'
+            quit(-1)
+
+        uvd = timeunit
+        tunitsec = timeunit.split(' ')
+        if len(tunitsec) == 4:
+            refdate = tunitsec[2][0:4]+tunitsec[2][5:7]+tunitsec[2][8:10] +          \
+              tunitsec[3][0:2] + tunitsec[3][3:5] + tunitsec[3][6:8]
+        else:
+            refdate = tunitsec[2][0:4]+tunitsec[2][5:7]+tunitsec[2][8:10] +          \
+              '000000'
+        tunitsval = tunitsec[0]
+        # Referring all times to the same reference time!
+        reftvals = gen.coincident_CFtimes(tvs, timeunit, tunitsvar)
+
+        tvals.append(list(reftvals))
+        yvals.append(list(yvs))
+
+        onc.close()
+
+    # Times
+    mintval = np.min(tvals)
+    maxtval = np.max(tvals)
+
+    dtvals = (maxtval - mintval)/10
+    dti = mintval
+    dte = maxtval
+    tvalsticks = np.arange(dti, dte, dtvals)
+
+    dtiS = drw.datetimeStr_conversion(str(dti) + ',' + timeunit, 'cfTime',           \
+     'Y/m/d H-M-S')
+    dteS = drw.datetimeStr_conversion(str(dte) + ',' + timeunit, 'cfTime',           \
+     'Y/m/d H-M-S')
+
+    print '  ' + fname + ': plotting from: ' + dtiS + ' to ' + dteS
+
+    timepos, timelabels = drw.CFtimes_plot(tvalsticks, timeunit, timekind, timefmt)
+
+    # ranges
+    if rangevals == 'None':
+        valmin = np.min(yvals)
+        valmax = np.max(yvals)
+    else:
+        valmin = np.float(rangevals.split(',')[0])
+        valmax = np.float(rangevals.split(',')[1])
+        if valmin != 'auto': valmin = np.min(yvals)
+        if valmax != 'auto': valmax = np.max(yvals)
+    yrange = [valmin, valmax]
+
+    xstyl, xaxf, Nxax, xaxor, ystyl, yaxf, Nyax, yaxor = drw.format_axes(dimxyfmt,',')
+    xaxis = [xstyl, xaxf, Nxax, xaxor]
+    yaxis = [ystyl, yaxf, Nyax, yaxor]
+
+    # Legend 
+    legloc, legsiz = drw.legend_values(legvalues,'|')
+
+    dyu = yunits
+
+    drw.plot_bars_time(tvals, yvals, timepos, timelabels, yaxis, dyu, aval, yrange,  \
+     timen, yaxislab, labels, colors, wdth, graphtit, legloc, legsiz, kindfig, fign, \
+     close)
+
+    return
+
 #quit()
 
@@ -6598,5 +6810,5 @@
   'draw_2D_shad_cont_time',                                                          \
   'draw_2D_shad_line', 'draw_2D_shad_line_time', 'draw_2lines', 'draw_2lines_time',  \
-  'draw_bar', 'draw_lines',                                                          \
+  'draw_bar', 'draw_bar_time', 'draw_lines',                                         \
   'draw_lines_time', 'draw_points', 'draw_Taylor', 'draw_topo_geogrid_boxes',        \
   'draw_trajectories', 'draw_vals_trajectories', 'variable_values']
@@ -6656,4 +6868,6 @@
     elif oper == 'draw_bar':
         draw_bar(opts.ncfile, opts.values)
+    elif oper == 'draw_bar_time':
+        draw_bar_time(opts.ncfile, opts.values)
     elif oper == 'draw_barbs':
         draw_barbs(opts.ncfile, opts.values, opts.varname)
Index: /trunk/tools/drawing_tools.py
===================================================================
--- /trunk/tools/drawing_tools.py	(revision 1541)
+++ /trunk/tools/drawing_tools.py	(revision 1542)
@@ -9300,2 +9300,125 @@
     return
 
+def plot_bars_time(xvalues, yvalues, tpos, tlabs, yaxv, dimyu, valaxis, valrange, xlabel, \
+  ylabel, labels, cols, width, gtit, lloc, lsiz, kfig, figname, ifclose):
+    """ Function to plot a bar plot with multiple columns
+      xvalues= list with the values along the x-ais
+      yvalues= list with the values along the y-ais
+      tpos= position of the time-ticks
+      tlabs= labels of the time-ticks
+      yaxv= values at the axis y
+      dimyu= units at the axis y
+      valaxis= which axis holds the values 'x' or 'y'
+      valrange= range of the axis with values
+      xlabel= label at the x-axis
+      ylabel= label at the y-axis
+      labels= list of labels for legend (None for no legend)
+      cols= list of colors for the bars (single value for the same, 'auto' for automatic)
+      width= size of the column
+      gtit= title of the figure
+      lloc= location of the legend (0, autmoatic)
+        1: 'upper right', 2: 'upper left', 3: 'lower left', 4: 'lower right',
+        5: 'right', 6: 'center left', 7: 'center right', 8: 'lower center',
+        9: 'upper center', 10: 'center'
+      lsiz= font size of the legend
+      kfig= kind of output: pdf, png, ps
+      figname= name of the figure
+      ifclose= whether figure should be closed
+    """
+    fname = 'plot_bars'
+
+    Nvalues = len(xvalues)
+
+    dyn = valrange[0]
+    dyx = valrange[1]
+
+    axstyles = ['pretty', 'Nfix', 'Stringlist', 'Vfix']
+    if yaxv[0] == 'pretty':
+        dimyt = np.array(gen.pretty_int(dyn,dyx,yaxv[2]))
+        dimyl = np.array(dimyt, dtype=str)
+    elif yaxv[0] == 'Nfix':
+        dimyt = np.arange(0.,1.,1./(yaxv[2]+1))
+        dimyl = np.arange(0.,1.,1./varsv.shape[0])
+        axytype='fixpixel'
+    elif yaxv[0] == 'Vfix':
+        dynvfix = int(dyn/yaxv[2])
+        dimyt = np.arange(dynvfix*xaxv[2],dyx,yaxv[2])
+        axytype='data'
+    else:
+        print errormsg
+        print '  ' + fname + ": x-xais style '" + xaxv[0] + "' not ready !!"
+        print '    available ones: ', axstyles
+        quit(-1)
+
+    colvs = []
+    if len(cols) == 1:
+        if cols[0] == 'auto':
+            colvs = colorsauto[0:Nvalues+1]
+        else:
+            for ic in range(Nvalues): colvs.append(cols[0])
+    else:
+        colvs = cols
+    
+    for iv in range(Nvalues):
+        xvls = xvalues[iv]
+        Lvalues = len(xvls)
+        dxmean = np.mean(np.array(xvls[1:Lvalues])-np.array(xvls[0:Lvalues-1]))
+        if dxmean < width*Nvalues:
+            print warnmsg
+            print '  ' + fname + ': mean distance among x-values:', dxmean,         \
+              'is smaller than the total number of bars with the given witdh (',    \
+              width, '):', width*Nvalues
+            print '    reduce widht of the column, should not be larger than:',     \
+              dxmean/Nvalues
+        if width*Nvalues < 0.1*dxmean:
+            print warnmsg
+            print '  ' + fname + ': mean distance among x-values:', dxmean,         \
+              'is 100-times larger than the total number of bars with the given ' + \
+              'witdh (', width, '):', width*Nvalues
+            print '    increase widht of the column, should not be smaller than:',  \
+              0.1*dxmean
+
+        # Relative position of the column respect the xtick
+        if np.mod(Nvalues,2) == 0:
+            xrel = width*(iv - Nvalues/2.)
+        else:
+            xrel = width*(iv - (Nvalues-1)/2.)
+
+        xrels = xrel*np.ones((Lvalues),dtype=np.float)
+
+        if valaxis == 'x':
+            if labels is not None:
+                plt.barh(xvls+xrels, yvalues[iv], height=width, color=colvs[iv],     \
+                  label=labels[iv])
+            else:
+                plt.barh(xvls+xrels, yvalues[iv], height=width, color=colvs[iv])
+        else:
+            if labels is not None:
+                plt.bar(xvls+xrels, yvalues[iv], width=width, color=colvs[iv],       \
+                  label=labels[iv])
+            else:
+                plt.bar(xvls+xrels, yvalues[iv], width=width, color=colvs[iv])
+ 
+    if valaxis == 'x':
+        plt.xticks(dimyt, dimyl, rotation=yaxv[3])
+        plt.yticks(tpos, tlabs, rotation=0)
+        plt.xlabel(ylabel + ' (' + units_lunits(dimyu) + ')')
+        plt.ylabel(gen.latex_text(xlabel))
+        plt.xlim(dyn, dyx)
+    else:
+        plt.xticks(tpos, tlabs)
+        plt.yticks(dimyt, list(dimyl), rotation=yaxv[3])
+        plt.xlabel(gen.latex_text(xlabel))
+        plt.ylabel(ylabel + ' (' + units_lunits(dimyu) + ')')
+        plt.ylim(dyn, dyx)
+
+    if labels is not None:
+        plt.legend(loc=lloc, prop={'size':lsiz})
+
+    plt.title(gen.latex_text(gtit))
+    
+    output_kind(kfig, figname, ifclose)
+
+    return
+
+
