18 |
|
my $legwidth = 100; # Legend width and height |
19 |
|
my $legheight = 200; |
20 |
|
my $docont = ''; # Contours |
21 |
< |
my $loff = 0; # Offset for drop-shadow |
21 |
> |
my $loff = 0; # Offset to align with values |
22 |
|
my $doextrem = 0; # Don't mark extrema |
23 |
|
my $needfile = 0; |
24 |
|
|
76 |
|
# Switches |
77 |
|
} elsif ("$ARGV[0]" eq '-cl') { # Contour lines |
78 |
|
$docont = 'a'; |
79 |
< |
$loff = 12; |
79 |
> |
$loff = 0.48; |
80 |
|
} elsif ("$ARGV[0]" eq '-cb') { # Contour bands |
81 |
|
$docont = 'b'; |
82 |
< |
$loff = 13; |
82 |
> |
$loff = 0.52; |
83 |
|
} elsif ("$ARGV[0]" eq '-e') { |
84 |
|
$doextrem = 1; |
85 |
|
$needfile = 1; |
95 |
|
my $td = tempdir( CLEANUP => 1 ); |
96 |
|
|
97 |
|
if ($needfile == 1 && $picture eq '-') { |
98 |
< |
$picture = $td . '/' . $picture; |
98 |
> |
# Pretend that $td/stdin.rad is the actual filename. |
99 |
> |
$picture = "$td/stdin.hdr"; |
100 |
|
open(FHpic, ">$picture") or |
101 |
|
die("Unable to write to file $picture\n"); |
102 |
+ |
# Input is from STDIN: Capture to file. |
103 |
+ |
while (<>) { |
104 |
+ |
print FHpic; |
105 |
+ |
} |
106 |
|
close(FHpic); |
107 |
+ |
|
108 |
+ |
if ($cpict eq '-') { |
109 |
+ |
$cpict = "$td/stdin.hdr"; |
110 |
+ |
} |
111 |
|
} |
112 |
|
|
113 |
|
# Find a good scale for auto mode. |
114 |
|
if ($scale =~ m/[aA].*/) { |
115 |
< |
my $LogLmax = `phisto $picture| tail -2| sed -n '1s/[0-9]*\$//p'`; |
115 |
> |
my @histo = split(/\s/, `phisto $picture| tail -2`); |
116 |
> |
# e.g. $ phisto tests/richmond.hdr| tail -2 |
117 |
> |
# 3.91267 14 |
118 |
> |
# 3.94282 6 |
119 |
> |
my $LogLmax = $histo[0]; |
120 |
|
$scale = $mult / 179 * 10**$LogLmax; |
121 |
|
} |
122 |
|
|
123 |
< |
my $pc0 = $td . '/pc0.cal'; |
123 |
> |
my $pc0 = "$td/pc0.cal"; |
124 |
|
open(FHpc0, ">$pc0"); |
125 |
|
print FHpc0 <<EndOfPC0; |
126 |
|
PI : 3.14159265358979323846 ; |
187 |
|
bo = if(in,clip($bluv),ba); |
188 |
|
EndOfPC0 |
189 |
|
|
190 |
< |
my $pc1 = $td . '/pc1.cal'; |
190 |
> |
my $pc1 = "$td/pc1.cal"; |
191 |
|
open(FHpc1, ">$pc1"); |
192 |
|
print FHpc1 <<EndOfPC1; |
193 |
|
norm : mult/scale/le(1); |
226 |
|
} |
227 |
|
|
228 |
|
# Colours in the legend |
229 |
< |
my $scolpic = $td . '/scol.hdr'; |
229 |
> |
my $scolpic = "$td/scol.hdr"; |
230 |
|
# Labels in the legend |
231 |
< |
my $slabpic = $td . '/slab.hdr'; |
231 |
> |
my $slabpic = "$td/slab.hdr"; |
232 |
|
my $cmd; |
233 |
|
|
234 |
< |
if ($legwidth > 20 && $legheight > 40) { |
222 |
< |
# Legend: Create the background colours |
223 |
< |
$cmd = "pcomb $pc0args -e 'v=(y+.5)/yres;vleft=v;vright=v'"; |
224 |
< |
$cmd .= " -e 'vbelow=(y-.5)/yres;vabove=(y+1.5)/yres'"; |
225 |
< |
$cmd .= " -x $legwidth -y $legheight > $scolpic"; |
226 |
< |
system $cmd; |
227 |
< |
|
234 |
> |
if (($legwidth > 20) && ($legheight > 40)) { |
235 |
|
# Legend: Create the text labels |
236 |
|
my $sheight = floor($legheight / $ndivs + 0.5); |
237 |
+ |
$legheight = $sheight * $ndivs; |
238 |
+ |
$loff = floor($loff * $sheight + 0.5); |
239 |
|
my $text = "$label"; |
240 |
< |
my $value; |
232 |
< |
my $i; |
233 |
< |
for ($i=0; $i<$ndivs; $i++) { |
240 |
> |
for (my $i=0; $i<$ndivs; $i++) { |
241 |
|
my $imap = ($ndivs - 0.5 - $i) / $ndivs; |
242 |
+ |
my $value = $scale; |
243 |
|
if ($decades > 0) { |
244 |
< |
$value = $scale * 10**(($imap - 1) * $decades); |
244 |
> |
$value *= 10**(($imap - 1) * $decades); |
245 |
|
} else { |
246 |
< |
$value = $scale * $imap; |
246 |
> |
$value *= $imap; |
247 |
|
} |
248 |
|
# Have no more than 3 decimal places |
249 |
|
$value =~ s/(\.[0-9]{3})[0-9]*/$1/; |
252 |
|
$cmd = "echo '$text' | psign -s -.15 -cf 1 1 1 -cb 0 0 0"; |
253 |
|
$cmd .= " -h $sheight > $slabpic"; |
254 |
|
system $cmd; |
255 |
+ |
|
256 |
+ |
# Legend: Create the background colours |
257 |
+ |
$cmd = "pcomb $pc0args -e 'v=(y+.5)/yres;vleft=v;vright=v'"; |
258 |
+ |
$cmd .= " -e 'vbelow=(y-.5)/yres;vabove=(y+1.5)/yres'"; |
259 |
+ |
$cmd .= " -x $legwidth -y $legheight > $scolpic"; |
260 |
+ |
system $cmd; |
261 |
|
} else { |
262 |
|
# Legend is too small to be legible. Don't bother doing one. |
263 |
|
$legwidth = 0; |
264 |
|
$legheight = 0; |
265 |
+ |
$loff = 0; |
266 |
+ |
# Create dummy colour scale and legend labels so we don't |
267 |
+ |
# need to change the final command line. |
268 |
|
open(FHscolpic, ">$scolpic"); |
269 |
< |
print FHscolpic '\n-Y 1 +X 1\naaa\n'; |
269 |
> |
print FHscolpic "\n-Y 1 +X 1\naaa\n"; |
270 |
|
close(FHscolpic); |
271 |
|
open(FHslabpic, ">$slabpic"); |
272 |
< |
print FHslabpic '\n-Y 1 +X 1\naaa\n'; |
272 |
> |
print FHslabpic "\n-Y 1 +X 1\naaa\n"; |
273 |
|
close(FHslabpic); |
274 |
|
} |
275 |
|
|
276 |
+ |
# Legend: Invert the text labels (for dropshadow) |
277 |
+ |
my $slabinvpic = "$td/slabinv.hdr"; |
278 |
+ |
$cmd = "pcomb -e 'lo=1-gi(1)' $slabpic > $slabinvpic"; |
279 |
+ |
system $cmd; |
280 |
+ |
|
281 |
|
my $loff1 = $loff - 1; |
282 |
|
# Command line without extrema |
283 |
|
$cmd = "pcomb $pc0args $pc1args $picture $cpict"; |
284 |
< |
$cmd .= "| pcompos $scolpic 0 0 +t .1"; |
263 |
< |
$cmd .= " \"\!pcomb -e 'lo=1-gi(1)' $slabpic\" 2 $loff1"; |
284 |
> |
$cmd .= "| pcompos $scolpic 0 0 +t .1 $slabinvpic 2 $loff1"; |
285 |
|
$cmd .= " -t .5 $slabpic 0 $loff - $legwidth 0"; |
286 |
|
|
287 |
|
if ($doextrem == 1) { |
294 |
|
# 211 202 1.292969e+00 1.308594e+00 1.300781e+00 |
295 |
|
|
296 |
|
my @extrema = split(/\s/, $retval); |
297 |
< |
my $lxmin = $extrema[0] + $legwidth; |
298 |
< |
my $ymin = $extrema[1]; |
299 |
< |
my $rmin = $extrema[2]; |
279 |
< |
my $gmin = $extrema[3]; |
280 |
< |
my $bmin = $extrema[4]; |
281 |
< |
my $lxmax = $extrema[5] + $legwidth; |
282 |
< |
my $ymax = $extrema[6]; |
283 |
< |
my $rmax = $extrema[7]; |
284 |
< |
my $gmax = $extrema[8]; |
285 |
< |
my $bmax = $extrema[9]; |
297 |
> |
my ($lxmin, $ymin, $rmin, $gmin, $bmin, $lxmax, $ymax, $rmax, $gmax, $bmax) = @extrema; |
298 |
> |
$lxmin += $legwidth; |
299 |
> |
$lxmax += $legwidth; |
300 |
|
|
301 |
|
# Weighted average of R,G,B |
302 |
|
my $minpos = "$lxmin $ymin"; |
307 |
|
$maxval =~ s/(\.[0-9]{3})[0-9]*/$1/; |
308 |
|
|
309 |
|
# Create the labels for min/max intensity |
310 |
< |
my $minvpic = $td . '/minv.hdr'; |
310 |
> |
my $minvpic = "$td/minv.hdr"; |
311 |
|
$cmd1 = "psign -s -.15 -a 2 -h 16 $minval > $minvpic"; |
312 |
|
system $cmd1; |
313 |
< |
my $maxvpic = $td . '/maxv.hdr'; |
313 |
> |
my $maxvpic = "$td/maxv.hdr"; |
314 |
|
$cmd1 = "psign -s -.15 -a 2 -h 16 $maxval > $maxvpic"; |
315 |
|
system $cmd1; |
316 |
|
|