Home > atmlab > handy > wait_for_existence.m

wait_for_existence

PURPOSE ^

wait_for_existence Wait until a particular file exists

SYNOPSIS ^

function found = wait_for_existence(file, timeout, varargin)

DESCRIPTION ^

 wait_for_existence Wait until a particular file exists

 This m-file waits until a particular file exists. It returns at the
 timeout or when the file exists. Since this is implemented in pure Matlab
 and Matlab does not support interrupts, it actually waits small amounts
 of time and then checks whether the file exists, so it may wait a
 little bit longer tahn necessary.

 FORMAT

   wait_for_existence(file, timeout)

 IN

   file        string      /path/to/file
   timeout     number      maximume time to wait
   step        number      (optional) timestep

 OUT

   found       logical     true if file was found, false otherwise

 $Id: wait_for_existence.m 6608 2010-10-27 18:25:56Z gerrit $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

wait_for_existence.m

SOURCE CODE ^

0001 function found = wait_for_existence(file, timeout, varargin)
0002 
0003 % wait_for_existence Wait until a particular file exists
0004 %
0005 % This m-file waits until a particular file exists. It returns at the
0006 % timeout or when the file exists. Since this is implemented in pure Matlab
0007 % and Matlab does not support interrupts, it actually waits small amounts
0008 % of time and then checks whether the file exists, so it may wait a
0009 % little bit longer tahn necessary.
0010 %
0011 % FORMAT
0012 %
0013 %   wait_for_existence(file, timeout)
0014 %
0015 % IN
0016 %
0017 %   file        string      /path/to/file
0018 %   timeout     number      maximume time to wait
0019 %   step        number      (optional) timestep
0020 %
0021 % OUT
0022 %
0023 %   found       logical     true if file was found, false otherwise
0024 %
0025 % $Id: wait_for_existence.m 6608 2010-10-27 18:25:56Z gerrit $
0026 
0027 timestep = optargs(varargin, {0.1});
0028 t = 0;
0029 found = true;
0030 while ~exist(file, 'file')
0031     t = t + timestep;
0032     if t>=timeout
0033         found = false;
0034         break
0035     end
0036     pause(timestep)
0037 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005