#!/bin/bash # Round down UTC times for data sampled on the hour function round_time() { if [ -z "$1" ]; then echo "ERROR: supply time for round_time" exit 1 fi IFS_OLD=$IFS IFS=":" read -ra utc <<< "$1" if [[ ${#utc[@]} -gt 1 ]]; then time=${utc[0]} mins=${utc[1]} # if [[ $mins -gt 50 ]]; then # time=$(( $time + 1 )) # fi else time=$utc fi IFS=$IFS_OLD return $time } # Read inputs date/lat/lon/utc input="profile_list.txt" if [ ! -f $input ]; then echo "Unable to find input file $input" exit 1 fi dates=() lats=() lons=() utcs=() while IFS= read -r line; do read -ra data <<< "$line" if [ ${data[0]} == '#' ]; then continue fi if [[ ${#data[@]} -ne 4 ]]; then echo "ERROR: input list inncomplete $line" exit 1 fi dates+=("${data[0]}") lats+=("${data[1]}") lons+=("${data[2]}") utcs+=("${data[3]}") done < $input tardir='profpngs' file='wind.png' if [ -d $tardir ]; then echo "Clearing $tardir..." rm -r $tardir fi mkdir $tardir for n in $(seq 0 $(( ${#dates[@]} - 1 ))); do date=${dates[n]} lat=${lats[n]} lon=${lons[n]} utc=${utcs[n]} round_time $utc time=$? day=$(echo $date | cut -d"/" -f 2) month=$(echo $date | cut -d"/" -f 1) year=$(echo $date | cut -d"/" -f 3) # Convert date to YYYY MM DD if (( $year < 50 )); then yyyy=$((year+2000)) elif (( $year < 1000 )); then yyyy=$((year+1900)) else yyyy=$year fi yy=${yyyy: 2} dd=$(( 10#$day )) mm=$(( 10#$month )) dd=$(printf "%02d" $dd) mm=$(printf "%02d" $mm) tt=$(printf "%02d" $time) #echo $yyyy $mm $dd $lat $lon $tt # Goto case directory month_str=$(date -d "2000/$mm/01" +%b) case_dir=$month_str$dd"_"$yyyy"_"$lat"_"$lon"_"$tt echo $case_dir lnfile=$case_dir"_wind.png" ln -s "$(readlink -f $case_dir/$file)" $tardir/$lnfile done tar -czhf "$tardir.tar" $tardir