module CGaugesProblems
	use SimulationVariables
	implicit none    
	public 
    contains   	
    subroutine GaugesProblemsToJson(parent)

        type(json_value),pointer :: parent
        type(json_core) :: json
        type(json_value),pointer :: p

        ! 1. create new node
        call json%create_object(p,'GaugesProblems')
        
        ! 2. add member of data type to new node
        call ProblemToJson(p,"WeightIndicator",data%problems%GaugesProblems%WeightIndicator)
        call ProblemToJson(p,"RotaryRpm",data%problems%GaugesProblems%RotaryRpm)
        call ProblemToJson(p,"RotaryTorque",data%problems%GaugesProblems%RotaryTorque)
        call ProblemToJson(p,"StandPipePressure",data%problems%GaugesProblems%StandPipePressure)
        call ProblemToJson(p,"CasingPressure",data%problems%GaugesProblems%CasingPressure)
        call ProblemToJson(p,"Pump1Strokes",data%problems%GaugesProblems%Pump1Strokes)
        call ProblemToJson(p,"Pump2Strokes",data%problems%GaugesProblems%Pump2Strokes)
        call ProblemToJson(p,"ReturnLineTemperature",data%problems%GaugesProblems%ReturnLineTemperature)
        call ProblemToJson(p,"TripTank",data%problems%GaugesProblems%TripTank)
        call ProblemToJson(p,"PitGainLoss",data%problems%GaugesProblems%PitGainLoss)
        call ProblemToJson(p,"MudTankVolume",data%problems%GaugesProblems%MudTankVolume)
        call ProblemToJson(p,"ReturnMudFlow",data%problems%GaugesProblems%ReturnMudFlow)
        call ProblemToJson(p,"TorqueLimit",data%problems%GaugesProblems%TorqueLimit)
        call ProblemToJson(p,"PowerLimit",data%problems%GaugesProblems%PowerLimit)
        call ProblemToJson(p,"AccumulatorPressure",data%problems%GaugesProblems%AccumulatorPressure)
        call ProblemToJson(p,"ManifoldPressure",data%problems%GaugesProblems%ManifoldPressure)
        call ProblemToJson(p,"AnnularPressure",data%problems%GaugesProblems%AnnularPressure)
        call ProblemToJson(p,"RigAirPressure",data%problems%GaugesProblems%RigAirPressure)
        call ProblemToJson(p,"StandPipe1",data%problems%GaugesProblems%StandPipe1)
        call ProblemToJson(p,"StandPipe2",data%problems%GaugesProblems%StandPipe2)
        call ProblemToJson(p,"DrillPipePressure",data%problems%GaugesProblems%DrillPipePressure)
        call ProblemToJson(p,"ChokePosition",data%problems%GaugesProblems%ChokePosition)
        call ProblemToJson(p,"CasingPressure2",data%problems%GaugesProblems%CasingPressure2)
        
        ! 3. add new node to parent
        call json%add(parent,p)
    end subroutine

    subroutine ProcessGaugesProblemsDueTime(time)
        implicit none
        integer :: time
        if(data%problems%GaugesProblems%WeightIndicator%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%WeightIndicator, ChangeWeightIndicator, time)
        if(data%problems%GaugesProblems%RotaryRpm%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%RotaryRpm, ChangeRotaryRpm, time)
        if(data%problems%GaugesProblems%RotaryTorque%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%RotaryTorque, ChangeRotaryTorque, time)
        if(data%problems%GaugesProblems%StandPipePressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%StandPipePressure, ChangeStandPipePressure, time)
        if(data%problems%GaugesProblems%CasingPressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%CasingPressure, ChangeCasingPressure, time)
        if(data%problems%GaugesProblems%Pump1Strokes%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%Pump1Strokes, ChangePump1Strokes, time)
        if(data%problems%GaugesProblems%Pump2Strokes%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%Pump2Strokes, ChangePump2Strokes, time)
        if(data%problems%GaugesProblems%ReturnLineTemperature%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%ReturnLineTemperature, ChangeReturnLineTemperature, time)
        if(data%problems%GaugesProblems%TripTank%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%TripTank, ChangeTripTank, time)
        if(data%problems%GaugesProblems%PitGainLoss%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%PitGainLoss, ChangePitGainLoss, time)
        if(data%problems%GaugesProblems%MudTankVolume%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%MudTankVolume, ChangeMudTankVolume, time)
        if(data%problems%GaugesProblems%ReturnMudFlow%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%ReturnMudFlow, ChangeReturnMudFlow, time)
        if(data%problems%GaugesProblems%TorqueLimit%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%TorqueLimit, ChangeTorqueLimit, time)
        if(data%problems%GaugesProblems%PowerLimit%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%PowerLimit, ChangePowerLimit, time)
        if(data%problems%GaugesProblems%AccumulatorPressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%AccumulatorPressure, ChangeAccumulatorPressure, time)
        if(data%problems%GaugesProblems%ManifoldPressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%ManifoldPressure, ChangeManifoldPressure, time)
        if(data%problems%GaugesProblems%AnnularPressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%AnnularPressure, ChangeAnnularPressure, time)
        if(data%problems%GaugesProblems%RigAirPressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%RigAirPressure, ChangeRigAirPressure, time)
        if(data%problems%GaugesProblems%StandPipe1%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%StandPipe1, ChangeStandPipe1, time)
        if(data%problems%GaugesProblems%StandPipe2%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%StandPipe2, ChangeStandPipe2, time)
        if(data%problems%GaugesProblems%DrillPipePressure%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%DrillPipePressure, ChangeDrillPipePressure, time)
        if(data%problems%GaugesProblems%ChokePosition%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%ChokePosition, ChangeChokePosition, time)
        if(data%problems%GaugesProblems%CasingPressure2%ProblemType == Time_ProblemType) call ProcessDueTime(data%problems%GaugesProblems%CasingPressure2, ChangeCasingPressure2, time)
    end subroutine
	
	subroutine ProcessGaugesProblemsDuePumpStrokes(strokes)
        implicit none
        integer :: strokes
        if(data%problems%GaugesProblems%WeightIndicator%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%WeightIndicator, ChangeWeightIndicator, strokes)
        if(data%problems%GaugesProblems%RotaryRpm%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%RotaryRpm, ChangeRotaryRpm, strokes)
        if(data%problems%GaugesProblems%RotaryTorque%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%RotaryTorque, ChangeRotaryTorque, strokes)
        if(data%problems%GaugesProblems%StandPipePressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%StandPipePressure, ChangeStandPipePressure, strokes)
        if(data%problems%GaugesProblems%CasingPressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%CasingPressure, ChangeCasingPressure, strokes)
        if(data%problems%GaugesProblems%Pump1Strokes%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%Pump1Strokes, ChangePump1Strokes, strokes)
        if(data%problems%GaugesProblems%Pump2Strokes%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%Pump2Strokes, ChangePump2Strokes, strokes)
        if(data%problems%GaugesProblems%ReturnLineTemperature%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%ReturnLineTemperature, ChangeReturnLineTemperature, strokes)
        if(data%problems%GaugesProblems%TripTank%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%TripTank, ChangeTripTank, strokes)
        if(data%problems%GaugesProblems%PitGainLoss%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%PitGainLoss, ChangePitGainLoss, strokes)
        if(data%problems%GaugesProblems%MudTankVolume%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%MudTankVolume, ChangeMudTankVolume, strokes)
        if(data%problems%GaugesProblems%ReturnMudFlow%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%ReturnMudFlow, ChangeReturnMudFlow, strokes)
        if(data%problems%GaugesProblems%TorqueLimit%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%TorqueLimit, ChangeTorqueLimit, strokes)
        if(data%problems%GaugesProblems%PowerLimit%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%PowerLimit, ChangePowerLimit, strokes)
        if(data%problems%GaugesProblems%AccumulatorPressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%AccumulatorPressure, ChangeAccumulatorPressure, strokes)
        if(data%problems%GaugesProblems%ManifoldPressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%ManifoldPressure, ChangeManifoldPressure, strokes)
        if(data%problems%GaugesProblems%AnnularPressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%AnnularPressure, ChangeAnnularPressure, strokes)
        if(data%problems%GaugesProblems%RigAirPressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%RigAirPressure, ChangeRigAirPressure, strokes)
        if(data%problems%GaugesProblems%StandPipe1%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%StandPipe1, ChangeStandPipe1, strokes)
        if(data%problems%GaugesProblems%StandPipe2%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%StandPipe2, ChangeStandPipe2, strokes)
        if(data%problems%GaugesProblems%DrillPipePressure%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%DrillPipePressure, ChangeDrillPipePressure, strokes)
        if(data%problems%GaugesProblems%ChokePosition%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%ChokePosition, ChangeChokePosition, strokes)
        if(data%problems%GaugesProblems%CasingPressure2%ProblemType == PumpStrokes_ProblemType) call ProcessDuePumpStrokes(data%problems%GaugesProblems%CasingPressure2, ChangeCasingPressure2, strokes)
    end subroutine
	
	subroutine ProcessGaugesProblemsDueVolumePumped(volume)
        implicit none
        real(8) :: volume
        if(data%problems%GaugesProblems%WeightIndicator%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%WeightIndicator, ChangeWeightIndicator, volume)
        if(data%problems%GaugesProblems%RotaryRpm%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%RotaryRpm, ChangeRotaryRpm, volume)
        if(data%problems%GaugesProblems%RotaryTorque%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%RotaryTorque, ChangeRotaryTorque, volume)
        if(data%problems%GaugesProblems%StandPipePressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%StandPipePressure, ChangeStandPipePressure, volume)
        if(data%problems%GaugesProblems%CasingPressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%CasingPressure, ChangeCasingPressure, volume)
        if(data%problems%GaugesProblems%Pump1Strokes%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%Pump1Strokes, ChangePump1Strokes, volume)
        if(data%problems%GaugesProblems%Pump2Strokes%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%Pump2Strokes, ChangePump2Strokes, volume)
        if(data%problems%GaugesProblems%ReturnLineTemperature%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%ReturnLineTemperature, ChangeReturnLineTemperature, volume)
        if(data%problems%GaugesProblems%TripTank%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%TripTank, ChangeTripTank, volume)
        if(data%problems%GaugesProblems%PitGainLoss%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%PitGainLoss, ChangePitGainLoss, volume)
        if(data%problems%GaugesProblems%MudTankVolume%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%MudTankVolume, ChangeMudTankVolume, volume)
        if(data%problems%GaugesProblems%ReturnMudFlow%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%ReturnMudFlow, ChangeReturnMudFlow, volume)
        if(data%problems%GaugesProblems%TorqueLimit%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%TorqueLimit, ChangeTorqueLimit, volume)
        if(data%problems%GaugesProblems%PowerLimit%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%PowerLimit, ChangePowerLimit, volume)
        if(data%problems%GaugesProblems%AccumulatorPressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%AccumulatorPressure, ChangeAccumulatorPressure, volume)
        if(data%problems%GaugesProblems%ManifoldPressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%ManifoldPressure, ChangeManifoldPressure, volume)
        if(data%problems%GaugesProblems%AnnularPressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%AnnularPressure, ChangeAnnularPressure, volume)
        if(data%problems%GaugesProblems%RigAirPressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%RigAirPressure, ChangeRigAirPressure, volume)
        if(data%problems%GaugesProblems%StandPipe1%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%StandPipe1, ChangeStandPipe1, volume)
        if(data%problems%GaugesProblems%StandPipe2%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%StandPipe2, ChangeStandPipe2, volume)
        if(data%problems%GaugesProblems%DrillPipePressure%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%DrillPipePressure, ChangeDrillPipePressure, volume)
        if(data%problems%GaugesProblems%ChokePosition%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%ChokePosition, ChangeChokePosition, volume)
        if(data%problems%GaugesProblems%CasingPressure2%ProblemType == VolumePumped_ProblemType) call ProcessDueVolumePumped(data%problems%GaugesProblems%CasingPressure2, ChangeCasingPressure2, volume)
    end subroutine
	
	subroutine ProcessGaugesProblemsDueDistanceDrilled(distance)
        implicit none
        real(8) :: distance
        if(data%problems%GaugesProblems%WeightIndicator%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%WeightIndicator, ChangeWeightIndicator, distance)
        if(data%problems%GaugesProblems%RotaryRpm%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%RotaryRpm, ChangeRotaryRpm, distance)
        if(data%problems%GaugesProblems%RotaryTorque%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%RotaryTorque, ChangeRotaryTorque, distance)
        if(data%problems%GaugesProblems%StandPipePressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%StandPipePressure, ChangeStandPipePressure, distance)
        if(data%problems%GaugesProblems%CasingPressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%CasingPressure, ChangeCasingPressure, distance)
        if(data%problems%GaugesProblems%Pump1Strokes%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%Pump1Strokes, ChangePump1Strokes, distance)
        if(data%problems%GaugesProblems%Pump2Strokes%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%Pump2Strokes, ChangePump2Strokes, distance)
        if(data%problems%GaugesProblems%ReturnLineTemperature%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%ReturnLineTemperature, ChangeReturnLineTemperature, distance)
        if(data%problems%GaugesProblems%TripTank%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%TripTank, ChangeTripTank, distance)
        if(data%problems%GaugesProblems%PitGainLoss%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%PitGainLoss, ChangePitGainLoss, distance)
        if(data%problems%GaugesProblems%MudTankVolume%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%MudTankVolume, ChangeMudTankVolume, distance)
        if(data%problems%GaugesProblems%ReturnMudFlow%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%ReturnMudFlow, ChangeReturnMudFlow, distance)
        if(data%problems%GaugesProblems%TorqueLimit%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%TorqueLimit, ChangeTorqueLimit, distance)
        if(data%problems%GaugesProblems%PowerLimit%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%PowerLimit, ChangePowerLimit, distance)
        if(data%problems%GaugesProblems%AccumulatorPressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%AccumulatorPressure, ChangeAccumulatorPressure, distance)
        if(data%problems%GaugesProblems%ManifoldPressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%ManifoldPressure, ChangeManifoldPressure, distance)
        if(data%problems%GaugesProblems%AnnularPressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%AnnularPressure, ChangeAnnularPressure, distance)
        if(data%problems%GaugesProblems%RigAirPressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%RigAirPressure, ChangeRigAirPressure, distance)
        if(data%problems%GaugesProblems%StandPipe1%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%StandPipe1, ChangeStandPipe1, distance)
        if(data%problems%GaugesProblems%StandPipe2%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%StandPipe2, ChangeStandPipe2, distance)
        if(data%problems%GaugesProblems%DrillPipePressure%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%DrillPipePressure, ChangeDrillPipePressure, distance)
        if(data%problems%GaugesProblems%ChokePosition%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%ChokePosition, ChangeChokePosition, distance)
        if(data%problems%GaugesProblems%CasingPressure2%ProblemType == DistanceDrilled_ProblemType) call ProcessDueDistanceDrilled(data%problems%GaugesProblems%CasingPressure2, ChangeCasingPressure2, distance)
    end subroutine
	
	
	
	
	
	
	
    
    
    subroutine ChangeWeightIndicator(status)
        use SimulationVariables !@
        implicit none
        integer, intent (in) :: status
        ! if(associated(WeightIndicatorPtr)) call WeightIndicatorPtr(status)
        if(status == Clear_StatusType)    data%State%TD_General%WeightIndicatorMalf = 0
        if(status == Executed_StatusType) data%State%TD_General%WeightIndicatorMalf = 1
    endsubroutine
    
    subroutine ChangeRotaryRpm(status)
        use SimulationVariables !@
        implicit none
        integer, intent (in) :: status
        ! if(associated(RotaryRpmPtr)) call RotaryRpmPtr(status)
        if(status == Clear_StatusType)    data%State%RTable%RpmGaugeMalf = 0
        if(status == Executed_StatusType) data%State%RTable%RpmGaugeMalf = 1
    endsubroutine
    
    subroutine ChangeRotaryTorque(status)
        use SimulationVariables !@
        implicit none
        integer, intent (in) :: status
        ! if(associated(RotaryTorquePtr)) call RotaryTorquePtr(status)
        if(status == Clear_StatusType)    data%State%RTable%TorqueGaugeMalf = 0
        if(status == Executed_StatusType) data%State%RTable%TorqueGaugeMalf = 1
    endsubroutine
    
    subroutine ChangeStandPipePressure(status)
        USE MudSystemVARIABLES
use SimulationVariables !@@@
        implicit none
        integer, intent (in) :: status
        ! if(associated(StandPipePressurePtr)) call StandPipePressurePtr(status)
        if(status == Clear_StatusType) data%State%MudSystem%StandPipePressure_DataDisplayMalf = 0
        if(status == Executed_StatusType) data%State%MudSystem%StandPipePressure_DataDisplayMalf = 1
    endsubroutine
    
    subroutine ChangeCasingPressure(status)
        USE FricPressDropVarsModule
        implicit none
        integer, intent (in) :: status
        ! if(associated(CasingPressurePtr)) call CasingPressurePtr(status)
        if(status == Clear_StatusType) data%State%FricPressDrop%CasingPressure_DataDisplayMalF = 0
        if(status == Executed_StatusType) data%State%FricPressDrop%CasingPressure_DataDisplayMalF = 1
    endsubroutine
    
    subroutine ChangePump1Strokes(status)
        use SimulationVariables
        implicit none
        integer, intent (in) :: status
        ! if(associated(Pump1StrokesPtr)) call Pump1StrokesPtr(status)
        if(status == Clear_StatusType)    data%State%Pump(1)%SPMGaugeMalf = 0
        if(status == Executed_StatusType) data%State%Pump(1)%SPMGaugeMalf = 1
    endsubroutine
    
    subroutine ChangePump2Strokes(status)
        use SimulationVariables
        implicit none
        integer, intent (in) :: status
        ! if(associated(Pump2StrokesPtr)) call Pump2StrokesPtr(status)
        if(status == Clear_StatusType)    data%State%Pump(2)%SPMGaugeMalf = 0
        if(status == Executed_StatusType) data%State%Pump(2)%SPMGaugeMalf = 1
    endsubroutine
    
    subroutine ChangeReturnLineTemperature(status)
        implicit none
        integer, intent (in) :: status
        ! if(associated(ReturnLineTemperaturePtr)) call ReturnLineTemperaturePtr(status)
        !if(status == Clear_StatusType) print*,'On_ReturnLineTemperature_Clear'
        !if(status == Executed_StatusType) print*,'On_ReturnLineTemperature_Execute'
    endsubroutine
    
    subroutine ChangeTripTank(status)
        USE MudSystemVARIABLES
use SimulationVariables !@@@
        implicit none
        integer, intent (in) :: status
        ! if(associated(TripTankPtr)) call TripTankPtr(status)
        if(status == Clear_StatusType) data%State%MudSystem%TripTankPressure_DataDisplayMalf = 0
        if(status == Executed_StatusType) data%State%MudSystem%TripTankPressure_DataDisplayMalf = 1
    endsubroutine
    
    subroutine ChangePitGainLoss(status)
        USE MudSystemVARIABLES
use SimulationVariables !@@@
        implicit none
        integer, intent (in) :: status
        ! if(associated(PitGainLossPtr)) call PitGainLossPtr(status)
        if(status == Clear_StatusType) data%State%MudSystem%PitGainLossGaugeMalf = 0
        if(status == Executed_StatusType) data%State%MudSystem%PitGainLossGaugeMalf = 1
    endsubroutine
    
    subroutine ChangeMudTankVolume(status)
        implicit none
        integer, intent (in) :: status
        ! if(associated(MudTankVolumePtr)) call MudTankVolumePtr(status)
        !if(status == Clear_StatusType) print*,'On_MudTankVolume_Clear'
        !if(status == Executed_StatusType) print*,'On_MudTankVolume_Execute'
    endsubroutine
    
    subroutine ChangeReturnMudFlow(status)
        implicit none
        integer, intent (in) :: status
        ! if(associated(ReturnMudFlowPtr)) call ReturnMudFlowPtr(status)
        !if(status == Clear_StatusType) print*,'On_ReturnMudFlow_Clear'
        !if(status == Executed_StatusType) print*,'On_ReturnMudFlow_Execute'
    endsubroutine
    
    subroutine ChangeTorqueLimit(status)
        use SimulationVariables !@
        implicit none
        integer, intent (in) :: status
        ! if(associated(TorqueLimitPtr)) call TorqueLimitPtr(status)
        if(status == Clear_StatusType)    data%State%RTable%TorqueLimitGaugeMalf = 0
        if(status == Executed_StatusType) data%State%RTable%TorqueLimitGaugeMalf = 1
    endsubroutine
    
    subroutine ChangePowerLimit(status)
        implicit none
        integer, intent (in) :: status
        ! if(associated(PowerLimitPtr)) call PowerLimitPtr(status)
        !if(status == Clear_StatusType) print*,'On_PowerLimit_Clear'
        !if(status == Executed_StatusType) print*,'On_PowerLimit_Execute'
    endsubroutine
    
    subroutine ChangeAccumulatorPressure(status)
        use SimulationVariables
        implicit none
        integer, intent (in) :: status
        ! if(associated(AccumulatorPressurePtr)) call AccumulatorPressurePtr(status)
        if(status == Clear_StatusType) data%State%BopStackAcc%AccumulatorPressureGaugeMalf = 0
        if(status == Executed_StatusType) data%State%BopStackAcc%AccumulatorPressureGaugeMalf = 1
    endsubroutine
    
    subroutine ChangeManifoldPressure(status)
        use SimulationVariables
        implicit none
        integer, intent (in) :: status
        ! if(associated(ManifoldPressurePtr)) call ManifoldPressurePtr(status)
        if(status == Clear_StatusType) data%State%BopStackAcc%ManifoldPressureGaugeMalf = 0
        if(status == Executed_StatusType) data%State%BopStackAcc%ManifoldPressureGaugeMalf = 1
    endsubroutine
    
    subroutine ChangeAnnularPressure(status)
        use SimulationVariables
        implicit none
        integer, intent (in) :: status
        ! if(associated(AnnularPressurePtr)) call AnnularPressurePtr(status)
        if(status == Clear_StatusType) data%State%Annular%AnnularPressureGaugeMalf = 0
        if(status == Executed_StatusType) data%State%Annular%AnnularPressureGaugeMalf = 1
    endsubroutine
    
    subroutine ChangeRigAirPressure(status)
        use SimulationVariables
        implicit none
        integer, intent (in) :: status
        ! if(associated(RigAirPressurePtr)) call RigAirPressurePtr(status)
        if(status == Clear_StatusType) data%State%BopStackAcc%AirSupplyPressureGaugeMalf = 0
        if(status == Executed_StatusType) data%State%BopStackAcc%AirSupplyPressureGaugeMalf = 1
    endsubroutine
    
    subroutine ChangeStandPipe1(status)
        USE MudSystemVARIABLES
use SimulationVariables !@@@
        implicit none
        integer, intent (in) :: status
        ! if(associated(StandPipe1Ptr)) call StandPipe1Ptr(status)
        if(status == Clear_StatusType)          data%State%MudSystem%StandPipeGauge1Malf = 0
        if(status == Executed_StatusType)       data%State%MudSystem%StandPipeGauge1Malf = 1
    endsubroutine
    
    subroutine ChangeStandPipe2(status)
        USE MudSystemVARIABLES
use SimulationVariables !@@@
        implicit none
        integer, intent (in) :: status
        ! if(associated(StandPipe2Ptr)) call StandPipe2Ptr(status)
        if(status == Clear_StatusType)          data%State%MudSystem%StandPipeGauge2Malf = 0
        if(status == Executed_StatusType)       data%State%MudSystem%StandPipeGauge2Malf = 1
    endsubroutine
    
    subroutine ChangeDrillPipePressure(status)
        USE MudSystemVARIABLES
use SimulationVariables !@@@
        implicit none
        integer, intent (in) :: status
        ! if(associated(DrillPipePressurePtr)) call DrillPipePressurePtr(status)
        if(status == Clear_StatusType)         data%State%MudSystem%DrillPipePressureMalf = 0
        if(status == Executed_StatusType)      data%State%MudSystem%DrillPipePressureMalf = 1
    endsubroutine
    
    subroutine ChangeChokePosition(status)
        USE CHOKEVARIABLES
use SimulationVariables !@
        implicit none
        integer, intent (in) :: status
        ! if(associated(ChokePositionPtr)) call ChokePositionPtr(status)
        if(status == Clear_StatusType) data%State%Choke%GaugeChokePositionMailf = 0
        if(status == Executed_StatusType) data%State%Choke%GaugeChokePositionMailf = 1
    endsubroutine
    
    subroutine ChangeCasingPressure2(status)
        USE FricPressDropVarsModule
        implicit none
        integer, intent (in) :: status
        ! if(associated(CasingPressure2Ptr)) call CasingPressure2Ptr(status)
        if(status == Clear_StatusType)          data%State%FricPressDrop%CasingPressure_ChokeMalF = 0
        if(status == Executed_StatusType)       data%State%FricPressDrop%CasingPressure_ChokeMalF = 1
    endsubroutine

end module CGaugesProblems