Skip to content

Commit

Permalink
Make error tracing consistent: RoutineNames
Browse files Browse the repository at this point in the history
  • Loading branch information
dzalkind committed May 17, 2021
1 parent 7fbfb86 commit c88f272
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 37 deletions.
21 changes: 13 additions & 8 deletions src/ControllerBlocks.f90
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ SUBROUTINE WindSpeedEstimator(LocalVar, CntrPar, objInst, PerfData, DebugVar, Er
REAL(8) :: R_m ! Measurement noise covariance [(rad/s)^2]

REAL(8), DIMENSION(3,1), SAVE :: B

CHARACTER(*), PARAMETER :: RoutineName = 'WindSpeedEstimator'

! ---- Debug Inputs ------
DebugVar%WE_b = LocalVar%PC_PitComTF*R2D
DebugVar%WE_w = LocalVar%RotSpeedF
Expand Down Expand Up @@ -308,10 +311,10 @@ SUBROUTINE WindSpeedEstimator(LocalVar, CntrPar, objInst, PerfData, DebugVar, Er
LocalVar%WE_Vw = LPFilter(LocalVar%HorWindV, LocalVar%DT, F_WECornerFreq, LocalVar%iStatus, .FALSE., objInst%instLPF)
ENDIF

! Error Catching
IF (ErrVar%aviFAIL == -1) THEN
ErrVar%ErrMsg = 'WindSpeedEstimator:'//TRIM(ErrVar%ErrMsg)
END IF
! Add RoutineName to error message
IF (ErrVar%aviFAIL < 0) THEN
ErrVar%ErrMsg = RoutineName//':'//TRIM(ErrVar%ErrMsg)
ENDIF

END SUBROUTINE WindSpeedEstimator
!-------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -355,13 +358,15 @@ REAL FUNCTION PitchSaturation(LocalVar, CntrPar, objInst, DebugVar, ErrVar)
TYPE(DebugVariables), INTENT(INOUT) :: DebugVar
TYPE(ErrorVariables), INTENT(INOUT) :: ErrVar

CHARACTER(*), PARAMETER :: RoutineName = 'PitchSaturation'

! Define minimum blade pitch angle as a function of estimated wind speed
PitchSaturation = interp1d(CntrPar%PS_WindSpeeds, CntrPar%PS_BldPitchMin, LocalVar%WE_Vw_F, ErrVar)

! Error Catching
IF (ErrVar%aviFAIL == -1) THEN
ErrVar%ErrMsg = 'PitchSaturation:'//TRIM(ErrVar%ErrMsg)
END IF
! Add RoutineName to error message
IF (ErrVar%aviFAIL < 0) THEN
ErrVar%ErrMsg = RoutineName//':'//TRIM(ErrVar%ErrMsg)
ENDIF

END FUNCTION PitchSaturation
!-------------------------------------------------------------------------------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions src/Controllers.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ SUBROUTINE PitchControl(avrSWAP, CntrPar, LocalVar, objInst, DebugVar, ErrVar)
TYPE(ErrorVariables), INTENT(INOUT) :: ErrVar

! Allocate Variables:
REAL(C_FLOAT), INTENT(INOUT) :: avrSWAP(*) ! The swap array, used to pass data to, and receive data from the DLL controller.
INTEGER(4) :: K ! Index used for looping through blades.
REAL(8), Save :: PitComT_Last
REAL(C_FLOAT), INTENT(INOUT) :: avrSWAP(*) ! The swap array, used to pass data to, and receive data from the DLL controller.
INTEGER(4) :: K ! Index used for looping through blades.
REAL(8), Save :: PitComT_Last

CHARACTER(*), PARAMETER :: RoutineName = 'PitchControl'

! ------- Blade Pitch Controller --------
! Load PC State
Expand Down
10 changes: 6 additions & 4 deletions src/DISCON.F90
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ SUBROUTINE DISCON(avrSWAP, aviFAIL, accINFILE, avcOUTNAME, avcMSG) BIND (C, NAME
TYPE(DebugVariables), SAVE :: DebugVar
TYPE(ErrorVariables), SAVE :: ErrVar

CHARACTER(*), PARAMETER :: RoutineName = 'ROSCO'

RootName = TRANSFER(avcOUTNAME, RootName)
!------------------------------------------------------------------------------------------------------------------------------
! Main control calculations
Expand All @@ -78,11 +80,11 @@ SUBROUTINE DISCON(avrSWAP, aviFAIL, accINFILE, avcOUTNAME, avcMSG) BIND (C, NAME
CALL Debug(LocalVar, CntrPar, DebugVar, avrSWAP, RootName, SIZE(avcOUTNAME))
END IF

! Error Catching
IF (ErrVar%aviFAIL == -1) THEN
ErrVar%ErrMsg = 'ROSCO:'//TRIM(ErrVar%ErrMsg)
! Add RoutineName to error message
IF (ErrVar%aviFAIL < 0) THEN
ErrVar%ErrMsg = RoutineName//':'//TRIM(ErrVar%ErrMsg)
print * , TRIM(ErrVar%ErrMsg)
END IF
ENDIF
ErrMsg = ErrVar%ErrMsg
avcMSG = TRANSFER(TRIM(ErrVar%ErrMsg)//C_NULL_CHAR, avcMSG, SIZE(avcMSG))
aviFAIL = ErrVar%aviFAIL
Expand Down
41 changes: 26 additions & 15 deletions src/Functions.f90
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,23 @@ REAL FUNCTION interp1d(xData, yData, xq, ErrVar)
TYPE(ErrorVariables), INTENT(INOUT) :: ErrVar
INTEGER(4) :: I_DIFF

CHARACTER(*), PARAMETER :: RoutineName = 'interp1d'


! Catch Errors
! Are xData and yData the same size?
IF (SIZE(xData) .NE. SIZE(yData)) THEN
ErrVar%aviFAIL = -1
ErrVar%ErrMsg = 'interp1d: xData and yData are not the same size'
WRITE(ErrVar%ErrMsg,"(A,I2,A,I2,A)") "interp1d: SIZE(xData) =", SIZE(xData), &
ErrVar%ErrMsg = ' xData and yData are not the same size'
WRITE(ErrVar%ErrMsg,"(A,I2,A,I2,A)") " SIZE(xData) =", SIZE(xData), &
' and SIZE(yData) =', SIZE(yData),' are not the same'
END IF

! Is xData non decreasing
DO I_DIFF = 1, size(xData) - 1
IF (xData(I_DIFF + 1) - xData(I_DIFF) <= 0) THEN
ErrVar%aviFAIL = -1
ErrVar%ErrMsg = 'interp1d: xData is not strictly increasing'
ErrVar%ErrMsg = ' xData is not strictly increasing'
EXIT
END IF
END DO
Expand All @@ -210,6 +212,11 @@ REAL FUNCTION interp1d(xData, yData, xq, ErrVar)
END IF
END DO
END IF

! Add RoutineName to error message
IF (ErrVar%aviFAIL < 0) THEN
ErrVar%ErrMsg = RoutineName//':'//TRIM(ErrVar%ErrMsg)
ENDIF

END FUNCTION interp1d

Expand Down Expand Up @@ -251,27 +258,29 @@ REAL FUNCTION interp2d(xData, yData, zData, xq, yq, ErrVar)
! Error Catching
TYPE(ErrorVariables), INTENT(INOUT) :: ErrVar
INTEGER(4) :: I_DIFF

CHARACTER(*), PARAMETER :: RoutineName = 'interp2d'

! Error catching
! Are xData and zData(:,1) the same size?
IF (SIZE(xData) .NE. SIZE(zData,2)) THEN
ErrVar%aviFAIL = -1
WRITE(ErrVar%ErrMsg,"(A,I4,A,I4,A)") "interp2d: SIZE(xData) =", SIZE(xData), &
WRITE(ErrVar%ErrMsg,"(A,I4,A,I4,A)") " SIZE(xData) =", SIZE(xData), &
' and SIZE(zData,1) =', SIZE(zData,2),' are not the same'
END IF

! Are yData and zData(1,:) the same size?
IF (SIZE(yData) .NE. SIZE(zData,1)) THEN
ErrVar%aviFAIL = -1
WRITE(ErrVar%ErrMsg,"(A,I4,A,I4,A)") "interp2d: SIZE(yData) =", SIZE(yData), &
WRITE(ErrVar%ErrMsg,"(A,I4,A,I4,A)") " SIZE(yData) =", SIZE(yData), &
' and SIZE(zData,2) =', SIZE(zData,1),' are not the same'
END IF

! Is xData non decreasing
DO I_DIFF = 1, size(xData) - 1
IF (xData(I_DIFF + 1) - xData(I_DIFF) <= 0) THEN
ErrVar%aviFAIL = -1
ErrVar%ErrMsg = 'interp2d: xData is not strictly increasing'
ErrVar%ErrMsg = ' xData is not strictly increasing'
EXIT
END IF
END DO
Expand All @@ -280,7 +289,7 @@ REAL FUNCTION interp2d(xData, yData, zData, xq, yq, ErrVar)
DO I_DIFF = 1, size(yData) - 1
IF (yData(I_DIFF + 1) - yData(I_DIFF) <= 0) THEN
ErrVar%aviFAIL = -1
ErrVar%ErrMsg = 'interp2d: yData is not strictly increasing'
ErrVar%ErrMsg = ' yData is not strictly increasing'
EXIT
END IF
END DO
Expand Down Expand Up @@ -352,10 +361,10 @@ REAL FUNCTION interp2d(xData, yData, zData, xq, yq, ErrVar)

interp2d = fxy(1)

! Error catching
IF (ErrVar%aviFAIL == -1) THEN
ErrVar%ErrMsg = 'interp2:'//TRIM(ErrVar%ErrMsg)
END IF
! Add RoutineName to error message
IF (ErrVar%aviFAIL < 0) THEN
ErrVar%ErrMsg = RoutineName//':'//TRIM(ErrVar%ErrMsg)
ENDIF

END FUNCTION interp2d

Expand Down Expand Up @@ -514,6 +523,8 @@ REAL FUNCTION AeroDynTorque(LocalVar, CntrPar, PerfData, ErrVar)
REAL(8) :: Cp
REAL(8) :: Lambda

CHARACTER(*), PARAMETER :: RoutineName = 'AeroDynTorque'

! Find Torque
RotorArea = PI*CntrPar%WE_BladeRadius**2
Lambda = LocalVar%RotSpeedF*CntrPar%WE_BladeRadius/LocalVar%WE_Vw
Expand All @@ -524,10 +535,10 @@ REAL FUNCTION AeroDynTorque(LocalVar, CntrPar, PerfData, ErrVar)
AeroDynTorque = 0.5*(CntrPar%WE_RhoAir*RotorArea)*(LocalVar%WE_Vw**3/LocalVar%RotSpeedF)*Cp
AeroDynTorque = MAX(AeroDynTorque, 0.0)

! Error Catching
IF (ErrVar%aviFAIL == -1) THEN
ErrVar%ErrMsg = 'AeroDynTorque:'//TRIM(ErrVar%ErrMsg)
END IF
! Add RoutineName to error message
IF (ErrVar%aviFAIL < 0) THEN
ErrVar%ErrMsg = RoutineName//':'//TRIM(ErrVar%ErrMsg)
ENDIF

END FUNCTION AeroDynTorque

Expand Down
23 changes: 16 additions & 7 deletions src/ReadSetParameters.f90
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ SUBROUTINE SetParameters(avrSWAP, accINFILE, size_avcMSG, CntrPar, LocalVar, obj

INTEGER(4) :: K ! Index used for looping through blades.
CHARACTER(200) :: git_version

CHARACTER(*), PARAMETER :: RoutineName = 'SetParameters'



! Error Catching Variables
! Set ErrVar%aviFAIL to 0 in each iteration:
Expand Down Expand Up @@ -148,8 +152,9 @@ SUBROUTINE SetParameters(avrSWAP, accINFILE, size_avcMSG, CntrPar, LocalVar, obj

CALL ReadControlParameterFileSub(CntrPar, accINFILE, NINT(avrSWAP(50)),ErrVar)
! If there's been an file reading error, don't continue
! Add RoutineName to error message
IF (ErrVar%aviFAIL < 0) THEN
ErrVar%ErrMsg = 'SetParameters:'//TRIM(ErrVar%ErrMsg)
ErrVar%ErrMsg = RoutineName//':'//TRIM(ErrVar%ErrMsg)
RETURN
ENDIF

Expand Down Expand Up @@ -183,8 +188,9 @@ SUBROUTINE SetParameters(avrSWAP, accINFILE, size_avcMSG, CntrPar, LocalVar, obj
! Check validity of input parameters:
CALL CheckInputs(LocalVar, CntrPar, avrSWAP, ErrVar, size_avcMSG)

! Add RoutineName to error message
IF (ErrVar%aviFAIL < 0) THEN
ErrVar%ErrMsg = 'SetParameters:'//TRIM(ErrVar%ErrMsg)
ErrVar%ErrMsg = RoutineName//':'//TRIM(ErrVar%ErrMsg)
ENDIF


Expand All @@ -204,6 +210,8 @@ SUBROUTINE ReadControlParameterFileSub(CntrPar, accINFILE, accINFILE_size,ErrVar

INTEGER(4) :: CurLine

CHARACTER(*), PARAMETER :: RoutineName = 'ReadControlParameterFileSub'

CurLine = 1


Expand Down Expand Up @@ -373,8 +381,9 @@ SUBROUTINE ReadControlParameterFileSub(CntrPar, accINFILE, accINFILE_size,ErrVar
!------------------- HOUSEKEEPING -----------------------
CntrPar%PerfFileName = TRIM(CntrPar%PerfFileName)

! Add RoutineName to error message
IF (ErrVar%aviFAIL < 0) THEN
ErrVar%ErrMsg = 'ReadControlParameterFileSub:'//TRIM(ErrVar%ErrMsg)
ErrVar%ErrMsg = RoutineName//':'//TRIM(ErrVar%ErrMsg)
ENDIF


Expand All @@ -394,7 +403,7 @@ SUBROUTINE CheckInputs(LocalVar, CntrPar, avrSWAP, ErrVar, size_avcMSG)
INTEGER(4), INTENT(IN ) :: size_avcMSG
REAL(C_FLOAT), INTENT(IN ) :: avrSWAP(*) ! The swap array, used to pass data to, and receive data from, the DLL controller.


CHARACTER(*), PARAMETER :: RoutineName = 'CheckInputs'
! Local

!..............................................................................................................................
Expand Down Expand Up @@ -818,7 +827,7 @@ SUBROUTINE CheckInputs(LocalVar, CntrPar, avrSWAP, ErrVar, size_avcMSG)
ENDIF

IF (ErrVar%aviFAIL < 0) THEN
ErrVar%ErrMsg = 'CheckInputs:'//TRIM(ErrVar%ErrMsg)
ErrVar%ErrMsg = RoutineName//':'//TRIM(ErrVar%ErrMsg)
ENDIF

END SUBROUTINE CheckInputs
Expand Down Expand Up @@ -1222,7 +1231,7 @@ SUBROUTINE ParseDbAry ( Un, LineNum, AryName, Ary, AryLen, FileName, ErrVar, Che
READ (Line,*,IOSTAT=ErrStatLcl) Ary
IF ( ErrStatLcl /= 0 ) THEN
ErrVar%aviFAIL = -1
ErrVar%ErrMsg = RoutineName//'A fatal error occurred when parsing data from "' &
ErrVar%ErrMsg = RoutineName//':A fatal error occurred when parsing data from "' &
//TRIM( FileName )//'".'//NewLine// &
' >> The "'//TRIM( AryName )//'" array was not assigned valid REAL values on line #' &
//TRIM( Int2LStr( LineNum ) )//'.'//NewLine//' >> The text being parsed was :'//NewLine &
Expand Down Expand Up @@ -1349,7 +1358,7 @@ SUBROUTINE ParseInAry ( Un, LineNum, AryName, Ary, AryLen, FileName, ErrVar, Che
READ (Line,*,IOSTAT=ErrStatLcl) Ary
IF ( ErrStatLcl /= 0 ) THEN
ErrVar%aviFAIL = -1
ErrVar%ErrMsg = RoutineName//'A fatal error occurred when parsing data from "' &
ErrVar%ErrMsg = RoutineName//':A fatal error occurred when parsing data from "' &
//TRIM( FileName )//'".'//NewLine// &
' >> The "'//TRIM( AryName )//'" array was not assigned valid REAL values on line #' &
//TRIM( Int2LStr( LineNum ) )//'.'//NewLine//' >> The text being parsed was :'//NewLine &
Expand Down

0 comments on commit c88f272

Please sign in to comment.