#!/bin/bash

#set -x

ferret -batch -script date.jnl

date1=`tail -n 720 date-6640.txt | head -n 1 | awk '{print $1}'`
date2=`tail -n 1   date-6640.txt | head -n 1 | awk '{print $1}'`

date3=`tail -n 720 date-0460.txt | head -n 1 | awk '{print $1}'`
date4=`tail -n 1   date-0460.txt | head -n 1 | awk '{print $1}'`

date5=`tail -n 720 date-0680.txt | head -n 1 | awk '{print $1}'`
date6=`tail -n 1   date-0680.txt | head -n 1 | awk '{print $1}'`

rm -f date.txt

echo $date1 $date2 $date3 $date4 $date5 $date6 ; sleep 1

ferret -batch -script fig.jnl $date1 $date2 $date3 $date4 $date5 $date6

for file in *.png ; do
# convert -antialias -background white -density 120 -flatten -quality 0 $file ${file%*.eps}.png
 optipng ${file%*.png}.png
done

pwd=$PWD

HOST="www.climatodata.uliege.be"
USER="climatodata"
PASS="S@l@de2Fru1t5"
FTPURL="ftp://$USER:$PASS@$HOST"
LCD="$pwd"
RCD="."
#DELETE="--delete"
lftp -c "set ftp:list-options -a;
open '$FTPURL';
lcd $LCD;
cd /public_html/img-katabata
mput *.png"

