Skip to content

Commit

Permalink
Remove extra GetNewUnit calls from SrvD
Browse files Browse the repository at this point in the history
Also fix some hard coded file numbers
  • Loading branch information
andrew-platt committed Nov 28, 2024
1 parent 14817bd commit da3b22c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 61 deletions.
34 changes: 19 additions & 15 deletions modules/servodyn/src/PitchCntrl_ACH.f90
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ SUBROUTINE PitchCntrl ( BlPitch, ElecPwr, LSS_Spd, TwrAccel, NB, ZTime, DT, DirR
INTEGER , SAVE :: NORDER (NSZ)
INTEGER :: NR
INTEGER :: NTEMP
integer :: unit

LOGICAL, SAVE :: INITFLAG = .TRUE.

Expand Down Expand Up @@ -91,34 +92,34 @@ SUBROUTINE PitchCntrl ( BlPitch, ElecPwr, LSS_Spd, TwrAccel, NB, ZTime, DT, DirR
END IF


CALL OpenFInpFile ( 86, TRIM(PitchFileName), ErrStat, ErrMsg )
CALL OpenFInpFile ( unit, TRIM(PitchFileName), ErrStat, ErrMsg )
IF (ErrStat >= AbortErrLev) CALL ProgAbort(TRIM(ErrMsg))


READ(86,FmtText) DESCRIP
READ(unit,FmtText) DESCRIP

CALL WrScr1( '***********************************************' )
CALL WrScr( 'Running with control option using data from:' )
CALL WrScr( TRIM(DESCRIP) )
CALL WrScr( '***********************************************' )
CALL WrScr( ' ' )

READ(86,*) CntrlRgn
READ(unit,*) CntrlRgn


READ(86,*) NCNST
READ(unit,*) NCNST

DO I = 1,NCNST
READ(86,*,END=20) CNST(I)
READ(unit,*,END=20) CNST(I)
ENDDO

NR = 1


10 READ(86,*,END=40) NTEMP ! Use NTEMP to avoid array overflow at end of file
10 READ(unit,*,END=40) NTEMP ! Use NTEMP to avoid array overflow at end of file
NORDER(NR) = NTEMP
READ(86,*,END=30) (BC(I,NR), I = NORDER(NR),0,-1)
READ(86,*,END=30) (AC(I,NR), I = NORDER(NR),1,-1), A0
READ(unit,*,END=30) (BC(I,NR), I = NORDER(NR),0,-1)
READ(unit,*,END=30) (AC(I,NR), I = NORDER(NR),1,-1), A0

IF ( ABS(A0) > 1.E-7 ) THEN
DO I = 0,NORDER(NR)
Expand Down Expand Up @@ -176,7 +177,7 @@ SUBROUTINE PitchCntrl ( BlPitch, ElecPwr, LSS_Spd, TwrAccel, NB, ZTime, DT, DirR

INITFLAG = .FALSE.

CLOSE(86)
CLOSE(unit)


RETURN
Expand Down Expand Up @@ -281,6 +282,7 @@ SUBROUTINE CTRL4 ( CNST, AC, BC, NORDER, MSZ, NSZ, &

INTEGER :: DEBUGFLAG
INTEGER :: K ! Blade number
integer :: unit

LOGICAL :: TRIMFLAG = .TRUE. ! Initialization flag

Expand Down Expand Up @@ -320,15 +322,15 @@ SUBROUTINE CTRL4 ( CNST, AC, BC, NORDER, MSZ, NSZ, &

IF( DEBUGFLAG == 1 ) THEN

CALL OpenFOutFile (40, 'pitcntrl.plt', ErrStat, ErrMsg )
CALL OpenFOutFile (unit, 'pitcntrl.plt', ErrStat, ErrMsg )
IF (ErrStat >= AbortErrLev) CALL ProgAbort(TRIM(ErrMsg))
WRITE (40,"( / 'This file was generated by ' , A , A , ' on ' , A , ' at ' , A , '.' / )") &
WRITE (unit,"( / 'This file was generated by ' , A , A , ' on ' , A , ' at ' , A , '.' / )") &
TRIM(ProgName), TRIM( ProgVer ), CurDate(), CurTime()

WRITE(40,*) 'Output of PITCH control control subroutine'
WRITE(40,*) 'Gain schedule coeffs = ', GSCoef, GSExp
WRITE(unit,*) 'Output of PITCH control control subroutine'
WRITE(unit,*) 'Gain schedule coeffs = ', GSCoef, GSExp

WRITE(40,Frmt1) &
WRITE(unit,Frmt1) &
'Time', TAB, &
'Pitch', TAB, &
'TFInput', TAB, &
Expand All @@ -342,6 +344,8 @@ SUBROUTINE CTRL4 ( CNST, AC, BC, NORDER, MSZ, NSZ, &
'GainSched', TAB, &
'Awindup'

CLOSE(unit)

ENDIF


Expand Down Expand Up @@ -754,4 +758,4 @@ FUNCTION DEADBAND ( X, XMIN, XMAX )
END FUNCTION DEADBAND
!=======================================================================
end module PitchCntrl_ACH


1 change: 0 additions & 1 deletion modules/servodyn/src/ServoDyn_Driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ PROGRAM SrvD_Driver
CALL GetRoot( InitInData%InputFile, OutFile )
OutFile = trim(OutFile)//'.out'

CALL GetNewUnit( Un, ErrStat, ErrMsg)
call OpenFOutFile ( Un, OutFile, ErrStat, ErrMsg )

! Set the driver's request for time interval here:
Expand Down
1 change: 0 additions & 1 deletion modules/servodyn/src/ServoDyn_IO.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2400,7 +2400,6 @@ subroutine InitializeSummaryFile(InputFileData,OutfileRoot,UnSum,ErrStat,ErrMsg)
ErrStat = ErrID_None
ErrMsg = ''
if ( InputFileData%SumPrint ) then
call GetNewUnit( UnSum )
CALL OpenEcho ( UnSum, TRIM(OutFileRoot)//'.sum', ErrStat2, ErrMsg2 )
CALL SetErrStat(ErrStat2,ErrMsg2,ErrStat,ErrMsg,RoutineName)
IF (ErrStat >= AbortErrLev) RETURN
Expand Down
49 changes: 6 additions & 43 deletions modules/servodyn/src/StrucCtrl_Driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,7 @@ SUBROUTINE ReadAngPosFile( InputFile, APvec, NumSteps, UnEc, ErrStat, ErrMsg )
! IF ( ErrStat >= AbortErrLev ) RETURN


! Get an available unit number for the file.

CALL GetNewUnit( UnIn, ErrStat2, ErrMsg2 )
CALL CheckError( ErrStat2, ErrMsg2 )
IF ( ErrStat >= AbortErrLev ) RETURN


! Open the Primary input file.

! Open the Primary input file.
CALL OpenFInpFile ( UnIn, InputFile, ErrStat2, ErrMsg2 )
CALL CheckError( ErrStat2, ErrMsg2 )
IF ( ErrStat >= AbortErrLev ) RETURN
Expand Down Expand Up @@ -271,15 +263,7 @@ SUBROUTINE ReadAngVelFile( InputFile, AVvec, NumSteps, UnEc, ErrStat, ErrMsg )
! IF ( ErrStat >= AbortErrLev ) RETURN


! Get an available unit number for the file.

CALL GetNewUnit( UnIn, ErrStat2, ErrMsg2 )
CALL CheckError( ErrStat2, ErrMsg2 )
IF ( ErrStat >= AbortErrLev ) RETURN


! Open the Primary input file.

! Open the Primary input file.
CALL OpenFInpFile ( UnIn, InputFile, ErrStat2, ErrMsg2 )
CALL CheckError( ErrStat2, ErrMsg2 )
IF ( ErrStat >= AbortErrLev ) RETURN
Expand Down Expand Up @@ -381,15 +365,7 @@ SUBROUTINE ReadAngAccelFile( InputFile, AAvec, NumSteps, UnEc, ErrStat, ErrMsg )
! IF ( ErrStat >= AbortErrLev ) RETURN


! Get an available unit number for the file.

CALL GetNewUnit( UnIn, ErrStat2, ErrMsg2 )
CALL CheckError( ErrStat2, ErrMsg2 )
IF ( ErrStat >= AbortErrLev ) RETURN


! Open the Primary input file.

! Open the Primary input file.
CALL OpenFInpFile ( UnIn, InputFile, ErrStat2, ErrMsg2 )
CALL CheckError( ErrStat2, ErrMsg2 )
IF ( ErrStat >= AbortErrLev ) RETURN
Expand Down Expand Up @@ -490,15 +466,7 @@ SUBROUTINE ReadAccelFile( InputFile, LAvec, NumSteps, UnEc, ErrStat, ErrMsg )
! IF ( ErrStat >= AbortErrLev ) RETURN


! Get an available unit number for the file.

CALL GetNewUnit( UnIn, ErrStat2, ErrMsg2 )
CALL CheckError( ErrStat2, ErrMsg2 )
IF ( ErrStat >= AbortErrLev ) RETURN


! Open the Primary input file.

! Open the Primary input file.
CALL OpenFInpFile ( UnIn, InputFile, ErrStat2, ErrMsg2 )
CALL CheckError( ErrStat2, ErrMsg2 )
IF ( ErrStat >= AbortErrLev ) RETURN
Expand Down Expand Up @@ -574,14 +542,9 @@ SUBROUTINE StC_OpenOutputFile(OutputFile,UnIn,ErrStat,ErrMsg)
!OutputFile = 'StC_Output_Data.txt'
!Fmt = "F10.2))/"

CALL GetNewUnit( UnIn, ErrStat, ErrMsg )
!CALL CheckError( ErrStat, ErrMsg)
!IF ( ErrStat >= AbortErrLev ) RETURN


! Open the output file.

! Open the output file.
CALL OpenFOutFile ( UnIn, OutputFile, ErrStat, ErrMsg )
if (ErrStat>=AbortErrLev) return
Header1 = "-------------- StrucCtrl Output ------------------------------"
Header2 = "x dxdt y dydt fx fy fz mx my mz"

Expand Down
2 changes: 1 addition & 1 deletion modules/servodyn/src/UserVSCont_KP.f90
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ SUBROUTINE UserVSCont ( HSS_Spd, LSS_Spd, NumBl, ZTime, DT, GenEff, DelGenTrq, D
INTEGER(IntKi) :: N1
INTEGER, SAVE :: NSCH = 0 ! Number of lines found in the file
INTEGER, PARAMETER :: NST = 5 ! Number of integration time steps between controller torque calculations.
INTEGER, PARAMETER :: UnCont = 99 ! Unit number for the input file
INTEGER :: UnCont ! Unit number for the input file

LOGICAL, SAVE :: SFLAG = .TRUE.

Expand Down

0 comments on commit da3b22c

Please sign in to comment.