#!/bin/sh
#
# $Id: get-NWSdata,v 1.16 2008/07/18 15:26:39 gstueve Exp $
#
# Script to retrieve NWS data files. 
#
# Originally written 2006/03/07 by Steven, WM5Z, and Curt, WE7U.
#
# Copyright (C) 2000-2008  The Xastir Group
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#
# See README.MAPS for a bit more information on the program.
#
#
# NOTE:  Run this script as root.
#
# MAINTAINERS:  Go here to find out what the latest versions are:
# <http://www.weather.gov/geodata/>


FILE1="z_01ap08"  # NWSM Libraries: Public Zone Boundaries
FILE2="w_16mr06"  # NWSM Libraries: County Warning Area Boundaries
FILE3="mz08jl08"  # NWSM Libraries: Coastal and Offshore Marine Zones
FILE4="oz02jn08"  # NWSM Libraries: Coastal and Offshore Marine Zones
FILE5="hz28au04"  # NWSM Libraries: Coastal and Offshore Marine Zones
FILE6="fz25jn08"  # NWSM Libraries: Fire Weather Zone Boundaries
FILE7="c_11mr07"  # County Libraries: AWIPS Counties

cd /usr/local/share/xastir/Counties


# Remove any old zip files hanging around in this directory
#
rm -f *.zip 2>&1 >/dev/null


# Fetch new copies, unzip into place, delete archive.
#
#
DIR=wsom
for d in $FILE1 $FILE2 $FILE3 $FILE4 $FILE5 $FILE6; do
if [ -e $d.shp ]
  then
    echo "Already have $d shapefile, skipping..."
  else
    # Remove possible older copies
    cut=`echo $d|cut -c1-2 -`
    rm -f $cut*.shx $cut*.shp $cut*.dbf $cut*.prj $cut*.zip 2>&1 >/dev/null
    wget http://www.weather.gov/geodata/catalog/$DIR/data/$d.zip
    unzip $d.zip
    rm -f *.zip
fi
done

DIR=county
for d in $FILE7; do
if [ -e $d.shp ]
  then
    echo "Already have $d shapefile, skipping..."
  else
    # Remove possible older copies
    cut=`echo $d|cut -c1-2 -`
    rm -f $cut*.shx $cut*.shp $cut*.dbf $cut*.prj $cut*.zip 2>&1 >/dev/null
    wget http://www.weather.gov/geodata/catalog/$DIR/data/$d.zip
    unzip $d.zip
    rm -f *.zip
fi
done

