function [dat, titles] = read_fluent_ascii(fname)
% Function to read the ascii comma-separated-value file exported from
% FLUENT named fname.
%
% Input:
% fname - Character string of file name of exported data. May be either a
% complete path, or a single file name (the latter only if the
% file is located in the current work directory
%
% Output:
% dat - Double-precision real of size [num_nodes,num_variables]
% containing the values of the exported data. The first two
% columns are the x and y locations of the nodes, respectively.
% num_nodes is the total number of nodes in the exported data.
% num_variables is the total number of variables in the data.
% titles - Array of strings of size [num_variables] containing a
% FLUENT-provided character string corresponding to each variable
% in the exported data.
fid = fopen(fname);
tline = fgetl(fid);
str = strread(tline,'%s','delimiter',',');
titles = str;
n = length(titles);
done = 0;
max_nodes = 2e6;
dat = zeros(max_nodes,n);
i = 0;
while done == 0
tline = fgetl(fid);
if tline == -1
done = 1;
else
i = i + 1;
if i > max_nodes
disp('Error: increase value of max_nodes');
return;
end
dat(i,:) = strread(tline,'%f','delimiter',',');
end
end
fclose(fid);
nnodes = i;
dat = dat(1:nnodes,:);