Fenòmens: minor changes to lab p4

- Modified gnuplot code.
- Changed |run.bash| so it can be executed standalone to interface with
  the mc2 program with a lot of possible options (run
  `./run.bash --help`).
- Added some more temperatures to runAll.bash in order to get better
  precision around the critical temperature.

Change-Id: I4c8bd84eeccd9d444981e885ba41b9fd6fc75481
diff --git a/quad10/fenomens/lab/p4/MC-2.f90 b/quad10/fenomens/lab/p4/MC-2.f90
index 9b8e78e..8398997 100644
--- a/quad10/fenomens/lab/p4/MC-2.f90
+++ b/quad10/fenomens/lab/p4/MC-2.f90
@@ -69,10 +69,6 @@
         M = M + 2*S(I, J)
       enddo
 
-      !if (mod(IMC, 10000) == 0) then
-      !  print *, "Iter:", IMC, "Energia:", E, "Magn:", INT(M)
-      !endif
-
       if (IMC > MCINI .and. mod(IMC, MCD) == 0) then
         SUMI = SUMI + 1
 
diff --git a/quad10/fenomens/lab/p4/graphs/dependenciaEnL.gnu b/quad10/fenomens/lab/p4/graphs/dependenciaEnL.gnu
index ec68f46..8061b30 100755
--- a/quad10/fenomens/lab/p4/graphs/dependenciaEnL.gnu
+++ b/quad10/fenomens/lab/p4/graphs/dependenciaEnL.gnu
@@ -4,24 +4,64 @@
 datafilepost = '.dat'
 LS = ARG1
 
-set terminal svg dashed size 600, 600 font "Computer Modern,Tinos,Helvetica,15"
+graphStyle = "with linespoints pointsize 0.7"
+svgTerminal = "set terminal svg dashed size 800, 800 font \"Computer Modern,Tinos,Helvetica,15\""
+pngTerminal = "set terminal pngcairo size 800, 800 font \"Computer Modern,Tinos,Helvetica,15\""
 
-set title "Capacitat calorífica"
-set output outputfile.'_capacitat_calorifica.svg'
-plot for [L in LS] datafilepre . L . datafilepost using 2:10 with linespoints title "L = ".L
+set xlabel "Temperatura (K)"
+set yrange [*<0:0<*]
+# ------------------------------------
+# Gràfica per la capacitat calorífica:
+# ------------------------------------
+set title "Capacitat calorífica per diferents valors d'L"
 
-set title "Susceptibilitat magnètica"
-set output outputfile.'_susceptibilitat_magnetica.svg'
-plot for [L in LS] datafilepre . L . datafilepost using 2:11 with linespoints title "L = ".L
+@svgTerminal
+set output outputfile.'capacitat_calorifica.svg'
+plot for [L in LS] datafilepre . L . datafilepost using 2:10 @graphStyle title "L = ".L
 
-set title "Energia"
-set output outputfile.'_energia.svg'
+@pngTerminal
+set output outputfile.'capacitat_calorifica.png'
+replot
+
+# ----------------------------------------
+# Gràfica per la susceptibilitat magnètica
+# ----------------------------------------
+set title "Susceptibilitat magnètica per diferents valors d'L"
+
+@svgTerminal
+set output outputfile.'susceptibilitat_magnetica.svg'
+plot for [L in LS] datafilepre . L . datafilepost using 2:11 @graphStyle title "L = ".L
+
+@pngTerminal
+set output outputfile.'susceptibilitat_magnetica.png'
+replot
+
+# ---------------------
+# Gràfica per l'energia
+# ---------------------
+set title "Energia per diferents valors d'L"
+
+@svgTerminal
+set output outputfile.'energia.svg'
 set key bottom right
-plot for [L in LS] datafilepre . L . datafilepost using 2:($3/(L**2)) with linespoints title "<E>/N, L = ".L, \
-     for [L in LS] datafilepre . L . datafilepost using 2:(-sqrt($4)/(L**2)) with linespoints title "-sqrt(<E^2>)/N, L = ".L
+plot for [L in LS] datafilepre . L . datafilepost using 2:($3/(L**2)) @graphStyle title "<E>/N, L = ".L, \
+     for [L in LS] datafilepre . L . datafilepost using 2:(-sqrt($4)/(L**2)) @graphStyle title "-sqrt(<E^2>)/N, L = ".L
 
-set title "Magnetització"
-set output outputfile.'_magnetitzacio.svg'
+@pngTerminal
+set output outputfile.'energia.png'
+replot
+
+# ----------------------------
+# Gràfica per la magnetització
+# ----------------------------
+set title "Magnetització per diferents valors d'L"
+
+@svgTerminal
+set output outputfile.'magnetitzacio.svg'
 set key top right
-plot for [L in LS] datafilepre . L . datafilepost using 2:($7/(L**2)) with linespoints title "<|M|>/N, L = ".L, \
-     for [L in LS] datafilepre . L . datafilepost using 2:(sqrt($8)/(L**2)) with linespoints title "sqrt(<M^2>)/N, L = ".L
+plot for [L in LS] datafilepre . L . datafilepost using 2:($7/(L**2)) @graphStyle title "<|M|>/N, L = ".L, \
+     for [L in LS] datafilepre . L . datafilepost using 2:(sqrt($8)/(L**2)) @graphStyle title "sqrt(<M^2>)/N, L = ".L
+
+@pngTerminal
+set output outputfile.'magnetitzacio.png'
+replot
diff --git a/quad10/fenomens/lab/p4/run.bash b/quad10/fenomens/lab/p4/run.bash
index 73031d7..96122de 100755
--- a/quad10/fenomens/lab/p4/run.bash
+++ b/quad10/fenomens/lab/p4/run.bash
@@ -1,12 +1,87 @@
 #!/bin/bash
+progname=$0
+function usage() {
+  cat <<END
+
+  Usage: $progname T L [outFilePrefix [--help --skipIfComputed
+             --nSeeds NSEEDS --mcTot MCTOT --mcIni MCINI --mcD MCD
+             --initialSeed INITIALSEED]]
+
+  the output file will be saved at "data_out/{{outFilePrefix}}"
+
+  optional arguments:
+    -h, --help            show this help message and exit.
+    -s, --skipIfComputed  skip if the output file already exists.
+    -n, --nSeeds          number of seeds which will be used for the
+                          simulation.
+    -m, --mcTot           number of iterations which will be performed
+                          in the simulation for each seed.
+    -i, --mcIni           number of iterations before the program
+                          starts measuring physical properties of the
+                          system.
+    -d, --mcD             the program will measure the physical
+                          properties when iteration % MCD == 0.
+    --initialSeed         initial seed for the Monte Carlo algorithm.
+END
+}
+
+if (( "$#" < 2 )); then
+  usage
+  exit 1
+fi
+
 T="$1"
 L="$2"
-outFolder="dep_en_L/$L"
-outFilePrefix="${outFolder}/$T"
+defaultOutFilePrefix="L$L-T$T"
+outFilePrefix="${3:-$defaultOutFilePrefix}"
 
-if [ -f "data_out/${outFilePrefix}.res" ]; then
+opts=$(getopt -l "help,skipIfComputed,nSeeds:,mcTot:,mcIni:,mcD:,initialSeed:" -o "hsn:m:i:d:" -n "$progname" -- "${@:4}")
+eval set -- "$opts"
+
+skipIfComputed=false
+nSeeds=150
+mcTot=40000
+mcIni=2000
+mcD=20
+initialSeed=117654
+
+while true; do
+  case "$1" in
+    -h | --help)
+      usage
+      exit
+      ;;
+    -s | --skipIfComputed)
+      skipIfComputed=true
+      shift
+      ;;
+    -n | --nSeeds)
+      nSeeds="$2"
+      shift 2
+      ;;
+    -m | --mcTot)
+      mcTot="$2"
+      shift 2
+      ;;
+    -i | --mcIni)
+      mcIni="$2"
+      shift 2
+      ;;
+    -d | --mcD)
+      mcD="$2"
+      shift 2
+      ;;
+    --initialSeed)
+      initialSeed="$2"
+      shift 2
+      ;;
+    *) break ;;
+  esac
+done
+
+if [ "$skipIfComputed" == "true" ] && [ -f "data_out/${outFilePrefix}.res" ]; then
   echo "Skipping computation for L=$L, T=$T (.res file already exists)"
-  exit 0
+  exit
 fi
 
 echo "Starting computation for L=$L, T=$T"
@@ -16,10 +91,10 @@
 L=$L,
 NOM="$outFilePrefix",
 TEMP=$T,
-NSEED=150,
-SEED0=117654,
-MCTOT=40000,
-MCINI=2000,
-MCD=20
+NSEED=$nSeeds,
+SEED0=$initialSeed,
+MCTOT=$mcTot,
+MCINI=$mcIni,
+MCD=$mcD
 &END
 EOF
diff --git a/quad10/fenomens/lab/p4/runAll.bash b/quad10/fenomens/lab/p4/runAll.bash
index e190a34..c4f0783 100755
--- a/quad10/fenomens/lab/p4/runAll.bash
+++ b/quad10/fenomens/lab/p4/runAll.bash
@@ -1,7 +1,7 @@
-TList=$(seq 1.6 0.05 3.2)
+TList=$((seq 1.6 0.05 3.2; seq 2.2 0.01 2.5) | sort -n | uniq)
 LList="8 16 32 64"
 for L in $LList; do
   mkdir -p data_out/dep_en_L/$L
 done
 joblogFile="data_out/dep_en_L/joblog"
-parallel -P -1 --linebuffer --tag --joblog "$joblogFile" ./run.bash {1} {2} ::: $TList ::: $LList
+parallel -P -1 --linebuffer --tag --joblog "$joblogFile" "./run.bash {1} {2} dep_en_L/{2}/{1} --skipIfComputed" ::: $TList ::: $LList