#!/bin/sh
#
# $Id: get-NWSdata,v 1.32 2012/12/03 21:30:39 we7u Exp $
#
# Script to retrieve NWS data files. 
#
# Originally written 2006/03/07 by Steven, WM5Z, and Curt, WE7U.
#
# Copyright (C) 2000-2012  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/>


# Please only have ONE of each variable listed here!  Note that the "Valid
# Date" listed on the NWS web pages is the date at which the Shapefile
# should START to be used.  Don't just blindly put the newest filename
# here if that start-date hasn't arrived yet!
#
FILE1="w_11oc12"  # NWSM Libraries: County Warning Area Boundaries
FILE2="z_04de12"  # NWSM Libraries: Public Zone Boundaries
FILE3="mz11oc12"  # NWSM Libraries: Coastal and Offshore Marine Zones
FILE4="oz28jn12"  # NWSM Libraries: Coastal and Offshore Marine Zones
FILE5="hz30mr09"  # NWSM Libraries: Coastal and Offshore Marine Zones
FILE6="fz04de12"  # NWSM Libraries: Fire Weather Zone Boundaries
FILE7="c_11oc12"  # AWIPS County Libraries (under "States, Provinces & Counties", "U.S. 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

