File | /wise/base/deliv/dev/lib/perl/WISE/PgAitoff.pm | Statements Executed | 492333 | Total Time | 0.780994000000007 seconds |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine | |
---|---|---|---|---|---|---|
14736 | 3 | 1 | 0.19574 | 0.39596 | WISE::PgAitoff:: | toaitoff |
1 | 1 | 1 | 0.16663 | 0.77204 | WISE::PgAitoff:: | make_aitoff |
14736 | 1 | 1 | 0.14322 | 0.14322 | WISE::PgAitoff:: | tocenter |
1 | 1 | 1 | 0.00878 | 0.05844 | WISE::PgAitoff:: | label_aitoff |
749 | 6 | 1 | 0.00647 | 0.02524 | WISE::PgAitoff:: | versplot |
1 | 1 | 1 | 0.00284 | 0.02277 | WISE::PgAitoff:: | color_key |
19 | 4 | 1 | 0.00030 | 0.00109 | WISE::PgAitoff:: | number |
1 | 1 | 1 | 0.00020 | 0.00020 | WISE::PgAitoff:: | set_spec_colors |
1 | 1 | 1 | 9.0e-5 | 9.0e-5 | WISE::PgAitoff:: | set_viewport |
1 | 1 | 1 | 2.6e-5 | 0.00028 | WISE::PgAitoff:: | normalize_coord |
1 | 1 | 1 | 2.5e-5 | 2.5e-5 | WISE::PgAitoff:: | allsky |
1 | 1 | 1 | 1.4e-5 | 1.4e-5 | WISE::PgAitoff:: | londiff |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | BEGIN |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | annot_int |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | cliptoedge |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | color_map |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | cursor |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | fromaitoff |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | fromcenter |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | max |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | min |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | onplot |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | pick |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | plot_grid |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | rev_color_map |
0 | 0 | 0 | 0 | 0 | WISE::PgAitoff:: | select_region |
Line | Stmts. | Exclusive Time | Avg. | Code |
---|---|---|---|---|
1 | #! /usr/bin/env perl | |||
2 | ||||
3 | 3 | 3.8e-5 | 1.3e-5 | use strict; # spent 12µs making 1 call to strict::import |
4 | 3 | 5.8e-5 | 1.9e-5 | use warnings; # spent 50µs making 1 call to warnings::import |
5 | ||||
6 | # $Id: PgAitoff.pm 7889 2010-05-13 01:42:18Z tim $ | |||
7 | ||||
8 | 3 | 4.2e-5 | 1.4e-5 | use WISE::Env (cfglib=>'/wise/base/deliv/dev/lib/perl'); # spent 468µs making 1 call to WISE::Env::import |
9 | ||||
10 | package WISE::PgAitoff; | |||
11 | ||||
12 | 3 | 3.3e-5 | 1.1e-5 | use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION); # spent 74µs making 1 call to vars::import |
13 | ||||
14 | 3 | 6.6e-5 | 2.2e-5 | use Exporter; # spent 68µs making 1 call to Exporter::import |
15 | 1 | 2.0e-6 | 2.0e-6 | $VERSION = 1.00; |
16 | 1 | 1.1e-5 | 1.1e-5 | @ISA = qw(Exporter); |
17 | ||||
18 | 1 | 1.0e-6 | 1.0e-6 | @EXPORT = qw(); |
19 | ||||
20 | 1 | 1.0e-6 | 1.0e-6 | %EXPORT_TAGS = (); |
21 | ||||
22 | 1 | 1.0e-6 | 1.0e-6 | @EXPORT_OK = ('make_aitoff'); |
23 | ||||
24 | 3 | 0.00105 | 0.00035 | use PGPLOT; # spent 600µs making 1 call to Exporter::import |
25 | ||||
26 | 3 | 0.00114 | 0.00038 | use WISE; # spent 201ms making 1 call to WISE::import |
27 | 3 | 6.8e-5 | 2.3e-5 | use WISE::CoUtils ('$R2D','cconv'); # spent 166µs making 1 call to Exporter::import |
28 | 3 | 0.00669 | 0.00223 | use WISE::CoUtilsXS; # spent 147µs making 1 call to Exporter::import |
29 | ||||
30 | 1 | 2.0e-6 | 2.0e-6 | my @ccoord = ('Equatorial Coordinates', |
31 | 'Galactic Coordinates', | |||
32 | 'Ecliptic Coordinates'); | |||
33 | ||||
34 | 1 | 1.0e-6 | 1.0e-6 | my (%color_vals, @colors, $lowc); |
35 | ||||
36 | 1 | 1.0e-6 | 1.0e-6 | my $aitoffdx = 360; # Full width of converted aitoff x values; |
37 | ||||
38 | 1 | 1.0e-6 | 1.0e-6 | my $err = "*** PgAitoff"; |
39 | 1 | 0 | 0 | my $warn = "=== PgAitoff"; |
40 | ||||
41 | 1 | 1.0e-6 | 1.0e-6 | my %popts; |
42 | 1 | 0 | 0 | my %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 | |||
45 | ||||
46 | 1 | 3.2e-5 | 3.2e-5 | %popts = %{ $_[0] || {} }; |
47 | ||||
48 | 1 | 1.2e-5 | 1.2e-5 | %popts0 = %popts; # Save original values |
49 | ||||
50 | 1 | 5.0e-6 | 5.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 | |||
55 | 1 | 2.0e-6 | 2.0e-6 | my $verbose = $popts{verbose} || 0; |
56 | 1 | 2.0e-6 | 2.0e-6 | my $pfile = $popts{pfile} || ""; |
57 | 1 | 2.0e-6 | 2.0e-6 | my $pdev = $popts{pdev} || '/xs'; |
58 | 1 | 2.0e-6 | 2.0e-6 | my $coord = $popts{coord} || 'equ'; |
59 | 1 | 2.0e-6 | 2.0e-6 | my $refdat = $popts{date} || ""; |
60 | 1 | 2.0e-6 | 2.0e-6 | my $keytitle= $popts{keyttl} || ""; |
61 | 1 | 2.0e-6 | 2.0e-6 | my $keylbls = $popts{keylbls} || []; |
62 | 1 | 3.0e-6 | 3.0e-6 | my $nogrid = $popts{nogrid} || 0; |
63 | 1 | 2.0e-6 | 2.0e-6 | my $binmark = $popts{binmark} || 16; # Mark for a filled, color-coded bin. |
64 | 1 | 1.0e-6 | 1.0e-6 | my $colormap= $popts{colmap}; # Map of bin value to color |
65 | 1 | 4.0e-6 | 4.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 | |||
70 | 1 | 2.0e-6 | 2.0e-6 | my $corder = $popts{corder} // 0; |
71 | 1 | 2.0e-6 | 2.0e-6 | my $spec = $popts{spec}; # Use pseudo-spectral color table |
72 | ||||
73 | # What to plot | |||
74 | 1 | 2.0e-6 | 2.0e-6 | my $binx = $popts{'x'} || []; # Longitudes |
75 | 1 | 2.0e-6 | 2.0e-6 | my $biny = $popts{'y'} || []; # Latitudes |
76 | 1 | 1.0e-6 | 1.0e-6 | my $binvals = $popts{'z'} || []; # Colors |
77 | 1 | 2.0e-6 | 2.0e-6 | my $binmarks= $popts{'m'}; # Markers |
78 | 1 | 3.6e-5 | 3.6e-5 | my $binsz = $popts{binsz} || 1; # degrees |
79 | ||||
80 | 1 | 2.0e-6 | 2.0e-6 | $binvals = [ (1) x @$binx ] if ! @$binvals; |
81 | ||||
82 | 1 | 1.0e-5 | 1.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) | |||
86 | 1 | 9.0e-6 | 9.0e-6 | set_spec_colors(); # spent 197µs making 1 call to WISE::PgAitoff::set_spec_colors |
87 | ||||
88 | ||||
89 | 1 | 1.0e-6 | 1.0e-6 | PLOT: { |
90 | ||||
91 | 1 | 1.0e-6 | 1.0e-6 | print "\nPlot device = $pfile$pdev ...\n" if $verbose; |
92 | ||||
93 | # Pull out plot options | |||
94 | # Accept other canonical coordinate system names | |||
95 | 1 | 1.1e-5 | 1.1e-5 | $coord = normalize_coord($coord); # spent 282µs making 1 call to WISE::PgAitoff::normalize_coord |
96 | 1 | 1.0e-6 | 1.0e-6 | $coord=2,warn("$warn: Defaulting coordinate to galactic.\n") |
97 | if ! $coord; | |||
98 | 1 | 1.0e-6 | 1.0e-6 | my $log = $popts{log}; # Log-scale the colors |
99 | 1 | 1.0e-6 | 1.0e-6 | my $nokey = $popts{nokey}; # Suppress color-key |
100 | # Constants for now (except lborder gets reduced when $nokey is true) | |||
101 | 1 | 1.0e-6 | 1.0e-6 | my $lborder = 0.15; # Fraction of viewport to leave empty at left |
102 | 1 | 1.0e-6 | 1.0e-6 | $lborder = .05 if $nokey; |
103 | 1 | 1.1e-5 | 1.1e-5 | my $rborder = 0.10; # Fraction of viewport to leave empty at right |
104 | 1 | 0 | 0 | my $bborder = 0.10; # Fraction of bottom to leave empty |
105 | 1 | 1.0e-6 | 1.0e-6 | my $tborder = 0.10; # Fraction of top to leave empty |
106 | 1 | 1.0e-6 | 1.0e-6 | $lon0 = $popts{lon0} || 0; # Aitoff proj center lon |
107 | 1 | 2.0e-6 | 2.0e-6 | $lat0 = $popts{lat0} || 0; # Aitoff proj center lat |
108 | 1 | 1.0e-5 | 1.0e-5 | $fovsym = $popts{fovsym} || 25; # Symbol for FOV plotting |
109 | 1 | 0 | 0 | my $pole = $popts{pole} || 0; # Polar projection |
110 | 1 | 2.0e-6 | 2.0e-6 | my $margin = defined $popts{margin} ? $popts{margin} : 0; # Degrees |
111 | 1 | 1.0e-6 | 1.0e-6 | my $fixproj = $popts{fixproj}; # Don't change proj center on zoom |
112 | 1 | 0 | 0 | my $notext = $popts{notext}; # Suppress text for symbol plots |
113 | 1 | 2.0e-6 | 2.0e-6 | my $papwidth = $popts{papxwidth}; # Canvas width (or height) |
114 | 1 | 1.0e-6 | 1.0e-6 | my $papaspect= $popts{papasp} || 0.77; # Canvas aspect |
115 | 1 | 1.0e-6 | 1.0e-6 | my $revcoord = ! $popts{norev}; # Reverse coordinate axes |
116 | 1 | 1.0e-6 | 1.0e-6 | my $pltaspect= $popts{plotasp} || 0; # Default picked below |
117 | 1 | 1.0e-6 | 1.0e-6 | my $toptitle = $popts{title}; |
118 | 1 | 1.3e-5 | 1.3e-5 | my $title = $popts{subtitle}; |
119 | 1 | 3.0e-6 | 3.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 | |||
121 | 1 | 1.0e-6 | 1.0e-6 | $x0 = 0 if ! defined $x0; |
122 | 1 | 1.1e-5 | 1.1e-5 | $x1 = 360 if ! defined $x1; |
123 | 1 | 1.0e-6 | 1.0e-6 | $y0 = -90 if ! defined $y0; |
124 | 1 | 1.0e-6 | 1.0e-6 | $y1 = 90 if ! defined $y1; |
125 | 1 | 0 | 0 | $x0 += 360 if $x0<0; |
126 | 1 | 1.0e-6 | 1.0e-6 | $x1 += 360 if $x1<0; |
127 | 1 | 1.0e-6 | 1.0e-6 | ($y0,$y1) = ($y1,$y0) if $y1 < $y0; |
128 | # Check that plot limits and projection center can play well together. | |||
129 | 1 | 2.1e-5 | 2.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 |
130 | 1 | 1.0e-6 | 1.0e-6 | ($x0,$x1,$y0,$y1) = (0,360,-90,90) if $allsky; |
131 | 1 | 1.0e-6 | 1.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 | |||
134 | 1 | 1.0e-6 | 1.0e-6 | ($plon0,$plat0) = ($lon0,$lat0); |
135 | 1 | 1.0e-6 | 1.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. | |||
142 | 1 | 1.0e-6 | 1.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? | |||
148 | 1 | 6.0e-6 | 6.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 | |||
151 | 1 | 2.0e-6 | 2.0e-6 | if($pole) { |
152 | $pltaspect ||= 0.6; | |||
153 | } else { | |||
154 | 1 | 1.7e-5 | 1.7e-5 | $pltaspect ||= ($y1-$y0)/(londiff($x0,$x1)*cos(($y0+$y1)/2/$R2D)); # spent 14µs making 1 call to WISE::PgAitoff::londiff |
155 | } | |||
156 | 1 | 1.0e-6 | 1.0e-6 | my $xmarg = $margin; |
157 | 1 | 1.0e-6 | 1.0e-6 | my $ymarg = $margin*$pltaspect; |
158 | ||||
159 | # Get plot boundaries; units are aitoff-projected x,y. | |||
160 | ||||
161 | 1 | 0 | 0 | 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 | |||
187 | 1 | 2.0e-6 | 2.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. | |||
192 | 1 | 1.1e-5 | 1.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. | |||
202 | 1 | 1.0e-6 | 1.0e-6 | $papwidth = $papwidth && $papwidth > 0 ? $papwidth |
203 | : $hard ? 10 | |||
204 | : 10; | |||
205 | ||||
206 | 1 | 1.0e-6 | 1.0e-6 | $papwidth = $newpapaspect>1 ? $papwidth/$newpapaspect : $papwidth; |
207 | ||||
208 | # Open plot device and initialize | |||
209 | ||||
210 | 1 | 1.0e-6 | 1.0e-6 | pgend() if $pgmain && $interacting; |
211 | 1 | 0.03968 | 0.03968 | $pgmain = pgbeg(0,$pfile.$pdev,1,1); # spent 39.7ms making 1 call to PGPLOT::pgbeg |
212 | 1 | 2.0e-6 | 2.0e-6 | die "$err: Couldn't open PGPLOT device $pfile$pdev.\n" |
213 | if $pgmain != 1; | |||
214 | ||||
215 | 1 | 0.00165 | 0.00165 | pgpap($papwidth,$newpapaspect); # spent 1.65ms making 1 call to PGPLOT::pgpap |
216 | ||||
217 | # Get viewport corners | |||
218 | 1 | 1.4e-5 | 1.4e-5 | my ($vx0,$vx1,$vy0,$vy1) = ($lborder,$lborder+$xvp, |
219 | $bborder,$bborder+$yvp); | |||
220 | ||||
221 | 1 | 4.0e-6 | 4.0e-6 | my $bestasp = (1-$tborder-$bborder)/(1-$rborder-$lborder); |
222 | 1 | 1.0e-6 | 1.0e-6 | my $bestskyasp = $bestasp*$papaspect; |
223 | ||||
224 | # Derive viewport aspect, in canvas units and real world units | |||
225 | 1 | 1.0e-6 | 1.0e-6 | my $vpaspect = ($vy1-$vy0)/($vx1-$vx0); |
226 | 1 | 1.0e-6 | 1.0e-6 | my $vpaspectreal = $vpaspect*$newpapaspect; |
227 | ||||
228 | 1 | 1.0e-6 | 1.0e-6 | if(! $hard) { |
229 | # Plot black on white background | |||
230 | 1 | 0.09768 | 0.09768 | pgscr(0,1.,1.,1.); # spent 97.7ms making 1 call to PGPLOT::pgscr |
231 | 1 | 0.00194 | 0.00194 | pgscr(1,0.,0.,0.); # spent 1.93ms making 1 call to PGPLOT::pgscr |
232 | } | |||
233 | ||||
234 | # Set spectral color indices in PGPLOT | |||
235 | 1 | 3.0e-6 | 3.0e-6 | if($spec) { |
236 | 1 | 1.0e-5 | 1.0e-5 | for my $ci (keys %color_vals) { |
237 | 16 | 3.0e-5 | 1.9e-6 | my ($red,$green,$blue) = @{$color_vals{$ci}}; |
238 | 16 | 0.00012 | 7.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 | |||
244 | 1 | 2.0e-5 | 2.0e-5 | pgsvp($vx0,$vx1,$vy0,$vy1); # spent 19µs making 1 call to PGPLOT::pgsvp |
245 | ||||
246 | # Set window world coordinate limits | |||
247 | 1 | 3.7e-5 | 3.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 | |||
250 | 1 | 1.0e-6 | 1.0e-6 | my (@xbox,@ybox); |
251 | 1 | 1.6e-5 | 1.6e-5 | pgsch(1); # spent 15µs making 1 call to PGPLOT::pgsch |
252 | 1 | 4.8e-5 | 4.8e-5 | pgqtxt (50,50, 0, 0, "X", \@xbox, \@ybox); # spent 44µs making 1 call to PGPLOT::pgqtxt |
253 | 1 | 1.0e-6 | 1.0e-6 | $dt = $ybox[1]-$ybox[0]; |
254 | ||||
255 | 1 | 1.0e-6 | 1.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 | |||
267 | 1 | 1.0e-5 | 1.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 | |||
271 | 1 | 4.0e-6 | 4.0e-6 | if(! $popts{nopoints} && @$binx) { |
272 | 1 | 0 | 0 | print "Plotting ".@$binx." points ...\n" if $verbose; |
273 | 1 | 1.0e-6 | 1.0e-6 | my @pbins = (); |
274 | 1 | 6.0e-6 | 6.0e-6 | for my $bin (0..$#{$binx}) { |
275 | 14018 | 0.01285 | 9.2e-7 | my $z = $binvals->[$bin]; |
276 | 14018 | 0.00744 | 5.3e-7 | my ($c,$ci); |
277 | 14018 | 0.01392 | 9.9e-7 | if($colormap) { |
278 | 14018 | 0.01054 | 7.5e-7 | $c = $colormap->{$z}; |
279 | 14018 | 0.00938 | 6.7e-7 | $ci = $spec ? $colors[$c] : $z; |
280 | } else { | |||
281 | $ci = $z; | |||
282 | } | |||
283 | 14018 | 0.00755 | 5.4e-7 | next if ! defined $ci; |
284 | 14018 | 0.02730 | 1.9e-6 | my ($lon,$lat) = ($binx->[$bin],$biny->[$bin]); |
285 | 14018 | 0.06835 | 4.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 | |||
288 | 14018 | 0.01508 | 1.1e-6 | push @{ $pbins[$ci]{'x'} }, $x; |
289 | 14018 | 0.01051 | 7.5e-7 | push @{ $pbins[$ci]{'y'} }, $y; |
290 | 14018 | 0.01692 | 1.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 | |||
295 | 1 | 3.0e-6 | 3.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. | |||
301 | 1 | 3.0e-6 | 3.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); | |||
307 | 1 | 1.0e-6 | 1.0e-6 | my $binmarksz = $popts{binmarksz} || $binmarkszsky*$binfill; |
308 | 1 | 1.6e-5 | 1.6e-5 | pgsch($binmarksz); # spent 14µs making 1 call to PGPLOT::pgsch |
309 | ||||
310 | # Plot the bins in color index order | |||
311 | 1 | 4.7e-5 | 4.7e-5 | pgstbg(0); # spent 34µs making 1 call to PGPLOT::pgstbg |
312 | 1 | 1.8e-5 | 1.8e-5 | my @ci = grep {$pbins[$_]} 0..$#pbins; |
313 | 1 | 3.0e-6 | 3.0e-6 | if($corder && $colormap) { |
314 | 1 | 0.00072 | 0.00072 | my %revmap = reverse %$colormap; |
315 | 1 | 6.9e-5 | 6.9e-5 | my %invcolors = map { ($colors[$_] => $_) } 0..$#colors; |
316 | 1 | 3.5e-5 | 3.5e-5 | @ci = sort {$revmap{$invcolors{$a}} <=> $revmap{$invcolors{$b}}} @ci; |
317 | 1 | 1.0e-5 | 1.0e-5 | @ci = reverse @ci if $corder < 0; |
318 | } | |||
319 | 1 | 0.00128 | 0.00128 | for my $ci (@ci) { |
320 | 10 | 1.6e-5 | 1.6e-6 | my $nplotbins = scalar(@{$pbins[$ci]{'x'}}); |
321 | 10 | 6.8e-5 | 6.8e-6 | pgsci($ci); # spent 54µs making 10 calls to PGPLOT::pgsci, avg 5µs/call |
322 | 10 | 1.3e-5 | 1.3e-6 | my $mark = $pbins[$ci]{'m'} ? $pbins[$ci]{'m'} : $binmark; |
323 | 10 | 2.4e-5 | 2.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 { | |||
331 | 10 | 0.00950 | 0.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. | |||
337 | 1 | 4.8e-5 | 4.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 | ||||
357 | 1 | 6.0e-6 | 6.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 | ||||
367 | 1 | 1.0e-6 | 1.0e-6 | if($popts{end}) { |
368 | pgend(); | |||
369 | } | |||
370 | ||||
371 | 1 | 7.0e-6 | 7.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 | |||
376 | 1 | 2.0e-6 | 2.0e-6 | my $coord = shift; |
377 | 1 | 1.0e-6 | 1.0e-6 | my $orig = $coord; |
378 | 1 | 1.0e-6 | 1.0e-6 | my $canon; |
379 | 2 | 1.5e-5 | 7.5e-6 | eval { $canon = (cconv($coord,0,0))[2] }; # spent 256µs making 1 call to WISE::CoUtils::cconv |
380 | 1 | 4.0e-6 | 4.0e-6 | $coord = {equ=>1, gal=>2, ecl=>3}->{$canon}; |
381 | 1 | 1.0e-6 | 1.0e-6 | warn "$err: Can't use coordinate system '$orig' ($canon).\n" |
382 | if ! $coord; | |||
383 | ||||
384 | 1 | 1.0e-6 | 1.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 | |||
422 | 1 | 3.0e-6 | 3.0e-6 | my ($realasp,$canvasasp,$a,$b,$c,$d,$rotok) = @_; |
423 | # Maximum viewport dimensions in canvas coordinates. | |||
424 | 1 | 3.0e-6 | 3.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! | |||
428 | 1 | 1.0e-6 | 1.0e-6 | my ($dx,$dy); |
429 | # Viewport dimensions in canvas coordinates. | |||
430 | 1 | 1.0e-6 | 1.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. | |||
438 | 1 | 1.0e-6 | 1.0e-6 | $dy = $ymax - $realasp/$canvasasp*$xmax; |
439 | # Derive resulting viewport. | |||
440 | 1 | 1.0e-6 | 1.0e-6 | push @xvp,$xmax; |
441 | 1 | 1.0e-6 | 1.0e-6 | push @yvp,$ymax - $dy; |
442 | 1 | 1.0e-6 | 1.0e-6 | push @asp,$canvasasp; |
443 | ||||
444 | # Set dy to zero and solve for dx. | |||
445 | 1 | 2.0e-6 | 2.0e-6 | $dx = $xmax - $canvasasp/$realasp*$ymax; |
446 | # Derive resulting viewport. | |||
447 | 1 | 1.0e-6 | 1.0e-6 | push @xvp,$xmax - $dx; |
448 | 1 | 0 | 0 | push @yvp,$ymax; |
449 | 1 | 1.0e-6 | 1.0e-6 | push @asp,$canvasasp; |
450 | ||||
451 | 1 | 2.0e-6 | 2.0e-6 | if($rotok) { |
452 | # Do the same with a rotated canvas | |||
453 | 1 | 1.0e-6 | 1.0e-6 | my $tmpasp = 1./$canvasasp; |
454 | ||||
455 | 1 | 1.0e-6 | 1.0e-6 | $dy = $ymax - $realasp/$tmpasp*$xmax; |
456 | 1 | 1.0e-6 | 1.0e-6 | push @xvp,$xmax; |
457 | 1 | 1.0e-6 | 1.0e-6 | push @yvp,$ymax - $dy; |
458 | 1 | 0 | 0 | push @asp,$tmpasp; |
459 | ||||
460 | 1 | 1.0e-6 | 1.0e-6 | $dx = $xmax - $tmpasp/$realasp*$ymax; |
461 | 1 | 1.0e-6 | 1.0e-6 | push @xvp,$xmax - $dx; |
462 | 1 | 1.0e-6 | 1.0e-6 | push @yvp,$ymax; |
463 | 1 | 0 | 0 | push @asp,$tmpasp; |
464 | } | |||
465 | ||||
466 | # Pick the winner | |||
467 | 1 | 1.0e-6 | 1.0e-6 | my ($max,$imax); |
468 | 1 | 5.0e-6 | 5.0e-6 | for my $i (0..$#xvp) { |
469 | 4 | 4.0e-6 | 1.0e-6 | next if $xvp[$i]>$xmax || $yvp[$i]>$ymax; |
470 | 2 | 3.1e-5 | 1.6e-5 | my $area = $xvp[$i]*$yvp[$i]; |
471 | 2 | 1.2e-5 | 6.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 | ||||
477 | 1 | 1.0e-6 | 1.0e-6 | die "$err: No suitable viewport possible.\n" if ! $max; |
478 | ||||
479 | 1 | 4.0e-6 | 4.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 | |||
484 | 1 | 1.0e-6 | 1.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. | |||
488 | 1 | 3.0e-6 | 3.0e-6 | for my $red (0,.5,1) { |
489 | 3 | 4.0e-6 | 1.3e-6 | for my $green (0,.5,1) { |
490 | 9 | 3.1e-5 | 3.4e-6 | for my $blue (0,.5,1) { |
491 | 27 | 1.1e-5 | 4.1e-7 | next if $red==$blue && $green==$blue; # No greys |
492 | 24 | 2.8e-5 | 1.2e-6 | next if $red!=0 && $green!=0 && $blue!=0; # No 3 color mixes |
493 | 18 | 7.0e-6 | 3.9e-7 | next if $red==.5 && ($green==.5 || $blue==.5); # No colors |
494 | 16 | 1.0e-5 | 6.3e-7 | next if $blue==.5 && ($green==.5 || $red==.5); # w/ 2 faint |
495 | 15 | 7.0e-6 | 4.7e-7 | next if $green==.5 && ($blue==.5 || $red==.5); # components |
496 | 15 | 4.0e-5 | 2.7e-6 | $color_vals{$ci} = [$red,$green,$blue]; |
497 | 15 | 1.5e-5 | 1.0e-6 | push @colors,$ci; |
498 | 15 | 2.3e-5 | 1.5e-6 | ++$ci; |
499 | }}} | |||
500 | ||||
501 | 1 | 2.0e-6 | 2.0e-6 | $color_vals{$ci} = [.5,.5,.5]; |
502 | 1 | 1.0e-6 | 1.0e-6 | $lowc = $ci if ! $popts{nolow}; |
503 | # Reorder | |||
504 | 1 | 7.0e-6 | 7.0e-6 | @colors = (0,23,26,29,30,20,21,22,19,17,24,1); |
505 | } | |||
506 | ||||
507 | sub 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 | ||||
527 | sub 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 | |||
535 | 1 | 2.0e-6 | 2.0e-6 | my $colormap = shift; |
536 | 1 | 1.0e-6 | 1.0e-6 | my $lbls = shift; |
537 | 1 | 2.0e-6 | 2.0e-6 | my $title = shift || ""; |
538 | 1 | 1.0e-6 | 1.0e-6 | my $mark = shift || 16; |
539 | 1 | 1.1e-5 | 1.1e-5 | my @labels = @$lbls; |
540 | 1 | 0 | 0 | my $text; |
541 | 1 | 1.0e-6 | 1.0e-6 | my ($vx0,$vx1,$vy0,$vy1); |
542 | 1 | 1.4e-5 | 1.4e-5 | pgqvp(0,$vx0,$vx1,$vy0,$vy1); # spent 12µs making 1 call to PGPLOT::pgqvp |
543 | 1 | 1.0e-6 | 1.0e-6 | my ($x0,$x1,$y0,$y1); |
544 | 1 | 1.5e-5 | 1.5e-5 | pgqwin($x0,$x1,$y0,$y1); # spent 13µs making 1 call to PGPLOT::pgqwin |
545 | 1 | 1.0e-6 | 1.0e-6 | my $lblsz = 0.75; |
546 | 1 | 6.0e-6 | 6.0e-6 | pgsch($lblsz); # spent 5µs making 1 call to PGPLOT::pgsch |
547 | 1 | 0 | 0 | my ($dtx,$dty); |
548 | 1 | 1.6e-5 | 1.6e-5 | pgqcs(4,$dtx,$dty); # spent 14µs making 1 call to PGPLOT::pgqcs |
549 | 1 | 3.0e-6 | 3.0e-6 | my $ystep = ($y1-$y0)/(@colors+1); |
550 | 1 | 2.0e-6 | 2.0e-6 | my $xvp2win = ($x1-$x0)/($vx1-$vx0); |
551 | 1 | 1.0e-6 | 1.0e-6 | my $yvp2win = ($y1-$y0)/($vy1-$vy0); |
552 | 1 | 1.0e-6 | 1.0e-6 | my $x = $x0 - $xvp2win*$vx0*.8; |
553 | 1 | 1.0e-6 | 1.0e-6 | my $y = $y1; |
554 | 1 | 4.0e-6 | 4.0e-6 | $y -= $ystep*(@colors - grep($_,@labels))/2 if @labels; |
555 | ||||
556 | 1 | 1.3e-5 | 1.3e-5 | pgsclp(0); # spent 11µs making 1 call to PGPLOT::pgsclp |
557 | ||||
558 | 1 | 2.0e-6 | 2.0e-6 | if($title) { |
559 | # Put the title of the color key at the bottom | |||
560 | 1 | 1.2e-5 | 1.2e-5 | pgsci(1); # spent 11µs making 1 call to PGPLOT::pgsci |
561 | 1 | 7.0e-6 | 7.0e-6 | pgsch(.75); # spent 5µs making 1 call to PGPLOT::pgsch |
562 | 1 | 0.01909 | 0.01909 | pgptext($x,$y0-$yvp2win*$vy0*.4,0,0,$title); # spent 19.1ms making 1 call to PGPLOT::pgptext |
563 | } | |||
564 | 1 | 1.0e-6 | 1.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 | |||
576 | 1 | 1.0e-6 | 1.0e-6 | my %seen; |
577 | 1 | 0.00094 | 0.00094 | for my $bin (sort {$a<=>$b} keys %$colormap) { |
578 | 589 | 0.00062 | 1.1e-6 | my $c = $colormap->{$bin}; |
579 | 589 | 0.00027 | 4.6e-7 | next if ! defined $c; |
580 | 589 | 0.00032 | 5.4e-7 | my $ci = $colors[$c] if defined $c; |
581 | #print "/$bin/$c/$ci/$labels[$c]/\n"; | |||
582 | 589 | 0.00049 | 8.4e-7 | next if ! defined $ci || ! defined $labels[$c] || $seen{$ci}++; |
583 | 10 | 5.0e-6 | 5.0e-7 | $text = $labels[$c]; |
584 | 10 | 6.1e-5 | 6.1e-6 | pgsci($ci); # spent 45µs making 10 calls to PGPLOT::pgsci, avg 4µs/call |
585 | 10 | 4.8e-5 | 4.8e-6 | pgsch(2); # spent 35µs making 10 calls to PGPLOT::pgsch, avg 3µs/call |
586 | 10 | 0.00031 | 3.1e-5 | pgpt(1,[$x],[$y],$mark); # spent 265µs making 10 calls to PGPLOT::pgpt, avg 26µs/call |
587 | 10 | 5.1e-5 | 5.1e-6 | pgsci(1); # spent 43µs making 10 calls to PGPLOT::pgsci, avg 4µs/call |
588 | 10 | 4.0e-5 | 4.0e-6 | pgsch($lblsz); # spent 29µs making 10 calls to PGPLOT::pgsch, avg 3µs/call |
589 | 10 | 0.00038 | 3.8e-5 | pgptext($x+$dtx,$y-$dty*.3,0,0,$text); # spent 355µs making 10 calls to PGPLOT::pgptext, avg 36µs/call |
590 | 10 | 1.2e-5 | 1.2e-6 | $y -= $ystep; |
591 | } | |||
592 | ||||
593 | 1 | 9.0e-6 | 9.0e-6 | pgsclp(1); # spent 8µs making 1 call to PGPLOT::pgsclp |
594 | ||||
595 | 1 | 7.0e-6 | 7.0e-6 | return; |
596 | } | |||
597 | ||||
598 | sub 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 | ||||
613 | sub 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 | ||||
697 | sub 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 | ||||
742 | sub 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 | |||
781 | 14736 | 0.00995 | 6.8e-7 | my $lon = shift; |
782 | 14736 | 0.00805 | 5.5e-7 | my $lat = shift; |
783 | 14736 | 0.00877 | 5.9e-7 | my $ht = shift || 1; |
784 | 14736 | 0.00882 | 6.0e-7 | my $lon0 = shift || 0; |
785 | 14736 | 0.00799 | 5.4e-7 | my $lat0 = shift || 0; |
786 | 14736 | 0.00732 | 5.0e-7 | my $pole = shift; |
787 | ||||
788 | #print "\t\t\tbefore lon,lat=$lon,$lat, lon0,lat0=$lon0,$lat0\n"; | |||
789 | 14736 | 0.06178 | 4.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] | |||
791 | 14736 | 0.08293 | 5.6e-6 | my ($x,$y) = WISE::CoUtilsXS::aitfwd($lon,$lat); # spent 57.0ms making 14736 calls to WISE::CoUtilsXS::aitfwd, avg 4µs/call |
792 | 14736 | 0.01221 | 8.3e-7 | $x *= $ht/2; |
793 | 14736 | 0.00842 | 5.7e-7 | $y *= $ht/2; |
794 | #print "\t\t\tafter lon,lat=$lon,$lat, x,y=$x,$y\n"; | |||
795 | ||||
796 | 14736 | 0.02426 | 1.6e-6 | return ($x, $y); |
797 | } | |||
798 | ||||
799 | sub 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 | |||
817 | 14736 | 0.00897 | 6.1e-7 | my $lon = shift; |
818 | 14736 | 0.00819 | 5.6e-7 | my $lon0 = shift || 0; |
819 | 14736 | 0.00745 | 5.1e-7 | my $lat = shift; |
820 | 14736 | 0.00793 | 5.4e-7 | my $lat0 = shift || 0; |
821 | 14736 | 0.00724 | 4.9e-7 | my $pole = shift; |
822 | ||||
823 | 14736 | 0.00662 | 4.5e-7 | if($pole) { |
824 | # Polar projection | |||
825 | ($lon,$lat) = WISE::CoUtilsXS::poleover($lon,$lat); | |||
826 | #$lon0 = $lat0 = 0; | |||
827 | } | |||
828 | ||||
829 | 14736 | 0.01397 | 9.5e-7 | $lon -= 360 if $lon> $lon0+180; |
830 | 14736 | 0.00991 | 6.7e-7 | $lon += 360 if $lon<=$lon0-180; |
831 | ||||
832 | 14736 | 0.00763 | 5.2e-7 | $lon -= $lon0; |
833 | ||||
834 | 14736 | 0.00887 | 6.0e-7 | if(defined $lat) { |
835 | $lat -= $lat0; | |||
836 | } | |||
837 | ||||
838 | 14736 | 0.03045 | 2.1e-6 | return wantarray ? ($lon,$lat) : $lon; |
839 | } | |||
840 | ||||
841 | sub 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 | |||
873 | 1 | 2.0e-6 | 2.0e-6 | my ($x0,$x1,$cen) = @_; |
874 | 1 | 1.0e-6 | 1.0e-6 | my $dx = $x1-$x0; |
875 | 1 | 2.0e-6 | 2.0e-6 | $dx = $dx>=0 ? $dx : 360+$dx; |
876 | 1 | 0 | 0 | if(defined $cen && $cen == 0 && $dx > 180) { |
877 | # Assume large angles means we crossed zero | |||
878 | $dx -= 360; | |||
879 | } | |||
880 | 1 | 2.0e-6 | 2.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 | |||
898 | 1 | 2.0e-6 | 2.0e-6 | my ($ht,$opts) = @_; |
899 | ||||
900 | 1 | 1.0e-6 | 1.0e-6 | $ht ||= 1; |
901 | 1 | 1.0e-6 | 1.0e-6 | $opts ||= {}; |
902 | ||||
903 | # Aitoff mins and maxes, before scaling by $ht. | |||
904 | 1 | 2.0e-6 | 2.0e-6 | my ($ax0,$ax1,$ay0,$ay1) = (-1.,1.,-.5,.5); |
905 | ||||
906 | 1 | 1.0e-6 | 1.0e-6 | $opts ||= {}; |
907 | ||||
908 | # Set options | |||
909 | 1 | 2.0e-6 | 2.0e-6 | my $ch = $opts->{ch} || 0.75; |
910 | 1 | 1.0e-6 | 1.0e-6 | my $coord = $opts->{coord} || 0; |
911 | 1 | 1.0e-6 | 1.0e-6 | my $title1= $opts->{title1} || ""; |
912 | 1 | 1.0e-6 | 1.0e-6 | my $title2= $opts->{title2} || ""; |
913 | 1 | 1.0e-6 | 1.0e-6 | my $lon0 = $opts->{lon0} || 0.; |
914 | 1 | 1.0e-6 | 1.0e-6 | my $lat0 = $opts->{lat0} || 0.; |
915 | 1 | 1.0e-6 | 1.0e-6 | my $nonum = $opts->{nonum}; |
916 | 1 | 1.0e-6 | 1.0e-6 | my $i20 = $opts->{i20}; |
917 | 1 | 1.0e-6 | 1.0e-6 | my $i30 = $opts->{i30}; |
918 | 1 | 1.0e-6 | 1.0e-6 | my $noint = $opts->{noint}; |
919 | 1 | 1.7e-5 | 1.7e-5 | my $nolin = $opts->{nolin}; |
920 | 1 | 1.0e-6 | 1.0e-6 | my $polok = $opts->{poleok}; |
921 | 1 | 1.0e-6 | 1.0e-6 | my $pole = $opts->{pole}; |
922 | 1 | 1.0e-6 | 1.0e-6 | my $do10 = $opts->{do10}; |
923 | ||||
924 | 1 | 1.0e-6 | 1.0e-6 | my ($x0,$x1,$y0,$y1,$rev); |
925 | 1 | 2.1e-5 | 2.1e-5 | pgqwin($x0,$x1,$y0,$y1); # spent 10µs making 1 call to PGPLOT::pgqwin |
926 | 1 | 3.0e-6 | 3.0e-6 | ($x0,$x1) = ($x1,$x0), $rev=-1 if $x1<$x0; |
927 | ||||
928 | 1 | 0 | 0 | return if $nolin; |
929 | ||||
930 | 1 | 1.6e-5 | 1.6e-5 | pgsci(1); # spent 15µs making 1 call to PGPLOT::pgsci |
931 | 1 | 9.0e-6 | 9.0e-6 | pgsch($ch); # spent 9µs making 1 call to PGPLOT::pgsch |
932 | 1 | 6.0e-6 | 6.0e-6 | pgstbg(-1); # spent 5µs making 1 call to PGPLOT::pgstbg |
933 | ||||
934 | 1 | 1.0e-6 | 1.0e-6 | my (@xbox,@ybox); |
935 | 1 | 3.5e-5 | 3.5e-5 | pgqtxt (50,50, 0, 0, "X", \@xbox, \@ybox); # spent 32µs making 1 call to PGPLOT::pgqtxt |
936 | 1 | 2.0e-6 | 2.0e-6 | my $dt = $ybox[1]-$ybox[0]; # Char. height in world coord.s |
937 | ||||
938 | 1 | 7.5e-5 | 7.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 |
939 | 1 | 7.1e-5 | 7.1e-5 | pgptext(0., $ht/2.+4.5*$dt,0,.5, $title1) if $title1; # spent 67µs making 1 call to PGPLOT::pgptext |
940 | 1 | 7.7e-5 | 7.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. | |||
943 | 1 | 2.0e-6 | 2.0e-6 | if(! $nonum || $polok) { |
944 | 1 | 1.0e-5 | 1.0e-5 | number(0, 90+0.5*$dt, 90, 0, 0, 2, 0); # spent 50µs making 1 call to WISE::PgAitoff::number |
945 | 1 | 8.0e-6 | 8.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 | ||||
948 | 1 | 1.0e-6 | 1.0e-6 | my ($i,$j,$ip,$x,$y,$lon,$lat,$lbllon,$lbllat); |
949 | ||||
950 | # Put pen at center. | |||
951 | 1 | 9.0e-6 | 9.0e-6 | versplot(0.,0.,3); # spent 78µs making 1 call to WISE::PgAitoff::versplot |
952 | # First draw and label the longitude lines ... | |||
953 | 1 | 3.6e-5 | 3.6e-5 | for($i=-180; $i<=180; $i+=10) { |
954 | 37 | 1.8e-5 | 4.9e-7 | $ip = 3; # Pen up |
955 | 37 | 0.00013 | 3.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. | |||
958 | 37 | 1.8e-5 | 4.9e-7 | $lon += .01 if $i == -180; |
959 | 37 | 1.4e-5 | 3.8e-7 | $lon -= .01 if $i == 180; |
960 | # Some futzing around to make sure all the correct longitude lines plot. | |||
961 | 37 | 2.6e-5 | 7.0e-7 | $lon += 360 if $lon < 0; |
962 | 37 | 1.8e-5 | 4.9e-7 | $lon -= 360 if $lon >= 360; |
963 | # Skip unwanted longitude lines depending on $i20 and $i30. | |||
964 | 37 | 2.1e-5 | 5.7e-7 | next if $i20 && abs($i)%20; |
965 | 37 | 5.8e-5 | 1.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. | |||
968 | 13 | 4.1e-5 | 3.2e-6 | next if $noint && abs($i) == 180; |
969 | 13 | 0.00045 | 3.5e-5 | for($j=-90; $j<=90; $j+=5) { |
970 | 481 | 0.00032 | 6.6e-7 | $lat = $j + $lat0; |
971 | # Draw no longitude lines above $lat 85 (except the outer lines). | |||
972 | 481 | 0.00034 | 7.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. | |||
976 | 459 | 0.00032 | 7.0e-7 | next if ! ($i20 || $i30) && abs($j)==85 && abs($i)%20; |
977 | # Get projection of current $lat and $lon. | |||
978 | 459 | 0.00262 | 5.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. | |||
980 | 459 | 0.00233 | 5.1e-6 | versplot($x,$y,$ip); # spent 16.5ms making 459 calls to WISE::PgAitoff::versplot, avg 36µs/call |
981 | 459 | 0.00030 | 6.5e-7 | $ip = 2; # Pen down |
982 | # Number the line | |||
983 | # Skip numbering if requested or if off-scale | |||
984 | 459 | 0.00026 | 5.7e-7 | next if $nonum; |
985 | # Don't label latitude 0 | |||
986 | 459 | 0.00026 | 5.7e-7 | next if $j == 0; |
987 | # Do not number the poles (already done). | |||
988 | 446 | 0.00031 | 6.9e-7 | next if abs($lat) > 85.; |
989 | # Print the latitude values along the center longitude (except | |||
990 | # 90 degrees) | |||
991 | 442 | 0.00052 | 1.2e-6 | next if $i != 0; |
992 | # Skip if off-plot | |||
993 | 34 | 5.6e-5 | 1.6e-6 | next if $x/$ht < $ax0 || $x/$ht > $ax1 || |
994 | $y/$ht < $ay0 || $y/$ht > $ay1; | |||
995 | # Only print requested intervals | |||
996 | 34 | 8.2e-5 | 2.4e-6 | next if $j%10; |
997 | 16 | 2.8e-5 | 1.8e-6 | next if $i20 && $j%20; |
998 | 16 | 3.5e-5 | 2.2e-6 | next if $i30 && $j%30; |
999 | # Round to 1 d.p. This hides sopme of the futzing around we do. | |||
1000 | 4 | 6.7e-5 | 1.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 |
1001 | 4 | 4.2e-5 | 1.0e-5 | versplot($x,$y,3); # spent 118µs making 4 calls to WISE::PgAitoff::versplot, avg 30µs/call |
1002 | 13 | 6.0e-6 | 4.6e-7 | } |
1003 | # Go to bottom of plot. | |||
1004 | 13 | 0.00014 | 1.1e-5 | versplot(0.,-$ht/2.,3); # spent 237µs making 13 calls to WISE::PgAitoff::versplot, avg 18µs/call |
1005 | 1 | 1.0e-6 | 1.0e-6 | } |
1006 | # | |||
1007 | # ... and then the latitude llines . . . . | |||
1008 | 1 | 0 | 0 | return if $noint; |
1009 | ||||
1010 | 1 | 1.4e-5 | 1.4e-5 | for($j=-90; $j<=90; $j+=10) { |
1011 | 19 | 1.3e-5 | 6.8e-7 | $ip = 3; # Pen up |
1012 | 19 | 5.0e-6 | 2.6e-7 | $lat = $j + $lat0; |
1013 | # This dodge substitutes the +-85 deg. arc for the unnecessary | |||
1014 | # +-90 point. | |||
1015 | 19 | 3.4e-5 | 1.8e-6 | $lat = 85.0 if $lat == 90.0; |
1016 | 19 | 6.0e-6 | 3.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. | |||
1020 | 19 | 3.1e-5 | 1.6e-6 | next if $i20 && ! ($do10 && abs($j)==10) && |
1021 | abs($j)%20 && abs($j) != 90; | |||
1022 | 19 | 2.1e-5 | 1.1e-6 | next if $i30 && ! ($do10 && abs($j)==10) && |
1023 | abs($j)%30 && abs($j) != 90; | |||
1024 | 7 | 0.00018 | 2.6e-5 | for($i=-180; $i<=180; $i+=10) { |
1025 | 259 | 0.00015 | 5.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. | |||
1028 | 259 | 0.00012 | 4.7e-7 | $lon += .01 if $i == -180; |
1029 | 259 | 0.00013 | 4.9e-7 | $lon -= .01 if $i == 180; |
1030 | # Futz the longitude. | |||
1031 | 259 | 0.00014 | 5.5e-7 | $lon += 360 if $lon < 0; |
1032 | 259 | 0.00014 | 5.4e-7 | $lon -= 360 if $lon >= 360; |
1033 | # Project ... | |||
1034 | 259 | 0.00140 | 5.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. | |||
1036 | 259 | 0.00110 | 4.2e-6 | versplot($x,$y,$ip); # spent 8.15ms making 259 calls to WISE::PgAitoff::versplot, avg 31µs/call |
1037 | 259 | 0.00016 | 6.1e-7 | $ip = 2; # Pen down |
1038 | # Number the line | |||
1039 | # Skip if not numbering. | |||
1040 | 259 | 0.00013 | 5.1e-7 | next if $nonum; |
1041 | # Print out the longitude values along the equator (0 - 360 dgs) | |||
1042 | 259 | 0.00035 | 1.4e-6 | next if abs($lat-$lat0) > .1; |
1043 | # Skip if off-plot | |||
1044 | 37 | 6.3e-5 | 1.7e-6 | next if $x/$ht < $ax0 || $x/$ht > $ax1 || |
1045 | $y/$ht < $ay0 || $y/$ht > $ay1; | |||
1046 | # Only print requested intervals | |||
1047 | 37 | 1.6e-5 | 4.3e-7 | next if $i20 && $i%20; |
1048 | 37 | 3.6e-5 | 9.7e-7 | next if $i30 && $i%30; |
1049 | # Round to 1 d.p. This hides sopme of the futzing around we do. | |||
1050 | 13 | 8.8e-5 | 6.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 |
1051 | 13 | 5.6e-5 | 4.3e-6 | versplot($x,$y,3); # spent 145µs making 13 calls to WISE::PgAitoff::versplot, avg 11µs/call |
1052 | 7 | 3.0e-6 | 4.3e-7 | } |
1053 | 1 | 1.0e-6 | 1.0e-6 | } |
1054 | ||||
1055 | 1 | 4.0e-6 | 4.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 | |||
1060 | 19 | 5.3e-5 | 2.8e-6 | my ($x,$y,$num,$ang,$just,$fld,$nd) = @_; |
1061 | ||||
1062 | 19 | 7.1e-5 | 3.7e-6 | my $str = sprintf("%.${nd}f",$num); |
1063 | 19 | 0.00082 | 4.3e-5 | pgptext($x,$y,$ang,$just,$str); # spent 790µs making 19 calls to PGPLOT::pgptext, avg 42µs/call |
1064 | ||||
1065 | 19 | 5.0e-5 | 2.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 | |||
1069 | 749 | 0.00128 | 1.7e-6 | my ($x,$y,$pen) = @_; |
1070 | ||||
1071 | 749 | 0.00084 | 1.1e-6 | pgmove($x,$y) if $pen == 3; # spent 318µs making 51 calls to PGPLOT::pgmove, avg 6µs/call |
1072 | 749 | 0.01982 | 2.6e-5 | pgdraw($x,$y) if $pen == 2; # spent 18.5ms making 698 calls to PGPLOT::pgdraw, avg 26µs/call |
1073 | ||||
1074 | 749 | 0.00109 | 1.5e-6 | return; |
1075 | } | |||
1076 | ||||
1077 | # Return the max of a list | |||
1078 | sub 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 | |||
1087 | sub 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 | ||||
1095 | sub 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 | |||
1248 | 1 | 2.0e-6 | 2.0e-6 | my ($xmn,$xmx,$ymn,$ymx) = @_; |
1249 | ||||
1250 | 1 | 5.0e-6 | 5.0e-6 | return abs( 0-$xmn)<5 && abs(360-$xmx)<5 && |
1251 | abs(-90-$ymn)<5 && abs( 90-$ymx)<5; | |||
1252 | } | |||
1253 | ||||
1254 | sub 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 | ||||
1272 | sub 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 | ||||
1281 | 1 | 1.3e-5 | 1.3e-5 | 1; |