#!/bin/sh

  MDL="${HOME}/hysplit"
  OUT="${MDL}/working"
  MET="${HOME}/Tutorial/captex"
  cd $OUT

  if [ ! -f ASCDATA.CFG ]; then
     echo "-90.0  -180.0"     >ASCDATA.CFG
     echo "1.0     1.0"      >>ASCDATA.CFG
     echo "180     360"      >>ASCDATA.CFG
     echo "2"                >>ASCDATA.CFG
     echo "0.2"              >>ASCDATA.CFG
     echo "'$MDL/bdyfiles/'" >>ASCDATA.CFG
  fi
  echo "### $0 ###"

  syr=83
  smo=09
  sda=28
  shr=13
     
  olat=38.665 
  olon=-71.369
  olvl=216.4
       
  run=-68
  ztop=10000.0

#----------------------------------------------------------

  echo "$syr $smo $sda $shr    " >CONTROL.head
  echo "1                      ">>CONTROL.head
  echo "$olat $olon $olvl      ">>CONTROL.head
  echo "$run                   ">>CONTROL.head

  echo "$ztop                  " >CONTROL.tail
  echo "1                      ">>CONTROL.tail
  echo "$MET/                  ">>CONTROL.tail
  echo "captex2_wrf27uw.bin    ">>CONTROL.tail
  echo "$OUT/                  ">>CONTROL.tail

#----------------------------------------------------------

  rm -f traj_files.txt
  rm -f tdump_data tdump_isob tdump_isen tdump_dens tdump_sigma tdump_divg
  rm -f SETUP.CFG

  cp    CONTROL.head        CONTROL
  echo "0"                >>CONTROL
  cat   CONTROL.tail      >>CONTROL
  echo "tdump_data"       >>CONTROL
  echo "tdump_data"        >traj_files.txt
  ${MDL}/exec/hyts_std    

  cp    CONTROL.head        CONTROL
  echo "1"                >>CONTROL
  cat   CONTROL.tail      >>CONTROL
  echo "tdump_isob"       >>CONTROL
  echo "tdump_isob"       >>traj_files.txt
  ${MDL}/exec/hyts_std    

  cp    CONTROL.head        CONTROL
  echo "2"                >>CONTROL
  cat   CONTROL.tail      >>CONTROL
  echo "tdump_isen"       >>CONTROL
  echo "tdump_isen"       >>traj_files.txt
  ${MDL}/exec/hyts_std    

  cp    CONTROL.head        CONTROL
  echo "3"                >>CONTROL
  cat   CONTROL.tail      >>CONTROL
  echo "tdump_dens"       >>CONTROL
  echo "tdump_dens"       >>traj_files.txt
  ${MDL}/exec/hyts_std    

  cp    CONTROL.head        CONTROL
  echo "4"                >>CONTROL
  cat   CONTROL.tail      >>CONTROL
  echo "tdump_sigma"      >>CONTROL
  echo "tdump_sigma"      >>traj_files.txt
  ${MDL}/exec/hyts_std    

  cp    CONTROL.head        CONTROL
  echo "5"                >>CONTROL
  cat   CONTROL.tail      >>CONTROL
  echo "tdump_divg"       >>CONTROL
  echo "tdump_divg"       >>traj_files.txt

  echo "tdump_fwrd"       >>traj_files.txt

  ${MDL}/exec/hyts_std    

  rm CONTROL.head CONTROL.tail

  echo "'TITLE&','### $0 ###&'"  >LABELS.CFG
  ${MDL}/exec/trajplot -z30 -i+traj_files.txt -j${MDL}/graphics/arlmap -v0
  if [[ "$OSTYPE" == "darwin"* ]]; then
     open trajplot.ps
  else
     gs trajplot.ps
  fi
