text:
function mass_matrix_outer_entries!(
    mass_matrix,
    outer_control::O,
    global_index::Base.ImmutableDict{Symbol, Int64},
) where {O <: PSY.OuterControl}
    @debug "Using default mass matrix entries $O"
end

#####################################################
### Auxiliary ODE calculations via Flags dispatch ###
#####################################################

### Active Controllers ###

#Freq_Flag = 1
function _mdl_ode_RE_active_controller_AB!(
    active_controller_ode::AbstractArray{<:ACCEPTED_REAL_TYPES},
    active_controller_states::AbstractArray{<:ACCEPTED_REAL_TYPES},
    p_elec_out::ACCEPTED_REAL_TYPES,
    ω_sys::ACCEPTED_REAL_TYPES,
    Vt_filt::ACCEPTED_REAL_TYPES,
    ::Type{Base.RefValue{1}},
    active_power_control::PSY.ActiveRenewableControllerAB,
    dynamic_device::DynamicWrapper{
        PSY.DynamicInverter{
            C,
            PSY.OuterControl{
                PSY.ActiveRenewableControllerAB,
                PSY.ReactiveRenewableControllerAB,
            },
            IC,
            DC,
            P,
            F,
        },
    },
    inner_vars::AbstractVector,
) where {
    C <: PSY.Converter,
    IC <: PSY.InnerControl,
    DC <: PSY.DCSource,
    P <: PSY.FrequencyEstimator,
    F <: PSY.Filter,
}

    #Obtain external parameters
    p_ref = get_P_ref(dynamic_device)
    ω_ref = get_ω_ref(dynamic_device)
    # To do: Obtain proper frequency for a plant. For now using the system frequency.
    ω_plant = ω_sys

    #Obtain additional Active Power Controller parameters
    K_pg = PSY.get_K_pg(active_power_control)
    K_ig = PSY.get_K_ig(active_power_control)
    T_p = PSY.get_T_p(active_power_control)
    fdbd1, fdbd2 = PSY.get_fdbd_pnts(active_power_control)
    fe_min, fe_max = PSY.get_fe_lim(active_power_control)
    P_min, P_max = PSY.get_P_lim(active_power_control)
    T_g = PSY.get_T_g(active_power_control)
    D_dn = PSY.get_D_dn(active_power_control)
    D_up = PSY.get_D_up(active_power_control)
    dP_min, dP_max = PSY.get_dP_lim(active_power_control)
    P_min_inner, P_max_inner = PSY.get_P_lim_inner(active_power_control)
    T_pord = PSY.get_T_pord(active_power_control)

    #Define internal states for outer control
    p_flt = active_controller_states[1]
    ξ_P = active_controller_states[2]
    p_ext = active_controller_states[3]
    p_ord = active_controller_states[4]

    #Compute additional terms
    f_err = deadband_function(ω_ref - ω_plant, fdbd1, fdbd2)
    p_droop = min(D_dn * f_err, 0.0) + max(D_up * f_err, 0.0)
    p_err = clamp(p_ref + p_droop - p_flt, fe_min, fe_max)

    #Compute block derivatives REPCA
    _, dpflt_dt = low_pass(p_elec_out, p_flt, 1.0, T_p)
    P_pi, dξP_dt = pi_block_nonwindup(p_err, ξ_P, K_pg, K_ig, P_min, P_max)
    _, dpext_dt = low_pass(P_pi, p_ext, 1.0, T_g)

    #Compute block derivatives REECB
    p_ord_sat, dpord_dt = low_pass_nonwindup_ramp_limits(
        p_ext,
        p_ord,
        1.0,
        T_pord,
        P_min_inner,
        P_max_inner,
        dP_min,
        dP_max,
    )

    #Update ODEs
    active_controller_ode[1] = dpflt_dt
    active_controller_ode[2] = dξP_dt
    active_controller_ode[3] = dpext_dt
    active_controller_ode[4] = dpord_dt

    #Update Inner Vars: Ioc_pcmd
    inner_vars[Id_oc_var] = p_ord_sat / max(Vt_filt, VOLTAGE_DIVISION_LOWER_BOUND)
end

#Freq_Flag = 0
function _mdl_ode_RE_active_controller_AB!(
    active_controller_ode::AbstractArray{<:ACCEPTED_REAL_TYPES},
    active_controller_states::AbstractArray{<:ACCEPTED_REAL_TYPES},
    p_elec_out::ACCEPTED_REAL_TYPES,
    ω_sys::ACCEPTED_REAL_TYPES,
    Vt_filt::ACCEPTED_REAL_TYPES,
    ::Type{Base.RefValue{0}},
    active_power_control::PSY.ActiveRenewableControllerAB,
    dynamic_device::DynamicWrapper{
        PSY.DynamicInverter{
            C,
            PSY.OuterControl{
                PSY.ActiveRenewableControllerAB,
                PSY.ReactiveRenewableControllerAB,
            },
            IC,
            DC,
            P,
            F,
        },
    },
    inner_vars::AbstractVector,
) where {
    C <: PSY.Converter,
    IC <: PSY.InnerControl,
    DC <: PSY.DCSource,
    P <: PSY.FrequencyEstimator,
    F <: PSY.Filter,
}

    #Obtain external parameters
    p_ref = get_P_ref(dynamic_device)
    #Obtain additional Active Power Controller parameters
    T_pord = PSY.get_T_pord(active_power_control)

    #Define internal states for outer control
    p_ord = active_controller_states[1]

    #Compute block derivatives
    _, dpord_dt = low_pass(p_ref, p_ord, 1.0, T_pord)

    #Update ODE
    active_controller_ode[1] = dpord_dt

    #Update Inner Vars: Ioc_pcmd
    inner_vars[Id_oc_var] = p_ord / max(Vt_filt, VOLTAGE_DIVISION_LOWER_BOUND)
end

### Reactive Controllers ###

# Order of Flags are:
# Ref_Flag, PF_Flag, V_Flag

# VC_Flag == N/A && Ref_Flag == 0 && PF_Flag == 0 && V_Flag == 1
# Named: Fixed Plant Q: Not compliant if Q_Flag = 0 from Inner Control
# Named: Plant Q and Local Q/V if Q_Flag = 1 (compliant).
function _mdl_ode_RE_reactive_controller_AB!(
    reactive_controller_ode::AbstractArray{<:ACCEPTED_REAL_TYPES},
    reactive_controller_states::AbstractArray{<:ACCEPTED_REAL_TYPES},
    q_elec_out::ACCEPTED_REAL_TYPES,
    Vt_filt::ACCEPTED_REAL_TYPES,
    ::Type{Base.RefValue{0}},
    ::Type{Base.RefValue{0}},
    ::Type{Base.RefValue{1}},
    reactive_power_control::PSY.ReactiveRenewableControllerAB,
    dynamic_device::DynamicWrapper{
        PSY.DynamicInverter{
            C,
            PSY.OuterControl{
                PSY.ActiveRenewableControllerAB,
                PSY.ReactiveRenewableControllerAB,
            },
            IC,
            DC,
            P,
            F,
        },
    },
    inner_vars::AbstractVector,
) where {
    C <: PSY.Converter,
    IC <: PSY.InnerControl,
    DC <: PSY.DCSource,
    P <: PSY.FrequencyEstimator,
    F <: PSY.Filter,
}

    #Obtain external parameters
    q_ref = get_Q_ref(dynamic_device)

    # Get Reactive Controller parameters
    T_fltr = PSY.get_T_fltr(reactive_power_control)
    K_p = PSY.get_K_p(reactive_power_control)
    K_i = PSY.get_K_i(reactive_power_control)
    T_ft = PSY.get_T_ft(reactive_power_control)
    T_fv = PSY.get_T_fv(reactive_power_control)
    # V_frz not implemented yet
    # V_frz = PSY.get_V_frz(reactive_power_control)
    e_min, e_max = PSY.get_e_lim(reactive_power_control)
    dbd1, dbd2 = PSY.get_dbd_pnts(reactive_power_control)
    Q_min, Q_max = PSY.get_Q_lim(reactive_power_control)
    Q_min_inner, Q_max_inner = PSY.get_Q_lim_inner(reactive_power_control)
    V_min, V_max = PSY.get_V_lim(reactive_power_control)
    K_qp = PSY.get_K_qp(reactive_power_control)
    K_qi = PSY.get_K_qi(reactive_power_control)

    #Define internal states for Reactive Control
    q_flt = reactive_controller_states[1]
    ξq_oc = reactive_controller_states[2]
    q_LL = reactive_controller_states[3]
    ξ_Q = reactive_controller_states[4]

    #Compute additional variables
    q_err = clamp(deadband_function(q_ref - q_flt, dbd1, dbd2), e_min, e_max)

    #Compute block derivatives REPCA
    _, dqflt_dt = low_pass(q_elec_out, q_flt, 1.0, T_fltr)
    Q_pi_sat, dξqoc_dt = pi_block_nonwindup(q_err, ξq_oc, K_p, K_i, Q_min, Q_max)
    Q_ext, dqLL_dt = lead_lag(Q_pi_sat, q_LL, 1.0, T_ft, T_fv)

    #Compute block derivatives REECB
    V_pi_in = clamp(Q_ext, Q_min_inner, Q_max_inner) - q_elec_out
    V_pi_sat, dξQ_dt = pi_block_nonwindup(V_pi_in, ξ_Q, K_qp, K_qi, V_min, V_max)

    #Update ODEs
    reactive_controller_ode[1] = dqflt_dt
    reactive_controller_ode[2] = dξqoc_dt
    reactive_controller_ode[3] = dqLL_dt
    reactive_controller_ode[4] = dξQ_dt

    #Update Inner Vars
    inner_vars[V_oc_var] = V_pi_sat - Vt_filt
    inner_vars[Iq_oc_var] = Q_ext / max(Vt_filt, VOLTAGE_DIVISION_LOWER_BOUND)
end

# VC_Flag == N/A && Ref_Flag == 0 && PF_Flag == 0 && V_Flag == 0
# Fixed Plant Q if Q_Flag = 0 from Inner Control (not Compliant from CAISO requirements)
function _mdl_ode_RE_reactive_controller_AB!(
    reactive_controller_ode::AbstractArray{<:ACCEPTED_REAL_TYPES},
    reactive_controller_states::AbstractArray{<:ACCEPTED_REAL_TYPES},
    q_elec_out::ACCEPTED_REAL_TYPES,
    Vt_filt::ACCEPTED_REAL_TYPES,
    ::Type{Base.RefValue{0}},
    ::Type{Base.RefValue{0}},
    ::Type{Base.RefValue{0}},
    reactive_power_control::PSY.ReactiveRenewableControllerAB,
    dynamic_device::DynamicWrapper{
        PSY.DynamicInverter{
            C,
            PSY.OuterControl{
                PSY.ActiveRenewableControllerAB,
                PSY.ReactiveRenewableControllerAB,
            },
            IC,
            DC,
            P,
            F,
        },
    },
    inner_vars::AbstractVector,
) where {
    C <: PSY.Converter,
    IC <: PSY.InnerControl,
    DC <: PSY.DCSource,
    P <: PSY.FrequencyEstimator,
    F <: PSY.Filter,
}
    #Obtain external parameters
    q_ref = get_Q_ref(dynamic_device)

    # Get Reactive Controller parameters
    T_fltr = PSY.get_T_fltr(reactive_power_control)
    K_p = PSY.get_K_p(reactive_power_control)
    K_i = PSY.get_K_i(reactive_power_control)
    T_ft = PSY.get_T_ft(reactive_power_control)
    T_fv = PSY.get_T_fv(reactive_power_control)
    # V_frz not implemented yet
    # V_frz = PSY.get_V_frz(reactive_power_control)
    e_min, e_max = PSY.get_e_lim(reactive_power_control)
    dbd1, dbd2 = PSY.get_dbd_pnts(reactive_power_control)
    Q_min, Q_max = PSY.get_Q_lim(reactive_power_control)

    #Define internal states for Reactive Control
    q_flt = reactive_controller_states[1]
    ξq_oc = reactive_controller_states[2]
    q_LL = reactive_controller_states[3]

    #Compute additional variables
    q_err = clamp(deadband_function(q_ref - q_flt, dbd1, dbd2), e_min, e_max)

    #Compute block derivatives REPCA
    _, dqflt_dt = low_pass(q_elec_out, q_flt, 1.0, T_fltr)
    Q_pi_sat, dξqoc_dt = pi_block_nonwindup(q_err, ξq_oc, K_p, K_i, Q_min, Q_max)
    Q_ext, dqLL_dt = lead_lag(Q_pi_sat, q_LL, 1.0, T_ft, T_fv)

    #Update ODEs
    reactive_controller_ode[1] = dqflt_dt
    reactive_controller_ode[2] = dξqoc_dt
    reactive_controller_ode[3] = dqLL_dt

    #Update Inner Vars
    inner_vars[V_oc_var] = Q_ext - Vt_filt
    inner_vars[Iq_oc_var] = Q_ext / max(Vt_filt, VOLTAGE_DIVISION_LOWER_BOUND)
end

# VC_Flag == 0 or 1 && Ref_Flag == 1 && PF_Flag == 0 && V_Flag == 1
# Plant V if Q_Flag = 0 (compliant)
# Plant V and Local Q/V if Q_Flag = 1 (compliant)
# Ref_Flag = 1 is used for plant-level voltage control, typically some point of the entire plant
# This depends on where V_reg is being measured. For our purposes, to regulate V_t, the voltage bus that
# the plant is connected, you can do it by setting up K_c = 0 (for VC_Flag = 0) or Rc = Xc = 0 (for VC_Flag = 1)
function _mdl_ode_RE_reactive_controller_AB!(
    reactive_controller_ode,
    reactive_controller_states,
    q_elec_out,
    Vt_filt,
    ::Type{Base.RefValue{1}},
    ::Type{Base.RefValue{0}},
    ::Type{Base.RefValue{1}},
    reactive_power_control::PSY.ReactiveRenewableControllerAB,
    dynamic_device::DynamicWrapper{
        PSY.DynamicInverter{
            C,
            PSY.OuterControl{
                PSY.ActiveRenewableControllerAB,
                PSY.ReactiveRenewableControllerAB,
            },
            IC,
            DC,
            P,
            F,
        },
    },
    inner_vars::AbstractVector,
) where {
    C <: PSY.Converter,
    IC <: PSY.InnerControl,
    DC <: PSY.DCSource,
    P <: PSY.FrequencyEstimator,
    F <: PSY.Filter,
}
    #Obtain external parameters
    V_ref = get_V_ref(dynamic_device)

    #Obtain regulated voltage (assumed to be terminal voltage)
    V_reg = sqrt(inner_vars[Vr_inv_var]^2 + inner_vars[Vi_inv_var]^2)
    I_R = inner_vars[Ir_inv_var]
    I_I = inner_vars[Ii_inv_var]

    # Get Reactive Controller parameters
    T_fltr = PSY.get_T_fltr(reactive_power_control)
    K_p = PSY.get_K_p(reactive_power_control)
    K_c = PSY.get_K_c(reactive_power_control)
    R_c = PSY.get_R_c(reactive_power_control)
    X_c = PSY.get_R_c(reactive_power_control)
    VC_Flag = PSY.get_VC_Flag(reactive_power_control)
    K_i = PSY.get_K_i(reactive_power_control)
    T_ft = PSY.get_T_ft(reactive_power_control)
    T_fv = PSY.get_T_fv(reactive_power_control)
    # V_frz not implemented yet
    # V_frz = PSY.get_V_frz(reactive_power_control)
    e_min, e_max = PSY.get_e_lim(reactive_power_control)
    dbd1, dbd2 = PSY.get_dbd_pnts(reactive_power_control)
    Q_min, Q_max = PSY.get_Q_lim(reactive_power_control)
    Q_min_inner, Q_max_inner = PSY.get_Q_lim_inner(reactive_power_control)
    V_min, V_max = PSY.get_V_lim(reactive_power_control)
    K_qp = PSY.get_K_qp(reactive_power_control)
    K_qi = PSY.get_K_qi(reactive_power_control)

    #Define internal states for Reactive Control
    V_cflt = reactive_controller_states[1]
    ξq_oc = reactive_controller_states[2]
    q_LL = reactive_controller_states[3]
    ξ_Q = reactive_controller_states[4]

    #Compute input to the compensated voltage filter
    if VC_Flag == 0
        V_flt_input = V_reg + K_c * q_elec_out
    else
        # Calculate compensated voltage: | V_reg - (R_c + jX_c)(I_r + jI_i) |
        V_flt_input = sqrt(
            V_reg^2 +
            2 * V_reg * (I_I * X_c - I_R * R_c) +
            (I_I^2 + I_R^2) * (R_c^2 + X_c^2),
        )
    end
    #Q error - PI controller
    q_err = clamp(deadband_function(V_ref - V_cflt, dbd1, dbd2), e_min, e_max)

    #Compute block derivatives REPCA
    _, dVcflt_dt = low_pass(V_flt_input, V_cflt, 1.0, T_fltr)
    Q_pi_sat, dξqoc_dt = pi_block_nonwindup(q_err, ξq_oc, K_p, K_i, Q_min, Q_max)
    Q_ext, dqLL_dt = lead_lag(Q_pi_sat, q_LL, 1.0, T_ft, T_fv)

    #Compute block derivatives REECB
    V_pi_in = clamp(Q_ext, Q_min_inner, Q_max_inner) - q_elec_out
    V_pi_sat, dξQ_dt = pi_block_nonwindup(V_pi_in, ξ_Q, K_qp, K_qi, V_min, V_max)

    #Update ODEs
    reactive_controller_ode[1] = dVcflt_dt
    reactive_controller_ode[2] = dξqoc_dt
    reactive_controller_ode[3] = dqLL_dt
    reactive_controller_ode[4] = dξQ_dt

    #Update Inner Vars
    inner_vars[V_oc_var] = V_pi_sat - Vt_filt
    inner_vars[Iq_oc_var] = Q_ext / max(Vt_filt, VOLTAGE_DIVISION_LOWER_BOUND)
end

# VC_Flag == 0 or 1 && Ref_Flag == 1 && PF_Flag == 0 && V_Flag == 0
# Plant V if Q_Flag = 0 (compliant)
# Plant V and Local V if Q_Flag = 1 (compliant)
# Ref_Flag = 1 is used for plant-level voltage control, typically some point of the entire plant
# This depends on where V_reg is being measured. For our purposes, to regulate V_t, the voltage bus that
# the plant is connected, you can do it by setting up K_c = 0 (for VC_Flag = 0) or Rc = Xc = 0 (for VC_Flag = 1)
# CURRENTLY NOT WORKING with Q_Flag = 1
function _mdl_ode_RE_reactive_controller_AB!(
    reactive_controller_ode,
    reactive_controller_states,
    q_elec_out,
    Vt_filt,
    ::Type{Base.RefValue{1}},
    ::Type{Base.RefValue{0}},
    ::Type{Base.RefValue{0}},
    reactive_power_control::PSY.ReactiveRenewableControllerAB,
    dynamic_device::DynamicWrapper{
        PSY.DynamicInverter{
            C,
            PSY.OuterControl{
                PSY.ActiveRenewableControllerAB,
                PSY.ReactiveRenewableControllerAB,
            },
            IC,
            DC,
            P,
            F,
        },
    },
    inner_vars::AbstractVector,
) where {
    C <: PSY.Converter,
    IC <: PSY.InnerControl,
    DC <: PSY.DCSource,
    P <: PSY.FrequencyEstimator,
    F <: PSY.Filter,
}
    #Obtain external parameters
    V_ref = get_V_ref(dynamic_device)

    #Obtain regulated voltage (assumed to be terminal voltage)
    V_reg = sqrt(inner_vars[Vr_inv_var]^2 + inner_vars[Vi_inv_var]^2)
    I_R = inner_vars[Ir_inv_var]
    I_I = inner_vars[Ii_inv_var]

    # Get Reactive Controller parameters
    T_fltr = PSY.get_T_fltr(reactive_power_control)
    K_p = PSY.get_K_p(reactive_power_control)
    K_c = PSY.get_K_c(reactive_power_control)
    R_c = PSY.get_R_c(reactive_power_control)
    X_c = PSY.get_R_c(reactive_power_control)
    VC_Flag = PSY.get_VC_Flag(reactive_power_control)
    K_i = PSY.get_K_i(reactive_power_control)
    T_ft = PSY.get_T_ft(reactive_power_control)
    T_fv = PSY.get_T_fv(reactive_power_control)
    # V_frz not implemented yet
    # V_frz = PSY.get_V_frz(reactive_power_control)
    e_min, e_max = PSY.get_e_lim(reactive_power_control)
    dbd1, dbd2 = PSY.get_dbd_pnts(reactive_power_control)
    Q_min, Q_max = PSY.get_Q_lim(reactive_power_control)
    V_min, V_max = PSY.get_V_lim(reactive_power_control)

    #Define internal states for Reactive Control
    V_cflt = reactive_controller_states[1]
    ξq_oc = reactive_controller_states[2]
    q_LL = reactive_controller_states[3]

    #Compute input to the compensated voltage filter
    if VC_Flag == 0
        V_flt_input = V_reg + K_c * q_elec_out
    else
        # Calculate compensated voltage: | V_reg - (R_c + jX_c)(I_r + jI_i) |
        V_flt_input = sqrt(
            V_reg^2 +
            2 * V_reg * (I_I * X_c - I_R * R_c) +
            (I_I^2 + I_R^2) * (R_c^2 + X_c^2),
        )
    end
    #Q error - PI controller
    q_err = clamp(deadband_function(V_ref - V_cflt, dbd1, dbd2), e_min, e_max)

    #Compute block derivatives REPCA
    _, dVcflt_dt = low_pass(V_flt_input, V_cflt, 1.0, T_fltr)
    Q_pi_sat, dξqoc_dt = pi_block_nonwindup(q_err, ξq_oc, K_p, K_i, Q_min, Q_max)
    Q_ext, dqLL_dt = lead_lag(Q_pi_sat, q_LL, 1.0, T_ft, T_fv)

    #Skip PI voltage inner block
    V_pi_sat = clamp(Q_ext, V_min, V_max)

    #Update ODEs
    reactive_controller_ode[1] = dVcflt_dt
    reactive_controller_ode[2] = dξqoc_dt
    reactive_controller_ode[3] = dqLL_dt

    #Update Inner Vars
    inner_vars[V_oc_var] = V_pi_sat - Vt_filt
    inner_vars[Iq_oc_var] = Q_ext / max(Vt_filt, VOLTAGE_DIVISION_LOWER_BOUND)
end

############################################
### ODE calculations via device dispatch ###
############################################

function mdl_outer_ode!(
    device_states::AbstractArray{<:ACCEPTED_REAL_TYPES},
    output_ode::AbstractArray{<:ACCEPTED_REAL_TYPES},
    inner_vars::AbstractArray{<:ACCEPTED_REAL_TYPES},
    ω_sys::ACCEPTED_REAL_TYPES,
    dynamic_device::DynamicWrapper{
        PSY.DynamicInverter{
            C,
            PSY.OuterControl{PSY.VirtualInertia, PSY.ReactivePowerDroop},
            IC,
            DC,
            P,
            F,
        },
    },
) where {
    C <: PSY.Converter,
    IC <: PSY.InnerControl,
    DC <: PSY.DCSource,
    P <: PSY.FrequencyEstimator,
    F <: PSY.Filter,
}

    #Obtain external states inputs for component
    external_ix = get_input_port_ix(
        dynamic_device,
        PSY.OuterControl{PSY.VirtualInertia, PSY.ReactivePowerDroop},
    )
    Vr_filter = device_states[external_ix[1]]
    Vi_filter = device_states[external_ix[2]]
    Ir_filter = device_states[external_ix[3]]
    Ii_filter = device_states[external_ix[4]]

    #Obtain inner variables for component
    ω_pll = inner_vars[ω_freq_estimator_var]

    #Get Active Power Controller parameters
    outer_control = PSY.get_outer_control(dynamic_device)
    active_power_control = PSY.get_active_power(outer_control)
    Ta = PSY.get_Ta(active_power_control) #VSM Inertia constant
    kd = PSY.get_kd(active_power_control) #VSM damping constant
    kω = PSY.get_kω(active_power_control) #Frequency droop gain
    f0 = get_system_base_frequency(dynamic_device)
    ωb = 2 * pi * f0 #Rated angular frequency

    #Get Reactive Power Controller parameters
    reactive_power_control = PSY.get_reactive_power(outer_control)
    kq = PSY.get_kq(reactive_power_control) #Reactive power droop gain
    ωf = PSY.get_ωf(reactive_power_control) #Reactive power filter cutoff frequency

    #Obtain external parameters
    p_ref = get_P_ref(dynamic_device)
    ω_ref = get_ω_ref(dynamic_device)
    V_ref = get_V_ref(dynamic_device)
    q_ref = get_Q_ref(dynamic_device)

    #Obtain indices for component w/r to device
    local_ix = get_local_state_ix(
        dynamic_device,
        PSY.OuterControl{PSY.VirtualInertia, PSY.ReactivePowerDroop},
    )

    #Define internal states for Outer Control
    internal_states = @view device_states[local_ix]
    θ_oc = internal_states[1]
    ω_oc = internal_states[2]
    qm = internal_states[3]

    #Obtain additional expressions
    p_elec_out = Ir_filter * Vr_filter + Ii_filter * Vi_filter
    q_elec_out = -Ii_filter * Vr_filter + Ir_filter * Vi_filter

    #Compute block derivatives
    _, dqm_dt = low_pass(q_elec_out, qm, 1.0, 1.0 / ωf)

    #Compute 3 states ODEs
    output_ode[local_ix[1]] = ωb * (ω_oc - ω_sys)
    output_ode[local_ix[2]] =
        (p_ref / Ta - p_elec_out / Ta - kd * (ω_oc - ω_pll) / Ta - kω * (ω_oc - ω_ref) / Ta)
    output_ode[local_ix[3]] = dqm_dt

    #Update inner vars
    inner_vars[θ_oc_var] = θ_oc
    inner_vars[ω_oc_var] = ω_oc
    inner_vars[V_oc_var] = V_ref + kq * (q_ref - qm)
end

function mdl_outer_ode!(
    device_states::AbstractArray{<:ACCEPTED_REAL_TYPES},
    output_ode::AbstractArray{<:ACCEPTED_REAL_TYPES},
    inner_vars::AbstractArray{<:ACCEPTED_REAL_TYPES},
    ω_sys::ACCEPTED_REAL_TYPES,
    dynamic_device::DynamicWrapper{
        PSY.DynamicInverter{
            C,
            PSY.OuterControl{PSY.ActivePowerDroop, PSY.ReactivePowerDroop},
            IC,
            DC,
            P,
            F,
        },
    },
) where {
    C <: PSY.Converter,
    IC <: PSY.InnerControl,
    DC <: PSY.DCSource,
    P <: PSY.FrequencyEstimator,
    F <: PSY.Filter,
}

    #Obtain external states inputs for component
    external_ix = get_input_port_ix(
        dynamic_device,
        PSY.OuterControl{PSY.ActivePowerDroop, PSY.ReactivePowerDroop},
    )
    Vr_filter = device_states[external_ix[1]]
    Vi_filter = device_states[external_ix[2]]
    Ir_filter = device_states[external_ix[3]]
    Ii_filter = device_states[external_ix[4]]

    #Get Active Power Controller parameters
    outer_control = PSY.get_outer_control(dynamic_device)
    active_power_control = PSY.get_active_power(outer_control)
    Rp = PSY.get_Rp(active_power_control) #Droop Gain
    ωz = PSY.get_ωz(active_power_control) #Frequency cutoff frequency
    f0 = get_system_base_frequency(dynamic_device)
    ωb = 2 * pi * f0 #Rated angular frequency

    #Get Reactive Power Controller parameters
    reactive_power_control = PSY.get_reactive_power(outer_control)
    kq = PSY.get_kq(reactive_power_control) #Reactive power droop gain
    ωf = PSY.get_ωf(reactive_power_control) #Reactive power filter cutoff frequency

    #Obtain external parameters
    p_ref = get_P_ref(dynamic_device)
    ω_ref = get_ω_ref(dynamic_device)
    V_ref = get_V_ref(dynamic_device)
    q_ref = get_Q_ref(dynamic_device)

    #Obtain indices for component w/r to device
    local_ix = get_local_state_ix(
        dynamic_device,
        PSY.OuterControl{PSY.ActivePowerDroop, PSY.ReactivePowerDroop},
    )

    #Define internal states for frequency estimator
    internal_states = @view device_states[local_ix]
    θ_oc = internal_states[1]
    pm = internal_states[2]
    qm = internal_states[3]

    #Obtain additional expressions
    p_elec_out = Ir_filter * Vr_filter + Ii_filter * Vi_filter
    q_elec_out = -Ii_filter * Vr_filter + Ir_filter * Vi_filter

    #Compute Frequency from Droop
    ω_oc = ω_ref + Rp * (p_ref - pm)

    #Compute block derivatives
    _, dpm_dt = low_pass(p_elec_out, pm, 1.0, 1.0 / ωz)
    _, dqm_dt = low_pass(q_elec_out, qm, 1.0, 1.0 / ωf)

    #Compute 3 states ODEs
    output_ode[local_ix[1]] = ωb * (ω_oc - ω_sys)
    output_ode[local_ix[2]] = dpm_dt
    output_ode[local_ix[3]] = dqm_dt

    #Update inner vars
    inner_vars[θ_oc_var] = θ_oc
    inner_vars[ω_oc_var] = ω_oc
    inner_vars[V_oc_var] = V_ref + kq * (q_ref - qm)
end

function mdl_outer_ode!(
    device_states::AbstractArray{<:ACCEPTED_REAL_TYPES},
    output_ode::AbstractArray{<:ACCEPTED_REAL_TYPES},
    inner_vars::AbstractArray{<:ACCEPTED_REAL_TYPES},
    ::ACCEPTED_REAL_TYPES,
    dynamic_device::DynamicWrapper{
        PSY.DynamicInverter{
            C,
            PSY.OuterControl{PSY.ActivePowerPI, PSY.ReactivePowerPI},
            IC,
            DC,
            P,
            F,
        },
    },
) where {
    C <: PSY.Converter,
    IC <: PSY.InnerControl,
    DC <: PSY.DCSource,
    P <: PSY.FrequencyEstimator,
    F <: PSY.Filter,
}

    #Obtain external states inputs for component
    external_ix = get_input_port_ix(
        dynamic_device,
        PSY.OuterControl{PSY.ActivePowerPI, PSY.ReactivePowerPI},
    )
    Vr_filter = device_states[external_ix[1]]
    Vi_filter = device_states[external_ix[2]]
    Ir_filter = device_states[external_ix[3]]
    Ii_filter = device_states[external_ix[4]]

    #Obtain inner variables for component
    θ_pll = inner_vars[θ_freq_estimator_var]
    ω_pll = inner_vars[ω_freq_estimator_var]

    #Get Active Power Controller parameters
    outer_control = PSY.get_outer_control(dynamic_device)
    active_power_control = PSY.get_active_power(outer_control)
    Kp_p = PSY.get_Kp_p(active_power_control) #Proportional Gain
    Ki_p = PSY.get_Ki_p(active_power_control) #Integral Gain
    ωz = PSY.get_ωz(active_power_control) #Frequency cutoff frequency

    #Get Reactive Power Controller parameters
    reactive_power_control = PSY.get_reactive_power(outer_control)
    Kp_q = PSY.get_Kp_q(reactive_power_control) #Proportional Gain
    Ki_q = PSY.get_Ki_q(reactive_power_control) #Integral Gain
    ωf = PSY.get_ωf(reactive_power_control) #Reactive power filter cutoff frequency

    #Obtain external parameters
    p_ref = get_P_ref(dynamic_device)
    q_ref = get_Q_ref(dynamic_device)

    #Obtain indices for component w/r to device
    local_ix = get_local_state_ix(
        dynamic_device,
        PSY.OuterControl{PSY.ActivePowerPI, PSY.ReactivePowerPI},
    )

    #Define internal states for outer control
    internal_states = @view device_states[local_ix]
    σp_oc = internal_states[1]
    p_oc = internal_states[2]
    σq_oc = internal_states[3]
    q_oc = internal_states[4]

    #Obtain additional expressions
    p_elec_out = Ir_filter * Vr_filter + Ii_filter * Vi_filter
    q_elec_out = -Ii_filter * Vr_filter + Ir_filter * Vi_filter

    #Compute block derivatives
    Iq_pi, dσpoc_dt = pi_block(p_ref - p_oc, σp_oc, Kp_p, Ki_p)
    _, dpoc_dt = low_pass(p_elec_out, p_oc, 1.0, 1.0 / ωz)
    Id_pi, dσqoc_dt = pi_block(q_ref - q_oc, σq_oc, Kp_q, Ki_q)
    _, dqoc_dt = low_pass(q_elec_out, q_oc, 1.0, 1.0 / ωf)

    #Compute 4 states ODEs
    output_ode[local_ix[1]] = dσpoc_dt
    output_ode[local_ix[2]] = dpoc_dt
    output_ode[local_ix[3]] = dσqoc_dt
    output_ode[local_ix[4]] = dqoc_dt

    #Update inner vars
    inner_vars[θ_oc_var] = θ_pll
    inner_vars[ω_oc_var] = ω_pll
    inner_vars[Iq_oc_var] = Iq_pi
    inner_vars[Id_oc_var] = Id_pi
end

function mdl_outer_ode!(
    device_states::AbstractArray{<:ACCEPTED_REAL_TYPES},
    output_ode::AbstractArray{<:ACCEPTED_REAL_TYPES},
    inner_vars::AbstractArray{<:ACCEPTED_REAL_TYPES},
    ω_sys::ACCEPTED_REAL_TYPES,
    dynamic_device::DynamicWrapper{
        PSY.DynamicInverter{
            C,
            PSY.OuterControl{
                PSY.ActiveRenewableControllerAB,
                PSY.ReactiveRenewableControllerAB,
            },
            IC,
            DC,
            P,
            F,
        },
    },
) where {
    C <: PSY.Converter,
    IC <: PSY.InnerControl,
    DC <: PSY.DCSource,
    P <: PSY.FrequencyEstimator,
    F <: PSY.Filter,
}

    #Obtain external states inputs for component
    external_ix = get_input_port_ix(
        dynamic_device,
        PSY.OuterControl{
            PSY.ActiveRenewableControllerAB,
            PSY.ReactiveRenewableControllerAB,
        },
    )
    Vt_filt = device_states[external_ix[1]]

    #Monitoring power from other branch not supported.
    V_R = inner_vars[Vr_inv_var]
    V_I = inner_vars[Vi_inv_var]
    I_R = inner_vars[Ir_inv_var]
    I_I = inner_vars[Ii_inv_var]
    p_elec_out = I_R * V_R + I_I * V_I
    q_elec_out = -I_I * V_R + I_R * V_I

    #Get Active Power Controller parameters
    outer_control = PSY.get_outer_control(dynamic_device)
    active_power_control = PSY.get_active_power(outer_control)
    #Note: Monitoring power from other branch not supported.
    Freq_Flag = PSY.get_Freq_Flag(active_power_control) #Frequency Flag

    #Get Reactive Power Controller parameters
    reactive_power_control = PSY.get_reactive_power(outer_control)
    #Note: Monitoring power from other branch not supported.
    Ref_Flag = PSY.get_Ref_Flag(reactive_power_control)
    PF_Flag = PSY.get_PF_Flag(reactive_power_control)
    V_Flag = PSY.get_V_Flag(reactive_power_control)

    #Obtain indices for component w/r to device
    local_ix = get_local_state_ix(
        dynamic_device,
        PSY.OuterControl{
            PSY.ActiveRenewableControllerAB,
            PSY.ReactiveRenewableControllerAB,
        },
    )
    internal_states = @view device_states[local_ix]
    internal_ode = @view output_ode[local_ix]
    active_n_states = PSY.get_n_states(active_power_control)
    reactive_n_states = PSY.get_n_states(reactive_power_control)
    active_ix_range = 1:active_n_states
    reactive_ix_range = (active_n_states + 1):(active_n_states + reactive_n_states)
    active_states = @view internal_states[active_ix_range]
    reactive_states = @view internal_states[reactive_ix_range]
    active_ode = @view internal_ode[active_ix_range]
    reactive_ode = @view internal_ode[reactive_ix_range]

    #Dispatch active power controller
    _mdl_ode_RE_active_controller_AB!(
        active_ode,
        active_states,
        p_elec_out,
        ω_sys,
        Vt_filt,
        Base.RefValue{Freq_Flag},
        active_power_control,
        dynamic_device,
        inner_vars,
    )

    #Dispatch reactive power controller
    _mdl_ode_RE_reactive_controller_AB!(
        reactive_ode,
        reactive_states,
        q_elec_out,
        Vt_filt,
        Base.RefValue{Ref_Flag},
        Base.RefValue{PF_Flag},
        Base.RefValue{V_Flag},
        reactive_power_control,
        dynamic_device,
        inner_vars,
    )
end


text:
# Created at Instituto Tecnológico de Orizaba
# Carolina Ayerim Bolaños Ruiz
# Mauricio Rivadeneyra Hernández
# Kelvyn Baruc Sánchez Sánchez
# Eusebio Bolaños Reynoso
# Joaquín Pinto Espinoza

using Gtk.ShortNames, ControlSystems, Plots
using Mustache, DataFrames, DefaultApplication, Dates, Printf
import Latexify, SymPy
pyplot()

# CSS Provider
global style_file = joinpath(dirname(Base.source_path()), "style.css")

# Icons path
global ico1 = joinpath(dirname(Base.source_path()), "icons\\icon_new.ico")
global ico2 = joinpath(dirname(Base.source_path()), "icons\\icon_close.ico")
global ico3 = joinpath(dirname(Base.source_path()), "icons\\icon_pdf.ico")

# Images Path
global rootStep = "C:\\Windows\\Temp\\rootStep.png"
global rootRamp = "C:\\Windows\\Temp\\rootRamp.png"
global rootRL = "C:\\Windows\\Temp\\rootRL.png"

global lagStep = "C:\\Windows\\Temp\\lagStep.png"
global lagRamp = "C:\\Windows\\Temp\\lagRamp.png"
global lagRL = "C:\\Windows\\Temp\\lagRL.png"

global leadStep = "C:\\Windows\\Temp\\leadStep.png"
global leadRamp = "C:\\Windows\\Temp\\leadRamp.png"
global leadRL = "C:\\Windows\\Temp\\leadRL.png"

global leadlagStep = "C:\\Windows\\Temp\\leadlagStep.png"
global leadlagRamp = "C:\\Windows\\Temp\\leadlagRamp.png"
global leadlagRL = "C:\\Windows\\Temp\\leadlagRL.png"

# TF output .tex file
global lagTFopen = "C:\\Windows\\Temp\\lagTFopen.tex"
global lagTFcerr = "C:\\Windows\\Temp\\lagTFcerr.tex"
global lagTFcomp = "C:\\Windows\\Temp\\lagTFcomp.tex"
global lagTFcerrcomp = "C:\\Windows\\Temp\\lagTFcerrcomp.tex"

# Global status variables
global rootLocusStatus = 0
global lagStatusTF = 0

function LLAGUI()
    # Environmental variable to allow Windows decorations
    ENV["GTK_CSD"] = 0

    # Style for CSS
    global provider = CssProviderLeaf(filename = style_file)

    # Measurement of screen-size to allow compatibility to all screen devices
    global w, h = screen_size()

    # DataFrame for RL-Assistant results
    global rootLocusTable = DataFrame(Parameter = String[], Value = String[])

    # main Window
    mainWin = Window()
    set_gtk_property!(mainWin, :title, "LeadLagAssistant v0.1.0")
    set_gtk_property!(mainWin, :width_request, w*0.6)
    set_gtk_property!(mainWin, :height_request, h*0.75)
    set_gtk_property!(mainWin, :window_position, 3)
    set_gtk_property!(mainWin, :resizable, false)

    # Apply style to mainWin from CSS
    set_gtk_property!(mainWin, :name, "mainWin")

    # Grid to locate widgets
    mainGrid = Grid()

    ############################################################################
    # Toolbar
    ############################################################################
    newTB = ToolButton("gtk-new")
    imgnewTB = Image()
    set_gtk_property!(imgnewTB, :file, ico1)
    set_gtk_property!(newTB, :icon_widget, imgnewTB)
    set_gtk_property!(newTB, :label, "New")
    set_gtk_property!(newTB, :tooltip_markup, "New analysis")
    signal_connect(newTB, :clicked) do widget
        global rootLocusTable
        empty!(imgRoot)
        empty!(imgRamp)
        empty!(imgRL)

        empty!(gRootUpTFImg)
        empty!(gRootBTFImg)

        empty!(imgLagRoot)
        empty!(imgLagRamp)
        empty!(imgLagRL)

        empty!(lagTFCompCerrImg)
        empty!(lagTFCompOpenImg)
        empty!(lagTFOpenImg)
        empty!(lagTFCerrImg)
        empty!(lagTFCompImg)

        listRoot[1,2] = "unsolved"
        listRoot[2,2] = "unsolved"
        listRoot[3,2] = "unsolved"
        listRoot[4,2] = "unsolved"
        listRoot[5,2] = "unsolved"
        listRoot[6,2] = "unsolved"
        listRoot[7,2] = "unsolved"
        listRoot[8,2] = "unsolved"

        set_gtk_property!(rootNumTf, :text, "")
        set_gtk_property!(rootDenTf, :text, "")
        set_gtk_property!(lagNumTf, :text, "")
        set_gtk_property!(lagDenTf, :text, "")
        set_gtk_property!(lagKv, :text, "")
        set_gtk_property!(lagT, :text, "")

        set_gtk_property!(exportTB, :sensitive, false)
        set_gtk_property!(suggesLabelRoot, :label, "")
        empty!(rootLocusTable)

        @sigatom set_gtk_property!(lagCheck, :active, false)
        global rootLocusStatus = 0
        global lagStatusTF = 0
    end

    closeTB = ToolButton("gtk-close")
    imgcloseTB = Image()
    set_gtk_property!(imgcloseTB, :file, ico2)
    set_gtk_property!(closeTB, :icon_widget, imgcloseTB)
    set_gtk_property!(closeTB, :label, "Close")
    set_gtk_property!(closeTB, :tooltip_markup, "Close program")
    signal_connect(closeTB, :clicked) do widget
        destroy(mainWin)
    end

    runTB = ToolButton("gtk-media-play")
    set_gtk_property!(runTB, :label, "Solve")
    signal_connect(runTB, :clicked) do widget
        if get_gtk_property(nb, :page, Int) == 0

            global rootNumTfData = get_gtk_property(rootNumTf, :text, String)
            global rootDenTfData = get_gtk_property(rootDenTf, :text, String)

            global rootNumTfClean = split(rootNumTfData,",")
            global rootDenTfClean = split(rootDenTfData,",")

            try
                # Check t0 only numbers
                for i=1:length(rootNumTfClean)
                    parse(Float64, rootNumTfClean[i])
                end

                for i=1:length(rootDenTfClean)
                    parse(Float64, rootDenTfClean[i])
                end

                # Convert to numeric values from string
                global rootArrayNum = Array{Float64}(undef, length(rootNumTfClean))
                for i=1:length(rootNumTfClean)
                    a = parse(Float64, rootNumTfClean[i])
                    rootArrayNum[i] =  a
                end

                global rootArrayDen = Array{Float64}(undef, length(rootDenTfClean))
                for i=1:length(rootDenTfClean)
                    a = parse(Float64, rootDenTfClean[i])
                    rootArrayDen[i] =  a
                end

                if length(rootArrayNum) < length(rootArrayDen)
                    global Gopen = tf(rootArrayNum,rootArrayDen)
                    global Gcerr = feedback(Gopen)

                    # Step plot
                    yRootStep, tRootStep, xRootStep = step(Gcerr)

                    # Step ramp
                    global Gramp = tf([1],[1,0])
                    yRootRamp, tRootRamp, xRootRamp = step(Gcerr*Gramp)

                    plotRootStep = plot(tRootStep, yRootStep,
                    xlabel = "Time (sec)",
                    ylabel = "Amplitude",
                    framestyle = :box)

                    plotRootRamp = plot(tRootRamp,yRootRamp,
                    xlabel = "Time (sec)",
                    ylabel = "Amplitude",
                    framestyle = :box)

                    plotRootRL =  rlocusplot(Gopen, framestyle=:box, title = "", lw=1, lc = :blue)

                    savefig(plotRootStep, rootStep)
                    savefig(plotRootRamp, rootRamp)
                    savefig(plotRootRL, rootRL)

                    set_gtk_property!(imgRoot, :file, rootStep)
                    set_gtk_property!(imgRamp, :file, rootRamp)
                    set_gtk_property!(imgRL, :file, rootRL)

                    # Steady state analysis
                    ωn, ζ, ps = damp(Gcerr)

                    # Kv
                    s = SymPy.symbols("s", real=true)

                    global GrealNum = 0
                    global GrealDen = 0

                    for i=1:length(rootArrayNum)
                        global GrealNum = GrealNum + rootArrayNum[i]*s^(length(rootArrayNum)-i)
                    end

                    for i=1:length(rootArrayDen)
                        global GrealDen = GrealDen + rootArrayDen[i]*s^(length(rootArrayDen)-i)
                    end

                    Greal = GrealNum/GrealDen

                    Kv = SymPy.limit(Greal*s, s, 0)

                    # TFopen image
                    msgtex = Latexify.latexify(string("G(s)=", SymPy.simplify(Greal)))
                    L =
                    """\\documentclass[border=2pt]{standalone}
                    \\usepackage{mathtools}
                    \\begin{document}
                    {{:msg}}
                    \\end{document}
                    """

                    out = render(L, msg = msgtex)
                    filename = "C:\\Windows\\Temp\\TFopen.tex"

                    Base.open(filename, "w") do file
                        write(file, out)
                    end

                    run(`pdflatex -output-directory="C:\\Windows\\Temp\\" "TFopen.tex"`)
                    run(`pdftocairo -png -r 300 "C:\\Windows\\Temp\\TFopen.pdf" "C:\\Windows\\Temp\\TFopen"`)

                    set_gtk_property!(gRootUpTFImg, :file, "C:\\Windows\\Temp\\TFopen-1.png")

                    # TFcerr image
                    GcerrTex = SymPy.simplify(Greal/(Greal+1))
                    msgtexcerr = Latexify.latexify(string("G(s)=", GcerrTex))
                    L =
                    """\\documentclass[border=2pt]{standalone}
                    \\usepackage{mathtools}
                    \\begin{document}
                    {{:msg}}
                    \\end{document}
                    """

                    out = render(L, msg = msgtexcerr)
                    filename = "C:\\Windows\\Temp\\TFcerr.tex"

                    Base.open(filename, "w") do file
                        write(file, out)
                    end

                    run(`pdflatex -output-directory="C:\\Windows\\Temp\\" "TFcerr.tex"`)
                    run(`pdftocairo -png -r 300 "C:\\Windows\\Temp\\TFcerr.pdf" "C:\\Windows\\Temp\\TFcerr"`)

                    set_gtk_property!(gRootBTFImg, :file, "C:\\Windows\\Temp\\TFcerr-1.png")

                    # Overshoot
                    PO=100*exp((-ζ[1]*pi)/(sqrt(1-ζ[1]^2)))

                    # Settling time
                    Ts = -log(0.05)/(ζ[1]*ωn[1])

                    # Peak Time Response
                    Tp = π/(ωn[1]*sqrt(1 - ζ[1]^2))

                    # #Rise time
                    beta = atan(ωn[1]/(ωn[1]*ζ[1]))
                    tR = (π-beta)/ωn[1]

                    listRoot[1,2] = ωn[1]
                    listRoot[2,2] = ζ[1]
                    listRoot[3,2] = string(ps)
                    listRoot[4,2] = SymPy.N(Kv)
                    listRoot[5,2] = tR
                    listRoot[6,2] = Tp
                    listRoot[7,2] = PO
                    listRoot[8,2] = Ts

                    push!(rootLocusTable,("Wn",listRoot[1,2]))
                    push!(rootLocusTable,("L",listRoot[2,2]))
                    push!(rootLocusTable,("Closed-loop Poles", listRoot[3,2]))
                    push!(rootLocusTable,("Kv", listRoot[4,2]))
                    push!(rootLocusTable,("Rise Time", listRoot[5,2]))
                    push!(rootLocusTable,("Peak Time", listRoot[6,2]))
                    push!(rootLocusTable,("Overshoot", listRoot[7,2]))
                    push!(rootLocusTable,("Settling Time", listRoot[8,2]))

                    set_gtk_property!(exportTB, :sensitive, true)

                    if PO > 20
                        msg1 = @sprintf("Based on the overshoot: %2.4f you should use a Lead Network", PO)
                        set_gtk_property!(suggesLabelRoot, :label, msg1)
                    end

                    if N(Kv) < 5
                        msg1 = @sprintf("Based on Kv: %2.4f you should use a Lag Network", N(Kv))
                        set_gtk_property!(suggesLabelRoot, :label, msg1)
                    end

                    if (PO > 20) & (N(Kv) < 5)
                        msg1 = @sprintf("You should use a Lead-Lag Network")
                        set_gtk_property!(suggesLabelRoot, :label, msg1)
                    end

                    global rootLocusStatus = 1
                else
                    warn_dialog("Numerator´s order must be lower than denominator", mainWin)
                    set_gtk_property!(rootNumTf, :text, "")
                    set_gtk_property!(rootDenTf, :text, "")
                end
                catch
                    warn_dialog("Enter only numbers!", mainWin)
                    set_gtk_property!(rootNumTf, :text, "")
                    set_gtk_property!(rootDenTf, :text, "")
                end
        end
        # Execute lag compensator
        if get_gtk_property(nb, :page, Int) == 1
            global lagNumTfData = get_gtk_property(lagNumTf, :text, String)
            global lagDenTfData = get_gtk_property(lagDenTf, :text, String)
            global lagKvData = get_gtk_property(lagKv, :text, String)
            global lagTData = get_gtk_property(lagT, :text, String)

            global lagNumTfClean = split(lagNumTfData,",")
            global lagDenTfClean = split(lagDenTfData,",")
            global lagKvClean = split(lagKvData,",")
            global lagTClean = split(lagTData,",")

            try
                # Check t0 only numbers
                for i=1:length(lagNumTfClean)
                    parse(Float64, lagNumTfClean[i])
                end

                for i=1:length(lagDenTfClean)
                    parse(Float64, lagDenTfClean[i])
                end

                # Convert to numeric values from string
                global lagArrayNum = Array{Float64}(undef, length(lagNumTfClean))
                for i=1:length(lagNumTfClean)
                    a = parse(Float64, lagNumTfClean[i])
                    lagArrayNum[i] =  a
                end

                global lagArrayDen = Array{Float64}(undef, length(lagDenTfClean))
                for i=1:length(lagDenTfClean)
                    a = parse(Float64, lagDenTfClean[i])
                    lagArrayDen[i] =  a
                end

                global lagStatusTF = 1
            catch
                warn_dialog("Enter only numbers!", mainWin)
                set_gtk_property!(lagNumTf, :text, "")
                set_gtk_property!(lagDenTf, :text, "")
            end

            if lagStatusTF == 1
                if length(lagKvClean) > 1
                    warn_dialog("Enter only 1 value for Kv", mainWin)
                    set_gtk_property!(lagKv, :text, "")
                else
                    try
                        parse(Float64, lagKvClean[1])

                        global lagKvNum = parse(Float64, lagKvClean[1])
                    catch
                        warn_dialog("Enter only numbers!", mainWin)
                        set_gtk_property!(lagKv, :text, "")
                    end
                end

                if length(lagTClean) > 1
                    warn_dialog("Enter only 1 value for T", mainWin)
                    set_gtk_property!(lagT, :text, "")
                else
                    try
                        parse(Float64, lagTClean[1])

                        global lagTNum = parse(Float64, lagTClean[1])
                    catch
                        warn_dialog("Enter only numbers!", mainWin)
                        set_gtk_property!(lagT, :text, "")
                    end
                end

                try
                    if length(lagArrayNum) < length(lagArrayDen)
                        global Gopen = tf(lagArrayNum,lagArrayDen)
                        global Gcerr = feedback(Gopen)

                        # Steady state analysis
                        ωn1, ζ1, ps1 = damp(Gcerr)

                        # Kv
                        s = SymPy.symbols("s", real=true)

                        global GrealNum = 0
                        global GrealDen = 0

                        for i=1:length(lagArrayNum)
                            global GrealNum = GrealNum + lagArrayNum[i]*s^(length(lagArrayNum)-i)
                        end

                        for i=1:length(lagArrayDen)
                            global GrealDen = GrealDen + lagArrayDen[i]*s^(length(lagArrayDen)-i)
                        end

                        Greal1 = GrealNum/GrealDen

                        Kv1 = SymPy.limit(Greal1*s, s, 0)

                        # TFopen image
                        msgtex = Latexify.latexify(string("G(s)=", SymPy.simplify(Greal1)))
                        L =
                        """\\documentclass[border=2pt]{standalone}
                        \\usepackage{mathtools}
                        \\begin{document}
                        {{:msg}}
                        \\end{document}
                        """

                        out = render(L, msg = msgtex)
                        filename = "C:\\Windows\\Temp\\lagTFopen.tex"

                        Base.open(filename, "w") do file
                            write(file, out)
                        end

                        run(`pdflatex -output-directory="C:\\Windows\\Temp\\" "lagTFopen.tex"`)
                        run(`pdftocairo -png -r 300 "C:\\Windows\\Temp\\TFopen.pdf" "C:\\Windows\\Temp\\lagTFopen"`)

                        set_gtk_property!(lagTFOpenImg, :file, "C:\\Windows\\Temp\\lagTFopen-1.png")

                        # TFcerr image
                        GcerrTex1 = SymPy.simplify(Greal1/(Greal1+1))
                        msgtexcerr = Latexify.latexify(string("G(s)=", GcerrTex1))
                        L =
                        """\\documentclass[border=2pt]{standalone}
                        \\usepackage{mathtools}
                        \\begin{document}
                        {{:msg}}
                        \\end{document}
                        """

                        out = render(L, msg = msgtexcerr)
                        filename = "C:\\Windows\\Temp\\lagTFcerr.tex"

                        Base.open(filename, "w") do file
                            write(file, out)
                        end

                        run(`pdflatex -output-directory="C:\\Windows\\Temp\\" "lagTFcerr.tex"`)
                        run(`pdftocairo -png -r 300 "C:\\Windows\\Temp\\TFcerr.pdf" "C:\\Windows\\Temp\\lagTFcerr"`)

                        set_gtk_property!(lagTFCerrImg, :file, "C:\\Windows\\Temp\\lagTFcerr-1.png")

                        # uncompensated
                        # Overshoot
                        PO1 = 100*exp((-ζ1[1]*pi)/(sqrt(1-ζ1[1]^2)))

                        # Settling time
                        Ts1 = -log(0.05)/(ζ1[1]*ωn1[1])

                        # Peak Time Response
                        Tp1 = π/(ωn1[1]*sqrt(1 - ζ1[1]^2))

                        # #Rise time
                        beta1 = atan(ωn1[1]/(ωn1[1]*ζ1[1]))
                        tR1 = (π-beta1)/ωn1[1]

                        # β
                        β = lagKvNum / SymPy.N(Kv1)

                        # Zero
                        global Zero = -1 / lagTNum
                        global Pole = -1 / (β*lagTNum)

                        # TF compensator

                        Gc1 = tf([1, - Zero],[1, - Pole])

                        msgtexcerr = Latexify.latexify(string("G(s)=Kc*",(1*s-Zero)/(1*s-Pole)))
                        L =
                        """\\documentclass[border=2pt]{standalone}
                        \\usepackage{mathtools}
                        \\begin{document}
                        {{:msg}}
                        \\end{document}
                        """

                        out = render(L, msg = msgtexcerr)
                        filename = "C:\\Windows\\Temp\\lagGc.tex"

                        Base.open(filename, "w") do file
                            write(file, out)
                        end

                        run(`pdflatex -output-directory="C:\\Windows\\Temp\\" "lagGc.tex"`)
                        run(`pdftocairo -png -r 300 "C:\\Windows\\Temp\\lagGc.pdf" "C:\\Windows\\Temp\\lagGc"`)

                        set_gtk_property!(lagTFCompImg, :file, "C:\\Windows\\Temp\\lagGc-1.png")

                        GcCerr1 = feedback(Gc1*Gopen)
                        ωn2, ζ2, ps2 = damp(GcCerr1)

                        # Compensated
                        # Overshoot
                        PO2 = 100*exp((-ζ2[2]*pi)/(sqrt(1-ζ2[2]^2)))

                        # Settling time
                        Ts2 = -log(0.05)/(ζ2[2]*ωn2[2])

                        # Peak Time Response
                        Tp2 = π/(ωn2[2]*sqrt(1 - ζ2[2]^2))

                        # #Rise time
                        beta2 = atan(ωn2[2]/(ωn2[2]*ζ2[2]))
                        tR2 = (π-beta2)/ωn2[2]

                        Greal2 = subs(Greal1, s, ps2[2])
                        Greal2 = SymPy.simplify(Greal2)
                        ϕ = atand(imag(SymPy.N(Greal2)) / real(SymPy.N(Greal2)))

                        Kc = 1 / sqrt((imag(Greal2)^2) + (real(Greal2)^2))

                        # List of values
                        listLag[1,2] = ωn1[1]
                        listLag[1,3] = ωn2[2]

                        listLag[2,2] = ζ1[1]
                        listLag[2,3] = ζ2[2]

                        listLag[3,2] = string(ps1)
                        listLag[3,3] = string(ps2)

                        listLag[4,2] = SymPy.N(Kv1)
                        listLag[4,3] = lagKvNum

                        listLag[5,2] = tR1
                        listLag[5,3] = tR2

                        listLag[6,2] = Tp1
                        listLag[6,3] = Tp2

                        listLag[7,2] = PO1
                        listLag[7,3] = PO2

                        listLag[8,2] = Ts1
                        listLag[8,3] = Ts2

                        listLag[9,3] = ϕ

                        listLag[10,3] = Pole
                        listLag[11,3] = Zero
                        listLag[12,3] = β

                        listLag[13,3] = Kc

                        # Step plot
                        yLagStep, tLagStep, xLagStep = step(Gcerr)

                        GCcerr = feedback(Kc*Gc1*Gopen)
                        yLagStep2, tLagStep2, xLagStep2 = step(GCcerr)

                        # Step ramp
                        global Gramp = tf([1],[1,0])
                        yLagRamp, tLagRamp, xLagRamp = step(Gcerr*Gramp)
                        yLagRamp2, tLagRamp2, xLagRamp2 = step(GCcerr*Gramp)

                        plotLagStep = plot(tLagStep, yLagStep,
                        xlabel = "Time (sec)",
                        ylabel = "Amplitude",
                        framestyle = :box,
                        label = "Uncompensated")
                        plot!(tLagStep2, yLagStep2, label="Uncompensated")

                        plotLagRamp = plot(tLagRamp,yLagRamp,
                        xlabel = "Time (sec)",
                        ylabel = "Amplitude",
                        framestyle = :box,
                        label = "Uncompensated")
                        plot!(tLagRamp2,yLagRamp2, label = "Compensated")

                        plotLagRL =  rlocusplot(Kc*Gc1*Gopen, framestyle=:box, title = "", lw=1, lc = :blue)

                        savefig(plotLagStep, lagStep)
                        savefig(plotLagRamp, lagRamp)
                        savefig(plotLagRL, lagRL)

                        set_gtk_property!(imgLagRoot, :file, lagStep)
                        set_gtk_property!(imgLagRamp, :file, lagRamp)
                        set_gtk_property!(imgLagRL, :file, lagRL)

                        # TFCopen image
                        TFCopen = Kc*Greal1*((1*s-Zero)/(1*s-Pole))
                        msgtex = Latexify.latexify(string("Gc(s)*G(s)=", SymPy.simplify(TFCopen)))
                        L =
                        """\\documentclass[border=2pt]{standalone}
                        \\usepackage{mathtools}
                        \\begin{document}
                        {{:msg}}
                        \\end{document}
                        """

                        out = render(L, msg = msgtex)
                        filename = "C:\\Windows\\Temp\\lagTFCopen.tex"

                        Base.open(filename, "w") do file
                            write(file, out)
                        end

                        run(`pdflatex -output-directory="C:\\Windows\\Temp\\" "lagTFCopen.tex"`)
                        run(`pdftocairo -png -r 300 "C:\\Windows\\Temp\\lagTFCopen.pdf" "C:\\Windows\\Temp\\lagTFCopen"`)

                        set_gtk_property!(lagTFCompOpenImg, :file, "C:\\Windows\\Temp\\lagTFCopen-1.png")

                        # TFCopen image
                        TFCopen = Kc*Greal1*((1*s-Zero)/(1*s-Pole))
                        TFCcerr = TFCopen/(1 + TFCopen)
                        msgtex = Latexify.latexify(string("C(s)/R(s)=", SymPy.simplify(TFCcerr)))
                        L =
                        """\\documentclass[border=2pt]{standalone}
                        \\usepackage{mathtools}
                        \\begin{document}
                        {{:msg}}
                        \\end{document}
                        """

                        out = render(L, msg = msgtex)
                        filename = "C:\\Windows\\Temp\\lagTFCcerr.tex"

                        Base.open(filename, "w") do file
                            write(file, out)
                        end

                        run(`pdflatex -output-directory="C:\\Windows\\Temp\\" "lagTFCcerr.tex"`)
                        run(`pdftocairo -png -r 300 "C:\\Windows\\Temp\\lagTFCcerr.pdf" "C:\\Windows\\Temp\\lagTFCcerr"`)

                        set_gtk_property!(lagTFCompCerrImg, :file, "C:\\Windows\\Temp\\lagTFCcerr-1.png")
                    #     push!(rootLocusTable,("Wn",listRoot[1,2]))
                    #     push!(rootLocusTable,("L",listRoot[2,2]))
                    #     push!(rootLocusTable,("Closed-loop Poles", listRoot[3,2]))
                    #     push!(rootLocusTable,("Kv", listRoot[4,2]))
                    #     push!(rootLocusTable,("Rise Time", listRoot[5,2]))
                    #     push!(rootLocusTable,("Peak Time", listRoot[6,2]))
                    #     push!(rootLocusTable,("Overshoot", listRoot[7,2]))
                    #     push!(rootLocusTable,("Settling Time", listRoot[8,2]))
                    #
                    #     set_gtk_property!(exportTB, :sensitive, true)
                    else
                        warn_dialog("Numerator´s order must be lower than denominator", mainWin)
                        set_gtk_property!(lagNumTf, :text, "")
                        set_gtk_property!(lagDenTf, :text, "")
                    end
                catch
                    println("Error en lag")
                end

            end
        end

        # Execute lag compensator
        if get_gtk_property(nb, :page, Int) == 2

        end

        # Execute lag compensator
        if get_gtk_property(nb, :page, Int) == 3

        end

    end

    exportTB = ToolButton("gtk-close")
    imgexportTB = Image()
    set_gtk_property!(imgexportTB, :file, ico3)
    set_gtk_property!(exportTB, :icon_widget, imgexportTB)
    set_gtk_property!(exportTB, :label, "Export")
    set_gtk_property!(exportTB, :tooltip_markup, "Export to .pdf file")
    set_gtk_property!(exportTB, :sensitive, false)
    signal_connect(exportTB, :clicked) do widget
        global pathfile = save_dialog_native("Save as...", Null(), ("*.pdf",))
        global rootLocusTable

        if ~isempty(pathfile)
            # Time for report
            timenow = Dates.now()
            timenow1 = Dates.format(timenow, "dd u yyyy HH:MM:SS")

            if Sys.iswindows()
                # Headers for dataframes
                fmtH1 = string("|",repeat("c|", size(rootLocusTable,2)))
                headerH1 = join(string.(names(rootLocusTable)), " & ")
                rowH1 = join(["{{:$x}}" for x in map(string, names(rootLocusTable))], " & ")

                LSNS = """
                \\documentclass{article}
                \\usepackage{graphicx}
                \\graphicspath{ {C:/Windows/Temp/} }
                \\usepackage[letterpaper, portrait, margin=1in]{geometry}
                \\begin{document}
                \\begin{center}
                \\Huge{\\textbf{LeadLagAssistant v0.1.0}}\\\\
                \\vspace{2mm}
                \\large{\\textbf{Root-locus Assistant Report}}\\break
                \\normalsize{{:time}}\n
                \\vspace{5mm}
                \\rule{15cm}{0.05cm}\n\n\n
                \\vspace{2mm}
                \\includegraphics[width=9cm, height=8cm]{rootStep}\n
                \\normalsize{Figure 1. Step response}\n
                \\vspace{2mm}
                \\includegraphics[width=9cm, height=8cm]{rootRamp}\n
                \\normalsize{Figure 2. Ramp response}\n
                \\vspace{3mm}\n
                \\rule{15cm}{0.05cm}\n
                \\pagebreak

                \\includegraphics[width=9cm, height=8cm]{rootRL}\n
                \\normalsize{Figure 3. Root-locus}\n
                \\vspace{2mm}

                \\rule{15cm}{0.05cm}\n\n\n
                \\vspace{2mm}
                \\normalsize{Table 1. Parameters}\n
                \\vspace{2mm}
                \\begin{tabular}{$fmtH1}
                \\hline
                $headerH1\\\\
                \\hline
                {{#:FGH1}} $rowH1\\cr
                {{/:FGH1}}
                \\hline\n
                \\end{tabular}

                \\vspace{5mm}\n
                \\end{center}
                \\end{document}
                """

                rendered = render(LSNS, time = timenow1, FGH1 = rootLocusTable)

                fileNameBase = string(basename(pathfile), ".tex")
                fileName = string("C:\\Windows\\Temp\\", fileNameBase)
                Base.open(fileName, "w") do file
                    write(file, rendered)
                end
                run(`pdflatex -output-directory="C:\\Windows\\Temp\\" $(fileNameBase)`)

                pdfName = string(pathfile, ".pdf")
                fileNameBase = string(basename(pathfile), ".pdf")
                fileName = string("C:\\Windows\\Temp\\", fileNameBase)
                cp(fileName, string(pathfile, ".pdf"); force=true)
                DefaultApplication.open(pdfName)
            end

            if Sys.islinux()
                warn_dialog("Export as .pdf is not currently implemented on Linux Operating System", mainWin)
            end
        end
    end

    mainToolbar = Toolbar()
    set_gtk_property!(mainToolbar, :height_request, (h * 0.75) * 0.09)
    set_gtk_property!(mainToolbar, :toolbar_style, 2)
    push!(mainToolbar, newTB)
    push!(mainToolbar, exportTB)
    push!(mainToolbar, runTB)
    push!(mainToolbar, closeTB)

    ############################################################################
    # main Notebook
    ############################################################################
    global nb = Notebook()
    set_gtk_property!(nb, :tab_pos, 3)
    set_gtk_property!(nb, :name, "nb")
    screen = Gtk.GAccessor.style_context(nb)
    push!(screen, StyleProvider(provider), 600)

    # Root-locus assistant #####################################################
    rootlocusFrame = Frame()

    mainGridRoot = Grid()
    set_gtk_property!(mainGridRoot, :column_homogeneous, false)
    set_gtk_property!(mainGridRoot, :row_homogeneous, false)
    set_gtk_property!(mainGridRoot, :margin_top, 10)
    set_gtk_property!(mainGridRoot, :margin_bottom, 10)
    set_gtk_property!(mainGridRoot, :margin_left, 10)
    set_gtk_property!(mainGridRoot, :margin_right, 10)
    set_gtk_property!(mainGridRoot, :column_spacing, 10)
    set_gtk_property!(mainGridRoot, :row_spacing, 10)

    gridRootLeft = Grid()
    set_gtk_property!(gridRootLeft, :valign, 3)
    set_gtk_property!(gridRootLeft, :halign, 3)
    set_gtk_property!(gridRootLeft, :column_spacing, 10)
    set_gtk_property!(gridRootLeft, :row_spacing, 10)
    set_gtk_property!(gridRootLeft, :column_homogeneous, true)

    gridRootRight = Grid()
    set_gtk_property!(gridRootRight, :valign, 3)
    set_gtk_property!(gridRootRight, :halign, 3)
    set_gtk_property!(gridRootRight, :column_spacing, 10)
    set_gtk_property!(gridRootRight, :row_spacing, 10)
    set_gtk_property!(gridRootRight, :column_homogeneous, true)

    gridRootLFrameUp = Frame("Input Data")
    set_gtk_property!(gridRootLFrameUp, :width_request, (w*0.6)*0.4)
    set_gtk_property!(gridRootLFrameUp, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.35)
    set_gtk_property!(gridRootLFrameUp, :label_xalign, 0.50)
    set_gtk_property!(gridRootLFrameUp, :label_yalign, 0.00)

    # TF, List and table for input data
    gridRootLFUp = Grid()
    set_gtk_property!(gridRootLFUp, :column_homogeneous, false)
    set_gtk_property!(gridRootLFUp, :row_homogeneous, false)
    set_gtk_property!(gridRootLFUp, :column_spacing, 10)
    set_gtk_property!(gridRootLFUp, :row_spacing, 10)
    set_gtk_property!(gridRootLFUp, :margin_top, 10)
    set_gtk_property!(gridRootLFUp, :margin_bottom, 10)
    set_gtk_property!(gridRootLFUp, :margin_left, 10)
    set_gtk_property!(gridRootLFUp, :margin_right, 10)

    # entry for TF

    rootNumTf = Entry()
    rootDenTf = Entry()

    labelGs = Label("G(s) = ")
    labelDen = Label("[d1,d2... dn]")
    labelNum = Label("[n1,n2... nm]")

    gRootLFUpTF = Frame()
    set_gtk_property!(gRootLFUpTF, :label_xalign, 0.50)
    set_gtk_property!(gRootLFUpTF, :label_yalign, 0.00)
    set_gtk_property!(gRootLFUpTF, :width_request, (w*0.6)*0.385)
    set_gtk_property!(gRootLFUpTF, :height_request, 0.35*((h*0.75)-((h * 0.75) * 0.09))*0.50)

    gRootUpTFImg = Image()
    gRootUpTFImgScroll = ScrolledWindow()
    push!(gRootUpTFImgScroll,gRootUpTFImg)
    push!(gRootLFUpTF, gRootUpTFImgScroll)

    gridRootLFUp[1,1:2] = labelGs
    gridRootLFUp[2,1] = labelNum
    gridRootLFUp[2,2] = labelDen
    gridRootLFUp[3,1] = rootNumTf
    gridRootLFUp[3,2] = rootDenTf
    gridRootLFUp[1:3,3] = gRootLFUpTF

    push!(gridRootLFrameUp, gridRootLFUp)

    gridRootLFrameB = Frame("Output Data")
    set_gtk_property!(gridRootLFrameB, :width_request, (w*0.6)*0.4)
    set_gtk_property!(gridRootLFrameB, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.60)
    set_gtk_property!(gridRootLFrameB, :label_xalign, 0.50)
    set_gtk_property!(gridRootLFrameB, :label_yalign, 0.00)

    gridRootRFrameUp = Frame()
    set_gtk_property!(gridRootRFrameUp, :width_request, (w*0.6)*0.57)
    set_gtk_property!(gridRootRFrameUp, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.70)

    imgRoot = Image()
    imgRamp = Image()
    imgRL = Image()

    gridRootRFrameB = Frame("Suggestions")
    set_gtk_property!(gridRootRFrameB, :width_request, (w*0.6)*0.57)
    set_gtk_property!(gridRootRFrameB, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.25)
    set_gtk_property!(gridRootRFrameB, :label_xalign, 0.50)
    set_gtk_property!(gridRootRFrameB, :label_yalign, 0.00)

    suggesLabelRoot = Label("")
    push!(gridRootRFrameB, suggesLabelRoot)

    gridRootLeft[1,1] = gridRootLFrameUp
    gridRootLeft[1,2] = gridRootLFrameB

    gridRootRight[1,1] = gridRootRFrameUp
    gridRootRight[1,2] = gridRootRFrameB

    mainGridRoot[1,1] = gridRootLeft
    mainGridRoot[2,1] = gridRootRight

    # TF, List and table for input data
    gridRootLFB = Grid()
    set_gtk_property!(gridRootLFB, :column_homogeneous, false)
    set_gtk_property!(gridRootLFB, :row_homogeneous, false)
    set_gtk_property!(gridRootLFB, :column_spacing, 10)
    set_gtk_property!(gridRootLFB, :row_spacing, 10)
    set_gtk_property!(gridRootLFB, :margin_top, 10)
    set_gtk_property!(gridRootLFB, :margin_bottom, 10)
    set_gtk_property!(gridRootLFB, :margin_left, 10)
    set_gtk_property!(gridRootLFB, :margin_right, 10)

    gRootLFBTF = Frame()
    set_gtk_property!(gRootLFBTF, :label_xalign, 0.50)
    set_gtk_property!(gRootLFBTF, :label_yalign, 0.00)
    set_gtk_property!(gRootLFBTF, :width_request, (w*0.6)*0.385)
    set_gtk_property!(gRootLFBTF, :height_request, 0.35*((h*0.75)-((h * 0.75) * 0.09))*0.50)

    gRootBTFImg = Image()
    gRootBTFImgScroll = ScrolledWindow()
    push!(gRootBTFImgScroll,gRootBTFImg)
    push!(gRootLFBTF, gRootBTFImgScroll)

    global listRoot = ListStore(String, String)

    push!(listRoot,("ωn","unsolved"))
    push!(listRoot,("ζ","unsolved"))
    push!(listRoot,("Closed-loop Poles", "unsolved"))
    push!(listRoot,("Kv", "unsolved"))
    push!(listRoot,("Rise Time (sec)", "unsolved"))
    push!(listRoot,("Peak Time (sec)", "unsolved"))
    push!(listRoot,("Overshoot (%)", "unsolved"))
    push!(listRoot,("Settling Time (sec)", "unsolved"))

    treeRoot = TreeView(TreeModel(listRoot))
    rowTxt = CellRendererText()

    c1Root = TreeViewColumn("Parameter", rowTxt, Dict([("text",0)]))
    c2Root = TreeViewColumn("Value", rowTxt, Dict([("text",1)]))

    Gtk.GAccessor.resizable(c1Root, true)
    Gtk.GAccessor.resizable(c2Root, true)

    push!(treeRoot, c1Root, c2Root)

    rootODScrollWin = ScrolledWindow()
    set_gtk_property!(rootODScrollWin, :name, "rootODScrollWin")
    set_gtk_property!(rootODScrollWin, :height_request, 0.70*((h*0.75)-((h * 0.75) * 0.09))*0.50)

    rootODScrollWinF = Frame()
    push!(rootODScrollWinF,rootODScrollWin)
    push!(rootODScrollWin,treeRoot)

    gridRootLFB[1,1] = gRootLFBTF
    gridRootLFB[1,2] = rootODScrollWinF

    push!(gridRootLFrameB, gridRootLFB)
    # end list and tree ########################################################

    push!(rootlocusFrame, mainGridRoot)

    # Notebook for Plots in Root-locus #########################################
    nbRoot = Notebook()
    set_gtk_property!(nbRoot, :tab_pos, 2)

    rootStepFrame = Frame()
    rootRampFrame = Frame()
    rootRootFrame = Frame()

    push!(rootStepFrame, imgRoot)
    push!(rootRampFrame, imgRamp)
    push!(rootRootFrame, imgRL)

    push!(nbRoot, rootStepFrame, "Step Response")
    push!(nbRoot, rootRampFrame, "Ramp Response")
    push!(nbRoot, rootRootFrame, "Root-locus")

    push!(gridRootRFrameUp, nbRoot)
    # End of root-locus assistant ##############################################

    # Lag assistant #####################################################
    lagFrame = Frame()

    mainGridLag = Grid()
    set_gtk_property!(mainGridLag, :column_homogeneous, false)
    set_gtk_property!(mainGridLag, :row_homogeneous, false)
    set_gtk_property!(mainGridLag, :margin_top, 10)
    set_gtk_property!(mainGridLag, :margin_bottom, 10)
    set_gtk_property!(mainGridLag, :margin_left, 10)
    set_gtk_property!(mainGridLag, :margin_right, 10)
    set_gtk_property!(mainGridLag, :column_spacing, 10)
    set_gtk_property!(mainGridLag, :row_spacing, 10)

    gridLagLeft = Grid()
    set_gtk_property!(gridLagLeft, :valign, 3)
    set_gtk_property!(gridLagLeft, :halign, 3)
    set_gtk_property!(gridLagLeft, :column_spacing, 10)
    set_gtk_property!(gridLagLeft, :row_spacing, 10)
    set_gtk_property!(gridLagLeft, :column_homogeneous, true)

    gridLagRight = Grid()
    set_gtk_property!(gridLagRight, :valign, 3)
    set_gtk_property!(gridLagRight, :halign, 3)
    set_gtk_property!(gridLagRight, :column_spacing, 10)
    set_gtk_property!(gridLagRight, :row_spacing, 10)
    set_gtk_property!(gridLagRight, :column_homogeneous, true)

    gridLagLFrameUp = Frame("Input Data")
    set_gtk_property!(gridLagLFrameUp, :width_request, (w*0.6)*0.4)
    set_gtk_property!(gridLagLFrameUp, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.35)
    set_gtk_property!(gridLagLFrameUp, :label_xalign, 0.50)
    set_gtk_property!(gridLagLFrameUp, :label_yalign, 0.00)

    # TF, List and table for input data
    gridLagLFUp = Grid()
    set_gtk_property!(gridLagLFUp, :column_homogeneous, false)
    set_gtk_property!(gridLagLFUp, :row_homogeneous, false)
    set_gtk_property!(gridLagLFUp, :column_spacing, 10)
    set_gtk_property!(gridLagLFUp, :row_spacing, 10)
    set_gtk_property!(gridLagLFUp, :margin_top, 10)
    set_gtk_property!(gridLagLFUp, :margin_bottom, 10)
    set_gtk_property!(gridLagLFUp, :margin_left, 10)
    set_gtk_property!(gridLagLFUp, :margin_right, 10)
    set_gtk_property!(gridLagLFUp, :valign, 3)
    set_gtk_property!(gridLagLFUp, :halign, 3)

    # entry for TF

    lagNumTf = Entry()
    lagDenTf = Entry()

    labelLagGs = Label("G(s) = ")
    labelLagDen = Label("[d1,d2... dn]")
    labelLagNum = Label("[n1,n2... nm]")

    # Entry for Kv, T
    lagT = Entry()
    lagKv = Entry()
    lagTLabel = Label("T:")
    lagKvLabel = Label("Kv:")

    global lagCheck = CheckButton("Copy from Root-locus Assistant")
    signal_connect(lagCheck, :toggled) do widget
        checkLagStatus = get_gtk_property(lagCheck, :active, Bool)

        if rootLocusStatus == 1
            if checkLagStatus == true
                global rootNumTfData = get_gtk_property(rootNumTf, :text, String)
                global rootDenTfData = get_gtk_property(rootDenTf, :text, String)

                set_gtk_property!(lagNumTf, :text, rootNumTfData)
                set_gtk_property!(lagDenTf, :text, rootDenTfData)
            else
                set_gtk_property!(lagNumTf, :text, "")
                set_gtk_property!(lagDenTf, :text, "")
            end
        else
            if checkLagStatus == true
                @sigatom set_gtk_property!(lagCheck, :active, false)
                warn_dialog("Data are not available from Root-Locus Assistant", mainWin)
            end
        end
    end

    gridLagLFUp[1,1:2] = labelLagGs
    gridLagLFUp[2,1] = labelLagNum
    gridLagLFUp[2,2] = labelLagDen
    gridLagLFUp[3,1] = lagNumTf
    gridLagLFUp[3,2] = lagDenTf
    gridLagLFUp[1:3,3] = lagCheck
    gridLagLFUp[1:2,4] = lagTLabel
    gridLagLFUp[1:2,5] = lagKvLabel
    gridLagLFUp[3,4] = lagT
    gridLagLFUp[3,5] = lagKv

    push!(gridLagLFrameUp, gridLagLFUp)

    gridLagLFrameB = Frame("Output Data")
    set_gtk_property!(gridLagLFrameB, :width_request, (w*0.6)*0.4)
    set_gtk_property!(gridLagLFrameB, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.60)
    set_gtk_property!(gridLagLFrameB, :label_xalign, 0.50)
    set_gtk_property!(gridLagLFrameB, :label_yalign, 0.00)

    gridLagRFrameUp = Frame()
    set_gtk_property!(gridLagRFrameUp, :width_request, (w*0.6)*0.57)
    set_gtk_property!(gridLagRFrameUp, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.70)

    imgLagRoot = Image()
    imgLagRamp = Image()
    imgLagRL = Image()
    imgLOpAmp = Image()

    gridLagRFrameB = Frame("Operational Amp")
    set_gtk_property!(gridLagRFrameB, :width_request, (w*0.6)*0.57)
    set_gtk_property!(gridLagRFrameB, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.25)
    set_gtk_property!(gridLagRFrameB, :label_xalign, 0.50)
    set_gtk_property!(gridLagRFrameB, :label_yalign, 0.00)

    # TF, List and table for input data
    gridLagLFB = Grid()
    set_gtk_property!(gridLagLFB, :column_homogeneous, false)
    set_gtk_property!(gridLagLFB, :row_homogeneous, false)
    set_gtk_property!(gridLagLFB, :column_spacing, 10)
    set_gtk_property!(gridLagLFB, :row_spacing, 10)
    set_gtk_property!(gridLagLFB, :margin_top, 10)
    set_gtk_property!(gridLagLFB, :margin_bottom, 10)
    set_gtk_property!(gridLagLFB, :margin_left, 10)
    set_gtk_property!(gridLagLFB, :margin_right, 10)

    lagNbTF = Notebook()

    lagTFOpenImg = Image()
    lagTFOpenFrame = Frame(lagTFOpenImg)
    lagTFOpenFrameScroll = ScrolledWindow(lagTFOpenFrame)
    set_gtk_property!(lagTFOpenFrameScroll, :tooltip_markup, "Uncompensated Open-loop transfer function")

    lagTFCerrImg = Image()
    lagTFCerrFrame = Frame(lagTFCerrImg)
    lagTFCerrFrameScroll = ScrolledWindow(lagTFCerrFrame)
    set_gtk_property!(lagTFCerrFrameScroll, :tooltip_markup, "Uncompensated Closed-loop transfer function")

    lagTFCompImg = Image()
    lagTFCompFrame = Frame(lagTFCompImg)
    lagTFCompFrameScroll = ScrolledWindow(lagTFCompFrame)
    set_gtk_property!(lagTFCompFrameScroll, :tooltip_markup, "Lag compensator transfer function")

    lagTFCompOpenImg = Image()
    lagTFCompOpenFrame = Frame(lagTFCompOpenImg)
    lagTFCompOpenFrameScroll = ScrolledWindow(lagTFCompOpenFrame)
    set_gtk_property!(lagTFCompOpenFrameScroll, :tooltip_markup, "Compensated Open-loop transfer function")

    lagTFCompCerrImg = Image()
    lagTFOpenCerrFrame = Frame(lagTFCompCerrImg)
    lagTFOpenCerrFrameScroll = ScrolledWindow(lagTFOpenCerrFrame)
    set_gtk_property!(lagTFOpenCerrFrameScroll, :tooltip_markup, "Compensated Closed-loop transfer function")

    push!(lagNbTF, lagTFOpenFrameScroll, "G(s)")
    push!(lagNbTF, lagTFCerrFrameScroll, "C(s)/R(s)")
    push!(lagNbTF, lagTFCompFrameScroll, "Gc(s)")
    push!(lagNbTF, lagTFCompOpenFrameScroll, "Gc(s)*G(s)")
    push!(lagNbTF, lagTFOpenCerrFrameScroll, "C(s)/R(s)")

    gLagLFBTF = Frame()
    set_gtk_property!(gLagLFBTF, :label_xalign, 0.50)
    set_gtk_property!(gLagLFBTF, :label_yalign, 0.00)
    set_gtk_property!(gLagLFBTF, :width_request, (w*0.6)*0.385)
    set_gtk_property!(gLagLFBTF, :height_request, 0.40*((h*0.75)-((h * 0.75) * 0.09))*0.50)

    gLagLFBTFScroll = ScrolledWindow()
    push!(gLagLFBTFScroll,lagNbTF)
    push!(gLagLFBTF,gLagLFBTFScroll)

    global listLag = ListStore(String, String, String)

    push!(listLag,("ωn","unsolved","unsolved"))
    push!(listLag,("ζ","unsolved", "unsolved"))
    push!(listLag,("Poles", "unsolved", "unsolved"))
    push!(listLag,("Kv", "unsolved", "unsolved"))
    push!(listLag,("Rise Time (sec)", "unsolved", "unsolved"))
    push!(listLag,("Peak Time (sec)", "unsolved", "unsolved"))
    push!(listLag,("Overshoot (%)", "unsolved", "unsolved"))
    push!(listLag,("Settling Time (sec)", "unsolved", "unsolved"))
    push!(listLag,("Angle contribution (degrees)", "---", "unsolved"))
    push!(listLag,("Pole", "---", "unsolved"))
    push!(listLag,("Zero", "---", "unsolved"))
    push!(listLag,("β", "---", "unsolved"))
    push!(listLag,("Kc", "---", "unsolved"))

    treeLag = TreeView(TreeModel(listLag))
    rowTxtL = CellRendererText()

    c1Lag = TreeViewColumn("Parameter", rowTxtL, Dict([("text",0)]))
    c2Lag = TreeViewColumn("Original Value", rowTxtL, Dict([("text",1)]))
    c3Lag = TreeViewColumn("Compensated Value", rowTxtL, Dict([("text",2)]))

    Gtk.GAccessor.resizable(c1Lag, true)
    Gtk.GAccessor.resizable(c2Lag, true)
    Gtk.GAccessor.resizable(c3Lag, true)

    push!(treeLag, c1Lag, c2Lag, c3Lag)

    lagODScrollWin = ScrolledWindow()
    set_gtk_property!(lagODScrollWin, :name, "lagODScrollWin")
    set_gtk_property!(lagODScrollWin, :height_request, 0.65*((h*0.75)-((h * 0.75) * 0.09))*0.50)
    screen = Gtk.GAccessor.style_context(lagODScrollWin)
    push!(screen, StyleProvider(provider), 600)

    lagODScrollWinF = Frame()
    push!(lagODScrollWin,treeLag)
    push!(lagODScrollWinF,lagODScrollWin)

    gridLagLFB[1,1] = gLagLFBTF
    gridLagLFB[1,2] = lagODScrollWinF

    push!(gridLagLFrameB, gridLagLFB)
    # end list and tree ########################################################

    gridLagLeft[1,1] = gridLagLFrameUp
    gridLagLeft[1,2] = gridLagLFrameB

    gridLagRight[1,1] = gridLagRFrameUp
    gridLagRight[1,2] = gridLagRFrameB

    mainGridLag[1,1] = gridLagLeft
    mainGridLag[2,1] = gridLagRight

    push!(lagFrame, mainGridLag)

    # Notebook for Plots in Lag compensator #########################################
    nbLag = Notebook()
    set_gtk_property!(nbLag, :tab_pos, 2)

    lagStepFrame = Frame()
    lagRampFrame = Frame()
    lagRootFrame = Frame()
    lagAmpOpFrame = Frame()

    push!(lagStepFrame, imgLagRoot)
    push!(lagRampFrame, imgLagRamp)
    push!(lagRootFrame, imgLagRL)

    push!(nbLag, lagStepFrame, "Step Response")
    push!(nbLag, lagRampFrame, "Ramp Response")
    push!(nbLag, lagRootFrame, "Root-locus")
    push!(nbLag, lagAmpOpFrame, "Amp Op Diagram")

    push!(gridLagRFrameUp, nbLag)

    # End of lag assistant ##############################################

    # Lead assistant #####################################################
    leadFrame = Frame()

    mainGridLead = Grid()
    set_gtk_property!(mainGridLead, :column_homogeneous, false)
    set_gtk_property!(mainGridLead, :row_homogeneous, false)
    set_gtk_property!(mainGridLead, :margin_top, 10)
    set_gtk_property!(mainGridLead, :margin_bottom, 10)
    set_gtk_property!(mainGridLead, :margin_left, 10)
    set_gtk_property!(mainGridLead, :margin_right, 10)
    set_gtk_property!(mainGridLead, :column_spacing, 10)
    set_gtk_property!(mainGridLead, :row_spacing, 10)

    gridLeadLeft = Grid()
    set_gtk_property!(gridLeadLeft, :valign, 3)
    set_gtk_property!(gridLeadLeft, :halign, 3)
    set_gtk_property!(gridLeadLeft, :column_spacing, 10)
    set_gtk_property!(gridLeadLeft, :row_spacing, 10)
    set_gtk_property!(gridLeadLeft, :column_homogeneous, true)

    gridLeadRight = Grid()
    set_gtk_property!(gridLeadRight, :valign, 3)
    set_gtk_property!(gridLeadRight, :halign, 3)
    set_gtk_property!(gridLeadRight, :column_spacing, 10)
    set_gtk_property!(gridLeadRight, :row_spacing, 10)
    set_gtk_property!(gridLeadRight, :column_homogeneous, true)

    gridLeadLFrameUp = Frame("Input Data")
    set_gtk_property!(gridLeadLFrameUp, :width_request, (w*0.6)*0.4)
    set_gtk_property!(gridLeadLFrameUp, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.45)
    set_gtk_property!(gridLeadLFrameUp, :label_xalign, 0.50)
    set_gtk_property!(gridLeadLFrameUp, :label_yalign, 0.00)

    gridLeadLFrameB = Frame("Output Data")
    set_gtk_property!(gridLeadLFrameB, :width_request, (w*0.6)*0.4)
    set_gtk_property!(gridLeadLFrameB, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.50)
    set_gtk_property!(gridLeadLFrameB, :label_xalign, 0.50)
    set_gtk_property!(gridLeadLFrameB, :label_yalign, 0.00)

    gridLeadRFrameUp = Frame()
    set_gtk_property!(gridLeadRFrameUp, :width_request, (w*0.6)*0.57)
    set_gtk_property!(gridLeadRFrameUp, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.70)

    gridLeadRFrameB = Frame("Operational Amp")
    set_gtk_property!(gridLeadRFrameB, :width_request, (w*0.6)*0.57)
    set_gtk_property!(gridLeadRFrameB, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.25)
    set_gtk_property!(gridLeadRFrameB, :label_xalign, 0.50)
    set_gtk_property!(gridLeadRFrameB, :label_yalign, 0.00)

    gridLeadLeft[1,1] = gridLeadLFrameUp
    gridLeadLeft[1,2] = gridLeadLFrameB

    gridLeadRight[1,1] = gridLeadRFrameUp
    gridLeadRight[1,2] = gridLeadRFrameB

    mainGridLead[1,1] = gridLeadLeft
    mainGridLead[2,1] = gridLeadRight

    push!(leadFrame, mainGridLead)

    # Notebook for Plots in Lead compensator #########################################
    nbLead = Notebook()
    set_gtk_property!(nbLead, :tab_pos, 2)

    leadStepFrame = Frame()
    leadRampFrame = Frame()
    leadRootFrame = Frame()
    leadGraphicFrame = Frame()
    leadAmpOpFrame = Frame()

    push!(nbLead, leadStepFrame, "Step Response")
    push!(nbLead, leadRampFrame, "Ramp Response")
    push!(nbLead, leadRootFrame, "Root-locus")
    push!(nbLead, leadGraphicFrame, "Graphic Design")
    push!(nbLead, leadAmpOpFrame, "Amp Op Diagram")

    scrollWin = ScrolledWindow()
    push!(scrollWin,nbLead)
    push!(gridLeadRFrameUp, scrollWin)

    # End of lead assistant ##############################################

    # Lead-lagFrame assistant ##################################################
    leadlagFrame = Frame()

    mainGridLeadlag = Grid()
    set_gtk_property!(mainGridLeadlag, :column_homogeneous, false)
    set_gtk_property!(mainGridLeadlag, :row_homogeneous, false)
    set_gtk_property!(mainGridLeadlag, :margin_top, 10)
    set_gtk_property!(mainGridLeadlag, :margin_bottom, 10)
    set_gtk_property!(mainGridLeadlag, :margin_left, 10)
    set_gtk_property!(mainGridLeadlag, :margin_right, 10)
    set_gtk_property!(mainGridLeadlag, :column_spacing, 10)
    set_gtk_property!(mainGridLeadlag, :row_spacing, 10)

    gridLeadlagLeft = Grid()
    set_gtk_property!(gridLeadlagLeft, :valign, 3)
    set_gtk_property!(gridLeadlagLeft, :halign, 3)
    set_gtk_property!(gridLeadlagLeft, :column_spacing, 10)
    set_gtk_property!(gridLeadlagLeft, :row_spacing, 10)
    set_gtk_property!(gridLeadlagLeft, :column_homogeneous, true)

    gridLeadlagRight = Grid()
    set_gtk_property!(gridLeadlagRight, :valign, 3)
    set_gtk_property!(gridLeadlagRight, :halign, 3)
    set_gtk_property!(gridLeadlagRight, :column_spacing, 10)
    set_gtk_property!(gridLeadlagRight, :row_spacing, 10)
    set_gtk_property!(gridLeadlagRight, :column_homogeneous, true)

    gridLeadlagLFrameUp = Frame("Input Data")
    set_gtk_property!(gridLeadlagLFrameUp, :width_request, (w*0.6)*0.4)
    set_gtk_property!(gridLeadlagLFrameUp, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.45)
    set_gtk_property!(gridLeadlagLFrameUp, :label_xalign, 0.50)
    set_gtk_property!(gridLeadlagLFrameUp, :label_yalign, 0.00)

    gridLeadlagLFrameB = Frame("Output Data")
    set_gtk_property!(gridLeadlagLFrameB, :width_request, (w*0.6)*0.4)
    set_gtk_property!(gridLeadlagLFrameB, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.50)
    set_gtk_property!(gridLeadlagLFrameB, :label_xalign, 0.50)
    set_gtk_property!(gridLeadlagLFrameB, :label_yalign, 0.00)

    gridLeadlagRFrameUp = Frame()
    set_gtk_property!(gridLeadlagRFrameUp, :width_request, (w*0.6)*0.57)
    set_gtk_property!(gridLeadlagRFrameUp, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.70)

    gridLeadlagRFrameB = Frame("Operational Amp")
    set_gtk_property!(gridLeadlagRFrameB, :width_request, (w*0.6)*0.57)
    set_gtk_property!(gridLeadlagRFrameB, :height_request, ((h*0.75)-((h * 0.75) * 0.09))*0.25)
    set_gtk_property!(gridLeadlagRFrameB, :label_xalign, 0.50)
    set_gtk_property!(gridLeadlagRFrameB, :label_yalign, 0.00)

    gridLeadlagLeft[1,1] = gridLeadlagLFrameUp
    gridLeadlagLeft[1,2] = gridLeadlagLFrameB

    gridLeadlagRight[1,1] = gridLeadlagRFrameUp
    gridLeadlagRight[1,2] = gridLeadlagRFrameB

    mainGridLeadlag[1,1] = gridLeadlagLeft
    mainGridLeadlag[2,1] = gridLeadlagRight

    push!(leadlagFrame, mainGridLeadlag)

    # Notebook for Plots in Lead-lag##############################################
    nbleadlag = Notebook()
    set_gtk_property!(nbleadlag, :tab_pos, 2)

    leadlagStepFrame = Frame()
    leadlagRampFrame = Frame()
    leadlagRootFrame = Frame()
    leadlagGraphicFrame = Frame()
    leadlagAmpOpFrame = Frame()

    push!(nbleadlag, leadlagStepFrame, "Step Response")
    push!(nbleadlag, leadlagRampFrame, "Ramp Response")
    push!(nbleadlag, leadlagRootFrame, "Root-locus")
    push!(nbleadlag, leadlagGraphicFrame, "Graphic Design")
    push!(nbleadlag, leadlagAmpOpFrame, "Amp Op Diagram")

    scrollleadlag = ScrolledWindow()
    push!(scrollleadlag,nbleadlag)
    push!(gridLeadlagRFrameUp, scrollleadlag)
    ##########End leadlag

    push!(nb, rootlocusFrame, "Root-locus Assistant")
    push!(nb, lagFrame, "Lag compensator")
    push!(nb, leadFrame, "Lead compensator")
    push!(nb, leadlagFrame, "Lead-lag compensator")

    #
    mainGrid[1,1] = mainToolbar
    mainGrid[1,2] = nb

    push!(mainWin,mainGrid)

    # Show program
    Gtk.showall(mainWin)
end

ext: jl


text:
using Distributions
using Base.Test

# Set location vector mu and scale matrix Sigma as in
# Hofert M. On Sampling from the Multivariate t Distribution. The R Journal
mu = [1., 2]
Sigma = [4. 2; 2 3]

# LogPDF evaluation for varying degrees of freedom df
# Julia's output is compared to R's corresponding values obtained via R's mvtnorm package
# R code exemplifying how the R values (rvalues) were obtained:
# options(digits=20)
# library("mvtnorm")
# mu <- 1:2
# Sigma <- matrix(c(4, 2, 2, 3), ncol=2)
# dmvt(c(-2., 3.), delta=mu, sigma=Sigma, df=1)
rvalues = [-5.6561739738159975133,
  -5.4874952805811396672,
  -5.4441948098568158088,
  -5.432461875138580254,
  -5.4585441614404803801]
df = [1., 2, 3, 5, 10]
for i = 1:length(df)
  d = MvTDist(df[i], mu, Sigma)
  @test_approx_eq_eps logpdf(d, [-2., 3]) rvalues[i] 1.0e-8
end


text:
using LazySets

function spikingNeuron_specification()
    # initial set in mode 1
    X0_m1 = Hyperrectangle(low=[-65.0, -0.2], high=[-60.0, 0.2])
    X0 = [(1, X0_m1)]

    # time horizon: 100 time units
    time_horizon = 100.0

    # specification
    O = Dict{Symbol, Any}(:T => time_horizon)

    return X0, O
end

max_stars_repo_name: JuliaReach/ReachabilityBenchmarks

max_issues_repo_name: JuliaReach/ReachabilityBenchmarks

max_forks_repo_name: JuliaReach/ReachabilityBenchmarks


text:
module AtmosphereWrapper

using JavaCall

const AbsoluteDate = @jimport org.orekit.time.AbsoluteDate
const Atmosphere = @jimport org.orekit.models.earth.atmosphere.Atmosphere
const BodyShape = @jimport org.orekit.bodies.BodyShape
const Class = @jimport java.lang.Class
const DTM2000 = @jimport org.orekit.models.earth.atmosphere.DTM2000
const DTM2000InputParameters = @jimport org.orekit.models.earth.atmosphere.DTM2000InputParameters
const FieldAbsoluteDate = @jimport org.orekit.time.FieldAbsoluteDate
const FieldVector3D = @jimport org.hipparchus.geometry.euclidean.threed.FieldVector3D
const Frame = @jimport org.orekit.frames.Frame
const HarrisPriester = @jimport org.orekit.models.earth.atmosphere.HarrisPriester
const JB2008 = @jimport org.orekit.models.earth.atmosphere.JB2008
const JB2008InputParameters = @jimport org.orekit.models.earth.atmosphere.JB2008InputParameters
const JString = @jimport java.lang.String
const NRLMSISE00 = @jimport org.orekit.models.earth.atmosphere.NRLMSISE00
const NRLMSISE00InputParameters = @jimport org.orekit.models.earth.atmosphere.NRLMSISE00InputParameters
const Object = @jimport java.lang.Object
const OneAxisEllipsoid = @jimport org.orekit.bodies.OneAxisEllipsoid
const PVCoordinatesProvider = @jimport org.orekit.utils.PVCoordinatesProvider
const RealFieldElement = @jimport org.hipparchus.RealFieldElement
const SimpleExponentialAtmosphere = @jimport org.orekit.models.earth.atmosphere.SimpleExponentialAtmosphere
const TimeScale = @jimport org.orekit.time.TimeScale
const Vector3D = @jimport org.hipparchus.geometry.euclidean.threed.Vector3D

export Atmosphere
export DTM2000
export DTM2000InputParameters
export HarrisPriester
export JB2008
export JB2008InputParameters
export NRLMSISE00
export NRLMSISE00InputParameters
export SimpleExponentialAtmosphere
export equals
export get24_hours_kp
export get_ap
export get_average_flux
export get_class
export get_daily_flux
export get_density
export get_dstdtc
export get_f10
export get_f10b
export get_frame
export get_instant_flux
export get_max_alt
export get_max_date
export get_mean_flux
export get_min_alt
export get_min_date
export get_s10
export get_s10b
export get_tab_density
export get_three_hourly_kp
export get_velocity
export get_xm10
export get_xm10b
export get_y10
export get_y10b
export hash_code
export notify
export notify_all
export to_string
export wait
export with_switch

include("DataWrapper/DataWrapper.jl")
include("atmosphere.jl")
include("dt_m2000.jl")
include("dt_m2000_input_parameters.jl")
include("harris_priester.jl")
include("j_b2008.jl")
include("j_b2008_input_parameters.jl")
include("nrlmsis_e00.jl")
include("nrlmsis_e00_input_parameters.jl")
include("simple_exponential_atmosphere.jl")

end


text:
using Tokenize

const word2color = Dict(
                        :KEYWORD       => :light_magenta,
                        :OP            => :light_yellow,
                        :END           => :magenta,
                        :TRUE          => :yellow,
                        :FALSE         => :yellow,
                        :FLOAT         => :cyan,
                        :INTEGER       => :cyan,
                        :STRING        => :light_green,
                        :TRIPLE_STRING => :light_green,
                        :CHAR          => :red,
                        :COMMENT       => :green,
                        :ERROR         => :light_red,
                       )

const ttc = Dict(zip(getfield.(Tokenize.Tokens, collect(keys(word2color))),
                     values(word2color)))

function colorize(s::String, c, def="\e[0m")
    tc = Base.text_colors
    c in keys(tc) ? string(tc[c], s, def) : s
end

function highlight(t::Tokenize.Tokens.Token)
    s = untokenize(t)
    k = Tokenize.Tokens.kind(t)
    ek = Tokenize.Tokens.exactkind(t)
    if ek in keys(ttc)
        colorize(s, ttc[ek])
    elseif k in keys(ttc)
        colorize(s, ttc[k])
    else
        s
    end
end

function highlight(s::String)
    tk = collect(tokenize(s))
    join(highlight.(tk))
end


text:
using DataFrames
using StatsBase

"""
	rxy(x::Real,y::Real)
	r -> sqrt{x^2 + y^2}
"""
function rxy(x::Real, y::Real)
    return sqrt(x^2 + y^2)
end

"""
	hixy(x::Real, y::Real)
	phi -> atan(y/x)
"""
function phixy(x::Real, y::Real)
    return atan(y,x)
end

"""
	phixy(hitdf::DataFrame)
	phi -> atan(y/x) where y and x are columns of the data frame
"""
function fphi(hitdf::DataFrame)
    return atan.(hitdf.y,hitdf.x)
end

"""
	dxyz(x1::Vector{<:Real}, x2::Vector{<:Real})

Distance between two points.
"""

function dxyz(x1::Vector{<:Real}, x2::Vector{<:Real})
    return sqrt((x1[1] - x2[1])^2 + (x1[2] - x2[2])^2 + (x1[3] - x2[3])^2)
end

"""
	gline2p(x1,y1,x2, y2)
	Line that goes through two points
"""
function gline2p(x1, y1, x2, y2)
    fxy(x) = y1 + (x - x1) * (y2 - y1)/(x2 -x1)
end

function gline2p(x1::Real, y1::Real, x2::Real, y2::Real)
    fxy(x::Real) = y1 + (x - x1) * (y2 - y1)/(x2 -x1)
end

"""
function wstd(x::Vector{<:Real}, q::Vector{<:Real})

Compute the std deviation in x weighted by q:
Sqrt(1/Q Sum_i (x - x_mean) * qi )
"""
function wstd(x::Vector{<:Real}, q::Vector{<:Real})
	xmean = mean(x)
	qs = sum((x.-xmean).^2 .* q)
	Q = sum(q)
	return sqrt(qs/Q)
end

"""
	mean_std(x, xmin, xmax)
	Returns mean and std for a vector x in the interval between xmin and xmax
"""
function mean_std(x::Vector{<:Real}, xmin::Real, xmax::Real)
    xx = in_range(x, xmin, xmax)
    xm = mean(xx)
    xs = StatsBase.std(xx)
    return xm, xs
end

max_stars_repo_name: jjgomezcadenas/ATools

max_issues_repo_name: jjgomezcadenas/ATools

max_forks_repo_name: jjgomezcadenas/ATools


text:
using QuickPOMDPs
using POMDPModelTools
using Distributions

#=
The simple 1-D light dark problem from https://arxiv.org/pdf/1709.06196v6.pdf, section 5.2, or https://slides.com/zacharysunberg/defense-4#/39
=#

r = 60
light_loc = 10

simple_lightdark = QuickPOMDP(
    states = -r:r+1,                  # r+1 is a terminal state
    actions = [-10, -1, 0, 1, 10],
    discount = 0.95,
    isterminal = s -> !(s in -r:r),
    obstype = Float64,

    transition = function (s, a)
        if a == 0
            return SparseCat(r+1, 1.0)
        else
            return SparseCat(clamp(s+a, -r, r), 1.0)
        end
    end,

    observation = (s, a, sp) -> Normal(sp, abs(sp - light_loc) + 0.0001),

    reward = function (s, a, sp, o)
        if a == 0
            return s == 0 ? 100 : -100
        else
            return -1.0
        end
    end,

    initialstate_distribution = POMDPModelTools.Uniform(div(-r,2):div(-r,2))
)


text:
using Interpolations
function parseAndUpdate(audioSamp::SampledSignals.SampleBuf, spec::SampledSignals.SpectrumBuf, led_data::LEDArray, socket::UDPSocket, mode::String)
    if usegpu[]
        spec .= fft(audioSamp[:,1])
    else
        spec .= fft(audioSamp[:,1])
    end
    # use an implicit reference to the function if possible,
    # else fall back on the bars animation.
    if mode in keys(update_methods)
        update_methods[mode](led_data, audioSamp[:,1], spec)
    else
        getBarsFrame(led_data, audioSamp[:,1], spec)
    end
    push(led_data, socket)
end

@inline function update!(channel::LEDChannel)
    Threads.@threads for i in eachindex(channel.itps)
        channel.itps[i] = interpolate(channel.virtualmem[:,i], BSpline(Quadratic(Natural())), OnCell())
    end
    for m in channel.map
        indicies = linspace(m[1]/100*channel.precision, m[2]/100*channel.precision, length(m[3]))
        Threads.@threads for i in 1:size(m[3],1)
            m[3][i,:] = round.(UInt8, map!(safeFloat, getindex.(channel.itps', indicies[i])))
        end
    end
end