ROMS
Loading...
Searching...
No Matches
obs_sen_i4dvar_analysis.h
Go to the documentation of this file.
1 MODULE roms_kernel_mod
2!
3!git $Id$
4!=================================================== Andrew M. Moore ===
5! Copyright (c) 2002-2025 The ROMS Group Hernan G. Arango !
6! Licensed under a MIT/X style license !
7! See License_ROMS.md !
8!=======================================================================
9! !
10! ROMS I4D-VAR Observation Sensitivity Analysis Driver: !
11! !
12! This driver evaluates the impact of each observation in the !
13! 4D-Var analysis increment by measuring their sensitivity over !
14! a specified circulation functional index, J, similar to the !
15! adjoint sensitivity driver. This is equivalent to taking the !
16! adjoint of the 4D-Var algorithm. !
17! !
18! Algorithm Outline: !
19! !
20! !
21! |----------------------------|-----------------------------| !
22! t=t0 t=t1 t=t2 !
23! Assimilation window Forecast period !
24! !
25! |----------------------------------------------------------> NLM !
26! !
27! <----------------------------------------------------------| ADM !
28! !
29! |----------------------------> TLM !
30! !
31! (1) We begin by running an I4D-Var Lanczos calculation using k !
32! inner-loops and 1 outer-loop for the period t=t0 to t1. We !
33! will denote by xb(0) the background initial condition, and !
34! the observations vector by y. The resulting Lanczos vectors !
35! that we save in the adjoint NetCDF file will be denoted by !
36! q_i, where i=1,2,...,k. !
37! !
38! (2) Next we run the NLM for the combined assimilation+forecast !
39! period t=t0 to t2, where t2>t1. This represents the final !
40! sweep of the NLM for the period t=t0 to t1 after exiting the !
41! inner-loop in the I4D-Var plus the forecast period t=t1 to t2. !
42! The initial condition for the NLM at t=t0 is xb(0) and not !
43! the new estimated initial conditions. We save the basic state !
44! trajectory, xb(t), of this NLM run for use in the adjoint !
45! sensitivity calculation next, and for use in the TLM run !
46! later in step (7). !
47! !
48! Depending on time for which the sensitivity functional J(t) !
49! is defined, this will dictate t2. For example, if J(t) is a !
50! functional defined during the forecast interval t1<t<t2, then !
51! t2>t1 for this run of the NLM. However, if J(t) is defined !
52! during the assimilation interval t0<t<t1, then t2=t1. That is, !
53! the definition of t2 should be flexible depending on the !
54! choice of J. !
55! !
56! (3) The next step involves an adjoint sensitivity calculation !
57! for the combined assimilation+forecast period t=t0 to t2. The !
58! basic state trajectory for this calculation will be that from !
59! the NLM run in step (2). !
60! !
61! (4) After running the regular adjoint sensitivity calculation in !
62! (3), we will have a full 3D-adjoint state vector at time t=t0. !
63! Let's call this vector x(0). The next thing we want to do is !
64! to compute the dot-product of x(0) with each of the Lanczos !
65! vectors from the previous I4D-Var run. So if we ran I4D-Var !
66! with k inner-loops we will have k Lanczos vectors which we !
67! denote as q_i where i=1,2,...,k. So we will compute a_i=x'q_i !
68! where x' is the transpose of the vector x(0), and a_i for !
69! i=1,2,...,k are scalars, so there will be k of them. !
70! !
71! (5) The next step is to invert the tridiagonal matrix associated !
72! with the Lanczos vectors. Let's denote this matrix as T. So !
73! what we want to solve T*b=a, where a is the k by 1 vector of !
74! scalars a_i from step (4), and b is the k by 1 vector that we !
75! want to find. So we solve for b by using a tridiagonal solver. !
76! !
77! (6) The next step is to compute a weighted sum of the Lanczos !
78! vectors. Let's call this z, where: !
79! !
80! z = SUM_i (b_i * q_i) and i=1,2,...,k !
81! !
82! The b_i are obtained from solving the tridiagonal equation in !
83! (5), and the q_i are the Lanczos vectors. The vector z is a !
84! full-state vector and be used as an initial condition for the !
85! TLM in step (8). !
86! !
87! (7) Finally, we run the TLM from t=t0 to t=t1 using z from (6) as !
88! the TLM initial condition. During this run of the TLM, we !
89! need to read and process the observations that we used in !
90! the I4D-Var of step (1) and write the TLM solution at the !
91! observation points and times to the DAV(ng)%name NetCDF file. !
92! The values that we write into this DAV(ng)%name are actually !
93! the TLM values multiplied by error variance assigned to each !
94! observation during the I4D-Var in step (1). !
95! !
96! These routines control the initialization, time-stepping, and !
97! finalization of ROMS model following ESMF conventions: !
98! !
99! ROMS_initialize !
100! ROMS_run !
101! ROMS_finalize !
102! !
103! References: !
104! !
105! Moore, A.M., H.G. Arango, G. Broquet, B.S. Powell, A.T. Weaver, !
106! and J. Zavala-Garay, 2011: The Regional Ocean Modeling System !
107! (ROMS) 4-dimensional variational data assimilations systems, !
108! Part I - System overview and formulation, Prog. Oceanogr., 91, !
109! 34-49, doi:10.1016/j.pocean.2011.05.004. !
110! !
111! Moore, A.M., H.G. Arango, G. Broquet, C. Edward, M. Veneziani, !
112! B. Powell, D. Foley, J.D. Doyle, D. Costa, and P. Robinson, !
113! 2011: The Regional Ocean Modeling System (ROMS) 4-dimensional !
114! variational data assimilations systems, Part II - Performance !
115! and application to the California Current System, Prog. !
116! Oceanogr., 91, 50-73, doi:10.1016/j.pocean.2011.05.003. !
117! !
118! Moore, A.M., H.G. Arango, G. Broquet, C. Edward, M. Veneziani, !
119! B. Powell, D. Foley, J.D. Doyle, D. Costa, and P. Robinson, !
120! 2011: The Regional Ocean Modeling System (ROMS) 4-dimensional !
121! variational data assimilations systems, Part III - Observation !
122! impact and observation sensitivity in the California Current !
123! System, Prog. Oceanogr., 91, 74-94, !
124! doi:10.1016/j.pocean.2011.05.005. !
125! !
126!=======================================================================
127!
128 USE mod_param
129 USE mod_parallel
130 USE mod_arrays
131 USE mod_fourdvar
132 USE mod_iounits
133 USE mod_ncparam
134 USE mod_netcdf
135#if defined PIO_LIB && defined DISTRIBUTE
137#endif
138 USE mod_scalars
139 USE mod_stepping
140!
141#ifdef ADJUST_BOUNDARY
143#endif
144#if defined OBS_IMPACT && defined OBS_IMPACT_SPLIT
145 USE mod_forces, ONLY : initialize_forces
146 USE mod_ocean, ONLY : initialize_ocean
147#endif
148!
149#ifdef BALANCE_OPERATOR
150 USE ad_balance_mod, ONLY : ad_balance
151#endif
154 USE close_io_mod, ONLY : close_inp, close_out
155 USE def_mod_mod, ONLY : def_mod
156 USE get_state_mod, ONLY : get_state
157 USE inp_par_mod, ONLY : inp_par
158#ifdef MCT_LIB
159# ifdef ATM_COUPLING
160 USE mct_coupler_mod, ONLY : initialize_ocn2atm_coupling
161# endif
162# ifdef WAV_COUPLING
163 USE mct_coupler_mod, ONLY : initialize_ocn2wav_coupling
164# endif
165#endif
168 USE strings_mod, ONLY : founderror
169#ifdef BALANCE_OPERATOR
170 USE tl_balance_mod, ONLY : tl_balance
171#endif
174 USE wrt_rst_mod, ONLY : wrt_rst
175#if defined BALANCE_OPERATOR && defined ZETA_ELLIPTIC
177#endif
178!
179 implicit none
180!
181 PUBLIC :: roms_initialize
182 PUBLIC :: roms_run
183 PUBLIC :: roms_finalize
184!
185 CONTAINS
186!
187 SUBROUTINE roms_initialize (first, mpiCOMM)
188!
189!=======================================================================
190! !
191! This routine allocates and initializes ROMS state variables !
192! and internal and external parameters. !
193! !
194!=======================================================================
195!
196! Imported variable declarations.
197!
198 logical, intent(inout) :: first
199!
200 integer, intent(in), optional :: mpiCOMM
201!
202! Local variable declarations.
203!
204 logical :: allocate_vars = .true.
205!
206#ifdef DISTRIBUTE
207 integer :: MyError, MySize
208#endif
209 integer :: NRMrec, STDrec, Tindex
210 integer :: chunk_size, ng, thread
211#ifdef _OPENMP
212 integer :: my_threadnum
213#endif
214!
215 character (len=*), parameter :: MyFile = &
216 & __FILE__//", ROMS_initialize"
217
218#ifdef DISTRIBUTE
219!
220!-----------------------------------------------------------------------
221! Set distribute-memory (mpi) world communictor.
222!-----------------------------------------------------------------------
223!
224 IF (PRESENT(mpicomm)) THEN
225 ocn_comm_world=mpicomm
226 ELSE
227 ocn_comm_world=mpi_comm_world
228 END IF
229 CALL mpi_comm_rank (ocn_comm_world, myrank, myerror)
230 CALL mpi_comm_size (ocn_comm_world, mysize, myerror)
231#endif
232!
233!-----------------------------------------------------------------------
234! On first pass, initialize model parameters a variables for all
235! nested/composed grids. Notice that the logical switch "first"
236! is used to allow multiple calls to this routine during ensemble
237! configurations.
238!-----------------------------------------------------------------------
239!
240 IF (first) THEN
241 first=.false.
242!
243! Initialize parallel control switches. These scalars switches are
244! independent from standard input parameters.
245!
247!
248! Set the ROMS standard output unit to write verbose execution info.
249! Notice that the default standard out unit in Fortran is 6.
250!
251! In some applications like coupling or disjointed mpi-communications,
252! it is advantageous to write standard output to a specific filename
253! instead of the default Fortran standard output unit 6. If that is
254! the case, it opens such formatted file for writing.
255!
256 IF (set_stdoutunit) THEN
258 set_stdoutunit=.false.
259 END IF
260!
261! Read in model tunable parameters from standard input. Allocate and
262! initialize variables in several modules after the number of nested
263! grids and dimension parameters are known.
264!
265 CALL inp_par (inlm)
266 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
267!
268! Set domain decomposition tile partition range. This range is
269! computed only once since the "first_tile" and "last_tile" values
270! are private for each parallel thread/node.
271!
272#if defined _OPENMP
273 mythread=my_threadnum()
274#elif defined DISTRIBUTE
276#else
277 mythread=0
278#endif
279 DO ng=1,ngrids
280 chunk_size=(ntilex(ng)*ntilee(ng)+numthreads-1)/numthreads
281 first_tile(ng)=mythread*chunk_size
282 last_tile(ng)=first_tile(ng)+chunk_size-1
283 END DO
284!
285! Initialize internal wall clocks. Notice that the timings does not
286! includes processing standard input because several parameters are
287! needed to allocate clock variables.
288!
289 IF (master) THEN
290 WRITE (stdout,10)
291 10 FORMAT (/,' Process Information:',/)
292 END IF
293!
294 DO ng=1,ngrids
295 DO thread=thread_range
296 CALL wclock_on (ng, inlm, 0, __line__, myfile)
297 END DO
298 END DO
299!
300! Allocate and initialize modules variables.
301!
302 CALL roms_allocate_arrays (allocate_vars)
304 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
305
306 END IF
307
308#if defined MCT_LIB && (defined ATM_COUPLING || defined WAV_COUPLING)
309!
310!-----------------------------------------------------------------------
311! Initialize coupling streams between model(s).
312!-----------------------------------------------------------------------
313!
314 DO ng=1,ngrids
315# ifdef ATM_COUPLING
316 CALL initialize_ocn2atm_coupling (ng, myrank)
317# endif
318# ifdef WAV_COUPLING
319 CALL initialize_ocn2wav_coupling (ng, myrank)
320# endif
321 END DO
322#endif
323!
324!-----------------------------------------------------------------------
325! Read in Lanczos algorithm coefficients (cg_beta, cg_delta) from
326! file LCZ(ng)%name NetCDF (I4D-Var adjoint file), as computed in the
327! I4D-Var Lanczos data assimilation algorithm for the first outer
328! loop. They are needed here, in routine "ini_lanczos", to compute
329! the tangent linear model initial conditions as the weighted sum
330! of the Lanczos vectors. The weighting coefficient are computed
331! by solving a tri-diagonal system that uses cg_beta and cg_gamma.
332!-----------------------------------------------------------------------
333!
334 sourcefile=myfile
335 DO ng=1,ngrids
336 SELECT CASE (lcz(ng)%IOtype)
337 CASE (io_nf90)
338 CALL netcdf_get_fvar (ng, iadm, lcz(ng)%name, &
339 & 'cg_beta', cg_beta)
340 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
341
342 CALL netcdf_get_fvar (ng, iadm, lcz(ng)%name, &
343 & 'cg_delta', cg_delta)
344 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
345
346#if defined PIO_LIB && defined DISTRIBUTE
347 CASE (io_pio)
348 CALL pio_netcdf_get_fvar (ng, iadm, lcz(ng)%name, &
349 & 'cg_beta', cg_beta)
350 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
351
352 CALL pio_netcdf_get_fvar (ng, iadm, lcz(ng)%name, &
353 & 'cg_delta', cg_delta)
354 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
355#endif
356 END SELECT
357 END DO
358
359#ifdef SKIP_NLM
360!
361!-----------------------------------------------------------------------
362! If skiping runing nonlinear model, read in observation screening and
363! quality control flag.
364!-----------------------------------------------------------------------
365!
366 wrtobsscale(1:ngrids)=.false.
367 DO ng=1,ngrids
368 SELECT CASE (lcz(ng)%IOtype)
369 CASE (io_nf90)
370 CALL netcdf_get_fvar (ng, itlm, lcz(ng)%name, &
371 & vname(1,idobss), obsscale)
372 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
373
374# if defined PIO_LIB && defined DISTRIBUTE
375 CASE (io_pio)
376 CALL netcdf_get_fvar (ng, itlm, lcz(ng)%name, &
377 & vname(1,idobss), obsscale)
378 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
379# endif
380 END SELECT
381 END DO
382#endif
383!
384!-----------------------------------------------------------------------
385! Read in standard deviation factors for error covariance.
386!-----------------------------------------------------------------------
387!
388! Initial conditions standard deviation. They are loaded in Tindex=1
389! of the e_var(...,Tindex) state variables.
390!
391 stdrec=1
392 tindex=1
393 DO ng=1,ngrids
394 CALL get_state (ng, 10, 10, std(1,ng), stdrec, tindex)
395 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
396 END DO
397
398#ifdef ADJUST_BOUNDARY
399!
400! Open boundary conditions standard deviation.
401!
402 stdrec=1
403 tindex=1
404 DO ng=1,ngrids
405 CALL get_state (ng, 12, 12, std(3,ng), stdrec, tindex)
406 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
407 END DO
408#endif
409#if defined ADJUST_WSTRESS || defined ADJUST_STFLUX
410!
411! Surface forcing standard deviation.
412!
413 stdrec=1
414 tindex=1
415 DO ng=1,ngrids
416 CALL get_state (ng, 13, 13, std(4,ng), stdrec, tindex)
417 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
418 END DO
419#endif
420!
421!-----------------------------------------------------------------------
422! Read in initial conditions, boundary conditions, and surface
423! forcing error covariance covariance normalization factors.
424!-----------------------------------------------------------------------
425!
426 nrmrec=1
427 DO ng=1,ngrids
428 CALL get_state (ng, 14, 14, nrm(1,ng), nrmrec, 1)
429 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
430
431#ifdef ADJUST_BOUNDARY
432 CALL get_state (ng, 16, 16, nrm(3,ng), nrmrec, 1)
433 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
434#endif
435#if defined ADJUST_WSTRESS || defined ADJUST_STFLUX
436 CALL get_state (ng, 17, 17, nrm(4,ng), nrmrec, 1)
437 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
438#endif
439 END DO
440!
441 RETURN
442 END SUBROUTINE roms_initialize
443!
444 SUBROUTINE roms_run (RunInterval)
445!
446!=======================================================================
447! !
448! This routine computes the adjoint sensitivity analysis, dJ/dS, !
449! to the specified functional J. The sensitivity masking arrays !
450! Rscope, Uscope, and Vscope are used to evaluate the functional !
451! in the desired spatial area. !
452! !
453!=======================================================================
454!
455! Imported variable declarations
456!
457 real(dp), intent(in) :: RunInterval ! seconds
458!
459! Local variable declarations.
460!
461 logical :: Ladjoint, Lweak
462!
463 integer :: i, lstr, ng, tile
464 integer :: Fcount, Lbck, Lini, Litl, Rec
465!
466 real (r8) :: str_day, end_day
467!
468 character (len=*), parameter :: MyFile = &
469 & __FILE__//", ROMS_run"
470!
471!=======================================================================
472! Run model for all nested grids, if any.
473!=======================================================================
474!
475! Initialize relevant parameters.
476!
477 lini=1 ! 4DVAR initial conditions record in INI
478 lbck=2 ! First guess initial conditions record in INI
479 litl=1 ! TLM initial conditions record
480 lweak=.false.
481 DO ng=1,ngrids
482#if defined ADJUST_BOUNDARY || defined ADJUST_STFLUX || \
483 defined adjust_wstress
484 lfinp(ng)=1 ! forcing index for input
485 lfout(ng)=1 ! forcing index for output history files
486#endif
487#ifdef ADJUST_BOUNDARY
488 lbinp(ng)=1 ! boundary index for input
489 lbout(ng)=1 ! boundary index for output history files
490#endif
491 lnew(ng)=1
492 END DO
493!
494! Initialize nonlinear model with the estimated initial conditions
495! from the I4D-Var Lanczos algorithm. Notice that the LreadBLK and
496! LreadFWD switches are turned off to suppress processing of the
497! structures when "check_multifile" during
498! nonlinear model execution.
499!
500 DO ng=1,ngrids
501#ifdef FORWARD_FLUXES
502 lreadblk(ng)=.false.
503#endif
504 lreadfwd(ng)=.false.
505 wrtnlmod(ng)=.false.
506 wrttlmod(ng)=.false.
507 rst(ng)%Rindex=0
508 fcount=rst(ng)%load
509 rst(ng)%Nrec(fcount)=0
510 END DO
511!
512 CALL initial
513 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
514
515#if defined BALANCE_OPERATOR && defined ZETA_ELLIPTIC
516!
517! Compute the reference zeta and biconjugate gradient arrays
518! required for the balance of free surface.
519!
520 IF (balance(isfsur)) THEN
521 DO ng=1,ngrids
522 DO tile=first_tile(ng),last_tile(ng),+1
523 CALL balance_ref (ng, tile, lini)
524 CALL biconj (ng, tile, inlm, lini)
525 END DO
526 wrtzetaref(ng)=.true.
527 END DO
528 END IF
529#endif
530#ifndef SKIP_NLM
531!
532! Run nonlinear model for the combined assimilation plus forecast
533! period, t=t0 to t2. Save nonlinear (basic state) tracjectory, xb(t),
534! needed by the adjoint model.
535!
536 DO ng=1,ngrids
537 IF (master) THEN
538 WRITE (stdout,10) 'NL', ng, ntstart(ng), ntend(ng)
539 END IF
540 END DO
541!
542# ifdef SOLVE3D
543 CALL main3d (runinterval)
544# else
545 CALL main2d (runinterval)
546# endif
547 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
548#endif
549!
550! Set structure for the nonlinear forward trajectory to be processed
551! by the tangent linear and adjoint models. Also, set switches to
552! process the FWD structure in routine "check_multifile". Notice that
553! it is possible to split solution into multiple NetCDF files to reduce
554! their size.
555!
556 CALL edit_multifile ('HIS2FWD')
557 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
558 DO ng=1,ngrids
559 lreadfwd(ng)=.true.
560 END DO
561
562#ifdef FORWARD_FLUXES
563!
564! Set the BLK structure to contain the nonlinear model surface fluxes
565! needed by the tangent linear and adjoint models. Also, set switches
566! to process that structure in routine "check_multifile". Notice that
567! it is possible to split the solution into multiple NetCDF files to
568! reduce their size.
569!
570! The switch LreadFRC is deactivated because all the atmospheric
571! forcing, including shortwave radiation, is read from the NLM
572! surface fluxes or is assigned during ESM coupling. Such fluxes
573! are available from the QCK structure. There is no need for reading
574! and processing from the FRC structure input forcing-files.
575!
576 CALL edit_multifile ('QCK2BLK')
577 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
578 DO ng=1,ngrids
579 lreadblk(ng)=.true.
580 lreadfrc(ng)=.false.
581 lreadqck(ng)=.false.
582 END DO
583#endif
584!
585! Initialize adjoint model and define sensitivity functional.
586!
587 lstiffness=.false.
588 DO ng=1,ngrids
589 CALL ad_initial (ng)
590 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
591 END DO
592!
593! Activate adjoint output.
594!
595 DO ng=1,ngrids
596 ldefadj(ng)=.true.
597 lwrtadj(ng)=.true.
598 lcycleadj(ng)=.false.
599 END DO
600!
601! Time-step adjoint model for the combined plus forecast period,
602! t=t2 to t0. Compute the gradient or index, dJ/dS, of the
603! sensitivity functional.
604!
605 DO ng=1,ngrids
606 str_day=tdays(ng)
607 end_day=str_day-ntimes(ng)*dt(ng)*sec2day
608 IF ((dstrs(ng).eq.0.0_r8).and.(dends(ng).eq.0.0_r8)) THEN
609 dstrs(ng)=end_day
610 dends(ng)=str_day
611 END IF
612 IF (master) THEN
613 WRITE (stdout,20) 'AD', ntstart(ng), ntend(ng), &
614 & dends(ng), dstrs(ng)
615 END IF
616#ifndef OBS_IMPACT
617 IF ((dstrs(ng).gt.str_day).or.(dstrs(ng).lt.end_day)) THEN
618 IF (master) WRITE (stdout,30) 'DstrS = ', dstrs(ng), &
619 & end_day, str_day
620 exit_flag=7
621 RETURN
622 END IF
623 IF ((dends(ng).gt.str_day).or.(dends(ng).lt.end_day)) THEN
624 IF (master) WRITE (stdout,30) 'DendS = ', dends(ng), &
625 & end_day, str_day
626 exit_flag=7
627 RETURN
628 END IF
629#endif
630 END DO
631!
632! If DstrS=DendS=dstart, skip the adjoint model and read adjoint solution
633! from ADS netcdf file, record 1.
634!
635 ladjoint=.true.
636 DO ng=1,ngrids
637 IF ((dstrs(ng).eq.dends(ng)).and.(dstrs(ng).eq.dstart)) THEN
638 rec=1
639 CALL get_state (ng, iadm, 4, ads(ng), rec, lnew(ng))
640 ladjoint=.false.
641 END IF
642 END DO
643
644 IF (ladjoint) THEN
645 DO ng=1,ngrids
646 IF (master) THEN
647 WRITE (stdout,10) 'AD', ng, ntstart(ng), ntend(ng)
648 END IF
649 END DO
650!
651#ifdef SOLVE3D
652 CALL ad_main3d (runinterval)
653#else
654 CALL ad_main2d (runinterval)
655#endif
656 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
657 END IF
658!
659! Load full adjoint sensitivity vector, x(0), for t=t0 into adjoint
660! state arrays at index Lnew.
661!
662 IF (ladjoint) THEN
663 DO ng=1,ngrids
664 CALL get_state (ng, iadm, 4, adm(ng), adm(ng)%Rindex, &
665 & lnew(ng))
666 END DO
667 END IF
668
669#ifdef BALANCE_OPERATOR
670!
671! Read in NLM reference state in readiness for the balance operator.
672!
673 DO ng=1,ngrids
674 CALL get_state (ng, inlm, 2, ini(ng), lini, lini)
675 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
676 nrhs(ng)=lini
677 END DO
678#endif
679!
680! Convert adjoint solution to v-space since the Lanczos vectors
681! are in v-space.
682!
683 DO ng=1,ngrids
684 DO tile=first_tile(ng),last_tile(ng),+1
685#ifdef BALANCE_OPERATOR
686 CALL ad_balance (ng, tile, lini, lnew(ng))
687#endif
688 CALL ad_variability (ng, tile, lnew(ng), lweak)
689 CALL ad_convolution (ng, tile, lnew(ng), lweak, 2)
690 END DO
691 END DO
692!
693! Check Lanczos vector input file and determine t=t1. That is, the
694! time to run the tangent linear model. This time must be the same
695! as the I4D-Var Lanczos algorithm.
696!
697 sourcefile=myfile
698 DO ng=1,ngrids
699 SELECT CASE (lcz(ng)%IOtype)
700 CASE (io_nf90)
701 CALL netcdf_get_ivar (ng, iadm, lcz(ng)%name, &
702 & 'ntimes', ntimes(ng))
703 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
704
705#if defined PIO_LIB && defined DISTRIBUTE
706 CASE (io_pio)
707 CALL pio_netcdf_get_ivar (ng, iadm, lcz(ng)%name, &
708 & 'ntimes', ntimes(ng))
709 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
710#endif
711 END SELECT
712 END DO
713
714#ifndef OBS_IMPACT
715!
716! Initialize nonlinear model with the same initial conditions, xb(0),
717! Lbck record in INI(ng)%name. This is the first guess NLM initial
718! conditions used to start the I4D-Var Lanczos algorithm. Notice that
719! the LreadBLK and LreadFWD switches are turned off to suppress
720! processing of the structures when "check_multifile" during
721! nonlinear model execution.
722!
723 DO ng=1,ngrids
724 ldefini(ng)=.false.
725# ifdef FORWARD_FLUXES
726 lreadblk(ng)=.false.
727# endif
728 lreadfwd(ng)=.false.
729 wrtnlmod(ng)=.false.
730 wrttlmod(ng)=.false.
731 rst(ng)%Rindex=0
732 ini(ng)%Rindex=lbck
733 fcount=rst(ng)%load
734 rst(ng)%Nrec(fcount)=0
735 END DO
736!
737 CALL initial
738 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
739!
740! Run nonlinear model for the combined assimilation plus forecast
741! period, t=t0 to t2. Save nonlinear (basic state) tracjectory, xb(t),
742! needed by the tangent linear model.
743!
744 DO ng=1,ngrids
745 IF (master) THEN
746 WRITE (stdout,10) 'NL', ng, ntstart(ng), ntend(ng)
747 END IF
748 END DO
749!
750# ifdef SOLVE3D
751 CALL main3d (runinterval)
752# else
753 CALL main2d (runinterval)
754# endif
755 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
756!
757! Set structure for the nonlinear forward trajectory to be processed
758! by the tangent linear and adjoint models. Also, set switches to
759! process the FWD structure in routine "check_multifile". Notice that
760! it is possible to split solution into multiple NetCDF files to reduce
761! their size.
762!
763 CALL edit_multifile ('HIS2FWD')
764 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
765 DO ng=1,ngrids
766 lreadfwd(ng)=.true.
767 END DO
768
769# ifdef FORWARD_FLUXES
770!
771! Set the BLK structure to contain the nonlinear model surface fluxes
772! needed by the tangent linear and adjoint models. Also, set switches
773! to process that structure in routine "check_multifile". Notice that
774! it is possible to split the solution into multiple NetCDF files to
775! reduce their size.
776!
777 CALL edit_multifile ('QCK2BLK')
778 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
779 DO ng=1,ngrids
780 lreadblk(ng)=.true.
781 END DO
782# endif
783#endif
784!
785! Initialize tangent linear model with the weighted sum of the
786! Lanczos vectors, steps (4) to (6) from the algorithm summary
787! above.
788!
789 DO ng=1,ngrids
790 CALL tl_initial (ng)
791 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
792 ldeftlm(ng)=.true.
793 lwrttlm(ng)=.true.
794 wrttlmod(ng)=.true.
795 END DO
796!
797! Convert TL initial condition from v-space to x-space.
798!
799 DO ng=1,ngrids
800 DO tile=first_tile(ng),last_tile(ng),+1
801 CALL tl_convolution (ng, tile, litl, lweak, 2)
802 CALL tl_variability (ng, tile, litl, lweak)
803#ifdef BALANCE_OPERATOR
804 CALL tl_balance (ng, tile, lini, litl)
805#endif
806 END DO
807 END DO
808!
809! Define output 4DVAR NetCDF file containing the sensitivity at the
810! observation locations.
811!
812 DO ng=1,ngrids
813 ldefmod(ng)=.true.
814 CALL def_mod (ng)
815 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
816 wrtimpact_tot(ng)=.true.
817#ifdef OBS_IMPACT_SPLIT
818 wrtimpact_ic(ng)=.false.
819#endif
820 END DO
821!
822! Write out outer loop beeing processed.
823!
824 sourcefile=myfile
825 DO ng=1,ngrids
826 SELECT CASE (dav(ng)%IOtype)
827 CASE (io_nf90)
828 CALL netcdf_put_ivar (ng, inlm, dav(ng)%name, &
829 & 'Nimpact', nimpact, &
830 & (/0/), (/0/), &
831 & ncid = dav(ng)%ncid)
832 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
833
834#if defined PIO_LIB && defined DISTRIBUTE
835 CASE (io_pio)
836 CALL pio_netcdf_put_ivar (ng, inlm, dav(ng)%name, &
837 & 'Nimpact', nimpact, &
838 & (/0/), (/0/), &
839 & piofile = dav(ng)%pioFile)
840 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
841#endif
842 END SELECT
843 END DO
844!
845! Run tangent linear model for the assimilation period, t=t0 to t1.
846! Read and process the 4DVAR observations.
847!
848 DO ng=1,ngrids
849 IF (master) THEN
850 WRITE (stdout,10) 'TL', ng, ntstart(ng), ntend(ng)
851 END IF
852 END DO
853!
854#ifdef SOLVE3D
855 CALL tl_main3d (runinterval)
856#else
857 CALL tl_main2d (runinterval)
858#endif
859 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
860
861#if defined OBS_IMPACT && defined OBS_IMPACT_SPLIT
862!
863!:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
864! Integrate tangent linear model with initial condition increments
865! only to compute the observation impact associated with the initial
866! conditions.
867!:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
868!
869! Load full adjoint sensitivity vector, x(0), for t=t0 into adjoint
870! state arrays at index Lnew.
871!
872 DO ng=1,ngrids
873 CALL get_state (ng, iadm, 4, adm(ng), adm(ng)%Rindex, lnew(ng))
874 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
875 END DO
876
877# ifdef BALANCE_OPERATOR
878!
879! Read in NLM reference state in readiness for the balance operator.
880!
881 DO ng=1,ngrids
882 CALL get_state (ng, inlm, 2, ini(ng), lini, lini)
883 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
884 nrhs(ng)=lini
885 END DO
886# endif
887!
888! Clear the adjoint forcing and boundary condition increment arrays.
889!
890 DO ng=1,ngrids
891 DO tile=first_tile(ng),last_tile(ng),+1
892 CALL initialize_forces (ng, tile, iadm)
893# ifdef ADJUST_BOUNDARY
894 CALL initialize_boundary (ng, tile, iadm)
895# endif
896 END DO
897 END DO
898!
899! Convert adjoint solution to v-space since the Lanczos vectors
900! are in v-space.
901!
902 DO ng=1,ngrids
903 DO tile=first_tile(ng),last_tile(ng),+1
904# ifdef BALANCE_OPERATOR
905 CALL ad_balance (ng, tile, lini, lnew(ng))
906# endif
907 CALL ad_variability (ng, tile, lnew(ng), lweak)
908 CALL ad_convolution (ng, tile, lnew(ng), lweak, 2)
909 END DO
910 END DO
911!
912! Check Lanczos vector input file and determine t=t1. That is, the
913! time to run the tangent linear model. This time must be the same
914! as the I4D-Var Lanczos algorithm.
915!
916 sourcefile=myfile
917 DO ng=1,ngrids
918 SELECT CASE (lcz(ng)%IOtype)
919 CASE (io_nf90)
920 CALL netcdf_get_ivar (ng, iadm, lcz(ng)%name, &
921 & 'ntimes', ntimes(ng))
922 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
923
924# if defined PIO_LIB && defined DISTRIBUTE
925 CASE (io_pio)
926 CALL pio_netcdf_get_ivar (ng, iadm, lcz(ng)%name, &
927 & 'ntimes', ntimes(ng))
928 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
929# endif
930 END SELECT
931 END DO
932!
933! Initialize tangent linear model with the weighted sum of the
934! Lanczos vectors, steps (4) to (6) from the algorithm summary
935! above.
936!
937 DO ng=1,ngrids
938 CALL tl_initial (ng)
939 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
940 ldeftlm(ng)=.true.
941 lwrttlm(ng)=.true.
942 wrttlmod(ng)=.true.
943 wrtimpact_tot(ng)=.false.
944 wrtimpact_ic(ng)=.true.
945# if defined ADJUST_WSTRESS || defined ADJUST_STFLUX
946 wrtimpact_fc(ng)=.false.
947# endif
948# if defined ADJUST_BOUNDARY
949 wrtimpact_bc(ng)=.false.
950# endif
951 END DO
952!
953! Convert TL initial condition from v-space to x-space.
954!
955 DO ng=1,ngrids
956 DO tile=first_tile(ng),last_tile(ng),+1
957 CALL tl_convolution (ng, tile, litl, lweak, 2)
958 CALL tl_variability (ng, tile, litl, lweak)
959# ifdef BALANCE_OPERATOR
960 CALL tl_balance (ng, tile, lini, litl)
961# endif
962 END DO
963 END DO
964!
965! Run tangent linear model for the assimilation period, t=t0 to t1.
966! Read and process the 4DVAR observations.
967!
968 DO ng=1,ngrids
969 IF (master) THEN
970 WRITE (stdout,10) 'TL', ng, ntstart(ng), ntend(ng)
971 END IF
972 END DO
973!
974# ifdef SOLVE3D
975 CALL tl_main3d (runinterval)
976# else
977 CALL tl_main2d (runinterval)
978# endif
979 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
980
981# if defined ADJUST_WSTRESS || defined ADJUST_STFLUX
982!
983!:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
984! Integrate tangent linear model with surface forcing increments only
985! to compute the observation impact associated with the surface forcing.
986!:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
987!
988! Load full adjoint sensitivity vector, x(0), for t=t0 into adjoint
989! state arrays at index Lnew.
990!
991 DO ng=1,ngrids
992 CALL get_state (ng, iadm, 4, adm(ng), adm(ng)%Rindex, lnew(ng))
993 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
994 END DO
995
996# ifdef BALANCE_OPERATOR
997!
998! Read in NLM reference state in readiness for the balance operator.
999!
1000 DO ng=1,ngrids
1001 CALL get_state (ng, inlm, 2, ini(ng), lini, lini)
1002 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1003 nrhs(ng)=lini
1004 END DO
1005# endif
1006!
1007! Clear the adjoint initial condition and boundary condition increment
1008! arrays.
1009!
1010 DO ng=1,ngrids
1011 DO tile=first_tile(ng),last_tile(ng),+1
1012 CALL initialize_ocean (ng, tile, iadm)
1013# ifdef ADJUST_BOUNDARY
1014 CALL initialize_boundary (ng, tile, iadm)
1015# endif
1016 END DO
1017 END DO
1018!
1019! Convert adjoint solution to v-space since the Lanczos vectors
1020! are in v-space.
1021!
1022 DO ng=1,ngrids
1023 DO tile=first_tile(ng),last_tile(ng),+1
1024# ifdef BALANCE_OPERATOR
1025 CALL ad_balance (ng, tile, lini, lnew(ng))
1026# endif
1027 CALL ad_variability (ng, tile, lnew(ng), lweak)
1028 CALL ad_convolution (ng, tile, lnew(ng), lweak, 2)
1029 END DO
1030 END DO
1031!
1032! Check Lanczos vector input file and determine t=t1. That is, the
1033! time to run the tangent linear model. This time must be the same
1034! as the I4D-Var Lanczos algorithm.
1035!
1036 sourcefile=myfile
1037 DO ng=1,ngrids
1038 SELECT CASE (lcz(ng)%IOtype)
1039 CASE (io_nf90)
1040 CALL netcdf_get_ivar (ng, iadm, lcz(ng)%name, &
1041 & 'ntimes', ntimes(ng))
1042 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1043
1044# if defined PIO_LIB && defined DISTRIBUTE
1045 CASE (io_pio)
1046 CALL pio_netcdf_get_ivar (ng, iadm, lcz(ng)%name, &
1047 & 'ntimes', ntimes(ng))
1048 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1049# endif
1050 END SELECT
1051 END DO
1052!
1053! Initialize tangent linear model with the weighted sum of the
1054! Lanczos vectors, steps (4) to (6) from the algorithm summary
1055! above.
1056!
1057 DO ng=1,ngrids
1058 CALL tl_initial (ng)
1059 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1060 ldeftlm(ng)=.true.
1061 lwrttlm(ng)=.true.
1062 wrttlmod(ng)=.true.
1063 wrtimpact_tot(ng)=.false.
1064 wrtimpact_ic(ng)=.false.
1065 wrtimpact_fc(ng)=.true.
1066# if defined ADJUST_BOUNDARY
1067 wrtimpact_bc(ng)=.false.
1068# endif
1069 END DO
1070!
1071! Convert TL initial condition from v-space to x-space.
1072!
1073 DO ng=1,ngrids
1074 DO tile=first_tile(ng),last_tile(ng),+1
1075 CALL tl_convolution (ng, tile, litl, lweak, 2)
1076 CALL tl_variability (ng, tile, litl, lweak)
1077# ifdef BALANCE_OPERATOR
1078 CALL tl_balance (ng, tile, lini, litl)
1079# endif
1080 END DO
1081 END DO
1082!
1083! Run tangent linear model for the assimilation period, t=t0 to t1.
1084! Read and process the 4DVAR observations.
1085!
1086 DO ng=1,ngrids
1087 IF (master) THEN
1088 WRITE (stdout,10) 'TL', ng, ntstart(ng), ntend(ng)
1089 END IF
1090 END DO
1091!
1092# ifdef SOLVE3D
1093 CALL tl_main3d (runinterval)
1094# else
1095 CALL tl_main2d (runinterval)
1096# endif
1097 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1098# endif
1099
1100# if defined ADJUST_BOUNDARY
1101!
1102!:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1103! Integrate tangent linear model with boundary increments only
1104! to compute the observation impact associated with the boundaries.
1105!:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1106!
1107! Load full adjoint sensitivity vector, x(0), for t=t0 into adjoint
1108! state arrays at index Lnew.
1109!
1110 DO ng=1,ngrids
1111 CALL get_state (ng, iadm, 4, adm(ng), adm(ng)%Rindex, lnew(ng))
1112 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1113 END DO
1114
1115# ifdef BALANCE_OPERATOR
1116!
1117! Read in NLM reference state in readiness for the balance operator.
1118!
1119 DO ng=1,ngrids
1120 CALL get_state (ng, inlm, 2, ini(ng), lini, lini)
1121 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1122 nrhs(ng)=lini
1123 END DO
1124# endif
1125!
1126! Clear the adjoint increment initial condition and forcing arrays.
1127!
1128 DO ng=1,ngrids
1129 DO tile=first_tile(ng),last_tile(ng),+1
1130 CALL initialize_ocean (ng, tile, iadm)
1131 CALL initialize_forces (ng, tile, iadm)
1132 END DO
1133 END DO
1134!
1135! Convert adjoint solution to v-space since the Lanczos vectors
1136! are in v-space.
1137!
1138 DO ng=1,ngrids
1139 DO tile=first_tile(ng),last_tile(ng),+1
1140# ifdef BALANCE_OPERATOR
1141 CALL ad_balance (ng, tile, lini, lnew(ng))
1142# endif
1143 CALL ad_variability (ng, tile, lnew(ng), lweak)
1144 CALL ad_convolution (ng, tile, lnew(ng), lweak, 2)
1145 END DO
1146 END DO
1147!
1148! Check Lanczos vector input file and determine t=t1. That is, the
1149! time to run the tangent linear model. This time must be the same
1150! as the I4D-Var Lanczos algorithm.
1151!
1152 sourcefile=myfile
1153 DO ng=1,ngrids
1154 SELECT CASE (lcz(ng)%IOtype)
1155 CASE (io_nf90)
1156 CALL netcdf_get_ivar (ng, iadm, lcz(ng)%name, &
1157 & 'ntimes', ntimes(ng))
1158 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1159
1160# if defined PIO_LIB && defined DISTRIBUTE
1161 CASE (io_pio)
1162 CALL pio_netcdf_get_ivar (ng, iadm, lcz(ng)%name, &
1163 & 'ntimes', ntimes(ng))
1164 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1165# endif
1166 END SELECT
1167 END DO
1168!
1169! Initialize tangent linear model with the weighted sum of the
1170! Lanczos vectors, steps (4) to (6) from the algorithm summary
1171! above.
1172!
1173 DO ng=1,ngrids
1174 CALL tl_initial (ng)
1175 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1176
1177 ldeftlm(ng)=.true.
1178 lwrttlm(ng)=.true.
1179 wrttlmod(ng)=.true.
1180 wrtimpact_tot(ng)=.false.
1181 wrtimpact_ic(ng)=.false.
1182# if defined ADJUST_WSTRESS || defined ADJUST_STFLUX
1183 wrtimpact_fc(ng)=.false.
1184# endif
1185 wrtimpact_bc(ng)=.true.
1186 END DO
1187!
1188! Convert TL initial condition from v-space to x-space.
1189!
1190 DO ng=1,ngrids
1191 DO tile=first_tile(ng),last_tile(ng),+1
1192 CALL tl_convolution (ng, tile, litl, lweak, 2)
1193 CALL tl_variability (ng, tile, litl, lweak)
1194# ifdef BALANCE_OPERATOR
1195 CALL tl_balance (ng, tile, lini, litl)
1196# endif
1197 END DO
1198 END DO
1199!
1200! Run tangent linear model for the assimilation period, t=t0 to t1.
1201! Read and process the 4DVAR observations.
1202!
1203 DO ng=1,ngrids
1204 IF (master) THEN
1205 WRITE (stdout,10) 'TL', ng, ntstart(ng), ntend(ng)
1206 END IF
1207 END DO
1208!
1209# ifdef SOLVE3D
1210 CALL tl_main3d (runinterval)
1211# else
1212 CALL tl_main2d (runinterval)
1213# endif
1214 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
1215# endif
1216
1217#endif
1218!
1219 10 FORMAT (/,1x,a,1x,'ROMS: started time-stepping:', &
1220 & ' (Grid: ',i2.2,' TimeSteps: ',i8.8,' - ',i8.8,')',/)
1221 20 FORMAT (/,1x,a,1x,'ROMS: started time-stepping:', &
1222 & '( TimeSteps: ',i8.8,' - ',i8.8,')',/,15x, &
1223 & 'adjoint forcing time range: ',f12.4,' - ',f12.4 ,/)
1224 30 FORMAT (/,' Out of range adjoint forcing time, ',a,f12.4,/, &
1225 & ' It must be between ',f12.4,' and ',f12.4)
1226!
1227 RETURN
1228 END SUBROUTINE roms_run
1229!
1230 SUBROUTINE roms_finalize
1231!
1232!=======================================================================
1233! !
1234! This routine terminates ROMS nonlinear and adjoint models !
1235! execution. !
1236! !
1237!=======================================================================
1238!
1239! Local variable declarations.
1240!
1241 integer :: Fcount, ng, thread
1242!
1243 character (len=*), parameter :: MyFile = &
1244 & __FILE__//", ROMS_finalize"
1245!
1246!-----------------------------------------------------------------------
1247! Read and write observation variables for completeness.
1248!-----------------------------------------------------------------------
1249!
1250 DO ng=1,ngrids
1251#ifdef DISTRIBUTE
1252 CALL stats_modobs (ng, myrank)
1253#else
1254 CALL stats_modobs (ng, -1)
1255#endif
1256 END DO
1257!
1258!-----------------------------------------------------------------------
1259! If blowing-up, save latest model state into RESTART NetCDF file.
1260!-----------------------------------------------------------------------
1261!
1262! If cycling restart records, write solution into the next record.
1263!
1264 IF (exit_flag.eq.1) THEN
1265 DO ng=1,ngrids
1266 IF (lwrtrst(ng)) THEN
1267 IF (master) WRITE (stdout,10)
1268 10 FORMAT (/,' Blowing-up: Saving latest model state into ', &
1269 & ' RESTART file',/)
1270 fcount=rst(ng)%load
1271 IF (lcyclerst(ng).and.(rst(ng)%Nrec(fcount).ge.2)) THEN
1272 rst(ng)%Rindex=2
1273 lcyclerst(ng)=.false.
1274 END IF
1277#ifdef DISTRIBUTE
1278 CALL wrt_rst (ng, myrank)
1279#else
1280 CALL wrt_rst (ng, -1)
1281#endif
1282 END IF
1283 END DO
1284 END IF
1285!
1286!-----------------------------------------------------------------------
1287! Stop model and time profiling clocks, report memory requirements, and
1288! close output NetCDF files.
1289!-----------------------------------------------------------------------
1290!
1291! Stop time clocks.
1292!
1293 IF (master) THEN
1294 WRITE (stdout,20)
1295 20 FORMAT (/,'Elapsed wall CPU time for each process (seconds):',/)
1296 END IF
1297!
1298 DO ng=1,ngrids
1299 DO thread=thread_range
1300 CALL wclock_off (ng, inlm, 0, __line__, myfile)
1301 END DO
1302 END DO
1303!
1304! Report dynamic memory and automatic memory requirements.
1305!
1306 CALL memory
1307!
1308! Close IO files.
1309!
1310 DO ng=1,ngrids
1311 CALL close_inp (ng, inlm)
1312 END DO
1313 CALL close_out
1314!
1315 RETURN
1316 END SUBROUTINE roms_finalize
1317
1318 END MODULE roms_kernel_mod
subroutine ad_initial(ng)
Definition ad_initial.F:4
subroutine ad_main2d
Definition ad_main2d.F:586
subroutine ad_main3d(runinterval)
Definition ad_main3d.F:4
subroutine edit_multifile(task)
subroutine initial
Definition initial.F:3
subroutine main2d
Definition main2d.F:746
subroutine main3d(runinterval)
Definition main3d.F:4
subroutine memory
Definition memory.F:3
subroutine, public ad_balance(ng, tile, lbck, linp)
Definition ad_balance.F:59
subroutine, public ad_convolution(ng, tile, linp, lweak, ifac)
subroutine, public ad_variability(ng, tile, linp, lweak)
subroutine, public close_out
Definition close_io.F:175
subroutine, public close_inp(ng, model)
Definition close_io.F:92
subroutine, public def_mod(ng)
Definition def_mod.F:49
subroutine, public get_state(ng, model, msg, s, inirec, tindex)
Definition get_state.F:90
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
subroutine, public initialize_boundary(ng, tile, model)
subroutine, public initialize_forces(ng, tile, model)
real(dp), dimension(:,:), allocatable cg_beta
logical, dimension(:), allocatable wrtimpact_bc
logical, dimension(:), allocatable wrtimpact_fc
logical, dimension(:), allocatable wrtimpact_ic
logical, dimension(:), allocatable wrttlmod
logical, dimension(:), allocatable wrtnlmod
real(r8), dimension(:), allocatable obsscale
logical, dimension(:), allocatable wrtimpact_tot
integer nimpact
logical, dimension(:), allocatable wrtobsscale
real(dp), dimension(:,:), allocatable cg_delta
logical, dimension(:), allocatable wrtzetaref
type(t_io), dimension(:), allocatable ads
type(t_io), dimension(:), allocatable lcz
type(t_io), dimension(:,:), allocatable std
type(t_io), dimension(:,:), allocatable nrm
type(t_io), dimension(:), allocatable adm
type(t_io), dimension(:), allocatable dav
type(t_io), dimension(:), allocatable rst
type(t_io), dimension(:), allocatable ini
integer stdout
character(len=256) sourcefile
integer idobss
integer, parameter io_nf90
Definition mod_ncparam.F:95
integer, parameter io_pio
Definition mod_ncparam.F:96
integer isfsur
character(len=maxlen), dimension(6, 0:nv) vname
subroutine, public initialize_ocean(ng, tile, model)
Definition mod_ocean.F:1526
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 ntilex
Definition mod_param.F:685
integer, parameter iadm
Definition mod_param.F:665
integer ngrids
Definition mod_param.F:113
integer, dimension(:), allocatable ntilee
Definition mod_param.F:686
integer, parameter itlm
Definition mod_param.F:663
logical, dimension(:), allocatable lreadqck
integer, dimension(:), allocatable ntimes
real(dp), dimension(:), allocatable dt
logical lstiffness
integer blowup
logical, dimension(:), allocatable balance
logical, dimension(:), allocatable lreadfrc
logical, dimension(:), allocatable ldefini
real(dp), dimension(:), allocatable tdays
real(r8), dimension(:), allocatable dends
logical, dimension(:), allocatable ldefadj
real(dp) dstart
logical, dimension(:), allocatable lcycleadj
logical, dimension(:), allocatable lwrtadj
real(dp), parameter sec2day
integer, dimension(:), allocatable ntend
logical, dimension(:), allocatable ldefmod
integer exit_flag
real(r8), dimension(:), allocatable dstrs
logical, dimension(:), allocatable lwrttlm
logical, dimension(:), allocatable lwrtrst
logical, dimension(:), allocatable ldeftlm
integer, dimension(:), allocatable ntstart
logical, dimension(:), allocatable lreadfwd
integer noerror
logical, dimension(:), allocatable lcyclerst
logical, dimension(:), allocatable lreadblk
integer, dimension(:), allocatable lbout
integer, dimension(:), allocatable nrhs
integer, dimension(:), allocatable lfinp
integer, dimension(:), allocatable lbinp
integer, dimension(:), allocatable lnew
integer, dimension(:), allocatable lfout
subroutine, public roms_finalize
Definition ad_roms.h:283
subroutine, public roms_run(runinterval)
Definition ad_roms.h:239
subroutine, public roms_initialize(first, mpicomm)
Definition ad_roms.h:52
subroutine, public stats_modobs(ng, tile)
integer function, public stdout_unit(mymaster)
Definition stdout_mod.F:48
logical, save set_stdoutunit
Definition stdout_mod.F:41
logical function, public founderror(flag, noerr, line, routine)
Definition strings.F:52
subroutine, public tl_balance(ng, tile, lbck, linp)
Definition tl_balance.F:59
subroutine, public tl_convolution(ng, tile, linp, lweak, ifac)
subroutine, public tl_variability(ng, tile, linp, lweak)
subroutine, public wrt_rst(ng, tile)
Definition wrt_rst.F:63
subroutine, public biconj(ng, tile, model, lbck)
subroutine, public balance_ref(ng, tile, lbck)
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_initial(ng)
Definition tl_initial.F:4
subroutine tl_main2d
Definition tl_main2d.F:429
subroutine tl_main3d(runinterval)
Definition tl_main3d.F:4