Skip to content

Commit cf4fa5d

Browse files
fangjianfangjian
authored andcommitted
fix bug reading input regarding sponge layer
1 parent 9a70334 commit cf4fa5d

File tree

2 files changed

+118
-3
lines changed

2 files changed

+118
-3
lines changed

src/readwrite.F90

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,17 @@ subroutine readinput
522522
use parallel,only : bcast
523523
use cmdefne, only : readkeyboad
524524
use bc, only : bctype,twall,xslip,turbinf,xrhjump,angshk
525+
use utility, only : line_2_strings
525526
!
526527
#ifdef COMB
527528
use thermchem,only: chemrep,chemread,thermdyn
528-
logical :: lfex
529529
#endif
530530
!
531531
! local data
532+
logical :: lfex
532533
character(len=64) :: inputfile
534+
character(len=255) :: lineread
535+
character(len=20),allocatable :: strings(:)
533536
character(len=5) :: char
534537
integer :: n,fh,i,ios
535538
!
@@ -629,8 +632,20 @@ subroutine readinput
629632
read(fh,'(/)')
630633
read(fh,*)ninit
631634
read(fh,'(/)')
632-
read(fh,*)spg_i0,spg_im,spg_j0,spg_jm,spg_k0,spg_km
633-
spg_def='layer'
635+
read(fh,'(A)')lineread
636+
strings=line_2_strings(lineread)
637+
read(strings(1),*)spg_i0
638+
read(strings(2),*)spg_im
639+
read(strings(3),*)spg_j0
640+
read(strings(4),*)spg_jm
641+
read(strings(5),*)spg_k0
642+
read(strings(6),*)spg_km
643+
print*, spg_i0,spg_im,spg_j0,spg_jm,spg_k0,spg_km
644+
if(size(strings)>6 .or. trim(strings(7))=='layer' .or. trim(strings(7))=='circl') then
645+
read(strings(7),*)spg_def
646+
else
647+
spg_def='layer'
648+
endif
634649
read(fh,'(/)')
635650
read(fh,'(A)')gridfile
636651
if(limmbou) then

src/utility.F90

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,106 @@ end subroutine progress_bar
682682
!| The end of the subroutine progress_bar. |
683683
!+-------------------------------------------------------------------+
684684

685+
686+
function line_2_strings(line) result(strings)
687+
688+
! arguments
689+
character(len=*), intent(in) :: line
690+
691+
! local data
692+
character(len=20), allocatable :: strings(:)
693+
character(len=20) :: token
694+
695+
integer :: n,i,istart
696+
697+
! Initialize counters
698+
699+
! Count number of tokens for allocation
700+
n = count_tokens(line)
701+
702+
! Allocate arrays based on the number of tokens
703+
allocate(strings(n))
704+
705+
! Split line into tokens and categorize them
706+
istart=1
707+
do i = 1, n
708+
call get_token(line, istart, token)
709+
strings(i) = token
710+
end do
711+
712+
return
713+
714+
end function line_2_strings
715+
716+
! Function to count tokens in a line
717+
integer function count_tokens(line)
718+
character(len=*), intent(in) :: line
719+
integer :: idx, len_line, count
720+
721+
count = 0
722+
idx = 1
723+
len_line = len_trim(line)
724+
725+
do while (idx <= len_line)
726+
! Skip delimiters
727+
if (line(idx:idx) == ' ' .or. line(idx:idx) == ',') then
728+
idx = idx + 1
729+
else
730+
count = count + 1
731+
! Skip the current token
732+
do while (idx <= len_line .and. &
733+
line(idx:idx) /= ' ' .and. line(idx:idx) /= ',')
734+
idx = idx + 1
735+
end do
736+
end if
737+
end do
738+
739+
count_tokens = count
740+
741+
end function count_tokens
742+
743+
744+
! Function to get each token from the line
745+
subroutine get_token(line, istart, token)
746+
character(len=*), intent(in) :: line
747+
integer, intent(inout) :: istart
748+
character(len=*), intent(out) :: token
749+
integer :: i, len_line
750+
751+
len_line = len_trim(line)
752+
token = ''
753+
i = istart
754+
do while (i <= len_line .and. (line(i:i) == ' ' .or. line(i:i) == ','))
755+
i = i + 1
756+
end do
757+
istart = i
758+
do while (i <= len_line .and. line(i:i) /= ' ' .and. line(i:i) /= ',')
759+
token = trim(adjustl(token)) // line(i:i)
760+
i = i + 1
761+
end do
762+
istart = i
763+
end subroutine get_token
764+
765+
! Function to check if a string is numeric
766+
logical function is_numeric(str)
767+
character(len=*), intent(in) :: str
768+
integer :: i, dot_count
769+
dot_count = 0
770+
is_numeric = .true.
771+
do i = 1, len_trim(str)
772+
if (str(i:i) == '.') then
773+
dot_count = dot_count + 1
774+
if (dot_count > 1) then
775+
is_numeric = .false.
776+
return
777+
end if
778+
else if (.not. (str(i:i) >= '0' .and. str(i:i) <= '9')) then
779+
is_numeric = .false.
780+
return
781+
end if
782+
end do
783+
end function is_numeric
784+
685785
end module utility
686786
!+---------------------------------------------------------------------+
687787
!| The end of the module utility |

0 commit comments

Comments
 (0)