#pragma once

// Generated by STruC++ - IEC 61131-3 Structured Text to C++ Compiler
// Do not edit this file manually.

#include "iec_types.hpp"
#include "iec_var.hpp"
#include "iec_global.hpp"
#include "iec_array.hpp"
#include "iec_located.hpp"
#include "iec_std_lib.hpp"
#include "iec_enum.hpp"
#include "iec_memory.hpp"
#include "iec_pointer.hpp"
#include "iec_string.hpp"
#include "iec_wstring.hpp"
#include <array>
#include <cstddef>
#include <string>

// Avoid clashes between ST identifiers and C stdlib macros
#ifdef TMP_MAX
#undef TMP_MAX
#endif
#ifdef EOF
#undef EOF
#endif
#ifdef BUFSIZ
#undef BUFSIZ
#endif
#ifdef FOPEN_MAX
#undef FOPEN_MAX
#endif
#ifdef FILENAME_MAX
#undef FILENAME_MAX
#endif
#ifdef RAND_MAX
#undef RAND_MAX
#endif
#ifdef EXIT_SUCCESS
#undef EXIT_SUCCESS
#endif
#ifdef EXIT_FAILURE
#undef EXIT_FAILURE
#endif

#undef OVERFLOW

// Global constants
constexpr size_t STRING_LENGTH = 254;
constexpr size_t LIST_LENGTH = 254;

namespace strucpp {

// Library: iec-standard-fb
class TON;
class TON {
public:
    // Inputs
    IEC_BOOL IN;
    IEC_TIME PT;
    // Outputs
    IEC_BOOL Q;
    IEC_TIME ET;
    // Local variables
    IEC_SINT STATE;
    IEC_BOOL PREV_IN;
    IEC_TIME CURRENT_TIME;
    IEC_TIME START_TIME;

    // Implicit IEC 61131-3 ENO pin (mirrors EN)
    IEC_BOOL ENO = true;

    // Constructor
    TON();

    // Execute function block
    void operator()();

    virtual ~TON() = default;
};


// Library: oscat-basic
class INTEGRATE;
class SPEED;
class INTEGRATE {
public:
    // Inputs
    IEC_BOOL E;
    IEC_REAL X;
    IEC_REAL K;
    // In-Out
    IEC_REAL Y;
    // Local variables
    IEC_REAL X_LAST;
    IEC_BOOL INIT;
    IEC_DWORD LAST;
    IEC_DWORD TX;

    // Implicit IEC 61131-3 ENO pin (mirrors EN)
    IEC_BOOL ENO = true;

    // Constructor
    INTEGRATE();

    // Execute function block
    void operator()();

    virtual ~INTEGRATE() = default;
};

class SPEED {
public:
    // Inputs
    IEC_REAL MS;
    IEC_REAL KMH;
    IEC_REAL KN;
    IEC_REAL MH;
    // Outputs
    IEC_REAL YMS;
    IEC_REAL YKMH;
    IEC_REAL YKN;
    IEC_REAL YMH;

    // Implicit IEC 61131-3 ENO pin (mirrors EN)
    IEC_BOOL ENO = true;

    // Constructor
    SPEED();

    // Execute function block
    void operator()();

    virtual ~SPEED() = default;
};

IEC_INT CEIL(IEC_REAL X);
IEC_REAL EXPN(IEC_REAL X, IEC_INT N);
IEC_REAL OFFSET(IEC_REAL X, IEC_BOOL O1, IEC_BOOL O2, IEC_BOOL O3, IEC_BOOL O4, IEC_BOOL D, IEC_REAL OFFSET_1, IEC_REAL OFFSET_2, IEC_REAL OFFSET_3, IEC_REAL OFFSET_4, IEC_REAL DEFAULT);
IEC_REAL RND(IEC_REAL X, IEC_INT N);
IEC_DWORD T_PLC_MS();

class FB_DUTY_SELECT;
class FB_HEADROOM;
class FB_LEVEL_CTRL;
class FB_PUMP;
class Program_CONTROL;
class Program_SIMULATION;
class Program_IO_MUX;
class Configuration_CONFIG0;

// Configuration VAR_GLOBAL storage — file-scope so every POU (program or nested function block) reaches the one canonical GlobalVar<V> (value + mutex).
inline GlobalVar<IEC_REAL> CFG_AREA_M2{120.0};
inline GlobalVar<IEC_REAL> CFG_SPILL_M{6.000};
inline GlobalVar<IEC_REAL> CFG_LSHH_M{5.500};
inline GlobalVar<IEC_REAL> CFG_MIN_HZ{38.0};
inline GlobalVar<IEC_REAL> CFG_MAX_HZ{50.0};
inline GlobalVar<IEC_INT> DEF_MODE{1};
inline GlobalVar<IEC_INT> DEF_SP_LEVEL{4200};
inline GlobalVar<IEC_INT> DEF_START_DUTY{4000};
inline GlobalVar<IEC_INT> DEF_START_P2{4500};
inline GlobalVar<IEC_INT> DEF_START_P3{5000};
inline GlobalVar<IEC_INT> DEF_STOP_ALL{1000};
inline GlobalVar<IEC_INT> DEF_HIGH_ALARM{5200};
inline GlobalVar<IEC_INT> DEF_MIN_SPEED{380};
inline GlobalVar<IEC_INT> DEF_SERVICE_HRS{4000};
inline GlobalVar<IEC_INT> CFG_NO_TIME{32767};
inline GlobalVar<IEC_INT> IW_LIT101{0};
inline GlobalVar<IEC_INT> IW_FIT201{0};
inline GlobalVar<IEC_INT> IW_FIT301{0};
inline GlobalVar<IEC_INT> IW_PIT302{0};
inline GlobalVar<IEC_INT> IW_PIT311{0};
inline GlobalVar<IEC_INT> IW_PIT321{0};
inline GlobalVar<IEC_INT> IW_PIT331{0};
inline GlobalVar<IEC_INT> IW_VE314{0};
inline GlobalVar<IEC_INT> IW_VE324{0};
inline GlobalVar<IEC_INT> IW_VE334{0};
inline GlobalVar<IEC_BOOL> IX_LSHH102{false};
inline GlobalVar<IEC_BOOL> IX_LSLL103{false};
inline GlobalVar<IEC_BOOL> IX_LSH104{false};
inline GlobalVar<IEC_BOOL> IX_TE312{false};
inline GlobalVar<IEC_BOOL> IX_TE322{false};
inline GlobalVar<IEC_BOOL> IX_TE332{false};
inline GlobalVar<IEC_BOOL> IX_MSE313{false};
inline GlobalVar<IEC_BOOL> IX_MSE323{false};
inline GlobalVar<IEC_BOOL> IX_MSE333{false};
inline GlobalVar<IEC_BOOL> IX_XA502{false};
inline GlobalVar<IEC_BOOL> QX_RUNCMD1{false};
inline GlobalVar<IEC_BOOL> QX_RUNCMD2{false};
inline GlobalVar<IEC_BOOL> QX_RUNCMD3{false};
inline GlobalVar<IEC_BOOL> QX_RUNNING1{false};
inline GlobalVar<IEC_BOOL> QX_RUNNING2{false};
inline GlobalVar<IEC_BOOL> QX_RUNNING3{false};
inline GlobalVar<IEC_BOOL> QX_AVAIL1{false};
inline GlobalVar<IEC_BOOL> QX_AVAIL2{false};
inline GlobalVar<IEC_BOOL> QX_AVAIL3{false};
inline GlobalVar<IEC_BOOL> QX_INAUTO{false};
inline GlobalVar<IEC_BOOL> QX_HIGHLEVEL{false};
inline GlobalVar<IEC_BOOL> QX_SPILLACTIVE{false};
inline GlobalVar<IEC_BOOL> QX_TRIPPED1{false};
inline GlobalVar<IEC_BOOL> QX_TRIPPED2{false};
inline GlobalVar<IEC_BOOL> QX_TRIPPED3{false};
inline GlobalVar<IEC_INT> QW_LEVEL{0};
inline GlobalVar<IEC_INT> QW_INFLOW{0};
inline GlobalVar<IEC_INT> QW_DISCHARGE{0};
inline GlobalVar<IEC_INT> QW_PUMPSRUNNING{0};
inline GlobalVar<IEC_INT> QW_SPEED{0};
inline GlobalVar<IEC_INT> QW_TIMETOSPILL{0};
inline GlobalVar<IEC_INT> QW_TIMETOLSHH{0};
inline GlobalVar<IEC_INT> QW_NETACCUM{0};
inline GlobalVar<IEC_INT> QW_RUNHOURS1{0};
inline GlobalVar<IEC_INT> QW_RUNHOURS2{0};
inline GlobalVar<IEC_INT> QW_RUNHOURS3{0};
inline GlobalVar<IEC_INT> QW_VOLTOSPILL{0};
inline GlobalVar<IEC_INT> QW_STATIONSTATE{0};
inline GlobalVar<IEC_INT> QW_PUMPSTATE1{0};
inline GlobalVar<IEC_INT> QW_PUMPSTATE2{0};
inline GlobalVar<IEC_INT> QW_PUMPSTATE3{0};
inline GlobalVar<IEC_INT> QW_DUTYPUMP{0};
inline GlobalVar<IEC_INT> QW_ALARMWORD{0};
inline GlobalVar<IEC_INT> QW_CMDACK{0};
inline GlobalVar<IEC_INT> MW_MODE{0};
inline GlobalVar<IEC_INT> MW_CMDWORD{0};
inline GlobalVar<IEC_INT> MW_CMDPARAM{0};
inline GlobalVar<IEC_INT> MW_SPLEVEL{0};
inline GlobalVar<IEC_INT> MW_STARTDUTY{0};
inline GlobalVar<IEC_INT> MW_STARTP2{0};
inline GlobalVar<IEC_INT> MW_STARTP3{0};
inline GlobalVar<IEC_INT> MW_STOPALL{0};
inline GlobalVar<IEC_INT> MW_HIGHALARM{0};
inline GlobalVar<IEC_INT> MW_MINSPEED{0};
inline GlobalVar<IEC_INT> MW_SERVICEHRS{0};
inline GlobalVar<IEC_INT> MW_SIMINFLOW{0};
inline GlobalVar<IEC_INT> MW_SIMMODE{0};
inline GlobalVar<IEC_INT> MW_SIMRESET{0};
inline GlobalVar<IEC_INT> MW_SIMTIMESCALE{0};
inline GlobalVar<IEC_INT> G_LEVELRAW_MM{0};
inline GlobalVar<IEC_INT> G_LEVEL_MM{0};
inline GlobalVar<IEC_REAL> G_LEVEL_M{0.0};
inline GlobalVar<IEC_REAL> G_INFLOW_LPS{0.0};
inline GlobalVar<IEC_REAL> G_DISCH_LPS{0.0};
inline GlobalVar<IEC_REAL> G_MANIFOLDP_KPA{0.0};
inline GlobalVar<Array1D<IEC_REAL, 1, 3>> G_PUMPP_KPA{};
inline GlobalVar<Array1D<IEC_REAL, 1, 3>> G_VIB_MMS{};
inline GlobalVar<IEC_BOOL> G_LSHH{false};
inline GlobalVar<IEC_BOOL> G_LSLL_WET{false};
inline GlobalVar<IEC_BOOL> G_SPILLDETECTED{false};
inline GlobalVar<Array1D<IEC_BOOL, 1, 3>> G_THERMALOK{};
inline GlobalVar<Array1D<IEC_BOOL, 1, 3>> G_SEALLEAK{};
inline GlobalVar<IEC_BOOL> G_MAINSOK{false};
inline GlobalVar<IEC_INT> G_CMD_MODE{0};
inline GlobalVar<IEC_INT> G_CMD_WORD{0};
inline GlobalVar<IEC_INT> G_CMD_PARAM{0};
inline GlobalVar<IEC_INT> G_SP_LEVEL{0};
inline GlobalVar<IEC_INT> G_SP_STARTDUTY{0};
inline GlobalVar<IEC_INT> G_SP_STARTP2{0};
inline GlobalVar<IEC_INT> G_SP_STARTP3{0};
inline GlobalVar<IEC_INT> G_SP_STOPALL{0};
inline GlobalVar<IEC_INT> G_SP_HIGHALARM{0};
inline GlobalVar<IEC_INT> G_SP_MINSPEED{0};
inline GlobalVar<IEC_INT> G_SP_SERVICEHRS{0};
inline GlobalVar<Array1D<IEC_BOOL, 1, 3>> G_O_RUNCMD{};
inline GlobalVar<Array1D<IEC_BOOL, 1, 3>> G_O_RUNNING{};
inline GlobalVar<Array1D<IEC_BOOL, 1, 3>> G_O_AVAILABLE{};
inline GlobalVar<Array1D<IEC_BOOL, 1, 3>> G_O_TRIPPED{};
inline GlobalVar<IEC_BOOL> G_O_INAUTO{false};
inline GlobalVar<IEC_BOOL> G_O_HIGHLEVEL{false};
inline GlobalVar<IEC_BOOL> G_O_SPILLACTIVE{false};
inline GlobalVar<IEC_INT> G_O_LEVEL_MM{0};
inline GlobalVar<IEC_INT> G_O_INFLOW_X10{0};
inline GlobalVar<IEC_INT> G_O_DISCH_X10{0};
inline GlobalVar<IEC_INT> G_O_PUMPSRUN{0};
inline GlobalVar<IEC_INT> G_O_SPEED_X10{0};
inline GlobalVar<IEC_INT> G_O_TIMETOSPILL{0};
inline GlobalVar<IEC_INT> G_O_TIMETOLSHH{0};
inline GlobalVar<IEC_INT> G_O_NETACCUM{0};
inline GlobalVar<Array1D<IEC_INT, 1, 3>> G_O_RUNHOURS{};
inline GlobalVar<IEC_INT> G_O_VOLTOSPILL{0};
inline GlobalVar<IEC_INT> G_O_STATIONSTATE{0};
inline GlobalVar<Array1D<IEC_INT, 1, 3>> G_O_PUMPSTATE{};
inline GlobalVar<IEC_INT> G_O_DUTYPUMP{0};
inline GlobalVar<IEC_INT> G_O_ALARMWORD{0};
inline GlobalVar<IEC_INT> G_O_CMDACK{0};
inline GlobalVar<IEC_BOOL> G_SIMACTIVE{false};
inline GlobalVar<IEC_BOOL> G_SIM_CLEARRESET{false};
inline GlobalVar<IEC_INT> G_SIMCMD_INFLOW{0};
inline GlobalVar<IEC_INT> G_SIMCMD_MODE{0};
inline GlobalVar<IEC_INT> G_SIMCMD_RESET{0};
inline GlobalVar<IEC_INT> G_SIMCMD_TIMESCALE{0};
inline GlobalVar<IEC_INT> G_SIM_LEVEL_MM{0};
inline GlobalVar<IEC_INT> G_SIM_INFLOW_X10{0};
inline GlobalVar<IEC_INT> G_SIM_DISCH_X10{0};
inline GlobalVar<IEC_INT> G_SIM_MANIFOLDP{0};
inline GlobalVar<Array1D<IEC_INT, 1, 3>> G_SIM_PUMPP{};
inline GlobalVar<Array1D<IEC_INT, 1, 3>> G_SIM_VIB_X10{};
inline GlobalVar<IEC_BOOL> G_SIM_LSHH{false};
inline GlobalVar<IEC_BOOL> G_SIM_LSLL_WET{false};
inline GlobalVar<IEC_BOOL> G_SIM_SPILL{false};
inline GlobalVar<Array1D<IEC_BOOL, 1, 3>> G_SIM_THERMALOK{};
inline GlobalVar<Array1D<IEC_BOOL, 1, 3>> G_SIM_SEALLEAK{};
inline GlobalVar<IEC_BOOL> G_SIM_MAINSOK{false};

class FB_DUTY_SELECT {
public:
    // Inputs
    Array1D<IEC_BOOL, 1, 3> AVAILABLE;
    Array1D<IEC_REAL, 1, 3> RUNHOURS;
    Array1D<IEC_BOOL, 1, 3> SERVICEDUE;
    Array1D<IEC_BOOL, 1, 3> RUNNINGNOW;
    IEC_INT PUMPSREQUIRED;
    // Outputs
    Array1D<IEC_BOOL, 1, 3> RUNREQUEST;
    IEC_INT DUTYPUMP;
    // Local variables
    IEC_REAL SERVICE_PENALTY;
    Array1D<IEC_INT, 1, 3> RANK;
    Array1D<IEC_BOOL, 1, 3> USED;
    Array1D<IEC_BOOL, 1, 3> SEL;
    IEC_INT I;
    IEC_INT K;
    IEC_INT BEST;
    IEC_REAL BESTKEY;
    IEC_REAL KEY;
    IEC_INT NRANKED;
    IEC_INT SLOTS;
    IEC_INT CNT;

    // Implicit IEC 61131-3 ENO pin (mirrors EN)
    IEC_BOOL ENO = true;

    // Constructor
    FB_DUTY_SELECT();

    // Execute function block
    void operator()();

    virtual ~FB_DUTY_SELECT() = default;
};

class FB_HEADROOM {
public:
    // Inputs
    IEC_REAL LEVEL;
    IEC_REAL INFLOW;
    IEC_REAL TOTALDISCHARGE;
    // Outputs
    IEC_REAL INFLOWFILT;
    IEC_REAL NETINFLOW;
    IEC_REAL VOLTOSPILL;
    IEC_REAL VOLTOLSHH;
    IEC_INT TIMETOSPILL;
    IEC_INT TIMETOLSHH;
    // Local variables
    IEC_REAL SCAN_S;
    IEC_REAL TAU_S;
    IEC_REAL AREA_M2;
    IEC_REAL SPILL_M;
    IEC_REAL LSHH_M;
    IEC_REAL MIN_NET;
    IEC_INT NO_TIME;
    IEC_REAL MAX_TIME;
    IEC_BOOL PRIMED;
    IEC_REAL T;

    // Implicit IEC 61131-3 ENO pin (mirrors EN)
    IEC_BOOL ENO = true;

    // Constructor
    FB_HEADROOM();

    // Execute function block
    void operator()();

    virtual ~FB_HEADROOM() = default;
};

class FB_LEVEL_CTRL {
public:
    // Inputs
    IEC_REAL LEVEL;
    IEC_REAL SETPOINT;
    IEC_BOOL ENABLE;
    IEC_REAL MINSPEED;
    IEC_REAL MAXSPEED;
    // Outputs
    IEC_REAL SPEED;
    // Local variables
    IEC_REAL SCAN_S;
    IEC_REAL KP;
    IEC_REAL TI;
    IEC_REAL INTEG;
    IEC_REAL ERR;
    IEC_REAL RAW;
    IEC_BOOL INTEGRATE;

    // Implicit IEC 61131-3 ENO pin (mirrors EN)
    IEC_BOOL ENO = true;

    // Constructor
    FB_LEVEL_CTRL();

    // Execute function block
    void operator()();

    virtual ~FB_LEVEL_CTRL() = default;
};

class FB_PUMP {
public:
    // Inputs
    IEC_BOOL RUNREQUEST;
    IEC_REAL SPEEDREF;
    IEC_BOOL THERMALOK;
    IEC_BOOL SEALLEAK;
    IEC_REAL VIBRATION;
    IEC_REAL DISCHPRESSURE;
    IEC_BOOL RESETTRIP;
    IEC_BOOL LOCKOUT;
    IEC_BOOL MINOFFBYPASS;
    IEC_REAL SERVICEINTERVAL;
    IEC_BOOL RESETHOURS;
    // Outputs
    IEC_BOOL RUNCMD;
    IEC_BOOL RUNNING;
    IEC_BOOL AVAILABLE;
    IEC_BOOL TRIPPED;
    IEC_INT STATE;
    IEC_REAL RUNHOURS;
    IEC_BOOL SERVICEDUE;
    IEC_BOOL VIBALARM;
    IEC_BOOL SEALALARM;
    // Local variables
    IEC_REAL SCAN_S;
    IEC_REAL VIB_ALARM;
    IEC_REAL VIB_TRIP;
    IEC_REAL NOFLOW_KPA;
    TON MINRUNTMR;
    TON MINOFFTMR;
    TON NOFLOWTMR;
    IEC_BOOL HASRUN;
    IEC_BOOL STARTOK;

    // Implicit IEC 61131-3 ENO pin (mirrors EN)
    IEC_BOOL ENO = true;

    // Constructor
    FB_PUMP();

    // Execute function block
    void operator()();

    virtual ~FB_PUMP() = default;
};

class Program_CONTROL : public ProgramBase {
public:
    // Local variables
    IEC_INT SPILL_MM;
    IEC_INT LEVEL_MAX_MM;
    IEC_REAL HARD_MIN_HZ;
    IEC_REAL HARD_MAX_HZ;
    FB_PUMP PUMP1;
    FB_PUMP PUMP2;
    FB_PUMP PUMP3;
    FB_DUTY_SELECT DUTY;
    FB_LEVEL_CTRL LVLCTL;
    FB_HEADROOM HEAD;
    IEC_INT V_MODE;
    IEC_INT V_SPLEVEL;
    IEC_INT V_STARTDUTY;
    IEC_INT V_STARTP2;
    IEC_INT V_STARTP3;
    IEC_INT V_STOPALL;
    IEC_INT V_HIGHALARM;
    IEC_INT V_MINSPEED;
    IEC_INT V_SERVICEHRS;
    IEC_BOOL SPREJECTED;
    IEC_BOOL SPOK;
    IEC_BOOL CMDBUSY;
    Array1D<IEC_BOOL, 1, 3> RESETTRIP;
    Array1D<IEC_BOOL, 1, 3> RESETHOURS;
    Array1D<IEC_BOOL, 1, 3> LOCKOUT;
    IEC_BOOL ACKALARMS;
    IEC_INT P;
    IEC_INT PUMPSREQUIRED;
    IEC_INT PUMPSALLOWED;
    TON STAGGERTMR;
    IEC_BOOL STAGGERARM;
    IEC_BOOL DRYRUN;
    IEC_BOOL DRYLOCKOUT;
    IEC_BOOL LEVELRANGEFAULT;
    IEC_BOOL LEVELFROZEN;
    IEC_BOOL LEVELFAULT;
    IEC_INT LEVELREF;
    IEC_BOOL LEVELMOVED;
    TON FROZENTMR;
    IEC_BOOL ANYRUNNING;
    Array1D<IEC_BOOL, 1, 3> AVAIL;
    Array1D<IEC_REAL, 1, 3> HOURS;
    Array1D<IEC_BOOL, 1, 3> SVCDUE;
    Array1D<IEC_BOOL, 1, 3> RUNNOW;
    Array1D<IEC_BOOL, 1, 3> REQ;
    IEC_REAL SPEED;
    IEC_REAL MINSPEEDHZ;
    IEC_REAL SPLEVEL_M;
    IEC_BOOL HIGHLEVEL;
    IEC_INT PUMPSRUN;
    IEC_DINT ALARM;
    IEC_INT I;
    IEC_REAL R;
    IEC_BOOL PRIMED;
    // External variables (pointers to shared globals)
    GlobalVar<IEC_INT>* G_LEVELRAW_MM = nullptr;
    GlobalVar<IEC_INT>* G_LEVEL_MM = nullptr;
    GlobalVar<IEC_REAL>* G_LEVEL_M = nullptr;
    GlobalVar<IEC_REAL>* G_INFLOW_LPS = nullptr;
    GlobalVar<IEC_REAL>* G_DISCH_LPS = nullptr;
    GlobalVar<Array1D<IEC_REAL, 1, 3>>* G_PUMPP_KPA = nullptr;
    GlobalVar<Array1D<IEC_REAL, 1, 3>>* G_VIB_MMS = nullptr;
    GlobalVar<IEC_BOOL>* G_LSHH = nullptr;
    GlobalVar<IEC_BOOL>* G_LSLL_WET = nullptr;
    GlobalVar<IEC_BOOL>* G_SPILLDETECTED = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_THERMALOK = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SEALLEAK = nullptr;
    GlobalVar<IEC_BOOL>* G_MAINSOK = nullptr;
    GlobalVar<IEC_INT>* G_CMD_MODE = nullptr;
    GlobalVar<IEC_INT>* G_CMD_WORD = nullptr;
    GlobalVar<IEC_INT>* G_CMD_PARAM = nullptr;
    GlobalVar<IEC_INT>* G_SP_LEVEL = nullptr;
    GlobalVar<IEC_INT>* G_SP_STARTDUTY = nullptr;
    GlobalVar<IEC_INT>* G_SP_STARTP2 = nullptr;
    GlobalVar<IEC_INT>* G_SP_STARTP3 = nullptr;
    GlobalVar<IEC_INT>* G_SP_STOPALL = nullptr;
    GlobalVar<IEC_INT>* G_SP_HIGHALARM = nullptr;
    GlobalVar<IEC_INT>* G_SP_MINSPEED = nullptr;
    GlobalVar<IEC_INT>* G_SP_SERVICEHRS = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_RUNCMD = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_RUNNING = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_AVAILABLE = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_TRIPPED = nullptr;
    GlobalVar<IEC_BOOL>* G_O_INAUTO = nullptr;
    GlobalVar<IEC_BOOL>* G_O_HIGHLEVEL = nullptr;
    GlobalVar<IEC_BOOL>* G_O_SPILLACTIVE = nullptr;
    GlobalVar<IEC_INT>* G_O_LEVEL_MM = nullptr;
    GlobalVar<IEC_INT>* G_O_INFLOW_X10 = nullptr;
    GlobalVar<IEC_INT>* G_O_DISCH_X10 = nullptr;
    GlobalVar<IEC_INT>* G_O_PUMPSRUN = nullptr;
    GlobalVar<IEC_INT>* G_O_SPEED_X10 = nullptr;
    GlobalVar<IEC_INT>* G_O_TIMETOSPILL = nullptr;
    GlobalVar<IEC_INT>* G_O_TIMETOLSHH = nullptr;
    GlobalVar<IEC_INT>* G_O_NETACCUM = nullptr;
    GlobalVar<Array1D<IEC_INT, 1, 3>>* G_O_RUNHOURS = nullptr;
    GlobalVar<IEC_INT>* G_O_VOLTOSPILL = nullptr;
    GlobalVar<IEC_INT>* G_O_STATIONSTATE = nullptr;
    GlobalVar<Array1D<IEC_INT, 1, 3>>* G_O_PUMPSTATE = nullptr;
    GlobalVar<IEC_INT>* G_O_DUTYPUMP = nullptr;
    GlobalVar<IEC_INT>* G_O_ALARMWORD = nullptr;
    GlobalVar<IEC_INT>* G_O_CMDACK = nullptr;

    // Implicit IEC 61131-3 ENO pin (mirrors EN)
    IEC_BOOL ENO = true;

    // Constructor
    explicit Program_CONTROL(GlobalVar<IEC_INT>* G_LEVELRAW_MM_ref, GlobalVar<IEC_INT>* G_LEVEL_MM_ref, GlobalVar<IEC_REAL>* G_LEVEL_M_ref, GlobalVar<IEC_REAL>* G_INFLOW_LPS_ref, GlobalVar<IEC_REAL>* G_DISCH_LPS_ref, GlobalVar<Array1D<IEC_REAL, 1, 3>>* G_PUMPP_KPA_ref, GlobalVar<Array1D<IEC_REAL, 1, 3>>* G_VIB_MMS_ref, GlobalVar<IEC_BOOL>* G_LSHH_ref, GlobalVar<IEC_BOOL>* G_LSLL_WET_ref, GlobalVar<IEC_BOOL>* G_SPILLDETECTED_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_THERMALOK_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SEALLEAK_ref, GlobalVar<IEC_BOOL>* G_MAINSOK_ref, GlobalVar<IEC_INT>* G_CMD_MODE_ref, GlobalVar<IEC_INT>* G_CMD_WORD_ref, GlobalVar<IEC_INT>* G_CMD_PARAM_ref, GlobalVar<IEC_INT>* G_SP_LEVEL_ref, GlobalVar<IEC_INT>* G_SP_STARTDUTY_ref, GlobalVar<IEC_INT>* G_SP_STARTP2_ref, GlobalVar<IEC_INT>* G_SP_STARTP3_ref, GlobalVar<IEC_INT>* G_SP_STOPALL_ref, GlobalVar<IEC_INT>* G_SP_HIGHALARM_ref, GlobalVar<IEC_INT>* G_SP_MINSPEED_ref, GlobalVar<IEC_INT>* G_SP_SERVICEHRS_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_RUNCMD_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_RUNNING_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_AVAILABLE_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_TRIPPED_ref, GlobalVar<IEC_BOOL>* G_O_INAUTO_ref, GlobalVar<IEC_BOOL>* G_O_HIGHLEVEL_ref, GlobalVar<IEC_BOOL>* G_O_SPILLACTIVE_ref, GlobalVar<IEC_INT>* G_O_LEVEL_MM_ref, GlobalVar<IEC_INT>* G_O_INFLOW_X10_ref, GlobalVar<IEC_INT>* G_O_DISCH_X10_ref, GlobalVar<IEC_INT>* G_O_PUMPSRUN_ref, GlobalVar<IEC_INT>* G_O_SPEED_X10_ref, GlobalVar<IEC_INT>* G_O_TIMETOSPILL_ref, GlobalVar<IEC_INT>* G_O_TIMETOLSHH_ref, GlobalVar<IEC_INT>* G_O_NETACCUM_ref, GlobalVar<Array1D<IEC_INT, 1, 3>>* G_O_RUNHOURS_ref, GlobalVar<IEC_INT>* G_O_VOLTOSPILL_ref, GlobalVar<IEC_INT>* G_O_STATIONSTATE_ref, GlobalVar<Array1D<IEC_INT, 1, 3>>* G_O_PUMPSTATE_ref, GlobalVar<IEC_INT>* G_O_DUTYPUMP_ref, GlobalVar<IEC_INT>* G_O_ALARMWORD_ref, GlobalVar<IEC_INT>* G_O_CMDACK_ref);

    // Run program
    void run() override;
};

class Program_SIMULATION : public ProgramBase {
public:
    // Local variables
    IEC_REAL SCAN_S;
    IEC_REAL AREA_M2;
    IEC_REAL SPILL_M;
    IEC_REAL LSHH_M;
    IEC_REAL LSLL_M;
    IEC_REAL START_DLY_S;
    IEC_REAL HZ_LO;
    IEC_REAL HZ_HI;
    IEC_REAL Q_LO;
    IEC_REAL Q_HI;
    IEC_REAL P_IDLE;
    IEC_REAL P_BASE;
    IEC_REAL P_PER_LPS;
    IEC_REAL VIB_IDLE;
    IEC_REAL VIB_BASE;
    IEC_REAL VIB_PER_LPS;
    IEC_BOOL INIT;
    IEC_REAL VOLUME_M3;
    IEC_REAL LEVEL_M;
    IEC_REAL INFLOW_LPS;
    IEC_REAL SUMFLOW_LPS;
    IEC_REAL SIMCLOCK_S;
    Array1D<IEC_REAL, 1, 3> STARTDLY_S;
    Array1D<IEC_BOOL, 1, 3> DELIVERING;
    Array1D<IEC_REAL, 1, 3> FLOW_LPS;
    Array1D<IEC_REAL, 1, 3> PRESS_KPA;
    Array1D<IEC_REAL, 1, 3> VIB_MMS;
    IEC_REAL TIMESCALE;
    IEC_REAL DT_S;
    IEC_REAL SPEED_HZ;
    IEC_REAL UNITQ_LPS;
    IEC_REAL DERATE;
    IEC_INT NDELIVERING;
    IEC_INT I;
    IEC_DINT RND;
    IEC_REAL NOISE;
    // External variables (pointers to shared globals)
    GlobalVar<IEC_INT>* G_SIMCMD_INFLOW = nullptr;
    GlobalVar<IEC_INT>* G_SIMCMD_MODE = nullptr;
    GlobalVar<IEC_INT>* G_SIMCMD_RESET = nullptr;
    GlobalVar<IEC_INT>* G_SIMCMD_TIMESCALE = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_RUNCMD = nullptr;
    GlobalVar<IEC_INT>* G_O_SPEED_X10 = nullptr;
    GlobalVar<IEC_BOOL>* G_SIMACTIVE = nullptr;
    GlobalVar<IEC_BOOL>* G_SIM_CLEARRESET = nullptr;
    GlobalVar<IEC_INT>* G_SIM_LEVEL_MM = nullptr;
    GlobalVar<IEC_INT>* G_SIM_INFLOW_X10 = nullptr;
    GlobalVar<IEC_INT>* G_SIM_DISCH_X10 = nullptr;
    GlobalVar<IEC_INT>* G_SIM_MANIFOLDP = nullptr;
    GlobalVar<Array1D<IEC_INT, 1, 3>>* G_SIM_PUMPP = nullptr;
    GlobalVar<Array1D<IEC_INT, 1, 3>>* G_SIM_VIB_X10 = nullptr;
    GlobalVar<IEC_BOOL>* G_SIM_LSHH = nullptr;
    GlobalVar<IEC_BOOL>* G_SIM_LSLL_WET = nullptr;
    GlobalVar<IEC_BOOL>* G_SIM_SPILL = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SIM_THERMALOK = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SIM_SEALLEAK = nullptr;
    GlobalVar<IEC_BOOL>* G_SIM_MAINSOK = nullptr;

    // Implicit IEC 61131-3 ENO pin (mirrors EN)
    IEC_BOOL ENO = true;

    // Constructor
    explicit Program_SIMULATION(GlobalVar<IEC_INT>* G_SIMCMD_INFLOW_ref, GlobalVar<IEC_INT>* G_SIMCMD_MODE_ref, GlobalVar<IEC_INT>* G_SIMCMD_RESET_ref, GlobalVar<IEC_INT>* G_SIMCMD_TIMESCALE_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_RUNCMD_ref, GlobalVar<IEC_INT>* G_O_SPEED_X10_ref, GlobalVar<IEC_BOOL>* G_SIMACTIVE_ref, GlobalVar<IEC_BOOL>* G_SIM_CLEARRESET_ref, GlobalVar<IEC_INT>* G_SIM_LEVEL_MM_ref, GlobalVar<IEC_INT>* G_SIM_INFLOW_X10_ref, GlobalVar<IEC_INT>* G_SIM_DISCH_X10_ref, GlobalVar<IEC_INT>* G_SIM_MANIFOLDP_ref, GlobalVar<Array1D<IEC_INT, 1, 3>>* G_SIM_PUMPP_ref, GlobalVar<Array1D<IEC_INT, 1, 3>>* G_SIM_VIB_X10_ref, GlobalVar<IEC_BOOL>* G_SIM_LSHH_ref, GlobalVar<IEC_BOOL>* G_SIM_LSLL_WET_ref, GlobalVar<IEC_BOOL>* G_SIM_SPILL_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SIM_THERMALOK_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SIM_SEALLEAK_ref, GlobalVar<IEC_BOOL>* G_SIM_MAINSOK_ref);

    // Run program
    void run() override;
};

class Program_IO_MUX : public ProgramBase {
public:
    // Local variables
    IEC_BOOL SEEDED;
    // External variables (pointers to shared globals)
    GlobalVar<IEC_INT>* IW_LIT101 = nullptr;
    GlobalVar<IEC_INT>* IW_FIT201 = nullptr;
    GlobalVar<IEC_INT>* IW_FIT301 = nullptr;
    GlobalVar<IEC_INT>* IW_PIT302 = nullptr;
    GlobalVar<IEC_INT>* IW_PIT311 = nullptr;
    GlobalVar<IEC_INT>* IW_PIT321 = nullptr;
    GlobalVar<IEC_INT>* IW_PIT331 = nullptr;
    GlobalVar<IEC_INT>* IW_VE314 = nullptr;
    GlobalVar<IEC_INT>* IW_VE324 = nullptr;
    GlobalVar<IEC_INT>* IW_VE334 = nullptr;
    GlobalVar<IEC_BOOL>* IX_LSHH102 = nullptr;
    GlobalVar<IEC_BOOL>* IX_LSLL103 = nullptr;
    GlobalVar<IEC_BOOL>* IX_LSH104 = nullptr;
    GlobalVar<IEC_BOOL>* IX_TE312 = nullptr;
    GlobalVar<IEC_BOOL>* IX_TE322 = nullptr;
    GlobalVar<IEC_BOOL>* IX_TE332 = nullptr;
    GlobalVar<IEC_BOOL>* IX_MSE313 = nullptr;
    GlobalVar<IEC_BOOL>* IX_MSE323 = nullptr;
    GlobalVar<IEC_BOOL>* IX_MSE333 = nullptr;
    GlobalVar<IEC_BOOL>* IX_XA502 = nullptr;
    GlobalVar<IEC_BOOL>* QX_RUNCMD1 = nullptr;
    GlobalVar<IEC_BOOL>* QX_RUNCMD2 = nullptr;
    GlobalVar<IEC_BOOL>* QX_RUNCMD3 = nullptr;
    GlobalVar<IEC_BOOL>* QX_RUNNING1 = nullptr;
    GlobalVar<IEC_BOOL>* QX_RUNNING2 = nullptr;
    GlobalVar<IEC_BOOL>* QX_RUNNING3 = nullptr;
    GlobalVar<IEC_BOOL>* QX_AVAIL1 = nullptr;
    GlobalVar<IEC_BOOL>* QX_AVAIL2 = nullptr;
    GlobalVar<IEC_BOOL>* QX_AVAIL3 = nullptr;
    GlobalVar<IEC_BOOL>* QX_INAUTO = nullptr;
    GlobalVar<IEC_BOOL>* QX_HIGHLEVEL = nullptr;
    GlobalVar<IEC_BOOL>* QX_SPILLACTIVE = nullptr;
    GlobalVar<IEC_BOOL>* QX_TRIPPED1 = nullptr;
    GlobalVar<IEC_BOOL>* QX_TRIPPED2 = nullptr;
    GlobalVar<IEC_BOOL>* QX_TRIPPED3 = nullptr;
    GlobalVar<IEC_INT>* QW_LEVEL = nullptr;
    GlobalVar<IEC_INT>* QW_INFLOW = nullptr;
    GlobalVar<IEC_INT>* QW_DISCHARGE = nullptr;
    GlobalVar<IEC_INT>* QW_PUMPSRUNNING = nullptr;
    GlobalVar<IEC_INT>* QW_SPEED = nullptr;
    GlobalVar<IEC_INT>* QW_TIMETOSPILL = nullptr;
    GlobalVar<IEC_INT>* QW_TIMETOLSHH = nullptr;
    GlobalVar<IEC_INT>* QW_NETACCUM = nullptr;
    GlobalVar<IEC_INT>* QW_RUNHOURS1 = nullptr;
    GlobalVar<IEC_INT>* QW_RUNHOURS2 = nullptr;
    GlobalVar<IEC_INT>* QW_RUNHOURS3 = nullptr;
    GlobalVar<IEC_INT>* QW_VOLTOSPILL = nullptr;
    GlobalVar<IEC_INT>* QW_STATIONSTATE = nullptr;
    GlobalVar<IEC_INT>* QW_PUMPSTATE1 = nullptr;
    GlobalVar<IEC_INT>* QW_PUMPSTATE2 = nullptr;
    GlobalVar<IEC_INT>* QW_PUMPSTATE3 = nullptr;
    GlobalVar<IEC_INT>* QW_DUTYPUMP = nullptr;
    GlobalVar<IEC_INT>* QW_ALARMWORD = nullptr;
    GlobalVar<IEC_INT>* QW_CMDACK = nullptr;
    GlobalVar<IEC_INT>* MW_MODE = nullptr;
    GlobalVar<IEC_INT>* MW_CMDWORD = nullptr;
    GlobalVar<IEC_INT>* MW_CMDPARAM = nullptr;
    GlobalVar<IEC_INT>* MW_SPLEVEL = nullptr;
    GlobalVar<IEC_INT>* MW_STARTDUTY = nullptr;
    GlobalVar<IEC_INT>* MW_STARTP2 = nullptr;
    GlobalVar<IEC_INT>* MW_STARTP3 = nullptr;
    GlobalVar<IEC_INT>* MW_STOPALL = nullptr;
    GlobalVar<IEC_INT>* MW_HIGHALARM = nullptr;
    GlobalVar<IEC_INT>* MW_MINSPEED = nullptr;
    GlobalVar<IEC_INT>* MW_SERVICEHRS = nullptr;
    GlobalVar<IEC_INT>* MW_SIMINFLOW = nullptr;
    GlobalVar<IEC_INT>* MW_SIMMODE = nullptr;
    GlobalVar<IEC_INT>* MW_SIMRESET = nullptr;
    GlobalVar<IEC_INT>* MW_SIMTIMESCALE = nullptr;
    GlobalVar<IEC_INT>* G_LEVELRAW_MM = nullptr;
    GlobalVar<IEC_INT>* G_LEVEL_MM = nullptr;
    GlobalVar<IEC_REAL>* G_LEVEL_M = nullptr;
    GlobalVar<IEC_REAL>* G_INFLOW_LPS = nullptr;
    GlobalVar<IEC_REAL>* G_DISCH_LPS = nullptr;
    GlobalVar<IEC_REAL>* G_MANIFOLDP_KPA = nullptr;
    GlobalVar<Array1D<IEC_REAL, 1, 3>>* G_PUMPP_KPA = nullptr;
    GlobalVar<Array1D<IEC_REAL, 1, 3>>* G_VIB_MMS = nullptr;
    GlobalVar<IEC_BOOL>* G_LSHH = nullptr;
    GlobalVar<IEC_BOOL>* G_LSLL_WET = nullptr;
    GlobalVar<IEC_BOOL>* G_SPILLDETECTED = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_THERMALOK = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SEALLEAK = nullptr;
    GlobalVar<IEC_BOOL>* G_MAINSOK = nullptr;
    GlobalVar<IEC_INT>* G_CMD_MODE = nullptr;
    GlobalVar<IEC_INT>* G_CMD_WORD = nullptr;
    GlobalVar<IEC_INT>* G_CMD_PARAM = nullptr;
    GlobalVar<IEC_INT>* G_SP_LEVEL = nullptr;
    GlobalVar<IEC_INT>* G_SP_STARTDUTY = nullptr;
    GlobalVar<IEC_INT>* G_SP_STARTP2 = nullptr;
    GlobalVar<IEC_INT>* G_SP_STARTP3 = nullptr;
    GlobalVar<IEC_INT>* G_SP_STOPALL = nullptr;
    GlobalVar<IEC_INT>* G_SP_HIGHALARM = nullptr;
    GlobalVar<IEC_INT>* G_SP_MINSPEED = nullptr;
    GlobalVar<IEC_INT>* G_SP_SERVICEHRS = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_RUNCMD = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_RUNNING = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_AVAILABLE = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_TRIPPED = nullptr;
    GlobalVar<IEC_BOOL>* G_O_INAUTO = nullptr;
    GlobalVar<IEC_BOOL>* G_O_HIGHLEVEL = nullptr;
    GlobalVar<IEC_BOOL>* G_O_SPILLACTIVE = nullptr;
    GlobalVar<IEC_INT>* G_O_LEVEL_MM = nullptr;
    GlobalVar<IEC_INT>* G_O_INFLOW_X10 = nullptr;
    GlobalVar<IEC_INT>* G_O_DISCH_X10 = nullptr;
    GlobalVar<IEC_INT>* G_O_PUMPSRUN = nullptr;
    GlobalVar<IEC_INT>* G_O_SPEED_X10 = nullptr;
    GlobalVar<IEC_INT>* G_O_TIMETOSPILL = nullptr;
    GlobalVar<IEC_INT>* G_O_TIMETOLSHH = nullptr;
    GlobalVar<IEC_INT>* G_O_NETACCUM = nullptr;
    GlobalVar<Array1D<IEC_INT, 1, 3>>* G_O_RUNHOURS = nullptr;
    GlobalVar<IEC_INT>* G_O_VOLTOSPILL = nullptr;
    GlobalVar<IEC_INT>* G_O_STATIONSTATE = nullptr;
    GlobalVar<Array1D<IEC_INT, 1, 3>>* G_O_PUMPSTATE = nullptr;
    GlobalVar<IEC_INT>* G_O_DUTYPUMP = nullptr;
    GlobalVar<IEC_INT>* G_O_ALARMWORD = nullptr;
    GlobalVar<IEC_INT>* G_O_CMDACK = nullptr;
    GlobalVar<IEC_INT>* DEF_MODE = nullptr;
    GlobalVar<IEC_INT>* DEF_SP_LEVEL = nullptr;
    GlobalVar<IEC_INT>* DEF_START_DUTY = nullptr;
    GlobalVar<IEC_INT>* DEF_START_P2 = nullptr;
    GlobalVar<IEC_INT>* DEF_START_P3 = nullptr;
    GlobalVar<IEC_INT>* DEF_STOP_ALL = nullptr;
    GlobalVar<IEC_INT>* DEF_HIGH_ALARM = nullptr;
    GlobalVar<IEC_INT>* DEF_MIN_SPEED = nullptr;
    GlobalVar<IEC_INT>* DEF_SERVICE_HRS = nullptr;
    GlobalVar<IEC_BOOL>* G_SIMACTIVE = nullptr;
    GlobalVar<IEC_BOOL>* G_SIM_CLEARRESET = nullptr;
    GlobalVar<IEC_INT>* G_SIMCMD_INFLOW = nullptr;
    GlobalVar<IEC_INT>* G_SIMCMD_MODE = nullptr;
    GlobalVar<IEC_INT>* G_SIMCMD_RESET = nullptr;
    GlobalVar<IEC_INT>* G_SIMCMD_TIMESCALE = nullptr;
    GlobalVar<IEC_INT>* G_SIM_LEVEL_MM = nullptr;
    GlobalVar<IEC_INT>* G_SIM_INFLOW_X10 = nullptr;
    GlobalVar<IEC_INT>* G_SIM_DISCH_X10 = nullptr;
    GlobalVar<IEC_INT>* G_SIM_MANIFOLDP = nullptr;
    GlobalVar<Array1D<IEC_INT, 1, 3>>* G_SIM_PUMPP = nullptr;
    GlobalVar<Array1D<IEC_INT, 1, 3>>* G_SIM_VIB_X10 = nullptr;
    GlobalVar<IEC_BOOL>* G_SIM_LSHH = nullptr;
    GlobalVar<IEC_BOOL>* G_SIM_LSLL_WET = nullptr;
    GlobalVar<IEC_BOOL>* G_SIM_SPILL = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SIM_THERMALOK = nullptr;
    GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SIM_SEALLEAK = nullptr;
    GlobalVar<IEC_BOOL>* G_SIM_MAINSOK = nullptr;

    // Implicit IEC 61131-3 ENO pin (mirrors EN)
    IEC_BOOL ENO = true;

    // Constructor
    explicit Program_IO_MUX(GlobalVar<IEC_INT>* IW_LIT101_ref, GlobalVar<IEC_INT>* IW_FIT201_ref, GlobalVar<IEC_INT>* IW_FIT301_ref, GlobalVar<IEC_INT>* IW_PIT302_ref, GlobalVar<IEC_INT>* IW_PIT311_ref, GlobalVar<IEC_INT>* IW_PIT321_ref, GlobalVar<IEC_INT>* IW_PIT331_ref, GlobalVar<IEC_INT>* IW_VE314_ref, GlobalVar<IEC_INT>* IW_VE324_ref, GlobalVar<IEC_INT>* IW_VE334_ref, GlobalVar<IEC_BOOL>* IX_LSHH102_ref, GlobalVar<IEC_BOOL>* IX_LSLL103_ref, GlobalVar<IEC_BOOL>* IX_LSH104_ref, GlobalVar<IEC_BOOL>* IX_TE312_ref, GlobalVar<IEC_BOOL>* IX_TE322_ref, GlobalVar<IEC_BOOL>* IX_TE332_ref, GlobalVar<IEC_BOOL>* IX_MSE313_ref, GlobalVar<IEC_BOOL>* IX_MSE323_ref, GlobalVar<IEC_BOOL>* IX_MSE333_ref, GlobalVar<IEC_BOOL>* IX_XA502_ref, GlobalVar<IEC_BOOL>* QX_RUNCMD1_ref, GlobalVar<IEC_BOOL>* QX_RUNCMD2_ref, GlobalVar<IEC_BOOL>* QX_RUNCMD3_ref, GlobalVar<IEC_BOOL>* QX_RUNNING1_ref, GlobalVar<IEC_BOOL>* QX_RUNNING2_ref, GlobalVar<IEC_BOOL>* QX_RUNNING3_ref, GlobalVar<IEC_BOOL>* QX_AVAIL1_ref, GlobalVar<IEC_BOOL>* QX_AVAIL2_ref, GlobalVar<IEC_BOOL>* QX_AVAIL3_ref, GlobalVar<IEC_BOOL>* QX_INAUTO_ref, GlobalVar<IEC_BOOL>* QX_HIGHLEVEL_ref, GlobalVar<IEC_BOOL>* QX_SPILLACTIVE_ref, GlobalVar<IEC_BOOL>* QX_TRIPPED1_ref, GlobalVar<IEC_BOOL>* QX_TRIPPED2_ref, GlobalVar<IEC_BOOL>* QX_TRIPPED3_ref, GlobalVar<IEC_INT>* QW_LEVEL_ref, GlobalVar<IEC_INT>* QW_INFLOW_ref, GlobalVar<IEC_INT>* QW_DISCHARGE_ref, GlobalVar<IEC_INT>* QW_PUMPSRUNNING_ref, GlobalVar<IEC_INT>* QW_SPEED_ref, GlobalVar<IEC_INT>* QW_TIMETOSPILL_ref, GlobalVar<IEC_INT>* QW_TIMETOLSHH_ref, GlobalVar<IEC_INT>* QW_NETACCUM_ref, GlobalVar<IEC_INT>* QW_RUNHOURS1_ref, GlobalVar<IEC_INT>* QW_RUNHOURS2_ref, GlobalVar<IEC_INT>* QW_RUNHOURS3_ref, GlobalVar<IEC_INT>* QW_VOLTOSPILL_ref, GlobalVar<IEC_INT>* QW_STATIONSTATE_ref, GlobalVar<IEC_INT>* QW_PUMPSTATE1_ref, GlobalVar<IEC_INT>* QW_PUMPSTATE2_ref, GlobalVar<IEC_INT>* QW_PUMPSTATE3_ref, GlobalVar<IEC_INT>* QW_DUTYPUMP_ref, GlobalVar<IEC_INT>* QW_ALARMWORD_ref, GlobalVar<IEC_INT>* QW_CMDACK_ref, GlobalVar<IEC_INT>* MW_MODE_ref, GlobalVar<IEC_INT>* MW_CMDWORD_ref, GlobalVar<IEC_INT>* MW_CMDPARAM_ref, GlobalVar<IEC_INT>* MW_SPLEVEL_ref, GlobalVar<IEC_INT>* MW_STARTDUTY_ref, GlobalVar<IEC_INT>* MW_STARTP2_ref, GlobalVar<IEC_INT>* MW_STARTP3_ref, GlobalVar<IEC_INT>* MW_STOPALL_ref, GlobalVar<IEC_INT>* MW_HIGHALARM_ref, GlobalVar<IEC_INT>* MW_MINSPEED_ref, GlobalVar<IEC_INT>* MW_SERVICEHRS_ref, GlobalVar<IEC_INT>* MW_SIMINFLOW_ref, GlobalVar<IEC_INT>* MW_SIMMODE_ref, GlobalVar<IEC_INT>* MW_SIMRESET_ref, GlobalVar<IEC_INT>* MW_SIMTIMESCALE_ref, GlobalVar<IEC_INT>* G_LEVELRAW_MM_ref, GlobalVar<IEC_INT>* G_LEVEL_MM_ref, GlobalVar<IEC_REAL>* G_LEVEL_M_ref, GlobalVar<IEC_REAL>* G_INFLOW_LPS_ref, GlobalVar<IEC_REAL>* G_DISCH_LPS_ref, GlobalVar<IEC_REAL>* G_MANIFOLDP_KPA_ref, GlobalVar<Array1D<IEC_REAL, 1, 3>>* G_PUMPP_KPA_ref, GlobalVar<Array1D<IEC_REAL, 1, 3>>* G_VIB_MMS_ref, GlobalVar<IEC_BOOL>* G_LSHH_ref, GlobalVar<IEC_BOOL>* G_LSLL_WET_ref, GlobalVar<IEC_BOOL>* G_SPILLDETECTED_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_THERMALOK_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SEALLEAK_ref, GlobalVar<IEC_BOOL>* G_MAINSOK_ref, GlobalVar<IEC_INT>* G_CMD_MODE_ref, GlobalVar<IEC_INT>* G_CMD_WORD_ref, GlobalVar<IEC_INT>* G_CMD_PARAM_ref, GlobalVar<IEC_INT>* G_SP_LEVEL_ref, GlobalVar<IEC_INT>* G_SP_STARTDUTY_ref, GlobalVar<IEC_INT>* G_SP_STARTP2_ref, GlobalVar<IEC_INT>* G_SP_STARTP3_ref, GlobalVar<IEC_INT>* G_SP_STOPALL_ref, GlobalVar<IEC_INT>* G_SP_HIGHALARM_ref, GlobalVar<IEC_INT>* G_SP_MINSPEED_ref, GlobalVar<IEC_INT>* G_SP_SERVICEHRS_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_RUNCMD_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_RUNNING_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_AVAILABLE_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_O_TRIPPED_ref, GlobalVar<IEC_BOOL>* G_O_INAUTO_ref, GlobalVar<IEC_BOOL>* G_O_HIGHLEVEL_ref, GlobalVar<IEC_BOOL>* G_O_SPILLACTIVE_ref, GlobalVar<IEC_INT>* G_O_LEVEL_MM_ref, GlobalVar<IEC_INT>* G_O_INFLOW_X10_ref, GlobalVar<IEC_INT>* G_O_DISCH_X10_ref, GlobalVar<IEC_INT>* G_O_PUMPSRUN_ref, GlobalVar<IEC_INT>* G_O_SPEED_X10_ref, GlobalVar<IEC_INT>* G_O_TIMETOSPILL_ref, GlobalVar<IEC_INT>* G_O_TIMETOLSHH_ref, GlobalVar<IEC_INT>* G_O_NETACCUM_ref, GlobalVar<Array1D<IEC_INT, 1, 3>>* G_O_RUNHOURS_ref, GlobalVar<IEC_INT>* G_O_VOLTOSPILL_ref, GlobalVar<IEC_INT>* G_O_STATIONSTATE_ref, GlobalVar<Array1D<IEC_INT, 1, 3>>* G_O_PUMPSTATE_ref, GlobalVar<IEC_INT>* G_O_DUTYPUMP_ref, GlobalVar<IEC_INT>* G_O_ALARMWORD_ref, GlobalVar<IEC_INT>* G_O_CMDACK_ref, GlobalVar<IEC_INT>* DEF_MODE_ref, GlobalVar<IEC_INT>* DEF_SP_LEVEL_ref, GlobalVar<IEC_INT>* DEF_START_DUTY_ref, GlobalVar<IEC_INT>* DEF_START_P2_ref, GlobalVar<IEC_INT>* DEF_START_P3_ref, GlobalVar<IEC_INT>* DEF_STOP_ALL_ref, GlobalVar<IEC_INT>* DEF_HIGH_ALARM_ref, GlobalVar<IEC_INT>* DEF_MIN_SPEED_ref, GlobalVar<IEC_INT>* DEF_SERVICE_HRS_ref, GlobalVar<IEC_BOOL>* G_SIMACTIVE_ref, GlobalVar<IEC_BOOL>* G_SIM_CLEARRESET_ref, GlobalVar<IEC_INT>* G_SIMCMD_INFLOW_ref, GlobalVar<IEC_INT>* G_SIMCMD_MODE_ref, GlobalVar<IEC_INT>* G_SIMCMD_RESET_ref, GlobalVar<IEC_INT>* G_SIMCMD_TIMESCALE_ref, GlobalVar<IEC_INT>* G_SIM_LEVEL_MM_ref, GlobalVar<IEC_INT>* G_SIM_INFLOW_X10_ref, GlobalVar<IEC_INT>* G_SIM_DISCH_X10_ref, GlobalVar<IEC_INT>* G_SIM_MANIFOLDP_ref, GlobalVar<Array1D<IEC_INT, 1, 3>>* G_SIM_PUMPP_ref, GlobalVar<Array1D<IEC_INT, 1, 3>>* G_SIM_VIB_X10_ref, GlobalVar<IEC_BOOL>* G_SIM_LSHH_ref, GlobalVar<IEC_BOOL>* G_SIM_LSLL_WET_ref, GlobalVar<IEC_BOOL>* G_SIM_SPILL_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SIM_THERMALOK_ref, GlobalVar<Array1D<IEC_BOOL, 1, 3>>* G_SIM_SEALLEAK_ref, GlobalVar<IEC_BOOL>* G_SIM_MAINSOK_ref);

    // Run program
    void run() override;
};

class Configuration_CONFIG0 : public ConfigurationInstance {
public:
    // Program instances
    Program_SIMULATION INST_SIM;
    Program_IO_MUX INST_MUX;
    Program_CONTROL INST_CTL;

    // Task storage
    TaskInstance tasks_storage[1];
    ProgramBase* task_programs_storage[3];
    // Resource storage
    ResourceInstance resources_storage[1];

    // Constructor
    Configuration_CONFIG0();

    // ConfigurationInstance interface
    const char* get_name() const override;
    ResourceInstance* get_resources() override;
    size_t get_resource_count() const override;
};

// =============================================================================
// Located Variables Descriptor Array
// =============================================================================

/**
 * Located variable descriptors for runtime I/O binding.
 * The runtime iterates this array to bind variables to I/O image tables.
 */

// Forward: IW_LIT101 AT %IW0 in configuration
// Forward: IW_FIT201 AT %IW1 in configuration
// Forward: IW_FIT301 AT %IW2 in configuration
// Forward: IW_PIT302 AT %IW3 in configuration
// Forward: IW_PIT311 AT %IW4 in configuration
// Forward: IW_PIT321 AT %IW5 in configuration
// Forward: IW_PIT331 AT %IW6 in configuration
// Forward: IW_VE314 AT %IW7 in configuration
// Forward: IW_VE324 AT %IW8 in configuration
// Forward: IW_VE334 AT %IW9 in configuration
// Forward: IX_LSHH102 AT %IX0.0 in configuration
// Forward: IX_LSLL103 AT %IX0.1 in configuration
// Forward: IX_LSH104 AT %IX0.2 in configuration
// Forward: IX_TE312 AT %IX0.3 in configuration
// Forward: IX_TE322 AT %IX0.4 in configuration
// Forward: IX_TE332 AT %IX0.5 in configuration
// Forward: IX_MSE313 AT %IX0.6 in configuration
// Forward: IX_MSE323 AT %IX0.7 in configuration
// Forward: IX_MSE333 AT %IX1.0 in configuration
// Forward: IX_XA502 AT %IX1.1 in configuration
// Forward: QX_RUNCMD1 AT %QX0.0 in configuration
// Forward: QX_RUNCMD2 AT %QX0.1 in configuration
// Forward: QX_RUNCMD3 AT %QX0.2 in configuration
// Forward: QX_RUNNING1 AT %QX0.3 in configuration
// Forward: QX_RUNNING2 AT %QX0.4 in configuration
// Forward: QX_RUNNING3 AT %QX0.5 in configuration
// Forward: QX_AVAIL1 AT %QX0.6 in configuration
// Forward: QX_AVAIL2 AT %QX0.7 in configuration
// Forward: QX_AVAIL3 AT %QX1.0 in configuration
// Forward: QX_INAUTO AT %QX1.1 in configuration
// Forward: QX_HIGHLEVEL AT %QX1.2 in configuration
// Forward: QX_SPILLACTIVE AT %QX1.3 in configuration
// Forward: QX_TRIPPED1 AT %QX1.4 in configuration
// Forward: QX_TRIPPED2 AT %QX1.5 in configuration
// Forward: QX_TRIPPED3 AT %QX1.6 in configuration
// Forward: QW_LEVEL AT %QW0 in configuration
// Forward: QW_INFLOW AT %QW1 in configuration
// Forward: QW_DISCHARGE AT %QW2 in configuration
// Forward: QW_PUMPSRUNNING AT %QW3 in configuration
// Forward: QW_SPEED AT %QW4 in configuration
// Forward: QW_TIMETOSPILL AT %QW5 in configuration
// Forward: QW_TIMETOLSHH AT %QW6 in configuration
// Forward: QW_NETACCUM AT %QW7 in configuration
// Forward: QW_RUNHOURS1 AT %QW8 in configuration
// Forward: QW_RUNHOURS2 AT %QW9 in configuration
// Forward: QW_RUNHOURS3 AT %QW10 in configuration
// Forward: QW_VOLTOSPILL AT %QW11 in configuration
// Forward: QW_STATIONSTATE AT %QW12 in configuration
// Forward: QW_PUMPSTATE1 AT %QW13 in configuration
// Forward: QW_PUMPSTATE2 AT %QW14 in configuration
// Forward: QW_PUMPSTATE3 AT %QW15 in configuration
// Forward: QW_DUTYPUMP AT %QW16 in configuration
// Forward: QW_ALARMWORD AT %QW17 in configuration
// Forward: QW_CMDACK AT %QW20 in configuration
// Forward: MW_MODE AT %MW0 in configuration
// Forward: MW_CMDWORD AT %MW1 in configuration
// Forward: MW_CMDPARAM AT %MW2 in configuration
// Forward: MW_SPLEVEL AT %MW3 in configuration
// Forward: MW_STARTDUTY AT %MW4 in configuration
// Forward: MW_STARTP2 AT %MW5 in configuration
// Forward: MW_STARTP3 AT %MW6 in configuration
// Forward: MW_STOPALL AT %MW7 in configuration
// Forward: MW_HIGHALARM AT %MW8 in configuration
// Forward: MW_MINSPEED AT %MW9 in configuration
// Forward: MW_SERVICEHRS AT %MW10 in configuration
// Forward: MW_SIMINFLOW AT %MW20 in configuration
// Forward: MW_SIMMODE AT %MW21 in configuration
// Forward: MW_SIMRESET AT %MW22 in configuration
// Forward: MW_SIMTIMESCALE AT %MW23 in configuration

extern LocatedVar locatedVars[69];
constexpr uint32_t locatedVarsCount = 69;

#ifdef STRUCPP_THREADED
extern void *locatedGlobals[69];
constexpr uint32_t locatedGlobalsCount = 69;
#endif

}  // namespace strucpp