|
| 1 | +module shr_lightning_coupling_mod |
| 2 | + |
| 3 | + !======================================================================== |
| 4 | + ! Module for handling namelist variables related to lightning coupling |
| 5 | + !======================================================================== |
| 6 | + |
| 7 | + use ESMF , only : ESMF_VMGetCurrent, ESMF_VM, ESMF_VMGet |
| 8 | + use ESMF , only : ESMF_LOGERR_PASSTHRU, ESMF_SUCCESS |
| 9 | + use ESMF , only : ESMF_VMBroadCast, ESMF_Logical, assignment(=) |
| 10 | + use shr_sys_mod , only : shr_sys_abort |
| 11 | + use shr_log_mod , only : shr_log_getLogUnit |
| 12 | + use shr_nl_mod , only : shr_nl_find_group_name |
| 13 | + use nuopc_shr_methods, only : chkerr |
| 14 | + |
| 15 | + implicit none |
| 16 | + private |
| 17 | + |
| 18 | + ! !PUBLIC MEMBER FUNCTIONS |
| 19 | + public shr_lightning_coupling_readnl ! Read namelist |
| 20 | + |
| 21 | + character(len=*), parameter :: & |
| 22 | + u_FILE_u=__FILE__ |
| 23 | + |
| 24 | + !==================================================================================== |
| 25 | +CONTAINS |
| 26 | + !==================================================================================== |
| 27 | + |
| 28 | + subroutine shr_lightning_coupling_readnl(NLFilename, atm_provides_lightning_out) |
| 29 | + |
| 30 | + !======================================================================== |
| 31 | + ! reads lightning_coupling_nl namelist and returns a variable specifying |
| 32 | + ! if atmosphere model provides lightning flash frequency field to mediator |
| 33 | + !======================================================================== |
| 34 | + |
| 35 | + ! input/output variables |
| 36 | + character(len=*), intent(in) :: NLFilename ! Namelist filename |
| 37 | + logical, intent(out) :: atm_provides_lightning_out ! if TRUE atm will provide lightning flash frequency |
| 38 | + |
| 39 | + !----- local ----- |
| 40 | + logical :: atm_provides_lightning |
| 41 | + type(ESMF_VM) :: vm |
| 42 | + integer :: unitn ! namelist unit number |
| 43 | + integer :: ierr ! error code |
| 44 | + logical :: exists ! if file exists or not |
| 45 | + type(ESMF_Logical):: ltmp(1) |
| 46 | + integer :: rc |
| 47 | + integer :: localpet |
| 48 | + integer :: mpicom |
| 49 | + integer :: s_logunit |
| 50 | + character(len=*), parameter :: atm_ozone_frequency_not_present = 'NOT_PRESENT' |
| 51 | + character(len=*), parameter :: subname = '(shr_lightning_coupling_readnl) ' |
| 52 | + ! ------------------------------------------------------------------ |
| 53 | + |
| 54 | + namelist /lightning_coupling_nl/ atm_provides_lightning |
| 55 | + |
| 56 | + rc = ESMF_SUCCESS |
| 57 | + |
| 58 | + atm_provides_lightning_out = .false. |
| 59 | + ltmp(1) = .false. |
| 60 | + |
| 61 | + !--- Open and read namelist --- |
| 62 | + if ( len_trim(NLFilename) == 0 ) then |
| 63 | + call shr_sys_abort( subname//'ERROR: nlfilename not set' ) |
| 64 | + end if |
| 65 | + call shr_log_getLogUnit(s_logunit) |
| 66 | + call ESMF_VMGetCurrent(vm, rc=rc) |
| 67 | + if (chkerr(rc,__LINE__,u_FILE_u)) return |
| 68 | + |
| 69 | + call ESMF_VMGet(vm, localPet=localpet, mpiCommunicator=mpicom, rc=rc) |
| 70 | + if (chkerr(rc,__LINE__,u_FILE_u)) return |
| 71 | + |
| 72 | + if (localpet==0) then |
| 73 | + ! ------------------------------------------------------------------------ |
| 74 | + ! Set default values in case namelist file doesn't exist, lightning_coupling_nl group |
| 75 | + ! doesn't exist within the file, or a given variable isn't present in the namelist |
| 76 | + ! group in the file. |
| 77 | + ! ------------------------------------------------------------------------ |
| 78 | + atm_provides_lightning = .false. |
| 79 | + |
| 80 | + ! ------------------------------------------------------------------------ |
| 81 | + ! Read namelist file |
| 82 | + ! ------------------------------------------------------------------------ |
| 83 | + inquire( file=trim(NLFileName), exist=exists) |
| 84 | + if ( exists ) then |
| 85 | + open(newunit=unitn, file=trim(NLFilename), status='old' ) |
| 86 | + write(s_logunit,'(a)') subname,'Read in lightning_coupling_nl namelist from: ', trim(NLFilename) |
| 87 | + call shr_nl_find_group_name(unitn, 'lightning_coupling_nl', ierr) |
| 88 | + if (ierr == 0) then |
| 89 | + ! Note that ierr /= 0 means no namelist is present. |
| 90 | + read(unitn, lightning_coupling_nl, iostat=ierr) |
| 91 | + if (ierr > 0) then |
| 92 | + call shr_sys_abort(subname//'problem reading lightning_coupling_nl') |
| 93 | + end if |
| 94 | + end if |
| 95 | + close( unitn ) |
| 96 | + end if |
| 97 | + |
| 98 | + ltmp(1) = atm_provides_lightning |
| 99 | + |
| 100 | + end if |
| 101 | + |
| 102 | + ! ------------------------------------------------------------------------ |
| 103 | + ! Broadcast values to all tasks |
| 104 | + ! ------------------------------------------------------------------------ |
| 105 | + call ESMF_VMBroadcast(vm, ltmp, count=1, rootPet=0, rc=rc) |
| 106 | + if (chkerr(rc,__LINE__,u_FILE_u)) return |
| 107 | + |
| 108 | + atm_provides_lightning_out = ltmp(1) |
| 109 | + |
| 110 | + end subroutine shr_lightning_coupling_readnl |
| 111 | + |
| 112 | +end module shr_lightning_coupling_mod |
0 commit comments