Astro-satpass

 view release on metacpan or  search on metacpan

lib/Astro/Coord/ECI/TLE.pm  view on Meta::CPAN

#	the corresponding FORTRAN IV simply leaves values in variables
#	for the use of the other deep-space routines. For the Perl
#	translation, we figure out which ones are actually used, and
#	return a list of key/value pairs to be added to the pre-
#	computed model parameters. -- TRW

sub _dpinit {
    my ($self, $eqsq, $siniq, $cosiq, $rteqsq, $a0, $cosq2, $sinomo,
	    $cosomo, $bsq, $xlldot, $omgdt, $xnodot, $xnodp) = @_;

    my $thgr = thetag ($self->{epoch});
    my $eq  =  $self->{eccentricity};
    my $xnq  =  $xnodp;
    my $aqnv  =  1 / $a0;
    my $xqncl  =  $self->{inclination};
    my $xmao = $self->{meananomaly};
    my $xpidot = $omgdt + $xnodot;
    my $sinq  =  sin ($self->{ascendingnode});
    my $cosq  =  cos ($self->{ascendingnode});

#*	Initialize lunar & solar terms

    my $day = $self->{ds50} + 18261.5;

#>>>	The original code contained here a comparison of DAY to
#>>>	uninitialized variable PREEP, and "optimized out" the
#>>>	following if they were equal. This works naturally in
#>>>	FORTRAN, which has a different concept of variable scoping.
#>>>	Rather than make this work in Perl, I have removed the
#>>>	test. As I understand the FORTRAN, it's only used if
#>>>	consecutive data sets have exactly the same epoch. Given
#>>>	that this is initialization code, the optimization is
#>>>	(I hope!) not that important, and given the mess that
#>>>	follows, its absence will not (I hope!) be noticable. - TRW

    my $xnodce = 4.5236020 - 9.2422029E-4 * $day;
    my $stem = sin ($xnodce);
    my $ctem = cos ($xnodce);
    my $zcosil = .91375164 - .03568096 * $ctem;
    my $zsinil = sqrt (1 - $zcosil * $zcosil);
    my $zsinhl =  .089683511 * $stem / $zsinil;
    my $zcoshl = sqrt (1 - $zsinhl * $zsinhl);
    my $c = 4.7199672 + .22997150 * $day;
    my $gam = 5.8351514 + .0019443680 * $day;
    my $zmol = mod2pi ($c - $gam);
    my $zx = .39785416 * $stem / $zsinil;
    my $zy = $zcoshl * $ctem + 0.91744867 * $zsinhl * $stem;
    $zx = _actan ($zx, $zy);
    $zx = $gam + $zx - $xnodce;
    my $zcosgl = cos ($zx);
    my $zsingl = sin ($zx);
    my $zmos = mod2pi (6.2565837 + .017201977 * $day);

#>>>	Here endeth the optimization - only it isn't one any more
#>>>	since I removed it. - TRW

#>>>	The following loop replaces some spaghetti involving an
#>>>	assigned goto which essentially executes the same big chunk
#>>>	of obscure code twice: once for the Sun, and once for the Moon.
#>>>	The comments "Do Solar terms" and "Do Lunar terms" in the
#>>>	original apply to the first and second iterations of the loop,
#>>>	respectively. The "my" variables declared just before the "for"
#>>>	are those values computed inside the loop that are used outside
#>>>	the loop. Accumulators are set to zero. -- TRW

#>>>trw    my $savtsn = 1.0E20;
    my $xnoi = 1 / $xnq;
    my ($sse, $ssi, $ssl, $ssh, $ssg) = (0, 0, 0, 0, 0);
    my ($se2, $ee2, $si2, $xi2, $sl2, $xl2, $sgh2, $xgh2, $sh2, $xh2, $se3,
	$e3, $si3, $xi3, $sl3, $xl3, $sgh3, $xgh3, $sh3, $xh3, $sl4, $xl4,
	$sgh4, $xgh4);

    foreach my $inputs (
	    [DS_ZCOSGS, DS_ZSINGS, DS_ZCOSIS, DS_ZSINIS, $cosq, $sinq,
		    DS_C1SS, DS_ZNS, DS_ZES, $zmos, 0],
	    [$zcosgl, $zsingl, $zcosil, $zsinil,
		    $zcoshl * $cosq + $zsinhl * $sinq,
		    $sinq * $zcoshl - $cosq * $zsinhl, DS_C1L, DS_ZNL,
		    DS_ZEL, $zmol, 1],
	    ) {

#>>>	Pick off the terms specific to the body being covered by this
#>>>	iteration. The $lunar flag was not in the original FORTRAN, but
#>>>	was added to help convert the assigned GOTOs and associated
#>>>	code into a loop. -- TRW

#>>>trw	my ($zcosg, $zsing, $zcosi, $zsini, $zcosh, $zsinh, $cc, $zn, $ze,
#>>>trw	    $zmo, $lunar) = @$inputs;
	my ($zcosg, $zsing, $zcosi, $zsini, $zcosh, $zsinh, $cc, $zn, $ze,
	    undef, $lunar) = @$inputs;

#>>>	From here until the next comment of mine is essentialy
#>>>	verbatim from the original FORTRAN - or as verbatim as
#>>>	is reasonable considering that the following is Perl. -- TRW

	my $a1 = $zcosg * $zcosh + $zsing * $zcosi * $zsinh;
	my $a3 = - $zsing * $zcosh + $zcosg * $zcosi * $zsinh;
	my $a7 = - $zcosg * $zsinh + $zsing * $zcosi * $zcosh;
	my $a8 = $zsing * $zsini;
	my $a9 = $zsing * $zsinh + $zcosg * $zcosi * $zcosh;
	my $a10 = $zcosg * $zsini;
	my $a2 = $cosiq * $a7 + $siniq * $a8;
	my $a4 = $cosiq * $a9 + $siniq * $a10;
	my $a5 = - $siniq * $a7 + $cosiq * $a8;
	my $a6 = - $siniq * $a9 + $cosiq * $a10;
#C
	my $x1 = $a1 * $cosomo + $a2 * $sinomo;
	my $x2 = $a3 * $cosomo + $a4 * $sinomo;
	my $x3 = - $a1 * $sinomo + $a2 * $cosomo;
	my $x4 = - $a3 * $sinomo + $a4 * $cosomo;
	my $x5 = $a5 * $sinomo;
	my $x6 = $a6 * $sinomo;
	my $x7 = $a5 * $cosomo;
	my $x8 = $a6 * $cosomo;
#C
	my $z31 = 12 * $x1 * $x1 - 3 * $x3 * $x3;
	my $z32 = 24 * $x1 * $x2 - 6 * $x3 * $x4;
	my $z33 = 12 * $x2 * $x2 - 3 * $x4 * $x4;
	my $z1 = 3 * ($a1 * $a1 + $a2 * $a2) + $z31 * $eqsq;
	my $z2 = 6 * ($a1 * $a3 + $a2 * $a4) + $z32 * $eqsq;
	my $z3 = 3 * ($a3 * $a3 + $a4 * $a4) + $z33 * $eqsq;



( run in 0.505 second using v1.01-cache-2.11-cpan-71847e10f99 )