-
Notifications
You must be signed in to change notification settings - Fork 7
/
ROMSPath.f90
2299 lines (1758 loc) · 83.4 KB
/
ROMSPath.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
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
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
! ROMSPath - Offlinwe PArticle tracking model v1.1
! Date: 25 OCtober 2021
!
! Description: ROMSPath is an
! off-line particle-tracking model that runs with the stored predictions of
! a 3D hydrodynamic model, specifically the Regional Ocean Modeling System
! (ROMS). Although ROMSPath was built to simulate oyster larvae, it can
! be adapted to simulate passive particles and other planktonic organisms.
! ROMSPath is written in Fortran 90 and is designed to track the trajectories
! of particles in three dimensions. It includes a 4th order Runge-Kutta scheme
! for particle advection and a random displacement model for vertical turbulent
! particle motion. Reflective boundary conditions, larval behavior, and
! settlement routines are also included. Components of ROMSPath have been in
! development since 2002 and are described in the following publications:
! North et al. 2004, North et al. 2006a, North et al. 2006b,
! North et al. 2008, North et al. 2011, Schlag and North 2012.
!
! Developers:
! Elizabeth North: [email protected]
! Zachary Schlag: [email protected]
! Ian Mitchell: [email protected]
! Elias Hunter: [email protected]
!
! Rutgers The State University of New Jersey
! Department of Marine and Coastal Sciences
! New Brunswick, NJ 08901 USA
!
! Funding was provided by the National Science Foundation Biological
! and Physical Oceanography Programs, Maryland Department of Natural
! Resources, NOAA Chesapeake Bay Office, NOAA Maryland Sea Grant College
! Program, & NOAA-funded UMCP Advanced Study Institute for the Environment.
!
! **********************************************************************
! **********************************************************************
! ** Copyright (c) 2019 **
! ** **
! **********************************************************************
! ** **
! ** This Software is open-source and licensed under the following **
! ** conditions as stated by MIT/X License: **
! ** **
! ** (See http://www.opensource.org/licenses/mit-license.php ). **
! ** **
! ** Permission is hereby granted, free of charge, to any person **
! ** obtaining a copy of this Software and associated documentation **
! ** files (the "Software"), to deal in the Software without **
! ** restriction, including without limitation the rights to use, **
! ** copy, modify, merge, publish, distribute, sublicense, **
! ** and/or sell copies of the Software, and to permit persons **
! ** to whom the Software is furnished to do so, subject to the **
! ** following conditions: **
! ** **
! ** The above copyright notice and this permission notice shall **
! ** be included in all copies or substantial portions of the **
! ** Software. **
! ** **
! ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, **
! ** EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE **
! ** WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE **
! ** AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT **
! ** HOLDERS BE LIABLE FOR ANY CLAIMS, DAMAGES OR OTHER LIABILITIES, **
! ** WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING **
! ** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR **
! ** OTHER DEALINGS IN THE SOFTWARE. **
! ** **
! ** The most current official versions of this Software and **
! ** associated tools and documentation are available at: **
! ** **
! ** **
! ** **
! ** We ask that users make appropriate acknowledgement of **
! ** The University of Maryland Center for Environmental Science, **
! ** individual developers, participating agencies and institutions, **
! ** and funding agencies. One way to do this is to cite one or **
! ** more of the relevant publications listed at: **
! ** **
! ** **
! ** **
! **********************************************************************
! **********************************************************************
PROGRAM main
! ROMSPath.f90 contains the main structure of the particle-tracking program.
! It executes the external time step, internal time step, and particle loops,
! advects particles, and writes output. It calls modules that read in
! hydrodynamic model information, move particles due to turbulence and
! behavior, test if particles are in habitat polygons, and apply boundary
! conditions to keep particles in the model domain.
!
! Program created by: Elizabeth North
! Modified by: Elias Hunter
! Created on: 2004
! Last Modified on: 25 October 2021
! ROMSPath Version: 1.0.1
IMPLICIT NONE
! *************************************************************************
! * *
! * Variable Declarations *
! * *
! *************************************************************************
INTEGER, PARAMETER :: nAttrib = 22
INTEGER, PARAMETER :: pX = 1 ! Particle X-coordinate
INTEGER, PARAMETER :: pY = 2 ! Particle Y-coordinate
INTEGER, PARAMETER :: pZ = 3 ! Particle Z-coordinate
INTEGER, PARAMETER :: pnX = 4 ! Particle new X-coordinate
INTEGER, PARAMETER :: pnY = 5 ! Particle new Y-coordinate
INTEGER, PARAMETER :: pnZ = 6 ! Particle new Z-coordinate
INTEGER, PARAMETER :: ppX = 7 ! Particle previous X-coordinate
INTEGER, PARAMETER :: ppY = 8 ! Particle previous Y-coordinate
INTEGER, PARAMETER :: ppZ = 9 ! Particle previous Z-coordinate
INTEGER, PARAMETER :: pStatus = 10 ! Status of particle (previously Color)
INTEGER, PARAMETER :: pDOB = 11 ! Particle Date Of Birth
INTEGER, PARAMETER :: pAge = 12 ! Particle Age (s)
INTEGER, PARAMETER :: pLifespan = 13 ! Age at which particle settled or died
INTEGER, PARAMETER :: pGID = 14 ! Current grid ID.
INTEGER, PARAMETER :: pSize = 15 ! Current particle size
INTEGER, PARAMETER :: pAcc = 16 ! Modeled PArticle acceleration
INTEGER, PARAMETER :: pVort = 17 ! Modeled particle vorticity
INTEGER, PARAMETER :: pbehaveW = 18 ! MOdeled particle bahavioral velocity
INTEGER, PARAMETER :: pSSF = 19 ! Modeled Sink/Swim flag
INTEGER, PARAMETER :: pWD = 20 ! Water Depth
INTEGER, PARAMETER :: pZeta = 21 ! ROMS Zeta
INTEGER, PARAMETER :: pBath = 22 ! ROMS Bathymetry (h)
DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:) :: par
DOUBLE PRECISION, ALLOCATABLE, DIMENSION( : ) :: P_Salt,P_Temp,mean_salt,mean_temp
DOUBLE PRECISION, ALLOCATABLE, DIMENSION( : ) :: P_HOB,P_bustr,P_bvstr
INTEGER, ALLOCATABLE, DIMENSION(:) :: startpoly,endpoly,hitBottom,hitLand
LOGICAL, ALLOCATABLE, DIMENSION(:) :: isIn
DOUBLE PRECISION :: ex(3),ix(3)
INTEGER :: printdt,ets,its,mI
REAL :: timeCounts(8),times(9)
INTEGER :: NCcount,NCstart,prcount
! *************************************************************************
! * *
! * Execution *
! * *
! *************************************************************************
call run_ROMSPath()
contains
subroutine run_ROMSPath()
! *************************************************************************
! * *
! * Run Model *
! * *
! *************************************************************************
use param_mod, only: days,dt,tdim
integer :: seconds,stepT
DOUBLE PRECISION :: before,after,tdiff
call ini_ROMSPath()
write(*,'(/,A)') '****** BEGIN ITERATIONS *******'
! days*24*60*60 = total number of seconds to run the model
! divide that by dt to get the number of external time steps
seconds = int(days*86400.0) !Total seconds to run model
stepT = seconds/dt !number of external time steps
do ets=1,stepT
call run_External_Timestep()
enddo
call fin_ROMSPath()
end subroutine run_ROMSPath
subroutine ini_ROMSPath()
! *************************************************************************
! * *
! * Initialize Model *
! * *
! *************************************************************************
! use behavior_mod, only: initBehave,setOut,die
use boundary_mod, only: bounds,zbounds
USE INT_MOD, ONLY: getInterp2D,getInterp3D
use random_mod, only: init_genrand,init_random_seed
use hydro_mod, only: updatehydro
use param_mod, only: numpar,days,dt,idt,seed,parfile,settlementon, &
Behavior,TrackCollisions,SaltTempOn,Ngrid,SaltTempMean, &
xi_rho,eta_rho,t_b,t_c,t_f,tstep,initsize,WriteBottom, &
WriteHeaders,WriteModelTiming,ErrorFlag,getParams,Behavior
use grid_mod, only: InitGrid,GRIDS
use INT_MOD, only: LL2ij,inside
integer :: n,istat,ng,i,j,nmask
logical :: ingrid,obound,inzgrid
double precision, allocatable, dimension(:) :: pLon,pLat,Ipar,Jpar
CHARACTER(len=200) :: filenm
integer :: in_island,inbounds,test
double precision:: tdepth,zeta,dpran
t_b = 1 !Back step is 1st time step in arrays
t_c = 2 !Center step is 2nd time step in arrays
t_f = 3 !Forward step is 3rd time step in arrays
tstep=1
! ***************************************************************************
! * Get Parameter Values *
! ***************************************************************************
CALL getParams()
CALL InitGrid()
CALL writeModelInfo()
write(*,*) ' '
write(*,*) ' *************** ROMSPath INITIALIZATION ************** '
#ifdef WETDRY
write(*,*) 'WETDRY ACTIVE'
#endif
#ifdef GROWTH
write(*,*) 'GROWTH ACTIVE'
#endif
#ifdef STOKES
write(*,*) 'STOKES ACTIVE'
#endif
! ! ***************************************************************************
! ! * Allocate Dynamic Variables *
! ! ***************************************************************************
ALLOCATE(par(numpar,nAttrib))
IF(SettlementOn)THEN
ALLOCATE(startpoly(numpar))
ALLOCATE(endpoly(numpar))
endpoly = 0 !initialize end polygon location to zero
ENDIF
IF(SaltTempOn)THEN
ALLOCATE(P_Salt(numpar))
ALLOCATE(P_Temp(numpar))
P_Salt = 0.0
P_Temp = 0.0
IF(SaltTempMean)THEN
ALLOCATE(mean_salt(numpar))
ALLOCATE(mean_temp(numpar))
mean_salt = 0.0
mean_temp = 0.0
ENDIF
ENDIF
IF(WriteBottom)THEN
ALLOCATE(P_HOB(numpar))
ALLOCATE(P_bustr(numpar))
ALLOCATE(P_bvstr(numpar))
P_HOB = 0.0
P_bustr = 0.0
P_bvstr = 0.0
ENDIF
IF(TrackCollisions)THEN
ALLOCATE(hitBottom(numpar))
ALLOCATE(hitLand(numpar))
hitBottom = 0
hitLand = 0
ENDIF
! !Local variables for read-in of Latitude and Longitude
ALLOCATE(pLon(numpar))
ALLOCATE(pLat(numpar))
ALLOCATE(isIn(numpar))
ALLOCATE(Ipar(numpar))
ALLOCATE(Jpar(numpar))
! ! *************************************************************************
! ! * Initialize print counters and random number generator *
! ! *************************************************************************
! ! THE FOLLOWING VARIABLE INITIALIZATIONS SHOULD NOT BE CHANGED:
prcount=0 !print counter; number of external time steps
printdt=0 !print counter
!set random random Seed Value (how inception is that)
IF (seed .EQ. 0) THEN
call init_random_seed(seed)
ENDIF
CALL init_genrand(seed)!set random number generator Seed Value
! ! *************************************************************************
! ! * *
! ! * Initialize Hydrodynamic data *
! ! * *
! ! *************************************************************************
call updateHydro(.TRUE.,1,t_b)
call updateHydro(.FALSE.,2,t_c)
call updateHydro(.FALSE.,3,t_f)
! ! *************************************************************************
! ! * Initialize Particle Attributes *
! ! *************************************************************************
! ! Read-in lat/long of particles. If settlement module is on, read in
! ! the habitat polygon on which the particle start
write(*,*) 'read in particle locations', numpar
OPEN(1,FILE=TRIM(parfile))
do n=1,numpar
par(n,pDOB) = -9.0
if(settlementon)then
read (1,*) pLon(n),pLat(n),par(n,pZ),par(n,pDOB),startpoly(n)
else
read (1,*) pLon(n),pLat(n),par(n,pZ),par(n,pDOB)
endif
par(n,pX) = 1.0
par(n,pY) = 1.0
par(n,pnX) = 1.0
par(n,pnY) = 1.0
par(n,pnZ) = 1.0
par(n,ppX) = 1.0
par(n,ppY) = 1.0
par(n,ppZ) = 1.0
par(n,pStatus) = 9.0
par(n,pAge) = 0.0
par(n,pLifespan) = 0.0
par(n,pGID) = dble(Ngrid)
par(n,pSize) = initsize
par(n,pAcc) = 0.0
par(n,pVort) = 0.0
par(n,pbehaveW) = 0.0
par(n,pSSF) = 0.0
par(n,pWD) = 9999.0
par(n,pBath) = 9999.0
par(n,pZeta) = 9999.0
Ipar(n)=0.0
Jpar(n)=0.0
IF(WriteBottom)THEN
P_HOB(n)=9999.0
ENDIF
isIn(n)=.False.
enddo
CLOSE(1)
write(*,*) '*********'
do ng =1,Ngrid
call LL2ij(GRIDS(ng)%lon_rho,GRIDS(ng)%lat_rho,GRIDS(ng)%angle,Plon,Plat, &
numpar,xi_rho(ng),eta_rho(ng),Ipar,Jpar)
do n=1,numpar
call bounds(ng,Ipar(n),Jpar(n),nmask,ingrid,obound)
! par(n,pnX)=Ipar(n)
! par(n,pnY)=Jpar(n)
! par(n,ppX)=Ipar(n)
! par(n,ppY)=Jpar(n)
! if ((ingrid).and.(par(n,pGID).eq.dble(Ngrid))) then
if (.not.(isIn(n))) then
if (ingrid) then
par(n,pX)=Ipar(n)
par(n,pY)=Jpar(n)
par(n,pGID)=dble(ng)
par(n,pStatus)=0.0
isIn(n)=ingrid
call zbounds(ng,Ipar(n),Jpar(n),par(n,pZ),inzgrid,t_b)
if (inzgrid) then
else
par(n,pStatus)=9.0
endif
else
endif
endif
enddo
if (SaltTempOn) then
do n=1,numpar
if (isIn(n)) then
tdepth = DBLE(-1.0)* getInterp2D("depth",int(par(n,pGID)),par(n,pX),par(n,pY),t_c)
zeta = getInterp2D("zeta",int(par(n,pGID)),par(n,pX),par(n,pY),t_c)
P_salt(n)=getInterp3d("salt",int(par(n,pGID)),par(n,pX),par(n,pY),par(n,pZ),t_c,1,zeta,tdepth)
P_temp(n)=getInterp3d("temp",int(par(n,pGID)),par(n,pX),par(n,pY),par(n,pZ),t_c,1,zeta,tdepth)
par(n,pWD)=(DBLE(-1.0)*tdepth)+zeta
par(n,pZeta)=zeta
par(n,pBath)=(DBLE(-1.0)*tdepth)
if (SaltTempMean) then
mean_salt(n)=P_salt(n)
mean_temp(n)=P_temp(n)
mI=1
endif
endif
enddo
endif
! close(10)
enddo
write(*,*) '*********'
write(*,*) ' Particle n=1 Latitude=',pLat(1),'Longitude=',pLon(1)
write(*,*) ' Particle n=1 Depth=',par(1,pZ)
write(*,*) ' Particle n=1 X=',par(1,pX),'Y=',par(1,pY)
! if(settlementon) write(*,*) ' Particle n=5 Start Polygon=',startpoly(5)
! ! *******************************************************************
! ! * Initialize NetCDF Output *
! ! *******************************************************************
!Create NetCDF Output File
CALL initNetCDF()
CALL createNetCDF(par(:,pDOB))
prcount = 0
call writeNetCDF(0,pLon,pLat)
! !Deallocate local variables
DEALLOCATE(pLon,pLat)
end subroutine ini_ROMSPath
subroutine run_External_Timestep()
use param_mod, only: dt,idt,WriteModelTiming,tdim,t_b,t_c,t_f,filenum,&
numdigits,prefix,suffix,tstep,multifile
use hydro_mod, only: updateHydro,HYDRODATA
USE GRID_MOD, ONLY: reftime
integer :: stepIT,ng
real :: before,after,tdiff,ibefore,iafter
ng=1
if (tstep.gt.tdim(ng)) then
tstep=1
filenum=filenum+1.0
if (.NOT.multifile) then
write(*,*) 'NOT ENOUGH TIMES STEP TO CONTINUE:'
STOP
endif
endif
stepIT = int(dt/idt) !number of internal time steps
!Read in hydrodynamic model data
IF(ets > 2) then
t_b = mod(t_b,3)+1 ! 1 -> 2 -> 3 -> 1
t_c = mod(t_c,3)+1 ! 2 -> 3 -> 1 -> 2
t_f = mod(t_f,3)+1 ! 3 -> 1 -> 2 -> 3
CALL updateHydro(.FALSE.,tstep,t_f) !do not start updating until 3rd iteration
endif
!Prepare external time step values to be used for
! calculating Advection and Turbulence
ex=0.0
ex(1) = (ets-2)*dt
ex(2) = (ets-1)*dt
ex(3) = ets*dt
! call CPU_TIME(before)
call CPU_TIME(before)
do its=1,stepIT
call run_Internal_Timestep()
enddo !ITloop
tstep=tstep+1
timeCounts=0.0
end subroutine run_External_Timestep
subroutine run_Internal_Timestep()
use param_mod, only: idt,iPrint
! calculating Advection and Turbulence
ix(1) = ex(2) + DBLE((its-2)*idt)
ix(2) = ex(2) + DBLE((its-1)*idt)
ix(3) = ex(2) + DBLE(its*idt)
!********************************************************
!* Particle Loop *
!********************************************************
call update_particles()
!********************************************************
!* PRINT OUTPUT TO FILE *
!********************************************************
mI=mI+1
printdt=printdt+idt
if(printdt.GE.iprint) then
write(*,*) 'write output to file, day = ',(DBLE(ix(3))/DBLE(86400))
!ix(3)/86400 = (current model time in seconds) /
! (# of seconds in a day)
call dataOutput()
printdt=0 !reset print counter
endif
end subroutine run_Internal_Timestep
subroutine fin_ROMSPath()
! use param_mod, only: numpar,outpathGiven,outpath,settlementon
! use behavior_mod, only: finBehave,getStatus
! use convert_mod, only: x2lon,y2lat
! use hydro_mod, only: finHydro
! !OUTPUT ENDFILE NAME CONSTRUCTION VARIABLE
! CHARACTER(LEN=100) :: efile
integer :: n,d,h,m
real :: fintime,s
! double precision :: pLon,pLat
! !DEALLOCATE LOCAL VARIABLES
! DEALLOCATE(par)
! IF(ALLOCATED(hitBottom)) DEALLOCATE(hitBottom)
! IF(ALLOCATED(startpoly)) DEALLOCATE(startpoly)
! IF(ALLOCATED(endpoly )) DEALLOCATE(endpoly)
! IF(ALLOCATED(hitLand )) DEALLOCATE(hitLand)
! IF(ALLOCATED(P_Salt )) DEALLOCATE(P_Salt)
! IF(ALLOCATED(P_Temp )) DEALLOCATE(P_Temp)
! !DEALLOCATE MODULE VARIABLES
! call finBehave()
! call finHydro()
!Calculate model run time and output to screen before exiting
call CPU_TIME(fintime)
d = int(fintime/86400.0) !# of full days that the model ran
h = int((fintime - real(d*86400))/3600.0) !# of hours (minus days)
m = int((fintime - real(d*86400 - h*3600))/60.0)!# of minutes (minus days and hours)
s = fintime - REAL(d*86400) - REAL(h*3600) - REAL(m*60) !# of seconds (- days, hrs and mins)
11 format('Time to run model = ',i4,' days ',i4,' hours ',i4, &
' minutes and ',f10.4,' seconds.')
12 format('Time to run model = ',i4,' hours ',i4,' minutes and ',f10.4, &
' seconds.')
13 format('Time to run model = ',i4,' minutes and ',f10.4,' seconds.')
14 format('Time to run model = ',f10.4,' seconds.')
if(fintime > 86400.0)then
write(*,11) d,h,m,s
elseif(fintime > 3600.0)then
write(*,12) h,m,s
elseif(fintime > 60.0)then
write(*,13) m,s
else
write(*,14) fintime
endif
write(*,'(/,A)') '****** END ROMSPath *******'
end subroutine fin_ROMSPath
subroutine update_particles()
USE PARAM_MOD, ONLY: numpar,xi_rho,eta_rho,s_rho,s_w,xi_u,eta_u, &
idt,HTurbOn,VTurbOn,settlementon,xi_v,eta_v, &
Behavior,SaltTempOn,OpenOceanBoundary,Swimdepth, &
TrackCollisions,WriteModelTiming,mortality, &
ErrorFlag,t_b,t_c,t_f,Ngrid,vertdist,scheme,nsb, &
SaltTempMean,WriteBottom,maxsize,Process_VA
!USE SETTLEMENT_MOD, ONLY: isSettled,testSettlement
#ifdef GROWTH
USE GROWTH_MOD, ONLY: growlarva
#endif
USE BEHAVIOR_MOD, ONLY: behave
USE BOUNDARY_MOD, ONLY: bounds
USE GRID_MOD, ONLY: getSlevel,getWlevel,GRIDS
USE HTURB_MOD, ONLY: HTurb
USE VTURB_MOD, ONLY: VTurb
USE ADVECTION_MOD, ONLY: RKAdvect
USE INT_MOD, ONLY: getinterp2d,getinterp3d,polintd,getInterpStr
IMPLICIT NONE
! Iteration Variables
INTEGER :: i,deplvl,n
! Particle tracking
DOUBLE PRECISION, ALLOCATABLE, DIMENSION( : ) :: Pwc_zb,Pwc_zc,Pwc_zf
DOUBLE PRECISION, ALLOCATABLE, DIMENSION( : ) :: Pwc_wzb,Pwc_wzc,Pwc_wzf
DOUBLE PRECISION :: Xpar,Ypar,Zpar,newXpos,newYpos,newZpos,P_zb,P_zc,P_zf, &
P_zeta,ey(3)
! Behavior and Turbulence
DOUBLE PRECISION :: TurbHx,TurbHy,TurbV,Behav,XBehav,YBehav,ZBehav
LOGICAL :: bott ! for Behavior 7 along with XBehav,YBehav,ZBehav
! Boundaries
INTEGER :: intersectf,skipbound,inbounds,reflects,inpoly,nmask,Inode,Jnode &
,ngid
DOUBLE PRECISION :: reflect,fintersectX,fintersectY,freflectX,freflectY, &
Xpos,Ypos,nXpos,nYpos,pm,pn
LOGICAL :: ingrid,obound,hbot,htop
! Advection
DOUBLE PRECISION :: AdvectX,AdvectY,AdvectZ,maxpartdepth,minpartdepth, &
kn1_u,kn1_v,kn1_w,kn2_u,kn2_v,kn2_w,kn3_u,kn3_v,kn3_w,kn4_u,kn4_v,kn4_w, &
P_V,P_U,P_W,UAD,VAD,WAD,x1,x2,x3,y1,y2,y3,z1,z2,z3,btemp,tbustr,tbvstr
DOUBLE PRECISION :: tempX,tempY,tdepth,zeta,zetab,zetac,zetaf,behout(4)
DO n=1,numpar
! *********************************************************
! * *
! * Update Particle Age and Characteristics *
! * *
! *********************************************************
!If the particle is not yet released, set new location to
! current location, and cycle to next particle
if(ix(3) <= par(n,pDOB))then
cycle
endif
if(par(n,pStatus).eq.9.0)then
cycle
endif
#ifdef GROWTH
if(par(n,pSize).gt.maxsize)then
par(n,pStatus)=9.0
cycle
endif
#endif
! !If there are open ocean boundaries and the current
! ! particle has exited the model domain via them, skip it
if(OpenOceanBoundary)then
if(.not.isIn(n)) cycle
endif
!Update particle age
par(n,pAge) = par(n,pAge) + float(idt)
! !If particle settled or dead, skip tracking
! if(settlementon)then
! if ( isSettled(n) ) cycle
! endif
! ! *********************************************************
! ! * *
! ! * Find Element that Contains Particle *
! ! * *
! ! *********************************************************
! !Get node Boundary ibformation
Xpar = par(n,pX)
Ypar = par(n,pY)
Zpar = par(n,pZ)
Inode=floor(Xpar)
Jnode=floor(Ypar)
! ! *********************************************************
! ! * *
! ! * Prepare for Particle Movement *
! ! * *
! ! *********************************************************
pm = getInterp2D("pm",int(par(n,pGID)),Xpar,Ypar,1)
pn = getInterp2D("pn",int(par(n,pGID)),Xpar,Ypar,1)
AdvectX = 0.0
AdvectY = 0.0
AdvectZ = 0.0
TurbHx = 0.0
TurbHy = 0.0
TurbV = 0.0
! Behav = 0.0
! ! *********************************************************
! ! * *
! ! * ADVECTION *
! ! * *
! ! *********************************************************
! !Find advection currents at original coordinates
call CPU_TIME(times(1))
SELECT CASE (scheme)
CASE (1)
call RKAdvect(Xpar,Ypar,Zpar,ex,ix,pm,pn,int(par(n,pGID)),ets,AdvectX,AdvectY,AdvectZ)
CASE DEFAULT
AdvectX = 0.0
AdvectY = 0.0
AdvectZ = 0.0
END SELECT
! ! *********************************************************
! ! * *
! ! * Horizontal Turbulence *
! ! * *
! ! *********************************************************
! IF (WriteModelTiming) call CPU_TIME(times(4))
call CPU_TIME(times(2))
IF (HTurbOn) CALL HTurb(TurbHx,TurbHy,int(par(n,pGID)))
TurbHx=TurbHx*pm
TurbHy=TurbHy*pn
! ! *********************************************************
! ! * *
! ! * Verticle Turbulence *
! ! * *
! ! *********************************************************
call CPU_TIME(times(3))
IF (VTurbOn) CALL VTurb(Xpar,Ypar,Zpar,ets,ex,ix,int(par(n,pGID)),TurbV)
! ! *********************************************************
! ! * *
! ! * Behavior *
! ! * *
! ! *********************************************************
call CPU_TIME(times(4))
!write(*,*) times(4)-times(3)
CALL behave(Xpar,Ypar,Zpar,XBehav,YBehav,ZBehav,par(n,pSize),ex,ix,int(par(n,pGID)),behout)
par(n,pAcc)=behout(1)
par(n,pVort)=behout(2)
par(n,pbehaveW)=behout(3)
par(n,pSSF)=behout(4)
! ! *********************************************************
! ! * *
! ! * Update Particle Locations and Check Boundaries *
! ! * *
! ! *********************************************************
! IF(WriteModelTiming) call CPU_TIME(times(7))
call CPU_TIME(times(5))
!Update due to Advection and Turbulence
newXpos = par(n,pX) + AdvectX + TurbHx
newYpos = par(n,pY) + AdvectY + TurbHy
!
! !Assign new particle positions
do i=1,Ngrid
tempX=GRIDS(int(par(n,pGID)))%scl(i,1)*newXpos+GRIDS(int(par(n,pGID)))%off(i,1)
tempY=GRIDS(int(par(n,pGID)))%scl(i,2)*newYpos+GRIDS(int(par(n,pGID)))%off(i,2)
call bounds(i,tempX,tempY,nmask,ingrid,obound)
if (ingrid) then
par(n,pGID)=i
exit
endif
enddo
tdepth = DBLE(-1.0)* getInterp2D("depth",int(par(n,pGID)),tempX,tempY,t_c)
ey(1) = DBLE(1.0)*getInterp2D("zeta",int(par(n,pGID)),tempX,tempY,t_b)
ey(2) = DBLE(1.0)*getInterp2D("zeta",int(par(n,pGID)),tempX,tempY,t_c)
ey(3) = DBLE(1.0)*getInterp2D("zeta",int(par(n,pGID)),tempX,tempY,t_f)
P_zeta=polintd(ex,ey,3,ix(2))
par(n,pWD)=(DBLE(-1.0)*tdepth)+P_zeta
par(n,pZeta)=P_zeta
par(n,pBath)=(DBLE(-1.0)*tdepth)
hbot=.FALSE.
htop=.FALSE.
SELECT CASE (nsb)
CASE (0)
newZpos = par(n,pZ) + AdvectZ + TurbV+Zbehav
!newZpos = par(n,pZ) + AdvectZ +Zbehav
if (newZpos.LT.tdepth) then
newZpos = tdepth + ABS(newZpos-tdepth)
hbot=.TRUE.
endif
if (newZpos.GT.P_zeta) then
! write(*,*) P_zeta,TurbV,ABS(newZpos-P_zeta)
newZpos = P_zeta - ABS(newZpos-P_zeta)
htop=.TRUE.
endif
CASE (1) !Near-Surface
newZpos = P_zeta-vertdist
CASE (2) !Near-Bottom
newZpos = tdepth+vertdist
CASE DEFAULT
WRITE(*,*) 'NO VALID BEHAVIOR SET'
EXIT
END SELECT
if (ingrid) then
isIn(n)=ingrid
par(n,pX) = tempX
par(n,pY) = tempY
par(n,pZ) = newZpos
par(n,pStatus) = 1.0
if (htop) par(n,pStatus) = 1.1
if (hbot) par(n,pStatus) = 1.2
else
if (obound) then
isIn(n)=ingrid
par(n,pGID)=Ngrid
par(n,pStatus) = -8.0
else
isIn(n)=.TRUE.
par(n,pStatus) = -9.0
endif
endif
#ifdef GROWTH
! ! *********************************************************
! ! * *
! ! * Growth *
! ! * *
! ! *********************************************************
call growlarva(P_temp(n),P_salt(n),par(n,pAge),par(n,pSize),par(n,pStatus))
#endif
! ! *********************************************************
! ! * *
! ! * Settlement *
! ! * *
! ! *********************************************************
! if(settlementon) then
! CALL testSettlement(par(n,pAge),n,par(n,pX),par(n,pY),inpoly)
! if (inpoly .GT. 0) then
! par(n,pnZ) = P_depth
! endpoly(n) = inpoly
! par(n,pLifespan) = par(n,pAge)
! endif
! endif
! tdepth = DBLE(-1.0)* getInterp2D("depth",int(par(n,pGID)),par(n,pX),par(n,pY),t_c)
! ! *********************************************************
! ! * *
! ! * Bottom Stuff *
! ! * *
! ! *********************************************************
if (WriteBottom) then
btemp=DBLE(-1.0)*tdepth+par(n,pZ)
P_HOB(n)=min(btemp,P_HOB(n))
if (btemp.EQ.P_HOB(n)) then
ey(1)=getInterpStr("bustr",int(par(n,pGID)),par(n,pX),par(n,pY),t_b)
ey(2)=getInterpStr("bustr",int(par(n,pGID)),par(n,pX),par(n,pY),t_c)
ey(3)=getInterpStr("bustr",int(par(n,pGID)),par(n,pX),par(n,pY),t_f)
P_bustr(n)=polintd(ex,ey,3,ix(2))
ey(1)=getInterpStr("bvstr",int(par(n,pGID)),par(n,pX),par(n,pY),t_b)
ey(2)=getInterpStr("bvstr",int(par(n,pGID)),par(n,pX),par(n,pY),t_c)
ey(3)=getInterpStr("bvstr",int(par(n,pGID)),par(n,pX),par(n,pY),t_f)
P_bvstr(n)=polintd(ex,ey,3,ix(2))
endif
endif
! ! *********************************************************
! ! * *
! ! * Salinity and Temperature *
! ! * *
! ! *********************************************************
call CPU_TIME(times(6))
if (SaltTempOn) then
zetab = getInterp2D("zeta",int(par(n,pGID)),par(n,pX),par(n,pY),t_b)
zetac = getInterp2D("zeta",int(par(n,pGID)),par(n,pX),par(n,pY),t_c)
zetaf = getInterp2D("zeta",int(par(n,pGID)),par(n,pX),par(n,pY),t_f)
ey(1)=getInterp3d("salt",int(par(n,pGID)),par(n,pX),par(n,pY),par(n,pZ),t_b,1,zetab,tdepth)
ey(2)=getInterp3d("salt",int(par(n,pGID)),par(n,pX),par(n,pY),par(n,pZ),t_c,1,zetac,tdepth)
ey(3)=getInterp3d("salt",int(par(n,pGID)),par(n,pX),par(n,pY),par(n,pZ),t_f,1,zetaf,tdepth)
P_salt(n)=polintd(ex,ey,3,ix(2))
ey(1)=getInterp3d("temp",int(par(n,pGID)),par(n,pX),par(n,pY),par(n,pZ),t_b,1,zetab,tdepth)
ey(2)=getInterp3d("temp",int(par(n,pGID)),par(n,pX),par(n,pY),par(n,pZ),t_c,1,zetac,tdepth)
ey(3)=getInterp3d("temp",int(par(n,pGID)),par(n,pX),par(n,pY),par(n,pZ),t_f,1,zetaf,tdepth)
P_temp(n)=polintd(ex,ey,3,ix(2))
if (SaltTempMean) then
mean_salt(n)=mean_salt(n)+P_salt(n)
mean_temp(n)=mean_temp(n)+P_temp(n)
endif
endif
! ! *****************************************************************
! ! * End of Particle Loop *
! ! *****************************************************************
! IF(WriteModelTiming) then
call CPU_TIME(times(7))
timeCounts(1) = timeCounts(1) + (times(2)-times(1))
timeCounts(2) = timeCounts(2) + (times(3)-times(2))
timeCounts(3) = timeCounts(3) + (times(4)-times(3))
timeCounts(4) = timeCounts(4) + (times(5)-times(4))
timeCounts(5) = timeCounts(5) + (times(6)-times(5))
timeCounts(6) = timeCounts(6) + (times(7)-times(6))
! ENDIF