Index: trunk/UTIL/PYTHON/mcs.py
===================================================================
--- trunk/UTIL/PYTHON/mcs.py	(revision 409)
+++ trunk/UTIL/PYTHON/mcs.py	(revision 417)
@@ -16,5 +16,5 @@
    from optparse import OptionParser    ### to be replaced by argparse
    from netCDF4 import Dataset
-   from os import system
+   from os import system,path
    from times import sol2ls
    import numpy as np
@@ -30,4 +30,7 @@
    parser.add_option('-m', '--mfile',  action='store',dest='mcsfile',     type="string",  default=None,  help='[NEEDED] filename for MCS comparison.')
    parser.add_option('-v', '--var',    action='append',dest='var',      type="string",  default=None,  help='[NEEDED] Variables to process. (coma-separated list. aps and bps are always included.)')
+   parser.add_option('-x', action='store_true',dest='recast',     default=False,  help='Force aps and bps to be ommited in output file (usefull if your file is already recasted along z) [False]')
+   parser.add_option('-i', '--zrecast', action='store_true', dest='zrecast', default=False, help='Cast zrecast.e on diagfi file with MCS pressure levels. Will pass this operation is recasted file is already present, unless --override is specified. [False]')
+   parser.add_option('--override', action='store_true', dest='override', default=False, help='Force zrecast.e to act even if recasted file is already present(will erase previous recasted file) [False]')
 
    #############################
@@ -38,7 +41,29 @@
    ### Load and check data
 
+   if opt.var is None:
+      print "You must specify at least a field to process with -v."
+      exit()
+
+   # Zrecast
+
+   varznames=separatenames(opt.var[0])
+
+   if opt.zrecast:
+      if (path.exists(opt.file[0:len(opt.file)-3]+"_P.nc") and (not opt.override)):
+         print "--> "+opt.file[0:len(opt.file)-3]+"_P.nc"
+         print "Recasted file is already there, skipping interpolation. [use --override to force interpolation]"
+         filename=opt.file[0:len(opt.file)-3]+"_P.nc"
+      else:
+         print "--> "+opt.file[0:len(opt.file)-3]+"_P.nc"
+         filename=call_zrecast (  interp_mode   = 2, \
+                    input_name      = [opt.file], \
+                    fields  = varznames, \
+                    predifined = 'mcs')[0]
+
    # Files
 
-   nc=Dataset(opt.file)
+   print "--> Loading diagfi dataset."
+
+   nc=Dataset(filename)
    ncmcs=Dataset(opt.mcsfile)
 
@@ -49,6 +74,16 @@
    alt=nc.variables["altitude"][:]
    time=nc.variables["Time"][:] # in fraction of sols
-   controle=nc.variables["controle"][:]
-   day_ini=controle[3]%669
+   if "controle" in nc.variables:
+      controle=nc.variables["controle"][:]
+      day_ini=controle[3]%669
+   else:
+      if opt.zrecast:
+         nccontrol=Dataset(opt.file)
+         if "controle" in nccontrol.variables:
+            controle=nccontrol.variables["controle"][:]
+            day_ini=controle[3]%669
+         else:
+            print "Error: could not find controle variable in diagfi."
+            day_ini=input("Please type initial sol number:")%669
    time[:]=time[:]+day_ini
    nx=len(lon)
@@ -59,4 +94,6 @@
 
    # MCS
+
+   print "--> Loading and preparing MCS dataset."
 
    dtimemintmp=ncmcs.variables["dtimemin"][:,:,:]
@@ -79,9 +116,15 @@
    # Variables to treat
 
+   print "--> Preparing diagfi dataset."
+
    varz=[]
-   varznames=separatenames(opt.var[0])
    n=0
    for zn in varznames:
-       varz.append(getfield(nc,zn))
+       load=getfield(nc,zn)
+       if opt.zrecast:
+          load=np.ma.masked_where(load < -1.e-30,load)
+          load.set_fill_value([np.NaN])
+          load=load.filled()
+       varz.append(load)
        print "Found: "+zn+" with dimensions: "
        print np.array(varz[n]).shape
@@ -109,5 +152,6 @@
        fullnames.append("n"+name)
    print "Will output: "
-   print fullnames
+   if opt.recast: print fullnames[2:]
+   else: print fullnames
    #############################
    ### Building
@@ -234,4 +278,8 @@
           all.append(varnightout[vv,:,:,:,:].filled())
 
+   if opt.recast:
+      all=all[2:]
+      fullnames=fullnames[2:] 
+
    make_gcm_netcdf (zfilename="diagfi_MCS.nc", \
                         zdescription="Temperatures from diagfi reworked to match MCS format", \
Index: trunk/UTIL/PYTHON/zrecast_wrapper.py
===================================================================
--- trunk/UTIL/PYTHON/zrecast_wrapper.py	(revision 409)
+++ trunk/UTIL/PYTHON/zrecast_wrapper.py	(revision 417)
@@ -11,40 +11,47 @@
     from os import system
     pressure_axis_tes=[1658.152,1291.37,1005.72,783.2555,610.,475.0685,369.9837,288.1436,224.4065,174.7679,136.1094,106.0021,82.55452,64.29353,50.07185,38.99599,30.37011,23.65227,18.4204,14.34583,11.17254]
-    pressure_axis_mcs=[1878.9, 1658.2, 1463.3, 1291.4, 1139.6, 1005.7, 887.54, 783.26,691.22, 610, 538.32, 475.07, 419.25, 369.98, 326.51, 288.14, 254.29,224.41, 198.04, 174.77, 154.23, 136.11, 120.12, 106, 93.547, 82.555,72.854, 64.294, 56.739, 50.072, 44.188, 38.996, 34.414, 30.37, 26.802,23.652, 20.873, 18.42, 16.256, 14.346, 12.66, 11.173, 9.8597, 8.7012,7.6788, 6.7765, 5.9802, 5.2775, 4.6574, 4.1101, 3.6272, 3.201, 2.8249,2.4929, 2.2, 1.9415, 1.7134, 1.512, 1.3344, 1.1776, 1.0392, 0.9171,0.80934, 0.71424, 0.63031, 0.55625, 0.49089, 0.43321, 0.3823, 0.33738,0.29774, 0.26275, 0.23188, 0.20463, 0.18059, 0.15937, 0.14064, 0.12412,0.10953, 0.096661, 0.085303, 0.07528, 0.066434, 0.058628, 0.051739,0.04566, 0.040294, 0.03556, 0.031381, 0.027694, 0.02444, 0.021568,0.019034, 0.016797, 0.014824, 0.013082, 0.011545, 0.010188, 0.0089909,0.0079345, 0.0070021, 0.0061794, 0.0054533, 0.0048125, 0.004247]
+    pressure_axis_mcs=[1878.9, 1658.2, 1463.3, 1291.4, 1139.6, 1005.7, 887.54, 783.26,691.22, 610., 538.32, 475.07, 419.25, 369.98, 326.51, 288.14, 254.29,224.41, 198.04, 174.77, 154.23, 136.11, 120.12, 106., 93.547, 82.555,72.854, 64.294, 56.739, 50.072, 44.188, 38.996, 34.414, 30.37, 26.802,23.652, 20.873, 18.42, 16.256, 14.346, 12.66, 11.173, 9.8597, 8.7012,7.6788, 6.7765, 5.9802, 5.2775, 4.6574, 4.1101, 3.6272, 3.201, 2.8249,2.4929, 2.2, 1.9415, 1.7134, 1.512, 1.3344, 1.1776, 1.0392, 0.9171,0.80934, 0.71424, 0.63031, 0.55625, 0.49089, 0.43321, 0.3823, 0.33738,0.29774, 0.26275, 0.23188, 0.20463, 0.18059, 0.15937, 0.14064, 0.12412,0.10953, 0.096661, 0.085303, 0.07528, 0.066434, 0.058628, 0.051739,0.04566, 0.040294, 0.03556, 0.031381, 0.027694, 0.02444, 0.021568,0.019034, 0.016797, 0.014824, 0.013082, 0.011545, 0.010188, 0.0089909,0.0079345, 0.0070021, 0.0061794, 0.0054533, 0.0048125, 0.004247]
     system("rm -f zrecast.auto.def")
     system("touch zrecast.auto.def")
     indicefile=0
     outputfilename=""
+    f = open('zrecast.auto.def', 'w')
     for zfile in input_name:
-        system("echo "+zfile+" >> zrecast.auto.def")
+        f.write(zfile+"\n")
         for zvar in fields:
-            system("echo "+zvar+" >> zrecast.auto.def")
-        system("echo >> zrecast.auto.def")
+             f.write(zvar+"\n")
+        f.write("\n")
         if interp_mode == 4:
              append="_S"
-             system("echo 3 >> zrecast.auto.def")
-             system("echo yes >> zrecast.auto.def")
-             system("echo 0 150000 >> zrecast.auto.def")
+             f.write("3"+"\n")
+             f.write("yes"+"\n")
+             f.write("0 150000"+"\n")
         elif interp_mode == 2:
              append="_P"
-             if predifined is "TES":
-                system("echo 1 >> zrecast.auto.def")
-                system("echo no >> zrecast.auto.def")
-                system("echo "+len(pressure_axis_tes)+" >> zrecast.auto.def")
+             if predifined in ["TES","tes"]:
+                print "Using TES pressure levels"
+                f.write("1"+"\n")
+                f.write("no"+"\n")
+                f.write(str(len(pressure_axis_tes))+"\n")
                 for zp in pressure_axis_tes:
-                   system("echo "+zp+" >> zrecast.auto.def")
-             elif predifined is "MCS":
-                system("echo no >> zrecast.auto.def")
-                system("echo "+len(pressure_axis_mcs)+" >> zrecast.auto.def")
+                    f.write(str(zp)+"\n")
+                f.write("\n")
+             elif predifined in ["MCS","mcs"]:
+                print "Using MCS pressure levels"
+                f.write("1"+"\n")
+                f.write("no"+"\n")
+                f.write(str(len(pressure_axis_mcs))+"\n")
                 for zp in pressure_axis_mcs:
-                   system("echo "+zp+" >> zrecast.auto.def")
+                    f.write(str(zp)+"\n")
+                f.write("\n")
              else:
-                system("echo 1 >> zrecast.auto.def")
-                system("echo yes >> zrecast.auto.def")
-                system("echo 370 0.1 >> zrecast.auto.def")  #I put that randomly! (a.c.)
-                system("echo 20 >> zrecast.auto.def")
+                f.write("1"+"\n")
+                f.write("yes"+"\n")
+                f.write("370 0.1"+"\n")
+                f.write("20"+"\n")
         else:
              print "zrecast interp option unsupported for now. Exiting."
              exit()
+        f.close()
         system("zrecast.e < zrecast.auto.def")
 
