#!/bin/bash

# Set installation directory
INSTALL=$HOME
cd $INSTALL
mkdir CSPP 

# Download and verify tarfiles
echo $'\n(Downloading tarfiles)\n'
cd $INSTALL/CSPP
mkdir tarfiles
cd tarfiles
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15.tar.gz
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_static_tiles.tar.gz
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_static_luts_j01.tar.gz
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_static_luts_j02.tar.gz
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_static_luts_npp.tar.gz
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_stray_luts_j01.tar.gz
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_stray_luts_j02.tar.gz  
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_stray_luts_npp.tar.gz
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15.tar.gz.sha1
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_testdata.tar.gz
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_static_tiles.tar.gz.sha1
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_static_luts_j01.tar.gz.sha1
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_static_luts_j02.tar.gz.sha1
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_static_luts_npp.tar.gz.sha1
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_stray_luts_j01.tar.gz.sha1
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_stray_luts_j02.tar.gz.sha1
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_stray_luts_npp.tar.gz.sha1
wget http://bin.ssec.wisc.edu/pub/CSPP/hidden/test/sdr_4_0_beta/SDR_4_0_b_15_testdata.tar.gz.sha1
shasum -c *.sha1

# Install tarfiles
echo $'\n(Installing tarfiles)\n'
cd $INSTALL/CSPP
tar xf tarfiles/SDR_4_0_b_15.tar.gz
tar xf tarfiles/SDR_4_0_b_15_static_luts_j01.tar.gz
tar xf tarfiles/SDR_4_0_b_15_static_luts_j02.tar.gz
tar xf tarfiles/SDR_4_0_b_15_static_luts_npp.tar.gz
tar xf tarfiles/SDR_4_0_b_15_static_tiles.tar.gz
tar xf tarfiles/SDR_4_0_b_15_stray_luts_j01.tar.gz
tar xf tarfiles/SDR_4_0_b_15_stray_luts_j02.tar.gz
tar xf tarfiles/SDR_4_0_b_15_stray_luts_npp.tar.gz
tar xf tarfiles/SDR_4_0_b_15_testdata.tar.gz

# Update LUT and ancillary files
echo $'\n(Updating LUTs and ancillary)\n'
cd $INSTALL/CSPP
export CSPP_SDR_HOME=$INSTALL/CSPP/SDR_4_0
source $CSPP_SDR_HOME/cspp_sdr_env.sh
sdr_luts.sh
sdr_ancillary.sh

# Process test data
echo $'\n(Processing test data)\n'
cd $INSTALL/CSPP
mkdir work
cd work
atms_sdr.sh -a ../testdata/RATMS*h5
viirs_sdr.sh -a ../testdata/RNSCA*h5
ls
