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