Home > NoiseTools > nt_read_header.m

nt_read_header

PURPOSE ^

[h,readwith]=nt_read_header(fname,flag) - read data from file

SYNOPSIS ^

function [h,readwith]=nt_read_header(fname)

DESCRIPTION ^

[h,readwith]=nt_read_header(fname,flag) - read data from file

  h: header
  readwith: fieldtrip or biosemi
 
  fname: file to read

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [h,readwith]=nt_read_header(fname)
0002 %[h,readwith]=nt_read_header(fname,flag) - read data from file
0003 %
0004 %  h: header
0005 %  readwith: fieldtrip or biosemi
0006 %
0007 %  fname: file to read
0008 %
0009 %
0010 if nargin < 1 ; error('!'); end
0011 if ~isa(fname, 'char'); 
0012     error('filename is not char string');
0013 end
0014 
0015 [PATHSTR,NAME,EXT] = fileparts(fname);
0016 if isempty(PATHSTR); 
0017     fname=[pwd,filesep,fname]; % safe to use exist
0018 end
0019 
0020 if 7==exist(fname);
0021     disp(fname);
0022     error('...is directory!')
0023 end
0024 
0025 if exist(fname,'file')~=2; 
0026     disp(fname)
0027     error('...not found');
0028 end
0029 
0030 if numel(fname)>4 & fname(end-3:end)=='.mat' % intercept matlab files
0031     disp(fname)
0032     error('...is mat file');
0033 end   
0034          
0035 % select file reader among those available
0036 persistent nt_read_header_readwith
0037 if isempty(nt_read_header_readwith)
0038     if 2==exist('ft_read_header');
0039         nt_read_header_readwith='fieldtrip';
0040     else
0041         warning('function ft_read_header() not found: download FieldTrip and/or adjust path');
0042     end
0043 end
0044 if isempty(nt_read_header_readwith)
0045     if 2==exist('sopen');
0046         nt_read_header_readwith='biosig';
0047     else
0048         warning('function sopen() not found: download BIOSIG and/or adjust path');
0049     end
0050 end
0051 if isempty(nt_read_header_readwith); error('no reading functions available'); end
0052 
0053 % read the header
0054 if strcmp(nt_read_header_readwith,'fieldtrip');
0055     try
0056         h=ft_read_header(fname);
0057     catch
0058         h=[];
0059     end
0060 else
0061     try
0062         h=sopen(fname);
0063         sclose(h);
0064     catch
0065         h=[];
0066     end
0067 end
0068 
0069 readwith=nt_read_header_readwith;
0070

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005