diff --git a/model/bin/ww3_from_ftp.sh b/model/bin/ww3_from_ftp.sh index 667bf37d1d..e1e9f78428 100755 --- a/model/bin/ww3_from_ftp.sh +++ b/model/bin/ww3_from_ftp.sh @@ -1,28 +1,69 @@ -#!/bin/bash +#!/bin/bash -e # --------------------------------------------------------------------------- # # # # Script for downloading data from ftp # # Created 0ct 10, 2017 # # --------------------------------------------------------------------------- # +usage() +{ + echo '' + echo ' Usage : ./ww3_from_ftp.sh [options]' + echo '' + echo ' Options : ' + echo ' -h : print usage' + echo ' -i : interactive mode' + echo ' -k : keep tar files' + echo '' +} + curr_dir=`pwd` # Set WW3 code version ww3ver=v7.12.6 +interactive='n' +keep='n' +if [ $# -eq 1 ] ; then + if [ "$1" = "-h" ] ; then + usage + exit 0 + elif [ "$1" = "-i" ] ; then + interactive='y' + elif [ "$1" = "-k" ] ; then + keep='y' + else + echo '[ERROR] input argument not recognized' + usage + exit 1 + fi +elif [ $# -gt 1 ] ; then + echo '[ERROR] only one input argument accepted' + usage + exit 1 +fi + +dir0=$(cd $(dirname $0) > /dev/null && pwd -P) +ww3dir=$(dirname $(dirname $dir0)) + #Get top level directory of ww3 from user: echo -e "\n\n This script will download data from the ftp for WAVEWATCH III " -echo -e "Enter the relative path to the main/top level directory, this would " -echo -e "be '../../' if in the model/bin directory or '.' if already in the " -echo -e "top/main directory:" -read ww3dir +if [ "$interactive" = "n" ] +then + echo $ww3dir +else +echo -e "Enter the absolute or relative path to the main/top directory, " +echo -e "this would be '../../' if in the model/bin directory " +echo -e "or './' if already in the top/main directory:" + read ww3dir +fi #Move to top level directory of ww3: cd $ww3dir #Download from ftp and uptar: echo -e "Downloading and untaring file from ftp:" -wget https://ftp.emc.ncep.noaa.gov/static_files/public/WW3/ww3_from_ftp.${ww3ver}.tar.gz +wget --no-check-certificate https://ftp.emc.ncep.noaa.gov/static_files/public/WW3/ww3_from_ftp.${ww3ver}.tar.gz tar -xvzf ww3_from_ftp.${ww3ver}.tar.gz #Move regtest info from data_regtests to regtests: @@ -60,8 +101,13 @@ cp -r data_regtests/ww3_ufs1.2/input/* regtests/ww3_ufs1.2/input/ cp -r data_regtests/ww3_ufs1.3/input/*nc regtests/ww3_ufs1.3/input/ #Do you want to clean up (aka delete tar file, delete the data_regtests directory) echo -e "\n\n Do you want to delete the tar file ww3_from_ftp.${ww3ver}.tar.gz [y|n]: " -read wnew -if [ "${wnew}" = "Y" ] || [ "${wnew}" = "y" ] +if [ "$interactive" = "n" ] +then + echo $keep +else + read keep +fi +if [ "${keep}" = "N" ] || [ "${keep}" = "n" ] then echo -e '\n Deleting tar file ww3_from_ftp.${ww3ver}.tar.gz' rm ww3_from_ftp.${ww3ver}.tar.gz @@ -71,8 +117,13 @@ fi echo -e "\n\n Files were copied from the data_regtests to the regtests folder." echo -e "Do you want to delete the data_regtests folder? [y|n]: " -read wnew2 -if [ "${wnew2}" = "Y" ] || [ "${wnew2}" = "y" ] +if [ "$interactive" = "n" ] +then + echo $keep +else + read keep +fi +if [ "${keep}" = "N" ] || [ "${keep}" = "n" ] then echo -e '\n Deleting the data_regtests folder' rm -rf data_regtests