#!/bin/sh
#
# $Id: get-NWSdata,v 1.24 2010/09/30 15:35:59 gstueve Exp $
#
# Script to retrieve NWS data files. 
#
# Originally written 2006/03/07 by Steven, WM5Z, and Curt, WE7U.
#
# Copyright (C) 2000-2010  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., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, 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_01de10"  # NWSM Libraries: Public Zone Boundaries
FILE1="z_15nv10"  # NWSM Libraries: Public Zone Boundaries
FILE1="z_15oc10"  # NWSM Libraries: Public Zone Boundaries
FILE1="z_11my10"  # NWSM Libraries: Public Zone Boundaries
FILE2="w_15jl09"  # NWSM Libraries: County Warning Area Boundaries
FILE3="mz01jn10"  # NWSM Libraries: Coastal and Offshore Marine Zones
FILE4="oz02jn09"  # NWSM Libraries: Coastal and Offshore Marine Zones
FILE5="hz30mr09"  # NWSM Libraries: Coastal and Offshore Marine Zones
FILE6="fz01de10"  # NWSM Libraries: Fire Weather Zone Boundaries
FILE6="fz15nv10"  # NWSM Libraries: Fire Weather Zone Boundaries
FILE6="fz01my10"  # NWSM Libraries: Fire Weather Zone Boundaries
FILE7="c_15jl09"  # County Libraries: AWIPS Counties

x=`dirname $0`
. $x/values
cd ${prefix}/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

