OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
dataintp.f
Go to the documentation of this file.
1  SUBROUTINE dataintp(LL,LAT,LON,F1,DT1,F2,DT2,IPT,NBAND,RNG,DEF
2  . ,INTORDER,DUMMY,FOUT, func, int_bad,IR,JC)
3 C**********************************************************************
4 C Data interpolation (spatial and temporal) subroutine.
5 C Spatial interpolation is weighted by distance and temporal interpolation
6 C is a simple linear approximation.
7 C [Only valid surrounding data will be used. If no valid surrounding value
8 C found, the user specified values will be assigned as output values.]
9 C------------------------------------------------------------
10 C Input parameters:
11 C -----------------
12 C LL R*4(2) Actual pixel location, latitude (-90.0 to 90.0) and
13 C longitude (-180. to 180.)
14 C LAT R*4(x) Surrounding latitudes (x=IPT=number of data points
15 C surrounding LL), -90.0 to 90.0.
16 C LON R*4(x) Surrounding longitudes (x=IPT=number of data points
17 C surrounding LL), -180.0 to 180.0.
18 C F1 R*4() Time step 1 surrounding data values. For the case of
19 C each data point has only one value (such as P,SST,...),
20 C the callig program declares F1 as a one dimensional array
21 C , F1(IPT).
22 C For multiple values data (e.g. ozone optical thicknesses),
23 C F1 will be declared as a two dimensional array,
24 C F1(IPT,NBAND).
25 C DT1 R*4 Time difference bt. actual time and time step 1. (DT1>=0.)
26 C [Note: actual time is a time bt. time steps 1 & 2].
27 C F2 R*4() Same as F1 except for time step 2.
28 C DT2 R*4 Time difference bt. actual time and time step 2. (DT2>=0.)
29 C IPT I*4 Number of data points surrounding position LL at any
30 C single time step. (1<=IPT<=25)
31 C NBAND I*4 Band number of each data point. If each data point has
32 C only one corresponding value, set NBAND=1. (1<=NBAND<=15)
33 C RNG R*4(2) Data thresholds. Any surrounding data outside the range
34 C (i.e. data less than or data greater than specified
35 C range) will be excluded for data interpolation.
36 C DEF R*4() User specified default value(s) which will only be used
37 C if no data is valid for interpolation. If NBAND=1 the
38 C calling program declares DEF as a scalar. Otherwise,
39 C DEF has the size of NBAND, DEF(NBAND).
40 C INTORDER I*4 Interpolation order. Valid sequences are:
41 C 112: space then time;
42 C 121: time then space;
43 C 110: spatial interpolation only;
44 C 101: temporal interpolation only.
45 C [Note: If all data are good, results from 112 and 121
46 C are identical]
47 C DUMMY R*4() A dummy array which has the size as that of F1.
48 C IR,JC I*4 Sizes, Row and column, of output parameter FOUT.
49 C 1)If you expect the output as a single value, set
50 C IR=1, JC=1 and FOUT as a scalar;
51 C 2)Output data contain NBAND values, set
52 C IR=1, JC=NBAND and FOUT(NBAND);
53 C 3)Output data contain IPT values (e.g. INTORDER=101), set
54 C IR=IPT, JC=1 and FOUT(IPT);
55 C 4)Results contain IPT & NBAND values (e.g. INTORDER=101),
56 C IR=IPT, JC=NBAND and FOUT(IPT,NBAND).
57 C Output parameters:
58 C -----------------
59 C FOUT R*4() Interpolated results for actual location and/or time from
60 C surrounding points. (Reference: parameters IR,JC)
61 C func R*4() Uncertainty estimate - for 112 intorder, the difference
62 C between the 2 time values
63 C int_bad I*4 flag to indicate that the space interpolation used
64 C the default or one or both of the inputs to the time
65 C interpolation was a default - cause for ATMWARN
66 C 0 if good, 1 if bad
67 C------------------------------------------------------------
68 C
69 C Created by Eueng-nan Yeh, 11/17/92, GSC
70 C W. Robinson, SAIC 6 Dec 2013 add the int_bad argument
71 C W. Robinson, SAIC 4 Aug 2016 add an uncertainty estimate and pass back
72 C
73 C**********************************************************************
74 C%%
75 
76  INTEGER*4 MBAND
77  parameter(mband=15)
78  INTEGER*4 NBAND,IPT,INTORDER,IR,JC, int_bad, int_bad1, int_bad2
79  real*4 ll(1),lat(1),lon(1),f1(ipt,1),f2(ipt,1),rng(*),def(1)
80  . ,fout(1),fout1(mband),fout2(mband),dummy(ipt,1)
81  . ,mimx(2)
82  real*4 func(1)
83  real*8 dt1,dt2
84 
85  int_bad = 0
86  IF(rng(2).GT.rng(1))THEN
87  mimx(2)=rng(2) ! maximum
88  mimx(1)=rng(1) ! minimum
89  ELSE
90  mimx(1)=rng(2)
91  mimx(2)=rng(1)
92  END IF
93 
94  IF(intorder .EQ. 112)THEN ! 112
95  CALL spaceint(ll,lat,lon,f1,ipt,nband,mimx,def,fout1, int_bad1 )
96  CALL spaceint(ll,lat,lon,f2,ipt,nband,mimx,def,fout2, int_bad2 )
97  CALL timeint(fout1,fout2,dt1,dt2,1,nband,mimx,def,fout,func,ir,jc)
98  IF( ( int_bad1 .EQ. 1 ) .OR. ( int_bad2 .EQ. 1 ) ) int_bad = 1
99  ELSE
100  ntot = nband * ir
101  DO 10 i = 1, ntot
102  func(i) = 0.
103  10 CONTINUE
104  IF(intorder.EQ.110)THEN ! 110
105  CALL spaceint(ll,lat,lon,f1,ipt,nband,mimx,def,fout, int_bad )
106  ELSE
107  if(intorder.EQ.101)then ! 101
108  CALL timeint(f1,f2,dt1,dt2,ipt,nband,mimx,def,fout,func,ir,jc)
109  else
110  IF(intorder.EQ.121)THEN ! 121
111  CALL timeint(f1,f2,dt1,dt2,ipt,nband,mimx,def,dummy,func
112  . ,ipt,nband)
113  CALL spaceint(ll,lat,lon,dummy,ipt,nband,mimx,def,fout, int_bad )
114  END IF
115  end if
116  END IF
117  END IF
118  RETURN
119  END
120 
121  SUBROUTINE timeint(F1,F2,DT1,DT2,IPT,NBAND,MIMX,DEF,FOUT,func
122  . ,IR,JC)
123 
124  INTEGER*4 NBAND,IPT,IR,JC,N,I,K,IJ
125  REAL*4 F1(IPT,1),F2(IPT,1),MIMX(*)
126  . ,def(1),fout(1),func(1)
127  real*8 dt1,dt2,t1,t2,w1,w2
128 C: FOUT(1)=FOUT(# data point, # of band)
129  t1=abs(dt1)
130  t2=abs(dt2)
131  IF(t1.EQ.0. .AND. t2.EQ.0.) t2=1
132 C: Interpolating data between T1 and T2
133  w1=t2/(t1+t2)
134  w2=t1/(t1+t2)
135  IF (w1.GE.1.) w2=0.
136  IF (w2.GE.1.) w1=0.
137  DO 200 n=1,nband
138  ij=(n-1)*ir
139  DO 201 i=1,ipt
140  k=ij+i
141  IF(f1(i,n).GE.mimx(1).AND.f1(i,n).LE.mimx(2))THEN ! F1 is OK
142  if(f2(i,n).GE.mimx(1).AND.f2(i,n).LE.mimx(2))then ! F1 OK & F2 OK
143  fout(k)=w1*f1(i,n)+w2*f2(i,n)
144  func(k)=abs(f1(i,n)-f2(i,n))
145  else
146  fout(k)=f1(i,n) ! F1 OK & F2 NG
147  func(k)=0
148  end if
149  ELSE ! F1 is NG
150  if(f2(i,n).GE.mimx(1).AND.f2(i,n).LE.mimx(2))then
151  fout(k)=f2(i,n) ! F1 NG & F2 OK
152  func(k)=0
153  else
154  fout(k)=def(n) ! F1 NG & F2 NG
155  func(k)=0
156  end if
157  END IF
158 201 CONTINUE
159 200 CONTINUE
160 
161 9000 CONTINUE
162  RETURN
163  END
164 c
165 c
166 c
167  SUBROUTINE spaceint(LL,LAT,LON,F,IPT,NBAND,MIMX,DEF,FOUT, int_bad )
168 C Rectangular bi-linear interpolation (IPT==4).
169 C by Eueng-nan Yeh GSC/SAIC 11/17/95
170 c
171  INTEGER*4 NBAND,IPT,I,N,NNG, int_bad
172  INTEGER*4 NCC,NC(4),N1(3,4),N2(5,6),N3(2,4)
173  real*4 ll(*),lat(*),lon(*),f(ipt,1),mimx(*),def(1)
174  $ ,fout(1),llft(2),urht(2),dx,dy,dd,xp,yp,a(4),g(4)
175  DATA nc/1,10,100,1000/
176  DATA n1/1,2,4,10,1,3,100,2,4,1000,1,3/
177  DATA n2/11,1,2,4,3,101,1,3,4,2,1001,1,4,2,3,110,2,3,1,4
178  $ ,1010,2,4,3,1,1100,3,4,2,1/
179  DATA n3/111,4,1110,1,1101,2,1011,3/
180  llft(1)=lat(1)
181  llft(2)=lon(1)
182  urht(1)=lat(3)
183  urht(2)=lon(3)
184 C: Rectangular bi-linear interpolation.
185  xp=ll(2)-llft(2)
186  IF(abs(xp) .gt. 180.) xp=sign(360-abs(xp), xp)
187  yp=ll(1)-llft(1)
188  dx=urht(2)-llft(2)
189  IF(abs(dx) .gt. 180.) dx=sign(360-abs(dx), dx)
190  dy=urht(1)-llft(1)
191  dd=dx*dy
192  DO 110 n=1,nband
193  ncc=0
194  nng=0
195  int_bad = 0
196  DO 115 i=1,ipt !IPT==4
197  g(i)=f(i,n) !assign F to local variable G
198  IF(g(i).LT.mimx(1) .OR. g(i).GT.mimx(2))THEN !F is ng
199  ncc=ncc+nc(i)
200  nng=nng+1
201  ENDIF
202 115 CONTINUE
203  IF(nng .eq. 0)GOTO 9000
204 
205  IF(nng .eq. 2)THEN !Two bad points
206  DO i=1,6 ! WDR replace IPT with 6 to correct
207  IF(ncc .eq. n2(1,i))THEN
208  g(n2(2,i))=g(n2(4,i))
209  g(n2(3,i))=g(n2(5,i))
210  GOTO 9000
211  ENDIF
212  ENDDO
213  ELSE
214  IF(nng .eq.1)THEN !One bad point
215  DO i=1,ipt
216  IF(ncc .eq. n1(1,i))THEN
217  g(i)=(g(n1(2,i))+g(n1(3,i)))/2.
218  GOTO 9000
219  ENDIF
220  ENDDO
221  ENDIF
222  ENDIF
223  IF(nng .eq. 4)THEN !Four bad points
224  fout(n)=def(n)
225  int_bad = 1
226  GOTO 110
227  ELSE
228  IF(nng .eq. 3) THEN !Three bad points
229  DO i=1,ipt
230  IF(ncc .eq. n3(1,i))THEN
231  fout(n)=g(n3(2,i))
232  GOTO 110
233  ENDIF
234  ENDDO
235  ENDIF
236  ENDIF
237 9000 CONTINUE
238  a(1)=g(1)
239  IF (abs(dx) .le. 1.e-9) THEN
240  a(2) = 0
241  ELSE
242  a(2)=(g(4)-a(1))/dx
243  ENDIF
244  IF (abs(dy) .le. 1.e-9) THEN
245  a(3) = 0
246  ELSE
247  a(3)=(g(2)-a(1))/dy
248  ENDIF
249  IF (abs(dd) .le. 1.e-9) THEN
250  a(4) = 0
251  ELSE
252  a(4)=(a(1)-g(2)+g(3)-g(4))/dd
253  ENDIF
254  fout(n)=a(1)+a(2)*xp+yp*(a(3)+a(4)*xp)
255 110 CONTINUE
256  RETURN
257  END
float f1(float x)
subroutine timeint(F1, F2, DT1, DT2, IPT, NBAND, MIMX, DEF, FOUT, func, IR, JC)
Definition: dataintp.f:123
#define sign(x)
Definition: misc.h:95
#define real
Definition: DbAlgOcean.cpp:26
float f2(float y)
README for MOD_PR03(V6.1.0) 2. POINTS OF CONTACT it can be either SDP Toolkit or MODIS Packet for Terra input files The orbit validation configuration parameter(LUN 600281) must be either "TRUE" or "FALSE". It needs to be "FALSE" when running in Near Real Time mode
subroutine func(x, conec, n, bconecno, bn, units, u, inno, i, outno, o, Input, Targ, p, sqerr)
Definition: ffnet.f:287
subroutine dataintp(LL, LAT, LON, F1, DT1, F2, DT2, IPT, NBAND, RNG, DEF, INTORDER, DUMMY, FOUT, func, int_bad, IR, JC)
Definition: dataintp.f:3
#define f
Definition: l1_czcs_hdf.c:702
#define abs(a)
Definition: misc.h:90
subroutine spaceint(LL, LAT, LON, F, IPT, NBAND, MIMX, DEF, FOUT, int_bad
Definition: dataintp.f:168