function waitsimready(donefile, wait_time)
% WAITSIMREADY(donefile, wait_time)
% This function checks for the existence of donefile, which is created when
% the target HDL simulator is ready. The process is repeated every 5
% seconds until the specified wait_time is reached. wait_time is defined in
% minutes.

%   Copyright 2007-2011 The MathWorks, Inc.
%     


% Store the present date/time
start_time = now; 

while (exist(donefile, 'file') ~= 2)

    disp('Waiting for the HDL simulator to initialize...');
    pause(5);
    % Check total wait time in minutes
    run_time = rem(now-start_time, 1)*24*60;
    if (run_time > wait_time)
        error(message('hdlcoder:hdlcoderdemos:nohdlsimulator', num2str( wait_time )));
    end

end

pause(1); % Wait 1 second for simulator return delay
disp('HDL simulator initialized.');
