ROMS
Loading...
Searching...
No Matches
jedi_roms.h
Go to the documentation of this file.
1 MODULE roms_kernel_mod
2!
3!git $Id$
4!================================================== Hernan G. Arango ===
5! Copyright (c) 2002-2025 The ROMS Group !
6! Licensed under a MIT/X style license !
7! See License_ROMS.md !
8!=======================================================================
9! !
10! ROMSJEDI Interface: Joint Effort for Data-assimilation Integration !
11! !
12! The routines in this driver control the initialization, time- !
13! stepping, and finalization of ROMSJEDI interface following !
14! ESMF/NUOPC conventions: !
15! !
16! ROMS_initializeP1 Phase 1 ROMSJEDI Initialization !
17! ROMS_initializeP2 Phase 2 ROMSJEDI Initialization !
18! ROMS_initializeP3 Phase 3 ROMSJEDI Initialization !
19! ROMS_run !
20! ROMS_finalize !
21! !
22!=======================================================================
23!
24 USE mod_param
25 USE mod_parallel
26 USE mod_arrays
27 USE mod_fourdvar
28 USE mod_iounits
29 USE mod_ncparam
30#ifdef NESTING
31 USE mod_nesting
32#endif
33 USE mod_ocean
34 USE mod_scalars
35 USE mod_stepping
36!
38!
39#ifdef TANGENT
41#endif
43 USE dateclock_mod, ONLY : time_string
44#ifdef DISTRIBUTE
45 USE distribute_mod, ONLY : mp_bcasti
46#endif
47#ifdef WET_DRY
48 USE get_wetdry_mod, ONLY : get_wetdry
49#endif
51 USE inp_par_mod, ONLY : inp_par
52#ifdef NESTING
53 USE nesting_mod, ONLY : nesting
54#endif
55#ifdef SOLVE3D
57 USE omega_mod, ONLY : omega
58 USE rho_eos_mod, ONLY : rho_eos
60#endif
62#ifdef MASKING
63 USE set_masks_mod, ONLY : set_masks
64#endif
65 USE stiffness_mod, ONLY : stiffness
66 USE strings_mod, ONLY : founderror
68#ifdef TANGENT
70 USE tl_set_depth_mod, ONLY : tl_bath
71#endif
72#ifdef WET_DRY
73 USE wetdry_mod, ONLY : wetdry
74#endif
75 USE wrt_rst_mod, ONLY : wrt_rst
76!
77 implicit none
78!
79 PUBLIC :: roms_initializep1
80 PUBLIC :: roms_initializep2
81 PUBLIC :: roms_initializep3
82 PUBLIC :: roms_run
83 PUBLIC :: roms_finalize
84!
85 PRIVATE :: nlm_initial
86#ifdef TANGENT
87 PRIVATE :: tlm_initial
88#endif
89#ifdef ADJOINT
90 PRIVATE :: adm_initial
91#endif
92!
93 CONTAINS
94!
95 SUBROUTINE roms_initializep1 (first, mpiCOMM, kernel)
96!
97!=======================================================================
98! !
99! ROMSJEDI phase 2 initialization. It allocates and initializes ROMS !
100! state variables and internal parameters. It reads standard input !
101! parameters. !
102! !
103!=======================================================================
104!
105! Imported variable declarations.
106!
107 logical, intent(inout) :: first
108!
109 integer, intent(in), optional :: mpicomm
110 integer, intent(in), optional :: kernel
111!
112! Local variable declarations.
113!
114 logical :: allocate_vars = .true.
115
116#ifdef DISTRIBUTE
117 integer :: myerror, mysize
118#endif
119 integer :: phase, chunk_size, ng, thread, tile
120!
121 character (len=*), parameter :: myfile = &
122 & __FILE__//", ROMS_initialize"
123
124#ifdef DISTRIBUTE
125!
126!-----------------------------------------------------------------------
127! Set distribute-memory (mpi) world communictor.
128!-----------------------------------------------------------------------
129!
130 IF (PRESENT(mpicomm)) THEN
131 ocn_comm_world=mpicomm
132 ELSE
133 ocn_comm_world=mpi_comm_world
134 END IF
135 CALL mpi_comm_rank (ocn_comm_world, myrank, myerror)
136 CALL mpi_comm_size (ocn_comm_world, mysize, myerror)
137#endif
138!
139!-----------------------------------------------------------------------
140! On first pass, initialize model parameters a variables for all
141! nested/composed grids. Notice that the logical switch "first"
142! is used to allow multiple calls to this routine during ensemble
143! configurations.
144!-----------------------------------------------------------------------
145!
146 IF (first) THEN
147 first=.false.
148!
149! Initialize parallel control switches. These scalars switches are
150! independent from standard input parameters.
151!
153!
154! Set the ROMS standard output unit to write verbose execution info.
155! Notice that the default standard out unit in Fortran is 6.
156!
157! In some applications like coupling or disjointed mpi-communications,
158! it is advantageous to write standard output to a specific filename
159! instead of the default Fortran standard output unit 6. If that is
160! the case, it opens such formatted file for writing.
161!
162 IF (set_stdoutunit) THEN
164 set_stdoutunit=.false.
165 END IF
166!
167! Read in model tunable parameters from standard input. Allocate and
168! initialize variables in several modules after the number of nested
169! grids and dimension parameters are known.
170!
171 CALL inp_par (inlm)
172 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
173!
174! Initialize counters.
175!
176 nrun=1 ! run counter
177!
178! Set domain decomposition tile partition range. This range is
179! computed only once since the "first_tile" and "last_tile" values
180! are private for each parallel thread/node.
181!
182#if defined DISTRIBUTE
184#else
185 mythread=0
186#endif
187 DO ng=1,ngrids
188 chunk_size=(ntilex(ng)*ntilee(ng)+numthreads-1)/numthreads
189 first_tile(ng)=mythread*chunk_size
190 last_tile(ng)=first_tile(ng)+chunk_size-1
191 END DO
192!
193! Initialize internal wall clocks. Notice that the timings does not
194! includes processing standard input because several parameters are
195! needed to allocate clock variables.
196!
197 IF (master) THEN
198 WRITE (stdout,10)
199 10 FORMAT (/,' Process Information:',/)
200 END IF
201!
202 DO ng=1,ngrids
203 DO thread=thread_range
204 CALL wclock_on (ng, inlm, 0, __line__, myfile)
205 END DO
206 END DO
207!
208! Allocate and initialize modules variables.
209!
210 CALL roms_allocate_arrays (allocate_vars)
212 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
213
214 END IF
215!
216!-----------------------------------------------------------------------
217! Initialize ROMS, phase 1.
218!-----------------------------------------------------------------------
219!
220 phase=1
221!
222 SELECT CASE (kernel)
223 CASE (inlm)
224 CALL nlm_initial (phase)
225#ifdef TANGENT
226 CASE (itlm)
227 CALL tlm_initial (phase)
228#endif
229#ifdef ADJOINT
230 CASE (iadm)
231 CALL adm_initial (phase)
232#endif
233 END SELECT
234!
235!-----------------------------------------------------------------------
236! Set ROMS application grid configuration. It is done once.
237!-----------------------------------------------------------------------
238!
239 DO ng=1,ngrids
240 IF (setgridconfig(ng)) THEN
241 CALL set_grid (ng, inlm)
242 setgridconfig(ng)=.false.
243 END IF
244 END DO
245!
246 RETURN
247 END SUBROUTINE roms_initializep1
248!
249 SUBROUTINE roms_initializep2 (kernel)
250!
251!=======================================================================
252! !
253! ROMSJEDI phase 2 initialization. It requires the initial state !
254! (set elsewhere) to complete the full initialization of the kernel. !
255! It computes depths, density, and horizontal mass fluxes. !
256! !
257!=======================================================================
258!
259! Imported variable declarations
260!
261 integer, intent(in) :: kernel
262!
263! Local variable declarations.
264!
265 integer :: phase
266!
267!-----------------------------------------------------------------------
268! Initialize ROMSJEDI, Phase 2.
269!-----------------------------------------------------------------------
270!
271 phase=2
272!
273 SELECT CASE (kernel)
274 CASE (inlm)
275 CALL nlm_initial (phase)
276#ifdef TANGENT
277 CASE (itlm)
278 CALL tlm_initial (phase)
279#endif
280#ifdef ADJOINT
281 CASE (iadm)
282 CALL adm_initial (phase)
283#endif
284 END SELECT
285!
286 RETURN
287 END SUBROUTINE roms_initializep2
288!
289 SUBROUTINE roms_initializep3 (kernel)
290!
291!=======================================================================
292! !
293! ROMSJEDI phase 3 initialization. It computes the initial depths !
294! and level thicknesses from the time-averaged free-surface, Zt_avg1, !
295! which are needed to calculate initial vertically integrated !
296! momentum. !
297! !
298! Also, it initializes the state variables for all time levels and !
299! applies lateral boundary conditions. !
300! !
301! Notice that the second data snapshot needs to be processed because !
302! it is necessary for the initial lateral boundary conditions. !
303! !
304!=======================================================================
305!
306! Imported variable declarations
307!
308 integer, intent(in) :: kernel
309!
310! Local variable declarations.
311!
312 integer :: phase
313!
314!-----------------------------------------------------------------------
315! Initialize ROMSJEDI, Phase 3.
316!-----------------------------------------------------------------------
317!
318 phase=3
319!
320 SELECT CASE (kernel)
321 CASE (inlm)
322 CALL nlm_initial (phase)
323#ifdef TANGENT
324 CASE (itlm)
325 CALL tlm_initial (phase)
326#endif
327#ifdef ADJOINT
328 CASE (iadm)
329 CALL adm_initial (phase)
330#endif
331 END SELECT
332!
333 RETURN
334 END SUBROUTINE roms_initializep3
335!
336 SUBROUTINE roms_run (RunInterval, kernel)
337!
338!=======================================================================
339! !
340! This routine advance ROMS kernel for the specified time interval. !
341! !
342! On Input: !
343! !
344! RunInterval Execution time stepping window (seconds) !
345! kernel Dynamical/numerical kernel (integer) !
346! !
347!=======================================================================
348!
349! Imported variable declarations
350!
351 integer, intent(in), optional :: kernel
352!
353 real(dp), intent(in) :: runinterval
354!
355! Local variable declarations.
356!
357 integer :: ng
358 integer :: nstrstep, nendstep, extra
359!
360 real(dp) :: endtime, nexttime
361!
362 character (len=2), dimension(4) :: mid = (/'NL','TL','RP','AD'/)
363
364 character (len=*), parameter :: myfile = &
365 & __FILE__//", ROMS_run"
366!
367 sourcefile=myfile
368!
369!=======================================================================
370! Advance ROMS dynamical/numerical kernel: NLM, TLM, or ADM
371!=======================================================================
372!
373! OOPS will advance ROMS kernels by smaller intervals, usually a single
374! timestep. The strategy here is different to that used for coupling
375! since ROMS delayed output. The delayed ouput last half timestep will
376! affect the OOPS trajectory logic needed to save the NLM background
377! fields needed to linearize the TLM and ADM kernels.
378!
379 myruninterval=runinterval
380 IF (master) WRITE (stdout,'(1x)')
381!
382 SELECT CASE (kernel)
383 CASE (inlm)
384 DO ng=1,ngrids
385 nexttime=time(ng)+runinterval
386 endtime=initime(ng)+ntimes(ng)*dt(ng)
387 extra=1
388 step_counter(ng)=0
389 nstrstep=iic(ng)-1
390 nendstep=nstrstep+int((myruninterval)/dt(ng))-extra
391 IF (iic(ng).eq.ntstart(ng)) THEN
392 processinputdata(ng)=.false. ! because Phase 3
393 ELSE
394 processinputdata(ng)=.true.
395 END IF
396 IF (master) WRITE (stdout,10) mid(kernel), ng, &
397 & nstrstep, max(0,nendstep)
398 END DO
399 IF (master) WRITE (stdout,'(1x)')
400 CASE (itlm)
401 DO ng=1,ngrids
402 nexttime=time(ng)+runinterval
403 endtime=initime(ng)+ntimes(ng)*dt(ng)
404 extra=1
405 step_counter(ng)=0
406 nstrstep=iic(ng)-1
407 nendstep=nstrstep+int((myruninterval)/dt(ng))-extra
408 IF (iic(ng).eq.ntstart(ng)) THEN
409 processinputdata(ng)=.false. ! because Phase 3
410 ELSE
411 processinputdata(ng)=.true.
412 END IF
413 IF (master) WRITE (stdout,10) mid(kernel), ng, &
414 & nstrstep, max(0,nendstep)
415 END DO
416 IF (master) WRITE (stdout,'(1x)')
417 CASE (iadm)
418 DO ng=1,ngrids
419 nexttime=time(ng)-runinterval
420 endtime=initime(ng)+ntimes(ng)*dt(ng)
421 extra=1
422 step_counter(ng)=0
423 nstrstep=iic(ng)-1
424 nendstep=nstrstep-int((myruninterval)/dt(ng))+extra
425 IF (master) WRITE (stdout,10) mid(kernel), ng, &
426 & nstrstep, max(0,nendstep)
427 END DO
428 IF (master) WRITE (stdout,'(1x)')
429 END SELECT
430!
431! Time-step ROMS kernel.
432!
433 SELECT CASE (kernel)
434 CASE (inlm)
435 CALL main3d (runinterval)
436#ifdef TANGENT
437 CASE (itlm)
438 CALL tl_main3d (runinterval)
439#endif
440#ifdef ADJOINT
441 CASE (iadm)
442 CALL ad_main3d (runinterval)
443#endif
444 END SELECT
445!
446 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
447!
448 10 FORMAT (1x,a,1x,'ROMS: started time-stepping:', &
449 & ' (Grid: ',i2.2,' TimeSteps: ',i0,' - ',i0,')')
450!
451 RETURN
452 END SUBROUTINE roms_run
453!
454 SUBROUTINE roms_finalize
455!
456!=======================================================================
457! !
458! This routine terminates ROMS W4D-RBLanczos execution. !
459! !
460!=======================================================================
461!
462! Local variable declarations.
463!
464 integer :: fcount, ng, thread
465!
466 character (len=*), parameter :: myfile = &
467 & __FILE__//", ROMS_finalize"
468!
469!-----------------------------------------------------------------------
470! If blowing-up, save latest model state into RESTART NetCDF file.
471!-----------------------------------------------------------------------
472!
473! If cycling restart records, write solution into record 3.
474!
475 IF (exit_flag.eq.1) THEN
476 DO ng=1,ngrids
477 IF (lwrtrst(ng)) THEN
478 IF (master) WRITE (stdout,10)
479 10 FORMAT (/,' Blowing-up: Saving latest model state into ', &
480 & ' RESTART file',/)
481 fcount=rst(ng)%load
482 IF (lcyclerst(ng).and.(rst(ng)%Nrec(fcount).ge.2)) THEN
483 rst(ng)%Rindex=2
484 lcyclerst(ng)=.false.
485 END IF
488#ifdef DISTRIBUTE
489 CALL wrt_rst (ng, myrank)
490#else
491 CALL wrt_rst (ng, -1)
492#endif
493 END IF
494 END DO
495 END IF
496!
497!-----------------------------------------------------------------------
498! Stop model and time profiling clocks, report memory requirements,
499! and close output NetCDF files.
500!-----------------------------------------------------------------------
501!
502! Stop time clocks.
503!
504 IF (master) THEN
505 WRITE (stdout,20)
506 20 FORMAT (/,'Elapsed wall CPU time for each process (seconds):',/)
507 END IF
508!
509 DO ng=1,ngrids
510 DO thread=thread_range
511 CALL wclock_off (ng, inlm, 0, __line__, myfile)
512 END DO
513 END DO
514!
515! Report dynamic memory and automatic memory requirements.
516!
517 CALL memory
518!
519! Close IO files.
520!
521 DO ng=1,ngrids
522 CALL close_inp (ng, inlm)
523 END DO
524 CALL close_out
525!
526 RETURN
527 END SUBROUTINE roms_finalize
528!
529 SUBROUTINE nlm_initial (Phase)
530!
531!=======================================================================
532! !
533! ROMSJEDI nonlinear model (NLM) kernel initialization Phases: !
534! !
535! Phase 1: Set time-stepping parameters !
536! !
537! Phase 2: Computes initial depths, density, horizontal mass !
538! fluxes, and other configuration arrays. It reads !
539! forcing snapshots. !
540! !
541! Phase 3: Computes the initial depths and level thicknesses from !
542! the initial time-averaged free-surface field, Zt_avg1. !
543! Additionally, it initializes the state variables for !
544! all time levels and applies lateral boundary conditions.!
545! !
546!=======================================================================
547!
548! Imported variable declarations
549!
550 integer, intent(in) :: phase
551!
552! Local variable declarations.
553!
554 integer :: fcount
555 integer :: ng, thread, tile
556#ifdef NESTING
557 integer :: ig, nl
558 integer :: cr, i, m
559#endif
560 integer, dimension(Ngrids) :: inirec, tindex
561!
562 character (len=*), parameter :: myfile = &
563 & __FILE__//", nlm_initial"
564
565#ifdef PROFILE
566!
567!-----------------------------------------------------------------------
568! Start time wall clocks.
569!-----------------------------------------------------------------------
570!
571 DO ng=1,ngrids
572 DO thread=thread_range
573 CALL wclock_on (ng, inlm, 2, __line__, myfile)
574 END DO
575 END DO
576#endif
577!
578!=======================================================================
579! ROMSJEDI NLM kernel, Phase 1 Initialization.
580!=======================================================================
581!
582 phase1 : IF (phase.eq.1) THEN
583!
584 IF (master) THEN
585 WRITE (stdout,10) 'NLM_INITIAL: Phase 1 Initialization: ', &
586 & 'Configuring ROMS nonlinear kernel ...'
587 END IF
588!
589! Initialize time stepping indices and counters.
590!
591 DO ng=1,ngrids
592 iif(ng)=1
593 indx1(ng)=1
594 kstp(ng)=1
595 krhs(ng)=1
596 knew(ng)=1
597 predictor_2d_step(ng)=.false.
598!
599 iic(ng)=0
600# ifdef JEDI
601 jic(ng)=0
602# endif
603 nstp(ng)=1
604 nrhs(ng)=1
605 nnew(ng)=1
606#ifdef FLOATS
607 nf(ng)=0
608 nfp1(ng)=1
609 nfm1(ng)=4
610 nfm2(ng)=3
611 nfm3(ng)=2
612#endif
613!
614 inirec(ng)=nrrec(ng)
615 tindex(ng)=1
616!
617 synchro_flag(ng)=.true.
618 first_time(ng)=0
619 tdays(ng)=dstart
620 time(ng)=tdays(ng)*day2sec
621#ifdef JEDI
622 time4jedi(ng)=time(ng)
623#endif
624 ntstart(ng)=int((time(ng)-dstart*day2sec)/dt(ng))+1
625 ntfirst(ng)=ntstart(ng)
626 step_counter(ng)=0
627 END DO
628!
629! Initialize global diagnostics variables.
630!
631 avgke=0.0_dp
632 avgpe=0.0_dp
633 avgkp=0.0_dp
634 volume=0.0_dp
635!
636! Reset output history files time record counters. These counters are
637! reset on every iteration pass. This file is created on the first
638! iteration pass.
639!
640 DO ng=1,ngrids
641 ldefhis(ng)=.true.
642 lwrthis(ng)=.true.
643 his(ng)%Rindex=0
644 fcount=his(ng)%Fcount
645 his(ng)%Nrec(fcount)=0
646
647 ldefqck(ng)=.true.
648 lwrtqck(ng)=.true.
649 qck(ng)%Rindex=0
650 fcount=qck(ng)%Fcount
651 qck(ng)%Nrec(fcount)=0
652
653 ldefrst(ng)=.true.
654 lwrtrst(ng)=.true.
655 rst(ng)%Rindex=0
656 fcount=rst(ng)%Fcount
657 rst(ng)%Nrec(fcount)=0
658 END DO
659
660 END IF phase1
661!
662!=======================================================================
663! ROMSJEDI NLM kernel, Phase 2 Initialization.
664!=======================================================================
665!
666 phase2: IF (phase.eq.2) THEN
667!
668 IF (master) THEN
669 WRITE (stdout,10) 'NLM_INITIAL: Phase 2 Initialization: ', &
670 & 'Get/Set required applications fields ...'
671 END IF
672!
673!-----------------------------------------------------------------------
674! Initialize horizontal mixing coefficients. If applicable, scale
675! mixing coefficients according to the grid size (smallest area).
676#ifndef ANA_SPONGE
677! Also increase their values in sponge areas using the "visc_factor"
678! and/or "diff_factor" read from input Grid NetCDF file.
679#endif
680!-----------------------------------------------------------------------
681!
682 DO ng=1,ngrids
683 DO tile=first_tile(ng),last_tile(ng),+1
684 CALL ini_hmixcoef (ng, tile, inlm)
685 END DO
686 END DO
687
688#ifdef ANA_SPONGE
689!
690!-----------------------------------------------------------------------
691! Increase horizontal mixing coefficients in sponge areas using
692! analytical functions.
693!-----------------------------------------------------------------------
694!
695 DO ng=1,ngrids
696 IF (lsponge(ng)) THEN
697 DO tile=first_tile(ng),last_tile(ng),+1
698 CALL ana_sponge (ng, tile, inlm)
699 END DO
700 END IF
701 END DO
702#endif
703
704#ifdef WET_DRY
705!
706!-----------------------------------------------------------------------
707! Process initial wet/dry masks.
708!-----------------------------------------------------------------------
709!
710 DO ng=1,ngrids
711 DO tile=first_tile(ng),last_tile(ng),+1
712 CALL wetdry (ng, tile, tindex(ng), .true.)
713 END DO
714 END DO
715#endif
716
717#ifdef SOLVE3D
718!
719!-----------------------------------------------------------------------
720! Compute time independent (Zt_avg1=0) and initial time dependent
721! depths and level thicknesses.
722!-----------------------------------------------------------------------
723!
724 DO ng=1,ngrids
725 DO tile=first_tile(ng),last_tile(ng),+1
726 CALL set_depth0 (ng, tile, inlm)
727 CALL set_depth (ng, tile, inlm)
728 END DO
729 END DO
730!
731!-----------------------------------------------------------------------
732! Compute initial horizontal mass fluxes, Hz*u/n and Hz*v/m.
733!-----------------------------------------------------------------------
734!
735 DO ng=1,ngrids
736 DO tile=first_tile(ng),last_tile(ng),+1
737 CALL set_massflux (ng, tile, inlm)
738 END DO
739 END DO
740!
741!-----------------------------------------------------------------------
742! Compute initial S-coordinates vertical velocity. Compute initial
743! density anomaly from potential temperature and salinity via equation
744! of state for seawater. Also compute other equation of state related
745! quatities.
746!-----------------------------------------------------------------------
747!
748 DO ng=1,ngrids
749 DO tile=first_tile(ng),last_tile(ng),+1
750 CALL omega (ng, tile, inlm)
751 CALL rho_eos (ng, tile, inlm)
752 END DO
753 END DO
754#endif
755
756#ifdef ANA_PSOURCE
757!
758!-----------------------------------------------------------------------
759! Set point Sources/Sinks position, direction, special flag, and mass
760! transport nondimensional shape profile with analytcal expressions.
761! Point sources are at U- and V-points. We need to get their positions
762! to process internal Land/Sea masking arrays during initialization.
763!-----------------------------------------------------------------------
764!
765 DO ng=1,ngrids
766 IF (luvsrc(ng).or.lwsrc(ng).or.any(ltracersrc(:,ng))) THEN
767 DO tile=first_tile(ng),last_tile(ng),+1
768 CALL ana_psource (ng, tile, inlm)
769 END DO
770 END IF
771 END DO
772#endif
773!
774!-----------------------------------------------------------------------
775! If applicable, close all input boundary, climatology, and forcing
776! NetCDF files and set associated parameters to the closed state. This
777! step is essential in iterative algorithms that run the full TLM
778! repetitively. Then, Initialize several parameters in their file
779! structure, so the appropriate input single or multi-file is selected
780! during initialization/restart.
781!-----------------------------------------------------------------------
782!
783 DO ng=1,ngrids
784 CALL close_inp (ng, inlm)
785 CALL check_multifile (ng, inlm)
786#ifdef DISTRIBUTE
787 CALL mp_bcasti (ng, inlm, exit_flag)
788#endif
789 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
790 END DO
791!
792! If applicable, read in input data.
793!
794 DO ng=1,ngrids
795 CALL get_idata (ng)
796 CALL get_data (ng)
797#ifdef DISTRIBUTE
798 CALL mp_bcasti (ng, inlm, exit_flag)
799#endif
800 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
801 END DO
802
803#ifdef MASKING
804!
805!-----------------------------------------------------------------------
806! Set internal I/O mask arrays.
807!-----------------------------------------------------------------------
808!
809 DO ng=1,ngrids
810 DO tile=first_tile(ng),last_tile(ng),+1
811 CALL set_masks (ng, tile, inlm)
812 END DO
813 END DO
814#endif
815
816#ifdef NESTING
817# if defined MASKING || defined WET_DRY
818!
819!-----------------------------------------------------------------------
820! If nesting and Land/Sea masking, scale horizontal interpolation
821! weights to account for land contact points.
822!-----------------------------------------------------------------------
823!
824 DO ng=1,ngrids
825 CALL nesting (ng, inlm, nmask)
826 END DO
827# endif
828!
829!-----------------------------------------------------------------------
830! If nesting, process state fields initial conditions in the contact
831! regions.
832!-----------------------------------------------------------------------
833!
834! Free-surface and 2D-momentum.
835!
836 DO nl=1,nestlayers
837 DO ig=1,gridsinlayer(nl)
838 ng=gridnumber(ig,nl)
839 IF (any(compositegrid(:,ng))) THEN
840 CALL nesting (ng, inlm, nfsic) ! free-surface
841# ifndef SOLVE3D
842 CALL nesting (ng, inlm, n2dic) ! 2d momentum
843# endif
844 END IF
845 END DO
846 END DO
847
848# ifdef SOLVE3D
849!
850! Determine vertical indices and vertical interpolation weights in
851! the contact zone using initial unperturbed depth arrays.
852!
853 DO ng=1,ngrids
854 CALL nesting (ng, inlm, nzwgt)
855 END DO
856!
857! 3D-momentum and tracers.
858!
859 DO nl=1,nestlayers
860 DO ig=1,gridsinlayer(nl)
861 ng=gridnumber(ig,nl)
862 IF (any(compositegrid(:,ng))) THEN
863 CALL nesting (ng, inlm, n3dic) ! 3D momentum
864 CALL nesting (ng, inlm, ntvic) ! Tracer variables
865 END IF
866 END DO
867 END DO
868# endif
869#endif
870
871#if defined ANA_DRAG && defined UV_DRAG_GRID
872!
873!-----------------------------------------------------------------------
874! Set analytical spatially varying bottom friction parameter.
875!-----------------------------------------------------------------------
876!
877 IF (nrun.eq.erstr) THEN
878 DO ng=1,ngrids
879 DO tile=first_tile(ng),last_tile(ng),+1
880 CALL ana_drag (ng, tile, inlm)
881 END DO
882 END DO
883 END IF
884#endif
885!
886!-----------------------------------------------------------------------
887! Compute grid stiffness.
888!-----------------------------------------------------------------------
889!
890 IF (lstiffness) THEN
891 lstiffness=.false.
892 DO ng=1,ngrids
893 DO tile=first_tile(ng),last_tile(ng),+1
894 CALL stiffness (ng, tile, inlm)
895 END DO
896 END DO
897 END IF
898
899#if defined FLOATS || defined STATIONS
900!
901!-----------------------------------------------------------------------
902! If applicable, convert initial locations to fractional grid
903! coordinates.
904!-----------------------------------------------------------------------
905!
906 DO ng=1,ngrids
907 CALL grid_coords (ng, inlm)
908 END DO
909#endif
910 END IF phase2
911!
912!=======================================================================
913! ROMSJEDI NLM kernel, Phase 3 Initialization.
914!=======================================================================
915!
916 phase3: IF (phase.eq.3) THEN
917!
918 IF (master) THEN
919 WRITE (stdout,10) 'NLM_INITIAL: Phase 3 Initialization: ', &
920 & 'State Lateral Boundary Conditions ...'
921 END IF
922!
923!-----------------------------------------------------------------------
924! Initialize time-stepping counter and time/date string. Save NLM
925! initial conditions time.
926!
927! Notice that it is allowed to modify the "simulation length" in the
928! roms-jedi YAML file, which will affect the values of "ntimes" and
929! "ntend".
930!-----------------------------------------------------------------------
931!
932 DO ng=1,ngrids
933 initime(ng)=time(ng)
934 iic(ng)=ntstart(ng)
935 ntend(ng)=ntstart(ng)+ntimes(ng)-1
936#ifdef JEDI
937 jic(ng)=ntstart(ng)
938 time4jedi(ng)=time(ng)
939#endif
940 CALL time_string (time(ng), time_code(ng))
941 END DO
942!
943!-----------------------------------------------------------------------
944! Read in required data, if any, from input NetCDF files.
945!-----------------------------------------------------------------------
946!
947 DO ng=1,ngrids
948 CALL get_data (ng)
950 & __line__, myfile)) RETURN
951 END DO
952!
953!-----------------------------------------------------------------------
954! If applicable, process input data: time interpolate between data
955! snapshots.
956!-----------------------------------------------------------------------
957!
958 DO ng=1,ngrids
959 DO tile=first_tile(ng),last_tile(ng),+1
960 CALL set_data (ng, tile)
961 END DO
962 END DO
963 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
964!
965!-----------------------------------------------------------------------
966! Computes the initial depths and level thicknesses from the initial
967! time=averaged free-surface field, Zt_avg1 . Additionally, it
968! initializes the nonlinear state variables for all time levels and
969! applies lateral boundary conditions.
970!-----------------------------------------------------------------------
971!
972 DO ng=1,ngrids
973 CALL post_initial (ng, inlm)
974 END DO
975 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
976
977 END IF phase3
978
979#ifdef PROFILE
980!
981!-----------------------------------------------------------------------
982! Turn off initialization time wall clock.
983!-----------------------------------------------------------------------
984!
985 DO ng=1,ngrids
986 DO thread=thread_range
987 CALL wclock_off (ng, inlm, 2, __line__, myfile)
988 END DO
989 END DO
990#endif
991!
992 10 FORMAT (/,1x,a,a,/,1x,'***********',/)
993!
994 RETURN
995 END SUBROUTINE nlm_initial
996
997#ifdef TANGENT
998!
999 SUBROUTINE tlm_initial (Phase)
1000!
1001!=======================================================================
1002! !
1003! ROMSJEDI tangent linear model (TLM) kernel initialization Phases: !
1004! !
1005! Phase 1: Set time-stepping parameters !
1006! !
1007! Phase 2: Computes masks and other configuration arrays. It reads !
1008! initial forcing snapshots. !
1009! !
1010!=======================================================================
1011!
1012! Imported variable declarations
1013!
1014 integer, intent(in) :: phase
1015!
1016! Local variable declarations.
1017!
1018 integer :: fcount
1019 integer :: ng, thread, tile
1020 integer :: lstr, ifile
1021
1022 integer, dimension(Ngrids) :: inirec, tindex
1023
1024# ifdef GENERIC_DSTART
1025!
1026 real(dp) :: my_dstart
1027# endif
1028!
1029 character (len=10) :: suffix
1030
1031 character (len=*), parameter :: myfile = &
1032 & __FILE__//", tlm_initial"
1033
1034# ifdef PROFILE
1035!
1036!-----------------------------------------------------------------------
1037! Start time wall clocks.
1038!-----------------------------------------------------------------------
1039!
1040 DO ng=1,ngrids
1041 DO thread=thread_range
1042 CALL wclock_on (ng, itlm, 2, __line__, myfile)
1043 END DO
1044 END DO
1045# endif
1046!
1047!=======================================================================
1048! ROMSJEDI TLM kernel, Phase 1 Initialization.
1049!=======================================================================
1050!
1051 phase1 : IF (phase.eq.1) THEN
1052!
1053 IF (master) THEN
1054 WRITE (stdout,10) 'TLM_INITIAL: Phase 1 Initialization: ', &
1055 & 'Configuring ROMS tangent linear kernel ...'
1056 END IF
1057!
1058! Initialize time stepping indices and counters.
1059!
1060 DO ng=1,ngrids
1061 iif(ng)=1
1062 indx1(ng)=1
1063 kstp(ng)=1
1064 krhs(ng)=1
1065 knew(ng)=1
1066 predictor_2d_step(ng)=.false.
1067!
1068 iic(ng)=0
1069# ifdef JEDI
1070 jic(ng)=0
1071# endif
1072 nstp(ng)=1
1073 nrhs(ng)=1
1074 nnew(ng)=1
1075# ifdef FLOATS_NOT_YET
1076 nf(ng)=0
1077 nfp1(ng)=1
1078 nfm1(ng)=4
1079 nfm2(ng)=3
1080 nfm3(ng)=2
1081# endif
1082!
1083 synchro_flag(ng)=.true.
1084 first_time(ng)=0
1085 IF (any(tl_volcons(:,ng))) THEN
1086 tl_ubar_xs=0.0_r8
1087 END IF
1088
1089# if defined GENERIC_DSTART
1090!
1091! Rarely, the tangent linear model is initialized from a NetCDF file,
1092! so we do not know its actual initialization time. Usually, it is
1093! computed from DSTART, implying that its value is correct in the ROMS
1094! input script. Therefore, the user needs to check and update its value
1095! to every time that ROMS is executed. Alternatively, if available, we
1096! can use the initialization time from the nonlinear model, INItime.
1097! This variable is assigned when computing or processing the basic
1098! state trajectory needed to linearize the adjoint model.
1099!
1100 IF (initime(ng).lt.0.0_dp) THEN
1101 my_dstart=dstart ! ROMS input script
1102 ELSE
1103 my_dstart=initime(ng)/86400.0_dp ! NLM IC time is known
1104 END IF
1105 tdays(ng)=my_dstart
1106# else
1107 tdays(ng)=dstart
1108# endif
1109 time(ng)=tdays(ng)*day2sec
1110# ifdef JEDI
1111 time4jedi(ng)=time(ng)
1112# endif
1113 ntstart(ng)=int((time(ng)-dstart*day2sec)/dt(ng))+1
1114 ntend(ng)=ntstart(ng)+ntimes(ng)-1
1115 ntfirst(ng)=ntstart(ng)
1116!
1117 inirec(ng)=nrrec(ng)
1118 tindex(ng)=1
1119 END DO
1120!
1121! Initialize global diagnostics variables.
1122!
1123 avgke=0.0_dp
1124 avgpe=0.0_dp
1125 avgkp=0.0_dp
1126 volume=0.0_dp
1127
1128 END IF phase1
1129!
1130!=======================================================================
1131! ROMSJEDI TLM kernel, Phase 2 Initialization.
1132!=======================================================================
1133!
1134 phase2: IF (phase.eq.2) THEN
1135!
1136 IF (master) THEN
1137 WRITE (stdout,10) 'TLM_INITIAL: Phase 2 Initialization: ', &
1138 & 'Get/Set required applications fields ...'
1139 END IF
1140!
1141!-----------------------------------------------------------------------
1142! Initialize horizontal mixing coefficients. If applicable, scale
1143! mixing coefficients according to the grid size (smallest area).
1144# ifndef ANA_SPONGE
1145! Also increase their values in sponge areas using the "visc_factor"
1146! and/or "diff_factor" read from input Grid NetCDF file.
1147# endif
1148!-----------------------------------------------------------------------
1149!
1150 DO ng=1,ngrids
1151 DO tile=first_tile(ng),last_tile(ng),+1
1152 CALL ini_hmixcoef (ng, tile, itlm)
1153 END DO
1154 END DO
1155
1156# ifdef ANA_SPONGE
1157!
1158!-----------------------------------------------------------------------
1159! Increase horizontal mixing coefficients in sponge areas using
1160! analytical functions.
1161!-----------------------------------------------------------------------
1162!
1163 DO ng=1,ngrids
1164 IF (lsponge(ng)) THEN
1165 DO tile=first_tile(ng),last_tile(ng),+1
1166 CALL ana_sponge (ng, tile, itlm)
1167 END DO
1168 END IF
1169 END DO
1170# endif
1171!
1172!-----------------------------------------------------------------------
1173! Initialize tangent linear bathymetry to zero.
1174!-----------------------------------------------------------------------
1175!
1176 DO ng=1,ngrids
1177 DO tile=first_tile(ng),last_tile(ng),+1
1178 CALL tl_bath (ng, tile)
1179 END DO
1180 END DO
1181
1182# ifdef WET_DRY
1183!
1184!-----------------------------------------------------------------------
1185! Process initial wet/dry masks.
1186!-----------------------------------------------------------------------
1187!
1188 DO ng=1,ngrids
1189 DO tile=first_tile(ng),last_tile(ng),+1
1190 CALL wetdry (ng, tile, tindex(ng), .true.)
1191 END DO
1192 END DO
1193# endif
1194
1195# ifdef FORWARD_FLUXES
1196!
1197!-----------------------------------------------------------------------
1198! Set the BLK structure to contain the nonlinear model surface fluxes
1199! needed by the tangent linear and adjoint models. Also, set switches
1200! to process that structure in routine "check_multifile". Notice that
1201! it is possible to split the solution into multiple NetCDF files to
1202! reduce their size.
1203!-----------------------------------------------------------------------
1204!
1205! Set the nonlinear model quicksave-history file as the basic state for
1206! the surface fluxes computed in "bulk_flux", which may be available at
1207! more frequent intervals while avoiding large files. Since the 4D-Var
1208! increment phase is calculated by a different executable and needs to
1209! know some of the QCK structure information.
1210!
1211 DO ng=1,ngrids
1212 WRITE (qck(ng)%name,"(a,'.nc')") trim(qck(ng)%head)
1213 lstr=len_trim(qck(ng)%name)
1214 qck(ng)%base=qck(ng)%name(1:lstr-3)
1215 IF (qck(ng)%Nfiles.gt.1) THEN
1216 DO ifile=1,qck(ng)%Nfiles
1217 WRITE (suffix,"('_',i4.4,'.nc')") ifile
1218 qck(ng)%files(ifile)=trim(qck(ng)%base)//trim(suffix)
1219 END DO
1220 qck(ng)%name=trim(qck(ng)%files(1))
1221 ELSE
1222 qck(ng)%files(1)=trim(qck(ng)%name)
1223 END IF
1224 END DO
1225!
1226! The switch LreadFRC is deactivated because all the atmospheric
1227! forcing, including shortwave radiation, is read from the NLM
1228! surface fluxes or is assigned during ESM coupling. Such fluxes
1229! are available from the QCK structure. There is no need for reading
1230! and processing from the FRC structure input forcing-files.
1231!
1232 CALL edit_multifile ('QCK2BLK')
1233 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1234 DO ng=1,ngrids
1235 lreadblk(ng)=.true.
1236 lreadfrc(ng)=.false.
1237 lreadqck(ng)=.false.
1238 END DO
1239# endif
1240!
1241!-----------------------------------------------------------------------
1242! If applicable, close all input boundary, climatology, and forcing
1243! NetCDF files and set associated parameters to the closed state. This
1244! step is essential in iterative algorithms that run the full TLM
1245! repetitively. Then, Initialize several parameters in their file
1246! structure, so the appropriate input single or multi-file is selected
1247! during initialization/restart.
1248!-----------------------------------------------------------------------
1249!
1250 DO ng=1,ngrids
1251 CALL close_inp (ng, itlm)
1252 CALL check_multifile (ng, itlm)
1253# ifdef DISTRIBUTE
1254 CALL mp_bcasti (ng, itlm, exit_flag)
1255# endif
1256 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1257 END DO
1258!
1259!-----------------------------------------------------------------------
1260! Read in initial forcing, climatology and assimilation data from
1261! input NetCDF files. It loads the first relevant data record for
1262! the time-interpolation between snapshots.
1263!-----------------------------------------------------------------------
1264!
1265 DO ng=1,ngrids
1266 CALL tl_get_idata (ng)
1267 CALL tl_get_data (ng)
1268# ifdef DISTRIBUTE
1269 CALL mp_bcasti (ng, itlm, exit_flag)
1270# endif
1271 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1272 END DO
1273
1274# ifdef MASKING
1275!
1276!-----------------------------------------------------------------------
1277! Set internal I/O mask arrays.
1278!-----------------------------------------------------------------------
1279!
1280 DO ng=1,ngrids
1281 DO tile=first_tile(ng),last_tile(ng),+1
1282 CALL set_masks (ng, tile, itlm)
1283 END DO
1284 END DO
1285# endif
1286
1287# if defined ANA_DRAG && defined UV_DRAG_GRID
1288!
1289!-----------------------------------------------------------------------
1290! Set analytical spatially varying bottom friction parameter.
1291!-----------------------------------------------------------------------
1292!
1293 IF (nrun.eq.erstr) THEN
1294 DO ng=1,ngrids
1295 DO tile=first_tile(ng),last_tile(ng),+1
1296 CALL ana_drag (ng, tile, itlm)
1297 END DO
1298 END DO
1299 END IF
1300# endif
1301!
1302!-----------------------------------------------------------------------
1303! Compute grid stiffness.
1304!-----------------------------------------------------------------------
1305!
1306 IF (lstiffness) THEN
1307 lstiffness=.false.
1308 DO ng=1,ngrids
1309 DO tile=first_tile(ng),last_tile(ng),+1
1310 CALL stiffness (ng, tile, itlm)
1311 END DO
1312 END DO
1313 END IF
1314
1315# if defined FLOATS_NOT_YET || defined STATIONS
1316!
1317!-----------------------------------------------------------------------
1318! If applicable, convert initial locations to fractional grid
1319! coordinates.
1320!-----------------------------------------------------------------------
1321!
1322 DO ng=1,ngrids
1323 CALL grid_coords (ng, itlm)
1324 END DO
1325# endif
1326 END IF phase2
1327!
1328!=======================================================================
1329! ROMSJEDI TLM kernel, Phase 3 Initialization.
1330!=======================================================================
1331!
1332 phase3: IF (phase.eq.3) THEN
1333!
1334 IF (master) THEN
1335 WRITE (stdout,10) 'TLM_INITIAL: Phase 3 Initialization: ', &
1336 & 'State Lateral Boundary Conditions ...'
1337 END IF
1338!
1339!-----------------------------------------------------------------------
1340! Initialize time-stepping counter and time/date string.
1341!
1342! Notice that it is allowed to modify the "simulation length" in the
1343! roms-jedi YAML file, which will affect the values of "ntimes" and
1344! "ntend".
1345!-----------------------------------------------------------------------
1346!
1347! Subsract one time unit to avoid special case due to initialization
1348! in the main time-stepping routine.
1349!
1350 DO ng=1,ngrids
1351 iic(ng)=ntstart(ng)
1352 ntend(ng)=ntstart(ng)+ntimes(ng)-1
1353#ifdef JEDI
1354 jic(ng)=ntstart(ng)
1355 time4jedi(ng)=time(ng)
1356#endif
1357 CALL time_string (time(ng), time_code(ng))
1358 ldeftlm(ng)=.true.
1359 lwrttlm(ng)=.true.
1360 END DO
1361!
1362!-----------------------------------------------------------------------
1363! Read in required data, if any, from input NetCDF files.
1364!-----------------------------------------------------------------------
1365!
1366 DO ng=1,ngrids
1367 CALL tl_get_data (ng)
1369 & __line__, myfile)) RETURN
1370 END DO
1371!
1372!-----------------------------------------------------------------------
1373! If applicable, process input data: time interpolate between data
1374! snapshots.
1375!-----------------------------------------------------------------------
1376!
1377 DO ng=1,ngrids
1378 DO tile=first_tile(ng),last_tile(ng),+1
1379 CALL tl_set_data (ng, tile)
1380 END DO
1381 END DO
1382 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1383!
1384!-----------------------------------------------------------------------
1385! Computes the initial depths and level thicknesses from the initial
1386! time-averaged free-surface field, Zt_avg1. Additionally, it
1387! initializes the nonlinear state variables for all time levels and
1388! applies lateral boundary conditions.
1389!-----------------------------------------------------------------------
1390!
1391 DO ng=1,ngrids
1392 CALL tl_post_initial (ng, itlm)
1393 END DO
1394 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1395
1396 END IF phase3
1397
1398# ifdef PROFILE
1399!
1400!-----------------------------------------------------------------------
1401! Turn off initialization time wall clock.
1402!-----------------------------------------------------------------------
1403!
1404 DO ng=1,ngrids
1405 DO thread=thread_range
1406 CALL wclock_off (ng, itlm, 2, __line__, myfile)
1407 END DO
1408 END DO
1409# endif
1410!
1411 10 FORMAT (/,1x,a,a,/,1x,'***********',/)
1412!
1413 RETURN
1414 END SUBROUTINE tlm_initial
1415#endif
1416
1417#ifdef ADJOINT
1418!
1419 SUBROUTINE adm_initial (Phase)
1420!
1421!=======================================================================
1422! !
1423! ROMSJEDI adjoint model (ADM) kernel initialization Phases: !
1424! !
1425! Phase 1: Set time-stepping parameters !
1426! !
1427! Phase 2: Computes masks and other configuration arrays. It reads !
1428! initial forcing snapshots. !
1429! !
1430!=======================================================================
1431!
1432! Imported variable declarations
1433!
1434 integer, intent(in) :: phase
1435!
1436! Local variable declarations.
1437!
1438 integer :: fcount
1439 integer :: ng, thread, tile
1440 integer :: lstr, ifile
1441
1442 integer, dimension(Ngrids) :: inirec, tindex
1443
1444# ifdef GENERIC_DSTART
1445!
1446 real(dp) :: my_dstart
1447# endif
1448!
1449 character (len=10) :: suffix
1450
1451 character (len=*), parameter :: myfile = &
1452 & __FILE__//", adm_initial"
1453
1454# ifdef PROFILE
1455!
1456!-----------------------------------------------------------------------
1457! Start time wall clocks.
1458!-----------------------------------------------------------------------
1459!
1460 DO ng=1,ngrids
1461 DO thread=thread_range
1462 CALL wclock_on (ng, iadm, 2, __line__, myfile)
1463 END DO
1464 END DO
1465# endif
1466!
1467!=======================================================================
1468! ROMSJEDI ADM kernel, Phase 1 Initialization.
1469!=======================================================================
1470!
1471 phase1 : IF (phase.eq.1) THEN
1472!
1473 IF (master) THEN
1474 WRITE (stdout,10) 'ADM_INITIAL: Phase 1 Initialization: ', &
1475 & 'Configuring ROMS nonlinear kernel ...'
1476 END IF
1477!
1478! Initialize time stepping indices and counters.
1479!
1480 DO ng=1,ngrids
1481 iif(ng)=1
1482 indx1(ng)=1
1483 kstp(ng)=1
1484 krhs(ng)=3
1485 knew(ng)=2
1486 predictor_2d_step(ng)=.false.
1487!
1488 iic(ng)=0
1489# ifdef JEDI
1490 jic(ng)=0
1491# endif
1492# ifdef SOLVE3D
1493 nstp(ng)=1
1494 nnew(ng)=2
1495 nrhs(ng)=nstp(ng)
1496# endif
1497# ifdef FLOATS_NOT_YET
1498 nf(ng)=0
1499 nfp1(ng)=1
1500 nfm1(ng)=4
1501 nfm2(ng)=3
1502 nfm3(ng)=2
1503# endif
1504!
1505 synchro_flag(ng)=.true.
1506 first_time(ng)=0
1507 ad_ubar_xs=0.0_r8
1508
1509# ifdef GENERIC_DSTART
1510!
1511! Rarely, the adjoint model is initialized from a NetCDF file, so we do
1512! not know its actual initialization time. Usually, it is computed from
1513! DSTART, implying that its value is correct in the ROMS input script.
1514! Therefore, the user needs to check and update its value to every time
1515! that ROMS is executed. Alternatively, if available, we can use the
1516! initialization time from the nonlinear model, INItime. This variable
1517! is assigned when computing or processing the basic state trajectory
1518! needed to linearize the adjoint model.
1519!
1520 IF (initime(ng).lt.0.0_dp) THEN
1521 my_dstart=dstart ! ROMS input script
1522 ELSE
1523 my_dstart=initime(ng)/86400.0_dp ! NLM IC time is known
1524 END IF
1525 tdays(ng)=my_dstart+dt(ng)*real(ntimes(ng),r8)*sec2day
1526 time(ng)=tdays(ng)*day2sec
1527 ntstart(ng)=int((time(ng)-dstart*day2sec)/dt(ng))+1
1528 ntend(ng)=ntstart(ng)-ntimes(ng)
1529 ntfirst(ng)=ntend(ng)
1530# else
1531 tdays(ng)=dstart+ &
1532 & dt(ng)*real(ntimes(ng)-ntfirst(ng)+1,r8)*sec2day
1533 time(ng)=tdays(ng)*day2sec
1534 ntstart(ng)=ntimes(ng)+1
1535 ntend(ng)=ntfirst(ng)
1536 ntfirst(ng)=ntend(ng)
1537# endif
1538# ifdef JEDI
1539 time4jedi(ng)=time(ng)
1540# endif
1541 inirec(ng)=nrrec(ng)
1542 tindex(ng)=1
1543 END DO
1544!
1545! Initialize global diagnostics variables.
1546!
1547 avgke=0.0_dp
1548 avgpe=0.0_dp
1549 avgkp=0.0_dp
1550 volume=0.0_dp
1551
1552 END IF phase1
1553!
1554!=======================================================================
1555! ROMSJEDI ADM kernel, Phase 2 Initialization.
1556!=======================================================================
1557!
1558 phase2: IF (phase.eq.2) THEN
1559!
1560 IF (master) THEN
1561 WRITE (stdout,10) 'ADM_INITIAL: Phase 2 Initialization: ', &
1562 & 'Get/Set required applications fields ...'
1563 END IF
1564!
1565!-----------------------------------------------------------------------
1566! Initialize horizontal mixing coefficients. If applicable, scale
1567! mixing coefficients according to the grid size (smallest area).
1568# ifndef ANA_SPONGE
1569! Also increase their values in sponge areas using the "visc_factor"
1570! and/or "diff_factor" read from input Grid NetCDF file.
1571# endif
1572!-----------------------------------------------------------------------
1573!
1574 DO ng=1,ngrids
1575 DO tile=first_tile(ng),last_tile(ng),+1
1576 CALL ini_hmixcoef (ng, tile, iadm)
1577 END DO
1578 END DO
1579
1580# ifdef ANA_SPONGE
1581!
1582!-----------------------------------------------------------------------
1583! Increase horizontal mixing coefficients in sponge areas using
1584! analytical functions.
1585!-----------------------------------------------------------------------
1586!
1587 DO ng=1,ngrids
1588 IF (lsponge(ng)) THEN
1589 DO tile=first_tile(ng),last_tile(ng),+1
1590 CALL ana_sponge (ng, tile, iadm)
1591 END DO
1592 END IF
1593 END DO
1594# endif
1595
1596# ifdef WET_DRY
1597!
1598!-----------------------------------------------------------------------
1599! Process initial wet/dry masks.
1600!-----------------------------------------------------------------------
1601!
1602 DO ng=1,ngrids
1603 DO tile=first_tile(ng),last_tile(ng),+1
1604 CALL wetdry (ng, tile, tindex(ng), .true.)
1605 END DO
1606 END DO
1607# endif
1608
1609# ifdef FORWARD_FLUXES
1610!
1611!-----------------------------------------------------------------------
1612! Set the BLK structure to contain the nonlinear model surface fluxes
1613! needed by the tangent linear and adjoint models. Also, set switches
1614! to process that structure in routine "check_multifile". Notice that
1615! it is possible to split the solution into multiple NetCDF files to
1616! reduce their size.
1617!-----------------------------------------------------------------------
1618!
1619! Set the nonlinear model quicksave-history file as the basic state for
1620! the surface fluxes computed in "bulk_flux", which may be available at
1621! more frequent intervals while avoiding large files. Since the 4D-Var
1622! increment phase is calculated by a different executable and needs to
1623! know some of the QCK structure information.
1624!
1625 DO ng=1,ngrids
1626 WRITE (qck(ng)%name,"(a,'.nc')") trim(qck(ng)%head)
1627 lstr=len_trim(qck(ng)%name)
1628 qck(ng)%base=qck(ng)%name(1:lstr-3)
1629 IF (qck(ng)%Nfiles.gt.1) THEN
1630 DO ifile=1,qck(ng)%Nfiles
1631 WRITE (suffix,"('_',i4.4,'.nc')") ifile
1632 qck(ng)%files(ifile)=trim(qck(ng)%base)//trim(suffix)
1633 END DO
1634 qck(ng)%name=trim(qck(ng)%files(1))
1635 ELSE
1636 qck(ng)%files(1)=trim(qck(ng)%name)
1637 END IF
1638 END DO
1639!
1640! The switch LreadFRC is deactivated because all the atmospheric
1641! forcing, including shortwave radiation, is read from the NLM
1642! surface fluxes or is assigned during ESM coupling. Such fluxes
1643! are available from the QCK structure. There is no need for reading
1644! and processing from the FRC structure input forcing-files.
1645!
1646 CALL edit_multifile ('QCK2BLK')
1647 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1648 DO ng=1,ngrids
1649 lreadblk(ng)=.true.
1650 lreadfrc(ng)=.false.
1651 lreadqck(ng)=.false.
1652 END DO
1653# endif
1654!
1655!-----------------------------------------------------------------------
1656! If applicable, close all input boundary, climatology, and forcing
1657! NetCDF files and set associated parameters to the closed state. This
1658! step is essential in iterative algorithms that run the full TLM
1659! repetitively. Then, Initialize several parameters in their file
1660! structure, so the appropriate input single or multi-file is selected
1661! during initialization/restart.
1662!-----------------------------------------------------------------------
1663!
1664 DO ng=1,ngrids
1665 CALL close_inp (ng, iadm)
1666 CALL check_multifile (ng, iadm)
1667# ifdef DISTRIBUTE
1668 CALL mp_bcasti (ng, iadm, exit_flag)
1669# endif
1670 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1671 END DO
1672!
1673!-----------------------------------------------------------------------
1674! Read in initial forcing, climatology and assimilation data from
1675! input NetCDF files. It loads the first relevant data record for
1676! the time-interpolation between snapshots.
1677!-----------------------------------------------------------------------
1678!
1679 DO ng=1,ngrids
1680 CALL ad_get_idata (ng)
1681 CALL ad_get_data (ng)
1682# ifdef DISTRIBUTE
1683 CALL mp_bcasti (ng, iadm, exit_flag)
1684# endif
1685 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1686 END DO
1687
1688# ifdef MASKING
1689!
1690!-----------------------------------------------------------------------
1691! Set internal I/O mask arrays.
1692!-----------------------------------------------------------------------
1693!
1694 DO ng=1,ngrids
1695 DO tile=first_tile(ng),last_tile(ng),+1
1696 CALL set_masks (ng, tile, iadm)
1697 END DO
1698 END DO
1699# endif
1700
1701# if defined ANA_DRAG && defined UV_DRAG_GRID
1702!
1703!-----------------------------------------------------------------------
1704! Set analytical spatially varying bottom friction parameter.
1705!-----------------------------------------------------------------------
1706!
1707 IF (nrun.eq.erstr) THEN
1708 DO ng=1,ngrids
1709 DO tile=first_tile(ng),last_tile(ng),+1
1710 CALL ana_drag (ng, tile, iadm)
1711 END DO
1712 END DO
1713 END IF
1714# endif
1715!
1716!-----------------------------------------------------------------------
1717! Compute grid stiffness.
1718!-----------------------------------------------------------------------
1719!
1720 IF (lstiffness) THEN
1721 lstiffness=.false.
1722 DO ng=1,ngrids
1723 DO tile=first_tile(ng),last_tile(ng),+1
1724 CALL stiffness (ng, tile, iadm)
1725 END DO
1726 END DO
1727 END IF
1728
1729# if defined FLOATS_NOT_YET || defined STATIONS
1730!
1731!-----------------------------------------------------------------------
1732! If applicable, convert initial locations to fractional grid
1733! coordinates.
1734!-----------------------------------------------------------------------
1735!
1736 DO ng=1,ngrids
1737 CALL grid_coords (ng, iadm)
1738 END DO
1739# endif
1740!
1741!-----------------------------------------------------------------------
1742! Initialize time-stepping counter.
1743!-----------------------------------------------------------------------
1744!
1745 DO ng=1,ngrids
1746!! ntstart(ng)=ntstart(ng)-1
1747 iic(ng)=ntstart(ng)
1748# ifdef JEDI
1749 jic(ng)=ntstart(ng)+1
1750 time4jedi(ng)=time(ng)+dt(ng)
1751# endif
1752 CALL time_string (time(ng), time_code(ng))
1753 ldefadj(ng)=.true.
1754 lwrtadj(ng)=.true.
1755 END DO
1756
1757 END IF phase2
1758
1759# ifdef PROFILE
1760!
1761!-----------------------------------------------------------------------
1762! Turn off initialization time wall clock.
1763!-----------------------------------------------------------------------
1764!
1765 DO ng=1,ngrids
1766 DO thread=thread_range
1767 CALL wclock_off (ng, iadm, 2, __line__, myfile)
1768 END DO
1769 END DO
1770# endif
1771!
1772 10 FORMAT (/,1x,a,a,/,1x,'***********',/)
1773!
1774 RETURN
1775 END SUBROUTINE adm_initial
1776#endif
1777
1778 END MODULE roms_kernel_mod
subroutine ad_get_data(ng)
Definition ad_get_data.F:4
subroutine ad_get_idata(ng)
Definition ad_get_idata.F:4
subroutine ad_main3d(runinterval)
Definition ad_main3d.F:4
subroutine check_multifile(ng, model)
subroutine edit_multifile(task)
subroutine get_data(ng)
Definition get_data.F:3
subroutine get_idata(ng)
Definition get_idata.F:3
subroutine grid_coords(ng, model)
Definition grid_coords.F:4
subroutine main3d(runinterval)
Definition main3d.F:4
subroutine memory
Definition memory.F:3
subroutine, public ad_post_initial(ng, model)
subroutine ana_sponge(ng, tile, model)
Definition ana_hmixcoef.h:3
subroutine ana_drag(ng, tile, model)
Definition ana_drag.h:3
subroutine ana_psource(ng, tile, model)
Definition ana_psource.h:3
subroutine, public close_out
Definition close_io.F:175
subroutine, public close_inp(ng, model)
Definition close_io.F:92
subroutine, public time_string(mytime, date_string)
Definition dateclock.F:1272
subroutine, public get_wetdry(ng, tile, model, inirec)
Definition get_wetdry.F:45
subroutine, public ini_hmixcoef(ng, tile, model)
subroutine, public inp_par(model)
Definition inp_par.F:56
subroutine, public roms_initialize_arrays
Definition mod_arrays.F:351
subroutine, public roms_allocate_arrays(allocate_vars)
Definition mod_arrays.F:114
type(t_io), dimension(:), allocatable his
type(t_io), dimension(:), allocatable qck
type(t_io), dimension(:), allocatable rst
integer stdout
character(len=256) sourcefile
integer, parameter ntvic
Definition mod_nesting.F:85
integer, parameter nzwgt
Definition mod_nesting.F:89
integer, parameter nfsic
Definition mod_nesting.F:82
integer, parameter n3dic
Definition mod_nesting.F:84
integer, parameter nmask
Definition mod_nesting.F:78
integer, parameter n2dic
Definition mod_nesting.F:83
subroutine, public initialize_parallel
integer numthreads
integer, dimension(:), allocatable first_tile
integer mythread
logical master
integer, dimension(:), allocatable last_tile
integer ocn_comm_world
integer, parameter inlm
Definition mod_param.F:662
integer, dimension(:,:), allocatable gridnumber
Definition mod_param.F:127
integer, dimension(:), allocatable ntilex
Definition mod_param.F:685
integer, parameter iadm
Definition mod_param.F:665
integer nestlayers
Definition mod_param.F:118
integer ngrids
Definition mod_param.F:113
integer, dimension(:), allocatable ntilee
Definition mod_param.F:686
integer, parameter itlm
Definition mod_param.F:663
integer, dimension(:), allocatable gridsinlayer
Definition mod_param.F:122
logical, dimension(:), allocatable luvsrc
logical, dimension(:), allocatable lwrtqck
real(dp), parameter day2sec
logical, dimension(:), allocatable lreadqck
integer, dimension(:), allocatable nrrec
logical, dimension(:,:), allocatable ltracersrc
integer, dimension(:), allocatable ntimes
integer, dimension(:), allocatable iic
real(dp), dimension(:), allocatable dt
logical, dimension(:), allocatable lsponge
logical, dimension(:), allocatable setgridconfig
logical lstiffness
integer blowup
real(dp) avgke
real(dp) avgpe
logical, dimension(:), allocatable synchro_flag
logical, dimension(:), allocatable lreadfrc
logical, dimension(:), allocatable predictor_2d_step
logical, dimension(:), allocatable ldefqck
integer, dimension(:), allocatable jic
real(dp), dimension(:), allocatable tdays
real(dp) tl_ubar_xs
logical, dimension(:), allocatable ldefadj
real(dp) dstart
logical, dimension(:), allocatable ldefhis
logical, dimension(:), allocatable lwrtadj
logical, dimension(:), allocatable lwsrc
real(dp), parameter sec2day
integer, dimension(:), allocatable ntend
real(dp) ad_ubar_xs
real(dp) volume
integer, dimension(:), allocatable first_time
character(len=22), dimension(:), allocatable time_code
integer exit_flag
real(dp), dimension(:), allocatable time4jedi
integer, dimension(:), allocatable indx1
logical, dimension(:,:), allocatable compositegrid
real(dp) myruninterval
integer erstr
real(dp) avgkp
logical, dimension(:), allocatable lwrthis
logical, dimension(:,:), allocatable tl_volcons
integer, dimension(:), allocatable ntfirst
logical, dimension(:), allocatable ldefrst
logical, dimension(:), allocatable lwrttlm
logical, dimension(:), allocatable lwrtrst
real(dp), dimension(:), allocatable time
logical, dimension(:), allocatable ldeftlm
integer, dimension(:), allocatable ntstart
integer nrun
integer, dimension(:), allocatable step_counter
logical, dimension(:), allocatable processinputdata
integer, dimension(:), allocatable iif
real(dp), dimension(:), allocatable initime
integer noerror
logical, dimension(:), allocatable lcyclerst
logical, dimension(:), allocatable lreadblk
integer, dimension(:), allocatable nfm2
integer, dimension(:), allocatable kstp
integer, dimension(:), allocatable knew
integer, dimension(:), allocatable nfm1
integer, dimension(:), allocatable nrhs
integer, dimension(:), allocatable nf
integer, dimension(:), allocatable nfm3
integer, dimension(:), allocatable nnew
integer, dimension(:), allocatable nfp1
integer, dimension(:), allocatable krhs
integer, dimension(:), allocatable nstp
subroutine, public nesting(ng, model, isection)
Definition nesting.F:140
subroutine, public omega(ng, tile, model)
Definition omega.F:42
subroutine, public post_initial(ng, model)
subroutine, public rho_eos(ng, tile, model)
Definition rho_eos.F:48
subroutine, public roms_initializep1(first, mpicomm, kernel)
Definition jedi_roms.h:96
subroutine, public roms_finalize
Definition ad_roms.h:283
subroutine, public roms_run(runinterval)
Definition ad_roms.h:239
subroutine, private tlm_initial(phase)
Definition jedi_roms.h:1000
subroutine, public roms_initializep2(kernel)
Definition jedi_roms.h:250
subroutine, private adm_initial(phase)
Definition jedi_roms.h:1420
subroutine, private nlm_initial(phase)
Definition jedi_roms.h:530
subroutine, public roms_initializep3(kernel)
Definition jedi_roms.h:290
subroutine, public set_depth(ng, tile, model)
Definition set_depth.F:34
subroutine, public set_depth0(ng, tile, model)
Definition set_depth.F:281
subroutine, public set_masks(ng, tile, model)
Definition set_masks.F:44
subroutine, public set_massflux(ng, tile, model)
integer function, public stdout_unit(mymaster)
Definition stdout_mod.F:48
logical, save set_stdoutunit
Definition stdout_mod.F:41
subroutine, public stiffness(ng, tile, model)
Definition stiffness.F:32
logical function, public founderror(flag, noerr, line, routine)
Definition strings.F:52
subroutine, public tl_post_initial(ng, model)
subroutine, public tl_bath(ng, tile)
subroutine wetdry(ng, tile, tindex, linitialize)
Definition wetdry.F:22
subroutine, public wrt_rst(ng, tile)
Definition wrt_rst.F:63
subroutine set_data(ng, tile)
Definition set_data.F:4
subroutine set_grid(ng, model)
Definition set_grid.F:3
recursive subroutine wclock_off(ng, model, region, line, routine)
Definition timers.F:148
recursive subroutine wclock_on(ng, model, region, line, routine)
Definition timers.F:3
subroutine tl_get_data(ng)
Definition tl_get_data.F:4
subroutine tl_get_idata(ng)
Definition tl_get_idata.F:4
subroutine tl_main3d(runinterval)
Definition tl_main3d.F:4
subroutine tl_set_data(ng, tile)
Definition tl_set_data.F:4