-
Notifications
You must be signed in to change notification settings - Fork 1
/
gridsearch.f90
540 lines (533 loc) · 20.9 KB
/
gridsearch.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
INTERFACE
SUBROUTINE LOCATE3D_GRIDSEARCH_DOUBLE64(ldgrd, ngrd, nobs, iwantOT, mask, &
tobs, varobs, test, logPDF, ierr) &
BIND(C, NAME='locate3d_gridsearch__double64')
USE ISO_C_BINDING
IMPLICIT NONE
INTEGER(C_INT), INTENT(IN) :: iwantOT, ldgrd, ngrd, nobs
REAL(C_DOUBLE), INTENT(IN) :: tobs(nobs), varobs(nobs), test(ngrd*nobs)
INTEGER(C_INT), INTENT(IN) :: mask(nobs)
REAL(C_DOUBLE), INTENT(OUT) :: logPDF(ngrd)
INTEGER(C_INT), INTENT(OUT) :: ierr
!DIR$ ATTRIBUTES ALIGN: 64 :: logPDF, test, tobs, varobs
END SUBROUTINE LOCATE3D_GRIDSEARCH_DOUBLE64
SUBROUTINE LOCATE3D_GRIDSEARCH_FLOAT64(ldgrd, ngrd, nobs, iwantOT, mask, &
tobs, varobs, test, logPDF, ierr) &
BIND(C, NAME='locate3d_gridsearch__float64')
USE ISO_C_BINDING
IMPLICIT NONE
INTEGER(C_INT), INTENT(IN) :: iwantOT, ldgrd, ngrd, nobs
REAL(C_FLOAT), INTENT(IN) :: tobs(nobs), varobs(nobs), test(ngrd*nobs)
INTEGER(C_INT), INTENT(IN) :: mask(nobs)
REAL(C_FLOAT), INTENT(OUT) :: logPDF(ngrd)
INTEGER(C_INT), INTENT(OUT) :: ierr
!DIR$ ATTRIBUTES ALIGN: 64 :: logPDF test, tobs, varobs
END SUBROUTINE LOCATE3D_GRIDSEARCH_FLOAT64
END INTERFACE
double precision, allocatable :: logPDF(:), test(:), tobs(:), varobs(:)
real, allocatable :: logPDF4(:), test4(:), tobs4(:), varobs4(:)
integer, allocatable :: mask(:)
integer nobs, ngrd
integer, parameter :: iwantOT = 1
!DIR$ ATTRIBUTES ALIGN: 64 :: logPDF, test, tobs, varobs
!DIR$ ATTRIBUTES ALIGN: 64 :: logPDF4, test4, tobs4, varobs4
double precision dx, dy, dz, xsrc, ysrc, zsrc
double precision, allocatable :: xrec(:), yrec(:), zrec(:)
dx = 1.d3
dy = 1.d3
dz = 1.d3
nobs = 20
nx = 79
ny = 71
nz = 15
ixsrc = 31
iysrc = 55
izsrc = 4
xsrc = (ixsrc-1)*dx
ysrc = (iysrc-1)*dy
zsrc = (izsrc-1)*dz
print *, nx*ny*nz, (izsrc-1)*nx*ny + (iysrc-1)*nx + ixsrc, ixsrc, iysrc, izsrc
print *, 'true optimum', (izsrc-1)*nx*ny + (iysrc-1)*nx + ixsrc
nobs = 14
allocate(xrec(nobs))
allocate(yrec(nobs))
allocate(zrec(nobs))
allocate(mask(nobs))
mask(:) = 0
call random_number(xrec)
call random_number(yrec)
call random_number(zrec)
ngrd = nx*ny*nz
ldgrd = ngrd + 64 - MOD(ngrd,64)
print *, ldgrd, ngrd, mod(ngrd,64)
allocate(logPDF(ngrd))
allocate(test(nobs*ldgrd))
allocate(tobs(nobs))
allocate(varobs(nobs))
test(:) = 0.d0
tobs(:) = 0.d0
do i=1,nobs
xrec(i) = xrec(i)*dble(nx-1)*dx
yrec(i) = yrec(i)*dble(ny-1)*dy
zrec(i) = zrec(i)*dble(nz-1)*dz
i1 = (i - 1)*ldgrd + 1
i2 = i*ldgrd
call makeTest(nx, ny, nz, ngrd, dx, dy, dz, xrec(i), yrec(i), zrec(i), test(i1:i2))
call makeObs(xrec(i), yrec(i), zrec(i), xsrc, ysrc, zsrc, tobs(i))
enddo
tobs(:) = tobs(:) + 4.d0
varobs(:) = 1.d0
print *, 'here'
!do i=1,nobs
CALL LOCATE3D_GRIDSEARCH_DOUBLE64(ldgrd, ngrd, nobs, iwantOT, mask, &
tobs, varobs, test, logPDF, ierr)
print *, 'optimum', minloc(logPDF), 'worst', maxloc(logPDF)
!enddo
DEALLOCATE(logPDF)
! DEALLOCATE(test)
! DEALLOCATE(tobs)
! DEALLOCATE(varobs)
allocate(logPDF4(ngrd))
allocate(test4(nobs*ldgrd))
allocate(tobs4(nobs))
allocate(varobs4(nobs))
test4(:) = sngl(test(:))
tobs4(:) = sngl(tobs(:))
varobs4(:) = sngl(varobs(:))
print *, varobs4
deallocate(test)
deallocate(tobs)
deallocate(varobs)
print *, 'here2'
!do i=1,nobs
CALL LOCATE3D_GRIDSEARCH_FLOAT64(ldgrd, ngrd, nobs, iwantOT, mask, &
tobs4, varobs4, test4, logPDF4, ierr )
!enddo
print *, 'done'
DEALLOCATE(logPDF4)
DEALLOCATE(test4)
DEALLOCATE(tobs4)
DEALLOCATE(varobs4)
stop
end
SUBROUTINE makeTest(nx, ny, nz, ngrd, dx, dy, dz, xsrc, ysrc, zsrc, test)
IMPLICIT NONE
INTEGER, INTENT(IN) :: ngrd, nx, ny, nz
DOUBLE PRECISION, INTENT(IN) :: dx, dy, dz, xsrc, ysrc, zsrc
DOUBLE PRECISION, INTENT(OUT) :: test(ngrd)
DOUBLE PRECISION d2, x, y, z
INTEGER igrd, i, j, k
DOUBLE PRECISION, PARAMETER :: slow = 1.d0/5.d3
DO 1 k=1,nz
DO 2 j=1,ny
DO 3 i=1,nx
igrd = (k-1)*nx*ny + (j-1)*nx + i
x = DBLE(i - 1)*dx
y = DBLE(j - 1)*dy
z = DBLE(k - 1)*dz
d2 = (x - xsrc)**2 + (y - ysrc)**2 + (z - zsrc)**2
test(igrd) = SQRT(d2)*slow
3 CONTINUE
2 CONTINUE
1 CONTINUE
RETURN
END
SUBROUTINE makeObs(x, y, z, xsrc, ysrc, zsrc, tobs)
IMPLICIT NONE
DOUBLE PRECISION, INTENT(IN) :: x, y, z, xsrc, ysrc, zsrc
DOUBLE PRECISION, INTENT(OUT) :: tobs
DOUBLE PRECISION d2
DOUBLE PRECISION, PARAMETER :: slow = 1.d0/5.d3
d2 = (x - xsrc)**2 + (y - ysrc)**2 + (z - zsrc)**2
tobs = SQRT(d2)*slow
RETURN
END
! !
!========================================================================================!
! !
!> @brief Stacks the weighted residuals into the analytic origin time
!> computation. This is for analytic removal of the sourc time
!> in an L2 optimization as described by Moser et. al. 1992 Eqn 19
!> for diagonal weights.
!>
!> @param[in] ngrd number of points in grid search
!> @param[in] tobs_i observed pick time (seconds)
!> @param[in] xnorm normalization factor which is the inverse of the
!> sum of the data variances for all observations.
!> @param[in] var_i variance in the pick time (seconds)
!> @param[in] test estimate arrival times at all points in grid
!>
!> @param[in,out] t0 on input contains the current weighted residual
!> sum for previous observations
!> on output contains the updated weighted residual
!> sum which incorporates the current observation.
!>
!> @author Ben Baker
!>
!> @copyright Apache 2
!>
SUBROUTINE LOCATE3D_STACK_T0_DOUBLE64(ngrd, tobs_i, xnorm, var_i, test, t0)
IMPLICIT NONE
INTEGER, INTENT(IN) :: ngrd
DOUBLE PRECISION, INTENT(IN) :: test(ngrd), xnorm, tobs_i, var_i
DOUBLE PRECISION, INTENT(INOUT) :: t0(ngrd)
DOUBLE PRECISION tobs, wt
INTEGER igrd
DOUBLE PRECISION, PARAMETER :: one = 1.d0
!DIR$ ATTRIBUTES ALIGN: 64 :: igrd, tobs, wt
wt = one/(var_i*xnorm)
tobs = tobs_i
!$OMP PARALLEL DO SIMD FIRSTPRIVATE(tobs, wt), &
!$OMP SHARED(ngrd, t0, test), DEFAULT(none)
DO 1 igrd=1,ngrd
t0(igrd) = t0(igrd) + wt*(tobs - test(igrd))
1 CONTINUE
!$OMP END PARALLEL DO SIMD
RETURN
END
! !
!========================================================================================!
! !
!> @brief Stacks the weighted residuals into the analytic origin time
!> computation. This is for analytic removal of the sourc time
!> in an L2 optimization as described by Moser et. al. 1992 Eqn 19
!> for diagonal weights.
!>
!> @param[in] ngrd number of points in grid search
!> @param[in] tobs_i observed pick time (seconds)
!> @param[in] xnorm normalization factor which is the inverse of the
!> sum of the data variances for all observations.
!> @param[in] var_i variance in the pick time (seconds)
!> @param[in] test estimate arrival times at all points in grid
!>
!> @param[in,out] t0 on input contains the current weighted residual
!> sum for previous observations
!> on output contains the updated weighted residual
!> sum which incorporates the current observation.
!>
!> @author Ben Baker
!>
!> @copyright Apache 2
!>
SUBROUTINE LOCATE3D_STACK_T0_FLOAT64(ngrd, tobs_i, xnorm, var_i, test, t0)
IMPLICIT NONE
INTEGER, INTENT(IN) :: ngrd
REAL, INTENT(IN) :: test(ngrd), xnorm, tobs_i, var_i
REAL, INTENT(INOUT) :: t0(ngrd)
REAL tobs, wt
INTEGER igrd
REAL, PARAMETER :: one = 1.0
!DIR$ ATTRIBUTES ALIGN: 64 :: igrd, tobs, wt
wt = one/(var_i*xnorm)
tobs = tobs_i
!$OMP PARALLEL DO SIMD FIRSTPRIVATE(tobs, wt), &
!$OMP SHARED(ngrd, t0, test), DEFAULT(none)
DO 1 igrd=1,ngrd
t0(igrd) = t0(igrd) + wt*(tobs - test(igrd))
1 CONTINUE
!$OMP END PARALLEL DO SIMD
RETURN
END
! !
!========================================================================================!
! !
!> @brief Stacks the squared residuals into the L2 penalty function. This
!> is for diagonal weighting.
!>
!> @param[in] ngrd number of points in grid search
!> @param[in] tobs_i i'th pick time (seconds)
!> @param[in] var_i variance (seconds) in i'th observation
!> @param[in] test theoretical traveltime to each point in grid
!> (seconds) [ngrd]
!> @param[in] t0 analytic origin time (seconds) at all points
!> in grid [ngrd]
!>
!> @param[in,out] on input contains the weighted squared residuals
!> at all points in the grid.
!> on output contains the contribution of the current
!> squared residual to all points in the grid. [ngrd]
!>
!> @author Ben Baker
!>
!> @copyright Apache 2
!>
SUBROUTINE LOCATE3D_STACK_LOGPDF_DOUBLE64(ngrd, tobs_i, var_i, test, &
t0, logPDF)
IMPLICIT NONE
INTEGER, INTENT(IN) :: ngrd
DOUBLE PRECISION, INTENT(IN) :: t0(ngrd), test(ngrd), tobs_i, var_i
DOUBLE PRECISION, INTENT(INOUT) :: logPDF(ngrd)
DOUBLE PRECISION res, tobs, wt
INTEGER igrd
DOUBLE PRECISION, PARAMETER :: one = 1.d0
DOUBLE PRECISION, PARAMETER :: two = 2.d0
DOUBLE PRECISION, PARAMETER :: sqrt2i = one/SQRT(two)
!DIR$ ATTRIBUTES ALIGN: 64 :: igrd, res, tobs, wt
wt = sqrt2i/var_i ! accounts for 1/2 half scaling in L2 norm
tobs = tobs_i
!$OMP PARALLEL DO SIMD FIRSTPRIVATE(tobs, wt), PRIVATE(res), &
!$OMP SHARED(logPDF, ngrd, t0, test), DEFAULT(none)
DO 1 igrd=1,ngrd
res = wt*(tobs - (test(igrd) + t0(igrd)))
logPDF(igrd) = logPDF(igrd) + res*res
1 CONTINUE
!$OMP END PARALLEL DO SIMD
RETURN
END
! !
!========================================================================================!
! !
!> @brief Stacks the squared residuals into the L2 penalty function. This
!> is for diagonal weighting.
!>
!> @param[in] ngrd number of points in grid search
!> @param[in] tobs_i i'th pick time (seconds)
!> @param[in] var_i variance (seconds) in i'th observation
!> @param[in] test theoretical traveltime to each point in grid
!> (seconds) [ngrd]
!> @param[in] t0 analytic origin time (seconds) at all points
!> in grid [ngrd]
!>
!> @param[in,out] on input contains the weighted squared residuals
!> at all points in the grid.
!> on output contains the contribution of the current
!> squared residual to all points in the grid. [ngrd]
!>
!> @author Ben Baker
!>
!> @copyright Apache 2
!>
SUBROUTINE LOCATE3D_STACK_LOGPDF_FLOAT64(ngrd, tobs_i, var_i, test, &
t0, logPDF)
IMPLICIT NONE
INTEGER, INTENT(IN) :: ngrd
REAL, INTENT(IN) :: t0(ngrd), test(ngrd), tobs_i, var_i
REAL, INTENT(OUT) :: logPDF(ngrd)
REAL res, tobs, wt
INTEGER igrd
REAL, PARAMETER :: one = 1.0
REAL, PARAMETER :: two = 2.0
REAL, PARAMETER :: sqrt2i = one/SQRT(two)
!DIR$ ATTRIBUTES ALIGN: 64 :: igrd, res, tobs, wt
wt = sqrt2i/var_i ! accounts for 1/2 half scaling in L2 norm
tobs = tobs_i
!$OMP PARALLEL DO SIMD FIRSTPRIVATE(tobs, wt), PRIVATE(res) &
!$OMP SHARED(logPDF, ngrd, t0, test), DEFAULT(none)
DO 1 igrd=1,ngrd
res = wt*(tobs - (test(igrd) + t0(igrd)))
logPDF(igrd) = logPDF(igrd) + res*res
1 CONTINUE
!$OMP END PARALLEL DO SIMD
RETURN
END
! !
!========================================================================================!
! !
!> @brief Zeros out a 64 bit aligned array x
!>
!> @param[in] n number of points in array x
!>
!> @param[out] x nulled out array [n]
!>
SUBROUTINE LOCATE3D_NULL_DOUBLE64(n, x)
IMPLICIT NONE
INTEGER, INTENT(IN) :: n
DOUBLE PRECISION, INTENT(OUT) :: x(n)
INTEGER i
DOUBLE PRECISION, PARAMETER :: zero = 0.d0
!DIR$ ATTRIBUTES ALIGN: 64 :: i, zero
!$OMP PARALLEL DO SIMD SHARED(n, x), DEFAULT(none)
DO 1 i=1,n
x(i) = zero
1 CONTINUE
!$OMP END PARALLEL DO SIMD
RETURN
END
! !
!========================================================================================!
! !
!> @brief Zeros out a 64 bit aligned array x
!>
!> @param[in] n number of points in array x
!>
!> @param[out] x nulled out array [n]
!>
SUBROUTINE LOCATE3D_NULL_FLOAT64(n, x)
IMPLICIT NONE
INTEGER, INTENT(IN) :: n
REAL, INTENT(OUT) :: x(n)
INTEGER i
REAL, PARAMETER :: zero = 0.0
!DIR$ ATTRIBUTES ALIGN: 64 :: i, zero
!$OMP PARALLEL DO SIMD SHARED(n, x), DEFAULT(none)
DO 1 i=1,n
x(i) = zero
1 CONTINUE
!$OMP END PARALLEL DO SIMD
RETURN
END
! !
!========================================================================================!
! !
!> @brief Performs the grid search over all estimates for aligned data
!>
!>
SUBROUTINE LOCATE3D_GRIDSEARCH_DOUBLE64(ldgrd, ngrd, nobs, iwantOT, mask, &
tobs, varobs, test, logPDF, ierr) &
BIND(C, NAME='locate3d_gridsearch__double64')
USE ISO_C_BINDING
IMPLICIT NONE
INTEGER(C_INT), INTENT(IN) :: iwantOT, ldgrd, ngrd, nobs
REAL(C_DOUBLE), INTENT(IN) :: tobs(nobs), varobs(nobs), test(ngrd*nobs)
INTEGER(C_INT), INTENT(IN) :: mask(nobs)
REAL(C_DOUBLE), INTENT(OUT) :: logPDF(ngrd)
INTEGER(C_INT), INTENT(OUT) :: ierr
!DIR$ ATTRIBUTES ALIGN: 64 :: logPDF, test, tobs, varobs
! local variables
DOUBLE PRECISION, ALLOCATABLE :: t0(:)
DOUBLE PRECISION tobs_i, xnorm, var_i
INTEGER ibeg, igrd, iobs, iopt
DOUBLE PRECISION, PARAMETER :: zero = 0.d0
DOUBLE PRECISION, PARAMETER :: one = 1.d0
!DIR$ ATTRIBUTES ALIGN: 64 :: t0, xnorm, zero
!----------------------------------------------------------------------------------!
!
! check input variables
ierr = 0
IF (MOD(ldgrd, 64) /= 0) THEN
WRITE(*,*) 'locate3d_gridsearch_double64: Require arrays be 64 byte aligned', &
ldgrd, MOD(8*ldgrd, 64)
ierr = 1
RETURN
ENDIF
IF (ngrd > ldgrd) THEN
WRITE(*,*) 'locate3d_gridsearch_double64: ngrd cannot be greater than ldgrd'
ierr = 1
RETURN
ENDIF
IF (SUM(mask) == nobs) THEN
WRITE(*,*) 'locate3d_gridsearch_double64: No observations'
ierr = 1
RETURN
ENDIF
IF (ABS(SUM(varobs) - zero) < EPSILON(one)) THEN
WRITE(*,*) 'locate3d_gridsearch_double64: Will be division by zero'
ierr = 1
RETURN
ENDIF
! initialize and set space
ALLOCATE(t0(ngrd))
CALL LOCATE3D_NULL_DOUBLE64(ngrd, t0)
CALL LOCATE3D_NULL_DOUBLE64(ngrd, logPDF)
! compute the origin time in this grid
IF (iwantOT == 1) THEN
xnorm = zero
DO 3 iobs=1,nobs
IF (mask(iobs) /= 1) xnorm = xnorm + varobs(iobs)
3 CONTINUE
DO 4 iobs=1,nobs
IF (mask(iobs) == 1) CYCLE
tobs_i = tobs(iobs)
var_i = varobs(iobs)
ibeg = ldgrd*(iobs - 1) + 1
CALL LOCATE3D_STACK_T0_DOUBLE64(ngrd, tobs_i, xnorm, var_i, test(ibeg), t0)
4 CONTINUE
ENDIF
! now compute the locations with the origin times at each grid point
DO 11 iobs=1,nobs
IF (mask(iobs) == 1) CYCLE
tobs_i = tobs(iobs)
var_i = varobs(iobs)
ibeg = ldgrd*(iobs - 1) + 1
CALL LOCATE3D_STACK_LOGPDF_DOUBLE64(ngrd, tobs_i, var_i, test(ibeg), &
t0, logPDF)
11 CONTINUE
! get the origin time
IF (iwantOT == 1) THEN
iopt = MINLOC(logPDF, 1)
print *, iopt, t0(iopt)
ENDIF
DEALLOCATE(t0)
RETURN
END
! !
!========================================================================================!
! !
SUBROUTINE LOCATE3D_GRIDSEARCH_FLOAT64(ldgrd, ngrd, nobs, iwantOT, mask, &
tobs, varobs, test, logPDF, ierr) &
BIND(C, NAME='locate3d_gridsearch__float64')
USE ISO_C_BINDING
IMPLICIT NONE
INTEGER(C_INT), INTENT(IN) :: iwantOT, ldgrd, ngrd, nobs
REAL(C_FLOAT), INTENT(IN) :: tobs(nobs), varobs(nobs), test(ngrd*nobs)
INTEGER(C_INT), INTENT(IN) :: mask(nobs)
REAL(C_FLOAT), INTENT(OUT) :: logPDF(ngrd)
INTEGER(C_INT), INTENT(OUT) :: ierr
!DIR$ ATTRIBUTES ALIGN: 64 :: logPDF, test, tobs, varobs
! local variables
REAL, ALLOCATABLE :: t0(:)
REAL tobs_i, xnorm, var_i
INTEGER ibeg, igrd, iobs, iopt
REAL, PARAMETER :: zero = 0.0
REAL, PARAMETER :: one = 1.0
!DIR$ ATTRIBUTES ALIGN: 64 :: t0, xnorm, zero
!----------------------------------------------------------------------------------!
!
! check input variables
ierr = 0
IF (MOD(ldgrd, 64) /= 0) THEN
WRITE(*,*) 'locate3d_gridsearch_float64: Require arrays be 64 byte aligned', &
ldgrd, MOD(ldgrd, 64)
ierr = 1
RETURN
ENDIF
IF (ngrd > ldgrd) THEN
WRITE(*,*) 'locate3d_gridsearch_float64: ngrd cannot be greater than ldgrd'
ierr = 1
RETURN
ENDIF
IF (SUM(mask) == nobs) THEN
WRITE(*,*) 'locate3d_gridsearch_float64: No observations'
ierr = 1
RETURN
ENDIF
IF (ABS(SUM(varobs) - zero) < EPSILON(one)) THEN
WRITE(*,*) 'locate3d_gridsearch_float64: Will be division by zero'
ierr = 1
RETURN
ENDIF
! initialize and set space
ALLOCATE(t0(ngrd))
CALL LOCATE3D_NULL_FLOAT64(ngrd, t0)
CALL LOCATE3D_NULL_FLOAT64(ngrd, logPDF)
! compute the origin time in this grid
IF (iwantOT == 1) THEN
xnorm = zero
DO 3 iobs=1,nobs
IF (mask(iobs) /= 1) xnorm = xnorm + varobs(iobs)
3 CONTINUE
DO 4 iobs=1,nobs
IF (mask(iobs) == 1) CYCLE
tobs_i = tobs(iobs)
var_i = varobs(iobs)
ibeg = ldgrd*(iobs - 1) + 1
CALL LOCATE3D_STACK_T0_FLOAT64(ngrd, tobs_i, xnorm, var_i, test(ibeg), t0)
4 CONTINUE
ENDIF
! now compute the locations with the origin times at each grid point
DO 11 iobs=1,nobs
IF (mask(iobs) == 1) CYCLE
tobs_i = tobs(iobs)
var_i = varobs(iobs)
ibeg = ldgrd*(iobs - 1) + 1
CALL LOCATE3D_STACK_LOGPDF_FLOAT64(ngrd, tobs_i, var_i, test(ibeg), &
t0, logPDF)
11 CONTINUE
! get the origin time
IF (iwantOT == 1) THEN
iopt = MINLOC(logPDF, 1)
print *, iopt, t0(iopt)
ENDIF
DEALLOCATE(t0)
RETURN
END