From f6ec92d87c62fd6cdc4896c5d2217a817a1462b0 Mon Sep 17 00:00:00 2001 From: kamischi <karl-michael.schindler@web.de> Date: Mon, 17 Jun 2024 16:52:37 +0200 Subject: [PATCH] Test for reading a variable number of real numbers The intention are the different terms for seteps. Lorentz, Drude and Kurosawa. --- testprograms/FortranReadInput.txt | 3 ++ testprograms/FortranReadTest.f90 | 47 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 testprograms/FortranReadInput.txt create mode 100644 testprograms/FortranReadTest.f90 diff --git a/testprograms/FortranReadInput.txt b/testprograms/FortranReadInput.txt new file mode 100644 index 0000000..0b230ce --- /dev/null +++ b/testprograms/FortranReadInput.txt @@ -0,0 +1,3 @@ +L 123.0 0.53 4.85 +D 457.0 358.45 +K 78324.5345 235.23 234.43 342.0 diff --git a/testprograms/FortranReadTest.f90 b/testprograms/FortranReadTest.f90 new file mode 100644 index 0000000..99290b4 --- /dev/null +++ b/testprograms/FortranReadTest.f90 @@ -0,0 +1,47 @@ +program FortranReadTest + + implicit none + + type :: termType + character (len = 1) :: mode + double precision, dimension (4) :: osc + end type termType + + type (termType), dimension (3) :: term + + integer :: i, j + + open (unit = 1, file = 'FortranReadInput.txt') + do i = 1, 3 + term(i) = parseTerm(1) + end do + close (1) + + do i = 1, 3 + write (*,*) term(i)%mode, (term(i)%osc(j), j = 1, 4) + enddo + + stop + + contains + + type (termType) function parseTerm(unit) + integer, intent (in) :: unit + + character (len = 300) :: line + integer :: i + + read (unit, '(A)') line + parseTerm%mode = line(1:1) + parseTerm%osc = 0 + select case (parseTerm%mode) + case ('L') + read(line(3:), *) (parseTerm%osc(i), i = 1, 3) + case ('D') + read(line(3:), *) (parseTerm%osc(i), i = 1, 2) + case ('K') + read(line(3:), *) (parseTerm%osc(i), i = 1, 4) +! case default + end select + end function parseTerm +end program FortranReadTest -- GitLab