! ROSCO Registry
! This file is automatically generated by write_registry.py using ROSCO v2.10.1
! For any modification to the registry, please edit the rosco_types.yaml accordingly
 
MODULE ROSCO_Types
USE, INTRINSIC :: ISO_C_Binding
USE Constants
IMPLICIT NONE

Character(*), PARAMETER     :: rosco_version = '2.10.1'             ! ROSCO version

TYPE, PUBLIC :: ControlParameters
    INTEGER(IntKi)                :: ZMQ_ID                      ! 0000 - 9999, Identifier of the rosco, used for zeromq interface only
    INTEGER(IntKi)                :: LoggingLevel                ! 0 - write no debug files, 1 - write standard output .dbg-file, 2 - write standard output .dbg-file and complete avrSWAP-array .dbg2-file
    INTEGER(IntKi)                :: Echo                        ! 0 - no Echo, 1 - Echo input data to <RootName>.echo
    INTEGER(IntKi)                :: Ext_Interface               ! 0 - use standard bladed interface, 1 - Use the extened DLL interface introduced in OpenFAST 3.5.0.
    REAL(DbKi)                    :: DT_Out                      ! Output time step
    INTEGER(IntKi)                :: n_DT_Out                    ! output every this many steps
    INTEGER(IntKi)                :: n_DT_ZMQ                    ! Send measurements to ZMQ after this many time steps
    INTEGER(IntKi)                :: F_LPFType                   ! Low pass filter on the rotor and generator speed {1 - first-order low-pass filter, 2 - second-order low-pass filter}, [rad/s]
    REAL(DbKi)                    :: F_LPFCornerFreq             ! Corner frequency (-3dB point) in the first-order low-pass filter, [rad/s]
    REAL(DbKi)                    :: F_LPFDamping                ! Damping coefficient [used only when F_FilterType = 2]
    INTEGER(IntKi)                :: F_NumNotchFilts             ! Number of notch filters
    INTEGER(IntKi)                :: F_GenSpdNotch_N             ! Number of gen speed notch filters
    INTEGER(IntKi), DIMENSION(:), ALLOCATABLE     :: F_GenSpdNotch_Ind           ! Indices of gen speed notch filters
    INTEGER(IntKi)                :: F_TwrTopNotch_N             ! Number of tower top notch filters
    INTEGER(IntKi), DIMENSION(:), ALLOCATABLE     :: F_TwrTopNotch_Ind           ! Indices of tower top notch filters
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: F_NotchFreqs                ! Natural frequencies of notch filters, [rad/s]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: F_NotchBetaNum              ! Notch Filter Numerator damping (determines width)
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: F_NotchBetaDen              ! Notch Filter Numerator damping (determines depth?)
    REAL(DbKi)                    :: F_SSCornerFreq              ! Corner frequency (-3dB point) in the first order low pass filter for the setpoint smoother [rad/s]
    REAL(DbKi)                    :: F_WECornerFreq              ! Corner frequency (-3dB point) in the first order low pass filter for the wind speed estimate [rad/s]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: F_FlCornerFreq              ! Corner frequency (-3dB point) in the second order low pass filter of the tower-top fore-aft motion for floating feedback control [rad/s].
    REAL(DbKi)                    :: F_FlHighPassFreq            ! Natural frequency of first-roder high-pass filter for nacelle fore-aft motion [rad/s].
    REAL(DbKi)                    :: F_YawErr                    ! Corner low pass filter corner frequency for yaw controller [rad/s].
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: F_FlpCornerFreq             ! Corner frequency (-3dB point) in the second order low pass filter of the blade root bending moment for flap control [rad/s].
    REAL(DbKi)                    :: F_VSRefSpdCornerFreq        ! Corner frequency (-3dB point) in the first order low pass filter of the generator speed reference used for TSR tracking torque control [rad/s].
    INTEGER(IntKi)                :: TRA_Mode                    ! Tower Fore-Aft control mode {0 - no fore-aft control, 1 - Tower fore-aft damping, 2 -Frequency exclusion zone, 3- Options 1 and 2}
    REAL(DbKi)                    :: TRA_ExclSpeed               ! Rotor speed for exclusion [LSS] [rad/s]
    REAL(DbKi)                    :: TRA_ExclBand                ! One-half of the total frequency exclusion band. Torque controller reference will be TRA_ExclFreq +/- TRA_ExlBand [rad/s]
    REAL(DbKi)                    :: TRA_RateLimit               ! Time constant for gain change when in exclusion zone [s]
    INTEGER(IntKi)                :: TD_Mode                     ! Tower Fore-Aft control mode {0 - no fore-aft control, 1 - Tower fore-aft damping, 2 -Frequency exclusion zone, 3- Options 1 and 2}
    REAL(DbKi)                    :: FA_HPFCornerFreq            ! Corner frequency (-3dB point) in the high-pass filter on the fore-aft acceleration signal [rad/s]
    REAL(DbKi)                    :: FA_IntSat                   ! Integrator saturation (maximum signal amplitude contrbution to pitch from FA damper), [rad]
    REAL(DbKi)                    :: FA_KI                       ! Integral gain for the fore-aft tower damper controller, -1 = off / >0 = on [rad s/m]
    INTEGER(IntKi)                :: IPC_ControlMode             ! Turn Individual Pitch Control (IPC) for fatigue load reductions (pitch contribution) {0 - off, 1 - 1P reductions, 2 - 1P+2P reductions}
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: IPC_Vramp                   ! Wind speeds for IPC cut-in sigma function [m/s]
    REAL(DbKi)                    :: IPC_IntSat                  ! Integrator saturation (maximum signal amplitude contrbution to pitch from IPC)
    INTEGER(IntKi)                :: IPC_SatMode                 ! IPC Saturation method IPC Saturation method (0 - no saturation (except by PC_MinPit), 1 - saturate by PS_BldPitchMin, 2 - saturate sotfly (full IPC cycle) by PC_MinPit, 3 - saturate softly by PS_BldPitchMin)
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: IPC_KP                      ! Integral gain for the individual pitch controller, [-].
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: IPC_KI                      ! Integral gain for the individual pitch controller, [-].
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: IPC_aziOffset               ! Phase offset added to the azimuth angle for the individual pitch controller, [rad].
    REAL(DbKi)                    :: IPC_CornerFreqAct           ! Corner frequency of the first-order actuators model, to induce a phase lag in the IPC signal {0 - Disable}, [rad/s]
    INTEGER(IntKi)                :: PC_ControlMode              ! Blade pitch control mode {0 - No pitch, fix to fine pitch, 1 - active PI blade pitch control}
    INTEGER(IntKi)                :: PC_GS_n                     ! Amount of gain-scheduling table entries
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PC_GS_angles                ! Gain-schedule table - pitch angles
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PC_GS_KP                    ! Gain-schedule table - pitch controller kp gains
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PC_GS_KI                    ! Gain-schedule table - pitch controller ki gains
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PC_GS_KD                    ! Gain-schedule table - pitch controller kd gains
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PC_GS_TF                    ! Gain-schedule table - pitch controller tf gains (derivative filter)
    REAL(DbKi)                    :: PC_MaxPit                   ! Maximum physical pitch limit, [rad].
    REAL(DbKi)                    :: PC_MinPit                   ! Minimum physical pitch limit, [rad].
    REAL(DbKi)                    :: PC_MaxRat                   ! Maximum pitch rate (in absolute value) in pitch controller, [rad/s].
    REAL(DbKi)                    :: PC_MinRat                   ! Minimum pitch rate (in absolute value) in pitch controller, [rad/s].
    REAL(DbKi)                    :: PC_RefSpd                   ! Desired (reference) HSS speed for pitch controller, [rad/s].
    REAL(DbKi)                    :: PC_FinePit                  ! Record 5 - Below-rated pitch angle set-point (deg) [used only with Bladed Interface]
    REAL(DbKi)                    :: PC_Switch                   ! Angle above lowest minimum pitch angle for switch [rad]
    INTEGER(IntKi)                :: VS_ControlMode              ! Generator torque control mode in below rated conditions {0 - no torque control, 1 - komega^2 with PI trans, 2 - WSE TSR Tracking, 3 - Power TSR Tracking, 4 - Torque TSR Tracking}
    INTEGER(IntKi)                :: VS_ConstPower               ! Constant power torque control
    INTEGER(IntKi)                :: VS_FBP                      ! Fixed blade pitch control mode in above rated conditions {0 - variable pitch (defer to PC_ControlMode and VS_ConstPower), 1 - P/omega overspeed control law, 2 - PI reference tracking based on WSE lookup table, 3 - PI reference tracking based on torque lookup table (must have VS_FBP_Tau be a monotonic function)}
    REAL(DbKi)                    :: VS_GenEff                   ! Generator efficiency mechanical power -> electrical power [-]
    REAL(DbKi)                    :: VS_ArSatTq                  ! Above rated generator torque PI control saturation, [Nm]
    REAL(DbKi)                    :: VS_MaxRat                   ! Maximum torque rate (in absolute value) in torque controller, [Nm/s].
    REAL(DbKi)                    :: VS_MaxTq                    ! Maximum generator torque in Region 3 (HSS side), [Nm].
    REAL(DbKi)                    :: VS_MinTq                    ! Minimum generator torque (HSS side), [Nm].
    REAL(DbKi)                    :: VS_MinOMSpd                 ! Optimal mode minimum speed, [rad/s]
    REAL(DbKi)                    :: VS_Rgn2K                    ! Generator torque constant in Region 2 (HSS side), N-m/(rad/s)^2
    REAL(DbKi)                    :: VS_RtPwr                    ! Wind turbine rated power [W]
    REAL(DbKi)                    :: VS_RtTq                     ! Rated torque, [Nm].
    REAL(DbKi)                    :: VS_RefSpd                   ! Rated generator speed [rad/s]
    INTEGER(IntKi)                :: VS_n                        ! Number of controller gains
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: VS_KP                       ! Proportional gain for generator PI torque controller, used in the transitional 2.5 region
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: VS_KI                       ! Integral gain for generator PI torque controller, used in the transitional 2.5 region
    REAL(DbKi)                    :: VS_TSRopt                   ! Power-maximizing region 2 tip-speed ratio [rad]
    INTEGER(IntKi)                :: VS_FBP_n                    ! Number of operating schedule entries for fixed blade pitch control
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: VS_FBP_U                    ! Operating schedule for fixed blade pitch control - Wind speed
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: VS_FBP_Omega                ! Operating schedule for fixed blade pitch control - Generator speed
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: VS_FBP_Tau                  ! Operating schedule for fixed blade pitch control - Generator torque
    INTEGER(IntKi)                :: SS_Mode                     ! Setpoint Smoother mode {0 - no setpoint smoothing, 1 - introduce setpoint smoothing}
    REAL(DbKi)                    :: SS_VSGain                   ! Variable speed torque controller setpoint smoother gain, [-].
    REAL(DbKi)                    :: SS_PCGain                   ! Collective pitch controller setpoint smoother gain, [-].
    INTEGER(IntKi)                :: PRC_Mode                    ! Power reference tracking mode, 0- use standard rotor speed set points, 1- use PRC rotor speed setpoints
    INTEGER(IntKi)                :: PRC_Comm                    ! Power reference communication mode, 0- use constant DISCON inputs, 1- use open loop inputs, 2- use ZMQ inputs
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PRC_WindSpeeds              ! Array of wind speeds used in rotor speed vs. wind speed lookup table
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PRC_GenSpeeds               ! Array of rotor speeds corresponding to PRC_WindSpeeds
    INTEGER(IntKi)                :: PRC_n                       ! Number of elements in PRC_WindSpeeds and PRC_GenSpeeds array
    REAL(DbKi)                    :: PRC_LPF_Freq                ! Frequency of the low pass filter on the wind speed estimate used to set PRC_GenSpeeds [rad/s]
    REAL(DbKi)                    :: PRC_R_Torque                ! Power rating through changing the rated torque, default is 1, effective above rated [-]
    REAL(DbKi)                    :: PRC_R_Speed                 ! Power rating through changing the rated generator speed, default is 1, effective above rated [-]
    REAL(DbKi)                    :: PRC_R_Pitch                 ! Power rating through changing the fine pitch angle, default is 1, effective below rated [-]
    INTEGER(IntKi)                :: PRC_Table_n                 ! Number of elements in PRC_R to _Pitch table
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PRC_Pitch_Table             ! Table of fine pitch versus PRC_R_Table, length should be PRC_Table_n [rad]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PRC_R_Table                 ! Table of turbine rating versus fine pitch (PRC_Pitch_Table), length should be PRC_Table_n, default is 1 [-]
    INTEGER(IntKi)                :: WE_Mode                     ! Wind speed estimator mode {0 - One-second low pass filtered hub height wind speed, 1 - Imersion and Invariance Estimator (Ortega et al.)
    REAL(DbKi)                    :: WE_BladeRadius              ! Blade length [m]
    INTEGER(IntKi)                :: WE_CP_n                     ! Amount of parameters in the Cp array
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: WE_CP                       ! Parameters that define the parameterized CP(\lambda) function
    REAL(DbKi)                    :: WE_Gamma                    ! Adaption gain of the wind speed estimator algorithm [m/rad]
    REAL(DbKi)                    :: WE_GearboxRatio             ! Gearbox ratio, >=1  [-]
    REAL(DbKi)                    :: WE_Jtot                     ! Total drivetrain inertia, including blades, hub and casted generator inertia to LSS [kg m^2]
    REAL(DbKi)                    :: WE_RhoAir                   ! Air density [kg m^-3]
    CHARACTER(1024)               :: PerfFileName                ! File containing rotor performance tables (Cp,Ct,Cq)
    INTEGER(IntKi), DIMENSION(:), ALLOCATABLE     :: PerfTableSize               ! Size of rotor performance tables, first number refers to number of blade pitch angles, second number referse to number of tip-speed ratios
    INTEGER(IntKi)                :: WE_FOPoles_N                ! Number of first-order system poles used in EKF
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: WE_FOPoles_v                ! Wind speeds corresponding to first-order system poles [m/s]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: WE_FOPoles                  ! First order system poles
    INTEGER(IntKi)                :: Y_ControlMode               ! Yaw control mode {0 - no yaw control, 1 - yaw rate control}
    REAL(DbKi)                    :: Y_uSwitch                   ! Wind speed to switch between Y_ErrThresh. If zero, only the first value of Y_ErrThresh is used [m/s]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: Y_ErrThresh                 ! Error threshold [rad]. Turbine begins to yaw when it passes this
    REAL(DbKi)                    :: Y_Rate                      ! Yaw rate [rad/s]
    REAL(DbKi)                    :: Y_MErrSet                   ! Yaw alignment error, setpoint (for wake steering) [rad]
    REAL(DbKi)                    :: Y_IPC_IntSat                ! Integrator saturation (maximum signal amplitude contrbution to pitch from yaw-by-IPC)
    REAL(DbKi)                    :: Y_IPC_KP                    ! Yaw-by-IPC proportional controller gain Kp
    REAL(DbKi)                    :: Y_IPC_KI                    ! Yaw-by-IPC integral controller gain Ki
    INTEGER(IntKi)                :: PS_Mode                     ! Pitch saturation mode {0 - no peak shaving, 1 -  implement pitch saturation}
    INTEGER(IntKi)                :: PS_BldPitchMin_N            ! Number of values in minimum blade pitch lookup table (should equal number of values in PS_WindSpeeds and PS_BldPitchMin)
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PS_WindSpeeds               ! Wind speeds corresponding to minimum blade pitch angles [m/s]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PS_BldPitchMin              ! Minimum blade pitch angles [rad]
    INTEGER(IntKi)                :: SU_Mode                     ! Startup mode {0 - no startup procedure, 1 - enable startup}
    REAL(DbKi)                    :: SU_StartTime                ! Time to start start up routine
    REAL(DbKi)                    :: SU_FW_MinDuration           ! Free-wheel minimum duration [s]
    REAL(DbKi)                    :: SU_RotorSpeedThresh         ! Rotor speed threshhold to switch from freewheel to loads [rad/s]
    REAL(DbKi)                    :: SU_RotorSpeedCornerFreq     ! Cutoff Frequency for first order low-pass filter for rotor speed for startup, [rad/s]
    INTEGER(IntKi)                :: SU_LoadStages_N             ! Number of load staged for startup (should equal number of values in SU_LoadStages, SU_LoadRampDuration and SU_LoadHoldDuration) [-]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: SU_LoadStages               ! Array containing loads as a fraction of full generator torque during startup [-]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: SU_LoadRampDuration         ! Array containing ramp duration to reach the corresponding partial loads during startup [s]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: SU_LoadHoldDuration         ! Array containing duration to hold the partial loads during startup [s]
    INTEGER(IntKi)                :: SD_Mode                     ! Shutdown mode {0 - no shutdown procedure, 1 - enable shutdown}
    REAL(DbKi)                    :: SD_TimeActivate             ! Time to acitvate shutdown modes, [s]
    INTEGER(IntKi)                :: SD_EnablePitch              ! Shutdown when collective blade pitch exceeds a threshold, [-]
    INTEGER(IntKi)                :: SD_EnableYawError           ! Shutdown when yaw error exceeds a threshold, [-]
    INTEGER(IntKi)                :: SD_EnableGenSpeed           ! Shutdown when generator speed exceeds a threshold, [-]
    INTEGER(IntKi)                :: SD_EnableTime               ! Shutdown at a predefined time, [-]
    REAL(DbKi)                    :: SD_MaxPit                   ! Maximum blade pitch angle to initiate shutdown, [rad]
    REAL(DbKi)                    :: SD_PitchCornerFreq          ! Cutoff Frequency for first order low-pass filter for blade pitch angle for shutdown, [rad/s]
    REAL(DbKi)                    :: SD_MaxYawError              ! Maximum yaw error to initiate shutdown, [deg]
    REAL(DbKi)                    :: SD_YawErrorCornerFreq       ! Cutoff Frequency for first order low-pass filter for yaw error for shutdown, [rad/s]
    REAL(DbKi)                    :: SD_MaxGenSpd                ! Maximum generator speed to initiate shutdown, [rad/s]
    REAL(DbKi)                    :: SD_GenSpdCornerFreq         ! Cutoff Frequency for first order low-pass filter for generator speed for shutdown, [rad/s]
    REAL(DbKi)                    :: SD_Time                     ! Shutdown time, [s]
    INTEGER(IntKi)                :: SD_Method                   ! Shutdown method {1 - Reduce generator torque and increase blade pitch}, [-]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: SD_MaxTorqueRate            ! Maximum torque rate for shutdown, [Nm/s]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: SD_MaxPitchRate             ! Maximum pitch rate used for shutdown, [rad/s]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: SD_StagePitch               ! Array containing the pitch angle to reach in each shutdown stage [rad]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: SD_StageTime                ! Array containing the time to spend in each shutdown stage [s]
    INTEGER(IntKi)                :: SD_Stage_N                  ! Number of shutdown stages (should equal number of values in SD_MaxPitchRate and SD_MaxTorqueRate) [-]
    INTEGER(IntKi)                :: Fl_Mode                     ! Floating specific feedback mode {0 - no nacelle velocity feedback, 1 - nacelle velocity feedback}
    INTEGER(IntKi)                :: Fl_n                        ! Number of Fl_Kp for gain scheduling
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: Fl_Kp                       ! Nacelle velocity proportional feedback gain [s]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: Fl_U                        ! Wind speeds for scheduling Fl_Kp [m/s]
    INTEGER(IntKi)                :: Flp_Mode                    ! Flap actuator mode {0 - off, 1 - fixed flap position, 2 - PI flap control}
    REAL(DbKi)                    :: Flp_Angle                   ! Fixed flap angle (degrees)
    REAL(DbKi)                    :: Flp_Kp                      ! PI flap control proportional gain
    REAL(DbKi)                    :: Flp_Ki                      ! PI flap control integral gain
    REAL(DbKi)                    :: Flp_MaxPit                  ! Maximum (and minimum) flap pitch angle [rad]
    CHARACTER(1024)               :: OL_Filename                 ! Input file with open loop timeseries
    INTEGER(IntKi)                :: OL_Mode                     ! Open loop control mode {0 - no open loop control, 1 - open loop control vs. time, 2 - open loop control vs. wind speed}
    INTEGER(IntKi)                :: OL_BP_Mode                  ! Open loop control mode {0 - no open loop control, 1 - open loop control vs. time, 2 - open loop control vs. wind speed}
    REAL(DbKi)                    :: OL_BP_FiltFreq              ! First order low pass filter cutoff frequency for open loop breakpoint
    INTEGER(IntKi)                :: Ind_Breakpoint              ! The column in OL_Filename that contains the breakpoint (time if OL_Mode = 1)
    INTEGER(IntKi), DIMENSION(:), ALLOCATABLE     :: Ind_BldPitch                ! The columns in OL_Filename that contains the blade pitch inputs (1,2,3) in rad
    INTEGER(IntKi)                :: Ind_GenTq                   ! The column in OL_Filename that contains the generator torque in Nm
    INTEGER(IntKi)                :: Ind_YawRate                 ! The column in OL_Filename that contains the generator torque in Nm
    INTEGER(IntKi)                :: Ind_R_Speed                 ! The column in OL_Filename that contains the R_Speed input
    INTEGER(IntKi)                :: Ind_R_Torque                ! The column in OL_Filename that contains the R_Torque input
    INTEGER(IntKi)                :: Ind_R_Pitch                 ! The column in OL_Filename that contains the R_Pitch input
    INTEGER(IntKi)                :: Ind_Azimuth                 ! The column in OL_Filename that contains the desired azimuth position in rad (used if OL_Mode = 2)
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: RP_Gains                    ! PID gains and Tf on derivative term for rotor position control (used if OL_Mode = 2)
    INTEGER(IntKi), DIMENSION(:), ALLOCATABLE     :: Ind_CableControl            ! The column in OL_Filename that contains the cable control inputs in m
    INTEGER(IntKi), DIMENSION(:), ALLOCATABLE     :: Ind_StructControl           ! The column in OL_Filename that contains the structural control inputs in various units
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: OL_Breakpoints              ! Open loop breakpoints in timeseries
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: OL_BldPitch1                ! Open loop blade pitch 1 timeseries
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: OL_BldPitch2                ! Open loop blade pitch 2 timeseries
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: OL_BldPitch3                ! Open loop blade pitch 3 timeseries
    REAL(DbKi), DIMENSION(:,:), ALLOCATABLE     :: OL_CableControl             ! None
    REAL(DbKi), DIMENSION(:,:), ALLOCATABLE     :: OL_StructControl            ! None
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: OL_GenTq                    ! Open loop generator torque timeseries
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: OL_YawRate                  ! Open loop yaw rate timeseries
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: OL_Azimuth                  ! Open loop azimuth timeseries
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: OL_R_Speed                  ! Open loop R_Speed timeseries
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: OL_R_Torque                 ! Open loop R_Torque timeseries
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: OL_R_Pitch                  ! Open loop R_Pitch timeseries
    REAL(DbKi), DIMENSION(:,:), ALLOCATABLE     :: OL_Channels                 ! Open loop channels in timeseries
    INTEGER(IntKi)                :: PA_Mode                     ! Pitch actuator mode {0 - not used, 1 - first order filter, 2 - second order filter}
    REAL(DbKi)                    :: PA_CornerFreq               ! Pitch actuator bandwidth/cut-off frequency [rad/s]
    REAL(DbKi)                    :: PA_Damping                  ! Pitch actuator damping ratio [-, unused if PA_Mode = 1]
    INTEGER(IntKi)                :: AWC_Mode                    ! Active wake control mode [0 - unused, 1 - complex number method, 2 - Coleman transform method]
    INTEGER(IntKi)                :: AWC_NumModes                ! AWC- Number of modes to include [-]
    INTEGER(IntKi), DIMENSION(:), ALLOCATABLE     :: AWC_n                       ! AWC azimuthal mode [-]
    INTEGER(IntKi), DIMENSION(:), ALLOCATABLE     :: AWC_harmonic                ! AWC Coleman transform harmonic [-]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: AWC_freq                    ! AWC frequency [Hz]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: AWC_amp                     ! AWC amplitude [deg]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: AWC_clockangle              ! AWC clocking angle [deg]
    REAL(DbKi)                    :: AWC_phaseoffset             ! AWC azimuth offset for Coleman transform [deg]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: AWC_CntrGains               ! AWC KP and KI/KR gain of the controller [-]
    INTEGER(IntKi)                :: PF_Mode                     ! Pitch actuator fault mode {0 - not used, 1 - offsets on one or more blades}
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PF_Offsets                  ! Pitch actuator fault offsets for blade 1-3 [rad/s]
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: PF_TimeStuck                ! Time for pitch actuator fault to be stuck for blade 1-3 [s]
    INTEGER(IntKi)                :: Ext_Mode                    ! External control mode (0 - not used, 1 - call external control library)
    CHARACTER(1024)               :: DLL_FileName                ! File name of external dynamic library
    CHARACTER(1024)               :: DLL_InFile                  ! Name of input file called by dynamic library (DISCON.IN, e.g.)
    CHARACTER(1024)               :: DLL_ProcName                ! Process name of subprocess called in DLL_Filename (Usually DISCON)
    INTEGER(IntKi)                :: ZMQ_Mode                    ! Flag for ZeroMQ (0-off, 1-yaw}
    CHARACTER(256)                :: ZMQ_CommAddress             ! Comm Address to zeroMQ client
    REAL(DbKi)                    :: ZMQ_UpdatePeriod            ! Integer for zeromq update frequency
    INTEGER(IntKi)                :: CC_Mode                     ! Flag for ZeroMQ (0-off, 1-yaw}
    INTEGER(IntKi)                :: CC_Group_N                  ! Number of cable control groups
    REAL(DbKi)                    :: CC_ActTau                   ! Time constant for line actuator [s]
    INTEGER(IntKi), DIMENSION(:), ALLOCATABLE     :: CC_GroupIndex               ! Cable control group indices
    INTEGER(IntKi)                :: StC_Mode                    ! Flag for StC Control
    INTEGER(IntKi)                :: StC_Group_N                 ! Number of cable control groups
    INTEGER(IntKi), DIMENSION(:), ALLOCATABLE     :: StC_GroupIndex              ! Cable control group indices
    REAL(DbKi)                    :: PC_RtTq99                   ! 99% of the rated torque value, using for switching between pitch and torque control, [Nm].
    REAL(DbKi)                    :: VS_MaxOMTq                  ! Maximum torque at the end of the below-rated region 2, [Nm]
    REAL(DbKi)                    :: VS_MinOMTq                  ! Minimum torque at the beginning of the below-rated region 2, [Nm]
END TYPE ControlParameters

TYPE, PUBLIC :: WE
    REAL(DbKi)                    :: om_r                        ! Estimated rotor speed [rad/s]
    REAL(DbKi)                    :: v_t                         ! Estimated wind speed, turbulent component [m/s]
    REAL(DbKi)                    :: v_m                         ! Estimated wind speed, 10-minute averaged [m/s]
    REAL(DbKi)                    :: v_h                         ! Combined estimated wind speed [m/s]
    REAL(DbKi), DIMENSION(3,3)     :: P                           ! Covariance estiamte
    REAL(DbKi), DIMENSION(3,1)     :: xh                          ! Estimated state matrix
    REAL(DbKi), DIMENSION(3,1)     :: K                           ! Kalman gain matrix
END TYPE WE

TYPE, PUBLIC :: FilterParameters
    REAL(DbKi), DIMENSION(1024)     :: lpf1_a1                     ! First order filter - Denominator coefficient 1
    REAL(DbKi), DIMENSION(1024)     :: lpf1_a0                     ! First order filter - Denominator coefficient 0
    REAL(DbKi), DIMENSION(1024)     :: lpf1_b1                     ! First order filter - Numerator coefficient 1
    REAL(DbKi), DIMENSION(1024)     :: lpf1_b0                     ! First order filter - Numerator coefficient 0
    REAL(DbKi), DIMENSION(1024)     :: lpf1_InputSignalLast        ! First order filter - Previous input
    REAL(DbKi), DIMENSION(1024)     :: lpf1_OutputSignalLast       ! First order filter - Previous output
    REAL(DbKi), DIMENSION(1024)     :: lpf2_a2                     ! Second order filter - Denominator coefficient 2
    REAL(DbKi), DIMENSION(1024)     :: lpf2_a1                     ! Second order filter - Denominator coefficient 1
    REAL(DbKi), DIMENSION(1024)     :: lpf2_a0                     ! Second order filter - Denominator coefficient 0
    REAL(DbKi), DIMENSION(1024)     :: lpf2_b2                     ! Second order filter - Numerator coefficient 2
    REAL(DbKi), DIMENSION(1024)     :: lpf2_b1                     ! Second order filter - Numerator coefficient 1
    REAL(DbKi), DIMENSION(1024)     :: lpf2_b0                     ! Second order filter - Numerator coefficient 0
    REAL(DbKi), DIMENSION(1024)     :: lpf2_InputSignalLast2       ! Second order filter - Previous input 2
    REAL(DbKi), DIMENSION(1024)     :: lpf2_OutputSignalLast2      ! Second order filter - Previous output 2
    REAL(DbKi), DIMENSION(1024)     :: lpf2_InputSignalLast1       ! Second order filter - Previous input 1
    REAL(DbKi), DIMENSION(1024)     :: lpf2_OutputSignalLast1      ! Second order filter - Previous output 1
    REAL(DbKi), DIMENSION(1024)     :: lpfV_a2                     ! Second order filter - Denominator coefficient 1
    REAL(DbKi), DIMENSION(1024)     :: lpfV_a1                     ! Second order filter - Denominator coefficient 1
    REAL(DbKi), DIMENSION(1024)     :: lpfV_a0                     ! Second order filter - Denominator coefficient 0
    REAL(DbKi), DIMENSION(1024)     :: lpfV_b2                     ! Second order filter - Numerator coefficient 2
    REAL(DbKi), DIMENSION(1024)     :: lpfV_b1                     ! Second order filter - Numerator coefficient 1
    REAL(DbKi), DIMENSION(1024)     :: lpfV_b0                     ! Second order filter - Numerator coefficient 0
    REAL(DbKi), DIMENSION(1024)     :: lpfV_InputSignalLast2       ! Second order filter - Previous input 2
    REAL(DbKi), DIMENSION(1024)     :: lpfV_OutputSignalLast2      ! Second order filter - Previous output 2
    REAL(DbKi), DIMENSION(1024)     :: lpfV_InputSignalLast1       ! Second order filter - Previous input 1
    REAL(DbKi), DIMENSION(1024)     :: lpfV_OutputSignalLast1      ! Second order filter - Previous output 1
    REAL(DbKi), DIMENSION(1024)     :: hpf_InputSignalLast         ! High pass filter - Previous output 1
    REAL(DbKi), DIMENSION(1024)     :: hpf_OutputSignalLast        ! High pass filter - Previous output 1
    REAL(DbKi), DIMENSION(1024)     :: nfs_OutputSignalLast1       ! Notch filter slopes previous output 1
    REAL(DbKi), DIMENSION(1024)     :: nfs_OutputSignalLast2       ! Notch filter slopes previous output 2
    REAL(DbKi), DIMENSION(1024)     :: nfs_InputSignalLast1        ! Notch filter slopes previous input 1
    REAL(DbKi), DIMENSION(1024)     :: nfs_InputSignalLast2        ! Notch filter slopes previous input 1
    REAL(DbKi), DIMENSION(1024)     :: nfs_b2                      ! Notch filter slopes numerator coefficient 2
    REAL(DbKi), DIMENSION(1024)     :: nfs_b0                      ! Notch filter slopes numerator coefficient 0
    REAL(DbKi), DIMENSION(1024)     :: nfs_a2                      ! Notch filter slopes denominator coefficient 2
    REAL(DbKi), DIMENSION(1024)     :: nfs_a1                      ! Notch filter slopes denominator coefficient 1
    REAL(DbKi), DIMENSION(1024)     :: nfs_a0                      ! Notch filter slopes denominator coefficient 0
    REAL(DbKi), DIMENSION(1024)     :: nf_OutputSignalLast1        ! Notch filter previous output 1
    REAL(DbKi), DIMENSION(1024)     :: nf_OutputSignalLast2        ! Notch filter previous output 2
    REAL(DbKi), DIMENSION(1024)     :: nf_InputSignalLast1         ! Notch filter previous input 1
    REAL(DbKi), DIMENSION(1024)     :: nf_InputSignalLast2         ! Notch filter previous input 2
    REAL(DbKi), DIMENSION(1024)     :: nf_b2                       ! Notch filter numerator coefficient 2
    REAL(DbKi), DIMENSION(1024)     :: nf_b1                       ! Notch filter numerator coefficient 1
    REAL(DbKi), DIMENSION(1024)     :: nf_b0                       ! Notch filter numerator coefficient 0
    REAL(DbKi), DIMENSION(1024)     :: nf_a1                       ! Notch filter denominator coefficient 1
    REAL(DbKi), DIMENSION(1024)     :: nf_a0                       ! Notch filter denominator coefficient 0
END TYPE FilterParameters

TYPE, PUBLIC :: rlParams
    REAL(DbKi), DIMENSION(1024)     :: LastSignal                  ! Last input signal
END TYPE rlParams

TYPE, PUBLIC :: piParams
    REAL(DbKi), DIMENSION(1024)     :: ITerm                       ! Integrator term
    REAL(DbKi), DIMENSION(1024)     :: ITermLast                   ! Previous integrator term
    REAL(DbKi), DIMENSION(1024)     :: ITerm2                      ! Integrator term - second integrator
    REAL(DbKi), DIMENSION(1024)     :: ITermLast2                  ! Previous integrator term - second integrator
    REAL(DbKi), DIMENSION(1024)     :: ELast                       ! Previous error term for derivative
END TYPE piParams

TYPE, PUBLIC :: resParams
    REAL(DbKi), DIMENSION(1024)     :: res_OutputSignalLast1       ! Previous output signal
    REAL(DbKi), DIMENSION(1024)     :: res_OutputSignalLast2       ! Previous output signal - second integrator
    REAL(DbKi), DIMENSION(1024)     :: res_InputSignalLast1        ! Previous input signal
    REAL(DbKi), DIMENSION(1024)     :: res_InputSignalLast2        ! Previous input signal - second integrator
END TYPE resParams

TYPE, PUBLIC :: LocalVariables
    INTEGER(IntKi)                :: iStatus                     ! Initialization status
    INTEGER(IntKi)                :: AlreadyInitialized = 0      ! Has ROSCO already been initialized (0-no, 1-yes)
    INTEGER(IntKi)                :: RestartWSE                  ! Restart WSE flag, 0 - restart, 1- not, to mirror iStatus
    REAL(DbKi)                    :: Time                        ! Time [s]
    REAL(DbKi)                    :: DT                          ! Time step [s]
    LOGICAL                       :: WriteThisStep               ! Write an output line this time step
    INTEGER(IntKi)                :: n_DT                        ! number of timesteps since start
    REAL(DbKi)                    :: Time_Last                   ! Last time [s]
    REAL(DbKi)                    :: VS_GenPwr                   ! Generator power [W]
    REAL(DbKi)                    :: GenSpeed                    ! Generator speed (HSS) [rad/s]
    REAL(DbKi)                    :: RotSpeed                    ! Rotor speed (LSS) [rad/s]
    REAL(DbKi)                    :: NacHeading                  ! Nacelle heading of the turbine w.r.t. north [deg]
    REAL(DbKi)                    :: NacVane                     ! Nacelle vane angle [deg]
    REAL(DbKi)                    :: NacVaneF                    ! Filtered nacelle vane angle [deg]
    REAL(DbKi)                    :: WindDir                     ! Compassed wind direction, accounting for nacelle heading [deg]
    REAL(DbKi)                    :: HorWindV                    ! Hub height wind speed m/s
    REAL(DbKi)                    :: HorWindV_F                  ! Filtered hub height wind speed m/s
    REAL(DbKi)                    :: rootMOOP(3)                 ! Blade root bending moment [Nm]
    REAL(DbKi)                    :: rootMOOPF(3)                ! Filtered Blade root bending moment [Nm]
    REAL(DbKi)                    :: BlPitch(3)                  ! Blade pitch [rad]
    REAL(DbKi)                    :: BlPitchCMeas                ! Mean (collective) blade pitch [rad]
    REAL(DbKi)                    :: Azimuth                     ! Rotor aziumuth angle [rad]
    REAL(DbKi)                    :: OL_Azimuth                  ! Rotor aziumuth angle [rad]
    REAL(DbKi)                    :: AzUnwrapped                 ! Rotor aziumuth angle [rad]
    REAL(DbKi)                    :: AzError                     ! Azimuth error angle [rad]
    REAL(DbKi)                    :: GenTqAz                     ! Gen torque command due to azimuth error
    REAL(DbKi)                    :: AzBuffer(2)                 ! Current and last rotor aziumuth angles [rad]
    INTEGER(IntKi)                :: NumBl                       ! Number of blades [-]
    REAL(DbKi)                    :: FA_Acc_TT                   ! Tower fore-aft acceleration [m/s^2], in fixed tower-top reference frame
    REAL(DbKi)                    :: SS_Acc_TT                   ! Tower side-to-side acceleration [m/s^2], in fixed tower-top reference frame
    REAL(DbKi)                    :: FA_Acc_Nac                  ! Tower fore-aft acceleration [m/s^2] in nacelle reference frame
    REAL(DbKi)                    :: NacIMU_FA_RAcc              ! Tower fore-aft acceleration [rad/s^2]
    REAL(DbKi)                    :: FA_AccHPF                   ! High-pass filtered fore-aft acceleration [m/s^2]
    REAL(DbKi)                    :: FA_AccHPFI                  ! Tower velocity, high-pass filtered and integrated fore-aft acceleration [m/s]
    REAL(DbKi)                    :: FA_PitCom(3)                ! Tower fore-aft vibration damping pitch contribution [rad]
    REAL(DbKi)                    :: VS_RefSpd                   ! Torque control generator speed set point [rad/s]
    REAL(DbKi)                    :: VS_RefSpd_TSR               ! Torque control generator speed set point based on optimal TSR (unfiltered) [rad/s]
    REAL(DbKi)                    :: VS_RefSpd_TRA               ! Torque control generator speed set point after freq avoidance [rad/s]
    REAL(DbKi)                    :: VS_RefSpd_RL                ! Torque control generator speed set point after rate limit [rad/s]
    REAL(DbKi)                    :: PC_RefSpd                   ! Generator speed set point of pitch controller [rad/s]
    REAL(DbKi)                    :: PC_RefSpd_SS                ! Generator speed set point of pitch controller after setpoint smoothing [rad/s]
    REAL(DbKi)                    :: PC_RefSpd_PRC               ! Generator speed set point of pitch controller after power ref control [rad/s]
    REAL(DbKi)                    :: RotSpeedF                   ! Filtered LSS (rotor) speed [rad/s].
    REAL(DbKi)                    :: GenSpeedF                   ! Filtered HSS (generator) speed [rad/s].
    REAL(DbKi)                    :: GenTq                       ! Electrical generator torque, [Nm].
    REAL(DbKi)                    :: GenTqMeas                   ! Measured generator torque [Nm]
    REAL(DbKi)                    :: GenArTq                     ! Electrical generator torque, for above-rated PI-control [Nm].
    REAL(DbKi)                    :: GenBrTq                     ! Electrical generator torque, for below-rated PI-control [Nm].
    REAL(DbKi)                    :: VS_KOmega2_GenTq            ! Calculation of torque signal used by K*Omega^2 controller
    REAL(DbKi)                    :: VS_ConstPwr_GenTq           ! Calculation of constant-power torque signal
    REAL(DbKi)                    :: IPC_PitComF(3)              ! Commanded pitch of each blade as calculated by the individual pitch controller, F stands for low-pass filtered [rad].
    REAL(DbKi)                    :: PC_KP                       ! Proportional gain for pitch controller at rated pitch (zero) [s].
    REAL(DbKi)                    :: PC_KI                       ! Integral gain for pitch controller at rated pitch (zero) [-].
    REAL(DbKi)                    :: PC_KD                       ! Differential gain for pitch controller at rated pitch (zero) [-].
    REAL(DbKi)                    :: PC_TF                       ! First-order filter parameter for derivative action
    REAL(DbKi)                    :: PC_MaxPit                   ! Maximum pitch setting in pitch controller (variable) [rad].
    REAL(DbKi)                    :: PC_MinPit                   ! Minimum pitch setting in pitch controller (variable) [rad].
    REAL(DbKi)                    :: PC_PitComT                  ! Total command pitch based on the sum of the proportional and integral terms [rad].
    REAL(DbKi)                    :: PC_PitComT_Last             ! Last total command pitch based on the sum of the proportional and integral terms [rad].
    REAL(DbKi)                    :: BlPitchCMeasF               ! Filtered collective pitch read from turbine/simulator [rad].
    REAL(DbKi)                    :: PC_PitComT_IPC(3)           ! Total command pitch based on the sum of the proportional and integral terms, including IPC term [rad].
    REAL(DbKi)                    :: PC_PwrErr                   ! Power error with respect to rated power [W]
    REAL(DbKi)                    :: PC_SpdErr                   ! Current speed error (pitch control) [rad/s].
    REAL(DbKi)                    :: IPC_AxisTilt_1P             ! Integral of the direct axis, 1P
    REAL(DbKi)                    :: IPC_AxisYaw_1P              ! Integral of quadrature, 1P
    REAL(DbKi)                    :: IPC_AxisTilt_2P             ! Integral of the direct axis, 2P
    REAL(DbKi)                    :: IPC_AxisYaw_2P              ! Integral of quadrature, 2P
    REAL(DbKi)                    :: axisTilt_1P                 ! Tilt moment, 1P
    REAL(DbKi)                    :: axisYaw_1P                  ! Yaw moment, 1P
    REAL(DbKi)                    :: axisYawF_1P                 ! Filtered yaw moment, 1P
    REAL(DbKi)                    :: axisTilt_2P                 ! Tilt moment, 2P
    REAL(DbKi)                    :: axisYaw_2P                  ! Yaw moment, 2P
    REAL(DbKi)                    :: axisYawF_2P                 ! Filtered yaw moment, 2P
    REAL(DbKi)                    :: IPC_KI(2)                   ! Integral gain for IPC, after ramp [-]
    REAL(DbKi)                    :: IPC_KP(2)                   ! Proportional gain for IPC, after ramp [-]
    REAL(DbKi)                    :: IPC_IntSat                  ! Integrator saturation (maximum signal amplitude contrbution to pitch from IPC)
    INTEGER(IntKi)                :: PC_State                    ! State of the pitch control system
    REAL(DbKi)                    :: PitCom(3)                   ! Commanded pitch of each blade the last time the controller was called [rad].
    REAL(DbKi)                    :: PitCom_SD(3)                ! Commanded pitch of each blade due to shutdown [rad].
    REAL(DbKi)                    :: PitComAct(3)                ! Actuated pitch command of each blade [rad].
    REAL(DbKi)                    :: SS_DelOmegaF                ! Filtered setpoint shifting term defined in setpoint smoother [rad/s].
    REAL(DbKi)                    :: TestType                    ! Test variable, no use
    REAL(DbKi)                    :: Kp_Float                    ! Local, instantaneous Kp_Float, scheduled on wind speed, if desired
    REAL(DbKi)                    :: VS_MaxTq                    ! Maximum allowable generator torque [Nm].
    REAL(DbKi)                    :: VS_LastGenTrq               ! Commanded electrical generator torque the last time the controller was called [Nm].
    REAL(DbKi)                    :: VS_LastGenPwr               ! Commanded electrical generator torque the last time the controller was called [Nm].
    REAL(DbKi)                    :: VS_MechGenPwr               ! Mechanical power on the generator axis [W]
    REAL(DbKi)                    :: VS_SpdErrAr                 ! Current speed error for region 2.5 PI controller (generator torque control) [rad/s].
    REAL(DbKi)                    :: VS_SpdErrBr                 ! Current speed error for region 1.5 PI controller (generator torque control) [rad/s].
    REAL(DbKi)                    :: VS_SpdErr                   ! Current speed error for tip-speed-ratio tracking controller (generator torque control) [rad/s].
    INTEGER(IntKi)                :: VS_State                    ! State of the torque control system
    REAL(DbKi)                    :: VS_Rgn3Pitch                ! Pitch angle at which the state machine switches to region 3, [rad].
    REAL(DbKi)                    :: WE_Vw                       ! Estimated wind speed [m/s]
    REAL(DbKi)                    :: WE_Vw_F                     ! Filtered estimated wind speed [m/s]
    REAL(DbKi)                    :: WE_VwI                      ! Integrated wind speed quantity for estimation [m/s]
    REAL(DbKi)                    :: WE_VwIdot                   ! Differentiated integrated wind speed quantity for estimation [m/s]
    INTEGER(IntKi)                :: WE_Op                       ! WSE Operational state (0- not operating, 1-operating)
    INTEGER(IntKi)                :: WE_Op_Last                  ! Last WSE Operational state (0- not operating, 1-operating)
    REAL(DbKi)                    :: VS_LastGenTrqF              ! Differentiated integrated wind speed quantity for estimation [m/s]
    REAL(DbKi)                    :: PRC_WSE_F                   ! Filtered wind speed estimate for power reference control
    REAL(DbKi)                    :: PRC_R_Speed                 ! Instantaneous PRC_R_Speed
    REAL(DbKi)                    :: PRC_R_Torque                ! Instantaneous PRC_R_Torque
    REAL(DbKi)                    :: PRC_R_Pitch                 ! Instantaneous PRC_R_Pitch
    REAL(DbKi)                    :: PRC_R_Total                 ! Instantaneous PRC_R_Total
    REAL(DbKi)                    :: PRC_Min_Pitch               ! Instantaneous PRC_Min_Pitch
    REAL(DbKi)                    :: PS_Min_Pitch                ! Instantaneous peak shaving
    REAL(DbKi)                    :: OL_Index                    ! Open loop indexing variable (time or wind speed)
    INTEGER(IntKi)                :: SU_Stage                    ! Current stage of startup procedure (0- Startup not active, 1- Free-wheeling, 2,3,.. - Load stage 1,2...etc)
    REAL(DbKi)                    :: SU_LoadStageStartTime       ! Time at which the current startup load stage started
    REAL(DbKi)                    :: SU_RotSpeedF                ! Rotor speed signal filtered for startup
    INTEGER(IntKi)                :: SD_Trigger                  ! Shutdown trigger (1 - shutdown due to pitch, 2 - shutdown due to yaw error, 3 - shutdown due to generator speed, 4 - shutdown due to time)
    REAL(DbKi)                    :: SD_BlPitchF                 ! Blade pitch signal filtered for shutdown
    REAL(DbKi)                    :: SD_NacVaneF                 ! Nacelle vane signal filtered for shutdown
    REAL(DbKi)                    :: SD_GenSpeedF                ! Generator speed signal filtered for shutdown
    INTEGER(IntKi)                :: SD_Stage                    ! Current stage of shutdown procedure (0- Shutdown not active, 1- First pitch/torque rate, 2,3,...)
    REAL(DbKi)                    :: SD_StageStartTime           ! Time at which the current shutdown stage started
    REAL(DbKi)                    :: SD_MaxPitchRate             ! Maximum pitch rate during current shutdown stage [rad/s]
    REAL(DbKi)                    :: SD_MaxTorqueRate            ! Maximum torque rate during current shutdown stage [Nm/s]
    REAL(DbKi)                    :: GenTq_SD                    ! Electrical generator torque command for shutdown, [Nm].
    REAL(DbKi)                    :: Fl_PitCom                   ! Shutdown, .FALSE. if inactive, .TRUE. if active
    REAL(DbKi)                    :: NACIMU_FA_AccF              ! None
    REAL(DbKi)                    :: FA_AccF                     ! Filtered fore-aft acceleration in rotation frame, ready for control
    INTEGER(IntKi)                :: FA_Hist                     ! Hysteresis state for tower resonance avoidance.
    REAL(DbKi)                    :: TRA_LastRefSpd              ! Last reference generator speed
    REAL(DbKi)                    :: VS_RefSpeed                 ! Torque controller reference speed
    REAL(DbKi)                    :: PtfmTDX                     ! Platform motion -- Displacement TDX (m)')
    REAL(DbKi)                    :: PtfmTDY                     ! Platform motion -- Displacement TDY (m)')
    REAL(DbKi)                    :: PtfmTDZ                     ! Platform motion -- Displacement TDZ (m)')
    REAL(DbKi)                    :: PtfmRDX                     ! Platform motion -- Displacement RDX (rad)')
    REAL(DbKi)                    :: PtfmRDY                     ! Platform motion -- Displacement RDY (rad)')
    REAL(DbKi)                    :: PtfmRDZ                     ! Platform motion -- Displacement RDZ (rad)')
    REAL(DbKi)                    :: PtfmTVX                     ! Platform motion -- Velocity     TVX (m/s)')
    REAL(DbKi)                    :: PtfmTVY                     ! Platform motion -- Velocity     TVY (m/s)')
    REAL(DbKi)                    :: PtfmTVZ                     ! Platform motion -- Velocity     TVZ (m/s)')
    REAL(DbKi)                    :: PtfmRVX                     ! Platform motion -- Velocity     RVX (rad/s)')
    REAL(DbKi)                    :: PtfmRVY                     ! Platform motion -- Velocity     RVY (rad/s)')
    REAL(DbKi)                    :: PtfmRVZ                     ! Platform motion -- Velocity     RVZ (rad/s)')
    REAL(DbKi)                    :: PtfmTAX                     ! Platform motion -- Acceleration TAX (m/s^2)')
    REAL(DbKi)                    :: PtfmTAY                     ! Platform motion -- Acceleration TAY (m/s^2)')
    REAL(DbKi)                    :: PtfmTAZ                     ! Platform motion -- Acceleration TAZ (m/s^2)')
    REAL(DbKi)                    :: PtfmRAX                     ! Platform motion -- Acceleration RAX (rad/s^2)')
    REAL(DbKi)                    :: PtfmRAY                     ! Platform motion -- Acceleration RAY (rad/s^2)')
    REAL(DbKi)                    :: PtfmRAZ                     ! Platform motion -- Acceleration RAZ (rad/s^2)')
    REAL(DbKi)                    :: CC_DesiredL(12)             ! None
    REAL(DbKi)                    :: CC_ActuatedL(12)            ! None
    REAL(DbKi)                    :: CC_ActuatedDL(12)           ! None
    REAL(DbKi)                    :: StC_Input(12)               ! None
    REAL(DbKi)                    :: Flp_Angle(3)                ! Flap Angle (rad)
    REAL(DbKi)                    :: RootMyb_Last(3)             ! Last blade root bending moment (Nm)
    INTEGER(IntKi)                :: ACC_INFILE_SIZE             ! Length of parameter input filename
    CHARACTER, DIMENSION(:), ALLOCATABLE     :: ACC_INFILE                  ! Parameter input filename
    LOGICAL                       :: restart                     ! Restart flag
    COMPLEX(DbKi)                 :: AWC_complexangle(3)         ! Complex angle for each blade, sum of modes?
    REAL(DbKi)                    :: TiltMean                    ! Mean tilt blade moment [Nm]
    REAL(DbKi)                    :: YawMean                     ! Mean yaw blade moment [Nm]
    INTEGER(IntKi)                :: ZMQ_ID                      ! 0000 - 9999, Identifier of the rosco, used for zeromq interface only
    REAL(DbKi)                    :: ZMQ_YawOffset               ! Yaw offset command, [rad]
    REAL(DbKi)                    :: ZMQ_TorqueOffset            ! Torque offset command, [Nm]
    REAL(DbKi)                    :: ZMQ_PitOffset(3)            ! Pitch command offset provided by ZeroMQ
    REAL(DbKi)                    :: ZMQ_R_Speed                 ! R_Speed command provided by ZeroMQ
    REAL(DbKi)                    :: ZMQ_R_Torque                ! R_Torque command provided by ZeroMQ
    REAL(DbKi)                    :: ZMQ_R_Pitch                 ! R_Pitch command provided by ZeroMQ
    TYPE(WE)                      :: WE                          ! Wind speed estimator parameters derived type
    TYPE(FilterParameters)        :: FP                          ! Filter parameters derived type
    TYPE(piParams)                :: piP                         ! PI parameters derived type
    TYPE(resParams)               :: resP                        ! PR parameters derived type
    TYPE(rlParams)                :: rlP                         ! Rate limiter parameters derived type
END TYPE LocalVariables

TYPE, PUBLIC :: ObjectInstances
    INTEGER(IntKi)                :: instLPF                     ! Low-pass filter instance
    INTEGER(IntKi)                :: instSecLPF                  ! Second order low-pass filter instance
    INTEGER(IntKi)                :: instSecLPFV                 ! Second order low-pass filter instance
    INTEGER(IntKi)                :: instHPF                     ! High-pass filter instance
    INTEGER(IntKi)                :: instNotchSlopes             ! Notch filter slopes instance
    INTEGER(IntKi)                :: instNotch                   ! Notch filter instance
    INTEGER(IntKi)                :: instPI                      ! PI controller instance
    INTEGER(IntKi)                :: instRes                     ! PR controller instance
    INTEGER(IntKi)                :: instRL                      ! Rate limiter instance
END TYPE ObjectInstances

TYPE, PUBLIC :: PerformanceData
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: TSR_vec                     ! TSR vector for performance surfaces
    REAL(DbKi), DIMENSION(:), ALLOCATABLE     :: Beta_vec                    ! Blade pitch vector for performance surfaces [deg]
    REAL(DbKi), DIMENSION(:,:), ALLOCATABLE     :: Cp_mat                      ! Power coefficient surface
    REAL(DbKi), DIMENSION(:,:), ALLOCATABLE     :: Ct_mat                      ! Thrust coefficient surface
    REAL(DbKi), DIMENSION(:,:), ALLOCATABLE     :: Cq_mat                      ! Torque coefficient surface
END TYPE PerformanceData

TYPE, PUBLIC :: DebugVariables
    REAL(DbKi)                    :: WE_Cp                       ! Cp that WSE uses to determine aerodynamic torque [-]
    REAL(DbKi)                    :: WE_b                        ! Pitch that WSE uses to determine aerodynamic torque [-]
    REAL(DbKi)                    :: WE_w                        ! Rotor Speed that WSE uses to determine aerodynamic torque [-]
    REAL(DbKi)                    :: WE_t                        ! Torque that WSE uses [-]
    REAL(DbKi)                    :: WE_Vm                       ! Mean wind speed component in WSE [m/s]
    REAL(DbKi)                    :: WE_Vt                       ! Turbulent wind speed component in WSE [m/s]
    REAL(DbKi)                    :: WE_Vw                       ! Estimated wind speed in WSE [m/s]
    REAL(DbKi)                    :: WE_lambda                   ! TSR in WSE [rad]
    REAL(DbKi)                    :: PC_PICommand                ! Commanded collective pitch from pitch PI controller [rad]
    REAL(DbKi)                    :: GenSpeedF                   ! Filtered generator speed [rad/s]
    REAL(DbKi)                    :: RotSpeedF                   ! Filtered rotor speed [rad/s]
    REAL(DbKi)                    :: NacIMU_FA_AccF              ! Filtered NacIMU_FA_RAcc [rad/s]
    REAL(DbKi)                    :: FA_AccF                     ! Filtered FA_Acc [m/s]
    REAL(DbKi)                    :: Fl_PitCom                   ! Floating contribution to the pitch command [rad]
    REAL(DbKi)                    :: PC_MinPit                   ! Minimum blade pitch angle [rad]
    REAL(DbKi)                    :: axisTilt_1P                 ! Tilt component of coleman transformation, 1P
    REAL(DbKi)                    :: axisYaw_1P                  ! Yaw component of coleman transformation, 1P
    REAL(DbKi)                    :: axisTilt_2P                 ! Tilt component of coleman transformation, 2P
    REAL(DbKi)                    :: axisYaw_2P                  ! Yaw component of coleman transformation, 2P
    REAL(DbKi)                    :: YawRateCom                  ! Commanded yaw rate [rad/s].
    REAL(DbKi)                    :: NacHeadingTarget            ! Target nacelle heading [deg].
    REAL(DbKi)                    :: NacVaneOffset               ! Nacelle vane angle with offset [deg].
    REAL(DbKi)                    :: Yaw_Err                     ! Yaw error [deg].
    REAL(DbKi)                    :: YawState                    ! State of yaw controller
    REAL(DbKi)                    :: VS_RefSpd                   ! Torque control generator speed set point [rad/s]
    REAL(DbKi)                    :: PC_RefSpd                   ! Generator speed set point of pitch controller [rad/s]
END TYPE DebugVariables

TYPE, PUBLIC :: ErrorVariables
    INTEGER(IntKi)                :: size_avcMSG                 ! None
    INTEGER(C_INT)                :: aviFAIL                     ! A flag used to indicate the success of this DLL call set as follows: 0 if the DLL call was successful, >0 if the DLL call was successful but cMessage should be issued as a warning messsage, <0 if the DLL call was unsuccessful or for any other reason the simulation is to be stopped at this point with cMessage as the error message.
    INTEGER(C_INT)                :: ErrStat                     ! An error status flag used by OpenFAST processes
    CHARACTER(:), ALLOCATABLE     :: ErrMsg                      ! a Fortran version of the C string argument (not considered an array here) [subtract 1 for the C null-character]
END TYPE ErrorVariables

TYPE, PUBLIC :: ExtDLL_Type
    INTEGER(C_INTPTR_T)           :: FileAddr                    ! The address of file FileName. (RETURN value from LoadLibrary ) [Windows]
    TYPE(C_PTR)                   :: FileAddrX = C_NULL_PTR      ! The address of file FileName. (RETURN value from dlopen ) [Linux]
    TYPE(C_FUNPTR)                :: ProcAddr(3)                 ! The address of procedure ProcName. (RETURN value from GetProcAddress or dlsym) [initialized to Null for pack/unpack]
    CHARACTER(1024)               :: FileName                    ! The name of the DLL file including the full path to the current working directory.
    CHARACTER(1024)               :: ProcName(3) = ""            ! The name of the procedure in the DLL that will be called.
END TYPE ExtDLL_Type

TYPE, PUBLIC :: ExtControlType
    REAL(ReKi), DIMENSION(:), ALLOCATABLE     :: avrSWAP                     ! The swap array- used to pass data to and from the DLL controller [see Bladed DLL documentation]
END TYPE ExtControlType

END MODULE ROSCO_Types
