← Index
Performance Profile   « block view • line view • sub view »
For /wise/base/deliv/dev/bin/wdate
  Run on Fri Jun 4 15:13:22 2010
Reported on Fri Jun 4 15:14:17 2010

File/wise/base/deliv/dev/lib/perl/WISE/Ingest/SurveyPlan.pm
Statements Executed28
Total Time0.001592 seconds

Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
00000WISE::Ingest::SurveyPlan::BEGIN
00000WISE::Ingest::SurveyPlan::_isopt
00000WISE::Ingest::SurveyPlan::data
00000WISE::Ingest::SurveyPlan::dumptbl
00000WISE::Ingest::SurveyPlan::naif
00000WISE::Ingest::SurveyPlan::nearest
00000WISE::Ingest::SurveyPlan::new

LineStmts.Exclusive
Time
Avg.Code
1#! /usr/bin/env perl
2
332.8e-59.3e-6use strict;
# spent 13µs making 1 call to strict::import
435.4e-51.8e-5use warnings;
# spent 31µs making 1 call to warnings::import
5
6package WISE::Ingest::SurveyPlan;
7
811.0e-61.0e-6my $pkg = __PACKAGE__;
9
10use WISE::Env (
11 mod => __PACKAGE__,
# spent 527µs making 1 call to WISE::Env::import
12 cfglib => '<:LIB:>',
13 version => '$Id: SurveyPlan.pm 5619 2009-08-21 20:30:50Z tim $ ',
1432.9e-59.7e-6 );
15
1633.7e-51.2e-5use Exporter::Lite;
# spent 44µs making 1 call to Exporter::Lite::import
1739.8e-53.3e-5use vars qw(@ISA @EXPORT_OK);
# spent 43µs making 1 call to vars::import
1811.0e-61.0e-6@EXPORT_OK = ();
19
20sub _isopt {
21 my $r = @_ ? shift : $_;
22 return ref($r)=~/hash/i && ! UNIVERSAL::isa($r,__PACKAGE__);
23}
24
2511.1e-51.1e-5my ($err, $warn) = WISE::Env->err_prefix();
# spent 18µs making 1 call to WISE::Env::err_prefix
26
2732.6e-58.7e-6use WISE;
# spent 582µs making 1 call to WISE::import
2832.9e-59.7e-6use WISE::Ingest::NAIF;
# spent 19µs making 1 call to Exporter::Lite::import
2930.001270.00042use Time::HiRes qw(time);
# spent 130µs making 1 call to Time::HiRes::import
30
31# Survey plan:
32#T68_maneuver Q1 Q2 Q3 Q4 Wx Wy Wz
33#1314339801.872 0.019401 -0.183072 0.955781 -0.229326 -0.001 3.785 0.000
34# T68_start T68_end
35# 1314339440.05 1314340855.99
36
37# Centers and times:
38#UTC Elon Elat
39#09336000000 342.437 -5.715
40
41sub new {
42 my $class = shift; # WISE::Ingest::HK
43 my $opts = @_ && _isopt($_[-1]) ? pop : {};
44 my $mpfile = shift;
45 my $verbose = $opts->{verbose};
46 my $centers = $opts->{centers};
47 my $table = $opts->{table} // ($mpfile =~ /\.tbl(\.gz)?$/);
48 my ($t0,$t1) = @{ $opts->{range} || [] };
49 my $this = {};
50 $class = ref($class) || $class;
51
52 if($table) {
53
54 my $tbl = WISE::IPACTbl->new($mpfile,{fast=>1})
55 or die "$err: Unable to read survey table '$mpfile'.\n";
56
57 my $data = $tbl->data();
58
59 $this = $tbl; # Rebless below
60 $this->{data} = $this->{rows};
61
62 } else {
63
64 my $naif = WISE::Ingest::NAIF->new();
65
66 my $to_open;
67 if($mpfile =~ /\.gz$/) {
68 $to_open = "gzip -dc $mpfile |"
69 } else {
70 $to_open = "<$mpfile";
71 }
72
73 $t0 = WISE::Time::Str_time($t0,{z=>1}) if defined $t0;
74 $t1 = WISE::Time::Str_time($t1,{z=>1}) if defined $t1;
75
76 open(my $mpfh, $to_open)
77 or die "$err: Unable to open mission plan file as '$to_open'; ".
78 "$!.\n";
79
80 my %cols;
81 my $n = 0;
82 my $elat_last = 999;
83 my $t_last;
84 my ($t68,$t68_end,$t68_man,$utc,$utc_man,$t,$elon,$elat);
85
86 while(<$mpfh>) {
87 next if ! /^\d/;
88 chomp;
89 my @cols = split " ";
90 if(! defined $centers) {
91 $centers = @cols == 3;
92 }
93 if(! $centers) {
94 $t68_man = $cols[0];
95 $t68 = $cols[8];
96 $t68_end = $cols[9];
97 $utc = $naif->plan2utc($t68);
98 $utc_man = $naif->plan2utc($t68_man);
99 $t = WISE::Time::Str_time($utc,{z=>1});
100 } else {
101 ($utc,$elon,$elat) = @cols;
102 next if abs($elat-$elat_last)<1;
103 $t = WISE::Time::Str_time($utc,{z=>1} );
104 $utc = WISE::Time::Time_str($t, {form=>4});
105 $t68 = $naif->utc2plan($utc);
106 }
107 next if defined $t0 && $t < $t0;
108 next if defined $t1 && $t > $t1;
109 die "$err: Records out of order at row $. in survey file ".
110 "'$mpfile'.\n"
111 if $t_last && $t <= $t_last;
112 push @{$cols{t}}, $t;
113 push @{$cols{utc}}, $utc;
114 push @{$cols{utc_man}},$utc_man if defined $t68_man;
115 push @{$cols{t68}}, $t68;
116 push @{$cols{t68_man}},$t68_man if defined $t68_man;
117 if(defined $elon) {
118 push @{$cols{elon}}, $elon;
119 push @{$cols{elat}}, $elat;
120 }
121 ++$n;
122 } continue {
123 $elat_last = $elat;
124 $t_last = $t;
125 }
126
127 my (@names,@types);
128 if(! $centers) {
129 @names = qw/t utc utc_man t68 t68_man/;
130 @types = qw/r c c r r/;
131 } else {
132 @names = qw/t utc t68 elon elat/;
133 @types = qw/r c r r r /;
134 }
135
136 $this->{rows} = \%cols;
137 $this->{data} = \%cols;
138 $this->{nrows} = $n;
139 $this->{names} = \@names;
140 $this->{types} = \@types;
141 $this->{blanks} = [('null') x @names];
142
143 }
144
145 my $n = $this->{nrows};
146 my $data = $this->{data};
147
148 my %index;
149 my $itlast = 0;
150 $index{0} = 0;
151 for my $i (1..$n-1) {
152 my $t = $data->{t}[$i] - $data->{t}[0] + 0;
153 my $it = int($t / 100);
154 $index{$it} = $i if ! defined $index{$it};
155 if($it > $itlast+1) {
156 for my $jt ($itlast+1..$it-1) {
157 $index{$jt} = $index{$itlast}
158 }
159 }
160 $itlast = $it;
161 }
162
163 $this->{index} = \%index;
164
165 bless $this, $class;
166
167 return $this;
168}
169
170sub naif {
171 my $this = shift;
172 my $opts = @_ && _isopt($_[-1]) ? pop : {};
173 my $naif = shift;
174 if(defined $naif) {
175 $this->{naif} = $naif;
176 }
177 return $this->{naif};
178}
179
180sub data {
181 my $this = shift;
182 return $this->{data};
183}
184
185sub dumptbl {
186 my $this = shift;
187 my $opts = @_ && _isopt($_[-1]) ? pop : {};
188 my $tblfile = shift || "-";
189 my $verbose = $opts->{verbose};
190 my $tbl = WISE::IPACTbl->new($tblfile,"w",$this,{data=>$this->{data}})
191 or die "$err: Unable to dump survey plan to table '$tblfile'.\n";
192 return $tbl->data($this->{data});
193}
194
195sub nearest {
196 my $this = shift;
197 my $opts = @_ && _isopt($_[-1]) ? pop : {};
198 my $t = shift;
199 my $after = $opts->{after};
200 my $before = $opts->{before};
201 $t = WISE::Time::Str_time($t,{z=>1});
202 my $data = $this->{data};
203 my $index = $this->{index};
204 my $t0 = $data->{t}[0];
205 my $t1 = $data->{t}[-1];
206 my $i_min;
207 if($t < $t0) {
208 if($before) { return; }
209 $i_min = 0;
210 } elsif($t > $t1) {
211 if($after) { return; }
212 $i_min = $#{$data->{t}};
213 } else {
214 my $ix = int(($t - $data->{t}[0]) / 100);
215 my $i0 = $index->{$ix-1} || 0;
216 my $i1 = $index->{$ix+1} || $#{$data->{t}};
217 if($i1 == $i0) { $i1 = $i0+1 }
218 my $dt_min;
219 for my $i ($i0..$i1) {
220 my $t_i = $data->{t}[$i];
221 my $dt = $t_i - $t;
222 next if $before && $dt > 0;
223 next if $after && $dt < 0;
224 if(! defined $dt_min || abs($dt) < $dt_min) {
225 $dt_min = abs($dt);
226 $i_min = $i;
227 }
228 }
229 }
230 my %row = map { ($_ => $data->{$_}[$i_min]) } keys %$data;
231 $row{dt} = $row{t} - $t;
232 return \%row;
233}
234
23516.0e-66.0e-61;