From f24a580554da715e4d735e5a2f4c201bc967df83 Mon Sep 17 00:00:00 2001 From: Test User Date: Wed, 3 Jun 2020 18:35:46 +0200 Subject: [PATCH 1/5] [skip ci] updated version information after successful test of v2.0.3-2650-g512e54a7 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index a8b8fd56d..08fd9e952 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.0.3-2636-g45878b9f +v2.0.3-2650-g512e54a7 From a9e0e93213314d18300935a8e6fad6b4caa9d945 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 5 Jun 2020 13:38:40 +0200 Subject: [PATCH 2/5] need to handle case of zero length file when splitting --- src/IO.f90 | 4 ++-- src/grid/DAMASK_grid.f90 | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/IO.f90 b/src/IO.f90 index e6e3d4a60..8d56bdd70 100644 --- a/src/IO.f90 +++ b/src/IO.f90 @@ -11,7 +11,6 @@ module IO implicit none private character(len=*), parameter, public :: & - 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('DAMASK'), & !< end of line character @@ -86,6 +85,7 @@ function IO_readlines(fileName) result(fileContent) do l=1, len(rawData) if (rawData(l:l) == IO_EOL) N_lines = N_lines+1 enddo + if (l>1) then; if(rawData(l-1:l-1) /= IO_EOL) N_lines = N_lines+1; endif ! no EOL@EOF, need exception for empty file allocate(fileContent(N_lines)) !-------------------------------------------------------------------------------------------------- @@ -94,7 +94,7 @@ function IO_readlines(fileName) result(fileContent) startPos = 1 l = 1 do while (l <= N_lines) - endPos = startPos + scan(rawData(startPos:),IO_EOL) - 2 + endPos = merge(startPos + scan(rawData(startPos:),IO_EOL) - 2,len(rawData),l /= N_lines) if (endPos - startPos > pStringLen-1) then line = rawData(startPos:startPos+pStringLen-1) if (.not. warned) then diff --git a/src/grid/DAMASK_grid.f90 b/src/grid/DAMASK_grid.f90 index 7b3265740..8e57a56af 100644 --- a/src/grid/DAMASK_grid.f90 +++ b/src/grid/DAMASK_grid.f90 @@ -140,7 +140,8 @@ program DAMASK_grid !-------------------------------------------------------------------------------------------------- ! reading information from load case file and to sanity checks - fileContent = IO_read_ASCII(trim(loadCaseFile)) + fileContent = IO_readlines(trim(loadCaseFile)) + if(size(fileContent) == 0) call IO_error(307,ext_msg='No load case specified') allocate (loadCases(0)) ! array of load cases do currentLoadCase = 1, size(fileContent) From 9cd9ee71c5e9034e53262e76193b73d4fd34f4bc Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 5 Jun 2020 14:44:31 +0200 Subject: [PATCH 3/5] off-by-one issue fixed --- src/IO.f90 | 4 ++-- src/mesh/discretization_mesh.f90 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/IO.f90 b/src/IO.f90 index 8d56bdd70..608d70fba 100644 --- a/src/IO.f90 +++ b/src/IO.f90 @@ -94,7 +94,7 @@ function IO_readlines(fileName) result(fileContent) startPos = 1 l = 1 do while (l <= N_lines) - endPos = merge(startPos + scan(rawData(startPos:),IO_EOL) - 2,len(rawData),l /= N_lines) + endPos = merge(startPos + scan(rawData(startPos:),IO_EOL) - 2,len(rawData)-1,l /= N_lines) if (endPos - startPos > pStringLen-1) then line = rawData(startPos:startPos+pStringLen-1) if (.not. warned) then @@ -106,7 +106,7 @@ function IO_readlines(fileName) result(fileContent) endif startPos = endPos + 2 ! jump to next line start - fileContent(l) = line + fileContent(l) = trim(line)//'' l = l + 1 enddo diff --git a/src/mesh/discretization_mesh.f90 b/src/mesh/discretization_mesh.f90 index 0880de115..80db37e8d 100644 --- a/src/mesh/discretization_mesh.f90 +++ b/src/mesh/discretization_mesh.f90 @@ -119,7 +119,7 @@ subroutine discretization_mesh_init(restart) call MPI_Bcast(mesh_boundaries,mesh_Nboundaries,MPI_INTEGER,0,PETSC_COMM_WORLD,ierr) if (worldrank == 0) then - fileContent = IO_read_ASCII(geometryFile) + fileContent = IO_readlines(geometryFile) l = 0 do l = l + 1 From 5c544a6e4e9ce61eb682638c3f308ffb0f32a11d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 5 Jun 2020 20:58:36 +0200 Subject: [PATCH 4/5] bugfix - IO_read sanities files such that they end with EOL (unless 0 byte) - IO_readline simply counts EOL to determine number of lines --- src/IO.f90 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/IO.f90 b/src/IO.f90 index 608d70fba..362f4a8d5 100644 --- a/src/IO.f90 +++ b/src/IO.f90 @@ -85,7 +85,6 @@ function IO_readlines(fileName) result(fileContent) do l=1, len(rawData) if (rawData(l:l) == IO_EOL) N_lines = N_lines+1 enddo - if (l>1) then; if(rawData(l-1:l-1) /= IO_EOL) N_lines = N_lines+1; endif ! no EOL@EOF, need exception for empty file allocate(fileContent(N_lines)) !-------------------------------------------------------------------------------------------------- @@ -94,7 +93,7 @@ function IO_readlines(fileName) result(fileContent) startPos = 1 l = 1 do while (l <= N_lines) - endPos = merge(startPos + scan(rawData(startPos:),IO_EOL) - 2,len(rawData)-1,l /= N_lines) + endPos = startPos + scan(rawData(startPos:),IO_EOL) - 2 if (endPos - startPos > pStringLen-1) then line = rawData(startPos:startPos+pStringLen-1) if (.not. warned) then @@ -114,7 +113,8 @@ end function IO_readlines !-------------------------------------------------------------------------------------------------- -!> @brief reads an entire ASCII file into a string +!> @brief read ASCII file into a string +!> @details ensures that the string ends with a new line (expected UNIX behavior) !-------------------------------------------------------------------------------------------------- function IO_read(fileName) result(fileContent) @@ -130,10 +130,14 @@ function IO_read(fileName) result(fileContent) status='old', position='rewind', action='read',iostat=myStat) if(myStat /= 0) call IO_error(100,ext_msg=trim(fileName)) allocate(character(len=fileLength)::fileContent) + if(fileLength==0) return + read(fileUnit,iostat=myStat) fileContent - if(myStat > 0) call IO_error(102,ext_msg=trim(fileName)) ! <0 for ifort (https://software.intel.com/en-us/comment/1960081) + if(myStat /= 0) call IO_error(102,ext_msg=trim(fileName)) close(fileUnit) + if(fileContent(fileLength:fileLength) /= IO_EOL) fileContent = fileContent//IO_EOL ! ensure EOL@EOF + end function IO_read From 0e11d6f0498fef6ba200dd3d54112a44dbdf9bc3 Mon Sep 17 00:00:00 2001 From: Test User Date: Sun, 14 Jun 2020 15:51:48 +0200 Subject: [PATCH 5/5] [skip ci] updated version information after successful test of v2.0.3-2654-g5c544a6e --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 08fd9e952..4a0b49cc6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.0.3-2650-g512e54a7 +v2.0.3-2654-g5c544a6e