#!/bin/bash USAGE="Usage: $0 [clean/filter] [jpl/sopac/comb/combwm] - select source type to continue" if [[ $1 != "clean" && $1 != "filter" || $2 != "jpl" && $2 != "sopac" && $2 != "comb" && $2 != "combwm" ]] ; then echo "Invalid arguments: $@" echo "$USAGE" exit 1 fi # Find the latest data folder # Expecting to find an expanded time series folder with files in a /neu subdirectory workingDir='.' data=`find $workingDir -maxdepth 1 -iname "WNAM_${1}_TrendNeuTimeSeries_${2}_*" -type d | sort | tail -n 1` echo "Found data folder: $data" TSLen=`find $workingDir/displGrid -iname "Station_Locations_*" | sort | tail -n 1 | cut -c 1-` StaList=`more "${TSLen}" | awk '{print $1}' ` if [[ $1 == "clean" ]]; then seriesType="CleanTrend" else seriesType="FilterTrend" fi tmin=1999.9968 tmax=2970 # must be equal to start + (n * step) | n >= number of desired steps, otherwise filter1D changes step to fit max scale='1.' #### Part1 ### Extract weekly displacement from daily time series : ### filter1d write with a wrong format for the following - awk to reformat ### do not interpolate where data gap of more than 1 week. # file destination path path="displGrid/DataST/ST/" for station in $StaList; do STI="${data}/neuC/${station}${seriesType}mFCo.neu" echo "filter1D $station" # -lack width start/stop/step -E: include ends -Fm: filter type: median gmt filter1d $STI -L0.0192 -T$tmin/$tmax/0.0192 -E -Fm0.02 -do > ${path}${station}_tmp.dat # -do: replace missing data in output (NaN) with empty string awk '{printf("%10.4lf %10.2lf %10.2lf %10.2lf %8.2lf %8.2lf %8.2lf \n",$1,$2,$3,$4,$5,$6,$7)}' ${path}${station}_tmp.dat > ${path}${station}.dat # Add Katherine Guns's non accumulating station .dat file code # echo " Calculating displacements for ${station}..." # echo " Differencing values..." awk 'p{print $1-p}{p=$1}' ${path}${station}.dat > ${path}dt.tmp awk 'NR-1{print $2-p}{p=$2}' ${path}${station}.dat > ${path}dn.tmp # awk snippet subtracts adjacent lines (NR-1 makes sure it includes lines that have 0.00) awk 'NR-1{print $3-p}{p=$3}' ${path}${station}.dat > ${path}de.tmp awk 'NR-1{print $4-p}{p=$4}' ${path}${station}.dat > ${path}du.tmp awk '{print $5}' ${path}${station}.dat | sed '1d' > ${path}sn.tmp awk '{print $6}' ${path}${station}.dat | sed '1d' > ${path}se.tmp awk '{print $7}' ${path}${station}.dat | sed '1d' > ${path}su.tmp awk '{print $1}' ${path}${station}.dat | sed '1d' > ${path}time.tmp echo " Applying logic and removing lines > 0.0192..." #paste time.tmp dt.tmp dn.tmp de.tmp du.tmp sn.tmp se.tmp su.tmp > draft.tmp paste ${path}time.tmp ${path}dt.tmp ${path}dn.tmp ${path}de.tmp ${path}du.tmp ${path}sn.tmp ${path}se.tmp ${path}su.tmp | awk '($2 == 0.0192)' | awk '{print $1,$3,$4,$5,$6,$7,$8}' > ${path}nonAcc_${station}.dat done rm ${path}*.tmp rm ${path}*_tmp.dat