[go: up one dir, main page]

Menu

[73c35b]: / bin / gupgo  Maximize  Restore  History

Download this file

206 lines (198 with data), 3.8 kB

#!/bin/sh

#wd=`dirname $0`
#wd=`dirname $wd`/webgup
wd=/data/webgup
wwwreq="anareg.txt"
locreq="anareq_done.txt"
wwwsite="http://www.eiscat.se/schedule"
export PATH=$PATH:/usr/local/bin
export EISCATSITE=web

fsiz() {
	filesize=`ls -l $1 | awk '{print $5}'`
	#return `ls -l $1 | awk '{print $5}'`
}
mail_it() {
#	mailx -s "Analysis results" -r "GUISDAP <ingemar@eiscat.se>" $* <<!
	mutt -F /home/eiscat/muttrc.webgup -s "Analysis results" -e "my_hdr From: GUISDAP <ingemar@eiscat.se>" $* <<!
Enclosed you find the requested analysis.
EISCAT
!
}

cd $wd
if [ "$1" ]
then
 echo "Doing from command line"
 eval $1
 echo $datapath
 echo $t
 echo $resultpath
 echo $maxfsize
 echo $name_expr
 echo $expver
 echo $siteid
 echo $intper
 echo $extra
 echo $REMOTE_ADDR
else
 if ! wget $wwwsite/$wwwreq -O $wwwreq 2>/dev/null
 then
 echo "Could not reach HQ"
  exit 0
 elif cmp -s $wwwreq $locreq
 then
 #echo "All already done"
  exit 0
 else
  QUERY_STRING=`comm -23 $wwwreq $locreq | head -n1`
 fi
 fsiz $wwwreq
 nsiz=$filesize
 fsiz $locreq
 if [ -z "$QUERY_STRING" ] || [ $nsiz -lt $filesize ]
 then
  echo "New list"
  cp $wwwreq $locreq
  exit 0
 fi
 echo $QUERY_STRING >> $locreq
 eval $QUERY_STRING
fi


atpos=`expr index "$resultpath" "@"`
if [ -z $resultpath ] || [ $atpos -eq 0 ]
then
 echo "Nowhere to send results"
 exit 1
#else
# echo "$resultpath"
fi
#rundir=www$RANDOM
rundir=`date +%y%m%dw%H%M`
if [ -d $rundir ]
then
 rm -rf $rundir
fi
mkdir $rundir
cd $rundir
gfdfil=gfd.m
for tar in $datapath
do
 wget -O - "$tar" 2>/dev/null | tar xf -
done
ls | grep information | xargs rm -rf
datapath=`ls`
if [ -z $datapath ]
then
 echo "No data defined"
 exit 1
fi
touch $gfdfil
maxsize=3000000
if [ $maxfsize ]
then
 maxsize=$(($maxfsize*730000)) #uuencoding maxes file ~27% bigger 
fi

ed $gfdfil 2>/dev/null <<!
a
name_expr='$name_expr';
siteid=$siteid;
data_path='$datapath';
result_path='AUTO';
t1=[$t 0 0 0];
t2=[$t 24 0 0];
rt=0;
intper=$intper;
path_exps=[path_GUP '/exps/'];
figs=[0 0 0 0 1];
expver=$expver;
extra='$extra';
.
w
q
!
#guisdap -tg $gfdfil " -c /opt/matlab7/etc/license.dat" >gupout.txt
guisdap -tg $gfdfil >gupout.txt
rm -rf $datapath $gfdfil
gzip -9 gupout.txt
filelist="gupout.txt.gz"
resdir=`ls -d [12]* 2>/dev/null`
if [ $resdir ]
then
 nextfile=`ls $resdir/NCAR* 2>/dev/null`
 if [ $nextfile ]
 then
  mv $resdir/NCAR* .
  bzip2 -9 NCAR*
 fi
 inhouse="@eiscat.se @eiscat.sgo.fi @eiscat.uit.no @esr.eiscat.no"
 goodsites="@uit.no @ntu.ac.uk @stfc.ac.uk @nipr.ac.jp @bas.ac.uk"
 goodguys="andkav@bas.ac.uk steve.crothers@stfc.ac.uk yogawa@nipr.ac.jp mike@eiscat.uit.no bjorn.gustavsson@uit.no"

 trusted=0
 mh=`expr substr $resultpath $atpos 99`
 for eis in $inhouse $goodsites
 do
  if [ "$eis" = "$mh" ]
  then
   trusted=1
  fi
 done 
 for eis in $goodguys
 do
  if [ "$eis" = "$resultpath" ]
  then
   trusted=1
  fi
 done 
 nextfile=`ls $resdir/*.png 2>/dev/null`
 if [ $nextfile ]
 then
  mv $resdir/*.png $resdir/*.pdf .
  filelist="`ls *.png` $filelist"
 elif [ $trusted -eq 0 ]
 then
  trusted=2
 fi
 if [ $trusted -eq 1 ]
 then
  #if [ $nextfile ]
  #then
  # bzip2 -9 *.eps
  #fi
  tar cf - $resdir | bzip2 -9c > $resdir.tar.bz2
 #elif [ $trusted -eq 0 ] && [ $nextfile ]
 #then
 # ps2pdf -sPAPERSIZE=a4 *.eps
 # filelist="$filelist `ls *.pdf`"
 fi
 filelist="$filelist `ls *.bz2`"
 rm -rf $resdir
fi
flist=""
for fil in $filelist
do
 fsiz $fil
 if [ $filesize -gt $maxsize ]
 then
  split -db $maxsize $fil $fil.
  flist="$flist `ls $fil.??`"
 else
  flist="$flist $fil"
 fi
done
nsiz=0
matt=""
for fil in $flist
do
 fsiz $fil
 if [ $((nsiz+filesize)) -gt $maxsize ] && [ $nsiz -ne 0 ]
 then
  mail_it $matt -- $resultpath
  sleep 30
  matt=""
  nsiz=0
 fi
 matt="$matt -a $fil"
 nsiz=$((nsiz+filesize))
done
mail_it $matt -- $resultpath
cd ..
#rm -rf $rundir