diff --git a/cyclone-tracking/get-vitals.sh b/cyclone-tracking/get-vitals.sh index 282a8e9..5c60369 100755 --- a/cyclone-tracking/get-vitals.sh +++ b/cyclone-tracking/get-vitals.sh @@ -6,6 +6,7 @@ # $1 -- YYYYMMDDHH of cycle (ex: 2018082112) # $2 -- TCVITFOLDER (ex: ./fin-tcvitals/) # $3 -- betacast script dir (ex: ~/betacast/) +# ./get-vitals.sh 2024070612 ./fin-tcvitals/ ~/work/betacast/ ############ USER OPTIONS ##################### @@ -28,20 +29,58 @@ if [ ! -f ${TCVITFILE} ]; then #if TCVITFILE doesn't exist, download COMBINEDVITFILE=combined_tcvitals.${yearstr}.dat echo "get-vitals: ${TCVITFILE} doesn't exist, attempting to create from ${TCVITFOLDER}/combined/${COMBINEDVITFILE}" mkdir -v -p ${TCVITFOLDER}/combined/ + if [ ! -f ${TCVITFOLDER}/combined/${COMBINEDVITFILE} ]; then echo "get-vitals: ${TCVITFOLDER}/combined/${COMBINEDVITFILE} doesn't exist, attempting to download" cd ${TCVITFOLDER}/combined/ - if [[ $yearstr -gt 2018 ]]; then - echo "get-vitals: Year $yearstr is 2019 or later, try to get from NCAR RAL" - wget http://hurricanes.ral.ucar.edu/repository/data/tcvitals_open/${COMBINEDVITFILE} + + # if get_from_nhc, get from NHC servers for this current year by gluing storm archived vitals + get_from_nhc=false + + if [ "$get_from_nhc" = true ]; then + BASE_URL="https://ftp.nhc.noaa.gov/atcf/com/" + TEMP_DIR="./vit_tmp/" + ORIGINAL_DIR=$(pwd) + echo "Temporary Directory: $TEMP_DIR" + echo "Original Directory: $ORIGINAL_DIR" + mkdir -p $TEMP_DIR ; cd $TEMP_DIR + + # CURL STUFF + curl -s $BASE_URL > index.html + # Extract the list of *-tcvitals-arch.dat files + FILES=$(grep -oP 'href="\K[^"]*-tcvitals-arch\.dat' index.html) + # Loop through each file and download it + for FILE in $FILES; do + curl -O "$BASE_URL$FILE" + done + + # Concatenate all the downloaded files into a single combined file + cat *-tcvitals-arch.dat > $COMBINEDVITFILE + + # Sort the combined file by the 4th and 5th columns (YYYYMMDD then HHNN) + sort -k 4,4 -k 5,5 $COMBINEDVITFILE -o $COMBINEDVITFILE + + # Move the combined and sorted file to the original directory + mv $COMBINEDVITFILE $ORIGINAL_DIR/$COMBINEDVITFILE + + # Clean up the temporary directory + cd .. ; rm -rf $TEMP_DIR + + # Tell the code to clear this file when done CLEARCOMBINEDVIT=true - else - echo "get-vitals: Year $yearstr is 2018 or earlier, try to get from NOAA NHC archives" - wget -q -nd -r --no-parent -P ./ -A dat "https://ftp.nhc.noaa.gov/atcf/archive/${yearstr}/tcvitals/" - rm *tcvitals.dat - cat *tcvitals-arch.dat > ${COMBINEDVITFILE} - rm *-tcvitals-arch.dat - CLEARCOMBINEDVIT=false + else # get from RAL server + if [[ $yearstr -gt 2018 ]]; then + echo "get-vitals: Year $yearstr is 2019 or later, try to get from NCAR RAL" + wget http://hurricanes.ral.ucar.edu/repository/data/tcvitals_open/${COMBINEDVITFILE} + CLEARCOMBINEDVIT=true + else + echo "get-vitals: Year $yearstr is 2018 or earlier, try to get from NOAA NHC archives" + wget -q -nd -r --no-parent -P ./ -A dat "https://ftp.nhc.noaa.gov/atcf/archive/${yearstr}/tcvitals/" + rm *tcvitals.dat + cat *tcvitals-arch.dat > ${COMBINEDVITFILE} + rm *-tcvitals-arch.dat + CLEARCOMBINEDVIT=false + fi fi sed -i $'s/\t/ /g' combined_tcvitals.${yearstr}.dat cd ../..