function cannon(filename)
%cannon(filename)
%
%  Description:
%
%    Calculate the distance of a projectile fired from a cannon by reading
%    the velocity and angle from a text input file and writing the distance
%    to a text output file.
%
%  Inputs:
%
%    filename = character string of an existing input file
%
%  Outputs:
%
%    The distance is written to a text output file named 'cannon.out'
%
%  Contact:
%
%    Bob Cochran
%    Applied CHT
%    rjc@heattransfer.org
%
%  History:
%
%    Who    Date   Version  Note
%    ---  -------- -------  -----------------------------------------------
%    RJC  05/27/17  0.1.0   Initial release.
%
%==========================================================================

velocity = NaN;  % (m/sec) first line of the input file
angle    = NaN;  % (degrees) second line of the input file

%  Open the input file and read the velocity and angle

fileID   = fopen(filename,'r');
velocity = fscanf(fileID,'%f',1);
angle    = fscanf(fileID,'%f',1);
fclose(fileID);

%  Calculate the distance of the projectile

g = 9.8;  % (m^2/sec)
distance = (2*velocity^2*sind(angle)*cosd(angle))/g; % (m)

%  Open the output file and write the solution

fileID = fopen('cannon.out','w');
fprintf(fileID,'  %16.9e\n',distance);
fclose(fileID);

end