Index: /trunk/tools/model_graphics.bash
===================================================================
--- /trunk/tools/model_graphics.bash	(revision 970)
+++ /trunk/tools/model_graphics.bash	(revision 971)
@@ -6,4 +6,56 @@
 # All purpouse
 ######## ###### ##### #### ### ## #
+
+function list_pairs() {
+# Function to provide two lists from one in order to obtain all the possibles pairs
+#   listv= ':' separated list of values to construct de couples
+#    $ list_pairs 1:2:3:4:5:6:7:8:9
+#      list_pairs: newlists= 1|2|3|4|5|6|7|8|:2|3|4|5|6|7|8|9|
+#     list_pairs: pairs= 1|2:1|3:1|4:1|5:1|6:1|7:1|8:1|9:2|3:2|4:2|5:2|6:2|7:2|8:2|9:3|4:3|5:3|6:3|7:3|8:3|9:4|5:4|6:4|7:4|8:4|9:5|6:5|7:5|8:5|9:6|7:6|8:6|9:7|8:7|9:8|9
+
+  fname='list_pairs'
+
+  listv=$1
+
+  lv=`echo ${listv} | tr ':' ' '`
+  Nlv=`echo ${listv} | tr ':' ' ' | wc -w | awk '{print $1}'`
+
+  if test ${Nlv} -lt 2; then
+    echo ${errormsg}
+    echo "  "${fname}": too few values from list, at least 2 are required!"
+    echo "    provided list: "${listv}
+    exit
+  fi
+
+  Nlv_1=`expr ${Nlv} - 1`
+
+  newlist1=`echo ${listv} | tr ':' '\n' | head -n ${Nlv_1} | tr '\n' '|'`
+  newlist2=`echo ${listv} | tr ':' '\n' | tail -n ${Nlv_1} | tr '\n' '|'`
+
+  pairs=''
+  ipair=1
+  il1=1
+  while test ${il1} -le ${Nlv_1}; do
+    lv1=`echo ${listv} | tr ':' '\n' | head -n ${il1} | tail -n 1`
+    il2=`expr ${il1} + 1`
+    while test ${il2} -le ${Nlv}; do
+      lv2=`echo ${listv} | tr ':' '\n' | head -n ${il2} | tail -n 1`
+      if test ${ipair} -eq 1; then
+        pairs=${lv1}'|'${lv2}
+      else
+        pairs=${pairs}':'${lv1}'|'${lv2}
+      fi
+
+      ipair=`expr ${ipair} + 1`
+      il2=`expr ${il2} + 1`
+    done
+
+    il1=`expr ${il1} + 1`
+  done
+
+  echo "  "${fname}": newlists= "${newlist1}':'${newlist2}
+  echo "  "${fname}": pairs= "${pairs}
+
+}
 
 function uploadvars() {
@@ -1311,101 +1363,100 @@
       itotv=1
       for vark in ${varks}; do
-        echo "    "${vark}" ..."
-        case ${vark} in
-          'acc')
-            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}
-          ;;
-          'direct')
-            varvks=${vardirect}
-          ;;
-          'last')
-            varvks=${varlast}
-          ;;
-          'Lmean')
-            varvks=${varLmean}
-          ;;
-          'Lsec')
-            varvks=${varLsec}
-          ;;
-          'lmean')
-            varvks=${varlmean}
-          ;;
-          'lsec')
-            varvks=${varlsec}
-          ;;
-          'pinterp')
-            varvks=${varpinterp}
-          ;;
-          'tmean')
-            varvks=${vartmean}
-          ;;
-          'xmean')
-            varvks=${varxmean}
-          ;;
-          'ymean')
-            varvks=${varymean}
-          ;;
-          'zsum')
-            varvks=${varzsum}
-          ;;
-          '*')
-            echo ${errmsg}
-            echo "  "${main}": variable kind '"${vark}"' not ready!!"
-            exit
-          ;;
-        esac
+        if test ! ${vark} = 'diff'; then
+          echo "    "${vark}" ..."
+          case ${vark} in
+            'acc')
+              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
+            ;;
+            'direct')
+              varvks=${vardirect}
+            ;;
+            'last')
+              varvks=${varlast}
+            ;;
+            'Lmean')
+              varvks=${varLmean}
+            ;;
+            'Lsec')
+              varvks=${varLsec}
+            ;;
+            'lmean')
+              varvks=${varlmean}
+            ;;
+            'lsec')
+              varvks=${varlsec}
+            ;;
+            'pinterp')
+              varvks=${varpinterp}
+            ;;
+            'tmean')
+              varvks=${vartmean}
+            ;;
+            'xmean')
+              varvks=${varxmean}
+            ;;
+            'ymean')
+              varvks=${varymean}
+            ;;
+            'zsum')
+              varvks=${varzsum}
+            ;;
+            '*')
+              echo ${errmsg}
+              echo "  "${main}": variable kind '"${vark}"' not ready!!"
+              exit
+            ;;
+          esac
 
 # Do we have variables for this kind?
-        Lvarvks=`expr length ${varvks}'0'`
-        if test ${Lvarvks} -lt 2; then
-          ferrmsg 1 ${main} "variable!kind!"${vark}"!without!variables"
-        fi
-        if test ${ik} -eq 1; then
-          allvars=${varvks}
-        else
-          allvars=${allvars}':'${varvks}
-        fi
-        ik=`expr ${ik} + 1`
-        vars=`echo ${varvks} | tr ':' ' '`
+          Lvarvks=`expr length ${varvks}'0'`
+          if test ${Lvarvks} -lt 2; then
+            ferrmsg 1 ${main} "variable!kind!"${vark}"!without!variables"
+          fi
+          if test ${ik} -eq 1; then
+            allvars=${varvks}
+          else
+            allvars=${allvars}':'${varvks}
+          fi
+          ik=`expr ${ik} + 1`
+          vars=`echo ${varvks} | tr ':' ' '`
 
 # Variables loop
 ##
-        iv=1
-        for var in ${vars}; do
-          echo "      "${var}
-          # How to compute it?
-          varcomp=`variable_compute ${iwdir} ${var} ${testfiles} | grep varcomp |    \
-            awk '{print $2}'`
-
-          if test ${itotv} -eq 1; then
-            varcompute=${varcomp}
-          else
-            varcompute=${varcompute}';'${varcomp}
-          fi
-
-          iv=`expr ${iv} + 1`
-          itotv=`expr ${itotv} + 1`
+          iv=1
+          for var in ${vars}; do
+            echo "      "${var}
+            # How to compute it?
+            varcomp=`variable_compute ${iwdir} ${var} ${testfiles} | grep varcomp |  \
+              awk '{print $2}'`
+  
+            if test ${itotv} -eq 1; then
+              varcompute=${varcomp}
+            else
+              varcompute=${varcompute}';'${varcomp}
+            fi
+
+            iv=`expr ${iv} + 1`
+            itotv=`expr ${itotv} + 1`
 
 # end loop of variables
-        done
+          done
+        fi
 # end of kind of variables
       done
@@ -1594,9 +1645,77 @@
 
     echo "  "${main}": "${idp}" direct plots hav been computed"
-# LLUIS
     cd ${rootsh}
-    exit
+
 # end of experiments
   done
+
+# Experiment differences
+## 
+  diffexperiments=`list_pairs $(echo ${exps} | tr ' ' ':') | grep -v newlists | awk '{print $3}'`
+  diffexps=`echo ${diffexperiments} | tr ':' ' '`
+
+  set -x
+
+  vdiffs=`echo ${vardiff} | tr ':' ' '`
+  ivd=1
+  for vdiff in ${vdiffs}; do
+    echo ${vdiff}" ..."
+    if test $(expr index ${vdiff} '|') -ne -1; then
+      vn=`echo ${vdiff} | tr '|' ' ' | awk '{print $1}'`
+      ops=`echo ${vdiff} | tr '|' ' ' | awk '{print $2}'`
+    else
+      vn=`echo ${vdiff} | tr '|' ' ' | awk '{print $1}'`
+      ops='None'
+    fi  
+    fileh=`echo ${varcompute} | tr ';' '\n' | grep ${vdiff} | tr '|' ' ' | awk '{print $3}'`
+
+    filen=`stats_filename ${vn} ${ops} ${fileh}`
+    opss=`echo ${ops} | tr '@' ' '`
+    for op in ${opss}; do
+      # Adding 'surnames' to the variable's name
+      if test ${op} = 'turb'; then
+        vn=${vn}'turb'
+      fi
+      if $(isInlist ${varmeanname} ${op}); then
+        vn=${vn}'mean'
+      fi
+    done
+
+    for diffexp in ${diffexps}; do
+      echo "  "${diffexp}
+      difexp1=`echo ${diffexp} | tr '|' ' ' | awk '{print $1}'`
+      difexp2=`echo ${diffexp} | tr '|' ' ' | awk '{print $2}'`
+
+      owdir=${ofold}/${mod}/${difexp1}-${difexp2}
+      if test ${ivd} -eq 1; then
+        mkdir -p ${owdir}
+      fi
+
+      if ${filescratch}; then rm ${owdir}/${filen} >& /dev/null; fi
+      if test ! -f ${owdir}/${filen}; then
+        dfile1=${ofold}/${mod}/${difexp1}/${filen}
+        dfile2=${ofold}/${mod}/${difexp2}/${filen}
+
+        dfiles='add|'${dfile1}'|'${vn}',sub|'${dfile2}'|'${vn}
+        dims='time|pres|lat|lon@'${dfiles}
+        echo "python ${pyHOME}/nc_var.py -S ${dims} -o compute_opersvarsfiles -v ${vn}"
+        pyout=`python ${pyHOME}/nc_var.py -S ${dims} -o compute_opersvarsfiles -v ${vn}`
+        pyn=$?
+        Spyout=`echo ${pyout} | tr '\n' '#' | tr ' ' '!'`
+        ferrmsg ${pyn} ${fname} "python!'difference'!failed"${Spyout}
+
+        mv opersvarsfiles_${vn}.nc ${owdir}/${filen}
+      fi
+
+    # end experiment pairs
+    done
+# LLUIS
+
+    ivd=`expr ${ivd} + 1`
+  # end of variable diff
+  done
+
+  exit
+
 # end of models
 done
Index: /trunk/tools/model_graphics_template.dat
===================================================================
--- /trunk/tools/model_graphics_template.dat	(revision 970)
+++ /trunk/tools/model_graphics_template.dat	(revision 971)
@@ -28,8 +28,8 @@
 
 # Have new files been added and do they need to be processed?
-addfiles = true
+addfiles = false
 
 # Have new figures been added and do they need to be drawn?
-addfigures = true
+addfigures = false
 
 # Debug
@@ -76,5 +76,5 @@
 #   ymean: y-axis mean values
 #   zsum: vertical aggregated values
-varkinds = last:tmean:xmean:diff:pinterp:combo
+varkinds = last:tmean:xmean:pinterp:diff:combo
 
 # variables (providing CF-name, script must provide equivalent variable for each model)
@@ -82,9 +82,16 @@
 #   must exist on the table $pyHOME/variables_values.dat
 #   varcombo = [varn];[vark1]@...@[varkN]: variable as consecutive kinds of operation
-varlast = 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:wss
-vartmean = 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:wss
-varxmean = ta:ua:va:hur:hurs:tas:wss:ps
-vardiff = ualmean:valmean:talmean:huslmean:uas:vas:ps:pr
+#varlast = 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:wss
+#vartmean = 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:wss
+#varxmean = ta:ua:va:hur:hurs:tas:wss:ps
+#vardiff = tas|last:tas|xmean:tas|tmean
+#varpinterp = ta:ua:va:hur:ws:hus
+#varcombo = ta;pinterp@last@xmean:ua;pinterp@last@xmean:va;pinterp@last@xmean:hur;pinterp@last@xmean:ws;pinterp@turb@xmean:hus;pinterp@turb@xmean
+
+varlast = tas:uas:vas:hfss:hfls:wss
+vartmean = tas:uas:vas:hfss:hfls:wss
+varxmean = tas:uas:vas:hfss:hfls:wss
 varpinterp = ta:ua:va:hur:ws:hus
+vardiff = tas|last:tas|xmean:tas|tmean
 varcombo = ta;pinterp@last@xmean:ua;pinterp@last@xmean:va;pinterp@last@xmean:hur;pinterp@last@xmean:ws;pinterp@turb@xmean:hus;pinterp@turb@xmean
 
