#!/bin/csh -f

/usr/ucb/mail junluo jiebing jignesh navin montage << EOF
I am using happy to run postgres number.
I will let you know when it's done.

Jun
EOF

# load all the setenv's and set's necessary
source config

#
# Creating database.
#
echo "create database:"
/bin/time $CREATEDB $DBNAME
cp $RASTER_O $PGDATA/base/$DBNAME/
cp $POLY_FUNCS_O $PGDATA/base/$DBNAME/

#
# Setup classes, types and functions.
#
echo "setup database:"
/bin/time $MONITOR -q $DBNAME < setup.pq

#
# load polygons
#
echo "loading polygons:"
echo "/bin/time $MONITOR -c "'"'"copy polygons from "'"'$POLYGON_FLAT'"' $DBNAME 
/bin/time $MONITOR -c "copy polygons from "'"'$POLYGON_FLAT'"' $DBNAME

# 
# load points
#
echo "loading points"
echo "/bin/time $MONITOR -c "'"'"copy gpoints from "'"'$POINT_FLAT'"' $DBNAME
/bin/time $MONITOR -c "copy gpoints from "'"'$POINT_FLAT'"' $DBNAME

#
# load islands
#
echo "/bin/time $MONITOR -c "'"'"copy islands from "'"'$ISLAND_FLAT'"' \
$DBNAME
/bin/time $MONITOR -c "copy islands from "'"'$ISLAND_FLAT'"' $DBNAME


#
# Load rasters
#
echo "loading raster:"
  set rasttime=0
  foreach i ($RASTER_PATH/*.ca)
    set rasttime=`echo $i | sed -e "s/.*p\(..\)ch..ca.*/\1/"`
    set freq=`echo $i | sed -e "s/.*p..ch\(.\).ca.*/\1/"`
    /bin/time $MONITOR -c "append rasters(time = $rasttime, frequency= $freq, \
      data = "'"0 0, -2029000 -16000, 2560 1600, 2 500 500, '$i'")' \
      $DBNAME
  end

#
# Setup index.
#
echo "create index"
/bin/time $MONITOR -q $DBNAME < index.pq

#
# Run all queries...
#
fe2

#
# Done.
#
echo "..... done ....."

run_query

/usr/ucb/mail jiebing jignesh navin montage << EOF
I am done.  You may use happy now.

Jun
EOF

