Index: trunk/tools/model_graphics.bash
===================================================================
--- trunk/tools/model_graphics.bash	(revision 922)
+++ trunk/tools/model_graphics.bash	(revision 923)
@@ -79,4 +79,54 @@
     exit
   fi
+}
+
+function variable_compute(){
+# Function to retrieve the computation way of a given variable using a series of 
+#   test files
+#   iwdir= directory with the test files
+#   var= name of the variable to test
+#   filtests= '@' separated list of '[head]|[file] test files
+  fname='variable_compute'
+
+  iwdir=$1
+  var=$2
+  filtests=$3
+
+  ftsts=`echo ${filtests} |tr '@' ' '`
+  cancompute=true
+
+  for ftest in ${ftsts}; do
+    headerf=`echo ${ftest} | tr '|' ' ' | awk '{print $1}'`
+    filen=`echo ${ftest} | tr '|' ' ' | awk '{print $2}'`
+    compute=`${pyHOME}/nc_var.py -o computevar_model -f ${iwdir}/${filen} -S ${var}`
+    ferrmsg $? ${main} "python!'computevar_model'!failed!#"$(echo ${compute} |       \
+      tr ' ' '!')
+    varmod=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' |           \
+      tr '@' ' ' | awk '{print $2}' | tr '=' ' ' | awk '{print $2}'`
+    vardiag=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' |          \
+      tr '@' ' ' | awk '{print $3}' | tr '=' ' ' | awk '{print $2}'`
+    echo "  "${var}" mod:"${varmod}" diag: "${vardiag}
+    if test ${varmod} = 'None' && test ${vardiag} = 'None'; then 
+      cancompute=false
+    else
+      cancompute=true
+    # Should be considered that variable can also be computed by both ways?
+      break
+    fi
+  done
+  if ! ${cancompute}; then
+    msg="there!is!no!way!to!compute!'"${var}"'!for!model!"${mod}
+# Too extrict!
+#    ferrmsg 1 ${main} ${msg}
+    echo ${warnmsg}
+    echo $(echo $msg | tr '!' ' ')
+  fi
+
+  # a ';' list 'varcompute' it is created for each variable giving:
+  #   [var]|[vark]|[headerf][varmod]|[vardiag]
+  # This list will be used to compute a new file for each variable
+  varcomp=${var}'|'${vark}'|'${headerf}'|'${varmod}'|'${vardiag}
+
+  echo "varcomp= "${varcomp}
 }
 
@@ -182,4 +232,6 @@
 #        diff: differences between models
 #        direct: no statistics
+#        last: last temporal value
+#        Lmean: latitudinal mean values
 #        Lsec: latitudinal section (latitudinal value must be given, [var]@[lat]) 
 #        lsec: longitudinal section (longitudinal value must be given, [var]@[lat])
@@ -187,4 +239,7 @@
 #        pinterp: pressure interpolation (to the given $plevels)
 #        tmean: temporal mean values
+#        tmean: temporal mean values
+#        xmean: x-axis mean values
+#        ymean: y-axis mean values
 #        zsum: vertical aggregated values
 #     [headerf]: header of the files to use
@@ -335,4 +390,5 @@
 #        diff: differences between models
 #        direct: no statistics
+#        last: last temporal value
 #        Lmean: latitudinal mean values
 #        Lsec: latitudinal section (latitudinal value must be given, [var]@[lat]) 
@@ -360,4 +416,12 @@
   scratch=$7
 
+  # Getting a previous file name to continue with(for combinations)
+  if test $# -eq 8; then
+    echo ${warnmsg}
+    echo "  "${fname}": using a previous file '"$8"' to continue with!!"
+    prevfile=$8
+    usefiles=$8
+  fi
+
   CFvarn=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'`
   vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'`
@@ -377,10 +441,16 @@
   cd ${odir}
 
-  if test ${vark} == 'pinterp'; then
-    fhead=${headerf}p
+  if test $# -ne 8; then
+    if test ${vark} == 'pinterp'; then
+      fhead=${headerf}p
+    else
+      fhead=${headerf}
+    fi
+    filen=${CFvarn}_${fhead}_${vark}.nc
   else
-    fhead=${headerf}
+    Lprevfile=`expr length ${prevfile}`
+    Lprevfile3=`expr ${Lprevfile} - 3`
+    filen=${prevfile:0:$Lprevfile3}_${vark}.nc
   fi
-  filen=${CFvarn}_${fhead}_${vark}.nc
   if ${scratch}; then rm ${filen} >& /dev/null; fi
 
@@ -401,4 +471,16 @@
       'direct')
         cp ${cfiles} ${filen}
+      ;;
+      # last temporal value
+      'last')
+        Lcfiles=`expr length ${cfiles}`
+        Lcfiles3=`expr ${Lcfiles} - 3`
+        vals='time,-9,0,0'
+        pyout=`python ${pyHOME}/nc_var.py -o DataSetSection -S ${vals} -f ${cfiles}  \
+          -v ${CFvarn}`
+        pyn=$?
+        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
+        ferrmsg ${pyn} ${fname} "python!'DataSetSection'!'last'!failed#"${Spyout}
+        mv ${cfiles:0:${Lcfiles3}}_time_B-9-E0-I0.nc ${filen}
       ;;
       # latitudinal mean values
@@ -490,6 +572,4 @@
 
   cleaning_varsfile ${filen} ${CFvarn}':lon:lat:pres:time'${varkeep}
-#  exit
-# LLUIS
 }
 
@@ -624,4 +704,5 @@
 # Kind variables loop
 ##
+      combo=false
       ik=1
       itotv=1
@@ -632,4 +713,20 @@
             varvks=${varacc}
           ;;
+          'combo')
+            combo=true
+            varvcombo=${varcombo}
+            varcos=`echo ${varvcombo} | tr ':' ' '`
+            varvks=''
+            ivco=1
+            for vco in ${varcos}; do
+              vn=`echo ${vco} | tr '@' ' ' | awk '{print $1}'`
+              if test ${ivco} -eq 1; then
+                varvks=${vco}
+              else
+                varvks=${varvks}':'${vco}
+              fi
+              ivco=`expr ${ivco} + 1`
+            done
+          ;;
           'diff')
             varvks=${vardiff}
@@ -637,4 +734,7 @@
           'direct')
             varvks=${vardirect}
+          ;;
+          'last')
+            varvks=${varlast}
           ;;
           'Lmean')
@@ -690,38 +790,8 @@
         for var in ${vars}; do
           echo "      "${var}
-          # How to copmute it?
-          cancompute=true
-          for ftest in ${testfs}; do
-            headerf=`echo ${ftest} | tr '|' ' ' | awk '{print $1}'`
-            filen=`echo ${ftest} | tr '|' ' ' | awk '{print $2}'`
-            compute=`${pyHOME}/nc_var.py -o computevar_model -f ${iwdir}/${filen}      \
-              -S ${var}`
-            ferrmsg $? ${main} "python!'computevar_model'!failed!#"$(echo ${compute} | \
-               tr ' ' '!')
-            varmod=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' |   \
-               tr '@' ' ' | awk '{print $2}' | tr '=' ' ' | awk '{print $2}'`
-            vardiag=`echo ${compute} | tr ' ' '#' | tr '|' ' ' | awk '{print $2}' |  \
-               tr '@' ' ' | awk '{print $3}' | tr '=' ' ' | awk '{print $2}'`
-            echo "  "${var}" mod:"${varmod}" diag: "${vardiag}
-            if test ${varmod} = 'None' && test ${vardiag} = 'None'; then 
-              cancompute=false
-            else
-              cancompute=true
-              # Should be considered that variable can also be computed by both ways?
-              break
-            fi
-          done
-          if ! ${cancompute}; then
-            msg="there!is!no!way!to!compute!'"${var}"'!for!model!"${mod}
-# Too extrict!
-#            ferrmsg 1 ${main} ${msg}
-            echo ${warnmsg}
-            echo $(echo $msg | tr '!' ' ')
-          fi
-
-          # A ';' list 'varcompute' it is created for each variable giving:
-          #   [var]|[vark]|[headerf][varmod]|[vardiag]
-          # This list will be used to compute a new file for each variable
-          varcomp=${var}'|'${vark}'|'${headerf}'|'${varmod}'|'${vardiag}
+          # How to compute it?
+          varcomp=`variable_compute ${iwdir} ${var} ${testfiles} | grep varcomp |    \
+            awk '{print $2}'`
+
           if test ${itotv} -eq 1; then
             varcompute=${varcomp}
@@ -743,4 +813,5 @@
 varcompute: ${varcompute}
 itotv: ${itotv}
+testfs: ${testfiles}
 EOF
     else
@@ -750,4 +821,5 @@
       varcompute=`cat ${owdir}/varcompute.inf | grep varcompute | awk '{print $2}'`
       itotv=`cat ${owdir}/varcompute.inf | grep itotv | awk '{print $2}'`
+      testfiles=`cat ${owdir}/varcompute.inf | grep testfs | awk '{print $2}'`
 # End of avoiding to repeat all the experiment search
     fi
@@ -774,5 +846,5 @@
         ic=`expr ${ic} + 1`
 
-        if test ! ${vark} = 'diff'; then
+        if test ! ${vark} = 'diff' && test ! ${vark} = 'combo'; then
           if test ${vark} = 'pinterp'; then
             fhead=${fileh}'p'
@@ -784,6 +856,11 @@
           isc=`expr ${isc} + 1`
         else
-          echo "  "${main}": differences will be calculated when all the " \
-            "model/experiments will be done !"
+          if test ${vark} = 'diff'; then
+            echo "  "${main}": differences will be calculated when all the "         \
+              "model/experiments will be done !"
+          elif test ${vark} = 'diff'; then
+            echo "  "${main}": combos will be calculated later when all the "        \
+              "variables will be done !"
+          fi
         fi
       else
@@ -794,4 +871,35 @@
 # end of computing vars
     done
+
+    # Computing combos
+    if ${combo}; then
+      echo "      Computing combos: "${varcombo}
+      varcos=`echo ${varcombo} | tr ':' ' '`
+      for vco in ${varcos}; do
+        echo "        "${vco}
+        CFvarn=`echo ${vco} | tr ';' ' ' | awk '{print $1}'`
+        cvar=`variable_compute ${iwdir} ${CFvarn} ${testfiles} | grep varcomp |      \
+          awk '{print $2}'`
+        CFv=`echo ${cvar} | tr '|' ' ' | awk '{print $1}'`
+        vark=`echo ${cvar} | tr '|' ' ' | awk '{print $2}'`
+        fileh=`echo ${cvar} | tr '|' ' ' | awk '{print $3}'`
+        modv=`echo ${cvar} | tr '|' ' ' | awk '{print $4}'`
+        diagv=`echo ${cvar} | tr '|' ' ' | awk '{print $5}'`
+
+        combs=`echo ${vco} | tr ';' ' ' | awk '{print $2}' | tr '@' ' '`
+        ifile=${CFv}_${fhead}
+        for comb in ${combs}; do
+          combcvar=${CFv}'|'${comb}'|'${fileh}'|'${modv}'|'${diagv}
+          compute_statistics ${iwdir} ${ifile}.nc ${owdir} ${combcvar} ${moddims}    \
+            ${modvdims} ${scratch} ${ifile}.nc
+          ifile=${ifile}_${comb}
+          isc=`expr ${isc} + 1`
+        # End of combo 
+        done
+      # End of combo variables
+      done
+    fi
+# LLUIS
+
     echo "  "${main}": "${ic}" variables has been computed"
     echo "  "${main}": "${isc}" statistics has been computed"
@@ -1019,5 +1127,5 @@
           fi
         fi
-        echo "HereLluis"${var}
+
 # Time means
         if $(isin_list ${var2Dtmeans} ${var}); then 
Index: trunk/tools/model_graphics_template.dat
===================================================================
--- trunk/tools/model_graphics_template.dat	(revision 922)
+++ trunk/tools/model_graphics_template.dat	(revision 923)
@@ -49,8 +49,9 @@
 LMDZheaders = histins
 
-# Kind of calculations (adding the euiqvalent `surname' to each variable)
+# Kind of calculations (adding the equivalent `surname' to each variable)
 #   acc: temporal accumulated values
 #   diff: differences between models
 #   direct: no statistics
+#   last: last temporal value
 #   Lmean: latitudinal mean values
 #   Lsec: latitudinal section (latitudinal value must be given, [var]@[lat]) 
@@ -62,9 +63,10 @@
 #   ymean: y-axis mean values
 #   zsum: vertical aggregated values
-varkinds = direct:tmean:xmean:diff:pinterp
+varkinds = direct:tmean:xmean:diff:pinterp:combo
 
 # variables (providing CF-name, script must provide equivalent variable for each model)
 #   in foudre values from: ${HOME}/UNSW-CCRC-WRF/tools/postprocess/GMS-UC/WRF4G/util/postprocess/wrfncxnj/wrfncxnj.table
 #   must exist on the table $pyHOME/variables_values.dat
+#   varcombo = [varn];[vark1]@...@[varkN]: variable as consecutive kinds of operation
 vardirect = tas:uas:vas:ps:pr:pracc:rsds:prw:evspsbl:hfss:hfls:hurs:huss:zmla:hufs:wakes:lwakeh:stherm:zmaxth:clt:cll:clm:clh:prc:prls:bils
 vartmean = prc:prls:zmla:hfss:hfls:evspsbl:bils:uas:vas:tas:ps:clt:cll:clm:clh:prw:huss:pr:wakes:wakeh:stherm:zmaxth
@@ -72,4 +74,5 @@
 vardiff = ualmean:valmean:talmean:huslmean:uas:vas:ps:pr
 varpinterp = ta:ua:va:hur
+varcombo = ta;pinterp@last@xmean:ua;pinterp@last@xmean:va;pinterp@last@xmean:hur;pinterp@last@xmean
 
 # Pressure levels
@@ -83,7 +86,7 @@
 #   map3D: 2D map of 3D values of 1 variable
 #   shadcount2D: 2D map of shadow (1st variable) and countour (2nd variable) [var1]@[var2] (no `surname' = 'direct')
-shadcount2D = huslmean@talmean:valmean@ualmean:tas@ps:uas@vas:pr@rsds:prw@huss:prls@prc:hfls@hfss:evspsbl@bils:zmaxth@stherm:wakeh@wakes:zmaxth@stherm:prls@prc:clt@cll:clh@clm
+shadcount2D = husxmean@taxmean:vaxmean@uaxmean:tas@ps:uas@vas:pr@rsds:prw@huss:prls@prc:hfls@hfss:evspsbl@bils:zmaxth@stherm:wakeh@wakes:zmaxth@stherm:prls@prc:clt@cll:clh@clm
 diffmap2Dsfc = uas:vas:ps:pr
-diffmap2Dz = ualmean:valmean:talmean:huslmean
+diffmap2Dz = uapxmean:vapxmean:tapxmean:huspxmean
 
 # Figures output 
