#!/bin/bash
#
# Rerun each of the stations in the tc.large.diffs file,
# extracting the DEM elevation from DGG and replacing station
# elevation before terrain correction.  Collect new differences
# for comparison with tc.large.diffs

INFILE="tc.large.diffs"
OUTFILE="tc.large.diffs.new"
TCFILE="UTEP.my_tc.rerun_largediffs"

echo "# Results from reruning tc.large.diffs stns with DEM elevations" > $OUTFILE
echo "# Results from reruning tc.large.diffs stns with DEM elevations" > $TCFILE
for stn in `awk '{print $1}' $INFILE`
do
  echo Processing ${stn}...
  grep "$stn " UTEP_gravdb > zap
  lon=`awk '{print $2}' zap`
  lat=`awk '{print $3}' zap`
  ele=`awk '{print $4}' zap`
  uteptc=`awk '{print $8}' zap`
  dem=`./get_dem_elevation $lon $lat | awk '{print $3}'`
  awk '{print $1, $2, $3, ELE, $5, $6, $7, $8}' ELE=$dem zap > zorch
  mv zorch zap
  ../terrain zap >> $TCFILE
done

# compute new differences
#./comparewutepdb.py UTEP_gravdb $TCFILE >> $OUTFILE
