function [X,Y,C]=open_dat_file()

% We need to specify the size of the computational domain, as this can't be
% inferred from the datafile.

Nx=201;
Ny=101;

% Here I create a character array called "filename".  This should
% correspond to the name of the Fortran-generated file.

filename='oned.dat';

% Here is the number of lines in the datafile.
n_lines=Nx*Ny;

% Open the file.  Here, fid is a label that labels which line in the file
% is being read.  Obviously, upon opening the file, we are at line 1.

fid=fopen(filename);

% Preallocate some arrays for storing the data.

X=0*(1:n_lines);
Y=0*(1:n_lines);
C=0*(1:n_lines);

% Loop over all lines.

for i=1:n_lines
    % Grab the data from the current line.  Once the data is grabbed, the
    % label fix automatically moves on to the next line.
    % The data from the current line is grabbed into a string - here called
    % c1.
    c1=fgetl(fid);

    % Next I have to convert the three strings on any given line into three
    % doubles.  This is done by scanning the string into an array of
    % doubles, using the "sscanf" command:
    vec_temp=sscanf(c1,'%f');
    
    % Now it is simple: just assign each double to a value x, y, or C.
    x_temp=vec_temp(1);
    y_temp=vec_temp(2);
    C_temp=vec_temp(3);
    
    % Read the x-, y-, and C-values into their own arrays.
    X(i)=x_temp;
    Y(i)=y_temp;
    C(i)=C_temp;
end

% Finally, reshape these arrays into physical, two-dimensional arrays.

X=reshape(X,Nx,Ny);
Y=reshape(Y,Nx,Ny);
C=reshape(C,Nx,Ny);

% Important! Close the file so that it is not left dangling.  Not closing a
% file properly means that in future, it will be difficult to manipulate
% it.  For example, it is impossible to delete or rename a a currently-open
% file.

fclose(fid);
    
end