#!/bin/bash # script to plot splitting measurements from the database maintained by # Guilhem Barruol http://splitting.gm.univ-montp2.fr/ # The script was inspired by and reused some code from map.gmt.sh distributed on the splittingDB website # # Author: Frederik Tilmann (GFZ Potsdam), 20180519 # # needs GMT4 (if anyone updates this to GMT5 please send me a copy!) # download database from # http://splitting.gm.univ-montp2.fr/ # hard-coded configuration variables: # Where locally the database is/should be stored #splitdb=~/work/data/splittingDB/splittingDB.txt splitdb=splittingDB.txt splitdbref=${splitdb%.txt}_ref.txt # set defaults OVERLAY= KONTINUE= LEGEND= RVALUE= JVALUE= BVALUE= GLOBAL= GSPLIT=255/0/0 WNULL=1.5p,0/0/255 SNULL=c0.25c # Length of a vector corresponding to delay LENDELAYONE=0.5c DEEP= usage () { echo >&2 "Usage: $0 [ options ]" echo >&2 "Plot splitting measurements from \"Splitting Database\" (http://splitting.gm.univ-montp2.fr/)." echo >&2 "Use script like a GMT command with limited option set, " echo >&2 "i.e. script generates postscript on standard output. In addition, the list of references" echo >&2 "and the number of measurements provided by each reference is printed for the particular map rectangle." echo >&2 "These references are also written to file draw_splitDB_ref.txt in nearly the same format as providing" echo >&2 "on the SplittingDB website, except that the number of measurements provided is added as the second " echo >&2 "field and all subsequent fields are shifted to the right." echo >&2 "Note that the counting does not distinguish single measurements from station averages and will therefore" echo >&2 "in general not reflect the importance of each reference." echo >&2 "The script works only properly for rectangular map regions not crossing the date line and with the " echo >&2 "standard R option. Where this condition is violated, the plot can still be used for plotting with the" echo >&2 "-g option." echo >&2 "The database is expected to be stored in $splidb . If this file does not already exist, it is" echo >&2 "downloaded on the fly by the script. A time stamp is added to the end of the first line of the downloaded file." echo >&2 "" echo >&2 "Options:" echo >&2 "-G Fill colour for splitting bars [Default: $GSPLIT]" echo >&2 "-W Pen for outline of null splitting symbol [Default: $WNULL]" echo >&2 "-S symbol for null splitting measurements [Default: $SNULL]" echo >&2 "-l Length of splitting bar for 1 s splitting delay [Default: $LENDELAYONE]" echo >&2 "-L plot legend for splitting measurements" echo >&2 "-R,-J,-B, -O, -K have their usual GMT meaning." echo >&2 " For the R option -Rg -Rxxxr variants will not work properly unless -g option is also given." echo >&2 "-g global - simply extract all splitting measurement from the database for plotting non-rectangular." echo >&2 " or date-line crossing regions. The automatic extraction of references does not work with this option." echo >&2 "-d forces downloading of the database even if the database file already exists locally. This option" echo >&2 " is meant to update the databse. It should not be on by default in case of frequent reruns of the script." echo >&2 "Refer to http://splitting.gm.univ-montp2.fr/ for details on the underlying dataset." exit 1 } tmproot=/tmp/draw_splitDB_$$ #tmproot=draw_splitDB_tmp while getopts J:G:KLOR:S:W:dghl: opt do case "$opt" in G) GSPLIT="$OPTARG";; W) WNULL="$OPTARG";; S) SNULL="$OPTARG";; l) LENDELAYONE="$OPTARG";; L) LEGEND=1;; g) GLOBAL=1;; R) RVALUE="$OPTARG";; B) BVALUE=-B"$OPTARG";; J) JVALUE="$OPTARG";; d) DEEP=1;; O) OVERLAY=-O ;; K) KONTINUE=-K ;; h | [?]) usage; esac done shift $((OPTIND-1)) # Download database if it does not already exist if [ -n "$DEEP" -o ! -f $splitdb ]; then echo >&2 "Downloading http://splitting.gm.univ-montp2.fr/DB/public/splittingDB.txt" wget -O - http://splitting.gm.univ-montp2.fr/DB/public/splittingDB.txt | awk 'NR==1 { print $0 " # Downloaded " date ; next } { print}' date=`date -I` > $splitdb fi if [ -n "$DEEP" -o ! -f $splitdbref ]; then echo >&2 "Downloading http://splitting.gm.univ-montp2.fr/DB/public/splittingDB_ref.txt" wget -O - http://splitting.gm.univ-montp2.fr/DB/public/splittingDB_ref.txt | awk 'NR==1 { print $0 " # Downloaded " date ; next } { print}' date=`date -I` > $splitdbref fi if [ -z $RVALUE ]; then RVALUE=`awk '/^-R/ { print substr($0,3) }' .gmtcommands4` fi if [ $GLOBAL ]; then declare -a bounds=(-180 180 -90 90 ) else IFS='/ ' read -r -a bounds <<< $RVALUE fi echo >&2 Processing Null Stations: awk 'BEGIN {FS="|"} NR>1 && $3>=minlat && $3<=maxlat && $4>=minlon && $4<=maxlon {if ($3*$3>0 && ($6==0 || tolower($5) == "null") ) print }' \ minlat=${bounds[2]} maxlat=${bounds[3]} minlon=${bounds[0]} maxlon=${bounds[1]} \ $splitdb > $tmproot.null.txt awk -F"|" '{ print $3, $4 }' $tmproot.null.txt | psxy -S$SNULL -: -W$WNULL $OVERLAY -K -R$RVALUE -J$JVALUE $BVALUE ## CSH-users: pleas add space around the = sign... #Nnull=`awk 'BEGIN {FS="|"}{"NR > 1"}{if ($3*$3>0 && ($6==0 || tolower($5) == "null") ) print $3, $4}' $splitdb |wc -l` Nnull=`cat $tmproot.null.txt | wc -l` echo >&2 $Nnull Null measurements # echo >&2 $tmproot.null.txt # save old gmtcommands4 to preserve -R -and -J setting if [ $LEGEND ]; then \cp .gmtcommands4 $tmproot.gmtcommands4 echo 0 -1.5 | psxy -R0/1/0/1 -Jx1 -S$SNULL -W$WNULL -K -O -N echo 0.5 -1.5 12 0 0 ML "Null station" | pstext -R -J -N -O -K -G0/0/0 echo 4.2 -1.5 90 $LENDELAYONE | psxy -R -J -SVB0.05c/0p/0p -W1 -G$GSPLIT -N -O -K echo 4.7 -1.5 12 0 0 ML "1 s splitting delay"| pstext -R -J -G0/0/0 -N -O -K \mv $tmproot.gmtcommands4 .gmtcommands4 fi echo >&2 Processing Splitting Stations: awk 'BEGIN {FS="|"} NR>1 && $3>=minlat && $3<=maxlat && $4>=minlon && $4<=maxlon {if ($3*$3>0 && $6>0 && tolower($5) != "null" ) print }' \ minlat=${bounds[2]} maxlat=${bounds[3]} minlon=${bounds[0]} maxlon=${bounds[1]} \ $splitdb > $tmproot.split.txt awk -F"|" '{ print $3, $4, $5, ($6*lendelayone)}' lendelayone=$LENDELAYONE $tmproot.split.txt | psxy -SVB0.05c/0p/0p -W1 -: -G$GSPLIT -O $KONTINUE -R -J # Nsplit=`awk 'BEGIN {FS="|"}{"NR > 1"}{if ($3*$3>0 && $6>0 && tolower($5) != "null" ) print $3, $4, $5, ($6*0.2), $6}' $splitdb|wc -l` Nsplit=`cat $tmproot.split.txt | wc -l` echo >&2 $Nsplit Split measurements # assemble references list if [ -z $GLOBAL ]; then awk -F"|" '{ print $7 }' $tmproot.{split,null}.txt | sort | uniq -c | awk 'BEGIN { OFS="|"} { print $2,$1}' > $tmproot.refid sort -k 1b,1 -t"|" $splitdbref | join -t"|" $tmproot.refid - > draw_splitDB_ref.txt echo >&2 "# Reference for compilation:" cat >&2 <&2 "# References for splitting measurements in selected rectangle." awk >&2 -F"|" ' { print $4, "(" $5 ")", $6 ", "$7", "$8 ", "$9, ($10 ~ /^ *$/) ? "" : " doi: " $10, "-", $2, " measurement(s)"}' draw_splitDB_ref.txt echo >&2 "# List of references saved in: draw_splitDB_ref.txt" else echo >&2 "With -g option, automatic reference extraction is disabled. Please check the website manually, which references to give." fi \rm $tmproot.*