Skip to content

Commit

Permalink
Allow passing values of type integer(8)/integer(kind=I8KIND) to mpas_…
Browse files Browse the repository at this point in the history
…log_write.
  • Loading branch information
jim-p-w committed Jan 7, 2025
1 parent 73b588d commit 09af9d7
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/framework/mpas_log.F
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,15 @@ end subroutine mpas_log_open
!> regardless of if all tasks have open log files.
!> flushNow: flag indicating the message should be flushed immediately.
!> Note: error and critical error messages are always flushed immediately.
!> intArgs, realArgs, logicArgs: arrays of variable values to be inserted into the
!> message to replace the following characters: $i, $r, $l
!> intArgs, int8Args,realArgs, logicArgs: arrays of variable values to be inserted into the
!> message to replace the following characters: $i, $w, $r, $l
!> See routine log_expand_string below for details.
!>
!
!-----------------------------------------------------------------------

recursive subroutine mpas_log_write(message, messageType, masterOnly, flushNow, &
intArgs, realArgs, logicArgs, err)
intArgs, int8Args, realArgs, logicArgs, err)

use mpas_threading

Expand All @@ -492,6 +492,7 @@ recursive subroutine mpas_log_write(message, messageType, masterOnly, flushNow,
logical, intent(in), optional :: masterOnly !< Input: flag to only print message on master task
logical, intent(in), optional :: flushNow !< Input: flag to force a flush of the message buffer
integer, dimension(:), intent(in), optional :: intArgs !< Input: integer variable values to insert into message
integer(kind=I8KIND), dimension(:), intent(in), optional :: int8Args !< Input: integer variable values to insert into message
real(kind=RKIND), dimension(:), intent(in), optional :: realArgs !< Input: real variable values to insert into message
!< Input: exponential notation variable values to insert into message
logical, dimension(:), intent(in), optional :: logicArgs !< Input: logical variable values to insert into message
Expand Down Expand Up @@ -540,7 +541,7 @@ recursive subroutine mpas_log_write(message, messageType, masterOnly, flushNow,


! Construct message by expanding variable values as needed and inserting message type prefix
call log_expand_string(message, messageExpanded, intArgs=intArgs, logicArgs=logicArgs, realArgs=realArgs)
call log_expand_string(message, messageExpanded, intArgs=intArgs, int8Args=int8Args, logicArgs=logicArgs, realArgs=realArgs)

! Determine message prefix
select case (messageTypeHere)
Expand Down Expand Up @@ -870,6 +871,7 @@ end subroutine log_abort
!> The variables to be expanded are represented with a '$' symbol followed
!> by one of these indicators:
!> $i -> integer, formatted to be length of integer
!> $w -> integer(kind=I8KIND), formatted to be length of integer
!> $l -> logical, fomatted as 'T' or 'F'
!> $r -> real, formatted as 9 digits of precision for SP mode, 17 for DP mode
!> Floats are formatted using 'G' format which is smart about
Expand All @@ -886,7 +888,7 @@ end subroutine log_abort
!> can be handled by the string concatenation command (//).
!> This routine is based off of mpas_expand_string.
!-----------------------------------------------------------------------
subroutine log_expand_string(inString, outString, intArgs, logicArgs, realArgs)
subroutine log_expand_string(inString, outString, intArgs, int8Args, logicArgs, realArgs)

implicit none

Expand All @@ -896,6 +898,7 @@ subroutine log_expand_string(inString, outString, intArgs, logicArgs, realArgs)
character (len=*), intent(in) :: inString !< Input: message to be expanded

integer, dimension(:), intent(in), optional :: intArgs
integer(kind=I8KIND), dimension(:), intent(in), optional :: int8Args
!< Input, Optional: array of integer variable values to be used in expansion
logical, dimension(:), intent(in), optional :: logicArgs
!< Input, Optional: array of logical variable values to be used in expansion
Expand All @@ -915,8 +918,8 @@ subroutine log_expand_string(inString, outString, intArgs, logicArgs, realArgs)
! local variables
!-----------------------------------------------------------------
integer :: i, curLen
integer :: nInts, nLogicals, nReals, nExps !< the length of the variable arrays passed in
integer :: iInt, iLogical, iReal !< Counter for the current index into each variable array
integer :: nInts, nInt8s, nLogicals, nReals, nExps !< the length of the variable arrays passed in
integer :: iInt, iInt8, iLogical, iReal !< Counter for the current index into each variable array
character (len=ShortStrKIND) :: realFormat !< Format string to create to use for writing real variables to log file
integer :: realPrecision !< precision of a real variable

Expand All @@ -926,6 +929,7 @@ subroutine log_expand_string(inString, outString, intArgs, logicArgs, realArgs)

! Initialize the current index for each variable array to 1
iInt = 1
iInt8 = 1
iLogical = 1
iReal = 1

Expand All @@ -936,6 +940,12 @@ subroutine log_expand_string(inString, outString, intArgs, logicArgs, realArgs)
nInts = 0
endif

if (present(int8Args)) then
nInt8s = size(int8Args)
else
nInt8s = 0
endif

if (present(logicArgs)) then
nLogicals = size(logicArgs)
else
Expand Down Expand Up @@ -973,6 +983,15 @@ subroutine log_expand_string(inString, outString, intArgs, logicArgs, realArgs)
else
varPart = errVarPart
endif
case ('w')
! make the format large enough to include a large integer (up to 17 digits for 8-byte int)
! it will be trimmed below
if (iInt8 <= nInt8s) then
write(varPart,'(i17)') int8Args(iInt8)
iInt8 = iInt8 + 1
else
varPart = errVarPart
endif
case ('l')
if (iLogical <= nLogicals) then
if (logicArgs(iLogical)) then
Expand Down

0 comments on commit 09af9d7

Please sign in to comment.