5 use constants_mod,
only: constants_init
6 use diag_manager_mod,
only: diag_manager_init, diag_manager_end
7 use field_manager_mod,
only: field_manager_init, field_manager_end
8 use fms_mod,
only: fms_init, fms_end, open_namelist_file, check_nml_error
9 use fms_mod,
only: close_file, file_exist, uppercase
10 use fms_io_mod,
only: fms_io_exit
11 use mpp_domains_mod,
only: domain2d, mpp_get_compute_domain, mpp_get_compute_domains
12 use mpp_domains_mod,
only: mpp_get_ntile_count, mpp_get_pelist, mpp_get_global_domain
13 use mpp_domains_mod,
only: mpp_get_domain_npes
14 use mpp_io_mod,
only: mpp_open, mpp_rdonly, mpp_ascii, mpp_overwr, mpp_append, mpp_close, mpp_single
15 use mpp_mod,
only: stdlog, stdout, mpp_root_pe, mpp_clock_id
16 use mpp_mod,
only: mpp_clock_begin, mpp_clock_end, mpp_clock_sync
17 use mpp_mod,
only: mpp_clock_detailed, clock_component, maxpes
18 use time_interp_external_mod,
only: time_interp_external_init
19 use time_manager_mod,
only: set_calendar_type, time_type, increment_date
20 use time_manager_mod,
only: set_time, set_date, get_time, get_date, month_name
21 use time_manager_mod,
only: gregorian, julian, noleap, thirty_day_months, no_calendar
22 use time_manager_mod,
only:
operator( <= ),
operator( < ),
operator( >= )
23 use time_manager_mod,
only:
operator( + ),
operator( - ),
operator( / )
24 use time_manager_mod,
only:
operator( * ),
operator( /= ),
operator( > )
25 use time_manager_mod,
only: date_to_string
26 use time_manager_mod,
only: fms_get_calendar_type => get_calendar_type
27 use mom_domains,
only: mom_infra_init, num_pes, root_pe, pe_here
45 use,
intrinsic :: iso_fortran_env, only: output_unit
47 use esmf,
only: esmf_clockadvance, esmf_clockget, esmf_clockprint
48 use esmf,
only: esmf_clockgetalarm, esmf_clockgetnexttime, esmf_clockadvance
49 use esmf,
only: esmf_clockset, esmf_clock, esmf_geomtype_flag, esmf_logmsg_info
50 use esmf,
only: esmf_grid, esmf_gridcreate, esmf_gridaddcoord
51 use esmf,
only: esmf_gridgetcoord, esmf_gridadditem, esmf_gridgetitem
52 use esmf,
only: esmf_gridcomp, esmf_gridcompsetentrypoint, esmf_gridcompget
53 use esmf,
only: esmf_logfounderror, esmf_logwrite, esmf_logseterror
54 use esmf,
only: esmf_logerr_passthru, esmf_kind_r8, esmf_rc_val_wrong
55 use esmf,
only: esmf_geomtype_mesh, esmf_geomtype_grid, esmf_success
56 use esmf,
only: esmf_method_initialize, esmf_methodremove, esmf_state
57 use esmf,
only: esmf_logmsg_info, esmf_rc_arg_bad, esmf_vm, esmf_time
58 use esmf,
only: esmf_timeinterval, esmf_maxstr, esmf_vmgetcurrent
59 use esmf,
only: esmf_vmget, esmf_timeget, esmf_timeintervalget, esmf_meshget
60 use esmf,
only: esmf_methodexecute, esmf_mesh, esmf_delayout, esmf_distgrid
61 use esmf,
only: esmf_distgridconnection, esmf_stateitem_flag, esmf_kind_i4
62 use esmf,
only: esmf_kind_i8, esmf_failure, esmf_distgridcreate, esmf_meshcreate
63 use esmf,
only: esmf_fileformat_esmfmesh, esmf_delayoutcreate, esmf_distgridconnectionset
64 use esmf,
only: esmf_distgridget, esmf_staggerloc_corner, esmf_griditem_mask
65 use esmf,
only: esmf_typekind_i4, esmf_typekind_r8, esmf_staggerloc_center
66 use esmf,
only: esmf_griditem_area, esmf_field, esmf_alarm, esmf_vmlogmeminfo
67 use esmf,
only: esmf_alarmisringing, esmf_alarmringeroff, esmf_stateremove
68 use esmf,
only: esmf_fieldcreate, esmf_logmsg_error, esmf_logmsg_warning
69 use esmf,
only: esmf_coordsys_sph_deg, esmf_gridcreate, esmf_index_delocal
70 use esmf,
only: esmf_meshloc_element, esmf_rc_val_outofrange, esmf_stateget
71 use esmf,
only: esmf_timeprint, esmf_alarmset, esmf_fieldget, esmf_array
72 use esmf,
only: esmf_arraycreate
73 use esmf,
only:
operator(==),
operator(/=),
operator(+),
operator(-)
79 use nuopc,
only: nuopc_compderive, nuopc_compsetentrypoint, nuopc_compspecialize
80 use nuopc,
only: nuopc_compfilterphasemap, nuopc_compattributeget, nuopc_compattributeadd
81 use nuopc,
only: nuopc_advertise, nuopc_setattribute, nuopc_isupdated, nuopc_write
82 use nuopc,
only: nuopc_isconnected, nuopc_realize, nuopc_compattributeset
83 use nuopc_model,
only: nuopc_modelget
86 model_label_advance => label_advance, &
87 model_label_datainitialize => label_datainitialize, &
88 model_label_setrunclock => label_setrunclock, &
89 model_label_finalize => label_finalize
91 implicit none;
private
99 type(ice_ocean_boundary_type),
pointer :: ice_ocean_boundary_type_ptr
110 character(len=64) :: stdname
111 character(len=64) :: shortname
112 character(len=64) :: transferoffer
140 type(esmf_geomtype_flag) ::
geomtype = esmf_geomtype_mesh
143 type(esmf_geomtype_flag) ::
geomtype = esmf_geomtype_grid
156 type(esmf_gridcomp) :: gcomp
157 integer,
intent(out) :: rc
160 character(len=*),
parameter :: subname=
'(MOM_cap:SetServices)'
165 call nuopc_compderive(gcomp, model_routine_ss, rc=rc)
166 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
172 call esmf_gridcompsetentrypoint(gcomp, esmf_method_initialize, &
174 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
180 call nuopc_compsetentrypoint(gcomp, esmf_method_initialize, &
182 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
186 call nuopc_compsetentrypoint(gcomp, esmf_method_initialize, &
188 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
197 call nuopc_compspecialize(gcomp, speclabel=model_label_datainitialize, &
199 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
204 call nuopc_compspecialize(gcomp, speclabel=model_label_advance, &
206 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
211 call esmf_methodremove(gcomp, label=model_label_setrunclock, rc=rc)
212 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
216 call nuopc_compspecialize(gcomp, speclabel=model_label_setrunclock, &
218 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
223 call nuopc_compspecialize(gcomp, speclabel=model_label_finalize, &
225 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
243 subroutine initializep0(gcomp, importState, exportState, clock, rc)
244 type(esmf_gridcomp) :: gcomp
245 type(esmf_state) :: importState, exportState
247 type(esmf_clock) :: clock
248 integer,
intent(out) :: rc
251 logical :: isPresent, isSet
253 character(len=64) ::
value, logmsg
254 character(len=*),
parameter :: subname=
'(MOM_cap:InitializeP0)'
259 call nuopc_compfilterphasemap(gcomp, esmf_method_initialize, &
260 acceptstringlist=(/
"IPDv03p"/), rc=rc)
261 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
267 call nuopc_compattributeget(gcomp, name=
"DumpFields",
value=
value, &
268 ispresent=ispresent, isset=isset, rc=rc)
269 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
276 call esmf_logwrite(
'MOM_cap:DumpFields = '//trim(logmsg), esmf_logmsg_info, rc=rc)
277 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
283 call nuopc_compattributeget(gcomp, name=
"OverwriteSlice",
value=
value, &
284 ispresent=ispresent, isset=isset, rc=rc)
285 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
291 call esmf_logwrite(
'MOM_cap:OverwriteSlice = '//trim(logmsg), esmf_logmsg_info, rc=rc)
292 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
298 call nuopc_compattributeget(gcomp, name=
"ProfileMemory",
value=
value, &
299 ispresent=ispresent, isset=isset, rc=rc)
300 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
306 call esmf_logwrite(
'MOM_cap:ProfileMemory = '//trim(logmsg), esmf_logmsg_info, rc=rc)
307 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
313 call nuopc_compattributeget(gcomp, name=
"GridAttachArea",
value=
value, &
314 ispresent=ispresent, isset=isset, rc=rc)
315 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
321 call esmf_logwrite(
'MOM_cap:GridAttachArea = '//trim(logmsg), esmf_logmsg_info, rc=rc)
322 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
328 call nuopc_compattributeget(gcomp, name=
"ScalarFieldName",
value=
value, &
329 ispresent=ispresent, isset=isset, rc=rc)
330 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
334 if (ispresent .and. isset)
then
336 call esmf_logwrite(
'MOM_cap:ScalarFieldName = '//trim(
scalar_field_name), esmf_logmsg_info, rc=rc)
337 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
344 call nuopc_compattributeget(gcomp, name=
"ScalarFieldCount",
value=
value, &
345 ispresent=ispresent, isset=isset, rc=rc)
346 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
350 if (ispresent .and. isset)
then
352 if (iostat /= 0)
then
353 call esmf_logseterror(esmf_rc_arg_bad, &
354 msg=subname//
": ScalarFieldCount not an integer: "//trim(
value), &
355 line=__line__, file=__file__, rctoreturn=rc)
359 call esmf_logwrite(
'MOM_cap:ScalarFieldCount = '//trim(logmsg), esmf_logmsg_info, rc=rc)
360 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
367 call nuopc_compattributeget(gcomp, name=
"ScalarFieldIdxGridNX",
value=
value, &
368 ispresent=ispresent, isset=isset, rc=rc)
369 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
373 if (ispresent .and. isset)
then
375 if (iostat /= 0)
then
376 call esmf_logseterror(esmf_rc_arg_bad, &
377 msg=subname//
": ScalarFieldIdxGridNX not an integer: "//trim(
value), &
378 line=__line__, file=__file__, rctoreturn=rc)
382 call esmf_logwrite(
'MOM_cap:ScalarFieldIdxGridNX = '//trim(logmsg), esmf_logmsg_info, rc=rc)
383 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
390 call nuopc_compattributeget(gcomp, name=
"ScalarFieldIdxGridNY",
value=
value, &
391 ispresent=ispresent, isset=isset, rc=rc)
392 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
396 if (ispresent .and. isset)
then
398 if (iostat /= 0)
then
399 call esmf_logseterror(esmf_rc_arg_bad, &
400 msg=subname//
": ScalarFieldIdxGridNY not an integer: "//trim(
value), &
401 line=__line__, file=__file__, rctoreturn=rc)
405 call esmf_logwrite(
'MOM_cap:ScalarFieldIdxGridNY = '//trim(logmsg), esmf_logmsg_info, rc=rc)
406 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
412 call nuopc_compattributeadd(gcomp, &
413 attrlist=(/
'RestartFileToRead',
'RestartFileToWrite'/), rc=rc)
414 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
432 type(esmf_gridcomp) :: gcomp
433 type(esmf_state) :: importState, exportState
435 type(esmf_clock) :: clock
436 integer,
intent(out) :: rc
440 type(esmf_time) :: MyTime
441 type(esmf_timeinterval) :: TINT
442 type (ocean_public_type),
pointer :: ocean_public => null()
443 type (ocean_state_type),
pointer :: ocean_state => null()
444 type(ice_ocean_boundary_type),
pointer :: Ice_ocean_boundary => null()
447 type(time_type) :: Run_len
448 type(time_type) :: time0
449 type(time_type) :: time_start
450 type(time_type) :: Time_restart
451 type(time_type) :: DT
453 integer :: isc,iec,jsc,jec
454 integer :: year=0, month=0, day=0, hour=0, minute=0, second=0
455 integer :: mpi_comm_mom
457 character(len=256) :: stdname, shortname
458 character(len=32) :: starttype
459 character(len=512) :: diro
460 character(len=512) :: logfile
461 character(ESMF_MAXSTR) :: cvalue
462 logical :: isPresent, isPresentDiro, isPresentLogfile, isSet
465 character(len=512) :: restartfile
466 character(len=*),
parameter :: subname=
'(MOM_cap:InitializeAdvertise)'
467 character(len=32) :: calendar
472 call esmf_logwrite(subname//
' enter', esmf_logmsg_info, rc=rc)
473 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
478 allocate(ice_ocean_boundary)
480 allocate(ocean_public)
481 allocate(ocean_internalstate%ptr)
482 ocean_internalstate%ptr%ice_ocean_boundary_type_ptr => ice_ocean_boundary
483 ocean_internalstate%ptr%ocean_public_type_ptr => ocean_public
484 ocean_internalstate%ptr%ocean_state_type_ptr => ocean_state
486 call esmf_vmgetcurrent(vm, rc=rc)
487 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
492 call esmf_vmget(vm, mpicommunicator=mpi_comm_mom, rc=rc)
493 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
498 call esmf_clockget(clock, currtime=mytime, timestep=tint, rc=rc)
499 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
504 call esmf_timeget (mytime, yy=year, mm=month, dd=day, h=hour, m=minute, s=second, rc=rc )
505 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
510 CALL esmf_timeintervalget(tint, s=dt_ocean, rc=rc)
511 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
516 call fms_init(mpi_comm_mom)
518 call field_manager_init
522 call nuopc_compattributeget(gcomp, name=
"calendar",
value=cvalue, &
523 ispresent=ispresent, isset=isset, rc=rc)
524 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
528 if (ispresent .and. isset)
then
529 read(cvalue,*) calendar
530 select case (trim(calendar))
532 call set_calendar_type (noleap)
534 call set_calendar_type (gregorian)
536 call esmf_logseterror(esmf_rc_arg_bad, &
537 msg=subname//
": Calendar not supported in MOM6: "//trim(calendar), &
538 line=__line__, file=__file__, rctoreturn=rc)
541 call set_calendar_type (noleap)
545 call set_calendar_type (julian)
548 call diag_manager_init
551 dt = set_time(dt_ocean, 0)
553 time_start = set_date(year,month,day,hour,minute,second)
556 write(
logunit,*) subname//
'current time: y,m,d-',year,month,day,
'h,m,s=',hour,minute,second
560 call esmf_clockget(clock, reftime=mytime, rc=rc)
561 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
566 call esmf_timeget (mytime, yy=year, mm=month, dd=day, h=hour, m=minute, s=second, rc=rc )
567 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
572 time0 = set_date(year,month,day,hour,minute,second)
575 write(
logunit,*) subname//
'start time: y,m,d-',year,month,day,
'h,m,s=',hour,minute,second
584 call nuopc_compattributeget(gcomp, name=
"diro", &
585 ispresent=ispresentdiro, rc=rc)
586 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
590 call nuopc_compattributeget(gcomp, name=
"logfile", &
591 ispresent=ispresentlogfile, rc=rc)
592 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
596 if (ispresentdiro .and. ispresentlogfile)
then
597 call nuopc_compattributeget(gcomp, name=
"diro",
value=diro, rc=rc)
598 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
602 call nuopc_compattributeget(gcomp, name=
"logfile",
value=logfile, rc=rc)
603 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
607 open(newunit=
logunit,file=trim(diro)//
"/"//trim(logfile))
616 call nuopc_compattributeget(gcomp, name=
'start_type',
value=cvalue, &
617 ispresent=ispresent, isset=isset, rc=rc)
618 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
622 if (ispresent .and. isset)
then
623 read(cvalue,*) starttype
625 call esmf_logwrite(
'MOM_cap:start_type unset - using input.nml for restart option', &
626 esmf_logmsg_info, rc=rc)
627 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
634 if (trim(starttype) == trim(
'startup'))
then
636 else if (trim(starttype) == trim(
'continue') )
then
638 else if (trim(starttype) == trim(
'branch'))
then
640 else if (len_trim(starttype) > 0)
then
641 call esmf_logseterror(esmf_rc_arg_bad, &
642 msg=subname//
": unknown starttype - "//trim(starttype), &
643 line=__line__, file=__file__, rctoreturn=rc)
647 if (len_trim(
runtype) > 0)
then
648 call esmf_logwrite(
'MOM_cap:startup = '//trim(
runtype), esmf_logmsg_info, rc=rc)
649 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
659 else if (
runtype ==
"continue")
then
662 call esmf_methodexecute(gcomp, label=
"GetRestartFileToRead", &
663 existflag=existflag, userrc=userrc, rc=rc)
664 if (esmf_logfounderror(rctocheck=rc, msg=
"Error executing user method to get restart filename", &
668 if (esmf_logfounderror(rctocheck=userrc, msg=
"Error in method to get restart filename", &
673 call esmf_logwrite(
'MOM_cap: called user GetRestartFileToRead', esmf_logmsg_info, rc=rc)
674 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
680 call nuopc_compattributeget(gcomp, name=
'RestartFileToRead', &
681 value=cvalue, ispresent=ispresent, isset=isset, rc=rc)
682 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
686 if (ispresent .and. isset)
then
687 restartfile = trim(cvalue)
688 call esmf_logwrite(
'MOM_cap: RestartFileToRead = '//trim(restartfile), esmf_logmsg_info, rc=rc)
689 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
694 call esmf_logwrite(
'MOM_cap: restart requested, no RestartFileToRead attribute provided-will use input.nml',&
695 esmf_logmsg_warning, rc=rc)
696 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
704 ocean_public%is_ocean_pe = .true.
705 call ocean_model_init(ocean_public, ocean_state, time0, time_start, input_restart_file=trim(restartfile))
707 call ocean_model_init_sfc(ocean_state, ocean_public)
709 call mpp_get_compute_domain(ocean_public%domain, isc, iec, jsc, jec)
711 allocate ( ice_ocean_boundary% u_flux (isc:iec,jsc:jec), &
712 ice_ocean_boundary% v_flux (isc:iec,jsc:jec), &
713 ice_ocean_boundary% t_flux (isc:iec,jsc:jec), &
714 ice_ocean_boundary% q_flux (isc:iec,jsc:jec), &
715 ice_ocean_boundary% salt_flux (isc:iec,jsc:jec), &
716 ice_ocean_boundary% lw_flux (isc:iec,jsc:jec), &
717 ice_ocean_boundary% sw_flux_vis_dir (isc:iec,jsc:jec), &
718 ice_ocean_boundary% sw_flux_vis_dif (isc:iec,jsc:jec), &
719 ice_ocean_boundary% sw_flux_nir_dir (isc:iec,jsc:jec), &
720 ice_ocean_boundary% sw_flux_nir_dif (isc:iec,jsc:jec), &
721 ice_ocean_boundary% lprec (isc:iec,jsc:jec), &
722 ice_ocean_boundary% fprec (isc:iec,jsc:jec), &
723 ice_ocean_boundary% seaice_melt_heat (isc:iec,jsc:jec),&
724 ice_ocean_boundary% seaice_melt (isc:iec,jsc:jec), &
725 ice_ocean_boundary% mi (isc:iec,jsc:jec), &
726 ice_ocean_boundary% p (isc:iec,jsc:jec), &
727 ice_ocean_boundary% lrunoff_hflx (isc:iec,jsc:jec), &
728 ice_ocean_boundary% frunoff_hflx (isc:iec,jsc:jec), &
729 ice_ocean_boundary% lrunoff (isc:iec,jsc:jec), &
730 ice_ocean_boundary% frunoff (isc:iec,jsc:jec))
732 ice_ocean_boundary%u_flux = 0.0
733 ice_ocean_boundary%v_flux = 0.0
734 ice_ocean_boundary%t_flux = 0.0
735 ice_ocean_boundary%q_flux = 0.0
736 ice_ocean_boundary%salt_flux = 0.0
737 ice_ocean_boundary%lw_flux = 0.0
738 ice_ocean_boundary%sw_flux_vis_dir = 0.0
739 ice_ocean_boundary%sw_flux_vis_dif = 0.0
740 ice_ocean_boundary%sw_flux_nir_dir = 0.0
741 ice_ocean_boundary%sw_flux_nir_dif = 0.0
742 ice_ocean_boundary%lprec = 0.0
743 ice_ocean_boundary%fprec = 0.0
744 ice_ocean_boundary%seaice_melt = 0.0
745 ice_ocean_boundary%seaice_melt_heat= 0.0
746 ice_ocean_boundary%mi = 0.0
747 ice_ocean_boundary%p = 0.0
748 ice_ocean_boundary%lrunoff_hflx = 0.0
749 ice_ocean_boundary%frunoff_hflx = 0.0
750 ice_ocean_boundary%lrunoff = 0.0
751 ice_ocean_boundary%frunoff = 0.0
753 ocean_internalstate%ptr%ocean_state_type_ptr => ocean_state
754 call esmf_gridcompsetinternalstate(gcomp, ocean_internalstate, rc)
755 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
812 call nuopc_advertise(importstate, standardname=
fldstoocn(n)%stdname, name=
fldstoocn(n)%shortname, rc=rc)
813 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
820 call nuopc_advertise(exportstate, standardname=
fldsfrocn(n)%stdname, name=
fldsfrocn(n)%shortname, rc=rc)
821 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
839 type(esmf_gridcomp) :: gcomp
840 type(esmf_state) :: importState, exportState
842 type(esmf_clock) :: clock
843 integer,
intent(out) :: rc
847 type(esmf_grid) :: gridIn, gridOut
848 type(esmf_mesh) :: Emesh, EmeshTemp
849 type(esmf_delayout) :: delayout
850 type(esmf_distgrid) :: Distgrid
851 type(esmf_distgridconnection),
allocatable :: connectionList(:)
852 type(esmf_stateitem_flag) :: itemFlag
853 type (ocean_public_type),
pointer :: ocean_public => null()
854 type (ocean_state_type),
pointer :: ocean_state => null()
855 type(ice_ocean_boundary_type),
pointer :: Ice_ocean_boundary => null()
858 integer :: npet, ntiles
859 integer :: nxg, nyg, cnt
860 integer :: isc,iec,jsc,jec
861 integer,
allocatable :: xb(:),xe(:),yb(:),ye(:),pe(:)
862 integer,
allocatable :: deBlockList(:,:,:)
863 integer,
allocatable :: petMap(:)
864 integer,
allocatable :: deLabelList(:)
865 integer,
allocatable :: indexList(:)
866 integer :: ioff, joff
867 integer :: i, j, n, i1, j1, n1, jlast
868 integer :: lbnd1,ubnd1,lbnd2,ubnd2
869 integer :: lbnd3,ubnd3,lbnd4,ubnd4
870 integer :: nblocks_tot
872 integer(ESMF_KIND_I4),
pointer :: dataPtr_mask(:,:)
873 real(ESMF_KIND_R8),
pointer :: dataPtr_area(:,:)
874 real(ESMF_KIND_R8),
pointer :: dataPtr_xcen(:,:)
875 real(ESMF_KIND_R8),
pointer :: dataPtr_ycen(:,:)
876 real(ESMF_KIND_R8),
pointer :: dataPtr_xcor(:,:)
877 real(ESMF_KIND_R8),
pointer :: dataPtr_ycor(:,:)
881 integer :: ig,jg, ni,nj,k
882 integer,
allocatable :: gindex(:)
883 character(len=128) :: fldname
884 character(len=256) :: cvalue
885 character(len=256) :: frmt
886 character(len=512) :: err_msg
887 character(len=*),
parameter :: subname=
'(MOM_cap:InitializeRealize)'
888 integer :: spatialDim
889 integer :: numOwnedElements
890 type(esmf_array) :: elemMaskArray
891 real(ESMF_KIND_R8) ,
pointer :: ownedElemCoords(:)
892 real(ESMF_KIND_R8) ,
pointer :: lat(:), latMesh(:)
893 real(ESMF_KIND_R8) ,
pointer :: lon(:), lonMesh(:)
894 integer(ESMF_KIND_I4) ,
pointer :: mask(:), maskMesh(:)
895 real(ESMF_KIND_R8) :: diff_lon, diff_lat
907 call esmf_gridcompgetinternalstate(gcomp, ocean_internalstate, rc)
908 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
913 ice_ocean_boundary => ocean_internalstate%ptr%ice_ocean_boundary_type_ptr
914 ocean_public => ocean_internalstate%ptr%ocean_public_type_ptr
915 ocean_state => ocean_internalstate%ptr%ocean_state_type_ptr
921 call esmf_vmgetcurrent(vm, rc=rc)
922 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
927 call esmf_vmget(vm, petcount=npet, mpicommunicator=mpicom, localpet=localpet, rc=rc)
928 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
937 call mpp_get_global_domain(ocean_public%domain, xsize=nxg, ysize=nyg)
938 write(
tmpstr,
'(a,2i6)') subname//
' nxg,nyg = ',nxg,nyg
939 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
940 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
949 ntiles=mpp_get_ntile_count(ocean_public%domain)
950 if (ntiles /= 1)
then
952 call esmf_logwrite(subname//
' ntiles must be 1', esmf_logmsg_error, rc=rc)
953 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
958 ntiles=mpp_get_domain_npes(ocean_public%domain)
959 write(
tmpstr,
'(a,1i6)') subname//
' ntiles = ',ntiles
960 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
961 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
970 allocate(xb(ntiles),xe(ntiles),yb(ntiles),ye(ntiles),pe(ntiles))
971 call mpp_get_compute_domains(ocean_public%domain, xbegin=xb, xend=xe, ybegin=yb, yend=ye)
972 call mpp_get_pelist(ocean_public%domain, pe)
975 write(
tmpstr,
'(a,6i6)') subname//
' tiles ',n,pe(n),xb(n),xe(n),yb(n),ye(n)
976 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
977 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
991 if (
geomtype == esmf_geomtype_mesh)
then
998 lsize = ( ocean_grid%iec - ocean_grid%isc + 1 ) * ( ocean_grid%jec - ocean_grid%jsc + 1 )
1001 allocate(gindex(lsize))
1003 do j = ocean_grid%jsc, ocean_grid%jec
1004 jg = j + ocean_grid%jdg_offset
1005 do i = ocean_grid%isc, ocean_grid%iec
1006 ig = i + ocean_grid%idg_offset
1008 gindex(k) = ni * (jg - 1) + ig
1012 distgrid = esmf_distgridcreate(arbseqindexlist=gindex, rc=rc)
1013 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1019 call nuopc_compattributeget(gcomp, name=
'mesh_ocn',
value=cvalue, rc=rc)
1020 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1025 emeshtemp = esmf_meshcreate(filename=trim(cvalue), fileformat=esmf_fileformat_esmfmesh, rc=rc)
1026 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1031 if (localpet == 0)
then
1032 write(
logunit,*)
'mesh file for mom6 domain is ',trim(cvalue)
1036 emesh = esmf_meshcreate(emeshtemp, elementdistgrid=distgrid, rc=rc)
1037 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1043 call esmf_meshget(emesh, spatialdim=spatialdim, numownedelements=numownedelements, rc=rc)
1044 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1049 allocate(ownedelemcoords(spatialdim*numownedelements))
1050 allocate(lonmesh(numownedelements), lon(numownedelements))
1051 allocate(latmesh(numownedelements), lat(numownedelements))
1052 allocate(maskmesh(numownedelements), mask(numownedelements))
1054 call esmf_meshget(emesh, ownedelemcoords=ownedelemcoords, rc=rc)
1055 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1059 do n = 1,numownedelements
1060 lonmesh(n) = ownedelemcoords(2*n-1)
1061 latmesh(n) = ownedelemcoords(2*n)
1064 elemmaskarray = esmf_arraycreate(distgrid, maskmesh, rc=rc)
1065 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1069 call esmf_meshget(emesh, elemmaskarray=elemmaskarray, rc=rc)
1070 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1075 call mpp_get_compute_domain(ocean_public%domain, isc, iec, jsc, jec)
1078 jg = j + ocean_grid%jsc - jsc
1080 ig = i + ocean_grid%isc - isc
1082 mask(n) = ocean_grid%mask2dT(ig,jg)
1083 lon(n) = ocean_grid%geolonT(ig,jg)
1084 lat(n) = ocean_grid%geolatT(ig,jg)
1089 do n = 1,numownedelements
1090 diff_lon = abs(mod(lonmesh(n) - lon(n),360.0))
1091 if (diff_lon > eps_omesh)
then
1092 frmt =
"('ERROR: Difference between ESMF Mesh and MOM6 domain coords is "//&
1093 "greater than parameter EPS_OMESH. n, lonMesh(n), lon(n), diff_lon, "//&
1094 "EPS_OMESH= ',i8,2(f21.13,3x),2(d21.5))"
1095 write(err_msg, frmt)n,lonmesh(n),lon(n), diff_lon, eps_omesh
1098 diff_lat = abs(latmesh(n) - lat(n))
1099 if (diff_lat > eps_omesh)
then
1100 frmt =
"('ERROR: Difference between ESMF Mesh and MOM6 domain coords is"//&
1101 "greater than parameter EPS_OMESH. n, latMesh(n), lat(n), diff_lat, "//&
1102 "EPS_OMESH= ',i8,2(f21.13,3x),2(d21.5))"
1103 write(err_msg, frmt)n,latmesh(n),lat(n), diff_lat, eps_omesh
1106 if (abs(maskmesh(n) - mask(n)) > 0)
then
1107 frmt =
"('ERROR: ESMF mesh and MOM6 domain masks are inconsistent! - "//&
1108 "MOM n, maskMesh(n), mask(n) = ',3(i8,2x))"
1109 write(err_msg, frmt)n,maskmesh(n),mask(n)
1114 deallocate(ownedelemcoords)
1115 deallocate(lonmesh , lon )
1116 deallocate(latmesh , lat )
1117 deallocate(maskmesh, mask)
1120 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1126 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1131 else if (
geomtype == esmf_geomtype_grid)
then
1139 allocate(deblocklist(2,2,ntiles))
1140 allocate(petmap(ntiles))
1141 allocate(delabellist(ntiles))
1145 deblocklist(1,1,n) = xb(n)
1146 deblocklist(1,2,n) = xe(n)
1147 deblocklist(2,1,n) = yb(n)
1148 deblocklist(2,2,n) = ye(n)
1159 delayout = esmf_delayoutcreate(petmap, rc=rc)
1160 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1168 allocate(connectionlist(2))
1171 call esmf_distgridconnectionset(connectionlist(1), tileindexa=1, &
1172 tileindexb=1, positionvector=(/nxg+1, 2*nyg+1/), &
1173 orientationvector=(/-1, -2/), rc=rc)
1174 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1180 call esmf_distgridconnectionset(connectionlist(2), tileindexa=1, &
1181 tileindexb=1, positionvector=(/nxg, 0/), rc=rc)
1182 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1187 distgrid = esmf_distgridcreate(minindex=(/1,1/), maxindex=(/nxg,nyg/), &
1189 deblocklist=deblocklist, &
1191 delayout=delayout, &
1192 connectionlist=connectionlist, &
1194 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1199 deallocate(xb,xe,yb,ye,pe)
1200 deallocate(connectionlist)
1201 deallocate(delabellist)
1202 deallocate(deblocklist)
1205 call esmf_distgridget(distgrid=distgrid, localde=0, elementcount=cnt, rc=rc)
1206 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1211 allocate(indexlist(cnt))
1212 write(
tmpstr,
'(a,i8)') subname//
' distgrid cnt= ',cnt
1213 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
1214 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1219 call esmf_distgridget(distgrid=distgrid, localde=0, seqindexlist=indexlist, rc=rc)
1220 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1225 write(
tmpstr,
'(a,4i8)') subname//
' distgrid list= ',&
1226 indexlist(1),indexlist(cnt),minval(indexlist), maxval(indexlist)
1227 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
1228 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1233 deallocate(indexlist)
1237 gridin = esmf_gridcreate(distgrid=distgrid, &
1238 gridedgelwidth=(/0,0/), gridedgeuwidth=(/0,1/), &
1239 coordsys = esmf_coordsys_sph_deg, &
1241 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1247 call esmf_gridaddcoord(gridin, staggerloc=esmf_staggerloc_center, rc=rc)
1248 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1253 call esmf_gridaddcoord(gridin, staggerloc=esmf_staggerloc_corner, rc=rc)
1254 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1259 call esmf_gridadditem(gridin, itemflag=esmf_griditem_mask, itemtypekind=esmf_typekind_i4, &
1260 staggerloc=esmf_staggerloc_center, rc=rc)
1261 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1268 call esmf_gridadditem(gridin, itemflag=esmf_griditem_area, itemtypekind=esmf_typekind_r8, &
1269 staggerloc=esmf_staggerloc_center, rc=rc)
1270 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1277 call esmf_gridgetcoord(gridin, coorddim=1, &
1278 staggerloc=esmf_staggerloc_center, &
1279 farrayptr=dataptr_xcen, rc=rc)
1280 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1285 call esmf_gridgetcoord(gridin, coorddim=2, &
1286 staggerloc=esmf_staggerloc_center, &
1287 farrayptr=dataptr_ycen, rc=rc)
1288 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1294 call esmf_gridgetcoord(gridin, coorddim=1, &
1295 staggerloc=esmf_staggerloc_corner, &
1296 farrayptr=dataptr_xcor, rc=rc)
1297 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1302 call esmf_gridgetcoord(gridin, coorddim=2, &
1303 staggerloc=esmf_staggerloc_corner, &
1304 farrayptr=dataptr_ycor, rc=rc)
1305 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1310 call esmf_gridgetitem(gridin, itemflag=esmf_griditem_mask, &
1311 staggerloc=esmf_staggerloc_center, &
1312 farrayptr=dataptr_mask, rc=rc)
1313 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1319 call esmf_gridgetitem(gridin, itemflag=esmf_griditem_area, &
1320 staggerloc=esmf_staggerloc_center, &
1321 farrayptr=dataptr_area, rc=rc)
1322 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1335 call mpp_get_compute_domain(ocean_public%domain, isc, iec, jsc, jec)
1337 lbnd1 = lbound(dataptr_mask,1)
1338 ubnd1 = ubound(dataptr_mask,1)
1339 lbnd2 = lbound(dataptr_mask,2)
1340 ubnd2 = ubound(dataptr_mask,2)
1342 lbnd3 = lbound(dataptr_xcor,1)
1343 ubnd3 = ubound(dataptr_xcor,1)
1344 lbnd4 = lbound(dataptr_xcor,2)
1345 ubnd4 = ubound(dataptr_xcor,2)
1347 write(
tmpstr,*) subname//
' iscjsc = ',isc,iec,jsc,jec
1348 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
1350 write(
tmpstr,*) subname//
' lbub12 = ',lbnd1,ubnd1,lbnd2,ubnd2
1351 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
1353 write(
tmpstr,*) subname//
' lbub34 = ',lbnd3,ubnd3,lbnd4,ubnd4
1354 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
1356 if (iec-isc /= ubnd1-lbnd1 .or. jec-jsc /= ubnd2-lbnd2)
then
1357 call esmf_logseterror(esmf_rc_arg_bad, &
1358 msg=subname//
": fld and grid do not have the same size.", &
1359 line=__line__, file=__file__, rctoreturn=rc)
1364 j1 = j + lbnd2 - jsc
1365 jg = j + ocean_grid%jsc - jsc
1367 i1 = i + lbnd1 - isc
1368 ig = i + ocean_grid%isc - isc
1369 dataptr_mask(i1,j1) = ocean_grid%mask2dT(ig,jg)
1370 dataptr_xcen(i1,j1) = ocean_grid%geolonT(ig,jg)
1371 dataptr_ycen(i1,j1) = ocean_grid%geolatT(ig,jg)
1373 dataptr_area(i1,j1) = ocean_grid%US%L_to_m**2 * ocean_grid%areaT(ig,jg)
1379 if(jec == nyg)jlast = jec+1
1382 j1 = j + lbnd4 - jsc
1383 jg = j + ocean_grid%jsc - jsc - 1
1385 i1 = i + lbnd3 - isc
1386 ig = i + ocean_grid%isc - isc - 1
1387 dataptr_xcor(i1,j1) = ocean_grid%geolonBu(ig,jg)
1388 dataptr_ycor(i1,j1) = ocean_grid%geolatBu(ig,jg)
1392 write(
tmpstr,*) subname//
' mask = ',minval(dataptr_mask),maxval(dataptr_mask)
1393 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
1396 write(
tmpstr,*) subname//
' area = ',minval(dataptr_area),maxval(dataptr_area)
1397 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
1400 write(
tmpstr,*) subname//
' xcen = ',minval(dataptr_xcen),maxval(dataptr_xcen)
1401 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
1403 write(
tmpstr,*) subname//
' ycen = ',minval(dataptr_ycen),maxval(dataptr_ycen)
1404 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
1406 write(
tmpstr,*) subname//
' xcor = ',minval(dataptr_xcor),maxval(dataptr_xcor)
1407 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
1409 write(
tmpstr,*) subname//
' ycor = ',minval(dataptr_ycor),maxval(dataptr_ycor)
1410 call esmf_logwrite(trim(
tmpstr), esmf_logmsg_info, rc=rc)
1415 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1421 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1435 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1442 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1472 type(esmf_gridcomp) :: gcomp
1473 integer,
intent(out) :: rc
1476 type(esmf_clock) :: clock
1477 type(esmf_state) :: importState, exportState
1478 type (ocean_public_type),
pointer :: ocean_public => null()
1479 type (ocean_state_type),
pointer :: ocean_state => null()
1480 type(ice_ocean_boundary_type),
pointer :: Ice_ocean_boundary => null()
1483 character(240) :: msgString
1484 integer :: fieldCount, n
1485 type(esmf_field) :: field
1486 character(len=64),
allocatable :: fieldNameList(:)
1487 character(len=*),
parameter :: subname=
'(MOM_cap:DataInitialize)'
1491 call esmf_gridcompget(gcomp, clock=clock, importstate=importstate, exportstate=exportstate, rc=rc)
1492 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1497 call esmf_gridcompgetinternalstate(gcomp, ocean_internalstate, rc)
1498 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1503 ice_ocean_boundary => ocean_internalstate%ptr%ice_ocean_boundary_type_ptr
1504 ocean_public => ocean_internalstate%ptr%ocean_public_type_ptr
1505 ocean_state => ocean_internalstate%ptr%ocean_state_type_ptr
1508 call mom_export(ocean_public, ocean_grid, ocean_state, exportstate, clock, rc=rc)
1509 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1514 call esmf_stateget(exportstate, itemcount=fieldcount, rc=rc)
1515 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1520 allocate(fieldnamelist(fieldcount))
1521 call esmf_stateget(exportstate, itemnamelist=fieldnamelist, rc=rc)
1522 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1528 call esmf_stateget(exportstate, itemname=fieldnamelist(n), field=field, rc=rc)
1529 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1534 call nuopc_setattribute(field, name=
"Updated",
value=
"true", rc=rc)
1535 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1540 deallocate(fieldnamelist)
1543 if (nuopc_isupdated(exportstate))
then
1544 call nuopc_compattributeset(gcomp, name=
"InitializeDataComplete",
value=
"true", rc=rc)
1546 call esmf_logwrite(
"MOM6 - Initialize-Data-Dependency SATISFIED!!!", esmf_logmsg_info, rc=rc)
1547 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1554 call nuopc_write(exportstate, filenameprefix=
'field_init_ocn_export_', &
1556 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1569 type(esmf_gridcomp) :: gcomp
1570 integer,
intent(out) :: rc
1574 logical :: existflag, isPresent, isSet
1575 logical :: do_advance = .true.
1576 type(esmf_clock) :: clock
1577 type(esmf_alarm) :: alarm
1578 type(esmf_state) :: importState, exportState
1579 type(esmf_time) :: currTime
1580 type(esmf_timeinterval) :: timeStep
1581 type(esmf_time) :: startTime
1582 type(esmf_timeinterval) :: time_elapsed
1583 integer(ESMF_KIND_I8) :: n_interval, time_elapsed_sec
1584 character(len=64) :: timestamp
1585 type (ocean_public_type),
pointer :: ocean_public => null()
1586 type (ocean_state_type),
pointer :: ocean_state => null()
1587 type(ice_ocean_boundary_type),
pointer :: Ice_ocean_boundary => null()
1590 type(time_type) :: Time
1591 type(time_type) :: Time_step_coupled
1592 type(time_type) :: Time_restart_current
1593 integer :: dth, dtm, dts
1595 type(esmf_time) :: MyTime
1596 integer :: seconds, day, year, month, hour, minute
1597 character(ESMF_MAXSTR) :: restartname, cvalue
1598 character(240) :: msgString
1599 character(len=*),
parameter :: subname=
'(MOM_cap:ModelAdvance)'
1602 if(
profile_memory)
call esmf_vmlogmeminfo(
"Entering MOM Model_ADVANCE: ")
1607 call esmf_gridcompget(gcomp, clock=clock, importstate=importstate, &
1608 exportstate=exportstate, rc=rc)
1609 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1616 call esmf_clockprint(clock, options=
"currTime", &
1617 prestring=
"------>Advancing OCN from: ", unit=msgstring, rc=rc)
1618 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1622 call esmf_logwrite(subname//trim(msgstring), esmf_logmsg_info, rc=rc)
1623 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1628 call esmf_clockget(clock, starttime=starttime, currtime=currtime, &
1629 timestep=timestep, rc=rc)
1630 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1635 call esmf_timeprint(currtime + timestep, &
1636 prestring=
"--------------------------------> to: ", unit=msgstring, rc=rc)
1637 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1641 call esmf_logwrite(trim(msgstring), esmf_logmsg_info, rc=rc)
1642 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1655 if (trim(
runtype) ==
"initial")
then
1658 if (currtime == starttime)
then
1659 call esmf_logwrite(
"MOM6 - Skipping the first coupling timestep", esmf_logmsg_info, rc=rc)
1660 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1664 do_advance = .false.
1669 if (do_advance)
then
1671 if (currtime == starttime + timestep)
then
1672 call esmf_logwrite(
"MOM6 - Stepping back one coupling timestep", esmf_logmsg_info, rc=rc)
1673 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1679 call esmf_logwrite(
"MOM6 - doubling the coupling timestep", esmf_logmsg_info, rc=rc)
1680 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1691 if (do_advance)
then
1693 call esmf_gridcompgetinternalstate(gcomp, ocean_internalstate, rc)
1694 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1699 ice_ocean_boundary => ocean_internalstate%ptr%ice_ocean_boundary_type_ptr
1700 ocean_public => ocean_internalstate%ptr%ocean_public_type_ptr
1701 ocean_state => ocean_internalstate%ptr%ocean_state_type_ptr
1708 call nuopc_write(importstate, filenameprefix=
'field_ocn_import_', &
1710 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1727 call mom_import(ocean_public, ocean_grid, importstate, ice_ocean_boundary, rc=rc)
1728 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1737 if(
profile_memory)
call esmf_vmlogmeminfo(
"Entering MOM update_ocean_model: ")
1738 call update_ocean_model(ice_ocean_boundary, ocean_state, ocean_public, time, time_step_coupled)
1739 if(
profile_memory)
call esmf_vmlogmeminfo(
"Leaving MOM update_ocean_model: ")
1745 call mom_export(ocean_public, ocean_grid, ocean_state, exportstate, clock, rc=rc)
1746 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1757 call esmf_clockgetalarm(clock, alarmname=
'alarm_restart', alarm=alarm, rc=rc)
1758 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1763 if (esmf_alarmisringing(alarm, rc=rc))
then
1764 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1769 call esmf_alarmringeroff(alarm, rc=rc )
1770 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1777 call esmf_methodexecute(gcomp, label=
"GetRestartFileToWrite", &
1778 existflag=existflag, userrc=userrc, rc=rc)
1779 if (esmf_logfounderror(rctocheck=rc, msg=
"Error executing user method to get restart filename", &
1784 if (esmf_logfounderror(rctocheck=userrc, msg=
"Error in method to get restart filename", &
1789 call esmf_logwrite(
"MOM_cap: called user GetRestartFileToWrite method", esmf_logmsg_info, rc=rc)
1790 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1794 call nuopc_compattributeget(gcomp, name=
'RestartFileToWrite', &
1795 ispresent=ispresent, isset=isset,
value=cvalue, rc=rc)
1796 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1800 if (ispresent .and. isset)
then
1801 restartname = trim(cvalue)
1802 call esmf_logwrite(
"MOM_cap: User RestartFileToWrite: "//trim(restartname), esmf_logmsg_info, rc=rc)
1803 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1810 if (len_trim(restartname) == 0)
then
1812 call esmf_clockgetnexttime(clock, mytime, rc=rc)
1813 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1817 call esmf_timeget (mytime, yy=year, mm=month, dd=day, &
1818 h=hour, m=minute, s=seconds, rc=rc )
1819 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1823 write(restartname,
'(A,".mom6.r.",I4.4,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2,"-",I2.2)') &
1824 "ocn", year, month, day, hour, minute, seconds
1825 call esmf_logwrite(
"MOM_cap: Using default restart filename: "//trim(restartname), esmf_logmsg_info, rc=rc)
1826 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1852 call ocean_model_restart(ocean_state, restartname=restartname)
1855 write(
logunit,*) subname//
' writing restart file ',trim(restartname)
1864 call nuopc_write(exportstate, filenameprefix=
'field_ocn_export_', &
1866 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1873 if(
profile_memory)
call esmf_vmlogmeminfo(
"Leaving MOM Model_ADVANCE: ")
1879 type(esmf_gridcomp) :: gcomp
1880 integer,
intent(out) :: rc
1883 type(esmf_clock) :: mclock, dclock
1884 type(esmf_time) :: mcurrtime, dcurrtime
1885 type(esmf_time) :: mstoptime
1886 type(esmf_timeinterval) :: mtimestep, dtimestep
1887 character(len=128) :: mtimestring, dtimestring
1888 character(len=256) :: cvalue
1889 character(len=256) :: restart_option
1890 integer :: restart_n
1891 integer :: restart_ymd
1892 type(esmf_alarm) :: restart_alarm
1893 logical :: isPresent, isSet
1894 logical :: first_time = .true.
1895 character(len=*),
parameter :: subname=
'MOM_cap:(ModelSetRunClock) '
1901 call nuopc_modelget(gcomp, driverclock=dclock, modelclock=mclock, rc=rc)
1902 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1907 call esmf_clockget(dclock, currtime=dcurrtime, timestep=dtimestep, rc=rc)
1908 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1913 call esmf_clockget(mclock, currtime=mcurrtime, timestep=mtimestep, rc=rc)
1914 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1923 if (mcurrtime /= dcurrtime)
then
1924 call esmf_timeget(dcurrtime, timestring=dtimestring, rc=rc)
1925 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1930 call esmf_timeget(mcurrtime, timestring=mtimestring, rc=rc)
1931 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1936 call esmf_logseterror(esmf_rc_val_wrong, &
1937 msg=subname//
": ERROR in time consistency: "//trim(dtimestring)//
" != "//trim(mtimestring), &
1938 line=__line__, file=__file__, rctoreturn=rc)
1946 mstoptime = mcurrtime + dtimestep
1948 call esmf_clockset(mclock, currtime=dcurrtime, timestep=dtimestep, stoptime=mstoptime, rc=rc)
1949 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1954 if (first_time)
then
1963 call nuopc_compattributeget(gcomp, name=
"restart_option", ispresent=ispresent, &
1964 isset=isset,
value=restart_option, rc=rc)
1965 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1969 if (ispresent .and. isset)
then
1970 call nuopc_compattributeget(gcomp, name=
"restart_n",
value=cvalue, &
1971 ispresent=ispresent, isset=isset, rc=rc)
1972 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1976 if (ispresent .and. isset)
then
1977 read(cvalue,*) restart_n
1979 call nuopc_compattributeget(gcomp, name=
"restart_ymd",
value=cvalue, &
1980 ispresent=ispresent, isset=isset, rc=rc)
1981 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
1985 if (ispresent .and. isset)
then
1986 read(cvalue,*) restart_ymd
1989 restart_option =
"none"
1993 alarm = restart_alarm, &
1994 option = trim(restart_option), &
1995 opt_n = restart_n, &
1996 opt_ymd = restart_ymd, &
1997 reftime = mcurrtime, &
1998 alarmname =
'alarm_restart', rc=rc)
1999 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2004 call esmf_alarmset(restart_alarm, clock=mclock, rc=rc)
2005 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2009 first_time = .false.
2011 call esmf_logwrite(subname//
" Set restart option = "//restart_option, &
2012 esmf_logmsg_info, rc=rc)
2013 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2024 call esmf_clockadvance(mclock,rc=rc)
2025 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2030 call esmf_clockset(mclock, currtime=dcurrtime, timestep=dtimestep, stoptime=mstoptime, rc=rc)
2031 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2047 type(esmf_gridcomp) :: gcomp
2048 integer,
intent(out) :: rc
2051 type (ocean_public_type),
pointer :: ocean_public
2052 type (ocean_state_type),
pointer :: ocean_state
2054 type(time_type) :: Time
2055 type(esmf_clock) :: clock
2056 type(esmf_time) :: currTime
2057 character(len=64) :: timestamp
2058 character(len=*),
parameter :: subname=
'(MOM_cap:ocean_model_finalize)'
2060 write(*,*)
'MOM: --- finalize called ---'
2063 call esmf_gridcompgetinternalstate(gcomp, ocean_internalstate, rc)
2064 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2069 ocean_public => ocean_internalstate%ptr%ocean_public_type_ptr
2070 ocean_state => ocean_internalstate%ptr%ocean_state_type_ptr
2072 call nuopc_modelget(gcomp, modelclock=clock, rc=rc)
2073 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2078 call esmf_clockget(clock, currtime=currtime, rc=rc)
2079 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2086 call ocean_model_end(ocean_public, ocean_state, time, write_restart=.false.)
2088 call ocean_model_end(ocean_public, ocean_state, time, write_restart=.true.)
2090 call field_manager_end()
2095 write(*,*)
'MOM: --- completed ---'
2101 subroutine state_setscalar(value, scalar_id, State, mytask, scalar_name, scalar_count, rc)
2102 real(ESMF_KIND_R8),
intent(in) :: value
2103 integer,
intent(in) :: scalar_id
2104 type(esmf_state),
intent(inout) :: State
2105 integer,
intent(in) :: mytask
2106 character(len=*),
intent(in) :: scalar_name
2107 integer,
intent(in) :: scalar_count
2108 integer,
intent(inout) :: rc
2111 type(esmf_field) :: field
2112 real(ESMF_KIND_R8),
pointer :: farrayptr(:,:)
2113 character(len=*),
parameter :: subname=
'(MOM_cap:State_SetScalar)'
2118 call esmf_stateget(state, itemname=trim(scalar_name), field=field, rc=rc)
2119 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, line=__line__, file=
u_file_u))
return
2121 if (mytask == 0)
then
2122 call esmf_fieldget(field, farrayptr=farrayptr, rc=rc)
2123 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, line=__line__, file=
u_file_u))
return
2125 if (scalar_id < 0 .or. scalar_id > scalar_count)
then
2126 call esmf_logseterror(esmf_rc_arg_bad, &
2127 msg=subname//
": ERROR in scalar_id", &
2128 line=__line__, file=__file__, rctoreturn=rc)
2132 farrayptr(scalar_id,1) =
value
2139 type(esmf_state) ,
intent(inout) :: state
2141 integer ,
intent(in) :: nfields
2144 character(len=*) ,
intent(in) :: tag
2145 type(esmf_grid) ,
intent(in),
optional :: grid
2146 type(esmf_mesh) ,
intent(in),
optional :: mesh
2147 integer ,
intent(inout) :: rc
2151 type(esmf_field) :: field
2152 real(ESMF_KIND_R8),
pointer :: fldptr1d(:)
2153 real(ESMF_KIND_R8),
pointer :: fldptr2d(:,:)
2154 character(len=*),
parameter :: subname=
'(MOM_cap:MOM_RealizeFields)'
2161 if (nuopc_isconnected(state, fieldname=field_defs(i)%shortname))
then
2165 call esmf_logwrite(subname // tag //
" Field "// trim(field_defs(i)%stdname) //
" is connected on root pe.", &
2172 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2179 call esmf_logwrite(subname // tag //
" Field "// trim(field_defs(i)%stdname) //
" is connected.", &
2185 if (
present(grid))
then
2187 field = esmf_fieldcreate(grid, esmf_typekind_r8, indexflag=esmf_index_delocal, &
2188 name=field_defs(i)%shortname, rc=rc)
2189 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2195 call esmf_fieldget(field, farrayptr=fldptr2d, rc=rc)
2196 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2202 else if (
present(mesh))
then
2204 field = esmf_fieldcreate(mesh=mesh, typekind=esmf_typekind_r8, meshloc=esmf_meshloc_element, &
2205 name=field_defs(i)%shortname, rc=rc)
2206 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2212 call esmf_fieldget(field, farrayptr=fldptr1d, rc=rc)
2213 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2224 call nuopc_realize(state, field=field, rc=rc)
2225 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2232 call esmf_logwrite(subname // tag //
" Field "// trim(field_defs(i)%stdname) //
" is not connected.", &
2238 call esmf_stateremove(state, (/field_defs(i)%shortname/), rc=rc)
2239 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2253 type(esmf_field),
intent(inout) :: field
2254 integer,
intent(inout) :: rc
2257 type(esmf_distgrid) :: distgrid
2258 type(esmf_grid) :: grid
2259 character(len=*),
parameter :: subname=
'(MOM_cap:SetScalarField)'
2264 distgrid = esmf_distgridcreate(minindex=(/1/), maxindex=(/1/), rc=rc)
2265 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2270 grid = esmf_gridcreate(distgrid, rc=rc)
2271 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2277 field = esmf_fieldcreate(name=trim(
scalar_field_name), grid=grid, typekind=esmf_typekind_r8, &
2278 ungriddedlbound=(/1/), ungriddedubound=(/
scalar_field_count/), gridtofieldmap=(/2/), rc=rc)
2279 if (esmf_logfounderror(rctocheck=rc, msg=esmf_logerr_passthru, &
2291 subroutine fld_list_add(num, fldlist, stdname, transferOffer, shortname)
2292 integer,
intent(inout) :: num
2294 character(len=*),
intent(in) :: stdname
2295 character(len=*),
intent(in) :: transferOffer
2296 character(len=*),
optional,
intent(in) :: shortname
2300 character(len=*),
parameter :: subname=
'(MOM_cap:fld_list_add)'
2305 call esmf_logseterror(esmf_rc_val_outofrange, &
2306 msg=trim(subname)//
": ERROR number of field exceeded fldsMax: "//trim(stdname), &
2307 line=__line__, file=__file__, rctoreturn=rc)
2311 fldlist(num)%stdname = trim(stdname)
2312 if (
present(shortname))
then
2313 fldlist(num)%shortname = trim(shortname)
2315 fldlist(num)%shortname = trim(stdname)
2317 fldlist(num)%transferOffer = trim(transferoffer)
2324 integer,
intent(in) :: nunit
2330 integer,
intent(in) :: nunit