0001 function [EMSE] = emse_read_avg(filename)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 ver = '$Revision: 1.1 $';
0029 fprintf('EMSE_READ_AVG [v %s]\n',ver(11:15));
0030
0031 [path,name,ext] = fileparts(filename);
0032 file = fullfile(path,[name ext]);
0033
0034 if exist(file) ~= 2,
0035 lookfile = which(file);
0036 if isempty(lookfile),
0037 msg = sprintf('Cannot locate %s\n', filename);
0038 error(msg);
0039 else
0040 file = lookfile;
0041 end
0042 end
0043
0044 fprintf('...reading: %s\n', file);
0045
0046 fid = fopen(file);
0047
0048 version = fscanf(fid,'%d',1);
0049 file_type = fscanf(fid,'%d',1);
0050 minor_rev = fscanf(fid,'%d',1);
0051
0052 if isempty(version),
0053 EMSE.channels = [];
0054 EMSE.pnts = [];
0055 EMSE.rate = [];
0056 EMSE.xmin = [];
0057 EMSE.volt = [];
0058 fprintf('...this is not an EMSE file.\n...it might be a Neuroscan file.\n');
0059 return
0060 end
0061
0062 fprintf('...Version = %d, File-Type = %d, Minor_Revision = %d\n',...
0063 version,file_type,minor_rev);
0064
0065 unknown = fscanf(fid,'%d',1);
0066 channels = fscanf(fid,'%d',1);
0067 points = fscanf(fid,'%d',1);
0068 samples = fscanf(fid,'%f',1) * 1000;
0069 unknown = fscanf(fid,'%f',1);
0070 baseline = fscanf(fid,'%f',1) * -1000;
0071 unknown = fscanf(fid,'%d',1);
0072 unknown = fscanf(fid,'%d',1);
0073
0074
0075 fprintf('...Sample Rate (msec) = %6.3f, Baseline (msec) = %6.3f\n',...
0076 samples,baseline);
0077
0078 for i = 1:channels,
0079 discard = fscanf(fid,'%d',2)';
0080 end
0081
0082 volt = zeros(points,channels);
0083
0084 for i = 1:points,
0085 volt(i,:) = fscanf(fid,'%f',channels)';
0086 end
0087
0088 fclose(fid);
0089
0090 fprintf('...Points (rows) = %d, Channels (cols) = %d\n',points,channels);
0091
0092 EMSE.channels = channels;
0093 EMSE.pnts = points;
0094 EMSE.rate = samples;
0095 EMSE.xmin = baseline;
0096 EMSE.volt = volt;
0097
0098 return