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

#include "generated.hpp"

namespace strucpp {

Program_CONTROL::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)
    : SPILL_MM(6000), LEVEL_MAX_MM(7000), HARD_MIN_HZ(38.0), HARD_MAX_HZ(50.0), V_MODE(1), V_SPLEVEL(4200), V_STARTDUTY(4000), V_STARTP2(4500), V_STARTP3(5000), V_STOPALL(1000), V_HIGHALARM(5200), V_MINSPEED(380), V_SERVICEHRS(4000), SPREJECTED(false), SPOK(false), CMDBUSY(false), ACKALARMS(false), P(0), PUMPSREQUIRED(0), PUMPSALLOWED(0), STAGGERARM(false), DRYRUN(false), DRYLOCKOUT(false), LEVELRANGEFAULT(false), LEVELFROZEN(false), LEVELFAULT(false), LEVELREF(0), LEVELMOVED(false), ANYRUNNING(false), SPEED(0.0), MINSPEEDHZ(0.0), SPLEVEL_M(0.0), HIGHLEVEL(false), PUMPSRUN(0), ALARM(0), I(0), R(0.0), PRIMED(false), G_LEVELRAW_MM(G_LEVELRAW_MM_ref), G_LEVEL_MM(G_LEVEL_MM_ref), G_LEVEL_M(G_LEVEL_M_ref), G_INFLOW_LPS(G_INFLOW_LPS_ref), G_DISCH_LPS(G_DISCH_LPS_ref), G_PUMPP_KPA(G_PUMPP_KPA_ref), G_VIB_MMS(G_VIB_MMS_ref), G_LSHH(G_LSHH_ref), G_LSLL_WET(G_LSLL_WET_ref), G_SPILLDETECTED(G_SPILLDETECTED_ref), G_THERMALOK(G_THERMALOK_ref), G_SEALLEAK(G_SEALLEAK_ref), G_MAINSOK(G_MAINSOK_ref), G_CMD_MODE(G_CMD_MODE_ref), G_CMD_WORD(G_CMD_WORD_ref), G_CMD_PARAM(G_CMD_PARAM_ref), G_SP_LEVEL(G_SP_LEVEL_ref), G_SP_STARTDUTY(G_SP_STARTDUTY_ref), G_SP_STARTP2(G_SP_STARTP2_ref), G_SP_STARTP3(G_SP_STARTP3_ref), G_SP_STOPALL(G_SP_STOPALL_ref), G_SP_HIGHALARM(G_SP_HIGHALARM_ref), G_SP_MINSPEED(G_SP_MINSPEED_ref), G_SP_SERVICEHRS(G_SP_SERVICEHRS_ref), G_O_RUNCMD(G_O_RUNCMD_ref), G_O_RUNNING(G_O_RUNNING_ref), G_O_AVAILABLE(G_O_AVAILABLE_ref), G_O_TRIPPED(G_O_TRIPPED_ref), G_O_INAUTO(G_O_INAUTO_ref), G_O_HIGHLEVEL(G_O_HIGHLEVEL_ref), G_O_SPILLACTIVE(G_O_SPILLACTIVE_ref), G_O_LEVEL_MM(G_O_LEVEL_MM_ref), G_O_INFLOW_X10(G_O_INFLOW_X10_ref), G_O_DISCH_X10(G_O_DISCH_X10_ref), G_O_PUMPSRUN(G_O_PUMPSRUN_ref), G_O_SPEED_X10(G_O_SPEED_X10_ref), G_O_TIMETOSPILL(G_O_TIMETOSPILL_ref), G_O_TIMETOLSHH(G_O_TIMETOLSHH_ref), G_O_NETACCUM(G_O_NETACCUM_ref), G_O_RUNHOURS(G_O_RUNHOURS_ref), G_O_VOLTOSPILL(G_O_VOLTOSPILL_ref), G_O_STATIONSTATE(G_O_STATIONSTATE_ref), G_O_PUMPSTATE(G_O_PUMPSTATE_ref), G_O_DUTYPUMP(G_O_DUTYPUMP_ref), G_O_ALARMWORD(G_O_ALARMWORD_ref), G_O_CMDACK(G_O_CMDACK_ref)
{
}

void Program_CONTROL::run() {
    if (((G_CMD_MODE->read() == 1)) | ((G_CMD_MODE->read() == 2))) {
        V_MODE = G_CMD_MODE->read();
    } else {
        SPREJECTED = true;
    }
    SPOK = true;
    if (((G_SP_STOPALL->read() < 0)) | ((G_SP_STOPALL->read() >= G_SP_STARTDUTY->read()))) {
        SPOK = false;
    }
    if (((G_SP_STARTDUTY->read() >= G_SP_STARTP2->read())) | ((G_SP_STARTDUTY->read() >= SPILL_MM))) {
        SPOK = false;
    }
    if (((G_SP_STARTP2->read() >= G_SP_STARTP3->read())) | ((G_SP_STARTP2->read() >= SPILL_MM))) {
        SPOK = false;
    }
    if ((G_SP_STARTP3->read() >= SPILL_MM)) {
        SPOK = false;
    }
    if (((G_SP_LEVEL->read() <= G_SP_STOPALL->read())) | ((G_SP_LEVEL->read() >= SPILL_MM))) {
        SPOK = false;
    }
    if (((G_SP_HIGHALARM->read() <= 0)) | ((G_SP_HIGHALARM->read() > SPILL_MM))) {
        SPOK = false;
    }
    if (SPOK) {
        V_SPLEVEL = G_SP_LEVEL->read();
        V_STARTDUTY = G_SP_STARTDUTY->read();
        V_STARTP2 = G_SP_STARTP2->read();
        V_STARTP3 = G_SP_STARTP3->read();
        V_STOPALL = G_SP_STOPALL->read();
        V_HIGHALARM = G_SP_HIGHALARM->read();
    } else {
        SPREJECTED = true;
    }
    if (((G_SP_MINSPEED->read() >= 380)) & ((G_SP_MINSPEED->read() <= 500))) {
        V_MINSPEED = G_SP_MINSPEED->read();
    } else {
        SPREJECTED = true;
    }
    if (G_SP_SERVICEHRS->read() > 0) {
        V_SERVICEHRS = G_SP_SERVICEHRS->read();
    } else {
        SPREJECTED = true;
    }
    MINSPEEDHZ = TO_REAL(V_MINSPEED) / 10.0;
    if (MINSPEEDHZ < HARD_MIN_HZ) {
        MINSPEEDHZ = HARD_MIN_HZ;
    }
    SPLEVEL_M = TO_REAL(V_SPLEVEL) / 1000.0;
    for (I = 1; I <= 3; I++) {
        RESETTRIP.at(I) = false;
        RESETHOURS.at(I) = false;
    }
    ACKALARMS = false;
    if (((G_CMD_WORD->read() != 0)) & (!CMDBUSY)) {
        CMDBUSY = true;
        P = G_CMD_PARAM->read();
        switch (G_CMD_WORD->read()) {
            case 1:
                for (I = 1; I <= 3; I++) {
                    RESETTRIP.at(I) = true;
                }
                if (G_LEVEL_MM->read() > V_STOPALL) {
                    DRYLOCKOUT = false;
                }
                break;
            case 2:
                if (((P >= 1)) & ((P <= 3))) {
                    RESETTRIP.at(P) = true;
                }
                break;
            case 3:
                if (((P >= 1)) & ((P <= 3))) {
                    LOCKOUT.at(P) = true;
                }
                break;
            case 4:
                if (((P >= 1)) & ((P <= 3))) {
                    LOCKOUT.at(P) = false;
                }
                break;
            case 5:
                if (((P >= 1)) & ((P <= 3))) {
                    RESETHOURS.at(P) = true;
                }
                break;
            case 6:
                ACKALARMS = true;
                SPREJECTED = false;
                break;
        }
        G_O_CMDACK->write(G_CMD_WORD->read());
    } else if (G_CMD_WORD->read() == 0) {
        CMDBUSY = false;
        G_O_CMDACK->write(0);
    }
    LEVELRANGEFAULT = ((G_LEVELRAW_MM->read() < 0)) | ((G_LEVELRAW_MM->read() > LEVEL_MAX_MM));
    if (!PRIMED) {
        LEVELREF = G_LEVELRAW_MM->read();
        PRIMED = true;
    }
    if (ABS(G_LEVELRAW_MM->read() - LEVELREF) > 1) {
        LEVELREF = G_LEVELRAW_MM->read();
        LEVELMOVED = true;
    } else {
        LEVELMOVED = false;
    }
    ANYRUNNING = ((PUMP1.RUNNING) | (PUMP2.RUNNING)) | (PUMP3.RUNNING);
    FROZENTMR.IN = (ANYRUNNING) & (!LEVELMOVED);
    FROZENTMR.PT = 600000000000LL;
    FROZENTMR();
    FROZENTMR.ENO = true;
    LEVELFROZEN = FROZENTMR.Q;
    LEVELFAULT = (LEVELRANGEFAULT) | (LEVELFROZEN);
    if (!LEVELFAULT) {
        if (G_LEVEL_MM->read() >= V_STARTP3) {
            PUMPSREQUIRED = 3;
        } else if (G_LEVEL_MM->read() >= V_STARTP2) {
            PUMPSREQUIRED = 2;
        } else if (G_LEVEL_MM->read() >= V_STARTDUTY) {
            PUMPSREQUIRED = 1;
        } else if (G_LEVEL_MM->read() <= V_STOPALL) {
            PUMPSREQUIRED = 0;
        }
    } else {
        if (G_LSHH->read()) {
            PUMPSREQUIRED = 3;
        }
    }
    if (G_LSHH->read()) {
        PUMPSREQUIRED = 3;
    }
    DRYRUN = !G_LSLL_WET->read();
    if (DRYRUN) {
        PUMPSREQUIRED = 0;
        DRYLOCKOUT = true;
    }
    if (DRYLOCKOUT) {
        PUMPSREQUIRED = 0;
    }
    if (V_MODE == 2) {
        PUMPSREQUIRED = 0;
    }
    if (G_LSHH->read()) {
        PUMPSALLOWED = PUMPSREQUIRED;
        STAGGERARM = false;
    } else {
        STAGGERTMR.IN = STAGGERARM;
        STAGGERTMR.PT = 30000000000LL;
        STAGGERTMR();
        STAGGERTMR.ENO = true;
        if (PUMPSALLOWED < PUMPSREQUIRED) {
            if (PUMPSALLOWED == 0) {
                PUMPSALLOWED = 1;
                STAGGERARM = false;
            } else if (STAGGERTMR.Q) {
                PUMPSALLOWED = PUMPSALLOWED + 1;
                STAGGERARM = false;
            } else {
                STAGGERARM = true;
            }
        } else {
            if (PUMPSALLOWED > PUMPSREQUIRED) {
                PUMPSALLOWED = PUMPSREQUIRED;
            }
            STAGGERARM = false;
        }
    }
    AVAIL.at(1) = PUMP1.AVAILABLE;
    AVAIL.at(2) = PUMP2.AVAILABLE;
    AVAIL.at(3) = PUMP3.AVAILABLE;
    HOURS.at(1) = PUMP1.RUNHOURS;
    HOURS.at(2) = PUMP2.RUNHOURS;
    HOURS.at(3) = PUMP3.RUNHOURS;
    SVCDUE.at(1) = PUMP1.SERVICEDUE;
    SVCDUE.at(2) = PUMP2.SERVICEDUE;
    SVCDUE.at(3) = PUMP3.SERVICEDUE;
    RUNNOW.at(1) = PUMP1.RUNNING;
    RUNNOW.at(2) = PUMP2.RUNNING;
    RUNNOW.at(3) = PUMP3.RUNNING;
    DUTY.AVAILABLE = AVAIL;
    DUTY.RUNHOURS = HOURS;
    DUTY.SERVICEDUE = SVCDUE;
    DUTY.RUNNINGNOW = RUNNOW;
    DUTY.PUMPSREQUIRED = PUMPSALLOWED;
    DUTY();
    DUTY.ENO = true;
    REQ.at(1) = DUTY.RUNREQUEST.at(1);
    REQ.at(2) = DUTY.RUNREQUEST.at(2);
    REQ.at(3) = DUTY.RUNREQUEST.at(3);
    LVLCTL.LEVEL = G_LEVEL_M->read();
    LVLCTL.SETPOINT = SPLEVEL_M;
    LVLCTL.ENABLE = (PUMPSALLOWED > 0);
    LVLCTL.MINSPEED = MINSPEEDHZ;
    LVLCTL.MAXSPEED = HARD_MAX_HZ;
    LVLCTL();
    LVLCTL.ENO = true;
    SPEED = LVLCTL.SPEED;
    if (G_LSHH->read()) {
        SPEED = HARD_MAX_HZ;
    }
    PUMP1.RUNREQUEST = REQ.at(1);
    PUMP1.SPEEDREF = SPEED;
    PUMP1.THERMALOK = G_THERMALOK->with_lock([&](auto* __glk){ return (*__glk).at(1); });
    PUMP1.SEALLEAK = G_SEALLEAK->with_lock([&](auto* __glk){ return (*__glk).at(1); });
    PUMP1.VIBRATION = G_VIB_MMS->with_lock([&](auto* __glk){ return (*__glk).at(1); });
    PUMP1.DISCHPRESSURE = G_PUMPP_KPA->with_lock([&](auto* __glk){ return (*__glk).at(1); });
    PUMP1.RESETTRIP = RESETTRIP.at(1);
    PUMP1.LOCKOUT = LOCKOUT.at(1);
    PUMP1.MINOFFBYPASS = G_LSHH->read();
    PUMP1.SERVICEINTERVAL = TO_REAL(V_SERVICEHRS);
    PUMP1.RESETHOURS = RESETHOURS.at(1);
    PUMP1();
    PUMP1.ENO = true;
    PUMP2.RUNREQUEST = REQ.at(2);
    PUMP2.SPEEDREF = SPEED;
    PUMP2.THERMALOK = G_THERMALOK->with_lock([&](auto* __glk){ return (*__glk).at(2); });
    PUMP2.SEALLEAK = G_SEALLEAK->with_lock([&](auto* __glk){ return (*__glk).at(2); });
    PUMP2.VIBRATION = G_VIB_MMS->with_lock([&](auto* __glk){ return (*__glk).at(2); });
    PUMP2.DISCHPRESSURE = G_PUMPP_KPA->with_lock([&](auto* __glk){ return (*__glk).at(2); });
    PUMP2.RESETTRIP = RESETTRIP.at(2);
    PUMP2.LOCKOUT = LOCKOUT.at(2);
    PUMP2.MINOFFBYPASS = G_LSHH->read();
    PUMP2.SERVICEINTERVAL = TO_REAL(V_SERVICEHRS);
    PUMP2.RESETHOURS = RESETHOURS.at(2);
    PUMP2();
    PUMP2.ENO = true;
    PUMP3.RUNREQUEST = REQ.at(3);
    PUMP3.SPEEDREF = SPEED;
    PUMP3.THERMALOK = G_THERMALOK->with_lock([&](auto* __glk){ return (*__glk).at(3); });
    PUMP3.SEALLEAK = G_SEALLEAK->with_lock([&](auto* __glk){ return (*__glk).at(3); });
    PUMP3.VIBRATION = G_VIB_MMS->with_lock([&](auto* __glk){ return (*__glk).at(3); });
    PUMP3.DISCHPRESSURE = G_PUMPP_KPA->with_lock([&](auto* __glk){ return (*__glk).at(3); });
    PUMP3.RESETTRIP = RESETTRIP.at(3);
    PUMP3.LOCKOUT = LOCKOUT.at(3);
    PUMP3.MINOFFBYPASS = G_LSHH->read();
    PUMP3.SERVICEINTERVAL = TO_REAL(V_SERVICEHRS);
    PUMP3.RESETHOURS = RESETHOURS.at(3);
    PUMP3();
    PUMP3.ENO = true;
    HEAD.LEVEL = G_LEVEL_M->read();
    HEAD.INFLOW = G_INFLOW_LPS->read();
    HEAD.TOTALDISCHARGE = G_DISCH_LPS->read();
    HEAD();
    HEAD.ENO = true;
    PUMPSRUN = 0;
    if (PUMP1.RUNNING) {
        PUMPSRUN = PUMPSRUN + 1;
    }
    if (PUMP2.RUNNING) {
        PUMPSRUN = PUMPSRUN + 1;
    }
    if (PUMP3.RUNNING) {
        PUMPSRUN = PUMPSRUN + 1;
    }
    HIGHLEVEL = G_LEVEL_MM->read() >= V_HIGHALARM;
    auto __gwv_0 = PUMP1.RUNCMD;
    G_O_RUNCMD->with_lock([&](auto* __glk){ (*__glk).at(1) = __gwv_0; });
    auto __gwv_1 = PUMP2.RUNCMD;
    G_O_RUNCMD->with_lock([&](auto* __glk){ (*__glk).at(2) = __gwv_1; });
    auto __gwv_2 = PUMP3.RUNCMD;
    G_O_RUNCMD->with_lock([&](auto* __glk){ (*__glk).at(3) = __gwv_2; });
    auto __gwv_3 = PUMP1.RUNNING;
    G_O_RUNNING->with_lock([&](auto* __glk){ (*__glk).at(1) = __gwv_3; });
    auto __gwv_4 = PUMP2.RUNNING;
    G_O_RUNNING->with_lock([&](auto* __glk){ (*__glk).at(2) = __gwv_4; });
    auto __gwv_5 = PUMP3.RUNNING;
    G_O_RUNNING->with_lock([&](auto* __glk){ (*__glk).at(3) = __gwv_5; });
    auto __gwv_6 = PUMP1.AVAILABLE;
    G_O_AVAILABLE->with_lock([&](auto* __glk){ (*__glk).at(1) = __gwv_6; });
    auto __gwv_7 = PUMP2.AVAILABLE;
    G_O_AVAILABLE->with_lock([&](auto* __glk){ (*__glk).at(2) = __gwv_7; });
    auto __gwv_8 = PUMP3.AVAILABLE;
    G_O_AVAILABLE->with_lock([&](auto* __glk){ (*__glk).at(3) = __gwv_8; });
    auto __gwv_9 = PUMP1.TRIPPED;
    G_O_TRIPPED->with_lock([&](auto* __glk){ (*__glk).at(1) = __gwv_9; });
    auto __gwv_10 = PUMP2.TRIPPED;
    G_O_TRIPPED->with_lock([&](auto* __glk){ (*__glk).at(2) = __gwv_10; });
    auto __gwv_11 = PUMP3.TRIPPED;
    G_O_TRIPPED->with_lock([&](auto* __glk){ (*__glk).at(3) = __gwv_11; });
    auto __gwv_12 = PUMP1.STATE;
    G_O_PUMPSTATE->with_lock([&](auto* __glk){ (*__glk).at(1) = __gwv_12; });
    auto __gwv_13 = PUMP2.STATE;
    G_O_PUMPSTATE->with_lock([&](auto* __glk){ (*__glk).at(2) = __gwv_13; });
    auto __gwv_14 = PUMP3.STATE;
    G_O_PUMPSTATE->with_lock([&](auto* __glk){ (*__glk).at(3) = __gwv_14; });
    G_O_INAUTO->write((V_MODE == 1));
    G_O_HIGHLEVEL->write(HIGHLEVEL);
    G_O_SPILLACTIVE->write(G_SPILLDETECTED->read());
    G_O_LEVEL_MM->write(G_LEVEL_MM->read());
    G_O_PUMPSRUN->write(PUMPSRUN);
    G_O_DUTYPUMP->write(DUTY.DUTYPUMP);
    R = G_INFLOW_LPS->read() * 10.0;
    if (R > 32767.0) {
        R = 32767.0;
    } else if (R < -32768.0) {
        R = -32768.0;
    }
    G_O_INFLOW_X10->write(TO_INT(R));
    R = G_DISCH_LPS->read() * 10.0;
    if (R > 32767.0) {
        R = 32767.0;
    } else if (R < -32768.0) {
        R = -32768.0;
    }
    G_O_DISCH_X10->write(TO_INT(R));
    R = SPEED * 10.0;
    if (R > 32767.0) {
        R = 32767.0;
    } else if (R < 0.0) {
        R = 0.0;
    }
    G_O_SPEED_X10->write(TO_INT(R));
    R = HEAD.NETINFLOW * 10.0;
    if (R > 32767.0) {
        R = 32767.0;
    } else if (R < -32768.0) {
        R = -32768.0;
    }
    G_O_NETACCUM->write(TO_INT(R));
    R = HEAD.VOLTOSPILL;
    if (R > 32767.0) {
        R = 32767.0;
    } else if (R < 0.0) {
        R = 0.0;
    }
    G_O_VOLTOSPILL->write(TO_INT(R));
    G_O_TIMETOSPILL->write(HEAD.TIMETOSPILL);
    G_O_TIMETOLSHH->write(HEAD.TIMETOLSHH);
    R = PUMP1.RUNHOURS;
    if (R > 32767.0) {
        R = 32767.0;
    }
    auto __gwv_15 = TO_INT(R);
    G_O_RUNHOURS->with_lock([&](auto* __glk){ (*__glk).at(1) = __gwv_15; });
    R = PUMP2.RUNHOURS;
    if (R > 32767.0) {
        R = 32767.0;
    }
    auto __gwv_16 = TO_INT(R);
    G_O_RUNHOURS->with_lock([&](auto* __glk){ (*__glk).at(2) = __gwv_16; });
    R = PUMP3.RUNHOURS;
    if (R > 32767.0) {
        R = 32767.0;
    }
    auto __gwv_17 = TO_INT(R);
    G_O_RUNHOURS->with_lock([&](auto* __glk){ (*__glk).at(3) = __gwv_17; });
    if (V_MODE == 2) {
        G_O_STATIONSTATE->write(0);
    } else if (G_LSHH->read()) {
        G_O_STATIONSTATE->write(4);
    } else if (DRYLOCKOUT) {
        G_O_STATIONSTATE->write(5);
    } else if (LEVELFAULT) {
        G_O_STATIONSTATE->write(6);
    } else if (HIGHLEVEL) {
        G_O_STATIONSTATE->write(3);
    } else if (PUMPSRUN > 0) {
        G_O_STATIONSTATE->write(2);
    } else {
        G_O_STATIONSTATE->write(1);
    }
    ALARM = 0;
    if (HIGHLEVEL) {
        ALARM = ALARM + 1;
    }
    if (G_LSHH->read()) {
        ALARM = ALARM + 2;
    }
    if ((DRYRUN) | (DRYLOCKOUT)) {
        ALARM = ALARM + 4;
    }
    if (G_SPILLDETECTED->read()) {
        ALARM = ALARM + 8;
    }
    if (PUMP1.TRIPPED) {
        ALARM = ALARM + 16;
    }
    if (PUMP2.TRIPPED) {
        ALARM = ALARM + 32;
    }
    if (PUMP3.TRIPPED) {
        ALARM = ALARM + 64;
    }
    if (PUMP1.SEALALARM) {
        ALARM = ALARM + 128;
    }
    if (PUMP2.SEALALARM) {
        ALARM = ALARM + 256;
    }
    if (PUMP3.SEALALARM) {
        ALARM = ALARM + 512;
    }
    if (PUMP1.VIBALARM) {
        ALARM = ALARM + 1024;
    }
    if (PUMP2.VIBALARM) {
        ALARM = ALARM + 2048;
    }
    if (PUMP3.VIBALARM) {
        ALARM = ALARM + 4096;
    }
    if (LEVELFAULT) {
        ALARM = ALARM + 8192;
    }
    if (!G_MAINSOK->read()) {
        ALARM = ALARM + 16384;
    }
    if (SPREJECTED) {
        ALARM = ALARM + 32768;
    }
    if (ALARM >= 32768) {
        G_O_ALARMWORD->write(TO_INT(ALARM - 65536));
    } else {
        G_O_ALARMWORD->write(TO_INT(ALARM));
    }
}

}  // namespace strucpp