Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

isfeof(fid)
function response = isfeof(fid)
% ISFEOF says if an open file is a the end or not - feof is only updated
% when the file is opened, and this is a far more robust version.

% checks the number of arguments
error(nargchk(1, 1, nargin))

% fids must all be valid
if any(~isfid(fid))
    % errors
    error('All of the file IDs must be valid and open.')
end

% pre-forms the response
response = false(size(fid));

% gets the current indicator
position = arrayfun(@ftell, fid);;

% reads out the remainder of the file
arrayfun(@fread, fid, 'UniformOutput', false);

% gets the new position indicator
endPosition = arrayfun(@ftell, fid);

% navigates back to the old position
seekStatus = arrayfun((@(x, y) fseek(x, y, 'bof')), fid, position);

% if the two positions are the same, then it is at the end position
response = position == endPosition;

% checks if it navigated back correctly
if any(seekStatus == -1)
    % gives a warning
    warning('isfeof:returnSeek', 'Did not navigate back to the original position in at least one file.')
end

% % for each fid...
% for m = 1:numel(fid)
%     % gets the current indicator
%     position = ftell(fid(m));
%     
%     % reads out the remainder of the file
%     fread(fid(m));
%     
%     % gets the new position indicator
%     endPosition = ftell(fid(m));
%     
%     % navigates back to the old position
%     seekStatus = fseek(fid(m), position, 'bof');
%     
%     % if the two positions are the same, then it is at the end position
%     response(m) = position == endPosition;
%     
%     % checks if it navigated back correctly
%     if seekStatus == -1
%         % gives a warning
%         warning('isfeof:returnSeek', 'Did not navigate back to the original position in the file.')
%     end
% end        

Contact us