From 94ff12b1cbc9b7d6b012d07c6042dd1e0193d492 Mon Sep 17 00:00:00 2001 From: JGonzalez Date: Sat, 27 Jul 2024 21:06:59 +0200 Subject: [PATCH] New subroutines in table These allow to invert the x and f arrays and make the X axis cumulative sum. --- src/modules/common/moduleTable.f90 | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/modules/common/moduleTable.f90 b/src/modules/common/moduleTable.f90 index 394fe37..a6b8c57 100644 --- a/src/modules/common/moduleTable.f90 +++ b/src/modules/common/moduleTable.f90 @@ -8,6 +8,8 @@ MODULE moduleTable PROCEDURE, PASS:: init => initTable1D PROCEDURE, PASS:: get => getValueTable1D PROCEDURE, PASS:: convert => convertUnits + PROCEDURE, PASS:: invertXF + PROCEDURE, PASS:: cumsumX END TYPE table1D @@ -126,4 +128,50 @@ MODULE moduleTable END SUBROUTINE convertUnits + ! Invert the arrays of x and f + SUBROUTINE invertXF(self) + IMPLICIT NONE + + CLASS(table1D), INTENT(inout):: self + REAL(8), ALLOCATABLE:: xTemp(:) + REAL(8):: xTempMin, xTempMax + + ! Store temporal x data + xTemp = self%x + xTempMin = self%xMin + xTempMax = self%xMax + + ! Replace x data with f data + self%x = self%f + self%xMin = self%fMin + self%xMax = self%fMax + + ! Put temporal x data in f data + self%f = xTemp + self%fMin = xTempMin + self%fMax = xTempMax + + END SUBROUTINE invertXF + + ! Makes the x axis its cumulative sum + SUBROUTINE cumSumX(self) + IMPLICIT NONE + + CLASS(table1D), INTENT(inout):: self + INTEGER:: nTotal, n + REAL(8), ALLOCATABLE:: cumX(:) + + nTotal = SIZE(self%x) + ALLOCATE(cumX(1:nTotal)) + cumX(1) = self%x(1) + DO n = 2, nTotal + cumX(n) = self%x(n) + cumX(n-1) + + END DO + + self%x = cumX / cumX(nTotal) + DEALLOCATE(cumX) + + END SUBROUTINE cumSumX + END MODULE moduleTable