From c9a6153e336ebe50ff207a28284f8d634c9a56e3 Mon Sep 17 00:00:00 2001 From: Bonnie Jonkman Date: Thu, 20 Oct 2022 09:24:14 -0600 Subject: [PATCH] HD: fix uninitialized NumOuts when no outputs listed 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. --- modules/hydrodyn/src/HydroDyn_Input.f90 | 4 +++- modules/hydrodyn/src/HydroDyn_Output.f90 | 18 +++++++++--------- modules/hydrodyn/src/Morison_Output.f90 | 14 ++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/hydrodyn/src/HydroDyn_Input.f90 b/modules/hydrodyn/src/HydroDyn_Input.f90 index 59b8004d07..c059a92cd3 100644 --- a/modules/hydrodyn/src/HydroDyn_Input.f90 +++ b/modules/hydrodyn/src/HydroDyn_Input.f90 @@ -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. diff --git a/modules/hydrodyn/src/HydroDyn_Output.f90 b/modules/hydrodyn/src/HydroDyn_Output.f90 index d956bdd554..95f1693bc7 100644 --- a/modules/hydrodyn/src/HydroDyn_Output.f90 +++ b/modules/hydrodyn/src/HydroDyn_Output.f90 @@ -1190,26 +1190,26 @@ 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 @@ -1217,8 +1217,8 @@ FUNCTION HDOut_GetChannels ( NUserOutputs, UserOutputs, OutList, foundMask, 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 @@ -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 diff --git a/modules/hydrodyn/src/Morison_Output.f90 b/modules/hydrodyn/src/Morison_Output.f90 index df85788ddf..16ccff3178 100644 --- a/modules/hydrodyn/src/Morison_Output.f90 +++ b/modules/hydrodyn/src/Morison_Output.f90 @@ -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 @@ -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 @@ -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