← Index
Performance Profile   « block view • line view • sub view »
For /wise/base/deliv/dev/bin/framedepth
  Run on Fri May 28 15:23:26 2010
Reported on Fri May 28 15:26:27 2010

File/wise/base/deliv/dev/lib/perl/WISE/PgAitoff.pm
Statements Executed492333
Total Time0.780994000000007 seconds

Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
14736310.195740.39596WISE::PgAitoff::toaitoff
1110.166630.77204WISE::PgAitoff::make_aitoff
14736110.143220.14322WISE::PgAitoff::tocenter
1110.008780.05844WISE::PgAitoff::label_aitoff
749610.006470.02524WISE::PgAitoff::versplot
1110.002840.02277WISE::PgAitoff::color_key
19410.000300.00109WISE::PgAitoff::number
1110.000200.00020WISE::PgAitoff::set_spec_colors
1119.0e-59.0e-5WISE::PgAitoff::set_viewport
1112.6e-50.00028WISE::PgAitoff::normalize_coord
1112.5e-52.5e-5WISE::PgAitoff::allsky
1111.4e-51.4e-5WISE::PgAitoff::londiff
00000WISE::PgAitoff::BEGIN
00000WISE::PgAitoff::annot_int
00000WISE::PgAitoff::cliptoedge
00000WISE::PgAitoff::color_map
00000WISE::PgAitoff::cursor
00000WISE::PgAitoff::fromaitoff
00000WISE::PgAitoff::fromcenter
00000WISE::PgAitoff::max
00000WISE::PgAitoff::min
00000WISE::PgAitoff::onplot
00000WISE::PgAitoff::pick
00000WISE::PgAitoff::plot_grid
00000WISE::PgAitoff::rev_color_map
00000WISE::PgAitoff::select_region

LineStmts.Exclusive
Time
Avg.Code
1#! /usr/bin/env perl
2
333.8e-51.3e-5use strict;
# spent 12µs making 1 call to strict::import
435.8e-51.9e-5use warnings;
# spent 50µs making 1 call to warnings::import
5
6# $Id: PgAitoff.pm 7889 2010-05-13 01:42:18Z tim $
7
834.2e-51.4e-5use WISE::Env (cfglib=>'/wise/base/deliv/dev/lib/perl');
# spent 468µs making 1 call to WISE::Env::import
9
10package WISE::PgAitoff;
11
1233.3e-51.1e-5use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
# spent 74µs making 1 call to vars::import
13
1436.6e-52.2e-5use Exporter;
# spent 68µs making 1 call to Exporter::import
1512.0e-62.0e-6$VERSION = 1.00;
1611.1e-51.1e-5@ISA = qw(Exporter);
17
1811.0e-61.0e-6@EXPORT = qw();
19
2011.0e-61.0e-6%EXPORT_TAGS = ();
21
2211.0e-61.0e-6@EXPORT_OK = ('make_aitoff');
23
2430.001050.00035use PGPLOT;
# spent 600µs making 1 call to Exporter::import
25
2630.001140.00038use WISE;
# spent 201ms making 1 call to WISE::import
2736.8e-52.3e-5use WISE::CoUtils ('$R2D','cconv');
# spent 166µs making 1 call to Exporter::import
2830.006690.00223use WISE::CoUtilsXS;
# spent 147µs making 1 call to Exporter::import
29
3012.0e-62.0e-6my @ccoord = ('Equatorial Coordinates',
31 'Galactic Coordinates',
32 'Ecliptic Coordinates');
33
3411.0e-61.0e-6my (%color_vals, @colors, $lowc);
35
3611.0e-61.0e-6my $aitoffdx = 360; # Full width of converted aitoff x values;
37
3811.0e-61.0e-6my $err = "*** PgAitoff";
39100my $warn = "=== PgAitoff";
40
4111.0e-61.0e-6my %popts;
42100my %popts0;
43
44
# spent 772ms (167+605) within WISE::PgAitoff::make_aitoff which was called # once (167ms+605ms) at line 320 of /wise/base/deliv/dev/bin/framedepth
sub make_aitoff {
45
4613.2e-53.2e-5 %popts = %{ $_[0] || {} };
47
4811.2e-51.2e-5 %popts0 = %popts; # Save original values
49
5015.0e-65.0e-6 my ($minlbl,$max,$step,$interacting,$hard,
51 $lon0,$lat0,$plon0,$plat0,$px0,$px1,$py0,$py1,$dt,$fovsym,$fovsz,
52 $pgmain,$interactive_pdev,$printing,$pfile_seq);
53
54 # Setup
5512.0e-62.0e-6 my $verbose = $popts{verbose} || 0;
5612.0e-62.0e-6 my $pfile = $popts{pfile} || "";
5712.0e-62.0e-6 my $pdev = $popts{pdev} || '/xs';
5812.0e-62.0e-6 my $coord = $popts{coord} || 'equ';
5912.0e-62.0e-6 my $refdat = $popts{date} || "";
6012.0e-62.0e-6 my $keytitle= $popts{keyttl} || "";
6112.0e-62.0e-6 my $keylbls = $popts{keylbls} || [];
6213.0e-63.0e-6 my $nogrid = $popts{nogrid} || 0;
6312.0e-62.0e-6 my $binmark = $popts{binmark} || 16; # Mark for a filled, color-coded bin.
6411.0e-61.0e-6 my $colormap= $popts{colmap}; # Map of bin value to color
6514.0e-64.0e-6 $colormap = undef if $colormap && ! %$colormap; # For faster boolean testing
66 # Color plot order;
67 # 0=color index order,
68 # >0=color key order, low-to-high,
69 # <0=color key order, high to low
7012.0e-62.0e-6 my $corder = $popts{corder} // 0;
7112.0e-62.0e-6 my $spec = $popts{spec}; # Use pseudo-spectral color table
72
73 # What to plot
7412.0e-62.0e-6 my $binx = $popts{'x'} || []; # Longitudes
7512.0e-62.0e-6 my $biny = $popts{'y'} || []; # Latitudes
7611.0e-61.0e-6 my $binvals = $popts{'z'} || []; # Colors
7712.0e-62.0e-6 my $binmarks= $popts{'m'}; # Markers
7813.6e-53.6e-5 my $binsz = $popts{binsz} || 1; # degrees
79
8012.0e-62.0e-6 $binvals = [ (1) x @$binx ] if ! @$binvals;
81
8211.0e-51.0e-5 die "$err: Unequal x,y,z array sizes.\n"
83 if (@$binx != @$biny) || (@$binvals != @$binx);
84
85 # Set up color spectral table (the @colors array and %color_vals hash)
8619.0e-69.0e-6 set_spec_colors();
# spent 197µs making 1 call to WISE::PgAitoff::set_spec_colors
87
88
8911.0e-61.0e-6 PLOT: {
90
9111.0e-61.0e-6 print "\nPlot device = $pfile$pdev ...\n" if $verbose;
92
93 # Pull out plot options
94 # Accept other canonical coordinate system names
9511.1e-51.1e-5 $coord = normalize_coord($coord);
# spent 282µs making 1 call to WISE::PgAitoff::normalize_coord
9611.0e-61.0e-6 $coord=2,warn("$warn: Defaulting coordinate to galactic.\n")
97 if ! $coord;
9811.0e-61.0e-6 my $log = $popts{log}; # Log-scale the colors
9911.0e-61.0e-6 my $nokey = $popts{nokey}; # Suppress color-key
100 # Constants for now (except lborder gets reduced when $nokey is true)
10111.0e-61.0e-6 my $lborder = 0.15; # Fraction of viewport to leave empty at left
10211.0e-61.0e-6 $lborder = .05 if $nokey;
10311.1e-51.1e-5 my $rborder = 0.10; # Fraction of viewport to leave empty at right
104100 my $bborder = 0.10; # Fraction of bottom to leave empty
10511.0e-61.0e-6 my $tborder = 0.10; # Fraction of top to leave empty
10611.0e-61.0e-6 $lon0 = $popts{lon0} || 0; # Aitoff proj center lon
10712.0e-62.0e-6 $lat0 = $popts{lat0} || 0; # Aitoff proj center lat
10811.0e-51.0e-5 $fovsym = $popts{fovsym} || 25; # Symbol for FOV plotting
109100 my $pole = $popts{pole} || 0; # Polar projection
11012.0e-62.0e-6 my $margin = defined $popts{margin} ? $popts{margin} : 0; # Degrees
11111.0e-61.0e-6 my $fixproj = $popts{fixproj}; # Don't change proj center on zoom
112100 my $notext = $popts{notext}; # Suppress text for symbol plots
11312.0e-62.0e-6 my $papwidth = $popts{papxwidth}; # Canvas width (or height)
11411.0e-61.0e-6 my $papaspect= $popts{papasp} || 0.77; # Canvas aspect
11511.0e-61.0e-6 my $revcoord = ! $popts{norev}; # Reverse coordinate axes
11611.0e-61.0e-6 my $pltaspect= $popts{plotasp} || 0; # Default picked below
11711.0e-61.0e-6 my $toptitle = $popts{title};
11811.3e-51.3e-5 my $title = $popts{subtitle};
11913.0e-63.0e-6 my ($x0,$x1,$y0,$y1) = @popts{qw/x0 x1 y0 y1/}; # World plot limits
120 # Default plot limits to all-sky and massage
12111.0e-61.0e-6 $x0 = 0 if ! defined $x0;
12211.1e-51.1e-5 $x1 = 360 if ! defined $x1;
12311.0e-61.0e-6 $y0 = -90 if ! defined $y0;
12411.0e-61.0e-6 $y1 = 90 if ! defined $y1;
125100 $x0 += 360 if $x0<0;
12611.0e-61.0e-6 $x1 += 360 if $x1<0;
12711.0e-61.0e-6 ($y0,$y1) = ($y1,$y0) if $y1 < $y0;
128 # Check that plot limits and projection center can play well together.
12912.1e-52.1e-5 my $allsky = allsky($x0,$x1,$y0,$y1); # Plot is nearly the whole sky
# spent 25µs making 1 call to WISE::PgAitoff::allsky
13011.0e-61.0e-6 ($x0,$x1,$y0,$y1) = (0,360,-90,90) if $allsky;
13111.0e-61.0e-6 $lat0=0,warn "$warn: lat0=$lat0 illegal in all-sky mode; set to 0.\n"
132 if $allsky && $lat0 != 0;
133 # Establish projection center
13411.0e-61.0e-6 ($plon0,$plat0) = ($lon0,$lat0);
13511.0e-61.0e-6 if (! $pole && ! $fixproj && ! $allsky) {
136 $plat0 = ($y0+$y1)/2;
137 $plon0 = $x0 + londiff($x0,$x1)/2;
138 $plon0 -= 360 if $plon0 > 360;
139 }
140
141 # Optimize plot space usage if plot aspect is set to -1.
14211.0e-61.0e-6 $pltaspect= ((1-$tborder)-$bborder)/((1-$rborder)-$lborder)*$papaspect
143 if $pltaspect == -1;
144
145 # Open plot device and begin plotting
146
147 # Hardcopy?
14816.0e-66.0e-6 $hard = 1 if $pdev =~ m@/([vc]*)(ps|gif|latex|pgmf|png|ppm|wd)$@i;
149
150 # Establish real-world aspect ratio, if it hasn't been manually fixed
15112.0e-62.0e-6 if($pole) {
152 $pltaspect ||= 0.6;
153 } else {
15411.7e-51.7e-5 $pltaspect ||= ($y1-$y0)/(londiff($x0,$x1)*cos(($y0+$y1)/2/$R2D));
# spent 14µs making 1 call to WISE::PgAitoff::londiff
155 }
15611.0e-61.0e-6 my $xmarg = $margin;
15711.0e-61.0e-6 my $ymarg = $margin*$pltaspect;
158
159 # Get plot boundaries; units are aitoff-projected x,y.
160
161100 if (! $allsky) {
162 if(! $pole) {
163 # Massage plot boundaries to account for the fact that the
164 # aitoff converter always returns points with values from -180
165 # - 180 around $lon0.
166 #($px0,$py0) = tocenter($px0,$plon0,$py0,$plat0);
167 #($px1,$py1) = tocenter($px1,$plon0,$py1,$plat0);
168 ($px0,$py0) = toaitoff($x0,$y0,$aitoffdx/2,$plon0,$plat0);
169 ($px1,$py1) = toaitoff($x1,$y1,$aitoffdx/2,$plon0,$plat0);
170 } else {
171 # Totally different (kludgy) tactic needed for polar plots
172 my $d = ($y1-$y0)/$pltaspect;
173 $d = $d > 89 ? 89 : $d;
174 ($y0,$y1,$pole) = $y0 > 0 ? ($y0,90,1) : (-90,$y1,-1);
175 my $ty = $y0 > 0 ? $y1-$d : $y0+$d;
176 ($px0,$py0) = toaitoff(150,$ty,$aitoffdx/2,
177 $plon0,$plat0,$pole);
178 ($px1,$py1) = toaitoff(330,$ty,$aitoffdx/2,
179 $plon0,$plat0,$pole);
180 $ymarg ||= $d;
181 #print "$y0,$y1,$d,$ty,$px0,$px1,$py0,$py1\n";
182 }
183 ($px1,$px0) = ($px0,$px1) if $px0 > $px1;
184 ($py1,$py0) = ($py0,$py1) if $py0 > $py1;
185 } else {
186 # All-sky
18712.0e-62.0e-6 ($px0,$px1,$py0,$py1) = (-180,180,-90,90);
188 }
189
190 # Set custom viewport to match the desired aspect ratio and leave
191 # room around the edge, as requested in the border parameters.
19211.1e-51.1e-5 my ($xvp,$yvp,$newpapaspect) = set_viewport($pltaspect,$papaspect,
# spent 90µs making 1 call to WISE::PgAitoff::set_viewport
193 $lborder,$rborder,
194 $bborder,$tborder,
195 ($popts{plotasp}
196 ? 0 # No canvas rotation
197 : 1 # Allowed to rotate
198 )
199 );
200
201 # Set canvas size and aspect.
20211.0e-61.0e-6 $papwidth = $papwidth && $papwidth > 0 ? $papwidth
203 : $hard ? 10
204 : 10;
205
20611.0e-61.0e-6 $papwidth = $newpapaspect>1 ? $papwidth/$newpapaspect : $papwidth;
207
208 # Open plot device and initialize
209
21011.0e-61.0e-6 pgend() if $pgmain && $interacting;
21110.039680.03968 $pgmain = pgbeg(0,$pfile.$pdev,1,1);
# spent 39.7ms making 1 call to PGPLOT::pgbeg
21212.0e-62.0e-6 die "$err: Couldn't open PGPLOT device $pfile$pdev.\n"
213 if $pgmain != 1;
214
21510.001650.00165 pgpap($papwidth,$newpapaspect);
# spent 1.65ms making 1 call to PGPLOT::pgpap
216
217 # Get viewport corners
21811.4e-51.4e-5 my ($vx0,$vx1,$vy0,$vy1) = ($lborder,$lborder+$xvp,
219 $bborder,$bborder+$yvp);
220
22114.0e-64.0e-6 my $bestasp = (1-$tborder-$bborder)/(1-$rborder-$lborder);
22211.0e-61.0e-6 my $bestskyasp = $bestasp*$papaspect;
223
224 # Derive viewport aspect, in canvas units and real world units
22511.0e-61.0e-6 my $vpaspect = ($vy1-$vy0)/($vx1-$vx0);
22611.0e-61.0e-6 my $vpaspectreal = $vpaspect*$newpapaspect;
227
22811.0e-61.0e-6 if(! $hard) {
229 # Plot black on white background
23010.097680.09768 pgscr(0,1.,1.,1.);
# spent 97.7ms making 1 call to PGPLOT::pgscr
23110.001940.00194 pgscr(1,0.,0.,0.);
# spent 1.93ms making 1 call to PGPLOT::pgscr
232 }
233
234 # Set spectral color indices in PGPLOT
23513.0e-63.0e-6 if($spec) {
23611.0e-51.0e-5 for my $ci (keys %color_vals) {
237163.0e-51.9e-6 my ($red,$green,$blue) = @{$color_vals{$ci}};
238160.000127.7e-6 pgscr($ci,$red,$green,$blue);
# spent 77µs making 16 calls to PGPLOT::pgscr, avg 5µs/call
239 }
240 }
241 # .... otherwise use default pgplot colors
242
243 # Set viewport
24412.0e-52.0e-5 pgsvp($vx0,$vx1,$vy0,$vy1);
# spent 19µs making 1 call to PGPLOT::pgsvp
245
246 # Set window world coordinate limits
24713.7e-53.7e-5 pgswin($revcoord?($px1,$px0):($px0,$px1),$py0,$py1);
# spent 24µs making 1 call to PGPLOT::pgswin
248
249 # Get height of 1 character in world corrd.s
25011.0e-61.0e-6 my (@xbox,@ybox);
25111.6e-51.6e-5 pgsch(1);
# spent 15µs making 1 call to PGPLOT::pgsch
25214.8e-54.8e-5 pgqtxt (50,50, 0, 0, "X", \@xbox, \@ybox);
# spent 44µs making 1 call to PGPLOT::pgqtxt
25311.0e-61.0e-6 $dt = $ybox[1]-$ybox[0];
254
25511.0e-61.0e-6 print "\tSky corners (lon0,lon1,lat0,lat1) = $x0, $x1, $y0, $y1\n".
256 "\tProjection center (lon,lat) = $plon0, $plat0\n",
257 "\tPlot corners (x0,x1,y0,y1) = $px0, $px1, $py0, $py1\n".
258 "\tSky aspect = $pltaspect, Viewport aspect = $vpaspect, ".
259 "Real aspect = $vpaspectreal\n".
260 "\tView port corners (x0,x1,y0,y1) = $vx0, $vx1, $vy0, $vy1\n".
261 "\tViewport width (inches) = $papwidth\n".
262 "\tPole = $pole\n".
263 ""
264 if $verbose;
265
266 # Plot out a color key to the left of the main plot
26711.0e-51.0e-5 color_key($colormap,$keylbls,$keytitle,$binmark)
# spent 22.8ms making 1 call to WISE::PgAitoff::color_key
268 if ! $nokey && $spec;
269
270 # Plot points
27114.0e-64.0e-6 if(! $popts{nopoints} && @$binx) {
272100 print "Plotting ".@$binx." points ...\n" if $verbose;
27311.0e-61.0e-6 my @pbins = ();
27416.0e-66.0e-6 for my $bin (0..$#{$binx}) {
275140180.012859.2e-7 my $z = $binvals->[$bin];
276140180.007445.3e-7 my ($c,$ci);
277140180.013929.9e-7 if($colormap) {
278140180.010547.5e-7 $c = $colormap->{$z};
279140180.009386.7e-7 $ci = $spec ? $colors[$c] : $z;
280 } else {
281 $ci = $z;
282 }
283140180.007555.4e-7 next if ! defined $ci;
284140180.027301.9e-6 my ($lon,$lat) = ($binx->[$bin],$biny->[$bin]);
285140180.068354.9e-6 my ($x,$y) = toaitoff($lon,$lat,$aitoffdx/2,
# spent 373ms making 14018 calls to WISE::PgAitoff::toaitoff, avg 27µs/call
286 $plon0,$plat0,$pole);
287 # Separate bins by map color for faster plotting
288140180.015081.1e-6 push @{ $pbins[$ci]{'x'} }, $x;
289140180.010517.5e-7 push @{ $pbins[$ci]{'y'} }, $y;
290140180.016921.2e-6 push @{ $pbins[$ci]{'m'} }, $binmarks->[$bin] if $binmarks;
291 }
292
293 # Get the size of the colored, filled box to plot to represent
294 # a bin
29513.0e-63.0e-6 my $binmarkszsky = $binsz/($py1-$py0)*3*40;
296 # ^^^^ (These constants
297 # almost fill the bin when $binfill is 1. They were arrived at
298 # empirically.)
299
300 # Fraction of the physical bin size to fill with color.
30113.0e-63.0e-6 my $binfill = $popts{binfill}
302 || ($hard # Print needs better saturation
303 ? ($binmarkszsky < 0.1
304 ? 0.1/$binmarkszsky # Min at 0.1
305 : $binmarkszsky)
306 : 0.25);
30711.0e-61.0e-6 my $binmarksz = $popts{binmarksz} || $binmarkszsky*$binfill;
30811.6e-51.6e-5 pgsch($binmarksz);
# spent 14µs making 1 call to PGPLOT::pgsch
309
310 # Plot the bins in color index order
31114.7e-54.7e-5 pgstbg(0);
# spent 34µs making 1 call to PGPLOT::pgstbg
31211.8e-51.8e-5 my @ci = grep {$pbins[$_]} 0..$#pbins;
31313.0e-63.0e-6 if($corder && $colormap) {
31410.000720.00072 my %revmap = reverse %$colormap;
31516.9e-56.9e-5 my %invcolors = map { ($colors[$_] => $_) } 0..$#colors;
31613.5e-53.5e-5 @ci = sort {$revmap{$invcolors{$a}} <=> $revmap{$invcolors{$b}}} @ci;
31711.0e-51.0e-5 @ci = reverse @ci if $corder < 0;
318 }
31910.001280.00128 for my $ci (@ci) {
320101.6e-51.6e-6 my $nplotbins = scalar(@{$pbins[$ci]{'x'}});
321106.8e-56.8e-6 pgsci($ci);
# spent 54µs making 10 calls to PGPLOT::pgsci, avg 5µs/call
322101.3e-51.3e-6 my $mark = $pbins[$ci]{'m'} ? $pbins[$ci]{'m'} : $binmark;
323102.4e-52.4e-6 if(ref $mark) {
324 # Marks are different per point, so we must plot one
325 # at a time
326 for my $i (0..$nplotbins-1) {
327 pgpt1($pbins[$ci]{'x'}[$i],$pbins[$ci]{'y'}[$i],
328 $mark->[$i]);
329 }
330 } else {
331100.009500.00095 pgpt($nplotbins,$pbins[$ci]{'x'},$pbins[$ci]{'y'},$mark);
# spent 9.47ms making 10 calls to PGPLOT::pgpt, avg 947µs/call
332 }
333 }
334 }
335
336 # Plot the grid.
33714.8e-54.8e-5 if(! $nogrid) {
# spent 58.4ms making 1 call to WISE::PgAitoff::label_aitoff
338 if($allsky) {
339 # Prettier aitoff labeling for all-sky plots.
340 label_aitoff($aitoffdx/2,
341 {lon0=>$plon0,lat0=>$plat0,coord=>$coord,
342 title1=>($toptitle||'')." $refdat",
343 title2=>$title, pole=>$pole,
344 i30=>1,
345 });
346 } else {
347 # Any (reasonable) sky region.
348 plot_grid($x0,$x1,$y0,$y1,$aitoffdx/2,
349 {lon0=>$plon0,lat0=>$plat0,coord=>$coord,
350 xmargin=>$xmarg,ymargin=>$ymarg,
351 title1=>($toptitle||'')." $refdat",
352 title2=>$title, pole=>$pole,
353 });
354 }
355 } # nogrid
356
35716.0e-66.0e-6 if($popts{pick}) {
358 print "\nInteractive ...\n\n" if $verbose;
359 my ($act,$c,$x,$y) = pick($popts{pick},\%popts,\%popts0,
360 $plon0,$plat0,$pole);
361 redo PLOT if $act && $act == 1;
362 return ($c,$x,$y);
363 }
364
365 } # PLOT
366
36711.0e-61.0e-6 if($popts{end}) {
368 pgend();
369 }
370
37117.0e-67.0e-6 return 1;
372
373}
374
375
# spent 282µs (26+256) within WISE::PgAitoff::normalize_coord which was called # once (26µs+256µs) by WISE::PgAitoff::make_aitoff at line 95
sub normalize_coord {
37612.0e-62.0e-6 my $coord = shift;
37711.0e-61.0e-6 my $orig = $coord;
37811.0e-61.0e-6 my $canon;
37921.5e-57.5e-6 eval { $canon = (cconv($coord,0,0))[2] };
# spent 256µs making 1 call to WISE::CoUtils::cconv
38014.0e-64.0e-6 $coord = {equ=>1, gal=>2, ecl=>3}->{$canon};
38111.0e-61.0e-6 warn "$err: Can't use coordinate system '$orig' ($canon).\n"
382 if ! $coord;
383
38411.0e-61.0e-6 return $coord;
385}
386
387# The viewport resulting from this code will be:
388#
389# (0,1) (1,1)
390# +-----------------------------+
391# | > xmax < |
392# > a < > b <
393# |v v +-----------------+ |
394# | dy | | |
395# | ^ +-----------v--+ | |
396# |y > xvp < | |
397# |m | | | |
398# |a | yvp | | |
399# |x | | | |
400# | | | | |
401# |^ v+-----------^--+--+ v |
402# | c >dx< d |
403# | |
404# +----^--------------------^---+
405# (0,0) (1,0)
406#
407# realasp = The real-world aspect ratio desired.
408# canvasasp = Canvas aspect ratio, the relation between view surface
409# coordinates and real-world measurements. I.e. if the paper
410# is 11x8.5", canvasasp = .773, though viewport coord.s go 0-1
411# for both axes. Thus if a given viewport is aspvp, it's
412# real-word aspect ratio is aspvp*papasp.
413#
414# The controlling equations:
415#
416# yvp/xvp = (ymax - dy)/(xmax - dx)
417#
418# yvp/xvp*canvasasp = realasp
419#
420#
421
# spent 90µs within WISE::PgAitoff::set_viewport which was called # once (90µs+0) by WISE::PgAitoff::make_aitoff at line 192
sub set_viewport {
42213.0e-63.0e-6 my ($realasp,$canvasasp,$a,$b,$c,$d,$rotok) = @_;
423 # Maximum viewport dimensions in canvas coordinates.
42413.0e-63.0e-6 my ($xmax,$ymax) = (1-$a-$b, 1-$c-$d); # Max viewport width,height
425 # We wish to find these. These adjust the viewport within the
426 # a,b,c,d margins to make the real-world aspect ratio = pltasp.
427 # At least one will be set to zero; but which one? That's the mystery!
42811.0e-61.0e-6 my ($dx,$dy);
429 # Viewport dimensions in canvas coordinates.
43011.0e-61.0e-6 my (@xvp,@yvp,@asp);
431
432 # There are two possibilities; $dx=0, or $dy=0. If $rotok is true,
433 # we also can try rotating the canvas to see if that improves
434 # space utlizatio. That will give us four possibilites.
435 # We choose the one where xvp*yxp is as large as possible.
436
437 # Set dx to zero and solve for dy.
43811.0e-61.0e-6 $dy = $ymax - $realasp/$canvasasp*$xmax;
439 # Derive resulting viewport.
44011.0e-61.0e-6 push @xvp,$xmax;
44111.0e-61.0e-6 push @yvp,$ymax - $dy;
44211.0e-61.0e-6 push @asp,$canvasasp;
443
444 # Set dy to zero and solve for dx.
44512.0e-62.0e-6 $dx = $xmax - $canvasasp/$realasp*$ymax;
446 # Derive resulting viewport.
44711.0e-61.0e-6 push @xvp,$xmax - $dx;
448100 push @yvp,$ymax;
44911.0e-61.0e-6 push @asp,$canvasasp;
450
45112.0e-62.0e-6 if($rotok) {
452 # Do the same with a rotated canvas
45311.0e-61.0e-6 my $tmpasp = 1./$canvasasp;
454
45511.0e-61.0e-6 $dy = $ymax - $realasp/$tmpasp*$xmax;
45611.0e-61.0e-6 push @xvp,$xmax;
45711.0e-61.0e-6 push @yvp,$ymax - $dy;
458100 push @asp,$tmpasp;
459
46011.0e-61.0e-6 $dx = $xmax - $tmpasp/$realasp*$ymax;
46111.0e-61.0e-6 push @xvp,$xmax - $dx;
46211.0e-61.0e-6 push @yvp,$ymax;
463100 push @asp,$tmpasp;
464 }
465
466 # Pick the winner
46711.0e-61.0e-6 my ($max,$imax);
46815.0e-65.0e-6 for my $i (0..$#xvp) {
46944.0e-61.0e-6 next if $xvp[$i]>$xmax || $yvp[$i]>$ymax;
47023.1e-51.6e-5 my $area = $xvp[$i]*$yvp[$i];
47121.2e-56.0e-6 $max = ! $max || $area>$max ? ($imax=$i,$area) : $max;
472 #printf("%1d: xvp,yvp=%6.4f,%6.4f, asp=%6.4f, area=%6.4f, ".
473 # "max,i=%6.4f,%1d\n",
474 # $i,$xvp[$i],$yvp[$i],$asp[$i],$area,$max,$imax);
475 }
476
47711.0e-61.0e-6 die "$err: No suitable viewport possible.\n" if ! $max;
478
47914.0e-64.0e-6 return ($xvp[$imax], $yvp[$imax], $asp[$imax]);
480}
481
482
483
# spent 197µs within WISE::PgAitoff::set_spec_colors which was called # once (197µs+0) by WISE::PgAitoff::make_aitoff at line 86
sub set_spec_colors {
48411.0e-61.0e-6 my $ci = 16;
485 # This is a little silly, but it's a somewhat self-documenting way
486 # of showing the color selection rational. We could just list the
487 # 10 color mixes explicitly.
48813.0e-63.0e-6 for my $red (0,.5,1) {
48934.0e-61.3e-6 for my $green (0,.5,1) {
49093.1e-53.4e-6 for my $blue (0,.5,1) {
491271.1e-54.1e-7 next if $red==$blue && $green==$blue; # No greys
492242.8e-51.2e-6 next if $red!=0 && $green!=0 && $blue!=0; # No 3 color mixes
493187.0e-63.9e-7 next if $red==.5 && ($green==.5 || $blue==.5); # No colors
494161.0e-56.3e-7 next if $blue==.5 && ($green==.5 || $red==.5); # w/ 2 faint
495157.0e-64.7e-7 next if $green==.5 && ($blue==.5 || $red==.5); # components
496154.0e-52.7e-6 $color_vals{$ci} = [$red,$green,$blue];
497151.5e-51.0e-6 push @colors,$ci;
498152.3e-51.5e-6 ++$ci;
499 }}}
500
50112.0e-62.0e-6 $color_vals{$ci} = [.5,.5,.5];
50211.0e-61.0e-6 $lowc = $ci if ! $popts{nolow};
503 # Reorder
50417.0e-67.0e-6 @colors = (0,23,26,29,30,20,21,22,19,17,24,1);
505}
506
507sub color_map {
508 my ($x,$min,$step,$log) = @_;
509 my @labels = @$min if ref $min;
510 my ($ci,$c);
511 $min ||= 1;
512 $step||= 1;
513 if(@labels) {
514 return 0 if $x<0 || $x > $#labels;
515 $c = $colors[int $x];
516 return $lowc if $lowc && ! defined $c;
517 } else {
518 return $lowc if $lowc && $x<$min;
519 $ci = int(log($x/$min)/$step) if $log;
520 $ci = int(($x-$min)*$step) if ! $log;
521 $c = $ci>=@colors ? $colors[-1] : $colors[$ci];
522 }
523 #print "$x, $min, $step, $log, $ci, $c\n";
524 return $c;
525}
526
527sub rev_color_map {
528 my ($ci,$min,$step,$log) = @_;
529 $min ||= 1;
530 $step||= 1;
531 return $log ? exp($ci*$step)*$min : $ci/$step + $min;
532}
533
534
# spent 22.8ms (2.84+19.9) within WISE::PgAitoff::color_key which was called # once (2.84ms+19.9ms) by WISE::PgAitoff::make_aitoff at line 267
sub color_key {
53512.0e-62.0e-6 my $colormap = shift;
53611.0e-61.0e-6 my $lbls = shift;
53712.0e-62.0e-6 my $title = shift || "";
53811.0e-61.0e-6 my $mark = shift || 16;
53911.1e-51.1e-5 my @labels = @$lbls;
540100 my $text;
54111.0e-61.0e-6 my ($vx0,$vx1,$vy0,$vy1);
54211.4e-51.4e-5 pgqvp(0,$vx0,$vx1,$vy0,$vy1);
# spent 12µs making 1 call to PGPLOT::pgqvp
54311.0e-61.0e-6 my ($x0,$x1,$y0,$y1);
54411.5e-51.5e-5 pgqwin($x0,$x1,$y0,$y1);
# spent 13µs making 1 call to PGPLOT::pgqwin
54511.0e-61.0e-6 my $lblsz = 0.75;
54616.0e-66.0e-6 pgsch($lblsz);
# spent 5µs making 1 call to PGPLOT::pgsch
547100 my ($dtx,$dty);
54811.6e-51.6e-5 pgqcs(4,$dtx,$dty);
# spent 14µs making 1 call to PGPLOT::pgqcs
54913.0e-63.0e-6 my $ystep = ($y1-$y0)/(@colors+1);
55012.0e-62.0e-6 my $xvp2win = ($x1-$x0)/($vx1-$vx0);
55111.0e-61.0e-6 my $yvp2win = ($y1-$y0)/($vy1-$vy0);
55211.0e-61.0e-6 my $x = $x0 - $xvp2win*$vx0*.8;
55311.0e-61.0e-6 my $y = $y1;
55414.0e-64.0e-6 $y -= $ystep*(@colors - grep($_,@labels))/2 if @labels;
555
55611.3e-51.3e-5 pgsclp(0);
# spent 11µs making 1 call to PGPLOT::pgsclp
557
55812.0e-62.0e-6 if($title) {
559 # Put the title of the color key at the bottom
56011.2e-51.2e-5 pgsci(1);
# spent 11µs making 1 call to PGPLOT::pgsci
56117.0e-67.0e-6 pgsch(.75);
# spent 5µs making 1 call to PGPLOT::pgsch
56210.019090.01909 pgptext($x,$y0-$yvp2win*$vy0*.4,0,0,$title);
# spent 19.1ms making 1 call to PGPLOT::pgptext
563 }
56411.0e-61.0e-6 if($lowc) {
565 # Label the out-of-range color at the top
566 pgsci($lowc);
567 pgsch(2);
568 pgpt(1,[$x],[$y],16);
569 pgsci(1);
570 pgsch($lblsz);
571 pgptext($x+$dtx,$y-$dty*.3,0,0,"Out of range");
572 $y -= $ystep;
573 }
574
575 # Label the colors
57611.0e-61.0e-6 my %seen;
57710.000940.00094 for my $bin (sort {$a<=>$b} keys %$colormap) {
5785890.000621.1e-6 my $c = $colormap->{$bin};
5795890.000274.6e-7 next if ! defined $c;
5805890.000325.4e-7 my $ci = $colors[$c] if defined $c;
581 #print "/$bin/$c/$ci/$labels[$c]/\n";
5825890.000498.4e-7 next if ! defined $ci || ! defined $labels[$c] || $seen{$ci}++;
583105.0e-65.0e-7 $text = $labels[$c];
584106.1e-56.1e-6 pgsci($ci);
# spent 45µs making 10 calls to PGPLOT::pgsci, avg 4µs/call
585104.8e-54.8e-6 pgsch(2);
# spent 35µs making 10 calls to PGPLOT::pgsch, avg 3µs/call
586100.000313.1e-5 pgpt(1,[$x],[$y],$mark);
# spent 265µs making 10 calls to PGPLOT::pgpt, avg 26µs/call
587105.1e-55.1e-6 pgsci(1);
# spent 43µs making 10 calls to PGPLOT::pgsci, avg 4µs/call
588104.0e-54.0e-6 pgsch($lblsz);
# spent 29µs making 10 calls to PGPLOT::pgsch, avg 3µs/call
589100.000383.8e-5 pgptext($x+$dtx,$y-$dty*.3,0,0,$text);
# spent 355µs making 10 calls to PGPLOT::pgptext, avg 36µs/call
590101.2e-51.2e-6 $y -= $ystep;
591 }
592
59319.0e-69.0e-6 pgsclp(1);
# spent 8µs making 1 call to PGPLOT::pgsclp
594
59517.0e-67.0e-6 return;
596}
597
598sub cliptoedge {
599 my ($x0,$x1,$y0,$y1) = @_;
600
601 ($y0,$y1,$x0,$x1) = ($y1,$y0,$x1,$x0) if $y0>$y1;
602
603 $x0 = max( 0,$x0);
604 $x1 = min(360,$x1);
605 if(defined $y0) {
606 $y0 = max(-90,$y0);
607 $y1 = min( 90,$y1)
608 };
609
610 return ($x0,$x1,$y0,$y1);
611}
612
613sub select_region {
614
615 my $x0 = shift;
616 my $y0 = shift;
617 my $curs = shift || 2;
618 my $ht = shift || $aitoffdx/2;
619 my $lon0 = shift;
620 my $lat0 = shift;
621 my $pole = shift;
622
623 print "\nRegion select. Middle button cancels.\n";
624
625 pgsci(1);
626
627
628 my (@x)=(0);
629 my (@y)=(0);
630 my $state=0;
631 my $ch;
632
633 if($pole) {
634 @x = (0);
635 @y = ($pole*90);
636 $state = 1;
637 }
638
639 if(defined $x0) {
640 # Use entry values as first corner choice.
641 $state = 1;
642 ($x[0],$y[0]) = ($x0,$y0);
643 }
644
645 while (1) {
646 pgupdt;
647 if($state == 0) { # Corner 1 selection; use point cursor
648 print "Click left button to select upper left corner ...\n";
649 ($ch,$x[0],$y[0]) = cursor( 7,0,1,$x[0],$y[0], undef,undef,
650 $ht,$lon0,$lat0,$pole)
651 or last;
652 } else { # Corner 2 selection; use region cursor
653 $x[1] = $x[0];
654 $y[1] = $y[0];
655 print "Click right button to select lower right corner ...\n"
656 if ! $pole;
657 print "Click right button to select lower latitude ...\n"
658 if $pole;
659 ($ch,$x[1],$y[1]) = cursor($curs,1,1,$x[1],$y[1], $x[0],$y[0],
660 $ht,$lon0,$lat0,$pole)
661 or last;
662 }
663 # Middle button; cancel interaction.
664 if($ch eq "D" || $ch eq "q") {
665 pgsci(1);
666 print "!!! Region select canceled.\n"; return;
667 }
668 # Left button; choose corner 1
669 elsif($ch eq "A") {
670 # No previously chosen corner 1; Set corner 1.
671 if($state == 0) { $state = 1; }
672 # Cancel previously chosen corner 1. Start over.
673 else { $state = 0; }
674 }
675 # Right button; choose corner 2
676 elsif($ch eq "X") {
677 # Both corners in place. We're done.
678 if($state == 1) { last; }
679 # First corner never chosen. Do nothing.
680 else { next; }
681 }
682 # Anything else; Do nothing.
683 else { warn "\n!!! Unrecognized key.\n"; next; }
684 }
685
686 if($state == 0) {
687 warn "!!! Too few window points selected.\n";
688 pgsci(1);
689 return;
690 }
691
692 pgsci(1);
693 return (@x,@y);
694
695}
696
697sub pick {
698 my ($callback,$popts,$popts0,$lon0,$lat0,$pole) = @_;
699 my ($c,$x,$y,$rc,$act);
700 $c = 1;
701 $rc = 1;
702 while(defined $c && $rc) {
703 ($c,$x,$y) = cursor(7,0,0,undef,undef,undef,undef,
704 $aitoffdx/2,$lon0,$lat0,$pole);
705 last if $c =~ /^[q]$/i;
706 warn("\n*** Point out of bounds.\n\n"), next
707 if ! defined $x;
708 if($popts && $c =~ /^[z]$/i) { # Zoom
709 # Zoom
710 my($lon0,$lon1,$lat0,$lat1) =
711 select_region(undef,undef,1,$aitoffdx/2,$lon0,$lat0,$pole);
712 next if ! defined $lon0;
713 ($lon0,$lon1) = ($lon1,$lon0) if $lon0 > $lon1;
714 ($lat0,$lat1) = ($lat1,$lat0) if $lat0 > $lat1;
715 if($lon1 - $lon0 > 180) {
716 $lon1 -= 360;
717 ($lon0,$lon1) = ($lon1,$lon0)
718 }
719 if($lat1 > 85 || $lat0 < -85) {
720 print "Switching to polar view.\n" if ! $popts->{pole};
721 ($lon0,$lon1) = (0,360);
722 $pole = $popts->{pole} = 1;
723 }
724 @{$popts}{qw/x0 x1 y0 y1/} = ($lon0,$lon1,$lat0,$lat1);
725 print "Zooming in on $lon0,$lon1,$lat0,$lat1 ...\n";
726 return 1; # Return to replot
727 } elsif($popts && $popts0 && $c =~ /^[r]$/i) { # Original plot
728 %$popts = %$popts0;
729 return 1;
730 } else { # Everything else
731 $act = 0;
732 if(ref $callback) {
733 $rc = $callback->($c,$x,$y,$popts);
734 } else {
735 print "(x,y) = ($x,$y), char = $c\n";
736 }
737 }
738 }
739 return ($act,$c,$x,$y);
740}
741
742sub cursor {
743 my ($curstype,$zip,$check,$x,$y,$x0,$y0,$ht,$lon0,$lat0,$pole) = @_;
744 my ($ch,$rc,$ci,$xt,$yt);
745
746 $ht ||= 1;
747 $lon0 ||= 0;
748 $lat0 ||= 0;
749
750 pgqci($ci);
751 pgsci(1);
752
753 ($x, $y) = toaitoff($x, $y, $ht,$lon0,$lat0,$pole)
754 if defined $x && defined $y;
755 ($x0,$y0) = toaitoff($x0,$y0,$ht,$lon0,$lat0,$pole)
756 if defined $x0 && defined $y0;
757
758 SELECT: {
759
760 $x ||= 0;
761 $y ||= 0;
762 pgband($curstype,$zip,$x0||0,$y0||0,$x,$y,$ch) or last SELECT;
763
764 ($xt, $yt, $rc) = fromaitoff($x, $y, $ht,$lon0,$lat0,$pole);
765
766 if($check && ! $rc) {
767 warn "\n*** Point ($x,$y) out of bounds. Select again.\n\n";
768 redo SELECT;
769 }
770
771 ($x,$y) = ($xt,$yt);
772
773 } # Select
774
775 pgsci($ci);
776
777 return wantarray ? ($ch,$x,$y,$rc) : $ch;
778}
779
780
# spent 396ms (196+200) within WISE::PgAitoff::toaitoff which was called 14736 times, avg 27µs/call: # 14018 times (184ms+188ms) by WISE::PgAitoff::make_aitoff at line 285, avg 27µs/call # 459 times (7.50ms+7.77ms) by WISE::PgAitoff::label_aitoff at line 978, avg 33µs/call # 259 times (3.82ms+3.96ms) by WISE::PgAitoff::label_aitoff at line 1034, avg 30µs/call
sub toaitoff {
781147360.009956.8e-7 my $lon = shift;
782147360.008055.5e-7 my $lat = shift;
783147360.008775.9e-7 my $ht = shift || 1;
784147360.008826.0e-7 my $lon0 = shift || 0;
785147360.007995.4e-7 my $lat0 = shift || 0;
786147360.007325.0e-7 my $pole = shift;
787
788 #print "\t\t\tbefore lon,lat=$lon,$lat, lon0,lat0=$lon0,$lat0\n";
789147360.061784.2e-6 ($lon,$lat) = tocenter($lon,$lon0,$lat,$lat0,$pole);
# spent 143ms making 14736 calls to WISE::PgAitoff::tocenter, avg 10µs/call
790 # Returned range: x = [-2,2], y = [-1,1]
791147360.082935.6e-6 my ($x,$y) = WISE::CoUtilsXS::aitfwd($lon,$lat);
# spent 57.0ms making 14736 calls to WISE::CoUtilsXS::aitfwd, avg 4µs/call
792147360.012218.3e-7 $x *= $ht/2;
793147360.008425.7e-7 $y *= $ht/2;
794 #print "\t\t\tafter lon,lat=$lon,$lat, x,y=$x,$y\n";
795
796147360.024261.6e-6 return ($x, $y);
797}
798
799sub fromaitoff {
800 my $x = shift;
801 my $y = shift;
802 my $ht = shift || 1;
803 my $lon0 = shift || 0;
804 my $lat0 = shift || 0;
805 my $pole = shift;
806
807 my ($lon,$lat,$rc) = WISE::CoUtilsXS::aitrev($x/($ht/2),$y/($ht/2));
808 #if($::selecting) {
809 # print "--- x,y=$x,$y, ht=$ht, lon0,lat0=$lon0,$lat0\n";
810 # print "--- lon,lat=$lon,$lat, RC=$rc\n";
811 # print "--- lon',lat'=".join(",",fromcenter($lon,$lon0,$lat,$lat0,$pole))."\n";
812 #}
813 return (fromcenter($lon,$lon0,$lat,$lat0,$pole),$rc);
814}
815
816
# spent 143ms within WISE::PgAitoff::tocenter which was called 14736 times, avg 10µs/call: # 14736 times (143ms+0) by WISE::PgAitoff::toaitoff at line 789, avg 10µs/call
sub tocenter {
817147360.008976.1e-7 my $lon = shift;
818147360.008195.6e-7 my $lon0 = shift || 0;
819147360.007455.1e-7 my $lat = shift;
820147360.007935.4e-7 my $lat0 = shift || 0;
821147360.007244.9e-7 my $pole = shift;
822
823147360.006624.5e-7 if($pole) {
824 # Polar projection
825 ($lon,$lat) = WISE::CoUtilsXS::poleover($lon,$lat);
826 #$lon0 = $lat0 = 0;
827 }
828
829147360.013979.5e-7 $lon -= 360 if $lon> $lon0+180;
830147360.009916.7e-7 $lon += 360 if $lon<=$lon0-180;
831
832147360.007635.2e-7 $lon -= $lon0;
833
834147360.008876.0e-7 if(defined $lat) {
835 $lat -= $lat0;
836 }
837
838147360.030452.1e-6 return wantarray ? ($lon,$lat) : $lon;
839}
840
841sub fromcenter {
842 my $lon = shift;
843 my $lon0 = shift || 0;
844 my $lat = shift;
845 my $lat0 = shift || 0;
846 my $pole = shift;
847
848 if($pole) {
849 #$lon0 = $lat0 = 0;
850 }
851
852 $lon += $lon0;
853
854 $lon += 360 if $lon < 0;
855 $lon -= 360 if $lon > 360;
856
857 if(defined $lat) {
858 $lat += $lat0;
859 }
860
861 if($pole) {
862 # Polar projection
863 ($lon,$lat) = WISE::CoUtilsXS::poleoverrev($lon,$lat);
864 }
865
866 $lon += 360 if $lon < 0;
867 $lon -= 360 if $lon > 360;
868
869 return wantarray ? ($lon,$lat) : $lon;
870}
871
872
# spent 14µs within WISE::PgAitoff::londiff which was called # once (14µs+0) by WISE::PgAitoff::make_aitoff at line 154
sub londiff {
87312.0e-62.0e-6 my ($x0,$x1,$cen) = @_;
87411.0e-61.0e-6 my $dx = $x1-$x0;
87512.0e-62.0e-6 $dx = $dx>=0 ? $dx : 360+$dx;
876100 if(defined $cen && $cen == 0 && $dx > 180) {
877 # Assume large angles means we crossed zero
878 $dx -= 360;
879 }
88012.0e-62.0e-6 return $dx;
881}
882
883# Plot out the aitoff projection overlay
884#
885# $iflag bit 1 (LSB): No numbers (degree markers)
886# 2 : Lines every 20 deg.s (instead of every 10).
887# 3 : Lines every 30 deg.s.
888# 4 : No internal lines (external oval only).
889# 5 : No lines at all.
890# 6 : OK to number poles despite bit 1 setting.
891# 7 : OK to draw the 10 deg. lat. line despite
892# bit 2,3 setting.
893# $coord: 1=equatorial, 2=galactic, 3=ecliptic
894# $title1 = character string for first line of title.
895# $title2 = character string for second line of title.
896
897
# spent 58.4ms (8.78+49.7) within WISE::PgAitoff::label_aitoff which was called # once (8.78ms+49.7ms) by WISE::PgAitoff::make_aitoff at line 337
sub label_aitoff {
89812.0e-62.0e-6 my ($ht,$opts) = @_;
899
90011.0e-61.0e-6 $ht ||= 1;
90111.0e-61.0e-6 $opts ||= {};
902
903 # Aitoff mins and maxes, before scaling by $ht.
90412.0e-62.0e-6 my ($ax0,$ax1,$ay0,$ay1) = (-1.,1.,-.5,.5);
905
90611.0e-61.0e-6 $opts ||= {};
907
908 # Set options
90912.0e-62.0e-6 my $ch = $opts->{ch} || 0.75;
91011.0e-61.0e-6 my $coord = $opts->{coord} || 0;
91111.0e-61.0e-6 my $title1= $opts->{title1} || "";
91211.0e-61.0e-6 my $title2= $opts->{title2} || "";
91311.0e-61.0e-6 my $lon0 = $opts->{lon0} || 0.;
91411.0e-61.0e-6 my $lat0 = $opts->{lat0} || 0.;
91511.0e-61.0e-6 my $nonum = $opts->{nonum};
91611.0e-61.0e-6 my $i20 = $opts->{i20};
91711.0e-61.0e-6 my $i30 = $opts->{i30};
91811.0e-61.0e-6 my $noint = $opts->{noint};
91911.7e-51.7e-5 my $nolin = $opts->{nolin};
92011.0e-61.0e-6 my $polok = $opts->{poleok};
92111.0e-61.0e-6 my $pole = $opts->{pole};
92211.0e-61.0e-6 my $do10 = $opts->{do10};
923
92411.0e-61.0e-6 my ($x0,$x1,$y0,$y1,$rev);
92512.1e-52.1e-5 pgqwin($x0,$x1,$y0,$y1);
# spent 10µs making 1 call to PGPLOT::pgqwin
92613.0e-63.0e-6 ($x0,$x1) = ($x1,$x0), $rev=-1 if $x1<$x0;
927
928100 return if $nolin;
929
93011.6e-51.6e-5 pgsci(1);
# spent 15µs making 1 call to PGPLOT::pgsci
93119.0e-69.0e-6 pgsch($ch);
# spent 9µs making 1 call to PGPLOT::pgsch
93216.0e-66.0e-6 pgstbg(-1);
# spent 5µs making 1 call to PGPLOT::pgstbg
933
93411.0e-61.0e-6 my (@xbox,@ybox);
93513.5e-53.5e-5 pgqtxt (50,50, 0, 0, "X", \@xbox, \@ybox);
# spent 32µs making 1 call to PGPLOT::pgqtxt
93612.0e-62.0e-6 my $dt = $ybox[1]-$ybox[0]; # Char. height in world coord.s
937
93817.5e-57.5e-5 pgptext(0.,-$ht/2.-3.5*$dt,0,.5, $ccoord[$coord-1]) if $coord;
# spent 70µs making 1 call to PGPLOT::pgptext
93917.1e-57.1e-5 pgptext(0., $ht/2.+4.5*$dt,0,.5, $title1) if $title1;
# spent 67µs making 1 call to PGPLOT::pgptext
94017.7e-57.7e-5 pgptext(0., $ht/2.+3.1*$dt,0,.5, $title2) if $title2;
# spent 74µs making 1 call to PGPLOT::pgptext
941
942 # Put in +/-90 latitude labels by hand, only because it looks neater.
94312.0e-62.0e-6 if(! $nonum || $polok) {
94411.0e-51.0e-5 number(0, 90+0.5*$dt, 90, 0, 0, 2, 0);
# spent 50µs making 1 call to WISE::PgAitoff::number
94518.0e-68.0e-6 number(0, -90-1.1*$dt, -90, 0, 0, 3, 0);
# spent 76µs making 1 call to WISE::PgAitoff::number
946 }
947
94811.0e-61.0e-6 my ($i,$j,$ip,$x,$y,$lon,$lat,$lbllon,$lbllat);
949
950 # Put pen at center.
95119.0e-69.0e-6 versplot(0.,0.,3);
# spent 78µs making 1 call to WISE::PgAitoff::versplot
952 # First draw and label the longitude lines ...
95313.6e-53.6e-5 for($i=-180; $i<=180; $i+=10) {
954371.8e-54.9e-7 $ip = 3; # Pen up
955370.000133.5e-6 $lon = $i + $lon0;
956 # This hack allows us to draw and label two longitude lines where
957 # physically there is only one, at lon+/-180.
958371.8e-54.9e-7 $lon += .01 if $i == -180;
959371.4e-53.8e-7 $lon -= .01 if $i == 180;
960 # Some futzing around to make sure all the correct longitude lines plot.
961372.6e-57.0e-7 $lon += 360 if $lon < 0;
962371.8e-54.9e-7 $lon -= 360 if $lon >= 360;
963 # Skip unwanted longitude lines depending on $i20 and $i30.
964372.1e-55.7e-7 next if $i20 && abs($i)%20;
965375.8e-51.6e-6 next if $i30 && abs($i)%30;
966 # If we're skipping all internal lines don't use anything but
967 # the exterior +-180 lines.
968134.1e-53.2e-6 next if $noint && abs($i) == 180;
969130.000453.5e-5 for($j=-90; $j<=90; $j+=5) {
9704810.000326.6e-7 $lat = $j + $lat0;
971 # Draw no longitude lines above $lat 85 (except the outer lines).
9724810.000347.0e-7 next if abs($i)!=180 && abs($j)>85;
973 # Draw only every 20 degrees between 80 and 85
974 # latitude, but don't worry about this restriction if
975 # $i20 or $i30 are set.
9764590.000327.0e-7 next if ! ($i20 || $i30) && abs($j)==85 && abs($i)%20;
977 # Get projection of current $lat and $lon.
9784590.002625.7e-6 ($x,$y) = toaitoff($lon,$lat,$ht,$lon0,0,$pole);
# spent 15.3ms making 459 calls to WISE::PgAitoff::toaitoff, avg 33µs/call
979 # Plot line.
9804590.002335.1e-6 versplot($x,$y,$ip);
# spent 16.5ms making 459 calls to WISE::PgAitoff::versplot, avg 36µs/call
9814590.000306.5e-7 $ip = 2; # Pen down
982 # Number the line
983 # Skip numbering if requested or if off-scale
9844590.000265.7e-7 next if $nonum;
985 # Don't label latitude 0
9864590.000265.7e-7 next if $j == 0;
987 # Do not number the poles (already done).
9884460.000316.9e-7 next if abs($lat) > 85.;
989 # Print the latitude values along the center longitude (except
990 # 90 degrees)
9914420.000521.2e-6 next if $i != 0;
992 # Skip if off-plot
993345.6e-51.6e-6 next if $x/$ht < $ax0 || $x/$ht > $ax1 ||
994 $y/$ht < $ay0 || $y/$ht > $ay1;
995 # Only print requested intervals
996348.2e-52.4e-6 next if $j%10;
997162.8e-51.8e-6 next if $i20 && $j%20;
998163.5e-52.2e-6 next if $i30 && $j%30;
999 # Round to 1 d.p. This hides sopme of the futzing around we do.
100046.7e-51.7e-5 number($x+$rev*.2*$dt, $y+.2*$dt, $lat, 0., 0., 3, 0);
# spent 302µs making 4 calls to WISE::PgAitoff::number, avg 75µs/call
100144.2e-51.0e-5 versplot($x,$y,3);
# spent 118µs making 4 calls to WISE::PgAitoff::versplot, avg 30µs/call
1002136.0e-64.6e-7 }
1003 # Go to bottom of plot.
1004130.000141.1e-5 versplot(0.,-$ht/2.,3);
# spent 237µs making 13 calls to WISE::PgAitoff::versplot, avg 18µs/call
100511.0e-61.0e-6 }
1006 #
1007 # ... and then the latitude llines . . . .
1008100 return if $noint;
1009
101011.4e-51.4e-5 for($j=-90; $j<=90; $j+=10) {
1011191.3e-56.8e-7 $ip = 3; # Pen up
1012195.0e-62.6e-7 $lat = $j + $lat0;
1013 # This dodge substitutes the +-85 deg. arc for the unnecessary
1014 # +-90 point.
1015193.4e-51.8e-6 $lat = 85.0 if $lat == 90.0;
1016196.0e-63.2e-7 $lat = -85.0 if $lat == -90.0;
1017 # Skip unwanted latitude lines (depending on $i20 and $i30),
1018 # but leave in the 85 deg. arcs in all cases to give the $lon
1019 # lines a terminus.
1020193.1e-51.6e-6 next if $i20 && ! ($do10 && abs($j)==10) &&
1021 abs($j)%20 && abs($j) != 90;
1022192.1e-51.1e-6 next if $i30 && ! ($do10 && abs($j)==10) &&
1023 abs($j)%30 && abs($j) != 90;
102470.000182.6e-5 for($i=-180; $i<=180; $i+=10) {
10252590.000155.8e-7 $lon = $i + $lon0;
1026 # This hack allows us to draw and label two longitude lines where
1027 # physically there is only one, at lon+/-180.
10282590.000124.7e-7 $lon += .01 if $i == -180;
10292590.000134.9e-7 $lon -= .01 if $i == 180;
1030 # Futz the longitude.
10312590.000145.5e-7 $lon += 360 if $lon < 0;
10322590.000145.4e-7 $lon -= 360 if $lon >= 360;
1033 # Project ...
10342590.001405.4e-6 ($x,$y) = toaitoff($lon,$lat,$ht,$lon0,0,$pole);
# spent 7.78ms making 259 calls to WISE::PgAitoff::toaitoff, avg 30µs/call
1035 # Plot line.
10362590.001104.2e-6 versplot($x,$y,$ip);
# spent 8.15ms making 259 calls to WISE::PgAitoff::versplot, avg 31µs/call
10372590.000166.1e-7 $ip = 2; # Pen down
1038 # Number the line
1039 # Skip if not numbering.
10402590.000135.1e-7 next if $nonum;
1041 # Print out the longitude values along the equator (0 - 360 dgs)
10422590.000351.4e-6 next if abs($lat-$lat0) > .1;
1043 # Skip if off-plot
1044376.3e-51.7e-6 next if $x/$ht < $ax0 || $x/$ht > $ax1 ||
1045 $y/$ht < $ay0 || $y/$ht > $ay1;
1046 # Only print requested intervals
1047371.6e-54.3e-7 next if $i20 && $i%20;
1048373.6e-59.7e-7 next if $i30 && $i%30;
1049 # Round to 1 d.p. This hides sopme of the futzing around we do.
1050138.8e-56.8e-6 number($x+$rev*.2*$dt, $y+.2*$dt, $lon, 0., 0., 4, 0);
# spent 661µs making 13 calls to WISE::PgAitoff::number, avg 51µs/call
1051135.6e-54.3e-6 versplot($x,$y,3);
# spent 145µs making 13 calls to WISE::PgAitoff::versplot, avg 11µs/call
105273.0e-64.3e-7 }
105311.0e-61.0e-6 }
1054
105514.0e-64.0e-6 return;
1056}
1057
1058# Emulate (in a VERY simple minded way) Versatec routines
1059
# spent 1.09ms (299µs+790µs) within WISE::PgAitoff::number which was called 19 times, avg 57µs/call: # 13 times (175µs+486µs) by WISE::PgAitoff::label_aitoff at line 1050, avg 51µs/call # 4 times (86µs+216µs) by WISE::PgAitoff::label_aitoff at line 1000, avg 75µs/call # once (10µs+66µs) by WISE::PgAitoff::label_aitoff at line 945 # once (28µs+22µs) by WISE::PgAitoff::label_aitoff at line 944
sub number {
1060195.3e-52.8e-6 my ($x,$y,$num,$ang,$just,$fld,$nd) = @_;
1061
1062197.1e-53.7e-6 my $str = sprintf("%.${nd}f",$num);
1063190.000824.3e-5 pgptext($x,$y,$ang,$just,$str);
# spent 790µs making 19 calls to PGPLOT::pgptext, avg 42µs/call
1064
1065195.0e-52.6e-6 return;
1066}
1067
1068
# spent 25.2ms (6.47+18.8) within WISE::PgAitoff::versplot which was called 749 times, avg 34µs/call: # 459 times (4.14ms+12.4ms) by WISE::PgAitoff::label_aitoff at line 980, avg 36µs/call # 259 times (1.99ms+6.16ms) by WISE::PgAitoff::label_aitoff at line 1036, avg 31µs/call # 13 times (138µs+99µs) by WISE::PgAitoff::label_aitoff at line 1004, avg 18µs/call # 13 times (101µs+44µs) by WISE::PgAitoff::label_aitoff at line 1051, avg 11µs/call # 4 times (88µs+30µs) by WISE::PgAitoff::label_aitoff at line 1001, avg 30µs/call # once (12µs+66µs) by WISE::PgAitoff::label_aitoff at line 951
sub versplot {
10697490.001281.7e-6 my ($x,$y,$pen) = @_;
1070
10717490.000841.1e-6 pgmove($x,$y) if $pen == 3;
# spent 318µs making 51 calls to PGPLOT::pgmove, avg 6µs/call
10727490.019822.6e-5 pgdraw($x,$y) if $pen == 2;
# spent 18.5ms making 698 calls to PGPLOT::pgdraw, avg 26µs/call
1073
10747490.001091.5e-6 return;
1075}
1076
1077# Return the max of a list
1078sub max {
1079 my $v=ref($_[0]) ? $_[0] : \@_;
1080 my $i=$#{$v};
1081 my $m=$v->[$i];
1082 while (--$i >= 0) { if ($v->[$i] > $m) { $m=$v->[$i]; }}
1083 return $m;
1084}
1085
1086# Return the min of a list
1087sub min {
1088 my $v=ref($_[0]) ? $_[0] : \@_;
1089 my $i=$#{$v};
1090 my $m=$v->[$i];
1091 while (--$i >= 0) { if ($v->[$i] < $m) { $m=$v->[$i]; }}
1092 return $m;
1093}
1094
1095sub plot_grid {
1096
1097 # Grid defaults
1098 my ($plotsz,$gridsz,$gridcol,$gridbg) = (1,0.8,1,0);
1099 my ($lonmin,$lonmax,$latmin,$latmax) = (0,360,-90,90);
1100
1101 # Parameters
1102 my ($xmn,$xmx,$ymn,$ymx,$ht) = (shift,shift,shift,shift,shift||1);
1103 my $opts = shift || {};
1104 my $pole = $opts->{pole}||0;
1105 my $lon0 = $opts->{lon0}||0;
1106 my $lat0 = $opts->{lat0}||0;
1107 my ($col,$sz) = ($opts->{gridcol}||$gridcol,$opts->{gridsz}||$gridsz);
1108 my($xmarg,$ymarg) = ($opts->{xmargin}||0,$opts->{ymargin}||0);
1109 my $ch = $opts->{ch} || 0.75;
1110 my $coord = $opts->{coord} || 0;
1111 my $title1= $opts->{title1} || "";
1112 my $title2= $opts->{title2} || "";
1113 my ($dlon,$dlat);
1114 my ($lonstep,$latstep,$minlat,$minlon,$maxlat,$maxlon,$lon,$tlon,$lat);
1115 my ($nlat,$nlon,$n,@x,@y,$i,$j,$midlat,$midlon,$done,$ang,$lbllon);
1116 my ($on,$nowoff,$wason,$cross);
1117 my $rev = 1;
1118 my ($pxr0,$pxr1,$py0,$py1);
1119 pgqwin($pxr0,$pxr1,$py0,$py1);
1120 my ($px0,$px1) = ($pxr0,$pxr1);
1121 ($px0,$px1) = ($px1,$px0), $rev=-1 if $px1<$px0;
1122 my ($vx0,$vx1,$vy0,$vy1);
1123 pgqvp(0,$vx0,$vx1,$vy0,$vy1);
1124 my $xvp2win = ($px1-$px0)/($vx1-$vx0);
1125 my $yvp2win = ($py1-$py0)/($vy1-$vy0);
1126 my $xpcen = $px0 + ($vx1-$vx0)/2*$xvp2win;
1127
1128 pgsci(1);
1129 pgsch($ch);
1130 pgstbg(-1);
1131
1132 my (@xbox,@ybox);
1133 pgqtxt (50,50, 0, 0, "X", \@xbox, \@ybox);
1134 my $dt = $ybox[1]-$ybox[0]; # Char. height in world coord.s
1135
1136 pgptext($xpcen, $py0-2.5*$dt, 0, .5, $ccoord[$coord-1]) if $coord;
1137 pgptext($xpcen, $py1+3.5*$dt, 0, .5, $title1) if $title1;
1138 pgptext($xpcen, $py1+2.1*$dt, 0, .5, $title2) if $title2;
1139
1140 pgsci($col);
1141 pgsch($sz);
1142
1143 ($ymn,$ymx) = ($ymn>$ymx ? ($ymx,$ymn) : ($ymn,$ymx));
1144
1145 # Draw border
1146 pgsclp(0);
1147 pgline(5,
1148 [$px0,$px0,$px1,$px1,$px0],
1149 [$py0,$py1,$py1,$py0,$py0]);
1150 pgsclp(1);
1151
1152 my $lonang = ! $pole ? londiff($xmn,$xmx)*cos(($ymn+$ymx)/2/$R2D) : 90;
1153
1154 $dlon = max(0.1,$lonang/25);
1155 $dlat = max(0.1,($ymx-$ymn)/25);
1156
1157 ($lonstep,$latstep) = ((annot_int($lonang))[0],
1158 (annot_int($ymx-$ymn))[0]);
1159
1160 $nlon = int((londiff($xmn,$xmx)+2*$xmarg)/$lonstep+.999999);
1161 $minlon = int(($xmn - $xmarg)/$lonstep - 1)*$lonstep;
1162 $maxlon = $minlon + ($nlon+2)*$lonstep;
1163 $nlat = int(($ymx-$ymn+2*$ymarg)/$latstep+.999999);
1164 $minlat = int(($ymn - $ymarg)/$latstep - 1)*$latstep;
1165 $maxlat = $minlat + ($nlat+2)*$latstep;
1166
1167 $midlon = ($px0+$px1)/2.;
1168 $midlat = ($py0+$py1)/2.;
1169
1170 #print "x/ymn/mx=$xmn,$xmx,$ymn,$ymx\nlon/lat0=$lon0,$lat0\n";
1171 #print "px/y0/1=$px0,$px1,$py0,$py1\n";
1172 #print "dlon/lat,lon/latstep,nlon/lat=$dlon,$dlat,".
1173 # "$lonstep,$latstep,$nlon,$nlat\n";
1174 #print "min/maxlon/lat=$minlon,$maxlon,$minlat,$maxlat\n";
1175
1176 $n = 0;
1177 for($i=0; $i<=$nlat+1; ++$i) {
1178 $done = 0;
1179 $nowoff = 0;
1180 $wason = 0;
1181 $lat = $minlat + $i*$latstep;
1182 next if abs($lat) > 90;
1183 #print "\t--- LAT: $minlat,$i,$latstep -> $lat\n";
1184 for($j = 0,$tlon=$minlon; $tlon<=$maxlon; $tlon += $dlon, ++$j) {
1185 $lon = $tlon;
1186 $lon += 360 if $lon < 0;
1187 $lon -= 360 if $lon >= 360;
1188 ($x[$n],$y[$n]) = toaitoff($lon,$lat,$ht,$lon0,$lat0,$pole);
1189 $on = onplot($x[$n],$y[$n],$px0,$px1,$py0,$py1);
1190 if(! $wason && $on) { $wason = 1; }
1191 $nowoff = $wason && ! $on;
1192 #print "\t\t--- $lon($tlon),$lat -> $x[$n],$y[$n] -> '$on'\n";
1193 if(! $done && ($on || $nowoff) && $j>0) { #&& $x[$n]>$midlon)
1194 $done = 1;
1195 $ang = atan2($y[$n-1]-$y[$n],$rev*($x[$n-1]-$x[$n]))*$R2D;
1196 if(abs($ang) > 90) { $ang -= 180; }
1197 pgptxt(($x[$n]+$x[$n-1])/2,($y[$n]+$y[$n-1])/2,
1198 $ang,0.5,sprintf("%3.2g",$lat));
1199 }
1200 $n++;
1201 }
1202 }
1203
1204 for($i=0; $i<=$nlon+1; ++$i) {
1205 $done = 0;
1206 $nowoff = 0;
1207 $wason = 0;
1208 $lon = $minlon + $i*$lonstep;
1209 $tlon = $lon;
1210 $lon += 360 if $lon < 0;
1211 $lon -= 360 if $lon >= 360;
1212 $lbllon = $lon;
1213 if($pole<0) { # !!! Horrible Kludge. Don't understand.
1214 # Special incomprehensible adjustment for labeling south pole
1215 $lbllon += 180;
1216 $lbllon += 360 if $lbllon < 0;
1217 $lbllon -= 360 if $lbllon >= 360;
1218 }
1219 $lbllon = sprintf("%3.3g",$lbllon);
1220 #print "\t--- LON: $minlon,$i,$lonstep,$pole -> $lon,$tlon\n";
1221 for($j = 0,$lat=$minlat; $lat<=$maxlat; $lat += $dlat, ++$j) {
1222 ($x[$n],$y[$n]) = toaitoff($lon,$lat,$ht,$lon0,$lat0,$pole);
1223 $on = onplot($x[$n],$y[$n],$px0,$px1,$py0,$py1);
1224 if(! $wason && $on) { $wason = 1; }
1225 $nowoff = $wason && ! $on;
1226 #print "\t\t--- $lon($tlon),$lat -> $x[$n],$y[$n] -> '$on'\n";
1227 if(! $done && ($on || $nowoff) && $j>0) { #&& $y[$n]>$midlat)
1228 $done = 1;
1229 $ang = atan2($y[$n-1]-$y[$n],$rev*($x[$n-1]-$x[$n]))*$R2D;
1230 if(abs($ang) > 90) { $ang -= 180; }
1231 pgptxt(($x[$n]+$x[$n-1])/2,($y[$n]+$y[$n-1])/2,
1232 $ang,0.5,$lbllon);
1233 }
1234 $n++;
1235 }
1236 }
1237
1238 pgpt($n,\@x,\@y,1);
1239
1240 pgsci(1);
1241 pgsch(1);
1242 pgstbg(-1);
1243
1244 return 1;
1245}
1246
1247
# spent 25µs within WISE::PgAitoff::allsky which was called # once (25µs+0) by WISE::PgAitoff::make_aitoff at line 129
sub allsky {
124812.0e-62.0e-6 my ($xmn,$xmx,$ymn,$ymx) = @_;
1249
125015.0e-65.0e-6 return abs( 0-$xmn)<5 && abs(360-$xmx)<5 &&
1251 abs(-90-$ymn)<5 && abs( 90-$ymx)<5;
1252}
1253
1254sub annot_int {
1255 my $delx = $_[0];
1256 my ($dx,$nsx);
1257
1258 if ($delx >= 90) { $dx = 30; $nsx = 6; }
1259 elsif ($delx >= 60) { $dx = 15; $nsx = 3; }
1260 elsif ($delx >= 40) { $dx = 10; $nsx = 5; }
1261 elsif ($delx >= 30) { $dx = 6; $nsx = 3; }
1262 elsif ($delx >= 20) { $dx = 5; $nsx = 5; }
1263 elsif ($delx >= 12) { $dx = 3; $nsx = 3; }
1264 elsif ($delx >= 6) { $dx = 2; $nsx = 2; }
1265 elsif ($delx >= 1) { $dx = 1; $nsx = 4; }
1266 elsif ($delx >= .5) { $dx =.5; $nsx = 3; }
1267 else { $dx =.25; $nsx = 3; }
1268
1269 return wantarray ? ($dx,$nsx) : $dx;
1270}
1271
1272sub onplot {
1273 my ($x,$y,$x0,$x1,$y0,$y1) = @_;
1274 my $on;
1275
1276 $on = $y <= $y1 && $y >= $y0 && $x <= $x1 && $x >= $x0;
1277
1278 return $on;
1279}
1280
128111.3e-51.3e-51;