better read file only once

This commit is contained in:
Martin Diehl 2019-10-12 21:58:26 +02:00
parent e6d25bfdab
commit 4c9bc326f6
1 changed files with 25 additions and 30 deletions

View File

@ -110,6 +110,8 @@ subroutine mesh_init(ip,el)
integer, intent(in) :: el, ip integer, intent(in) :: el, ip
integer, parameter :: FILEUNIT = 222 integer, parameter :: FILEUNIT = 222
character(len=pStringLen), dimension(:), allocatable :: inputFile !< file content, separated per lines
integer :: j, fileFormatVersion, elemType, & integer :: j, fileFormatVersion, elemType, &
mesh_maxNelemInSet, & mesh_maxNelemInSet, &
mesh_nElems, & mesh_nElems, &
@ -129,13 +131,13 @@ subroutine mesh_init(ip,el)
write(6,'(/,a)') ' <<<+- mesh init -+>>>' write(6,'(/,a)') ' <<<+- mesh init -+>>>'
mesh_unitlength = numerics_unitlength ! set physical extent of a length unit in mesh mesh_unitlength = numerics_unitlength ! set physical extent of a length unit in mesh
inputFile = IO_read_ASCII(trim(modelName)//trim(InputFileExtension))
myDebug = (iand(debug_level(debug_mesh),debug_levelBasic) /= 0) myDebug = (iand(debug_level(debug_mesh),debug_levelBasic) /= 0)
! parsing Marc input file ! parsing Marc input file
call IO_open_inputFile(FILEUNIT,modelName) call IO_open_inputFile(FILEUNIT,modelName)
fileFormatVersion = mesh_marc_get_fileFormat(FILEUNIT) fileFormatVersion = mesh_marc_get_fileFormat(inputFile)
call mesh_marc_get_tableStyles(initialcondTableStyle,hypoelasticTableStyle,FILEUNIT) call mesh_marc_get_tableStyles(initialcondTableStyle,hypoelasticTableStyle,inputFile)
if (fileFormatVersion > 12) & if (fileFormatVersion > 12) &
marc_matNumber = mesh_marc_get_matNumber(FILEUNIT,hypoelasticTableStyle) marc_matNumber = mesh_marc_get_matNumber(FILEUNIT,hypoelasticTableStyle)
call mesh_marc_count_nodesAndElements(mesh_nNodes, mesh_nElems, FILEUNIT) call mesh_marc_count_nodesAndElements(mesh_nNodes, mesh_nElems, FILEUNIT)
@ -223,55 +225,48 @@ end subroutine mesh_init
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief Figures out version of Marc input file format !> @brief Figures out version of Marc input file format
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
integer function mesh_marc_get_fileFormat(fileUnit) integer function mesh_marc_get_fileFormat(fileContent)
integer, intent(in) :: fileUnit character(len=pStringLen), dimension(:), intent(in) :: fileContent !< file content, separated per lines
integer, allocatable, dimension(:) :: chunkPos integer, allocatable, dimension(:) :: chunkPos
character(len=300) line integer :: l
do l = 1, size(fileContent)
rewind(fileUnit) chunkPos = IO_stringPos(fileContent(l))
do if ( IO_lc(IO_stringValue(fileContent(l),chunkPos,1)) == 'version') then
read (fileUnit,'(A300)',END=620) line mesh_marc_get_fileFormat = IO_intValue(fileContent(l),chunkPos,2)
chunkPos = IO_stringPos(line)
if ( IO_lc(IO_stringValue(line,chunkPos,1)) == 'version') then
mesh_marc_get_fileFormat = IO_intValue(line,chunkPos,2)
exit exit
endif endif
enddo enddo
620 end function mesh_marc_get_fileFormat end function mesh_marc_get_fileFormat
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief Figures out table styles for initial cond and hypoelastic !> @brief Figures out table styles for initial cond and hypoelastic
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
subroutine mesh_marc_get_tableStyles(initialcond,hypoelastic,fileUnit) subroutine mesh_marc_get_tableStyles(initialcond,hypoelastic,fileContent)
integer, intent(out) :: initialcond, hypoelastic integer, intent(out) :: initialcond, hypoelastic
integer, intent(in) :: fileUnit character(len=pStringLen), dimension(:), intent(in) :: fileContent !< file content, separated per lines
integer, allocatable, dimension(:) :: chunkPos integer, allocatable, dimension(:) :: chunkPos
character(len=300) line integer :: l
initialcond = 0 initialcond = 0
hypoelastic = 0 hypoelastic = 0
rewind(fileUnit) do l = 1, size(fileContent)
do chunkPos = IO_stringPos(fileContent(l))
read (fileUnit,'(A300)',END=620) line if ( IO_lc(IO_stringValue(fileContent(l),chunkPos,1)) == 'table' .and. chunkPos(1) > 5) then
chunkPos = IO_stringPos(line) initialcond = IO_intValue(fileContent(l),chunkPos,4)
hypoelastic = IO_intValue(fileContent(l),chunkPos,5)
if ( IO_lc(IO_stringValue(line,chunkPos,1)) == 'table' .and. chunkPos(1) > 5) then
initialcond = IO_intValue(line,chunkPos,4)
hypoelastic = IO_intValue(line,chunkPos,5)
exit exit
endif endif
enddo enddo
620 end subroutine mesh_marc_get_tableStyles end subroutine mesh_marc_get_tableStyles
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------