% File: lab1.m (Solution of BE-205 Lab 1 (van der Waals equation)  
%
% Purpose
%
% Calculate the pressure of a specified gas given its molar volume and
% pressure.
%
% Pre and Post Conditions
%
% Existance of files (including formats), etc.
%
% User Input(s)
%
% Selected gas, molar volume (l/mole) and temperature (degrees C).
%
% Displayed Output(s)
%
% Calculated pressure and warning message if pressure exceeds specified
% value.
%
% Selected Variables Used
%
% gas -- Cell array of gas name strings.
% a -- van der Waals a constants (l^2*atm/mole^2).
% b -- van der Waals a constants (l/mole).
% s -- Response from gas selection menu (1 to number of gasses).
% prompt -- Cell array of prompt strings.
% answer -- Cell array of user response strings.
% vol -- User entered molar volume as a double (l/mole).
% temp -- User entered temperature as a double (deg. C).
% pres -- Calculated preessure (atm).
%
% Revision History
%
% Created 12/8/06 by Dr. C. S. Tritt

% Store constants

gas = {'Helium', 'Hydrogen', 'Oxygen'};
a = [ 0.0341 0.244 1.36 ];
b = [ 0.0237 0.0266 0.0318];

%Prompt for and get user input.

s = menu('Select a Gas', gas(1), gas(2), gas(3));

prompt{1} = 'Volume (liters/mole): ';
prompt{2} = 'Temperature (deg. C): ';
answer = inputdlg(prompt, 'Enter Gas Conditions');

% Extract volume and temperature from user input.

vol = str2double(answer{1});
temp = str2double(answer{2}) + 273.15; % Convert from deg. C to K.

% Call function to compute pressure (atm)

pres = vdweqs(vol, temp, a(s), b(s));

% Display results (including warning).

if pres > 1
    out_string = sprintf( ...
    'Calculated pressure (%.2f atm) exceeds safe limits.!', pres);
else 
    out_string = sprintf('Calculated pressure %.4f atm.', pres);
end

msgbox(out_string, 'van der Waals Results');