@@ -28,9 +28,11 @@ module MOM_cap_mod
28
28
use MOM_cap_methods, only: mom_import, mom_export, mom_set_geomtype, mod2med_areacor
29
29
use MOM_cap_methods, only: med2mod_areacor, state_diagnose
30
30
use MOM_cap_methods, only: ChkErr
31
+ use MOM_ensemble_manager, only: ensemble_manager_init
31
32
32
33
#ifdef CESMCOUPLED
33
34
use shr_log_mod, only: shr_log_setLogUnit
35
+ use nuopc_shr_methods, only: get_component_instance
34
36
#endif
35
37
use time_utils_mod, only: esmf2fms_time
36
38
@@ -147,7 +149,8 @@ module MOM_cap_mod
147
149
logical :: cesm_coupled = .false.
148
150
type (ESMF_GeomType_Flag) :: geomtype
149
151
#endif
150
- character (len= 8 ) :: restart_mode = ' alarms'
152
+ character (len= 8 ) :: restart_mode = ' alarms'
153
+ character (len= 16 ) :: inst_suffix = ' '
151
154
real (8 ) :: timere
152
155
153
156
contains
@@ -434,6 +437,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
434
437
! (same as restartfile if single restart file)
435
438
character (len=* ), parameter :: subname= ' (MOM_cap:InitializeAdvertise)'
436
439
character (len= 32 ) :: calendar
440
+ character (len= :), allocatable :: rpointer_filename
441
+ integer :: inst_index
437
442
real (8 ) :: MPI_Wtime, timeiads
438
443
!- -------------------------------
439
444
@@ -465,6 +470,13 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
465
470
CALL ESMF_TimeIntervalGet(TINT, S= DT_OCEAN, RC= rc)
466
471
if (ChkErr(rc,__LINE__,u_FILE_u)) return
467
472
473
+ #ifdef CESMCOUPLED
474
+ call get_component_instance(gcomp, inst_suffix, inst_index, rc)
475
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
476
+ call ensemble_manager_init(inst_suffix)
477
+ rpointer_filename = ' rpointer.ocn' // trim (inst_suffix)
478
+ #endif
479
+
468
480
! reset shr logging to my log file
469
481
if (localPet== 0 ) then
470
482
call NUOPC_CompAttributeGet(gcomp, name= " diro" , &
@@ -474,11 +486,20 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
474
486
isPresent= isPresentLogfile, rc= rc)
475
487
if (ChkErr(rc,__LINE__,u_FILE_u)) return
476
488
if (isPresentDiro .and. isPresentLogfile) then
477
- call NUOPC_CompAttributeGet(gcomp, name= " diro" , value= diro, rc= rc)
478
- if (ChkErr(rc,__LINE__,u_FILE_u)) return
479
- call NUOPC_CompAttributeGet(gcomp, name= " logfile" , value= logfile, rc= rc)
480
- if (ChkErr(rc,__LINE__,u_FILE_u)) return
481
- open (newunit= stdout,file= trim (diro)// " /" // trim (logfile))
489
+ call NUOPC_CompAttributeGet(gcomp, name= " diro" , value= diro, rc= rc)
490
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
491
+ call NUOPC_CompAttributeGet(gcomp, name= " logfile" , value= logfile, rc= rc)
492
+ if (ChkErr(rc,__LINE__,u_FILE_u)) return
493
+
494
+ if (cesm_coupled) then
495
+ ! Multiinstance logfile name needs a correction
496
+ if (len_trim (inst_suffix) > 0 ) then
497
+ n = index (logfile, ' .' )
498
+ logfile = logfile(1 :n-1 )// trim (inst_suffix)// logfile(n:)
499
+ endif
500
+ endif
501
+
502
+ open (newunit= stdout,file= trim (diro)// " /" // trim (logfile))
482
503
else
483
504
stdout = output_unit
484
505
endif
@@ -535,12 +556,6 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
535
556
536
557
time0 = set_date (YEAR,MONTH,DAY,HOUR,MINUTE,SECOND)
537
558
538
-
539
- ! rsd need to figure out how to get this without share code
540
- ! call shr_nuopc_get_component_instance(gcomp, inst_suffix, inst_index)
541
- ! inst_name = "OCN"//trim(inst_suffix)
542
-
543
-
544
559
if (is_root_pe()) then
545
560
write (stdout,* ) subname// ' start time: y,m,d-' ,year,month,day,' h,m,s=' ,hour,minute,second
546
561
endif
@@ -595,9 +610,9 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
595
610
596
611
if (localPet == 0 ) then
597
612
! this hard coded for rpointer.ocn right now
598
- open (newunit= readunit, file= ' rpointer.ocn ' , form= ' formatted' , status= ' old' , iostat= iostat)
613
+ open (newunit= readunit, file= rpointer_filename , form= ' formatted' , status= ' old' , iostat= iostat)
599
614
if (iostat /= 0 ) then
600
- call ESMF_LogSetError(ESMF_RC_FILE_OPEN, msg= subname// ' ERROR opening rpointer.ocn ' , &
615
+ call ESMF_LogSetError(ESMF_RC_FILE_OPEN, msg= subname// ' ERROR opening ' // rpointer_filename , &
601
616
line= __LINE__, file= u_FILE_u, rcToReturn= rc)
602
617
return
603
618
endif
@@ -607,7 +622,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
607
622
if (len (trim (restartfiles))>1 .and. iostat< 0 ) then
608
623
exit ! done reading restart files list.
609
624
else
610
- call ESMF_LogSetError(ESMF_RC_FILE_READ, msg= subname// ' ERROR reading rpointer.ocn ' , &
625
+ call ESMF_LogSetError(ESMF_RC_FILE_READ, msg= subname// ' ERROR reading ' // rpointer_filename , &
611
626
line= __LINE__, file= u_FILE_u, rcToReturn= rc)
612
627
return
613
628
endif
@@ -630,7 +645,12 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
630
645
endif
631
646
632
647
ocean_public% is_ocean_pe = .true.
633
- call ocean_model_init(ocean_public, ocean_state, time0, time_start, input_restart_file= trim (adjustl (restartfiles)))
648
+ if (cesm_coupled .and. len_trim (inst_suffix)>0 ) then
649
+ call ocean_model_init(ocean_public, ocean_state, time0, time_start, &
650
+ input_restart_file= trim (adjustl (restartfiles)), inst_index= inst_index)
651
+ else
652
+ call ocean_model_init(ocean_public, ocean_state, time0, time_start, input_restart_file= trim (adjustl (restartfiles)))
653
+ endif
634
654
635
655
! GMM, this call is not needed in CESM. Check with EMC if it can be deleted.
636
656
call ocean_model_flux_init(ocean_state)
@@ -1511,6 +1531,7 @@ subroutine ModelAdvance(gcomp, rc)
1511
1531
character (len= 128 ) :: fldname
1512
1532
character (len=* ),parameter :: subname= ' (MOM_cap:ModelAdvance)'
1513
1533
character (len= 8 ) :: suffix
1534
+ character (len= :), allocatable :: rpointer_filename
1514
1535
integer :: num_rest_files
1515
1536
real (8 ) :: MPI_Wtime, timers
1516
1537
@@ -1685,20 +1706,26 @@ subroutine ModelAdvance(gcomp, rc)
1685
1706
call ESMF_VMGet(vm, localPet= localPet, rc= rc)
1686
1707
if (ChkErr(rc,__LINE__,u_FILE_u)) return
1687
1708
1709
+ rpointer_filename = ' rpointer.ocn' // trim (inst_suffix)
1710
+
1688
1711
write (restartname,' (A,".mom6.r.",I4.4,"-",I2.2,"-",I2.2,"-",I5.5)' ) &
1689
1712
trim (casename), year, month, day, seconds
1690
1713
call ESMF_LogWrite(" MOM_cap: Writing restart : " // trim (restartname), ESMF_LOGMSG_INFO)
1691
1714
! write restart file(s)
1692
1715
call ocean_model_restart(ocean_state, restartname= restartname, num_rest_files= num_rest_files)
1693
1716
if (localPet == 0 ) then
1694
1717
! Write name of restart file in the rpointer file - this is currently hard-coded for the ocean
1695
- open (newunit= writeunit, file= ' rpointer.ocn ' , form= ' formatted' , status= ' unknown' , iostat= iostat)
1718
+ open (newunit= writeunit, file= rpointer_filename , form= ' formatted' , status= ' unknown' , iostat= iostat)
1696
1719
if (iostat /= 0 ) then
1697
1720
call ESMF_LogSetError(ESMF_RC_FILE_OPEN, &
1698
- msg= subname// ' ERROR opening rpointer.ocn ' , line= __LINE__, file= u_FILE_u, rcToReturn= rc)
1721
+ msg= subname// ' ERROR opening ' // rpointer_filename , line= __LINE__, file= u_FILE_u, rcToReturn= rc)
1699
1722
return
1700
1723
endif
1701
- write (writeunit,' (a)' ) trim (restartname)// ' .nc'
1724
+ if (len_trim (inst_suffix) == 0 ) then
1725
+ write (writeunit,' (a)' ) trim (restartname)// ' .nc'
1726
+ else
1727
+ write (writeunit,' (a)' ) trim (restartname)// ' .' // trim (inst_suffix)// ' .nc'
1728
+ endif
1702
1729
1703
1730
if (num_rest_files > 1 ) then
1704
1731
! append i.th restart file name to rpointer
0 commit comments