#! /bin/csh -f

# QSUB -s /bin/csh
# QSUB -q prem
# QSUB -lM 9MW
# QSUB -lm 9MW
# QSUB -lT 1000

@ PID = 1096
set DEBUG

# Turn on job accounting...
ja 

cd $TMPDIR

set HOST = ouray.hao.ucar.edu
set SRCDIR = /home/ouray/roble/thunder
set DESTDIR = /ouray/d/thunder

#set HOST = ouray.hao.ucar.edu
#set SRCDIR = /home/ouray/roble/thunder
#set DESTDIR = /ouray/d/thunder

rcp $HOST\:$SRCDIR/orog.data .
# rcp $HOST\:$SRCDIR/pot.data .
rcp $HOST\:$SRCDIR/nzlvl.data .
rcp $HOST\:$SRCDIR/HistReq . 

rcp $HOST\:$SRCDIR/thunder.f .
rcp $HOST\:$SRCDIR/mbcntr.f .
rcp $HOST\:$SRCDIR/mbsrfc.f .
rcp $HOST\:$SRCDIR/mbvec.f .
rcp $HOST\:$SRCDIR/sizeo.f .
rcp $HOST\:$SRCDIR/scaleit.f .
rcp $HOST\:$SRCDIR/fipd_R.f .
rcp $HOST\:$SRCDIR/polint.f .
rcp $HOST\:$SRCDIR/lowlay.f .
rcp $HOST\:$SRCDIR/ltpbvp.f .

if ($?DEBUG) then
  cft77 -o off -ez -a static -b thunder.o thunder.f
  cft77 -o off -ez -b mbcntr.o mbcntr.f
  cft77 -o off -ez -b mbsrfc.o mbsrfc.f
  cft77 -o off -ez -b sizeo.o sizeo.f
  cft77 -o off -ez -b scaleit.o scaleit.f
  cft77 -o off -ez -b mbvec.o mbvec.f 
  cft77 -o off -ez -b fipd_R.o fipd_R.f
  cft77 -o off -ez -b polint.o polint.f
  cft77 -o off -ez -b lowlay.o lowlay.f
  cft77 -o off -ez -b ltpbvp.o ltpbvp.f
else
  cft77 -a static -b thunder.o thunder.f
  cft77 -b mbcntr.o mbcntr.f
  cft77 -b mbsrfc.o mbsrfc.f
  cft77 -b sizeo.o sizeo.f
  cft77 -b scaleit.o scaleit.f
  cft77 -b mbvec.o mbvec.f 
  cft77 -b fipd_R.o fipd_R.f
  cft77 -b polint.o polint.f
  cft77 -b lowlay.o lowlay.f
  cft77 -b ltpbvp.o ltpbvp.f
endif

segldr -o thunder -L/lib,/usr/lib,/usr/local/lib \
 -lncarg,ncarg_gks,ncarg_c,ncarg_loc,X11,ncarm,ncaro,mss \
 thunder.o mbcntr.o mbsrfc.o mbvec.o sizeo.o scaleit.o \
 fipd_R.o polint.o lowlay.o ltpbvp.o ~foster/lib/getgcm.a

thunder > thunder.stdout

if ($status != 0) then
 debug -s thunder core  > DEBUG$PID
 rcp DEBUG$PID $HOST\:$DESTDIR/DEBUG$PID
endif

rcp thunder.stdout $HOST\:$DESTDIR/thunderOUT$PID

if (-e gmeta) then
  rcp gmeta $HOST\:$DESTDIR/thunderCGM$PID
endif

# Turn off job accounting...
ja -cst > thunderACCT$PID 

rcp thunderACCT$PID  $HOST\:$DESTDIR/thunderACCT$PID

cat << EOM > thunderMail
thunder program has completed execution. 
Output transferred to lhotse.hao.ucar.edu:/d/thunder
standard output file: thunderOUT$PID
graphics metacode file: thunderCGM$PID
job accting file: thunderACCT$PID 
EOM

mail $user < thunderMail

# /bin/rm thunder$PID thunder.o* thunder.e*
