Due to the lapse in federal government funding, NASA is not updating this website. We sincerely regret this inconvenience.
NASA Logo
Ocean Color Science Software

ocssw V2022
fitgps.f
Go to the documentation of this file.
1  subroutine fitgps(ngps,gps,nsig,vecs,driv,s0,updorb)
2 c
3 c Purpose: This routine uses the GPS, the interpolated ASAP vectors and
4 c the partial derivatives to compute updates to the orbital
5 c elements. It uses a weighted batch least-squares algorithm
6 c to minimize the orbit position differences and also performs
7 c data rejection based on an initial fit to the data.
8 c
9 c Calling Arguments:
10 c
11 c Name Type I/O Description
12 c -------- ---- --- -----------
13 c ngps I*4 I Number of data samples
14 c gps(6,ngps) R*8 I GPS orbit vectors
15 c nsig(ngps) R*8 I Number of GPS signals per sample
16 c vecs(6,ngps) R*8 I ASAP orbit vectors
17 c driv(6,3,ngps) R*8 I Partial derivatives of orbit position with
18 c respect to initial orbital elements
19 c s0(6) R*8 I State weights to use in least-squares
20 c updorb(6) R*8 O Updates to orbital elements
21 c
22 c By: Frederick S. Patt, GSC, December 23, 1993
23 c
24 c Notes:
25 c
26 c Modification History:
27 c
28  implicit none
29 #include "nav_cnst.fin"
30 
31  real*8 gps(6,maxlin), vecs(6,maxlin), driv(6,3,maxlin), updorb(6)
32  real*8 pd(3,maxlin), pe(3,maxlin), up(6), w(6,6), v(6), s0(6)
33  real*8 xtol, xmed, xiqr
34  integer*4 nsig(maxlin), ngps, nobs, n, min, i, j, k, l, ier
35 
36  nobs = 3*ngps
37 
38 c Compute position differences
39  do i=1,ngps
40  do j=1,3
41  pd(j,i) = gps(j,i) - vecs(j,i)
42 
43 c Scale derivatives for eccentricity and argument of perigee to
44 c avoid numerical roundoff errors in matrix inversion
45  driv(2,j,i) = driv(2,j,i)/1.d2
46  driv(5,j,i) = driv(5,j,i)*1.d2
47  end do
48  end do
49 
50 c Set tolerance for points with large differences
51  call mediqr(pd,nobs,xmed,xiqr)
52  xtol = 2.d0*xiqr
53  min = 5
54 
55 c Zero out state matrix and vector
56  do k=1,6
57  v(k) = 0.d0
58  do l=1,6
59  w(k,l) = 0.d0
60  end do
61  end do
62 
63 c Perform initial estimate of correction
64 
65 c Generate state equations
66  n = 0
67  do i=1,ngps
68  if((nsig(i).ge.min).and.
69  * (abs(pd(1,i)-xmed).lt.xtol).and.
70  * (abs(pd(2,i)-xmed).lt.xtol).and.
71  * (abs(pd(3,i)-xmed).lt.xtol)) then
72  n = n + 1
73  do j=1,3
74  do k=1,6
75  v(k) = v(k) + pd(j,i)*driv(k,j,i)
76  do l=1,6
77  w(k,l) = w(k,l) + driv(k,j,i)*driv(l,j,i)
78  end do
79  end do
80  end do
81  end if
82  end do
83  print *,'FITGPS:',n,xmed,xiqr
84 
85 c Add state weights
86  do k=1,6
87  w(k,k) = w(k,k) + s0(k)
88  end do
89 
90 c Solve for state update
91  call invert(w,v,6,6,up,ier)
92  print *,up
93 
94 c Recompute fitting residuals
95  do i=1,ngps
96  do j=1,3
97  pe(j,i)=pd(j,i)
98  do k=1,6
99  pe(j,i) = pe(j,i) - up(k)*driv(k,j,i)
100  end do
101  end do
102  end do
103 
104 c Compute updated tolerance
105  call mediqr(pe,nobs,xmed,xiqr)
106  xtol = 2.d0*xiqr
107  min = 4
108 
109 c Zero out state matrix and vector
110  do k=1,6
111  v(k) = 0.d0
112  do l=1,6
113  w(k,l) = 0.d0
114  end do
115  end do
116 
117 c Perform final estimate of correction
118 
119 c Generate state equations
120  n = 0
121  do i=1,ngps
122  if((nsig(i).ge.min).and.
123  * (abs(pe(1,i)-xmed).lt.xtol).and.
124  * (abs(pe(2,i)-xmed).lt.xtol).and.
125  * (abs(pe(3,i)-xmed).lt.xtol)) then
126  n = n + 1
127  do j=1,3
128  do k=1,6
129  v(k) = v(k) + pd(j,i)*driv(k,j,i)
130  do l=1,6
131  w(k,l) = w(k,l) + driv(k,j,i)*driv(l,j,i)
132  end do
133  end do
134  end do
135  end if
136  end do
137  print *,'FITGPS:',n,xmed,xiqr
138 
139 c Add state weights
140  do k=1,6
141  w(k,k) = w(k,k) + s0(k)
142  end do
143 
144 c Solve for state update
145  call invert(w,v,6,6,up,ier)
146  print *,up
147 
148 c Scale corrections for eccentricity and argument of perigee
149  up(2) = up(2)/1.d2
150  up(5) = up(5)*1.d2
151 
152 c Load corrections into output array
153 
154  do k=1,6
155  updorb(k) = up(k)
156  end do
157 
158  return
159  end
subroutine mediqr(dat, ndat, xmed, xiqr)
Definition: mediqr.f:2
#define real
Definition: DbAlgOcean.cpp:26
subroutine invert(a, b, n, l, c, ier)
Definition: invert.f:3
subroutine fitgps(ngps, gps, nsig, vecs, driv, s0, updorb)
Definition: fitgps.f:2
void print(std::ostream &stream, const char *format)
Definition: PrintDebug.hpp:38
#define abs(a)
Definition: misc.h:90