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
tiltcomp.f
Go to the documentation of this file.
1  subroutine tiltcomp( nlines, tlm, timref, time, gaclac, navqc,
2  1 tiltpr, tiltfl )
3 
4 c $Header$
5 c $Log$
6 c
7 c tiltcomp( nlines, tlm, gaclac, navqc, tiltpr, tiltfl )
8 c
9 c Purpose: process tilt angle data to a line-by-line array
10 c
11 c Calling Arguments:
12 c
13 c Name Type I/O Description
14 c -------- ---- --- -----------
15 c nlines I*4 I number of scan lines covered
16 c tlm struct I telemetry structure containing tilt info
17 c timref R*8 I size 3 reference time at start line
18 c of data: year, day, sec
19 c time R*8 I array of time in seconds relative to
20 c timref for every scan line
21 c gaclac I*4 I flag for GAC or LAC data. If LAC
22 c data, a time exists for each scan
23 c line, else only once every 5 lines
24 c navqc struct I navigation quality control info
25 c tiltpr R*4 O size nlines processed tilt data
26 c for each line and for two tilt measurements
27 c tiltfl I*4 O flags for goodness of tilts 0 - good,
28 c 1 - bad
29 c
30 c By: W. Robinson, GSC, 13 Apr 93
31 c
32 c Notes:
33 c
34 c Modification History:
35 c
36 c Fixed error in last call to runfit3t. F. S. Patt, January 12, 1995.
37 c
38 c Fixed error in indexing of smoothed tilt angles. F.S. Patt, Oct. 31, 1997
39 c
40 c Fixed bug in initializing counter for end-of-scene processing. F. S. Patt,
41 c SAIC GSC, May 21, 1998.
42 c
43 c Added a consistency check on the tilt angles during tilt changes; include
44 c a final limit check on tilt angles to catch processing problems.
45 c F. S. Patt, SAIC GSC, August 4, 1998.
46 
47 
48  implicit none
49 #include "tlm_str.fin"
50 #include "navqc_s.fin"
51  type(tlm_struct) :: tlm
52  type(navqc_struct) :: navqc
53 c
54  integer*4 gaclac, nlines, tiltfl(nlines)
55 c
56  integer*4 nper, ilin, j, k, i1, in(4), ntilt, n1, n2, tfl(100)
57  integer*4 nskip, iret, nfit, jp, sgn
58  real*8 timref(3),time(nlines)
59  real*4 tiltpr(nlines)
60  real*4 tout(100),tlcl(100),tdif(100),tdlim(2),tldif,tlim(2)
61  logical gottwo
62  data nfit/9/,nskip/2/,tdif/100*0.0/,tdlim/-1.,10./,tlim/-20.,20./
63 c
64 c
65 c initialize output arrays for processed tilt
66 c
67  nper = 1
68  if( gaclac .eq. 1 ) nper = 5
69 c
70  do ilin = 1, nlines
71  tiltpr(ilin) = 0
72  tiltfl(ilin) = 1
73  end do
74 c
75 c First transfer the tilt info
76 c
77  do ilin = 1, tlm%ntlm
78 
79  do j = 1, nper
80 
81 c
82  tiltfl((ilin - 1) * nper + j ) = tlm%tilt(1)%flag(j,ilin)
83 c tiltfl(2,(ilin - 1) * nper + j ) = tlm%tilt(2)%flag(j,ilin)
84 c
85  tiltpr((ilin - 1) * nper + j ) = tlm%tilt(1)%ang(j,ilin)
86 c tiltpr(2,(ilin - 1) * nper + j ) = tlm%tilt(2)%ang(j,ilin)
87  end do
88  end do
89 
90 c Add consistency check at some future date
91 c call tiltcnst(
92 
93 c Now fill in missing values
94 
95 c do itilt=1,2
96  ilin = 1
97  i1 = 1
98 
99 c Initialize by finding first 4 static tilt times
100  do k=1,4
101  call fndflg(tiltfl(1),nlines,i1,in(k))
102 c If end of range encountered, process data and exit
103  if (in(k).eq.-1) then
104 
105 c If 0 or 1 static values, attempt smoothing
106  if (k.lt.3) then
107  print *,'Insufficient static tilt data samples'
108  print *,' Smoothing attempted'
109  do j=1,nlines
110  if (tiltfl(j).eq.2) tiltfl(j) = 0
111  end do
112  ntilt = nlines
113  call runfit3t(nfit,nskip,tlcl,tiltpr(1),ntilt,1,tiltfl(1),
114  * 1,time(1),tdif,tout,tfl,iret)
115  do j=1,nlines
116  tiltpr(j) = tout(j)
117  tiltfl(j) = 2 - tfl(j)
118  end do
119  go to 990
120 
121 c Else if 2 static values, process data
122  else if (k.eq.3) then
123  in(3) = in(2)
124  end if
125  end if
126  i1 = in(k) + 1
127  end do
128 
129 c Now handle cases of non-static tilt at start of interval
130 c Change tilt change data flags to be used in smoothing
131  n2 = 0
132  n1 = 0
133  do j=1,in(3)-1
134  if (tiltfl(j).eq.2) then
135  tiltfl(j) = 0
136  n2 = n2 + 1
137  if (j.lt.in(1)) n1 = n1 + 1
138  end if
139  end do
140 
141 c Try to perform smoothing
142  ntilt = in(3)
143  call runfit3t(nfit,nskip,tlcl,tiltpr(1),ntilt,1,tiltfl(1),
144  * 1,time(1),tdif,tout,tfl,iret)
145 
146 c Fill in values before first pointer if necessary
147  if (in(1).gt.1) then
148  if ((n1.gt.0).and.(iret.eq.0)) then
149  do j=1,in(1)-1
150  tiltpr(j) = tout(j)
151  tiltfl(j) = 2 - tfl(j)
152  end do
153  else
154  do j=1,in(1)-1
155  tiltpr(j) = tiltpr(in(1))
156  tiltfl(j) = tiltfl(in(1))
157  end do
158  end if
159  end if
160 
161 c Fill in values between first and second pointers
162  if (in(2).gt.(in(1)+1)) then
163  if (tiltpr(in(2)).eq.tiltpr(in(1))) then
164  do j=in(1)+1,in(2)-1
165  tiltpr(j) = tiltpr(in(1))
166  tiltfl(j) = tiltfl(in(1))
167  end do
168  else
169  do j=in(1)+1,in(2)-1
170  tiltpr(j) = tout(j)
171  tiltfl(j) = 2 - tfl(j)
172  end do
173  end if
174  end if
175 
176 
177 c Now fill remaining array locations with good values
178  dowhile(in(4).ne.-1)
179 
180 c Check for tilt change between second and third pointers
181  if (tiltpr(in(3)).eq.tiltpr(in(2))) then
182  if (in(3).gt.(in(2)+1)) then
183  do j=in(2)+1,in(3)-1
184  tiltpr(j) = tiltpr(in(2))
185  tiltfl(j) = tiltfl(in(2))
186  end do
187  end if
188 
189 c Else smooth and load tilt change data
190  else
191 
192 c Perform consistency check on tilt angles
193  gottwo = .false.
194  jp = in(2)
195  sgn = sign(1.0,(tiltpr(in(3)) - tiltpr(in(2))))
196  do j=in(2)+1,in(3)-1
197  if (tiltfl(j).eq.2) then
198  if (time(j).ne.time(jp)) then
199  tldif = sgn*(tiltpr(j) - tiltpr(jp)) /
200  * (time(j)-time(jp))
201  if ((tldif.lt.tdlim(1)).or.(tldif.gt.tdlim(2))) then
202  if (.not.gottwo) tiltfl(jp) = 1
203  gottwo = .false.
204  else
205  tiltfl(j) = 0
206  gottwo = .true.
207  end if
208  jp = j
209  else
210  tiltfl(j) = 1
211  end if
212  end if
213  end do
214  if (.not.gottwo) tiltfl(jp) = 1
215  ntilt = in(3) - in(2) + 1
216  call runfit3t(nfit,nskip,tlcl,tiltpr(in(2)),ntilt,1,
217  1 tiltfl(in(2)),1,time(in(2)),tdif,tout,tfl,iret)
218  do j=in(2)+1,in(3)-1
219  tiltpr(j) = tout(j-in(2)+1)
220  tiltfl(j) = 2 - tfl(j-in(2)+1)
221  end do
222  end if
223 
224 c Find next static value and shift pointers
225  do j=1,3
226  in(j) = in(j+1)
227  end do
228  i1 = in(3) + 1
229  call fndflg(tiltfl(1),nlines,i1,in(4))
230 
231 c End of main processing loop
232  end do
233 
234 c Now process data at end of interval
235 c Change tilt change data flags to be used in smoothing
236  n1 = 0
237  n2 = 0
238  do j=in(2),nlines
239  if (tiltfl(j).eq.2) then
240  tiltfl(j) = 0
241  n2 = n2 + 1
242  if (j.gt.in(3)) n1 = n1 + 1
243  end if
244  end do
245 
246 c Try to perform smoothing
247  ntilt = nlines - in(1) + 1
248  call runfit3t(nfit,nskip,tlcl,tiltpr(in(1)),ntilt,1,
249  1 tiltfl(in(1)),1,time(in(1)),tdif,tout,tfl,iret)
250 
251 c Fill in values between second and third pointers
252  if (in(3).gt.(in(2)+1)) then
253  if (tiltpr(in(3)).eq.tiltpr(in(2))) then
254  do j=in(2)+1,in(3)-1
255  tiltpr(j) = tiltpr(in(2))
256  tiltfl(j) = tiltfl(in(2))
257  end do
258  else
259  do j=in(2)+1,in(3)-1
260  tiltpr(j) = tout(j-in(1)+1)
261  tiltfl(j) = 2 - tfl(j-in(1)+1)
262  end do
263  end if
264  end if
265 
266 c Fill in values after third pointer if necessary
267  if (in(3).lt.nlines) then
268  if ((n1.gt.0).and.(iret.eq.0)) then
269  do j=in(3)+1,nlines
270  tiltpr(j) = tout(j-in(1)+1)
271  tiltfl(j) = 2 - tfl(j-in(1)+1)
272  end do
273  else
274  do j=in(3)+1,nlines
275  tiltpr(j) = tiltpr(in(3))
276  tiltfl(j) = tiltfl(in(3))
277  end do
278  end if
279  end if
280 
281 c
282 c and end
283 c
284  990 continue
285 
286  do j=1,nlines
287 c Perform final check to limit tilt angles to +/- 20 degrees
288  if (tiltpr(j).gt.tlim(2)) then
289  tiltpr(j) = tlim(2)
290  tiltfl(j) = 1
291  else if (tiltpr(j).lt.tlim(1)) then
292  tiltpr(j) = tlim(1)
293  tiltfl(j) = 1
294  end if
295 
296 c print *,tiltpr(j),tiltfl(j)
297  end do
298 
299  return
300  end
#define sign(x)
Definition: misc.h:95
#define real
Definition: DbAlgOcean.cpp:26
subroutine fndflg(flag, nflag, istndx, next)
Definition: fndflg.f:2
void print(std::ostream &stream, const char *format)
Definition: PrintDebug.hpp:38
subroutine tiltcomp(nlines, tlm, timref, time, gaclac, navqc, tiltpr, tiltfl)
Definition: tiltcomp.f:3
subroutine runfit3t(nfpts, nskip, measlcl, meas, nmeas, nquant, flag, nper, time, timdif, measout, flgout, iret)
Definition: runfit3t.f:3