-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptraj.F
627 lines (621 loc) · 21.3 KB
/
ptraj.F
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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
#ifdef trajectories
subroutine ptraji
c
c=======================================================================
c initialize particle positions
c
c author: r. c. pacanowski e-mail=> rcp@gfdl.gov
c=======================================================================
c
#include "param.h"
#include "coord.h"
#include "ptraj.h"
#include "iounit.h"
#include "switch.h"
#include "tmngr.h"
c
c-----------------------------------------------------------------------
c distribute particles within volume defined using starting and
c ending longitudes, latitudes, and depths given by
c ptslon, ptelon, ptslat, ptelat. ptsdpt, and ptedpt.
c for example: if nptraj = 500 particles then
c
c pacific distribution: drop 100 particles between 180E and 190E
c 5S to 5N, and down to 200 meters.
c
c ptslon = 180.0
c ptelon = 190.0
c ptslat = -5.0
c ptelat = 5.0
c ptsdpt = 5.1e2
c ptedpt = 200.e2
c call pdist (1, 100)
c
c deep central atlantic distribution: drop 400 particles between
c 330E and 340E, 5S to 5N and between 200 and 3000 meters depth.
c
c ptslon = 330.0
c ptelon = 340.0
c ptslat = -5.0
c ptelat = 5.0
c ptsdpt = 200.1e2
c ptedpt = 3000.e2
c call pdist (201, nptraj)
c-----------------------------------------------------------------------
c
# ifdef timing
call tic ('diagnostic', 'particle trajectories')
# endif
c
c distribute all particles within volume defined by the following:
c
ptslon = 180.0
ptelon = 190.0
ptslat = -5.0
ptelat = 5.0
ptsdpt = 5.1e2
ptedpt = 200.e2
call pdist (1, nptraj)
# ifdef lyapunov
c
c-----------------------------------------------------------------------
c initialize deformation rate matrix
c-----------------------------------------------------------------------
c
do n=1,nptraj
em(1,1,n) = c1
em(1,2,n) = c0
em(2,1,n) = c0
em(2,2,n) = c1
enddo
# endif
c
c-----------------------------------------------------------------------
c write initial particle positions to file
c-----------------------------------------------------------------------
c
reltim = relyr
c
call getunit (io, 'particles.dta','u s a ieee')
c
iotext = 'read (iotraj) reltim'
write (io) stamp, iotext, expnam
write (io) reltim
c
# ifdef lyapunov
iotext ='read (iotraj) nptraj, pxyz, pijk, em'
write (io) stamp, iotext, expnam
write (io) nptraj, pxyz, pijk, em
write (stdout,*)
&' => Initial particle positions (lyapunov) written'
&, ' unformatted to file particles.dta on ts = ',itt,' ', stamp
# else
iotext ='read (iotraj) nptraj, pxyz, pijk'
write (io) stamp, iotext, expnam
write (io) nptraj, pxyz, pijk
write (stdout,*) ' => Initial particle positions written'
&, ' unformatted to file particles.dta on ts = ',itt,' ', stamp
# endif
call relunit (io)
c
# ifdef timing
call toc ('diagnostic', 'particle trajectories')
# endif
c
return
end
subroutine pdist (ns, ne)
c
c=======================================================================
c distribute n particles (ne-ns+1) within volume given by
c ptslon, ptelon, ptslat, ptelat, ptsdpt, ptedpt by uniformly
c placing approximately n**(1/3) particles along each dimension
c
c author: r. c. pacanowski e-mail=> rcp@gfdl.gov
c=======================================================================
c
# include "param.h"
# include "coord.h"
# include "ptraj.h"
c
if (ns .gt. nptraj .or. ne .gt. nptraj) then
print *, ' => Error: ns=',ns,', ne=',ne
stop "=>pdist"
endif
c
c-----------------------------------------------------------------------
c constrain the volume (containing starting positions of
c particles) to lie within the model domain.
c-----------------------------------------------------------------------
c
if (ptslon .lt. xu(2)) ptslon = xu(2)
if (ptslon .gt. xu(imtm1)) ptslon = xu(imtm1)
if (ptslat .lt. yu(1)) ptslat = yu(1)
if (ptslat .gt. yu(jmtm1)) ptslat = yu(jmtm1)
if (ptsdpt .lt. zt(1)) ptsdpt = zt(1)
if (ptsdpt .gt. zt(km)) ptsdpt = zt(km)
c
if (ptelon .lt. xu(2)) ptelon = xu(2)
if (ptelon .gt. xu(imtm1)) ptelon = xu(imtm1)
if (ptelat .lt. yu(1)) ptelat = yu(1)
if (ptelat .gt. yu(jmtm1)) ptelat = yu(jmtm1)
if (ptedpt .lt. zt(1)) ptedpt = zt(1)
if (ptedpt .gt. zt(km)) ptedpt = zt(km)
c
if (ptslon .gt. ptelon) then
t = ptslon
ptslon = ptelon
ptelon = t
endif
if (ptslat .gt. ptelat) then
t = ptslat
ptslat = ptelat
ptelat = t
endif
if (ptsdpt .gt. ptedpt) then
t = ptsdpt
ptsdpt = ptedpt
ptedpt = t
endif
c
c-----------------------------------------------------------------------
c distribute the particles throughout the volume
c-----------------------------------------------------------------------
c
cubr = (float(ne-ns+1))**0.333333
distx = (ptelon - ptslon)/cubr
disty = (ptelat - ptslat)/cubr
distz = (ptedpt - ptsdpt)/cubr
pxyz(1,ns) = p5*distx + ptslon
pxyz(2,ns) = p5*disty + ptslat
pxyz(3,ns) = p5*distz + ptsdpt
do n=ns,ne
if (n .gt. ns) then
pxyz(1,n) = pxyz(1,n-1)
pxyz(2,n) = pxyz(2,n-1)
pxyz(3,n) = pxyz(3,n-1)
endif
pxyz(1,n) = pxyz(1,n) + distx
if (pxyz(1,n) .gt. ptelon) then
pxyz(1,n) = ptslon + (pxyz(1,n)-ptelon)
pxyz(2,n) = pxyz(2,n) + disty
if (pxyz(2,n) .gt. ptelat) then
pxyz(2,n) = ptslat + (pxyz(2,n)-ptelat)
pxyz(3,n) = pxyz(3,n) + distz
endif
endif
c
i = indp (pxyz(1,n), xu, imt)
if (xu(i) .gt. pxyz(1,n)) then
pijk(1,n) = i
else
pijk(1,n) = i+1
endif
c
jrow = indp (pxyz(2,n), yu, jmt)
if (yu(jrow) .gt. pxyz(2,n)) then
pijk(2,n) = jrow
else
pijk(2,n) = jrow+1
endif
c
k = indp (pxyz(3,n), zt, km)
if (zt(k) .gt. pxyz(3,n)) then
pijk(3,n) = k
else
pijk(3,n) = k+1
endif
enddo
write (stdout,9000)
npart = ne-ns+1
write (stdout,*) npart,' particles were initialized'
&, ' to lie within the volume described by:'
write (stdout,'(1x,f8.2," < lon <",f8.2)') ptslon, ptelon
write (stdout,'(1x,f8.2," < lat <",f8.2)') ptslat, ptelat
write (stdout,'(1x,e10.3," < dpt < ",e10.3)') ptsdpt, ptedpt
write (stdout,*) ' '
return
9000 format (/20x,'P A R T I C L E I N I T I A L I Z A T I O N'/)
end
subroutine ptraj (j, jrow)
c
c=======================================================================
c integrate particle trajectories
c
c note:
c
c all indicies refer to the "xu","yv" and "zt" grids.
c
c it may be useful to interpolate other quantities (eg: potential
c temperature ...) to the particle positions and save them as well.
c this can help in understanding where and when such quantities
c are conserved.
c
c author: r. c. pacanowski e-mail=> rcp@gfdl.gov
c=======================================================================
c
# include "param.h"
# include "coord.h"
# include "ptraj.h"
# include "grdvar.h"
# include "iounit.h"
# include "mw.h"
# include "scalar.h"
# include "switch.h"
# include "tmngr.h"
c
# ifdef timing
call tic ('diagnostic', 'particle trajectories')
# endif
c
c-----------------------------------------------------------------------
c initialize so that every particle needs to be considered
c-----------------------------------------------------------------------
c
if (jrow .eq. 2) then
do n=1,nptraj
ptdone(n) = .false.
enddo
endif
c
c-----------------------------------------------------------------------
c calculate trajectory for all particles between jrow and jrow-1
c-----------------------------------------------------------------------
c
rrad = c1/radian
cmdeg = 8.982799e-8
c
do n=1,nptraj
if (.not. ptdone(n) .and. pijk(2,n) .eq. jrow) then
ptdone(n) = .true.
c
c-----------------------------------------------------------------------
c the particle is bounded by the volume with verticies given by
c the eight nearest surrounding model grid points on the "xu",
c "yu", and "zt" grids. (i,j,k) is the index of the deepest
c northeast corner of this bounding volume.
c-----------------------------------------------------------------------
c
i = pijk(1,n)
c j in the MW corresponds to jrow = pijk(2,n)
k = pijk(3,n)
c
c-----------------------------------------------------------------------
c compute volume weights for linear interpolation of velocity
c at verticies of bounding volume to the particle position.
c
c distances between particle and bounding volume faces
c
c xe = distance to the east face
c xw = distance to the west face
c yn = distance to the north face
c ys = distance to the south face
c za = distance above to the top face
c zb = distance below to the bottom face
c-----------------------------------------------------------------------
c
xe = (xu(i) - pxyz(1,n))
xw = (pxyz(1,n) - xu(i-1))
yn = (yu(jrow) - pxyz(2,n))
ys = (pxyz(2,n) - yu(jrow-1))
za = (pxyz(3,n) - zt(k-1))
zb = (zt(k) - pxyz(3,n))
dv = c1/((xt(i)-xt(i-1))*(yt(jrow)-yt(jrow-1))*(zt(k)-zt(k-1)))
c
c-----------------------------------------------------------------------
c construct velocity at position of particle by 3-d linear
c interpolation.
c-----------------------------------------------------------------------
c
xeyszb = xe*ys*zb*dv
xwyszb = xw*ys*zb*dv
xeysza = xe*ys*za*dv
xwysza = xw*ys*za*dv
xeynzb = xe*yn*zb*dv
xwynzb = xw*yn*zb*dv
xeynza = xe*yn*za*dv
xwynza = xw*yn*za*dv
c
uu = u(i-1,k-1,j,1,tau)*xeyszb + u(i,k-1,j,1,tau)*xwyszb
& +u(i-1,k ,j,1,tau)*xeysza + u(i,k ,j,1,tau)*xwysza
& +u(i-1,k-1,j-1,1,tau)*xeynzb + u(i,k-1,j-1,1,tau)*xwynzb
& +u(i-1,k ,j-1,1,tau)*xeynza + u(i,k ,j-1,1,tau)*xwynza
c
vv = u(i-1,k-1,j,2,tau)*xeyszb + u(i,k-1,j,2,tau)*xwyszb
& +u(i-1,k ,j,2,tau)*xeysza + u(i,k ,j,2,tau)*xwysza
& +u(i-1,k-1,j-1,2,tau)*xeynzb + u(i,k-1,j-1,2,tau)*xwynzb
& +u(i-1,k ,j-1,2,tau)*xeynza + u(i,k ,j-1,2,tau)*xwynza
c
c interpolate vertical velocities at the bases of
c the "u" cells.
c
if (pxyz(3,n) .gt. zw(k-1)) then
za = pxyz(3,n) - zw(k-1)
zb = zw(k) - pxyz(3,n)
dv = c1/((xt(i)-xt(i-1))*(yt(jrow)-yt(jrow-1))
& *(zw(k)-zw(k-1)))
xeyszb = xe*ys*zb*dv
xwyszb = xw*ys*zb*dv
xeysza = xe*ys*za*dv
xwysza = xw*ys*za*dv
xeynzb = xe*yn*zb*dv
xwynzb = xw*yn*zb*dv
xeynza = xe*yn*za*dv
xwynza = xw*yn*za*dv
ww = adv_vbu(i-1,k-1,j)*xeyszb + adv_vbu(i,k-1,j)*xwyszb
& +adv_vbu(i-1,k ,j)*xeysza + adv_vbu(i,k ,j)*xwysza
& +adv_vbu(i-1,k-1,j-1)*xeynzb + adv_vbu(i,k-1,j-1)*xwynzb
& +adv_vbu(i-1,k ,j-1)*xeynza + adv_vbu(i,k ,j-1)*xwynza
else
if (k-2 .eq. 0) then
za = pxyz(3,n)
else
za = pxyz(3,n) - zw(k-2)
endif
zb = zw(k-1) - pxyz(3,n)
dv = c1/((xt(i)-xt(i-1))*(yt(jrow)-yt(jrow-1))
& *(zw(k)-zw(k-1)))
xeyszb = xe*ys*zb*dv
xwyszb = xw*ys*zb*dv
xeysza = xe*ys*za*dv
xwysza = xw*ys*za*dv
xeynzb = xe*yn*zb*dv
xwynzb = xw*yn*zb*dv
xeynza = xe*yn*za*dv
xwynza = xw*yn*za*dv
ww = adv_vbu(i-1,k-2,j)*xeyszb + adv_vbu(i,k-2,j)*xwyszb
& +adv_vbu(i-1,k-1,j)*xeysza + adv_vbu(i,k-1,j)*xwysza
& +adv_vbu(i-1,k-2,j-1)*xeynzb + adv_vbu(i,k-2,j-1)*xwynzb
& +adv_vbu(i-1,k-1,j-1)*xeynza + adv_vbu(i,k-1,j-1)*xwynza
endif
# ifdef lyapunov
c
c-----------------------------------------------------------------------
c construct the shear and compression above and below the particle
c-----------------------------------------------------------------------
c
c for du/dx and du/dy
c
c
uxn = (u(i,k-1,j,1,tau) - u(i-1,k-1,j,1,tau))*dxtr(i)*csu(jrow)
uxs = (u(i,k-1,j-1,1,tau) - u(i-1,k-1,j-1,1,tau))*dxtr(i)
& *csu(jrow-1)
uxn2 = (u(i,k,j,1,tau) - u(i-1,k,j,1,tau))*dxtr(i)*csu(jrow)
uxs2 = (u(i,k,j-1,1,tau) - u(i-1,k,j-1,1,tau))*dxtr(i)*csu(jrow-1)
c
uye = (u(i,k-1,j,1,tau) - u(i,k-1,j-1,1,tau))*dytr(jrow)
uyw = (u(i-1,k-1,j,1,tau) - u(i-1,k-1,j-1,1,tau))*dytr(jrow)
uye2 = (u(i,k,j,1,tau) - u(i,k,j-1,1,tau))*dytr(jrow)
uyw2 = (u(i-1,k,j,1,tau) - u(i-1,k,j-1,1,tau))*dytr(jrow)
c
c for dv/dx and dv/dy
c
vxn = (u(i,k-1,j,2,tau) - u(i-1,k-1,j,2,tau))*dxtr(i)*csu(jrow)
vxs = (u(i,k-1,j-1,2,tau) - u(i-1,k-1,j-1,2,tau))*dxtr(i)
& *csu(jrow-1)
vxn2 = (u(i,k,j,2,tau) - u(i-1,k,j,2,tau))*dxtr(i)*csu(jrow)
vxs2 = (u(i,k,j-1,2,tau) - u(i-1,k,j-1,2,tau))*dxtr(i)*csu(jrow-1)
c
vye = (u(i,k-1,j,2,tau) - u(i,k-1,j-1,2,tau))*dytr(jrow)
vyw = (u(i-1,k-1,j,2,tau) - u(i-1,k-1,j-1,2,tau))*dytr(jrow)
vye2 = (u(i,k,j,2,tau) - u(i,k,j-1,2,tau))*dytr(jrow)
vyw2 = (u(i-1,k,j,2,tau) - u(i-1,k,j-1,2,tau))*dytr(jrow)
c
c interpolate du/dx, du/dy, dv/dx, and dv/dy to particle position
c
dxr = c1/((xw+xe)*(zb+za))
dyr = c1/((ys+yn)*(zb+za))
c
yszb = ys*zb*dyr
ynzb = yn*zb*dyr
ysza = ys*za*dyr
ynza = yn*za*dyr
c
xwzb = xw*zb*dxr
xezb = xe*zb*dxr
xwza = xw*za*dxr
xeza = xe*za*dxr
c
dudx = uxn*yszb + uxs*ynzb + uxn2*ysza + uxs2*ynza
dudy = uye*xwzb + uyw*xezb + uye2*xwza + uyw2*xeza
c
dvdx = vxn*yszb + vxs*ynzb + vxn2*ysza + vxs2*ynza
dvdy = vye*xwzb + vyw*xezb + vye2*xwza + vyw2*xeza
c
c-----------------------------------------------------------------------
c integrate the deformation matrix. note that this is not quite
c correct when a particle encounters a boundary and "slips" along
c the boundary.
c
c the Lyapunov exponents can be computed from the eigenvalues of
c the deformation rate matrix "em". the exponents are given by:
c log(abs(eigen(1..2)))/T where T is the integration time.
c let c = (em(2,2)-em(1,1)**2 + 4*(em(1,2)*em(2,1))
c if (c >= 0.0) then
c abs(eigen(1..2)) = abs(((em(2,2)+em(1,1))**2 + or - sqrt(c))/2)
c else
c abs(eigen(1)) = abs(eigen(2)) =
c sqrt((em(2,2)+em(1,1))**2 + abs(c)))/2
c endif
c-----------------------------------------------------------------------
c
em11 = em(1,1,n) + (dudx*em(1,1,n) + dudy*em(2,1,n))*dtuv
em12 = em(1,2,n) + (dudx*em(1,2,n) + dudy*em(2,2,n))*dtuv
em21 = em(2,1,n) + (dvdx*em(1,1,n) + dvdy*em(2,1,n))*dtuv
em22 = em(2,2,n) + (dvdx*em(1,2,n) + dvdy*em(2,2,n))*dtuv
c
em(1,1,n) = em11
em(1,2,n) = em12
em(2,1,n) = em21
em(2,2,n) = em22
# endif
c
c-----------------------------------------------------------------------
c remember where the particle was
c-----------------------------------------------------------------------
c
xold = pxyz(1,n)
yold = pxyz(2,n)
zold = pxyz(3,n)
c
c-----------------------------------------------------------------------
c integrate the particle trajectory forward for one time step
c taking convergence of meridians into account.
c-----------------------------------------------------------------------
c
rcos = cmdeg/cos(pxyz(2,n)*rrad)
pxyz(1,n) = pxyz(1,n) + dtuv*uu*rcos
pxyz(2,n) = pxyz(2,n) + dtuv*vv*cmdeg
pxyz(3,n) = pxyz(3,n) - dtuv*ww
c
c-----------------------------------------------------------------------
c update bottom most northeast index of bounding volume
c-----------------------------------------------------------------------
c
if (pxyz(1,n) .ge. xu(i)) then
pijk(1,n) = i + 1
else if (pxyz(1,n) .lt. xu(i-1)) then
pijk(1,n) = i - 1
endif
c
if (pxyz(2,n) .ge. yu(jrow)) then
pijk(2,n) = jrow + 1
else if (pxyz(2,n) .lt. yu(jrow-1)) then
pijk(2,n) = jrow - 1
endif
c
if (pxyz(3,n) .ge. zt(k)) then
pijk(3,n) = k + 1
else if (pxyz(3,n) .lt. zt(k-1)) then
pijk(3,n) = k - 1
endif
c
c-----------------------------------------------------------------------
c do not allow any component of the trajectory to enter
c land. If it does, reset it to its previous value
c thereby simulating free slip conditions. hey... not perfect,
c but beats loosing particles in land. Also if the grid has
c isolated "T,S" cells (ones where all eight surrounding
c velocities are on land), replace references to "tmask(i,k,j)"
c by umask(i,k,j) + umask(i-1,k,j) + umask(i,k,j-1) +
c umask(i-1,k,j-1) to prevent stagnation of particles if this
c is a problem.
c-----------------------------------------------------------------------
c
c
# ifdef cyclic
if (pijk(1,n) .gt. imt) then
if (tmask(3,k,j) .ne. 0) then
pijk(1,n) = pijk(1,n) - (imt-2)
i = pijk(1,n)
pxyz(1,n) = xu(i-1) + (pxyz(1,n)-xu(imt))
else
pijk(1,n) = i
pxyz(1,n) = xold
endif
endif
if (pijk(1,n) .lt. 2) then
if (tmask(imt-2,k,j) .ne. 0) then
pijk(1,n) = pijk(1,n) + (imt-2)
i = pijk(1,n)
pxyz(1,n) = xu(i-1) + (pxyz(1,n)-xu(1))
else
pijk(1,n) = i
pxyz(1,n) = xold
endif
endif
# endif
c
c-----------------------------------------------------------------------
c constrain particles vertically to lie within ocean
c-----------------------------------------------------------------------
c
if (pijk(3,n) .ne. k) then
if (pijk(3,n) .eq. 1 .or. pijk(3,n) .gt. km) then
pxyz(3,n) = zold
pijk(3,n) = k
else if (pijk(3,n) .gt. k .and. tmask(i,k+1,j) .eq. c0) then
pxyz(3,n) = zold
pijk(3,n) = k
endif
endif
c
c-----------------------------------------------------------------------
c constrain particles longitudinally to stay within ocean
c-----------------------------------------------------------------------
c
if (pijk(1,n) .ne. i) then
if (pijk(1,n) .gt. i .and. tmask(i+1,k,j) .eq. c0) then
pxyz(1,n) = xold
pijk(1,n) = i
else if (pijk(1,n) .lt. i .and. tmask(i-1,k,j) .eq. c0) then
pxyz(1,n) = xold
pijk(1,n) = i
endif
endif
c
c-----------------------------------------------------------------------
c constrain particles latitudinally to stay within ocean
c-----------------------------------------------------------------------
c
if (pijk(2,n) .ne. jrow) then
if (pijk(2,n) .gt. jrow .and. tmask(i,k,j+1) .eq. c0) then
pxyz(2,n) = yold
pijk(2,n) = jrow
else if (pijk(2,n) .lt. jrow .and. tmask(i,k,j-1) .eq. c0)
& then
pxyz(2,n) = yold
pijk(2,n) = jrow
endif
endif
endif
enddo
c
c-----------------------------------------------------------------------
c write particle positions
c note: last positions are also written to "iorest" for restarting
c-----------------------------------------------------------------------
c
if ((jrow .eq. jmtm1) .and. trajts) then
c
reltim = relyr
c
write (stdout,9000) nptraj, stamp, pxyz(1,1), pxyz(2,1)
&, pxyz(3,1)*0.01
c
call getunit (io, 'particles.dta','u s a ieee')
c
iotext = 'read (iotraj) reltim'
write (io) stamp, iotext, expnam
write (io) reltim
c
# ifdef lyapunov
iotext ='read (iotraj) nptraj, pxyz, pijk em'
write (io) stamp, iotext, expnam
write (io) nptraj, pxyz, pijk, em
write (stdout,*) ' => Particle trajectories (lyapunov) written'
&, ' unformatted to file particles.dta on ts = ',itt, ' ', stamp
# else
iotext ='read (iotraj) nptraj, pxyz, pijk'
write (io) stamp, iotext, expnam
write (io) nptraj, pxyz, pijk
write (stdout,*) ' => Particle trajectories written'
&, ' unformatted to file particles.dta on ts = ',itt,' ', stamp
# endif
call relunit (io)
endif
c
# ifdef timing
call toc ('diagnostic', 'particle trajectories')
# endif
c
return
9000 format (1x,'=> Following',i5, ' particles at ',a32
&, '. (lon,lat,depth) of 1st particle is ('
&,f8.2,',',f8.2,',',f8.2,'m)')
end
#else
subroutine ptraj (j, jrow)
return
end
#endif