% IAP 2006 Introduction to MATLAB
% Programming
% CC Violeta Ivanova, MIT Information Services and Technology

% EXAMPLE 3 Orbital Velocity - An Interactive Program
% An interactive program that uses this script M-file and the function
% orbitalvelocity defined in the function M-file orbitalvelocity.m.

% This example uses the same data as Exercise Two in Session 1: Interface
% and Basics, and is based on NASA's educational web site:
% http://exploration.grc.nasa.gov/education/rocket/rktrflght.html

% A. Get input from the Command Window

disp('This program computes circular orbital velocity.')

% A1. Get input about the units for calculation

units = input('What units? E for English or M for metric: ', 's');

if isempty(units)
    units = 'm';
    disp('The program will use default metric units.')

else 
    units = lower(units);
    
    switch units
        case {'m', 'metric'}
            units = 'm';
            disp('The program will use metric units.')
        case {'e', 'english'}
            units = 'e';
            disp('The program will use English units.')
        otherwise 
            error('Unsupported units.')
    end
end

% A2. Get input about the planet 

disp ('1. Earth')
disp ('2. Mars')

planet = input('Which planet: ', 's');

if isempty(planet)
    planet = 'Earth';
    disp('Assuming planet Earth ...')

else 
    planet = lower(planet);
    
    switch planet
        
        case {'1', 'earth'}
            planet = 'Earth';
            if strcmp(units, 'm')
                Re = 6376; g0 = 9.814;
                disp('Computing for planet Earth in metric units ...')
            else
                Re = 3963; g0 = 32.2;
                disp('Computing for planet Earth in English units ...')
            end

        case {'2', 'mars'}
            planet = 'Mars';
            if strcmp(units, 'm')
                Re = 3396; g0 = 3.688;
                disp('Computing for planet Mars in metric units ...')
            else
                Re = 2111; g0 = 12.1;
                disp('Computing for planet Mars in English units ...')
            end
            
        otherwise 
            Re  = input('Enter mean radius of the planet: ');
            g0 = input('Enter gravitational constant of the planet: ');
            if (Re <= 0 || g0 <= 0)
                error('Impossible values for Re or g0.')
            end
    end
end

% A3. Get input about the altitude H

altitude = input('What altitude above the planet: ');

% B. Compute the orbital velocity

V = orbitalvelocity(Re, g0, altitude, units);

% B1. Add the code to include the Moon in the options above
% Re and g0 for the Moon are as follows:
% In metric units: Re = 1736 and g0 = 1.615.
% In English units: Re = 1079 and g0 = 5.3.
% YOU HAVE TO ADD YOUR CODE AMONG THE LINES ABOVE

