← 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:22 2010

File/wise/base/deliv/dev/lib/perl/WISE/Ingest/GroundTrack.pm
Statements Executed31
Total Time0.002231 seconds

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

LineStmts.Exclusive
Time
Avg.Code
1#! /usr/bin/env perl
2
332.8e-59.3e-6use strict;
# spent 11µs making 1 call to strict::import
434.9e-51.6e-5use warnings;
# spent 21µs making 1 call to warnings::import
5
6package WISE::Ingest::GroundTrack;
7
811.0e-61.0e-6my $pkg = __PACKAGE__;
9
10use 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 $ ',
1432.9e-59.7e-6 );
15
1632.9e-59.7e-6use Exporter::Lite;
# spent 31µs making 1 call to Exporter::Lite::import
1739.4e-53.1e-5use vars qw(@ISA @EXPORT_OK);
# spent 37µ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
2513.9e-53.9e-5my ($err, $warn) = WISE::Env->err_prefix();
# spent 59µs making 1 call to WISE::Env::err_prefix
26
2732.7e-59.0e-6use WISE;
# spent 668µs making 1 call to WISE::import
2835.9e-52.0e-5use WISE::Ingest::NAIF;
# spent 46µs making 1 call to Exporter::Lite::import
2932.9e-59.7e-6use Time::HiRes qw(time);
# spent 241µs making 1 call to Time::HiRes::import
3030.001810.00060use 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
44sub 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
120sub 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
130sub data {
131 my $this = shift;
132 return $this->{data};
133}
134
135sub 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
145sub 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
181sub file_ets {
182 my $this = shift;
183 return ($this->{et0},$this->{et1});
184}
185
18614.0e-54.0e-51;