File | /wise/base/deliv/dev/lib/perl/WISE/Ingest/GroundTrack.pm | Statements Executed | 31 | Total Time | 0.002231 seconds |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine | |
---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | WISE::Ingest::GroundTrack:: | BEGIN |
0 | 0 | 0 | 0 | 0 | WISE::Ingest::GroundTrack:: | _isopt |
0 | 0 | 0 | 0 | 0 | WISE::Ingest::GroundTrack:: | data |
0 | 0 | 0 | 0 | 0 | WISE::Ingest::GroundTrack:: | dumptbl |
0 | 0 | 0 | 0 | 0 | WISE::Ingest::GroundTrack:: | file_ets |
0 | 0 | 0 | 0 | 0 | WISE::Ingest::GroundTrack:: | naif |
0 | 0 | 0 | 0 | 0 | WISE::Ingest::GroundTrack:: | nearest |
0 | 0 | 0 | 0 | 0 | WISE::Ingest::GroundTrack:: | new |
0 | 0 | 0 | 0 | 0 | main:: | BEGIN |
Line | Stmts. | Exclusive Time | Avg. | Code |
---|---|---|---|---|
1 | #! /usr/bin/env perl | |||
2 | ||||
3 | 3 | 2.8e-5 | 9.3e-6 | use strict; # spent 11µs making 1 call to strict::import |
4 | 3 | 4.9e-5 | 1.6e-5 | use warnings; # spent 21µs making 1 call to warnings::import |
5 | ||||
6 | package WISE::Ingest::GroundTrack; | |||
7 | ||||
8 | 1 | 1.0e-6 | 1.0e-6 | my $pkg = __PACKAGE__; |
9 | ||||
10 | use WISE::Env ( | |||
11 | mod => __PACKAGE__, # spent 488µs making 1 call to WISE::Env::import | |||
12 | cfglib => '<:LIB:>', | |||
13 | version => '$Id: GroundTrack.pm 5995 2009-10-15 20:09:27Z tim $ ', | |||
14 | 3 | 2.9e-5 | 9.7e-6 | ); |
15 | ||||
16 | 3 | 2.9e-5 | 9.7e-6 | use Exporter::Lite; # spent 31µs making 1 call to Exporter::Lite::import |
17 | 3 | 9.4e-5 | 3.1e-5 | use vars qw(@ISA @EXPORT_OK); # spent 37µs making 1 call to vars::import |
18 | 1 | 1.0e-6 | 1.0e-6 | @EXPORT_OK = (); |
19 | ||||
20 | sub _isopt { | |||
21 | my $r = @_ ? shift : $_; | |||
22 | return ref($r)=~/hash/i && ! UNIVERSAL::isa($r,__PACKAGE__); | |||
23 | } | |||
24 | ||||
25 | 1 | 3.9e-5 | 3.9e-5 | my ($err, $warn) = WISE::Env->err_prefix(); # spent 59µs making 1 call to WISE::Env::err_prefix |
26 | ||||
27 | 3 | 2.7e-5 | 9.0e-6 | use WISE; # spent 668µs making 1 call to WISE::import |
28 | 3 | 5.9e-5 | 2.0e-5 | use WISE::Ingest::NAIF; # spent 46µs making 1 call to Exporter::Lite::import |
29 | 3 | 2.9e-5 | 9.7e-6 | use Time::HiRes qw(time); # spent 241µs making 1 call to Time::HiRes::import |
30 | 3 | 0.00181 | 0.00060 | use File::Slurp; # spent 68µs making 1 call to Exporter::import |
31 | ||||
32 | # Ground track file: | |||
33 | #*--------------------------------------------------------------------------------------------------- | |||
34 | #* Date and Time Geocentric Latitude East Longitude GCD2SAA Geodetic Height | |||
35 | #* (UTC) (deg) (deg) (deg) (km) | |||
36 | #*--------------------------------------------------------------------------------------------------- | |||
37 | # 2010-171T11:45:00.0000 -82.458000 189.426353 42.853864 545.524112 | |||
38 | # 2010-171T11:45:04.0000 -82.477020 187.493299 43.022346 545.529101 | |||
39 | # 2010-171T11:45:08.0000 -82.487683 185.552735 43.191392 545.533232 | |||
40 | # 2010-171T11:45:12.0000 -82.489956 183.608857 43.360999 545.536504 | |||
41 | # 2010-171T11:45:16.0000 -82.483828 181.665983 43.531154 545.538918 | |||
42 | ||||
43 | ||||
44 | sub new { | |||
45 | my $class = shift; # WISE::Ingest::GroundTrack | |||
46 | my $opts = @_ && _isopt($_[-1]) ? pop : {}; | |||
47 | my $trkfiles = shift; | |||
48 | my $verbose = $opts->{verbose}; | |||
49 | my ($t0,$t1) = @{ $opts->{range} || [] }; | |||
50 | my $this = {}; | |||
51 | my $naif = $opts->{naif}; | |||
52 | my $dt = $opts->{dt} || 4; | |||
53 | $class = ref($class) || $class; | |||
54 | $trkfiles = [$trkfiles] if ! ref $trkfiles; | |||
55 | ||||
56 | if(! $naif) { | |||
57 | $naif = WISE::Ingest::NAIF->new() or die; | |||
58 | } | |||
59 | $this->{naif} = $naif; | |||
60 | ||||
61 | my @cols = qw/unixt et utc lat lon gcd2saa alt /; | |||
62 | $this->{names} = \@cols; | |||
63 | $this->{types} = [qw/r r c r r r r /]; | |||
64 | $this->{blanks}= [qw/null null null null null null null/]; | |||
65 | $this->{units} = [qw/secs secs - deg deg deg deg /]; | |||
66 | my %data; | |||
67 | my $n = 0; | |||
68 | my ($min,$max) = (1e30,-1e30); | |||
69 | for my $trk (@$trkfiles) { | |||
70 | my $lines = File::Slurp::read_file($trk, array_ref=>1); | |||
71 | my ($et,$t); | |||
72 | for (@$lines) { | |||
73 | next if /^\s*\*/; | |||
74 | chomp; | |||
75 | my @row = split " "; | |||
76 | if(! $et) { | |||
77 | $et = $naif->utc2et($row[0]) or die; | |||
78 | $t = WISE::Time::Str_time($row[0],{z=>1}) or die; | |||
79 | } else { | |||
80 | $et += $dt; | |||
81 | } | |||
82 | next if $et>=$min && $et<=$max; # Skip overlapping records | |||
83 | $min = $et if $et<$min; | |||
84 | $max = $et if $et>$max; | |||
85 | unshift @row, $t,$et; | |||
86 | push @{$data{$cols[$_]}},$row[$_] for 0..$#cols; | |||
87 | ++$n; | |||
88 | } | |||
89 | } | |||
90 | ||||
91 | $this->{rows} = \%data; | |||
92 | $this->{data} = \%data; | |||
93 | $this->{nrows} = $n; | |||
94 | ||||
95 | $this->{et0} = $min; | |||
96 | $this->{et1} = $max; | |||
97 | ||||
98 | my %index; | |||
99 | my $itlast = 0; | |||
100 | $index{0} = 0; | |||
101 | for my $i (1..$n-1) { | |||
102 | my $t = $data{et}[$i] - $data{et}[0] + 0; | |||
103 | my $it = int($t / 100); | |||
104 | $index{$it} = $i if ! defined $index{$it}; | |||
105 | if($it > $itlast+1) { | |||
106 | for my $jt ($itlast+1..$it-1) { | |||
107 | $index{$jt} = $index{$itlast} | |||
108 | } | |||
109 | } | |||
110 | $itlast = $it; | |||
111 | } | |||
112 | ||||
113 | $this->{index} = \%index; | |||
114 | ||||
115 | bless $this, $class; | |||
116 | ||||
117 | return $this; | |||
118 | } | |||
119 | ||||
120 | sub naif { | |||
121 | my $this = shift; | |||
122 | my $opts = @_ && _isopt($_[-1]) ? pop : {}; | |||
123 | my $naif = shift; | |||
124 | if(defined $naif) { | |||
125 | $this->{naif} = $naif; | |||
126 | } | |||
127 | return $this->{naif}; | |||
128 | } | |||
129 | ||||
130 | sub data { | |||
131 | my $this = shift; | |||
132 | return $this->{data}; | |||
133 | } | |||
134 | ||||
135 | sub dumptbl { | |||
136 | my $this = shift; | |||
137 | my $opts = @_ && _isopt($_[-1]) ? pop : {}; | |||
138 | my $tblfile = shift || "-"; | |||
139 | my $verbose = $opts->{verbose}; | |||
140 | my $tbl = WISE::IPACTbl->new($tblfile,"w",$this,{data=>$this->{data}}) | |||
141 | or die "$err: Unable to dump survey plan to table '$tblfile'.\n"; | |||
142 | return $tbl->data($this->{data}); | |||
143 | } | |||
144 | ||||
145 | sub nearest { | |||
146 | my $this = shift; | |||
147 | my $opts = @_ && _isopt($_[-1]) ? pop : {}; | |||
148 | my $t = shift; | |||
149 | my $naif = $this->{naif}; | |||
150 | $t = $naif->etordate2et($t,{unixt=>$opts->{unixt}}); | |||
151 | my $utc = WISE::Time::Time_str($t,{form=>4}); | |||
152 | my $data = $this->{data}; | |||
153 | my $index = $this->{index}; | |||
154 | my $t0 = $data->{et}[0]; | |||
155 | my $t1 = $data->{et}[-1]; | |||
156 | my $i_min; | |||
157 | if($t < $t0) { | |||
158 | $i_min = 0; | |||
159 | } elsif($t > $t1) { | |||
160 | $i_min = $#{$data->{et}}; | |||
161 | } else { | |||
162 | my $ix = int(($t - $data->{et}[0]) / 100); | |||
163 | my $i0 = $index->{$ix-1} || 0; | |||
164 | my $i1 = $index->{$ix+1} || $#{$data->{t}}; | |||
165 | if($i1 == $i0) { $i1 = $i0+1 } | |||
166 | my $dt_min; | |||
167 | for my $i ($i0..$i1) { | |||
168 | my $t_i = $data->{et}[$i]; | |||
169 | my $dt = $t_i - $t; | |||
170 | if(! defined $dt_min || abs($dt) < $dt_min) { | |||
171 | $dt_min = abs($dt); | |||
172 | $i_min = $i; | |||
173 | } | |||
174 | } | |||
175 | } | |||
176 | my %row = map { ($_ => $data->{$_}[$i_min]) } keys %$data; | |||
177 | $row{dt} = $row{et} - $t; | |||
178 | return \%row; | |||
179 | } | |||
180 | ||||
181 | sub file_ets { | |||
182 | my $this = shift; | |||
183 | return ($this->{et0},$this->{et1}); | |||
184 | } | |||
185 | ||||
186 | 1 | 4.0e-5 | 4.0e-5 | 1; |