#!/bin/bash

function all_results()
{
    cd $ROOT/RUNS
    for TEST in * ; do
	NAME=$(echo $TEST | tr _ /)
	echo "\subsection{$NAME}"
	for GRAPH in $TEST/*.png ; do
	    cat <<EOF
\begin{figure}
\centering{}
\includegraphics[scale=0.5]{$ROOT/RUNS/$GRAPH}
\end{figure}
EOF
	done
    done
#    cd $ROOT/tmp
}

function all_params()
{
    cd $ROOT/RUNS
    for TEST in * ; do
	NAME=$(echo $TEST | tr _ /)
	cat <<EOF
\subsection{$NAME}
\begin{lstlisting}
$(cat $TEST/run.def)
\end{lstlisting}
EOF
    done
#    cd $ROOT/tmp
}

ROOT=$PWD

for dir in $ROOT/RUNS/* ; do
    cd $dir
    echo
    pwd
    ls -l post.py netcdf
    python post.py & 
done
wait

cd $ROOT/tmp
rm -f *.aux *.log *.toc *.tex

cat <<EOF >report.tex
\documentclass[a4paper,english]{article}
\usepackage{graphicx}
\usepackage{listings}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{color}
\usepackage{babel}
\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=true]
 {hyperref}

\begin{document}

\title{DYNAMICO correctness report ($arch)}
\author{Thomas Dubos}
\maketitle
\tableofcontents{}
\section{Results}
$(all_results)
\section{Parameters}
$(all_params)
\end{document}
EOF

pdflatex report.tex >/dev/null
pdflatex report.tex >/dev/null
mailx -s "DYNAMICO correctness report " -a report.pdf dubos@lmd.polytechnique.fr </dev/null
