function [STIM]=ImportStrangeFormat(filename)

% function ImportStrangeFormat(filename)
%
% it reads a text file and displays it on screen
%
% INPUT : filename = a string containing the file name
% OUTPUT: STIM = is a vector of struct containing the following fields
% : nStim = stimulus number
% : MPos = Matrix 2 x Npos of mouse clicks
% : time = vector 1 x Npos of time for each click
% Author: Borgo, Soranzo, Grassi 2010

try
    fid=fopen(filename); % open file
    if fid == -1 % it can be not possible
        disp(sprintf('Unable to write file ''%s'' ',filename));
    else % in this case file opens correctly
        NStmp=0;
        while ~feof(fid) % Start loop. End if eof is reached
            NStmp=NStmp+1; % Update the number of NStmp
            sn=textscan(fid,'Stimulus number: %d'); % read the line
            STIM(NStmp).nStim=sn{1}; % Save the stimulus number
            fgetl(fid); % jump a line
            STIMtemp=textscan(fid,'\t %4d \t \t x=%4.0f y=%4.0f');
            STIM(NStmp).time=STIMtemp{1}; % Create the struct vect
            STIM(NStmp).MPos=[STIMtemp{2}, STIMtemp{3}];
        end
        fclose(fid); % close the file
    end
catch
    fclose(fid);
    disp('Something wrong happened');
end