OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
eanom.c
Go to the documentation of this file.
1 /*
2  *----------------------------------------------------------------------
3  * @(#) eanom.c 1.0 02 Apr 98 <shc>
4  * Copyright (c) 1993, CSIRO Division of Oceanography
5  * Copyright (c) 1998, Datron Transco Inc.
6  *----------------------------------------------------------------------
7  *
8  * eanom --
9  *
10  * Mean anomaly to eccentric anomaly iteration.
11  *
12  * Results:
13  *
14  * Calculate eccentric anomaly from mean anomaly using modified Newton
15  * iteration. No angle normalisation is done here in order to retain
16  * the notion of the mean and eccentric anomalies increasing monotonically
17  * with time. Inputs are mean anomaly (MANOM) and orbit eccentricity
18  * (ECC), result is the corresponding eccentric anomaly to absolute
19  * precision EPS.
20  *
21  * On error, ERRSTR is set to point to an error message and the
22  * value FP_ERRVAL is returned, since many systems do not have NaN
23  * definitions.
24  *
25  * Side effects:
26  * None.
27  *
28  * History:
29  * 30 Mar 93 <shc>
30  * Converted from FORTRAN to C.
31  *
32  * 12 Dec 94 <shc>
33  * Added errmsg stuff for integration with Python
34  *
35  * 02 Apr 98 <shc>
36  * Added dual EPS limits and increased MAXIT from 10 to 100 to
37  * reduce incidence of convergence failures.
38  *
39  * 13 Apr 98 <shc>
40  * Changed to use same convergence scheme as ktosgp4(): iterate
41  * to convergence, then do another couple of steps for good measure.
42  *
43  *----------------------------------------------------------------------
44  */
45 
46 #include <stdio.h>
47 #include "orbit.h"
48 
49 #define MAXIT 100 /* Maximum numer of iterations */
50 #define EPS 1.0e-12 /* Error goal */
51 
52 double
53 eanom(manom, ecc, errmsg)
54 double manom, ecc;
55 char **errmsg;
56 {
57  int i, converged;
58  double delta, ea, func, ean;
59 
60  if (ecc < 0.0 || ecc > 1.0) {
61  if (errmsg != NULL)
62  *errmsg = "eanom - non-elliptic orbit";
63  return FP_ERRVAL;
64  }
65 
66  ea = manom;
67  for (i = converged = 0; i < MAXIT && converged < 2; i++) {
68  func = ea - ecc * sin(ea) - manom;
69  ean = ea - func / (1.0 - ecc * cos(ea - func / 2.0));
70  delta = ean - ea;
71  if (fabs(delta) < EPS) {
72  converged += 1;
73  }
74  ea = ean;
75  }
76 
77  if (converged) {
78  return (ea);
79  } else {
80  if (errmsg != NULL)
81  *errmsg = "eanom: eccentric anomaly iteration "
82  "failed to converge";
83  return FP_ERRVAL;
84  }
85 }
#define MAXIT
Definition: eanom.c:49
double eanom(double manom, double ecc, char **errmsg)
Definition: eanom.c:53
#define NULL
Definition: decode_rs.h:63
#define FP_ERRVAL
Definition: orbit.h:48
subroutine func(x, conec, n, bconecno, bn, units, u, inno, i, outno, o, Input, Targ, p, sqerr)
Definition: ffnet.f:287
const double delta
#define EPS
Definition: eanom.c:50
#define fabs(a)
Definition: misc.h:93
int i
Definition: decode_rs.h:71