From bf43156112764edef8d61ad9560ae5a11e064eeb Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 2 Jun 2018 06:32:16 +0200 Subject: [PATCH] search for global tags can stop once first section is found --- src/IO.f90 | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/IO.f90 b/src/IO.f90 index 7291f36ad..d1b039c1e 100644 --- a/src/IO.f90 +++ b/src/IO.f90 @@ -900,10 +900,10 @@ function IO_spotTagInPart(fileUnit,part,tag,Nsections) do while (trim(line) /= IO_EOF) line = IO_read(fileUnit) if (IO_isBlank(line)) cycle ! skip empty lines - if (IO_getTag(line,'<','>') /= '') then ! stop at next part + foundNextPart: if (IO_getTag(line,'<','>') /= '') then line = IO_read(fileUnit, .true.) ! reset IO_read exit - endif + endif foundNextPart if (IO_getTag(line,'[',']') /= '') section = section + 1_pInt ! found [section] identifier if (section > 0_pInt) then chunkPos = IO_stringPos(line) @@ -925,13 +925,10 @@ logical function IO_globalTagInPart(fileUnit,part,tag) character(len=*),intent(in) :: part, & !< part in which tag is searched for tag !< tag to search for - integer(pInt), allocatable, dimension(:) :: chunkPos - integer(pInt) :: section character(len=65536) :: line IO_globalTagInPart = .false. ! assume to nowhere spot tag - section = 0_pInt line ='' rewind(fileUnit) @@ -942,16 +939,20 @@ logical function IO_globalTagInPart(fileUnit,part,tag) do while (trim(line) /= IO_EOF) line = IO_read(fileUnit) if (IO_isBlank(line)) cycle ! skip empty lines - if (IO_getTag(line,'<','>') /= '') then ! stop at next part + foundNextPart: if (IO_getTag(line,'<','>') /= '') then line = IO_read(fileUnit, .true.) ! reset IO_read exit - endif - if (IO_getTag(line,'[',']') /= '') section = section + 1_pInt ! found [section] identifier - if (section == 0_pInt) then - chunkPos = IO_stringPos(line) - if (tag == trim(IO_lc(IO_stringValue(line,chunkPos,1_pInt)))) & ! match - IO_globalTagInPart = .true. - endif + endif foundNextPart + foundFirstSection: if (IO_getTag(line,'[',']') /= '') then + line = IO_read(fileUnit, .true.) ! reset IO_read + exit + endif foundFirstSection + chunkPos = IO_stringPos(line) + match: if (tag == trim(IO_lc(IO_stringValue(line,chunkPos,1_pInt)))) then + IO_globalTagInPart = .true. + line = IO_read(fileUnit, .true.) ! reset IO_read + exit + endif match enddo end function IO_globalTagInPart