Ilodie

function	Data = functionReadAirfoilData(file)

% This Matlab function reads airfoil coordinates files from uiuc web site 
% http://www.uiuc.edu/ph/www/m-selig/ads/coord_database.html
%
% The Input is the name file you want to study : (for example)
%		file='b737a.dat';
%		Data = functionReadAirfoilData(file);
% The produced Output is a matlab structure : 
% Data.title 		= 'BOEING 737 ROOT AIRFOIL'	% first file line : airfoil name
% Data.x_upper 		= [23x1 double]				% undimensionless upper airfoil abscisse.
% Data.y_upper 		= [23x1 double]				% undimensionless upper airfoil data : 
%												% y_upper = y_upper(x_upper)
% Data.x_lower 		= [23x1 double]				% undimensionless lower airfoil abscisse.
% Data.y_lower 		= [23x1 double]				% undimensionless lower airfoil data : 
%												% y_lower = y_lower(x_lower)
% Data.thickness_chord	= 0.1537					% ratio : max airfoil thickness / Chord
%
% If you want to plot airfoil, do :
%		figure(1)
%		hold on,
%		plot(Data.x_upper,Data.y_upper)
%		plot(Data.x_lower,Data.y_lower)
%		axis([0 1 -0.5 0.5])
%		title(Data.title)
%
% made by Élodie Roux from Toulouse (april 2002)

fid=fopen(file);

Data.title = fgetl(fid);
tamp = fgetl(fid);	% number of data
clear tamp

% empty line
tamp=fgetl(fid);
clear tamp 

% upper airfoil data start here
i=1;
while 1
	tline = fgetl(fid);
	if isempty(str2num(tline)), break, end
	tamp(i,:) = tline;
	i=i+1;
end
tamp=str2num(tamp);
Data.x_upper = tamp(:,1);
Data.y_upper = tamp(:,2);
clear tamp

% lower airfoil data start here
i=1;
while 1
	tline = fgetl(fid);
	if size(tline,2)==1, break, end	% stop at the file's end
	tamp(i,:) = tline;
	i=i+1;
end
tamp=str2num(tamp);
Data.x_lower = tamp(:,1);
Data.y_lower = tamp(:,2);
clear tamp
clear i

fclose(fid);

x=[0:0.01:1];
flddkfl=spline(Data.x_upper,Data.y_upper,x)-spline(Data.x_lower,Data.y_lower,x);
[Data.thickness_chord pos]= max(flddkfl);
Data.xthickness_chord=x(pos);