From 1b1a574edc9e85c7c87bc906e781358cbfd2cfea Mon Sep 17 00:00:00 2001 From: JGonzalez Date: Fri, 23 Jan 2026 15:04:39 +0100 Subject: [PATCH] Read initial Now we can read an initial condition as we do with other formats. Only documentation left. --- .../mesh/inout/text/moduleMeshInputText.f90 | 38 +++++++++++++++++++ .../mesh/inout/vtu/moduleMeshInputVTU.f90 | 2 + 2 files changed, 40 insertions(+) diff --git a/src/modules/mesh/inout/text/moduleMeshInputText.f90 b/src/modules/mesh/inout/text/moduleMeshInputText.f90 index 26c7a6c..a41e6d3 100644 --- a/src/modules/mesh/inout/text/moduleMeshInputText.f90 +++ b/src/modules/mesh/inout/text/moduleMeshInputText.f90 @@ -182,12 +182,50 @@ module moduleMeshInputText end subroutine readText subroutine readInitialText(filename, density, velocity, temperature) + use moduleErrors implicit none character(:), allocatable, intent(in):: filename real(8), allocatable, intent(out), dimension(:):: density real(8), allocatable, intent(out), dimension(:,:):: velocity real(8), allocatable, intent(out), dimension(:):: temperature + integer:: fileID, reason + character(len=256):: line + integer:: nNodes + integer:: n + + fileID = 10 + + open(fileID, file=trim(filename)) + + do + read(fileID, *, iostat=reason) line + + if (reason > 0) then + call criticalError('Error reading mesh file', 'readText') + + else if (reason < 0) then + exit + + else if (len(line) > 0) then + nNodes = nNodes + 1 + + end if + + end do + + allocate(density(1:nNodes)) + allocate(velocity(1:nNodes, 1:3)) + allocate(temperature(1:nNodes)) + + rewind(fileID) + + do n = 1, nNodes + read(fileID, *) density(n), velocity(n, 1:3), temperature(n) + + end do + + close(fileID) end subroutine readInitialText diff --git a/src/modules/mesh/inout/vtu/moduleMeshInputVTU.f90 b/src/modules/mesh/inout/vtu/moduleMeshInputVTU.f90 index e07db01..c7b89b5 100644 --- a/src/modules/mesh/inout/vtu/moduleMeshInputVTU.f90 +++ b/src/modules/mesh/inout/vtu/moduleMeshInputVTU.f90 @@ -548,6 +548,8 @@ MODULE moduleMeshInputVTU CALL readDataBlock(fileID, numNodes, temperature) REWIND(fileID) + close(fileID) + END SUBROUTINE readInitialVTU END MODULE moduleMeshInputVTU