OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
fitrng.f
Go to the documentation of this file.
1  subroutine fitrng(meas, nmeas, nquant, flag, nper,
2  1 measout, flgout )
3 c
4 c fitrng(meas, nmeas, nquant, flag, nper, measout, flgout )
5 c
6 c Purpose: fit data to a finer sampling over a range
7 c
8 c Calling Arguments:
9 c
10 c Name Type I/O Description
11 c -------- ---- --- -----------
12 c meas R*4 I size nquant by nmeas array of measured
13 c quantitys
14 c nmeas I*4 I number of measurements in array
15 c nquant I*4 I number of quantities in the array
16 c flag I*4 I flag array for meas: 0- good, 1- bad
17 c nper I*4 I expansion factor from meas to measout
18 c measout R*4 O size nquant by nmeas * nper array of
19 c fitted measurements
20 c flgout I*4 O flag array for measout: 0- good, 1- bad
21 c
22 c By: W. Robinson, GSC, 25 Mar 93
23 c
24 c Notes:
25 c
26 c Modification History:
27 c
28 c Eliminated redundant call to fndflg. F.S. Patt, GSC, August 16, 1996.
29 c
30 
31  implicit none
32 c
33  integer*4 nmeas, nquant, nper
34  real*4 meas(nquant,nmeas), measout(nquant,nmeas*nper)
35  integer*4 flag(nmeas), flgout(nmeas*nper)
36 c
37  real*4 del(20)
38  integer*4 imeas, iquant, i1, i2
39  logical end
40 c
41 c
42 c Use interpolation for now
43 c
44 c fill the output flag array with bad values
45 c
46  do imeas = 1,nmeas * nper
47  flgout(imeas) = 1
48  end do
49 c
50 c move the array values from the meas array to
51 c the output array
52 c
53  do imeas = 1,nmeas
54  flgout( ( imeas - 1 ) * nper + 1 ) = flag( imeas )
55  do iquant = 1, nquant
56  measout( iquant, ( imeas - 1 ) * nper + 1 ) =
57  1 meas( iquant, imeas )
58  end do
59  end do
60 c
61 c extrapolate any lines required at the start of the segment
62 c
63 c use first 2 good measurements to extrapolate or interpolate below
64 c
65  call fndflg(flag, nmeas, 1, i1 )
66  call fndflg(flag, nmeas, ( i1 + 1 ), i2 )
67 c
68  if( flag(1) .eq. 1) then
69 c
70  do iquant = 1, nquant
71  del(iquant) = ( meas(iquant,i2) - meas(iquant,i1) ) /
72  1 ((i2 - i1) * nper)
73  end do
74 c
75  do imeas = 1, (i1 - 1) * nper
76  flgout( imeas ) = 0
77  do iquant = 1, nquant
78  measout(iquant, imeas ) =
79  1 meas(iquant,i1) - del(iquant) *
80  1 ( (i1 - 1) * nper + 1 - imeas )
81  end do
82  end do
83  end if
84 c
85 c interpolate through the available measurements, start
86 c with first 2 found above
87 c
88  end = .FALSE.
89  do while( .not. end )
90  call fndflg(flag, nmeas, (i1 + 1), i2 )
91  if( i2 .le. 0 ) then
92  end = .TRUE.
93  else
94  do iquant = 1, nquant
95  del(iquant) = ( meas(iquant,i2) - meas(iquant,i1) ) /
96  1 ((i2 - i1) * nper)
97  end do
98 c
99  if( ( i2 * nper - i1 * nper ) .gt. 1 ) then
100 c
101 c there are spaces to fill in output array
102 c
103  do imeas = (i1 - 1) * nper + 2, (i2 - 1) * nper
104  flgout(imeas) = 0
105  do iquant = 1, nquant
106  measout(iquant,imeas) =
107  1 meas(iquant,i1) + del(iquant) *
108  1 ( imeas - ( i1 - 1 ) * nper - 1 )
109  end do
110  end do
111  end if
112 c
113 c find next pair to interpolate
114  i1 = i2
115 c call fndflg(flag, nmeas, ( i1 + 1 ), i2 )
116 c if( i2 .le. 0 ) end = .TRUE.
117  end if
118  end do
119 c
120 c extrapolate times to the end of the segment
121 c
122  if( ( flag(nmeas) .eq. 1 ) .or. ( nper .ne. 1 ) ) then
123  do imeas = (i1 - 1 ) * nper + 2, nmeas * nper
124  flgout(imeas) = 0
125  do iquant = 1, nquant
126  measout(iquant,imeas) = meas(iquant,i1) + del(iquant) *
127  1 ( imeas - ( i1 - 1 ) * nper - 1 )
128  end do
129  end do
130  end if
131 c
132 c and end
133 c
134  990 continue
135  return
136  end
#define real
Definition: DbAlgOcean.cpp:26
subroutine fndflg(flag, nflag, istndx, next)
Definition: fndflg.f:2
subroutine fitrng(meas, nmeas, nquant, flag, nper, measout, flgout)
Definition: fitrng.f:3