From 51c0d2716134d476bee80477df3b80d0342dbf0c Mon Sep 17 00:00:00 2001 From: Randy LeVeque Date: Wed, 29 May 2024 17:41:45 -0700 Subject: [PATCH 1/2] create gauge filenames that allow more than 5 digits in gauge number If fewer than 5 digits, still add zero padding e.g. gauge00012.txt but no longer throws an error for large gauge numbers, e.g. gauge1234567.txt --- src/2d/shallow/gauges_module.f90 | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/2d/shallow/gauges_module.f90 b/src/2d/shallow/gauges_module.f90 index 82b20e2a7..b00b11a41 100644 --- a/src/2d/shallow/gauges_module.f90 +++ b/src/2d/shallow/gauges_module.f90 @@ -58,8 +58,8 @@ module gauges_module integer :: gauge_num integer :: gdata_bytes - character(len=14) :: file_name ! for header (and data if 'ascii') - character(len=14) :: file_name_bin ! used if file_format='binary' + character(len=24) :: file_name ! for header (and data if 'ascii') + character(len=24) :: file_name_bin ! used if file_format='binary' ! Location in time and space real(kind=8) :: x, y, t_start, t_end @@ -116,6 +116,7 @@ subroutine set_gauges(restart, num_eqn, num_aux, fname) integer, parameter :: UNIT = 7 character(len=128) :: header_1 character(len=40) :: q_column, aux_column + character(len=15) :: numstr if (.not.module_setup) then @@ -206,18 +207,22 @@ subroutine set_gauges(restart, num_eqn, num_aux, fname) end do ! Create gauge output files + ! with format gauge00012.txt or gauge1234567.txt do i = 1, num_gauges - gauges(i)%file_name = 'gaugexxxxx.txt' ! ascii num = gauges(i)%gauge_num - do pos = 10, 6, -1 - digit = mod(num,10) - gauges(i)%file_name(pos:pos) = char(ichar('0') + digit) - num = num / 10 - end do + ! convert num to string numstr: + if (num > 100000) then + ! > 5 digits, no padding + write (numstr,'(I0)') num + else + ! <= 5 digits, add zero padding + write (numstr,'(I5.5)') num + endif + + gauges(i)%file_name = 'gauge'//trim(numstr)//'.txt' if (gauges(i)%file_format >= 2) then - gauges(i)%file_name_bin = gauges(i)%file_name - gauges(i)%file_name_bin(12:14) = 'bin' + gauges(i)%file_name_bin = 'gauge'//trim(numstr)//'.bin' endif @@ -243,7 +248,7 @@ subroutine set_gauges(restart, num_eqn, num_aux, fname) if (.not. restart) then ! Write header to .txt file: - header_1 = "('# gauge_id= ',i5,' " // & + header_1 = "('# gauge_id= ',i0,' " // & "location=( ',1e17.10,' ',1e17.10,' ) " // & "num_var= ',i2)" write(OUTGAUGEUNIT, header_1) gauges(i)%gauge_num, & From 794e75199bba070083971a0930a58536b83d1abe Mon Sep 17 00:00:00 2001 From: Randy LeVeque Date: Wed, 29 May 2024 17:46:07 -0700 Subject: [PATCH 2/2] cleaner way to zero pad only if fewer than 5 digits using I0.5 format --- src/2d/shallow/gauges_module.f90 | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/2d/shallow/gauges_module.f90 b/src/2d/shallow/gauges_module.f90 index b00b11a41..5c60833d2 100644 --- a/src/2d/shallow/gauges_module.f90 +++ b/src/2d/shallow/gauges_module.f90 @@ -207,18 +207,12 @@ subroutine set_gauges(restart, num_eqn, num_aux, fname) end do ! Create gauge output files - ! with format gauge00012.txt or gauge1234567.txt do i = 1, num_gauges num = gauges(i)%gauge_num - ! convert num to string numstr: - if (num > 100000) then - ! > 5 digits, no padding - write (numstr,'(I0)') num - else - ! <= 5 digits, add zero padding - write (numstr,'(I5.5)') num - endif + ! convert num to string numstr with zero padding if <5 digits + ! since we want format gauge00012.txt or gauge1234567.txt: + write (numstr,'(I0.5)') num gauges(i)%file_name = 'gauge'//trim(numstr)//'.txt' if (gauges(i)%file_format >= 2) then