finfo.m 1.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
function [fileType, openAction, loadAction, description] = finfo(varargin)

% <ITA-Toolbox>
% This file is part of the ITA-Toolbox. Some rights reserved.
% You can find the license for this m-file in the license.txt file in the ITA-Toolbox folder.
% </ITA-Toolbox>


%% Check if file exists and get correct path
filename = varargin{1};
fid = fopen(filename, 'r');
if (fid == -1)
    if ~isempty(dir(filename))
        error('MATLAB:fileOpen', ['Can''t open file "%s" for reading;\nyou' ...
            ' may not have read permission.'], ...
            filename);
    else
        error('MATLAB:fileOpen', 'File "%s" does not exist or is not in path.', filename);
    end
    
else
    % File exists.  Get full filename.
    filename = fopen(fid);
    fclose(fid);
end

[filepath,filename,fileext] = fileparts(filename);
if isempty(filepath)
    filename = which([filename,fileext]);
else
    filename = fullfile(filepath,[filename,fileext]);
end

%% Get readable audio files
persistent extensionMap;
if isempty(extensionMap)
    [pathstr, name] = fileparts(which('ita_read.m'));
    extensionMap = ita_io_get_daughter(pathstr, name);
end

%% If file is a readable audio file, call ita_read
[~,~,fileType] = fileparts(varargin{1});
if any(strcmpi(fileType, extensionMap(:,1))) || ...   % ita read files
        any(strcmpi(['.' fileType], extensionMap(:,1)))
    openAction = 'ita_read_doubleclick';
    loadAction = 'ita_read_doubleclick';
    description = 'ITA file';
else
    % Move to original finfo folder and run it
    oldPath = pwd;
    path = fileparts(which('general/finfo.m'));
    cd(path)
    [fileType, openAction, loadAction, description] = finfo(filename,varargin{2:end});
    cd(oldPath)
end
end