%% Read a csv file of position,load data into MATLAB

wellInputData = csvread("welldata/melinda254.csv");

%
%% Well Parameters

dt = 0.090;
tubingHeadPressure = 100.0;
fluidGradient = 0.380;
stuffingBoxFriction = 100.0;
pumpDiameter = 1.750;
tubingInnerDiameter = 2.441;
tubingOuterDiameter = 2.875;
tubingAnchorDepth = 8872.0;
structuralRating = 320000;

rodLengths = [4375.0, 3925.0, 150.0];
rodDiameters = [1.225, 1.000, 1.500];
rodMaterials = ["fiberglass", "steel", "steel"];
rodDampingFactors = [0.1, 0.1, 0.1];

%
%% Use the Well class to define the well.

thisWell = Well(dt, rodLengths, rodDiameters, ...
    rodMaterials, rodDampingFactors, tubingHeadPressure, ...
    stuffingBoxFriction, fluidGradient, pumpDiameter, tubingOuterDiameter, ...
    tubingInnerDiameter, tubingAnchorDepth, structuralRating);

%
%% Setup some variables.
% Double the well data to ensure that the last card is a full card.

wellInputData = [wellInputData; wellInputData];

% Persistent variables for the pump-off algorithm.

count = zeros(1, thisWell.parameters.numTapers);
topPosArray = zeros(thisWell.parameters.numTapers+1, 100);
topLoadArray = zeros(thisWell.parameters.numTapers+1, 100);

%
%% Loop through the well data and calculate downhole data

for ptI = 2:length(wellInputData)
    thisWell.evalSim(wellInputData(ptI,1), wellInputData(ptI,2));
end

%
%% Plot the surface and downhole cards.

thisWell.plotCards();

%

