function sData = som_read_data(filename, varargin)
%SOM_READ_DATA Read data from an ascii file in SOM_PAK format.
%
% sD = som_read_data(filename, dim, [missing])
% sD = som_read_data(filename, [missing])
%
% sD = som_read_data('system.data');
% sD = som_read_data('system.data',10);
% sD = som_read_data('system.data','*');
% sD = som_read_data('system.data',10,'*');
%
% Input and output arguments ([]'s are optional):
% filename (string) input file name
% dim (scalar) input space dimension
% [missing] (string) string which indicates a missing component
% value, 'NaN' by default
%
% sD (struct) data struct
%
% Reads data from an ascii file. The file must be in SOM_PAK format,
% except that it may lack the input space dimension from the first
% line.
%
% For more help, try 'type som_read_data' or check out online documentation.
% See also SOM_WRITE_DATA, SOM_READ_COD, SOM_WRITE_COD, SOM_DATA_STRUCT.
%%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% som_read_data
%
% PURPOSE
%
% Reads data from an ascii file in SOM_PAK format.
%
% SYNTAX
%
% sD = som_read_data(filename)
% sD = som_read_data(..., dim)
% sD = som_read_data(..., 'missing')
% sD = som_read_data(..., dim, 'missing')
%
% DESCRIPTION
%
% This function is offered for compatibility with SOM_PAK, a SOM software
% package in C. It reads data from a file in SOM_PAK format.
%
% The SOM_PAK data file format is as follows. The first line must
% contain the input space dimension and nothing else. The following
% lines are comment lines, empty lines or data lines. Unlike programs
% in SOM_PAK, this function can also determine the input dimension