stateName(1) = "Surface Ops";
stateName(2) = "Init Profile";
stateName(3) = "Decrease Buoyancy Fast";
stateName(4) = "Descend";
stateName(5) = "Anchor";
stateName(6) = "Start CP Mode";
stateName(7) = "DeAnchor";
stateName(8) = "Ascend";
stateName(9) = "Set Bellows";
stateName(10) = "Dump CPData";
stateName(11) = "Recovery";
stateName(12) = "Init Platform";
stateName(13) = "Init Mission";

for profileNum = 1:length(profile)
    fprintf("\nProfile Number: %d\n", profileNum);
    if( profileNum == 1)
        lastState = length(stateName);
    elseif(profileNum == length(profile))
        lastState = 11
    else
        lastState = 10;
    end
        
    
    for i = 1: lastState
        stateTimes = find(profile(profileNum).state == stateName(i));
        if(length(stateTimes) > 0)
            startTime = find(profile(profileNum).pumpEnergyCalcDT >= profile(profileNum).DT(stateTimes(1)));
            endTime = find(profile(profileNum).pumpEnergyCalcDT <= profile(profileNum).DT(stateTimes(end)));
            if(length(endTime) == 0)
                endTime(1) = length(profile(profileNum).pumpEnergyCalcSum(end));
            end
            
            stateEnergy(profileNum, i) = profile(profileNum).pumpEnergyCalcSum(endTime(end)) - profile(profileNum).pumpEnergyCalcSum(startTime(1));
            fprintf(1, "%s state enegy = %.1f\n", stateName(i), stateEnergy(profileNum, i))
        else
            stateEnergy(profileNum, i) = 0;
            fprintf(1, "%s not present in this profile\n", stateName(i))
        end
    end
end


for i=1:13
    nonZeroRows = find(stateEnergy(1:length(profile),i) ~= 0)
    if(length(nonZeroRows) > 0)
        temp = stateEnergy(nonZeroRows,i)
        meanStateEnergy(i) = mean(temp);
        minStateEnergy(i) = min(temp);
        maxStateEnergy(i) = max(temp);
    else
        meanStateEnergy(i) = NaN;
        minStateEnergy(i) = NaN;
        maxStateEnergy(i) = NaN;
    end
end

for i = 1:length(stateName)
    fprintf("%s Mean, min, max Energy: \t%.1f \t%.1f \t%.1f\n", stateName(i), meanStateEnergy(i), minStateEnergy(i), maxStateEnergy(i));
end
