Index: /trunk/UTIL/PYTHON/mymath.py
===================================================================
--- /trunk/UTIL/PYTHON/mymath.py	(revision 429)
+++ /trunk/UTIL/PYTHON/mymath.py	(revision 430)
@@ -197,2 +197,33 @@
     return idx
 
+def fig2data ( fig ):
+    import numpy
+    """
+    @brief Convert a Matplotlib figure to a 4D numpy array with RGBA channels and return it
+    @param fig a matplotlib figure
+    @return a numpy 3D array of RGBA values
+    """
+    # draw the renderer
+    fig.canvas.draw ( )
+ 
+    # Get the RGBA buffer from the figure
+    w,h = fig.canvas.get_width_height()
+    buf = numpy.fromstring ( fig.canvas.tostring_argb(), dtype=numpy.uint8 )
+    buf.shape = ( w, h,4 )
+ 
+    # canvas.tostring_argb give pixmap in ARGB mode. Roll the ALPHA channel to have it in RGBA mode
+    buf = numpy.roll ( buf, 3, axis = 2 )
+    return buf
+
+def fig2img ( fig ):
+    import Image
+    import numpy
+    """
+    @brief Convert a Matplotlib figure to a PIL Image in RGBA format and return it
+    @param fig a matplotlib figure
+    @return a Python Imaging Library ( PIL ) image
+    """
+    # put the figure pixmap into a numpy array
+    buf = fig2data ( fig )
+    w, h, d = buf.shape
+    return Image.fromstring( "RGBA", ( w ,h ), buf.tostring( ) )
Index: /trunk/UTIL/PYTHON/myplot.py
===================================================================
--- /trunk/UTIL/PYTHON/myplot.py	(revision 429)
+++ /trunk/UTIL/PYTHON/myplot.py	(revision 430)
@@ -374,5 +374,5 @@
     return
 
-## Author: AS
+## Author: AS + AC
 def dumpbdy (field,n,stag=None):
     nx = len(field[0,:])-1
@@ -380,4 +380,5 @@
     if stag == 'U': nx = nx-1
     if stag == 'V': ny = ny-1
+    if stag == 'W': nx = nx+1 #special les case when we dump stag on W
     return field[n:ny-n,n:nx-n]
 
Index: /trunk/UTIL/PYTHON/planetoplot.py
===================================================================
--- /trunk/UTIL/PYTHON/planetoplot.py	(revision 429)
+++ /trunk/UTIL/PYTHON/planetoplot.py	(revision 430)
@@ -50,5 +50,6 @@
            blat=None,\
            tsat=False,\
-           flagnolow=False):
+           flagnolow=False,\
+           movie_axis=0):
 
 
@@ -63,5 +64,5 @@
                        zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow,\
                        getname,localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar,hole_bounds
-    from mymath import deg,max,min,mean,get_tsat,writeascii
+    from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img
     import matplotlib as mpl
     from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title
@@ -69,4 +70,5 @@
     import numpy as np
     from numpy.core.defchararray import find
+    from videosink import VideoSink
 
     ################################
@@ -281,13 +283,17 @@
               if var2 == 'HGT':  zelevels = np.arange(-10000.,30000.,2000.)
               if mapmode == 0:
+                  if typefile in ['mesoideal']:    what_I_plot = dumpbdy(what_I_plot,0,stag='W')
+                  itime=indextime
+                  if len(what_I_plot.shape) is 3:itime=[0]
                   what_I_plot, x, y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\
-                        indextime,what_I_plot, len(all_var2[index_f].shape),vertmode)
+                        itime,what_I_plot, len(all_var2[index_f].shape),vertmode)
               ### If we plot a 2-D field
               if len(what_I_plot.shape) is 2:
+                  zelevels=[-10.,-8.,-6.,-4.,-2.,0.,2.,4.,6.,8.,10.]
                   cs = contour(x,y,what_I_plot, zelevels, colors='k', linewidths = 1 ) #0.33 colors='w' )# , alpha=0.5)
-#                  clabel(cs,#zelevels[::2],
-#                     inline=3,
-#                     fmt='%1.1e',
-#                     fontsize=7)
+                  clabel(cs,zelevels,
+                     inline=3,
+                     fmt='%1.1f',
+                     fontsize=7)
               ### If we plot a 1-D field
               elif len(what_I_plot.shape) is 1:
@@ -308,6 +314,8 @@
                    if typefile in ['mesoapi','meso']:    what_I_plot = dumpbdy(what_I_plot,6)
                elif mapmode == 0:
+                   itime=indextime
+                   if len(what_I_plot.shape) is 3:itime=[0]
                    what_I_plot, x, y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\
-                         indextime,what_I_plot, len(all_var[index_f].shape),vertmode)
+                         itime,what_I_plot, len(all_var[index_f].shape),vertmode)
                    zxmin, zxmax = xaxis ; zymin, zymax = yaxis
                    if zxmin is not None: mpl.pyplot.xlim(xmin=zxmin)
@@ -322,26 +330,52 @@
                elif (fileref is not None) and (index_f is numplot-1): palette = get_cmap(name="RdBu_r")
                else:                           palette = get_cmap(name=colorb)
-               ##### 2D field
-               if len(what_I_plot.shape) is 2:
-                 if hole: what_I_plot = hole_bounds(what_I_plot,zevmin,zevmax)
-                 else: what_I_plot = bounds(what_I_plot,zevmin,zevmax)
-                 if flagnolow: what_I_plot = nolow(what_I_plot)
-                 if not tile:
-                     #zelevels = np.linspace(zevmin*(1. + 1.e-7),zevmax*(1. - 1.e-7)) #,num=20)
-                     zelevels = np.linspace(zevmin,zevmax,num=ticks)
-                     print np.array(x).shape
-                     print np.array(y).shape
-                     print np.array(what_I_plot).shape
-
-                     if mapmode == 1:       m.contourf( x, y, what_I_plot, zelevels, cmap = palette)
-                     elif mapmode == 0:     contourf( x, y, what_I_plot, zelevels, cmap = palette)
-                 else:
-                     if mapmode == 1:       m.pcolor( x, y, what_I_plot, cmap = palette, vmin=zevmin, vmax=zevmax )
-                     elif mapmode == 0:     pcolor( x, y, what_I_plot, cmap = palette, vmin=zevmin, vmax=zevmax )
-                 if colorb != 'nobar':        
-                     if (fileref is not None) and (index_f is numplot-1):   daformat = "%.3f"
-                     else:                                                  daformat = fmtvar(fvar.upper())
-                     colorbar( fraction=0.05,pad=0.03,format=daformat,\
-                               ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,20])),extend='neither',spacing='proportional' ) 
+               ##### simple 2D field and movies of 2D fields
+               if len(what_I_plot.shape) >= 2:
+                 istart=0
+                 if indextime is None:iend=len(time)-1
+                 else:iend=istart
+                 imov=istart
+
+                 while imov <= iend:
+                    what_I_plot_frame=what_I_plot
+                    if len(what_I_plot.shape) is 3:
+                       what_I_plot_frame=what_I_plot[imov,:,:]
+                       print "-> frame ",imov+1
+                    if hole: what_I_plot_frame = hole_bounds(what_I_plot_frame,zevmin,zevmax)
+                    else: what_I_plot_frame = bounds(what_I_plot_frame,zevmin,zevmax)
+                    if flagnolow: what_I_plot_frame = nolow(what_I_plot_frame)
+                    if not tile:
+                        #zelevels = np.linspace(zevmin*(1. + 1.e-7),zevmax*(1. - 1.e-7)) #,num=20)
+                        zelevels = np.linspace(zevmin,zevmax,num=ticks)
+                        if imov is 0:
+                           print np.array(x).shape
+                           print np.array(y).shape
+                           print np.array(what_I_plot_frame).shape
+   
+                        if mapmode == 1:       m.contourf( x, y, what_I_plot_frame, zelevels, cmap = palette)
+                        elif mapmode == 0:     contourf( x, y, what_I_plot_frame, zelevels, cmap = palette)
+                    else:
+                        if mapmode == 1:       m.pcolor( x, y, what_I_plot_frame, cmap = palette, vmin=zevmin, vmax=zevmax )
+                        elif mapmode == 0:     pcolor( x, y, what_I_plot_frame, cmap = palette, vmin=zevmin, vmax=zevmax )
+                    if colorb != 'nobar':        
+                        if (fileref is not None) and (index_f is numplot-1):   daformat = "%.3f"
+                        else:                                                  daformat = fmtvar(fvar.upper())
+                        colorbar( fraction=0.05,pad=0.03,format=daformat,\
+                                  ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,20])),extend='neither',spacing='proportional' ) 
+                        #mframe=mpl.pyplot.gci().to_rgba(mpl.pyplot.gci().get_array())
+                        #mframe=mpl.pyplot.imshow()
+                        #mframe=fig2data(mpl.pyplot.gcf())
+                        mframe=fig2img(mpl.pyplot.gcf())
+
+                        if ((len(what_I_plot.shape) is 3) and (imov is 0)):
+                            W,H = mpl.pyplot.gcf().canvas.get_width_height()
+                            rate = 10
+                            video = VideoSink((H,W), "test", rate=rate, byteorder="rgba")
+                        if len(what_I_plot.shape) is 3: 
+                            video.run(mframe)
+                            mpl.pyplot.close()
+
+                        imov=imov+1
+                 if len(what_I_plot.shape) is 3: video.close
                ##### 1D field
                elif len(what_I_plot.shape) is 1:
Index: /trunk/UTIL/PYTHON/videosink.py
===================================================================
--- /trunk/UTIL/PYTHON/videosink.py	(revision 430)
+++ /trunk/UTIL/PYTHON/videosink.py	(revision 430)
@@ -0,0 +1,21 @@
+import numpy as np
+import subprocess
+
+class VideoSink(object) :
+
+    def __init__( self, size, filename="output", rate=10, byteorder="bgra") :
+            self.size = size
+            cmdstring  = ('mencoder',
+                    '/dev/stdin',
+                    '-demuxer', 'rawvideo',
+                    '-rawvideo', 'w=%i:h=%i'%size[::-1]+":fps=%i:format=%s"%(rate,byteorder),
+                    '-o', filename+'.avi',
+                    '-ovc', 'lavc',
+                    )
+            self.p = subprocess.Popen(cmdstring, stdin=subprocess.PIPE, shell=False)
+
+    def run(self, image) :
+            #assert image.shape[0:2] == self.size
+            self.p.stdin.write(image.tostring())
+    def close(self) :
+            self.p.stdin.close()
