Debian Codegraph @

src/gsfml/fzprofiler

raw symbols SCIP
1 #!/bin/bash
2 #--------------------------------------------------------------------
3 # Copyright (c) 2015-2023 by P. Wessel
4 # See LICENSE.TXT file for copying and redistribution conditions.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser General Public License as published by
8 # the Free Software Foundation; version 3 or any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
14 #
15 # Contact info: http://www.soest.hawaii.edu/PT/GSFML
16 #--------------------------------------------------------------------
17 # Bash script to make a single large-format GMT plot of all cross-
18 # profiles for a given FZ segment. We select the dimensions of a
19 # single profile panel and scale up to determine the custom paper
20 # needed.
21 #
22 # Author: Paul Wessel
23 # Date: 01-DEC-2023 (Requires GMT >= 6)
24 # Mode: GMT classic mode
25 #--------------------------------------------------------------------
26
27 . fz_funcs.sh # Load in FZ-specific shell functions
28 if [ $# -eq 0 ]; then
29 version=`fz_get_version`
30 cat << EOF >&2
31 fzprofiler $version - Plot one or all FZ cross-profiles
32
33 Usage: fzprofiler [-H<height>[c|i]] [-I<ID>] [-L<inc>] [-N<ncols>] [-T<prefix>] [-V] [-W<width>[c|i]]
34
35 OPTIONS:
36 -H <height> specify the height of each profile plot.
37 Append units c or i [Default uses PROJ_LENGTH_UNIT].
38 -I Picks a single profile ID to plot (first is 0) [all].
39 -L <inc> sets labeling increment for profiles [1].
40 -N <ncols> sets the number of plot columns [1].
41 -T sets the profile prefix [fztrack].
42 -V Report on progress [quiet].
43 -W <width> specify the width of each profile plot.
44 Append units c or i [Default uses PROJ_LENGTH_UNIT].
45
46 EOF
47 exit
48 fi
49
50 trap 'fz_cleanup 1' 1 2 3 15 # Set interrupt handling
51 #default values
52 ncols=1
53 W=6
54 H=2
55 inc=1
56 P=-1
57 verbose=0
58 prefix=fztrack
59
60 while [ ! x"$1" = x ]; do
61 case $1
62 in
63 -W*) W=`fz_get_dim $1` # Width of each sub-panel with one profile
64 shift;;
65 -H*) H=`fz_get_dim $1` # Height of each sub-panel with one profile
66 shift;;
67 -I*) P=`fz_get_arg $1`; # Specific profile
68 shift;;
69 -L*) inc=`fz_get_arg $1`; # Profile increment
70 shift;;
71 -N*) ncols=`fz_get_arg $1`; # Number of sub-panel columns
72 shift;;
73 -T*) prefix=`fz_get_arg $1` # Get file prefix
74 shift;;
75 -V) verbose=1; # Gave a VGG grid
76 shift;;
77 -*) echo "$0: Unrecognized option $1" 1>&2; # Bad option argument
78 exit 1;;
79 esac
80 done
81
82 XFILE=${prefix}_cross.txt # Cross-profiles file
83 # Make sure we convert to inches
84 . ${prefix}_par.txt # Read and assign parameters for these profiles
85 #------------------------------------------------------------------------------------------------------
86 # All dimensions are now in inches, regardless of what the user's units are.
87 # Cross-profiles have lon,lat,dist,azimuth,vgg,age,fzdist columns.
88 # Assign variables and calculate dimensions (inches used throughout)
89 #------------------------------------------------------------------------------------------------------
90 space=0.50 # Space between columns of panels
91 ymargin=0.75 # Bottom margin
92 xmargin=1 # Left margin
93 zone=`gmt math -Q ${CORR_WIDTH} 0.5 MUL =` # half-width of central corridor
94 n_cross=`gmt convert -L ${XFILE} | wc -l` # Number of cross-profiles
95 ndig=`gmt math -Q ${n_cross} LOG10 FLOOR 1 ADD =` # Number of digits to use for running numbers
96 dmin=`gmt math -Q ${CROSS_LENGTH} 0.5 MUL NEG =` # Only plot the central 50% of the cross profiles
97 dmax=`gmt math -Q ${CROSS_LENGTH} 0.5 MUL =`
98 gmt info ${XFILE} -C -I2/2/2/5/10/10/10/10/10 > $$.info # Get clean multiples of min/max for each column
99 vmin=`cut -f9 $$.info` # Low VGG bounds
100 vmax=`cut -f10 $$.info` # High VGG bounds
101 vinc=`gmt math -Q ${vmax} ${vmin} SUB 50 DIV CEIL 10 MUL =` # VGG scale bar length is ~1/5 the range, in multiples of 10
102 vinc2=`gmt math -Q ${vinc} 2 DIV =` # +- half vinc
103 amin=`cut -f11 $$.info` # Low age bounds
104 amax=`cut -f12 $$.info` # High age bounds
105 range=`gmt math -Q ${vmax} ${vmin} SUB =` # VGG range for this panel
106 if [ ${amin} = "NaN" ]; then
107 got_age=0
108 else
109 got_age=1
110 arange=`gmt math -Q ${amax} ${amin} SUB =` # Age range for this panel
111 am=`gmt math -Q ${amin} ${arange} 0.5 MUL ADD =` # Mid-age value
112 am1=`gmt math -Q ${am} 5 SUB =` # am1/am2 are 1- Myr apart and will serve as age scale bar
113 am2=`gmt math -Q ${am} 5 ADD =`
114 atxt=" and ${arange} Myr (dashed orange line)"
115 fi
116 if [ $P -ge 0 ]; then # Selected to plot a single profile
117 nrows=1 # Obviously only a single row
118 single=1 # TRUE for this case
119 txt=" $P" # Text identifying the profile
120 else
121 P=0 # Do all profiles
122 nrows=`gmt math -Q ${n_cross} ${inc} DIV ${ncols} DIV CEIL =` # The number of rows depends on how many columns we have and how often we plot
123 single=0 # FALSE for this case
124 txt="s" # Text identifying all profiles (plural s)
125 fi
126 height=`gmt math -Q ${H} ${nrows} MUL =` # Height of all panels
127 width=`gmt math -Q ${W} ${ncols} MUL ${ncols} 1 SUB ${space} MUL ADD =` # Width of all plot columns together
128 width2=`gmt math -Q ${width} 2 ${xmargin} MUL ADD =` # PLot width, including margings
129 height2=`gmt math -Q ${height} 2 ${ymargin} MUL ADD =` # Plot height, including margins
130 xu=`gmt math -Q -0.75 1 ${xmargin} SUB ADD =` # Placement x for -U logo and label
131 yu=`gmt math -Q -0.75 1 ${ymargin} SUB ADD =` # Placement y for -U logo and label
132 VB=`gmt math -Q ${vmax} 0.75 MUL =` # VGG-value to use for placement of blend width indicator symbol
133 VT=`gmt math -Q ${vmax} 0.50 MUL =` # VGG-value to use for placement of trough width indicator symbol
134 VD=`gmt math -Q ${vmax} 0.25 MUL =` # VGG-value to use for placement of data width indicator symbol
135 #------------------------------------------------------- -----------------------------------------------
136 # Ready for plotting
137 if [ $verbose -eq 1 ]; then
138 echo "fzprofiler: Papersize is ${width2}i by ${height2}i; vertical range per row panel is $range Eotvos${atxt}." >&2
139 fi
140 #------------------------------------------------------------------------------------------------------
141 # Draw the outline of the combined rowsxcols panels; add title and -U label, using a custom paper size tailored to fit the plot
142 gmt begin ${prefix}_cross pdf
143 gmt basemap -R0/$width/0/$height -Jx1i -Xa${xmargin}i -Ya${ymargin}i -B+gwhite -U/${xu}i/${yu}i/"${prefix}: Cross profile${txt}"
144 let row=9999 # This will be reset to 1 immediately in the loop below
145 let col=0 # This will be reset to 1 in the loop. We start from left-most column (1) and work to the right
146 while [ $P -lt $n_cross ]; do # As long as there are profiles left
147 if [ $verbose -eq 1 ]; then
148 echo "fzprofiler: Plotting profile ${P}" >&2
149 fi
150 let row=row+1 # Go to next row (row = 1 is the first row)
151 if [ ${row} -gt ${nrows} ]; then # Must go to next column
152 let row=1 # Back to the bottom
153 let col=col+1 # Move to next column
154 let frame=1 # Time to plot a basemap again for the entire column
155 if [ ${col} -gt 1 ]; then # Draw the central d = 0 line for the entire column
156 gmt basemap -R${dmin}/${dmax}/0/${height} -JX${W}i/${height}i -Bx0g1000 -By0 -Xa${xpos}i -Ya${ymargin}i
157 fi
158 fi
159 xpos=`gmt math -Q $col 1 SUB $W $space ADD MUL $xmargin ADD =` # Determines the x position of the current panel's LL corner
160 ypos=`gmt math -Q $nrows $row SUB $H MUL $ymargin ADD =` # Determines the y position of the current panel's LL corner
161 xposL=`gmt math -Q $xpos 0.15 SUB =` # We will plot a VGG scale bar 0.15 inches to the left of each panel
162 xposR=`gmt math -Q $xpos 0.15 ADD =` # We will plot an Age scale bar 0.15 inches to the right of each panel
163 if [ ${frame} -eq 1 ]; then # Plot the central corridor in light blue color, annotate the distance axis
164 gmt plot -Glightblue -Bx20f5 -By0 -BwSne -Xa${xpos}i -Ya${ymargin}i --FONT_ANNOT_PRIMARY=10 --FONT_LABEL=14 <<- EOF
165 -${zone} 0
166 ${zone} 0
167 ${zone} $height
168 -${zone} $height
169 EOF
170 let frame=0
171 fi
172 gmt convert -Q${P} ${XFILE} > $$.raw # Extract the profile to plot (includes the segment header)
173 header=`head -1 $$.raw` # Get this cross profile's header
174 # Pull out several parameter values from the segment header, via strings such as WD=25
175
176 az=`fz_get_item "${header}" az` # Extract the azimuth of this profile
177 mb=`fz_get_item "${header}" mb` # Extract the blend parameter for best-fitting model
178 OB=`fz_get_item "${header}" OB` # Extract the offset parameter for best-fitting blend model
179 WB=`fz_get_item "${header}" WB` # Extract the width parameter for best-fitting blend model
180 UB=`fz_get_item "${header}" UB` # Extract the compression parameter for best-fitting blend model
181 OT=`fz_get_item "${header}" OT` # Extract the offset parameter for best-fitting trough model
182 WT=`fz_get_item "${header}" WT` # Extract the width parameter for best-fitting trough model
183 UT=`fz_get_item "${header}" UT` # Extract the compression parameter for best-fitting trough model
184 OD=`fz_get_item "${header}" OD` # Extract trough location parameter for the data
185 WD=`fz_get_item "${header}" WD` # Extract the width estimate of the data trough
186 OE=`fz_get_item "${header}" OE` # Extract the offset parameter for best-fitting edge model
187 WT2=`gmt math -Q $WT 0.5 MUL =` # Compute half-widths
188 WB2=`gmt math -Q $WB 0.5 MUL =`
189 northsouth=`gmt math -Q $az ABS 45 LE =` # Determine if profile is mostly E-W or S-N
190 if [ ${northsouth} -eq 1 ]; then # It is mostly S to N
191 L="S"
192 R="N"
193 else # It is mostly E to W
194 L="W"
195 R="E"
196 fi
197 # Build a polygon the plot as lightcyan the +- 2 sigma uncertainty on the trough location OT
198 echo ${OT} ${WT} ${vmin} ${vmax} | awk '{printf "%g\t%s\n%g\t%s\n%g\t%s\n%g\t%s\n", $1-0.5*$2/3, $3, $1+0.5*$2/3, $3, $1+0.5*$2/3, $4, $1-0.5*$2/3, $4}' > $$.w
199 y=`gmt math -Q ${P} ${H} MUL 1 ADD =`
200 # Plot the uncertainty area on OT as lightcyan
201 gmt plot -R${dmin}/${dmax}/${vmin}/${vmax} -JX${W}i/${H}i -Bx0 -Byf1000g1000 -Bwe $$.w -Glightcyan -Xa${xpos}i -Ya${ypos}i
202 # Plot the data as red circles connected by a thin dotted red line
203 gmt plot $$.raw -i2,4 -Wthinnest,red,. -Xa${xpos}i -Ya${ypos}i
204 gmt plot $$.raw -i2,4 -Sc0.04i -Gred -Xa${xpos}i -Ya${ypos}i
205 # Plot the trough model as thin solid green3 line
206 gmt plot $$.raw -i2,7 -B0 -Bsn -Wthin,green3 -Xa${xpos}i -Ya${ypos}i --MAP_FRAME_PEN=faint
207 # Plot the blend model as thin blue line
208 gmt plot $$.raw -i2,8 -Wthin,blue -Xa${xpos}i -Ya${ypos}i
209 if [ ${got_age} -eq 1 ]; then
210 # Plot the crustal ages as thin dashed orange line
211 gmt plot $$.raw -i2,5 -R${dmin}/${dmax}/${amin}/${amax} -Wthin,orange,- -Xa${xpos}i -Ya${ypos}i
212 fi
213 # Place width error-bar and trough symbol for the blend model
214 echo ${OB} ${VB} ${WB2} | gmt plot -R${dmin}/${dmax}/${vmin}/${vmax} -Ex+pthin,blue -Gblue -Wthinnest -Si0.075i -Xa${xpos}i -Ya${ypos}i
215 # Place width error-bar and trough symbol for the trough model
216 echo ${OT} ${VT} ${WT2} | gmt plot -Ex+pthin,green3 -Wthinnest -Si0.075i -Ggreen3 -Xa${xpos}i -Ya${ypos}i
217 # Place width error-bar and max-slope (edge) symbol for the blend model
218 echo ${OE} 0.0 | gmt plot -Wthinnest -Sc0.075i -Gblue -Xa${xpos}i -Ya${ypos}i
219 if [ "${WD}" = "NaN" ] || [ "${WD}" = "nan" ]; then # Cannot do it
220 echo "WD is NaN - skipped" >&2
221 else
222 WD2=`gmt math -Q $WD 0.5 MUL =` # Compute half-width
223 echo ${OD} ${VD} ${WD2} | gmt plot -Ex+pthin,red -Wthinnest -Si0.075i -Gred -Xa${xpos}i -Ya${ypos}i
224 fi
225 # Place profile ID in upper-left corner of panel
226 echo "${dmin} ${vmax} LT ${P}" | gmt text -Dj0.05i -C0.01i -F+f7p,Helvetica,white+a0+j -Gblack -To -W0.5p -Xa${xpos}i -Ya${ypos}i
227 # Write blend value in upper-right corner of panel
228 echo "${dmax} ${vmax} RT @;green3;u@-t@- = ${UT}@;; @;blue;u@-b@- = $UB m = ${mb}@;;" | gmt text -Dj0.05i -F+f7p,Helvetica+a0+j -Xa${xpos}i -Ya${ypos}i
229 # Write the W-E or S-N labels on left/right side of the top of the panel
230 echo "${dmin} ${vmax} LT ${L}" | gmt text -Dj0.05i/0.2i -F+f12p,Helvetica-Bold+a0+j -Xa${xpos}i -Ya${ypos}i
231 echo "${dmax} ${vmax} RT ${R}" | gmt text -Dj0.05i/0.2i -F+f12p,Helvetica-Bold+a0+j -Xa${xpos}i -Ya${ypos}i
232 # Draw $vinc Eotvos scale bar to the left of the panel
233 gmt plot -W2p,red -Xa${xposL}i -Ya${ypos}i <<- EOF
234 ${dmin} -${vinc2}
235 ${dmin} ${vinc2}
236 EOF
237 # Label the VGG scale bar with "$vinc"
238 echo ${dmin} 0 ${vinc} | gmt text -F+f6p,Helvetica+a0+jCM -C0.01i -Gwhite -To -W0.5p -N -Xa${xposL}i -Ya${ypos}i
239 if [ ${got_age} -eq 1 ]; then
240 # Draw 10 Myr scale bar to the right of the panel
241 gmt plot -R${dmin}/${dmax}/${amin}/${amax} -W2p,orange -Xa${xposR}i -Ya${ypos}i <<- EOF
242 ${dmax} ${am1}
243 ${dmax} ${am2}
244 EOF
245 # Label the age scale bar with "10"
246 echo ${dmax} ${am} 10 | gmt text -F+f6p,Helvetica+a0+jCM -C0.01i -Gwhite -To -W0.5p -N -Xa${xposR}i -Ya${ypos}i
247 fi
248 if [ ${single} -eq 1 ]; then # Set P to last profile so the loop will exit immediately
249 P=${n_cross}
250 else # March on to the next profile
251 let P=P+inc
252 fi
253 done
254 # Finalize plot by drawing the d = 0 line for the last panel
255 gmt basemap -R${dmin}/${dmax}/0/${height} -JX${W}i/${height}i -Bx0g1000 -By0 -Xa${xpos}i -Ya${ymargin}i
256 gmt end show
257 if [ ${verbose} -eq 1 ]; then
258 echo "fzprofiler: Final plot is called ${prefix}_cross.pdf" >&2
259 fi
260
261 fz_cleanup 1