single source of truth
This commit is contained in:
parent
9bfaf4fbfb
commit
cf8e3fb91a
45
src/IO.f90
45
src/IO.f90
|
@ -12,9 +12,11 @@ module IO
|
|||
implicit none
|
||||
private
|
||||
character(len=*), parameter, public :: &
|
||||
IO_EOF = '#EOF#' !< end of file string
|
||||
IO_EOF = '#EOF#', & !< end of file string
|
||||
IO_WHITESPACE = achar(44)//achar(32)//achar(9)//achar(10)//achar(13) !< whitespace characters
|
||||
character, parameter, public :: &
|
||||
IO_EOL = new_line(' ') !< end of line str
|
||||
IO_EOL = new_line('DAMASK'), & !< end of line character
|
||||
IO_COMMENT = '#'
|
||||
character(len=*), parameter, private :: &
|
||||
IO_DIVIDER = '───────────────────'//&
|
||||
'───────────────────'//&
|
||||
|
@ -172,14 +174,10 @@ logical pure function IO_isBlank(string)
|
|||
|
||||
character(len=*), intent(in) :: string !< string to check for content
|
||||
|
||||
character(len=*), parameter :: blankChar = achar(32)//achar(9)//achar(10)//achar(13) ! whitespaces
|
||||
character(len=*), parameter :: comment = achar(35) ! comment id '#'
|
||||
integer :: posNonBlank
|
||||
|
||||
integer :: posNonBlank, posComment
|
||||
|
||||
posNonBlank = verify(string,blankChar)
|
||||
posComment = scan(string,comment)
|
||||
IO_isBlank = posNonBlank == 0 .or. posNonBlank == posComment
|
||||
posNonBlank = verify(string,IO_WHITESPACE)
|
||||
IO_isBlank = posNonBlank == 0 .or. posNonBlank == scan(string,IO_COMMENT)
|
||||
|
||||
end function IO_isBlank
|
||||
|
||||
|
@ -194,18 +192,14 @@ pure function IO_getTag(string,openChar,closeChar)
|
|||
closeChar !< indicates end of tag
|
||||
character(len=:), allocatable :: IO_getTag
|
||||
|
||||
character(len=*), parameter :: SEP=achar(32)//achar(9)//achar(10)//achar(13) ! whitespaces
|
||||
integer :: left,right
|
||||
|
||||
if (openChar /= closeChar) then
|
||||
left = scan(string,openChar)
|
||||
right = scan(string,closeChar)
|
||||
else
|
||||
left = scan(string,openChar)
|
||||
right = left + merge(scan(string(left+1:),openChar),0,len(string) > left)
|
||||
endif
|
||||
right = merge(scan(string,closeChar), &
|
||||
left + merge(scan(string(left+1:),openChar),0,len(string) > left), &
|
||||
openChar /= closeChar)
|
||||
|
||||
foundTag: if (left == verify(string,SEP) .and. right > left) then
|
||||
foundTag: if (left == verify(string,IO_WHITESPACE) .and. right > left) then
|
||||
IO_getTag = string(left+1:right-1)
|
||||
else foundTag
|
||||
IO_getTag = ''
|
||||
|
@ -215,8 +209,8 @@ end function IO_getTag
|
|||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief locates all space-separated chunks in given string and returns array containing number
|
||||
!! them and the left/right position to be used by IO_xxxVal
|
||||
!> @brief locates all whitespace-separated chunks in given string and returns array containing
|
||||
!! number them and the left/right position to be used by IO_xxxVal
|
||||
!! Array size is dynamically adjusted to number of chunks found in string
|
||||
!! IMPORTANT: first element contains number of chunks!
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
|
@ -225,16 +219,15 @@ pure function IO_stringPos(string)
|
|||
character(len=*), intent(in) :: string !< string in which chunk positions are searched for
|
||||
integer, dimension(:), allocatable :: IO_stringPos
|
||||
|
||||
character(len=*), parameter :: SEP=achar(44)//achar(32)//achar(9)//achar(10)//achar(13) ! comma and whitespaces
|
||||
integer :: left, right
|
||||
|
||||
allocate(IO_stringPos(1), source=0)
|
||||
right = 0
|
||||
|
||||
do while (verify(string(right+1:),SEP)>0)
|
||||
left = right + verify(string(right+1:),SEP)
|
||||
right = left + scan(string(left:),SEP) - 2
|
||||
if ( string(left:left) == '#' ) exit
|
||||
do while (verify(string(right+1:),IO_WHITESPACE)>0)
|
||||
left = right + verify(string(right+1:),IO_WHITESPACE)
|
||||
right = left + scan(string(left:),IO_WHITESPACE) - 2
|
||||
if ( string(left:left) == IO_COMMENT) exit
|
||||
IO_stringPos = [IO_stringPos,left,right]
|
||||
IO_stringPos(1) = IO_stringPos(1)+1
|
||||
endOfString: if (right < left) then
|
||||
|
@ -704,6 +697,10 @@ subroutine unitTest
|
|||
chunkPos = IO_stringPos(str)
|
||||
if(3112019 /= IO_intValue(str,chunkPos,2)) call IO_error(0,ext_msg='IO_intValue')
|
||||
|
||||
if(.not. IO_isBlank(' ')) call IO_error(0,ext_msg='IO_isBlank/1')
|
||||
if(.not. IO_isBlank(' #isBlank')) call IO_error(0,ext_msg='IO_isBlank/2')
|
||||
if( IO_isBlank(' i#s')) call IO_error(0,ext_msg='IO_isBlank/3')
|
||||
|
||||
end subroutine unitTest
|
||||
|
||||
end module IO
|
||||
|
|
Loading…
Reference in New Issue