function [data,failed] = read_opt (data,opt_file)
% readINI: read inputs from INI file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% open file
fid=fopen(opt_file,'r');

% initalize variables
data.config.accel_axis_names=[];
data.config.accel_axis_name_label=[];
data.config.accel_axis_locations=[];
data.config.accel_axis_location_label=[];

% read from file
i=0;
eof=0;
readline=fgetl(fid);
while (eof==0)
   i=i+1;
   
   if (isempty(readline)==0)
      if (strcmp(readline(1),'%')==0)
         j01=findstr(readline,'=');
         if (isempty(j01)==0)
            j02=findstr(readline,'%');
            if (isempty(j02)==0)
               readline=readline(1:(j02(1)-1));
            end;
            variable=readline(1:(j01(1)-1));
            value=readline((j01(1)+1):end);
            
            if (strcmpi(variable,'accel_axis_names')==1)
               data.config.accel_axis_names=eval(value);
            elseif (strcmpi(variable,'accel_axis_name_label')==1)
               data.config.accel_axis_name_label=eval(value);
            elseif (strcmpi(variable,'accel_axis_locations')==1)
               data.config.accel_axis_locations=eval(value);
            elseif (strcmpi(variable,'accel_axis_location_label')==1)
               data.config.accel_axis_location_label=eval(value);
            else
               fprintf('Invalid input variable: %s! (value: %s)\n',variable,value);
            end;
         end;
      end;
   end;
   
   eof=feof(fid);
   if (eof==0)
      readline=fgetl(fid);
   end;
end;

% close file
fclose(fid);

% check that all variables have been set
if ((isempty(data.config.accel_axis_names)==1)|(isempty(data.config.accel_axis_name_label)==1)|...
      (isempty(data.config.accel_axis_locations)==1)|(isempty(data.config.accel_axis_location_label)==1))
   err_text='Not all of the options variables have been set!';
   fault(err_text);
   failed=1;
else
   failed=0;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;
