SUBROUTINE FlowStartup
    
    USE Fluid_Flow_Startup_Vars
    USE CStringConfigurationVariables
    USE CMudPropertiesVariables
    USE FricPressDropVarsModule
    use KickVARIABLESModule
    USE MudSystemVARIABLES
use SimulationVariables !@@@
    use PressureDisplayVARIABLESModule
    USE CShoeVariables
    USE TD_DrillStemComponents
    use SimulationVariables !@, pi3 => pi
    use SimulationVariables !@
    USE CWellSurveyDataVariables
    USE CHOKEVARIABLES
use SimulationVariables !@, pi4 => pi
    use SimulationVariables

    IMPLICIT NONE
    
    INTEGER :: i
    
    data%State%PressureDisplay%PressureGauges(:) = 0.0
    
    KickVARIABLES%KickSinglePocket = Reservoir%MakeKickSinglePacket
    IF (KickVARIABLES%KickSinglePocket) THEN
        KickVARIABLES%MaxGasPocket = 1
    ELSE
        KickVARIABLES%MaxGasPocket = 4
    END IF
    KickVARIABLES%MaxChokeDensityChange = 25.0     ! [ppg/min]
    KickVARIABLES%ChokeMinDensity = 2.0

    KickVARIABLES%ChokeDensity = data%Configuration%Mud%ActiveDensity
    
    KickVARIABLES%MinKickVol = 0.5            ! USGal
    
    KickVARIABLES%SecondaryKickVol = 0.0
    KickVARIABLES%SecondaryKickWeight = 0.0
    
    KickVARIABLES%NoGasPocket = 0                 ! No Kick
    KickVARIABLES%WellHeadOpen = .TRUE.
    KickVARIABLES%WellHeadWasOpen = .TRUE.
    data%State%FricPressDrop%BackPressure = 0.0
    KickVARIABLES%GasKickPumpFlowRate = 0.0
    DownHole%KickVolume = 0.0
    DownHole%InfluxRate = 0.0
    KickVARIABLES%ExitMass = 0.0
    KickVARIABLES%MinAllowableKickVol = 1.0 * (42.0 / Convft3toUSgal)      ! 1 bbl * 42 gal/bbl / 7.48 gal/ft^3 = ... ft^3
    data%State%FricPressDrop%StCompressedMudVol = 0.0
    data%State%FricPressDrop%AnnCompressedMudVol = 0.0
    KickVARIABLES%KickFlux = .FALSE.
    KickVARIABLES%KickOffBottom = .FALSE.
    KickVARIABLES%KickWasExitingThroughChoke = .FALSE.
    data%State%FricPressDrop%FloatValveOpen = .TRUE.
    
    data%State%Choke%ChokeAreaFullyOpen = 123.0 / 64.0     ! fully open area is 123/64 in^2 = 0.01334635 ft^2
    data%State%FricPressDrop%ChokeBypassArea = PI / 4.0 * data%Configuration%BopStack%ChokeLineId**2
    data%State%FricPressDrop%BHPSafetyMargin = 150.0
    data%State%FricPressDrop%AChBHPTol = 15.0
    
    
    data%State%FricPressDrop%ManChoke1Plug = 0
    data%State%FricPressDrop%ManChoke2Plug = 0
    data%State%FricPressDrop%ManChoke1Washout = 0
    data%State%FricPressDrop%ManChoke2Washout = 0
    data%State%FricPressDrop%BitJetsPlugged = 0
    data%State%FricPressDrop%BitJetsWashedOut = 0
    data%State%FricPressDrop%CasingPressure_DataDisplayMalF = 0
    
    SoundSpeed = 1530.0 / Convfttom
    data%State%PressureDisplay%PressureTimeStepDelay(1) = INT(2.0 * SUM(data%Configuration%StringConfiguration%StringConfigurations(2:)%ComponentLength) / SoundSpeed / dt)
    data%State%PressureDisplay%PressureTimeStepDelay(2) = INT(data%Configuration%Path%Items(SIZE(data%Configuration%Path%Items))%MeasuredDepth / SoundSpeed / dt)
    data%State%PressureDisplay%PressureTimeStepDelay(3) = INT(Shoe%ShoeDepth / SoundSpeed / dt)
    
    !WRITE (*,*) SUM(StringConfigurations(2:)%ComponentLength), PathGenerations(SIZE(PathGenerations))%TotalVerticalDepth!, WellSurveyData(SIZE(WellSurveyData))%TotalVerticalDepth
    !WRITE (*,*) PathGenerations(SIZE(PathGenerations))%MeasuredDepth!, WellSurveyData(SIZE(WellSurveyData))%MeasuredDepth
    WRITE (*,*) 'time step delay', data%State%PressureDisplay%PressureTimeStepDelay
    
    DO i = 1 , data%State%PressureDisplay%PressureTimeStepDelay(1)
        CALL PumpPressureDelay%AddToFirst(0.0)
    END DO
    
    DO i = 1 , data%State%PressureDisplay%PressureTimeStepDelay(2)
        CALL BottomHolePressureDelay%AddToFirst(REAL(0.052 * data%Configuration%Mud%ActiveDensity * data%Configuration%Path%Items(SIZE(data%Configuration%Path%Items))%TotalVerticalDepth))
    END DO
    
    DO i = 1 , data%State%PressureDisplay%PressureTimeStepDelay(3)
        CALL ShoePressureDelay%AddToFirst(REAL(0.052 * data%Configuration%Mud%ActiveDensity * Shoe%ShoeDepth))
    END DO
        
    
    !!!!!!! Methane Information
    data%State%GasType(1)%CritPress = 673.0
    data%State%GasType(1)%CritTemp = 344.0
    data%State%GasType(1)%MolarWt = 16.04
    data%State%GasType(1)%StDensity = 0.04238
    data%State%GasType(1)%GasConstant = RUniversal / data%State%GasType(1)%MolarWt
    
    !!!!!!!! H2S Information
    data%State%GasType(2)%CritPress = 1306.0
    data%State%GasType(2)%CritTemp = 673.0
    data%State%GasType(2)%MolarWt = 34.08
    data%State%GasType(2)%StDensity = 0.09087
    data%State%GasType(2)%GasConstant = RUniversal / data%State%GasType(2)%MolarWt

    !!!!!!!! CO2 Information
    data%State%GasType(3)%CritPress = 1072.0
    data%State%GasType(3)%CritTemp = 548.0
    data%State%GasType(3)%MolarWt = 44.01
    !data%State%GasType(3)%StDensity = 00
    data%State%GasType(3)%GasConstant = RUniversal / data%State%GasType(2)%MolarWt

    !!!!!!!! Mud density and viscosity
    Theta600Refrence = data%Configuration%Mud%ActiveThetaSixHundred
    Theta300Refrence = data%Configuration%Mud%ActiveThetaThreeHundred
    DensityRefrence = data%Configuration%Mud%ActiveDensity
    
    END SUBROUTINE