%Burst at 106,000 ft
%This program was not created before the launch, following data is
%guesswork:
%Balloon Temp: assumed to be atmosphereic
%Tank pressure: one tank was close to empty, (500 psi or lower) the other
%tank wasn't quite full (2300 psi or less)
%Atmosphereic Data from wunderground.com the day of
%Payload data: guesswork of what flew
%% Lifting payload Approximation
close all
clear all
%Constants
PapPSI = 6894.75728; %Pascals per PSI
lbpN = 4.4482216283; %pounds per Newton
Rbar = 8314.4598; %m^3 Pa K^-1 Kmol^-1 (Liter-kPa interchangable)
PapHg = 3386.3886667; %Pascals per inch mercery

%Air Metrics
Lalt = 175; %meters
AirTemp = ((57 - 32)*5/9)+273.15; %Degrees Fahrenheit 
AirPres = 30.42 *PapHg; %inches Hg converted to Pa
[PAlt] = AltAdjust(Lalt,AirPres);

%Ballon Metrics
tanks = [2250 100; 400 100]*PapPSI; %pressure difference PSI converted to Pa
BP = AirPres; % The balloon pressure is assumed to be atmosphereic at filling
BalloonTemp =(( 62 -32)*5/9+273.15); %degrees Fahrenheit converted to Kelvin

%Calculations
pair = (AirPres)*28.97/( AirTemp*Rbar);
[lift Vballoon] = balloonlift(tanks,BP,BalloonTemp,pair,AirTemp);
liftweight = lift/lbpN;

%% Fill to lift payload
payload = (2.99+2.4+2.5+3.5)*1.1; %pounds
payNew = payload*lbpN; %converting Payload from lbs to Newtons
Pend = balloonpressure(payNew,BP,BalloonTemp,pair)/PapPSI; %answer in Pascals, converted to PSI


%% Balloon Drag and Assent Rate
difflift = liftweight-payload;

%% Balloon Burst Altitude
Dburst = [10.5:.01:11]; %burst diameter in meters
alt = balloonburst(Dburst,Vballoon,BP,BalloonTemp);
feet = (alt+(PAlt))*3.280839895; 

figure(1)
hold on
plot(Dburst,feet,'r')
grid on 
hold off

%% Results
liftweight
Pend 
difflift

%% Bach's Box Burst Calculation

BachP = 0; %Pressure in Pascals converted from torr
BachT = 0+273.15; %Tempurature converted to Kelvin
BachV = Vballoon*(BP)/(BachP)*(BachT)/(BalloonTemp); %Calculation of Pressure
BachD = 2*(3/4*BachV/pi)^(1/3);

%% Additional Analysis
DensityAltitude = 0;
tankP = (2250-100+ 400-100)*PapPSI;
HeMass = HeliumMass(tankP,295);
MassAlt = burstmass(11,HeMass);
Massfeet =(MassAlt+DensityAltitude)*3.280839895
