SUBROUTINE ReadTableData(CurveNum, CurrentModuleObject, ReadFromFile, FileName, Alphas, Numbers, NumNumbers, ErrorsFound)
! SUBROUTINE INFORMATION:
! AUTHOR Richard Raustad, FSEC
! DATE WRITTEN August 2010
! MODIFIED na
! RE-ENGINEERED na
! PURPOSE OF THIS SUBROUTINE:
! Given the curve index, read the table data.
! METHODOLOGY EMPLOYED:
! na
! REFERENCES:
! na
! USE STATEMENTS:
USE General, ONLY: RoundSigDigits
USE DataGlobals, ONLY: DisplayAdvancedReportVariables, OutputFileInits
USE DataSystemVariables, ONLY: iASCII_CR, iUnicode_end,GoodIOStatValue,TempFullFileName,CheckForActualFileName
! SUBROUTINE ARGUMENT DEFINITIONS:
INTEGER, INTENT(IN) :: CurveNum
CHARACTER(len=MaxNameLength) :: CurrentModuleObject
LOGICAL, INTENT(IN) :: ReadFromFile
CHARACTER(len=MaxNameLength) :: FileName
CHARACTER(len=MaxNameLength), DIMENSION(:) :: Alphas
REAL(r64), DIMENSION(:) :: Numbers
INTEGER, INTENT(IN) :: NumNumbers
LOGICAL, INTENT(INOUT) :: ErrorsFound
! SUBROUTINE PARAMETER DEFINITIONS:
CHARACTER(len=*), PARAMETER :: fmtA="(A)"
! INTERFACE BLOCK SPECIFICATIONS
! na
! DERIVED TYPE DEFINITIONS
! na
! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
INTEGER :: FileNum
INTEGER,EXTERNAL :: GetNewUnitNumber
INTEGER :: endcol
INTEGER :: TableNum
CHARACTER(len=400) :: NextLine ! Line of data
INTEGER :: DataSetCount ! counter for number of lines read (used in some error messages)
INTEGER :: ReadStat ! File read status
LOGICAL :: EOFonFile ! True if EOF during file read
INTEGER :: I, J, NumDataSets ! Do loop indexes and data set counter
REAL(r64) :: Var3, Var4, Var5 ! Temp variables for processing table lookup data
INTEGER :: Var3Index, Var4Index, Var5Index, NumIVars, TotalDataSets
INTEGER :: NumbersOffset, BaseOffset
LOGICAL, SAVE :: WriteHeaderOnce = .TRUE. ! eio header file write flag
CHARACTER(len=1000) :: CharTableData ! used to echo each line of table data read in to eio file
LOGICAL :: EchoTableDataToEio ! logical set equal to global and used to report to eio file
LOGICAL :: FileExists
EchoTableDataToEio = DisplayAdvancedReportVariables
TableNum = PerfCurve(CurveNum)%TableIndex
140 FORMAT('! Reading external file tabular data for ',A,' "',A,'"')
150 FORMAT('! Reading tabular data for ',A,' "',A,'"')
TotalDataSets = 0 !Objexx:Uninit GO TO 1000 will cause TotalDataSets to be used before it is initialized: Line added
IF(ReadFromFile)THEN
FileExists=.false.
CALL CheckForActualFileName(FileName,FileExists,TempFullFileName)
IF (.not. FileExists) GOTO 999
FileNum = GetNewUnitNumber()
OPEN(UNIT=FileNum, FILE=TempFullFileName, Action='read', Err=999)
READ(Unit=FileNum,FMT=fmtA) NextLine
endcol=LEN_TRIM(NextLine)
IF(endcol == 0)THEN
CALL ShowWarningError('ReadTableData: Blank line found in external file = '//TRIM(FileName))
CALL ShowContinueError('...Blank lines are not allowed. Will try to read next line.')
READ(Unit=FileNum, FMT=fmtA) NextLine
endcol=LEN_TRIM(NextLine)
IF(endcol == 0)THEN
CALL ShowWarningError('ReadTableData: Data not found on second line in external file = '//TRIM(FileName))
CALL ShowContinueError('...Check that file is ASCII text and that file is not locked by other applications.')
CALL ShowFatalError('External table data not found. Simulation will terminate.')
ELSE
CALL ShowWarningError('Second read attempt found data in external file = '//TRIM(FileName))
CALL ShowFatalError('...Blank lines are not allowed. Simulation will terminate.')
END IF
END IF
IF (endcol > 0) THEN
IF (ICHAR(NextLine(endcol:endcol)) == iUnicode_end) THEN
CALL ShowSevereError('ReadTableData: For Table:MultiVariableLookup "'//TRIM(PerfCurve(CurveNum)%Name)//'" '// &
' external file, appears to be a Unicode or binary file.')
CALL ShowContinueError('...This file cannot be read by this program. Please save as PC or Unix file and try again')
CALL ShowFatalError('Program terminates due to previous condition.')
ENDIF
ENDIF
REWIND(FileNum)
READ(FileNum,*,IOSTAT=ReadStat)NumIVars
IF(NumIVars > 5 .OR. NumIVars < 1)THEN
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...Invalid number of independent variables found in external file = '//TRIM(FileName))
CALL ShowFatalError('...Only 1 to 5 independent variables are allowed.')
END IF
REWIND(FileNum)
IF(NumIVars .EQ. 1)READ(FileNum,*,IOSTAT=ReadStat)NumIVars, &
TableLookup(TableNum)%NumX1Vars
IF(NumIVars .EQ. 2)READ(FileNum,*,IOSTAT=ReadStat)NumIVars, &
TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars
IF(NumIVars .EQ. 3)READ(FileNum,*,IOSTAT=ReadStat)NumIVars, &
TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars, &
TableLookup(TableNum)%NumX3Vars
IF(NumIVars .EQ. 4)READ(FileNum,*,IOSTAT=ReadStat)NumIVars, &
TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars, &
TableLookup(TableNum)%NumX3Vars, &
TableLookup(TableNum)%NumX4Vars
IF(NumIVars .EQ. 5)READ(FileNum,*,IOSTAT=ReadStat)NumIVars, &
TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars, &
TableLookup(TableNum)%NumX3Vars, &
TableLookup(TableNum)%NumX4Vars, &
TableLookup(TableNum)%NumX5Vars
IF(ReadStat < GoodIOStatValue) GO TO 1000
TableLookup(TableNum)%NumIndependentVars = NumIVars
! Echo table data for user verification
110 FORMAT('! <READING LOOKUP TABLE DATA>')
130 FORMAT('READING LOOKUP TABLE DATA')
131 FORMAT('END READING LOOKUP TABLE DATA')
IF(EchoTableDataToEio)THEN
IF(WriteHeaderOnce)THEN
WRITE(OutputFileInits,110)
WriteHeaderOnce = .FALSE.
END IF
WRITE(OutputFileInits,130)
WRITE(OutputFileInits,140)TRIM(CurrentModuleObject),TRIM(Alphas(1))
END IF
ELSE
IF(EchoTableDataToEio)THEN
IF(WriteHeaderOnce)THEN
WRITE(OutputFileInits,110)
WriteHeaderOnce = .FALSE.
END IF
WRITE(OutputFileInits,130)
WRITE(OutputFileInits,150)TRIM(CurrentModuleObject),TRIM(Alphas(1))
END IF
NumIVars = Numbers(15)
IF(NumIVars > 5 .OR. NumIVars < 1)THEN
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...Invalid number of independent variables.')
CALL ShowFatalError('...Only 1 to 5 independent variables are allowed.')
END IF
BaseOffset = 15
TableLookup(TableNum)%NumIndependentVars = NumIVars
TableLookup(TableNum)%NumX1Vars = Numbers(16)
IF(NumIVars .GT. 1)TableLookup(TableNum)%NumX2Vars = Numbers(17)
IF(NumIVars .GT. 2)TableLookup(TableNum)%NumX3Vars = Numbers(18)
IF(NumIVars .GT. 3)TableLookup(TableNum)%NumX4Vars = Numbers(19)
IF(NumIVars .GT. 4)TableLookup(TableNum)%NumX5Vars = Numbers(20)
END IF
IF(EchoTableDataToEio)THEN
IF(NumIVars .EQ. 1)THEN
WRITE(CharTableData,160)NumIVars,TableLookup(TableNum)%NumX1Vars
ELSEIF(NumIVars .EQ. 2)THEN
WRITE(CharTableData,160)NumIVars,TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars
ELSEIF(NumIVars .EQ. 3)THEN
WRITE(CharTableData,160)NumIVars,TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars, &
TableLookup(TableNum)%NumX3Vars
ELSEIF(NumIVars .EQ. 4)THEN
WRITE(CharTableData,160)NumIVars,TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars, &
TableLookup(TableNum)%NumX3Vars, &
TableLookup(TableNum)%NumX4Vars
ELSE
WRITE(CharTableData,160)NumIVars,TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars, &
TableLookup(TableNum)%NumX3Vars, &
TableLookup(TableNum)%NumX4Vars, &
TableLookup(TableNum)%NumX5Vars
END IF
160 FORMAT(1X,10(I2,2X))
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
ALLOCATE(TableLookup(TableNum)%X1Var(TableLookup(TableNum)%NumX1Vars))
ALLOCATE(TableLookup(TableNum)%X2Var(TableLookup(TableNum)%NumX2Vars))
ALLOCATE(TableLookup(TableNum)%X3Var(TableLookup(TableNum)%NumX3Vars))
ALLOCATE(TableLookup(TableNum)%X4Var(TableLookup(TableNum)%NumX4Vars))
ALLOCATE(TableLookup(TableNum)%X5Var(TableLookup(TableNum)%NumX5Vars))
IF(NumIVars .GT. 0)THEN
IF(ReadFromfile)THEN
READ(FileNum,*,IOSTAT=ReadStat)(TableLookup(TableNum)%X1Var(I), &
I=1,TableLookup(TableNum)%NumX1Vars)
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)(TableLookup(TableNum)%X1Var(I), &
I=1,TableLookup(TableNum)%NumX1Vars)
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
IF(NumNumbers .GE. BaseOffset + NumIVars + TableLookup(TableNum)%NumX1Vars)THEN
DO I = 1, TableLookup(TableNum)%NumX1Vars
TableLookup(TableNum)%X1Var(I) = Numbers(BaseOffset + NumIVars + I)
END DO
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)(TableLookup(TableNum)%X1Var(I), &
I=1,TableLookup(TableNum)%NumX1Vars)
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
ELSE
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...The number of numeric inputs is less than expected.')
ErrorsFound=.true.
END IF
END IF
! check to make sure XVars are in increaseing (ascending) order
DO I = 1, TableLookup(TableNum)%NumX1Vars
IF(I.EQ. 1)CYCLE
IF(TableLookup(TableNum)%X1Var(I) .LE. &
TableLookup(TableNum)%X1Var(I-1))THEN
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...The values for the independent variable X1 must be in increasing (ascending) order.')
ErrorsFound=.true.
EXIT
END IF
END DO
IF(NumIVars .GT. 1)THEN
IF(ReadFromfile)THEN
READ(FileNum,*,IOSTAT=ReadStat)(TableLookup(TableNum)%X2Var(I), &
I=1,TableLookup(TableNum)%NumX2Vars)
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)(TableLookup(TableNum)%X2Var(I), &
I=1,TableLookup(TableNum)%NumX2Vars)
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
IF(NumNumbers .GE. BaseOffset + NumIVars + TableLookup(TableNum)%NumX1Vars + &
TableLookup(TableNum)%NumX2Vars)THEN
DO I = 1, TableLookup(TableNum)%NumX2Vars
TableLookup(TableNum)%X2Var(I) = Numbers(BaseOffset + NumIVars + &
TableLookup(TableNum)%NumX1Vars + I)
END DO
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)(TableLookup(TableNum)%X2Var(I), &
I=1,TableLookup(TableNum)%NumX2Vars)
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
ELSE
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...The number of numeric inputs is less than expected.')
ErrorsFound=.true.
END IF
END IF
! check to make sure XVars are in increaseing (ascending) order
DO I = 1, TableLookup(TableNum)%NumX2Vars
IF(I.EQ. 1)CYCLE
IF(TableLookup(TableNum)%X2Var(I) .LE. &
TableLookup(TableNum)%X2Var(I-1))THEN
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...The values for the independent variable X2 must be in increasing (ascending) order.')
ErrorsFound=.true.
EXIT
END IF
END DO
IF(NumIVars .GT. 2)THEN
IF(ReadFromfile)THEN
READ(FileNum,*,IOSTAT=ReadStat)(TableLookup(TableNum)%X3Var(I), &
I=1,TableLookup(TableNum)%NumX3Vars)
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)(TableLookup(TableNum)%X3Var(I), &
I=1,TableLookup(TableNum)%NumX3Vars)
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
IF(NumNumbers .GE. BaseOffset + NumIVars + TableLookup(TableNum)%NumX1Vars + &
TableLookup(TableNum)%NumX2Vars + &
TableLookup(TableNum)%NumX3Vars)THEN
DO I = 1, TableLookup(TableNum)%NumX3Vars
TableLookup(TableNum)%X3Var(I) = Numbers(BaseOffset + NumIVars + &
TableLookup(TableNum)%NumX1Vars + &
TableLookup(TableNum)%NumX2Vars + I)
END DO
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)(TableLookup(TableNum)%X3Var(I), &
I=1,TableLookup(TableNum)%NumX3Vars)
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
ELSE
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...The number of numeric inputs is less than expected.')
ErrorsFound=.true.
END IF
END IF
! check to make sure XVars are in increaseing (ascending) order
DO I = 1, TableLookup(TableNum)%NumX3Vars
IF(I.EQ. 1)CYCLE
IF(TableLookup(TableNum)%X3Var(I) .LE. &
TableLookup(TableNum)%X3Var(I-1))THEN
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...The values for the independent variable X3 must be in increasing (ascending) order.')
ErrorsFound=.true.
EXIT
END IF
END DO
IF(NumIVars .GT. 3)THEN
IF(ReadFromfile)THEN
READ(FileNum,*,IOSTAT=ReadStat)(TableLookup(TableNum)%X4Var(I), &
I=1,TableLookup(TableNum)%NumX4Vars)
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)(TableLookup(TableNum)%X4Var(I), &
I=1,TableLookup(TableNum)%NumX4Vars)
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
IF(NumNumbers .GE. BaseOffset + NumIVars + TableLookup(TableNum)%NumX1Vars + &
TableLookup(TableNum)%NumX2Vars + &
TableLookup(TableNum)%NumX3Vars + &
TableLookup(TableNum)%NumX4Vars)THEN
DO I = 1, TableLookup(TableNum)%NumX4Vars
TableLookup(TableNum)%X4Var(I) = Numbers(BaseOffset + NumIVars + &
TableLookup(TableNum)%NumX1Vars + &
TableLookup(TableNum)%NumX2Vars + &
TableLookup(TableNum)%NumX3Vars + I)
END DO
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)(TableLookup(TableNum)%X4Var(I), &
I=1,TableLookup(TableNum)%NumX4Vars)
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
ELSE
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...The number of numeric inputs is less than expected.')
ErrorsFound=.true.
END IF
END IF
! check to make sure XVars are in increaseing (ascending) order
DO I = 1, TableLookup(TableNum)%NumX4Vars
IF(I.EQ. 1)CYCLE
IF(TableLookup(TableNum)%X4Var(I) .LE. &
TableLookup(TableNum)%X4Var(I-1))THEN
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...The values for the independent variable X4 must be in increasing (ascending) order.')
ErrorsFound=.true.
EXIT
END IF
END DO
IF(NumIVars .GT. 4)THEN
IF(ReadFromfile)THEN
READ(FileNum,*,IOSTAT=ReadStat)(TableLookup(TableNum)%X5Var(I), &
I=1,TableLookup(TableNum)%NumX5Vars)
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)(TableLookup(TableNum)%X5Var(I), &
I=1,TableLookup(TableNum)%NumX5Vars)
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
IF(NumNumbers .GE. BaseOffset + NumIVars + TableLookup(TableNum)%NumX1Vars + &
TableLookup(TableNum)%NumX2Vars + &
TableLookup(TableNum)%NumX3Vars + &
TableLookup(TableNum)%NumX4Vars + &
TableLookup(TableNum)%NumX5Vars)THEN
DO I = 1, TableLookup(TableNum)%NumX5Vars
TableLookup(TableNum)%X5Var(I) = Numbers(BaseOffset + NumIVars + &
TableLookup(TableNum)%NumX1Vars + &
TableLookup(TableNum)%NumX2Vars + &
TableLookup(TableNum)%NumX3Vars + &
TableLookup(TableNum)%NumX4Vars + I)
END DO
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)(TableLookup(TableNum)%X5Var(I), &
I=1,TableLookup(TableNum)%NumX5Vars)
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
ELSE
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...The number of numeric inputs is less than expected.')
ErrorsFound=.true.
END IF
END IF
! check to make sure XVars are in increaseing (ascending) order
DO I = 1, TableLookup(TableNum)%NumX5Vars
IF(I.EQ. 1)CYCLE
IF(TableLookup(TableNum)%X5Var(I) .LE. &
TableLookup(TableNum)%X5Var(I-1))THEN
CALL ShowSevereError('ReadTableData: For '//TRIM(CurrentModuleObject)//': '//TRIM(Alphas(1)))
CALL ShowContinueError('...The values for the independent variable X5 must be in increasing (ascending) order.')
ErrorsFound=.true.
EXIT
END IF
END DO
ALLOCATE(TableLookup(TableNum)%TableLookupZData &
(TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars, &
TableLookup(TableNum)%NumX3Vars, &
TableLookup(TableNum)%NumX4Vars, &
TableLookup(TableNum)%NumX5Vars))
ELSE
ALLOCATE(TableLookup(TableNum)%TableLookupZData &
(TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars, &
TableLookup(TableNum)%NumX3Vars, &
TableLookup(TableNum)%NumX4Vars,1))
END IF
ELSE
ALLOCATE(TableLookup(TableNum)%TableLookupZData &
(TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars, &
TableLookup(TableNum)%NumX3Vars,1,1))
END IF
ELSE
ALLOCATE(TableLookup(TableNum)%TableLookupZData &
(TableLookup(TableNum)%NumX1Vars, &
TableLookup(TableNum)%NumX2Vars,1,1,1))
END IF
ELSE
ALLOCATE(TableLookup(TableNum)%TableLookupZData &
(TableLookup(TableNum)%NumX1Vars,1,1,1,1))
END IF
END IF
TotalDataSets = 1
DataSetCount = 0
IF(NumIVars .EQ. 3)TotalDataSets = TableLookup(TableNum)%NumX3Vars
IF(NumIVars .EQ. 4)TotalDataSets = TableLookup(TableNum)%NumX3Vars * &
TableLookup(TableNum)%NumX4Vars
IF(NumIVars .EQ. 5)TotalDataSets = TableLookup(TableNum)%NumX3Vars * &
TableLookup(TableNum)%NumX4Vars * &
TableLookup(TableNum)%NumX5Vars
NumbersOffset = 15 + NumIVars + TableLookup(TableNum)%NumX1Vars + &
TableLookup(TableNum)%NumX2Vars + &
TableLookup(TableNum)%NumX3Vars + &
TableLookup(TableNum)%NumX4Vars + &
TableLookup(TableNum)%NumX5Vars + 1
! initialize NumX2Vars to 1 so the DO loops work correctly
IF(NumIVars .EQ. 1)TableLookup(TableNum)%NumX2Vars = 1
DO NumDataSets = 1, TotalDataSets
IF(NumIVars .EQ. 3)THEN
IF(ReadFromfile)THEN
READ(FileNum,*,IOSTAT=ReadStat)Var3
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)Var3
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
Var3 = Numbers(NumbersOffset)
NumbersOffset = NumbersOffset + 1
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)Var3
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
END IF
ELSE IF(NumIVars .EQ. 4)THEN
IF(ReadFromfile)THEN
READ(FileNum,*,IOSTAT=ReadStat)Var3, Var4
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)Var3,' ',Var4
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
Var3 = Numbers(NumbersOffset)
Var4 = Numbers(NumbersOffset + 1)
NumbersOffset = NumbersOffset + 2
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)Var3,' ',Var4
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
END IF
ELSE IF(NumIVars .EQ. 5)THEN
IF(ReadFromfile)THEN
READ(FileNum,*,IOSTAT=ReadStat)Var3, Var4, Var5
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)Var3,' ',Var4,' ',Var5
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
Var3 = Numbers(NumbersOffset)
Var4 = Numbers(NumbersOffset + 1)
Var5 = Numbers(NumbersOffset + 2)
NumbersOffset = NumbersOffset + 3
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*)Var3,' ',Var4,' ',Var5
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
END IF
END IF
IF(NumIVars .GT. 2)THEN
Var3Index = 0
! match the independent variable values to the allowed values to find the index. Input must match allowed values.
DO I = 1, TableLookup(TableNum)%NumX3Vars
IF(Var3 .NE. TableLookup(TableNum)%X3Var(I))CYCLE
Var3Index = I
EXIT
END DO
IF(Var3Index .EQ. 0)THEN
CALL ShowSevereError('GetTableDataFile: For Table:MultiVariableLookup "'//TRIM(PerfCurve(CurveNum)%Name)//'" ')
CALL ShowContinueError('...The value of the 3rd independent variable ('//TRIM(RoundSigDigits(Var3,9))//')'// &
' does not match the values listed as valid entries for this independent variable.')
CALL ShowContinueError('...Valid entries are: ')
IF(TableLookup(TableNum)%NumX3Vars .GE. 1) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X3Var(1),9)))
IF(TableLookup(TableNum)%NumX3Vars .GE. 2) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X3Var(2),9)))
IF(TableLookup(TableNum)%NumX3Vars .GE. 3) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X3Var(3),9)))
IF(TableLookup(TableNum)%NumX3Vars .GE. 4) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X3Var(4),9)))
IF(TableLookup(TableNum)%NumX3Vars .GE. 5) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X3Var(5),9)))
IF(TableLookup(TableNum)%NumX3Vars .GE. 6) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X3Var(6),9)))
IF(TableLookup(TableNum)%NumX3Vars .GE. 7) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X3Var(7),9)))
IF(TableLookup(TableNum)%NumX3Vars .GE. 8) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X3Var(8),9)))
IF(TableLookup(TableNum)%NumX3Vars .GE. 9) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X3Var(9),9)))
IF(TableLookup(TableNum)%NumX3Vars .GE. 10) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X3Var(10),9)))
CALL ShowContinueError('...This occurs for data set = '//TRIM(RoundSigDigits(DataSetCount + 1,0))//' in data file = '// &
TRIM(FileName))
ErrorsFound = .TRUE.
Var3Index = 1
END IF
ELSE
Var3Index = 1
END IF
IF(NumIVars .GT. 3)THEN
Var4Index = 0
! match the independent variable values to the allowed values to find the index. Input must match allowed values.
DO I = 1, TableLookup(TableNum)%NumX4Vars
IF(Var4 .NE. TableLookup(TableNum)%X4Var(I))CYCLE
Var4Index = I
EXIT
END DO
IF(Var4Index .EQ. 0)THEN
CALL ShowSevereError('GetTableDataFile: For Table:MultiVariableLookup "'//TRIM(PerfCurve(CurveNum)%Name)//'" ')
CALL ShowContinueError('...The value of the 4th independent variable ('//TRIM(RoundSigDigits(Var4,9))//')'// &
' does not match the values listed as valid entries for this independent variable.')
CALL ShowContinueError('...Valid entries are: ')
IF(TableLookup(TableNum)%NumX4Vars .GE. 1) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X4Var(1),9)))
IF(TableLookup(TableNum)%NumX4Vars .GE. 2) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X4Var(2),9)))
IF(TableLookup(TableNum)%NumX4Vars .GE. 3) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X4Var(3),9)))
IF(TableLookup(TableNum)%NumX4Vars .GE. 4) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X4Var(4),9)))
IF(TableLookup(TableNum)%NumX4Vars .GE. 5) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X4Var(5),9)))
IF(TableLookup(TableNum)%NumX4Vars .GE. 6) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X4Var(6),9)))
IF(TableLookup(TableNum)%NumX4Vars .GE. 7) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X4Var(7),9)))
IF(TableLookup(TableNum)%NumX4Vars .GE. 8) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X4Var(8),9)))
IF(TableLookup(TableNum)%NumX4Vars .GE. 9) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X4Var(9),9)))
IF(TableLookup(TableNum)%NumX4Vars .GE. 10) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X4Var(10),9)))
CALL ShowContinueError('...This occurs for data set = '//TRIM(RoundSigDigits(DataSetCount + 1,0))//' in data file = '// &
TRIM(FileName))
ErrorsFound = .TRUE.
Var4Index = 1
END IF
ELSE
Var4Index = 1
END IF
IF(NumIVars .GT. 4)THEN
Var5Index = 0
! match the independent variable values to the allowed values to find the index. Input must match allowed values.
DO I = 1, TableLookup(TableNum)%NumX5Vars
IF(Var5 .NE. TableLookup(TableNum)%X5Var(I))CYCLE
Var5Index = I
EXIT
END DO
IF(Var5Index .EQ. 0 .AND. NumIVars .GT. 4)THEN
CALL ShowSevereError('GetTableDataFile: For Table:MultiVariableLookup "'//TRIM(PerfCurve(CurveNum)%Name)//'" ')
CALL ShowContinueError('...The value of the 5th independent variable ('//TRIM(RoundSigDigits(Var5,9))//')'// &
' does not match the values listed as valid entries for this independent variable.')
CALL ShowContinueError('...Valid entries are: ')
IF(TableLookup(TableNum)%NumX5Vars .GE. 1) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X5Var(1),9)))
IF(TableLookup(TableNum)%NumX5Vars .GE. 2) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X5Var(2),9)))
IF(TableLookup(TableNum)%NumX5Vars .GE. 3) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X5Var(3),9)))
IF(TableLookup(TableNum)%NumX5Vars .GE. 4) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X5Var(4),9)))
IF(TableLookup(TableNum)%NumX5Vars .GE. 5) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X5Var(5),9)))
IF(TableLookup(TableNum)%NumX5Vars .GE. 6) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X5Var(6),9)))
IF(TableLookup(TableNum)%NumX5Vars .GE. 7) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X5Var(7),9)))
IF(TableLookup(TableNum)%NumX5Vars .GE. 8) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X5Var(8),9)))
IF(TableLookup(TableNum)%NumX5Vars .GE. 9) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X5Var(9),9)))
IF(TableLookup(TableNum)%NumX5Vars .GE. 10) &
CALL ShowContinueError('...'//TRIM(RoundSigDigits(TableLookup(TableNum)%X5Var(10),9)))
CALL ShowContinueError('...This occurs for data set = '//TRIM(RoundSigDigits(DataSetCount + 1,0))//' in data file = '// &
TRIM(FileName))
ErrorsFound = .TRUE.
Var5Index = 1
END IF
ELSE
Var5Index = 1
END IF
! now read in X1 | X2 matrix data set
IF(PerfCurve(CurveNum)%X1SortOrder == ASCENDING)THEN
IF(PerfCurve(CurveNum)%X2SortOrder == ASCENDING)THEN
DO J = 1, TableLookup(TableNum)%NumX2Vars
IF(ReadFromFile)THEN
READ(FileNum,*,IOSTAT=ReadStat) &
(TableLookup(TableNum)%TableLookupZData(I,J,Var3Index,Var4Index,Var5Index), &
I=1,TableLookup(TableNum)%NumX1Vars)
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
DO I = 1,TableLookup(TableNum)%NumX1Vars
TableLookup(TableNum)%TableLookupZData(I,J,Var3Index,Var4Index,Var5Index)= &
Numbers(NumbersOffset)
NumbersOffset = NumbersOffset + 1
END DO
END IF
END DO
ELSE ! PerfCurve(CurveNum)%X2SortOrder == DESCENDING
DO J = TableLookup(TableNum)%NumX2Vars, 1, -1
IF(ReadFromFile)THEN
READ(FileNum,*,IOSTAT=ReadStat) &
(TableLookup(TableNum)%TableLookupZData(I,J,Var3Index,Var4Index,Var5Index), &
I=1,TableLookup(TableNum)%NumX1Vars)
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
DO I = 1,TableLookup(TableNum)%NumX1Vars
TableLookup(TableNum)%TableLookupZData(I,J,Var3Index,Var4Index,Var5Index)= &
Numbers(NumbersOffset)/TableData(TableNum)%NormalPoint
NumbersOffset = NumbersOffset + 1
END DO
END IF
END DO
END IF
ELSE ! PerfCurve(CurveNum)%X1SortOrder == DESCENDING
IF(PerfCurve(CurveNum)%X2SortOrder == ASCENDING)THEN
DO J = 1, TableLookup(TableNum)%NumX2Vars
IF(ReadFromFile)THEN
READ(FileNum,*,IOSTAT=ReadStat) &
(TableLookup(TableNum)%TableLookupZData(I,J,Var3Index,Var4Index,Var5Index), &
I=TableLookup(TableNum)%NumX1Vars,1,-1)
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
DO I = TableLookup(TableNum)%NumX1Vars,1,-1
TableLookup(TableNum)%TableLookupZData(I,J,Var3Index,Var4Index,Var5Index)= &
Numbers(NumbersOffset)
NumbersOffset = NumbersOffset + 1
END DO
END IF
END DO
ELSE
DO J = TableLookup(TableNum)%NumX2Vars, 1, -1
IF(ReadFromFile)THEN
READ(FileNum,*,IOSTAT=ReadStat) &
(TableLookup(TableNum)%TableLookupZData(I,J,Var3Index,Var4Index,Var5Index), &
I=TableLookup(TableNum)%NumX1Vars,1,-1)
IF(ReadStat < GoodIOStatValue) GO TO 1000
ELSE
DO I = TableLookup(TableNum)%NumX1Vars,1,-1
TableLookup(TableNum)%TableLookupZData(I,J,Var3Index,Var4Index,Var5Index)= &
Numbers(NumbersOffset)
NumbersOffset = NumbersOffset + 1
END DO
END IF
END DO
END IF
END IF
DO J = 1, TableLookup(TableNum)%NumX2Vars
! write data to eio file in ascending order
IF(EchoTableDataToEio)THEN
WRITE(CharTableData,*) &
(TableLookup(TableNum)%TableLookupZData(I,J,Var3Index,Var4Index,Var5Index), &
I=1,TableLookup(TableNum)%NumX1Vars)
WRITE(OutputFileInits,fmtA)TRIM(CharTableData)
END IF
! normalize the data according to the user entered normal point
DO I=1,TableLookup(TableNum)%NumX1Vars
TableLookup(TableNum)%TableLookupZData(I,J,Var3Index,Var4Index,Var5Index) = &
TableLookup(TableNum)%TableLookupZData(I,J,Var3Index,Var4Index,Var5Index)/ &
TableData(TableNum)%NormalPoint
END DO
END DO
DataSetCount = DataSetCount + 1
END DO
IF(EchoTableDataToEio)THEN
WRITE(OutputFileInits,131)
END IF
1000 EOFonFile = .TRUE.
IF(ReadFromFile) CLOSE (FileNum)
IF(TotalDataSets .LT. DataSetCount)THEN
CALL ShowSevereError('GetTableDataFile: For Table:MultiVariableLookup "'//TRIM(PerfCurve(CurveNum)%Name)//'" ')
CALL ShowContinueError('...The required number of data sets ('//trim(RoundSigDigits(TotalDataSets))// &
') is less than the number determined by the number and count of independent variables ('// &
trim(RoundSigDigits(DataSetCount))//').')
END IF
RETURN
999 CALL ShowSevereError('CurveManager: SearchTableDataFile: '// &
'Could not open Table Data File, expecting it as file name = '//TRIM(FileName))
CALL ShowContinueError('Certain run environments require a full path to be included with the file name in the input field.')
CALL ShowContinueError('Try again with putting full path and file name in the field.')
CALL ShowFatalError('Program terminates due to these conditions.')
END SUBROUTINE ReadTableData