Skip to content

Commit

Permalink
HD: fix uninitialized NumOuts when no outputs listed
Browse files Browse the repository at this point in the history
If HD doesn't request any outputs, the number of outputs to Morison (and probably HD) was undefined. This has been fixed.

I also updated the code so that it should not have uninitialized values in the output channel list if a channel is listed multiple times.
  • Loading branch information
bjonkman committed Oct 20, 2022
1 parent b307423 commit c9a6153
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 3 additions & 1 deletion modules/hydrodyn/src/HydroDyn_Input.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2364,7 +2364,9 @@ SUBROUTINE HydroDynInput_ProcessInitData( InitInp, Interval, InputFileData, ErrS
IF (ErrStat >= AbortErrLev ) RETURN

DEALLOCATE(foundMask)

ELSE
InputFileData%NumOuts = 0
InputFileData%Morison%NumOuts = 0
END IF
! Now that we have the sub-lists organized, lets do some additional validation.

Expand Down
18 changes: 9 additions & 9 deletions modules/hydrodyn/src/HydroDyn_Output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1190,35 +1190,35 @@ FUNCTION HDOut_GetChannels ( NUserOutputs, UserOutputs, OutList, foundMask,
!----------------------------------------------------------------------------------------------------
INTEGER, INTENT( IN ) :: NUserOutputs ! Number of user-specified output channels
CHARACTER(ChanLen), INTENT( IN ) :: UserOutputs (:) ! An array holding the names of the requested output channels.
CHARACTER(ChanLen),ALLOCATABLE,INTENT( OUT ) :: OutList (:) ! An array holding the names of the matched WAMIT output channels.
CHARACTER(ChanLen),ALLOCATABLE,INTENT( OUT ) :: OutList (:) ! An array holding the names of the matched HD output channels.
LOGICAL, INTENT( INOUT ) :: foundMask (:) ! A mask indicating whether a user requested channel belongs to a module's output channels.
INTEGER, INTENT( OUT ) :: ErrStat ! a non-zero value indicates an error occurred
CHARACTER(*), INTENT( OUT ) :: ErrMsg ! Error message if ErrStat /= ErrID_None

INTEGER HDOut_GetChannels ! The number of channels found in this module
INTEGER :: HDOut_GetChannels ! The number of channels found in this module

! Local variables.

INTEGER :: I ! Generic loop-counting index.
INTEGER :: I, J ! Generic loop-counting index.
INTEGER :: count ! Generic loop-counting index.
INTEGER :: INDX ! Index for valid arrays
LOGICAL :: newFoundMask (NUserOutputs) ! A mask indicating whether a user requested channel belongs to a module's output channels
INTEGER :: newFoundMask (NUserOutputs) ! A mask indicating whether a user requested channel belongs to a module's output channels

! Initialize ErrStat
ErrStat = ErrID_None
ErrMsg = ""

HDOut_GetChannels = 0
newFoundMask = .false.
newFoundMask = 0

DO I = 1,NUserOutputs
IF (.NOT. foundMask(I) ) THEN

Indx = FindValidChannelIndx(UserOutputs(I), ValidParamAry)

IF ( Indx > 0 ) THEN
newFoundMask(I) = .TRUE.
foundMask(I) = .TRUE.
foundMask(I) = .TRUE.
newFoundMask(I) = newFoundMask(I) + 1
HDOut_GetChannels = HDOut_GetChannels + 1
END IF
END IF
Expand All @@ -1230,10 +1230,10 @@ FUNCTION HDOut_GetChannels ( NUserOutputs, UserOutputs, OutList, foundMask,
count = 1

DO I = 1,NUserOutputs
IF ( newFoundMask(I) ) THEN
DO J = 1,newFoundMask(I) ! in case an output is listed more than once
OutList(count) = UserOutputs(I)
count = count + 1
END IF
END DO
END DO

END IF
Expand Down
14 changes: 6 additions & 8 deletions modules/hydrodyn/src/Morison_Output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8100,25 +8100,24 @@ FUNCTION GetMorisonChannels ( NUserOutputs, UserOutputs, OutList, foundMask

! Local variables.

INTEGER :: I ! Generic loop-counting index.
INTEGER :: I, J ! Generic loop-counting index.
INTEGER :: count ! Generic loop-counting index.
INTEGER :: INDX ! Index for valid arrays
LOGICAL :: newFoundMask (NUserOutputs) ! A mask indicating whether a user requested channel belongs to a module's output channels
INTEGER :: newFoundMask (NUserOutputs) ! A mask indicating whether a user requested channel belongs to a module's output channels

! Initialize ErrStat
ErrStat = ErrID_None
ErrMsg = ""

GetMorisonChannels = 0

newFoundMask = .FALSE.
newFoundMask = 0

DO I = 1,NUserOutputs
IF (.NOT. foundMask(I) ) THEN
Indx = FindValidChannelIndx(UserOutputs(I), ValidParamAry)

IF ( Indx > 0 ) THEN
newFoundMask(I) = .TRUE.
newFoundMask(I) = newFoundMask(I) + 1
foundMask(I) = .TRUE.
GetMorisonChannels = GetMorisonChannels + 1
END IF
Expand All @@ -8131,10 +8130,10 @@ FUNCTION GetMorisonChannels ( NUserOutputs, UserOutputs, OutList, foundMask
count = 1

DO I = 1,NUserOutputs
IF ( newFoundMask(I) ) THEN
DO J = 1, newFoundMask(I) ! in case an output is requested more than one time
OutList(count) = UserOutputs(I)
count = count + 1
END IF
END DO
END DO

END IF
Expand Down Expand Up @@ -8945,7 +8944,6 @@ SUBROUTINE SetOutParam(OutList, p, ErrStat, ErrMsg )
ALLOCATE ( p%OutParam(1:p%NumOuts) , STAT=ErrStat2 )
IF ( ErrStat2 /= 0_IntKi ) THEN
CALL SetErrStat( ErrID_Fatal,"Error allocating memory for the Morison OutParam array.", ErrStat, ErrMsg, RoutineName )
call WrScr1(NewLine//'Morison NumOuts='//trim(num2lstr(p%NumOuts))//NewLine)
RETURN
ENDIF

Expand Down

0 comments on commit c9a6153

Please sign in to comment.