TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
fltopen.m
Go to the documentation of this file.
1 function [HDR]=fltopen(arg1,arg3,arg4,arg5,arg6)
2 % FLTOPEN opens FLT file
3 % However, it is recommended to use SOPEN instead .
4 % For loading whole data files, use SLOAD.
5 %
6 % see also: SOPEN, SREAD, SSEEK, STELL, SCLOSE, SWRITE, SEOF
7 
8 % HDR=fltopen(HDR);
9 
10 % $Id: fltopen.m 2663 2011-04-01 15:04:08Z schloegl $
11 % Copyright (c) 2006,2007,2008,2009 by Alois Schloegl <a.schloegl@ieee.org>
12 % This is part of the BIOSIG-toolbox http://biosig.sf.net/
13 
14 % This program is free software; you can redistribute it and/or
15 % modify it under the terms of the GNU General Public License
16 % as published by the Free Software Foundation; either version 3
17 % of the License, or (at your option) any later version.
18 
19 if isstruct(arg1),
20  HDR=arg1;
21 else
22  FILENAME=arg1;
23  HDR.FileName = FILENAME;
24  [pfad,file,FileExt] = fileparts(HDR.FileName);
25  HDR.FILE.Name = file;
26  HDR.FILE.Path = pfad;
27  HDR.FILE.Ext = FileExt(2:length(FileExt));
28  HDR.FILE.PERMISSION = 'r';
29  HDR.FILE.stdout = 1;
30  HDR.FILE.stderr = 2;
31 end;
32 
33 
34 if any(HDR.FILE.PERMISSION=='r'),
35  %%%%% READ HEADER
36 
37  fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.hdr']),'rt');
38  [r,c] = fread(fid,[1,inf],'uint8');
39  fclose(fid);
40 
41  r = char(r);
42  HDR.H1 = r;
43  HDR.SampleRate = 1;
44  FLAG.BioSig = 0; FLAG.LockBioSig = 0;
45  %HDR.FLT.remark = 'Do Not Modify !!!';
46  HDR.FLT = [];
47 
48  r0 = r;
49  hdr = '';
50  while any(r0=='['); %~strcmp(hdr,'System'),
51  [t1,r0] = strtok(r0,'['); % search begin of section
52  [hdr,body] = strtok(t1,']'); % search end of section header
53  body = strtok(body,'[]');
54  b = [];
55 
56  while any(body=='=')
57  [tline,body] = strtok(body,[10,13]);
58  [tok1,left1] = strtok(tline,['=']);
59  [tok2,left2] = strtok(left1,[10,13,'=']);
60  if 0,
61  elseif strncmp(tok1,'*',1);
62  elseif ~any(tline=='='),
63  elseif any(tok2=='{');
64  [tok,block]=strtok(body,'{}');
65  b = setfield(b,tok1,tok);
66  body = body(min(find(body=='}'))+1:end);
67  else
68  [num,v,sa] = str2double(tok2);
69  if v,
70  b = setfield(b,tok1,tok2);
71  else
72  b = setfield(b,tok1,num);
73  end;
74  end;
75  end;
76  HDR.FLT = setfield(HDR.FLT,hdr,b);
77  end;
78 
79  HDR.SPR = HDR.FLT.Dataformat.number_of_samples;
80  HDR.NRec = 1;
81  HDR.NS = HDR.FLT.System.number_of_channels;
82  [n,v,sa]=str2double(HDR.FLT.System.parameter_of_sensors);
83  %HDR.FLT.System = rmfield(HDR.FLT.System,'parameter_of_sensors');
84  HDR.FLT.sensors.id = n(:,1);
85  HDR.FLT.sensors.name = sa(:,2);
86  HDR.FLT.sensors.type = n(:,3);
87  HDR.FLT.sensors.mod = n(:,4);
88  HDR.FLT.sensors.XYZabcArea = n(:,5:11);
89 
90 % HDR.FLT.sensors.id(n(:,1)+1,1) = n(:,1);
91 % HDR.FLT.sensors.name(n(:,1)+1,:) = sa(:,2);
92 % HDR.FLT.sensors.type(n(:,1)+1,:) = n(:,3);
93 % HDR.FLT.sensors.mod(n(:,1)+1,:) = n(:,4);
94 % HDR.FLT.sensors.XYZabcArea(n(:,1)+1,:) = n(:,5:11);
95 
96  [n,v,sa]=str2double(HDR.FLT.System.parameter_of_groups);
97 % HDR.FLT.System = rmfield(HDR.FLT.System,'parameter_of_groups');
98  HDR.FLT.groups.id = n(:,1);
99  HDR.FLT.groups.usage = n(:,2);
100  HDR.FLT.groups.name = sa(:,3);
101  HDR.FLT.groups.unit = sa(:,4);
102  HDR.FLT.groups.unit_exp = n(:,5);
103  HDR.FLT.groups.calib = n(:,6);
104  Cal_Group(n(:,1)+1) = n(:,6).*10.^n(:,5);
105  PhysDim_Group(n(:,1)+1) = sa(:,4);
106 
107  [n,v,sa]=str2double(HDR.FLT.System.parameter_of_modules);
108  HDR.FLT.System = rmfield(HDR.FLT.System,'parameter_of_modules');
109  HDR.FLT.modules.id = n(:,1);
110  HDR.FLT.modules.name = sa(:,2);
111  HDR.FLT.modules.XYZabc = n(:,3:8);
112  HDR.FLT.modules.unit = n(:,9);
113  HDR.FLT.modules.exp = n(:,10);
114  HDR.FLT.modules.unitname = sa(:,11);
115 
116  [tline,tch] = strtok(HDR.FLT.System.parameter_of_channels,[10,13]);
117  HDR.FLT.System = rmfield(HDR.FLT.System,'parameter_of_channels');
118  K = 0;
119  HDR.FLT.channels.num = repmat(NaN,HDR.NS,9);
120  HDR.FLT.channels.seq = repmat(NaN,HDR.NS,1);
121  HDR.FLT.channels.id = repmat(NaN,HDR.NS,1);
122  HDR.FLT.channels.usage = repmat(NaN,HDR.NS,1);
123  HDR.FLT.channels.cal = repmat(NaN,HDR.NS,1);
124  HDR.FLT.channels.Cal = sparse(HDR.NS,HDR.FLT.System.number_of_sensors);
125  HDR.FLT.channels.grd_mode = repmat(NaN,HDR.NS,1);
126  HDR.FLT.channels.grp_id = repmat(NaN,HDR.NS,1);
127 
128  while ~isempty(tline),
129  [n,v,sa]=str2double(tline);
130  K = K+1;
131  HDR.FLT.channels.num(K,:)=n;
132 
133  ch = n(1)+1;
134  HDR.FLT.channels.seq(ch) = n(1);
135  HDR.FLT.channels.id(ch) = n(2);
136  HDR.FLT.channels.usage(ch) = n(3);
137  HDR.Label{ch} = sa{4};
138  HDR.FLT.channels.cal(ch) = n(5);
139  HDR.FLT.channels.grd_mode(ch) = n(6);
140  HDR.FLT.channels.grd_mode_name{ch} = sa{7};
141  HDR.FLT.channels.grp_id(ch) = n(8);
142  HDR.FLT.channels.no_sensors(ch) = n(9);
143 
144  for k=1:n(9);
145  [tline,tch] = strtok(tch,[10,13]);
146  [n1,v1,sa]=str2double(tline);
147  %sen = n1(1);
148  sen = find(n1(1)==HDR.FLT.sensors.id);
149  HDR.FLT.channels.Cal(ch,sen) = n1(2);
150  if (length(sa)>=4) && ~strcmp(sa{4},HDR.FLT.sensors.name{sen}),
151  fprintf(HDR.FILE.stderr,'Warning SOPEN(ET-MEG): sensor name does not fit: %s %s. \n Maybe header of file %s is corrupted!\n',sa{4},HDR.FLT.sensors.name{sen}, HDR.FileName);
152  end;
153  end;
154  [tline,tch] = strtok(tch,[10,13]);
155  end;
156 
157  if isfield(HDR.FLT.Header,'name_of_data_file');
158  if exist(fullfile(HDR.FILE.Path,HDR.FLT.Header.name_of_data_file)),
159  HDR.FLT.datafile = HDR.FLT.Header.name_of_data_file;
160  end;
161  end;
162  if HDR.FLT.Dataformat.type(1)<10;
163  HDR.Endianity = 'ieee-be';
164  else
165  HDR.Endianity = 'ieee-le';
166  end;
167  switch mod(HDR.FLT.Dataformat.type(1),10)
168  case 1,
169  HDR.GDFTYP = 1;
170  case 2,
171  HDR.GDFTYP = 3;
172  case 3,
173  HDR.GDFTYP = 5;
174  case 4,
175  HDR.GDFTYP = 16;
176  case 5,
177  HDR.GDFTYP = 17;
178  otherwise
179  fprintf(HDR.FILE.stderr,'Error SOPEN(FLT): type %i not supported',type);
180  end;
181 
182  [tmp,scale] = physicalunits(HDR.FLT.Measurement.sampling_unit);
183  HDR.SampleRate = 10.^-HDR.FLT.Measurement.sampling_exponent ./ (HDR.FLT.Measurement.sampling_step.*scale);
184  tmp = [HDR.FLT.Measurement.measurement_day,' ',HDR.FLT.Measurement.measurement_time];
185  tmp (tmp=='.')=' ';
186  tmp (tmp==':')=' ';
187  HDR.T0([3,2,1,4:6]) = str2double(tmp);
188  if isfield(HDR.FLT,'Patient'),
189  HDR.Patient.Sex = 0; % unknown
190  HDR.FLT.Patient.remark = 'Do Not Modify !!!';
191  if isfield(HDR.FLT.Patient,'sex')
192  tmp = deblank(HDR.FLT.Patient.sex);
193  if length(tmp)
194  HDR.Patient.Sex = any(tmp(1)=='mM1') + 2*any(tmp(1)=='fFwW2');
195  end;
196  end;
197  if isfield(HDR.FLT.Patient,'birthday')
198  tmp = deblank(HDR.FLT.Patient.birthday);
199  tmp(tmp=='.' | tmp=='-' | tmp=='/')=' ';
200  [tmp,v,sa] = str2double(tmp);
201  if length(tmp)==3 & ~any(v),
202  HDR.Patient.Birthday(1:3) = tmp;
203  end
204  end;
205  end
206  HDR.PhysDim = PhysDim_Group(HDR.FLT.channels.grp_id+1);
207  HDR.Cal = Cal_Group(HDR.FLT.channels.grp_id+1);
208 
209  ix1 = strmatch('gr1s',HDR.FLT.channels.grd_mode_name,'exact');
210  ix2 = find(any(HDR.FLT.channels.Cal(ix1,:),1));
211  tmp = size(HDR.FLT.channels.Cal);
212  ix1 = 1:tmp(1); ix2 = 1:tmp(2);
213  grad.tra = HDR.FLT.channels.Cal;
214  grad.pnt = HDR.FLT.sensors.XYZabcArea(:,1:3);
215  grad.ori = HDR.FLT.sensors.XYZabcArea(:,4:6);
216  grad.label = HDR.Label;
217  grad.group_id = HDR.FLT.channels.grp_id;
218  HDR.MEG.grad = grad;
219 
220  %% compute HDR.ELEC.XYZ
221  cal = HDR.FLT.channels.Cal;
222  HDR.ELEC.XYZ = abs(cal)*(HDR.FLT.sensors.XYZabcArea(:,1:3));
223 
224  HDR.Calib = sparse(2:HDR.NS+1,1:HDR.NS,HDR.Cal);
225  if HDR.GDFTYP < 10,
226  FLAG = HDR.FLAG; % backup
227  HDR.FLAG.UCAL = 1; % default: no calibration information
228  % read scaling information
229  ix = strfind([HDR.FILE.Name,'.'],'.');
230  fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.calib.txt']),'r');
231  if fid < 0,
232  fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name(1:ix(1)-1),'.calib.txt']),'r');
233  end;
234  if fid>0,
235  c = fread(fid,[1,inf],'uint8=>char'); fclose(fid);
236  [n1,v1,sa1] = str2double(c,9,[10,13]);
237  %fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name(1:ix-1),'.calib2.txt']),'r');
238  %c = fread(fid,[1,inf],'uint8'); fclose(fid);
239  %[n2,v2,sa2] = str2double(c);
240  %HDR.Calib = sparse(2:HDR.NS+1,1:HDR.NS,(n2(4:131,5).*n1(4:131,3)./n2(4:131,4))./100);
241  HDR.Calib = sparse(2:HDR.NS+1,1:HDR.NS,n1(4:131,3)*1e-13*(2^-12));
242  HDR.FLAG = FLAG; % restore
243  end
244  end
245  if ~isfield(HDR,'PhysDim') & ~isfield(HDR,'PhysDimCode')
246  HDR.PhysDimCode = zeros(HDR.NS,1);
247  end;
248 
249  % read data
250  HDR.FILE.FID = -1;
251  if isfield(HDR.FLT,'datafile')
252  fn = fullfile(HDR.FILE.Path,HDR.FLT.datafile);
253  HDR.FILE.FID = fopen(fn,'rb',HDR.Endianity);
254  if HDR.FILE.FID<0
255  [p,f,e]=fileparts(HDR.FLT.datafile);
256  fn = fullfile(HDR.FILE.Path,f);
257  HDR.FILE.FID = fopen(fn,'rb',HDR.Endianity);
258  end;
259  else
260  fn = fullfile(HDR.FILE.Path,HDR.FILE.Name);
261  HDR.FILE.FID = fopen(fn,'rb',HDR.Endianity);
262  end;
263 
264  if HDR.FILE.FID>0,
265  HDR.FILE.OPEN=1;
266  fseek(HDR.FILE.FID,0,'eof');
267  HDR.FILE.size = ftell(HDR.FILE.FID);
268  fseek(HDR.FILE.FID,0,'bof');
269  else
270  fprintf(HDR.FILE.stderr,'Warning SOPEN(FLT): Binary data file %s not found!\n',fn);
271  end;
272  HDR.HeadLen = 0;
273  HDR.FILE.POS = 0;
274 
275  [datatyp,limits,datatypes,numbits,GDFTYP]=gdfdatatype(HDR.GDFTYP);
276  HDR.AS.bpb = HDR.NS*numbits/8;
277  HDR.AS.endpos = HDR.FILE.size/HDR.AS.bpb;
278 
279  % check file size
280  if (HDR.AS.bpb*HDR.NRec*HDR.SPR) ~= HDR.FILE.size,
281  % heuristic: try different data type
282  HDR.GDFTYP = 3;
283  [datatyp,limits,datatypes,numbits,GDFTYP]=gdfdatatype(HDR.GDFTYP);
284  HDR.AS.bpb = HDR.NS*numbits/8;
285  HDR.AS.endpos = HDR.FILE.size/HDR.AS.bpb;
286  end;
287  if (HDR.AS.bpb*HDR.NRec*HDR.SPR) ~= HDR.FILE.size,
288  % heuristic: try different data type
289  HDR.GDFTYP = 16;
290  [datatyp,limits,datatypes,numbits,GDFTYP]=gdfdatatype(HDR.GDFTYP);
291  HDR.AS.bpb = HDR.NS*numbits/8;
292  HDR.AS.endpos = HDR.FILE.size/HDR.AS.bpb;
293  end;
294  if (HDR.AS.bpb*HDR.NRec*HDR.SPR) ~= HDR.FILE.size,
295  fprintf(HDR.FILE.stderr,'Warning SOPEN(ET-MEG): size of file does not fit to header information\n');
296  fprintf(HDR.FILE.stderr,'\tFile:\t%s\n',fullfile(HDR.FILE.Path,HDR.FILE.Name));
297  fprintf(HDR.FILE.stderr,'\tFilesize:\t%i is not %i bytes\n',HDR.FILE.size,HDR.AS.bpb*HDR.NRec*HDR.SPR);
298  fprintf(HDR.FILE.stderr,'\tSamples:\t%i\n',HDR.NRec*HDR.SPR);
299  fprintf(HDR.FILE.stderr,'\tChannels:\t%i\n',HDR.NS);
300  fprintf(HDR.FILE.stderr,'\tDatatype:\t%s\n',datatyp);
301  HDR.SPR = floor(HDR.AS.endpos/HDR.NRec);
302  end;
303 
304 elseif any(HDR.FILE.PERMISSION=='w'),
305  fid = fopen(fullfile(HDR.FILE.Path,[HDR.FILE.Name,'.hdr']),'wt');
306  if 0, isfield(HDR,'H1')
307  % copy header
308  fwrite(fid,HDR.H1,'uint8');
309  else
310 
311  %%%%%%%% CHANNEL DATA %%%%%%%%%%%%%%%
312  if ~isfield(HDR,'AS')
313  HDR.AS.SampleRate = repmat(HDR.SampleRate,HDR.NS,1);
314  end;
315  if ~isfield(HDR.AS,'SampleRate')
316  HDR.AS.SampleRate = repmat(HDR.SampleRate,HDR.NS,1);
317  end;
318  if ~isfield(HDR,'THRESHOLD')
319  HDR.THRESHOLD = repmat(NaN,HDR.NS,2);
320  end;
321  if ~isfield(HDR.Filter,'Notch')
322  HDR.Filter.Notch = repmat(NaN,HDR.NS,1);
323  end;
324  if ~isfield(HDR,'PhysDimCode')
325  HDR.PhysDimCode = physicalunits(HDR.PhysDim);
326  end;
327  if ~isfield(HDR,'LeadIdCode')
328  HDR = leadidcodexyz(HDR);
329  end;
330  if ~isfield(HDR,'REC')
331  HDR.REC.Impedance = repmat(NaN,HDR.NS,1);
332  end;
333  if ~isfield(HDR.REC,'Impedance')
334  HDR.REC.Impedance = repmat(NaN,HDR.NS,1);
335  end;
336  if ~isfield(HDR,'Off')
337  HDR.Off = zeros(HDR.NS,1);
338  end;
339  if ~isfield(HDR,'Cal')
340  HDR.Cal = ones(HDR.NS,1);
341  HDR.Cal(HDR.InChanSelect) = diag(HDR.Calib(2:end,:));
342  end;
343  if length(HDR.Filter.HighPass)==1,
344  HDR.Filter.HighPass = repmat(HDR.Filter.HighPass,HDR.NS,1);
345  end;
346  if length(HDR.Cal)==1,
347  HDR.Cal = repmat(HDR.Cal,HDR.NS,1);
348  end;
349  if length(HDR.Filter.LowPass)==1,
350  HDR.Filter.LowPass = repmat(HDR.Filter.LowPass,HDR.NS,1);
351  end;
352  if length(HDR.Filter.Notch)==1,
353  HDR.Filter.Notch = repmat(HDR.Filter.Notch,HDR.NS,1);
354  end;
355 
356  PhysDim = physicalunits(HDR.PhysDimCode);
357  if ~isfield(HDR,'FLT'); HDR.FLT = []; end;
358 
359  %%%%%%%%% FIXED HEADER %%%%%%%%%%%%%%
360  fprintf(fid,'[Header]\n');
361  fprintf(fid,'version=2.1\nid=1\n');
362  fprintf(fid,'name=created by BioSig for Octave and Matlab http://biosig.sf.net/\n');
363  fprintf(fid,'comment= -\n');
364  fprintf(fid,'name_of_data_file=%s\n',HDR.FILE.Name);
365 
366  fprintf(fid,'\n[Dataformat]\n');
367  fprintf(fid,'* data types : HP-UX data\n');
368  fprintf(fid,'* 1=(1 byte int) 2=(2 byte int) 3=(4 byte int)\n');
369  fprintf(fid,'* 4=(4 byte float) 5=(8 byte float) 6=(ASCII)\n');
370  fprintf(fid,'* LINUX data\n');
371  fprintf(fid,'* 11=(1 byte int) 12=(2 byte int) 13=(4 byte int)\n');
372  fprintf(fid,'* 14=(4 byte float) 15=(8 byte float) 16=(ASCII)\n');
373  fprintf(fid,'version=1.0\nid=1\nname=ET-MEG double data format\n');
374  fprintf(fid,'type=14\n'); HDR.GDFTYP=16; % float32
375  if isfield(HDR,'data')
376  [HDR.SPR,HDR.NS]=size(HDR.data);
377  HDR.NRec = 1;
378  end;
379  fprintf(fid,'number_of_samples=%i\n',HDR.NRec*HDR.SPR);
380 
381  fprintf(fid,'\n[Measurement]\nversion=0.0\nlaboratory_name=%s\n',HDR.FLT.Measurement.laboratory_name);
382  fprintf(fid,'*\nmeasurement_day=%02i.%02i.%04i\n',HDR.T0([3,2,1]));
383  fprintf(fid,'measurement_time=%02i:%02i:%02i\n',HDR.T0(4:6));
384  fprintf(fid,'sampling_unit=s\n');
385  e = floor(log10(1/HDR.SampleRate));
386  fprintf(fid,'sampling_exponent=%i\n',e);
387  fprintf(fid,'sampling_step=%f\n',10^-e/HDR.SampleRate);
388 
389  if isfield(HDR,'Patient')
390  fprintf(fid,'\n[Patient]\nid= 1\nversion= 1.00\n');
391  fprintf(fid,'name= -\n'); %%% will not be supported due to privacy reasons
392  if HDR.Patient.Sex==1,
393  fprintf(fid,'sex= male\n');
394  elseif HDR.Patient.Sex==2,
395  fprintf(fid,'sex= female\n');
396  else
397  fprintf(fid,'sex= -\n');
398  end;
399  if isfield(HDR.Patient,'Birthday')
400  fprintf(fid,'birthday=%02i.%02i.%04i\n',HDR.T0([3,2,1]));
401  else
402  fprintf(fid,'birthday= -\n');
403  end;
404  end;
405 
406  fprintf(fid,'\n[System]\nversion=0.0\n');
407  fprintf(fid,'number_of_channels=%i\n',HDR.NS);
408  %fprintf(fid,'SamplingRate=%i\n',HDR.SampleRate);
409 
410 
411  fprintf(fid,'*---------------------------------------------------------------\n');
412  fprintf(fid,'*seq id u name calib grd grd_name grp n_sensors\n');
413  fprintf(fid,'*---------------------------------------------------------------\n');
414  fprintf(fid,'parameter_of_channels={\n');
415  if isfield(HDR.FLT,'channels')
416  % write original channel header
417  num = [HDR.FLT.channels.seq,HDR.FLT.channels.id,HDR.FLT.channels.usage,HDR.FLT.channels.cal,HDR.FLT.channels.grd_mode,HDR.FLT.channels.grp_id];
418  for k=1:HDR.NS,
419  ix = find(HDR.FLT.channels.Cal(k,:));
420  fprintf(fid,'%04i %04i %i %-17s %5.3f %i %-8s %04i %i\n',num(k,1:3),HDR.Label{k},num(k,4:5),HDR.FLT.channels.grd_mode_name{k},num(k,6),length(ix));
421  for k1 = 1:length(ix)
422  fprintf(fid,'\t%04i %9.6f * %s\n',ix(k1)-1,full(HDR.FLT.channels.Cal(k,ix(k1))),HDR.FLT.sensors.name{ix(k1)});
423  end;
424  end;
425  else
426  for k=1:HDR.NS,
427  fprintf(fid,'%04i %04i 1 %-16s 1.000 1 #### 0000 1\n',k-1,k-1,HDR.Label{k});
428  fprintf(fid,' %04i 1.000000 * CH%i\n',k-1,k-1);
429  end;
430  end;
431 
432  if isfield(HDR.FLT,'sensors');
433  fprintf(fid,'}\n\nnumber_of_sensors=%i\n',HDR.FLT.System.number_of_sensors);
434  else
435  fprintf(fid,'}\n\nnumber_of_sensors=%i\n',HDR.NS);
436  end;
437  fprintf(fid,'*----------------------------------------------------------------------------------------\n');
438  fprintf(fid,'*id name type mod x y z a b c area\n');
439  fprintf(fid,'*----------------------------------------------------------------------------------------\n');
440  fprintf(fid,'parameter_of_sensors={\n');
441  if isfield(HDR.FLT,'sensors');
442  for k=1:size(HDR.FLT.sensors.id,1),
443  fprintf(fid,'%04i %-10s %i %04i %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f\n',HDR.FLT.sensors.id(k),HDR.FLT.sensors.name{k},HDR.FLT.sensors.type(k),HDR.FLT.sensors.mod(k),HDR.FLT.sensors.XYZabcArea(k,:));
444  end;
445  else
446  for k=1:HDR.NS,
447  fprintf(fid,'%04i CH%-08i 1 0000 %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %11.9f\n',k-1,k-1,HDR.ELEC.XYZ(k,1:3),[NaN,NaN,NaN,NaN]);
448  end;
449  end;
450 
451  fprintf(fid,'}\n\nnumber_of_groups=%i\n',HDR.FLT.System.number_of_groups);
452  fprintf(fid,'*----------------------------------------\n');
453  fprintf(fid,'*id u name unit exp calib\n');
454  fprintf(fid,'*----------------------------------------\n');
455  fprintf(fid,'parameter_of_groups={\n');
456  if isfield(HDR.FLT,'groups')
457  for k=1:size(HDR.FLT.groups.id,1),
458  fprintf(fid,'%04i %i %-16s %-6s %i %8.3f\n',HDR.FLT.groups.id(k),HDR.FLT.groups.usage(k),HDR.FLT.groups.name{k},HDR.FLT.groups.unit{k},HDR.FLT.groups.unit_exp(k),HDR.FLT.groups.calib(k));
459  end;
460  else
461  fprintf(fid,'0001 1 ET-Mag_80WH T 0 1.000\n');
462  fprintf(fid,'0002 1 ET-AxGrd_80WH T 0 1.000\n');
463  fprintf(fid,'0003 1 ET-PlGrd_80WH T 0 1.000\n');
464  fprintf(fid,'0004 1 ET-Mag_RefCh T 0 1.000\n');
465  fprintf(fid,'0005 1 ET-AxGrd_RefCh T 0 1.000\n');
466  fprintf(fid,'0006 1 ET-PlGrd_RefCh T 0 1.000\n');
467  fprintf(fid,'0007 1 Trigger V 0 1.000\n');
468  fprintf(fid,'0008 1 EEG V 0 1.000\n');
469  fprintf(fid,'0009 1 ECG V 0 1.000\n');
470  fprintf(fid,'0010 1 Etc V 0 1.000\n');
471  fprintf(fid,'0011 0 Null_Channel V 0 1.000\n');
472  end;
473  fprintf(fid,'}\n');
474  fprintf(fid,'\nnumber_of_modules=%i\n',HDR.FLT.System.number_of_modules);
475  fprintf(fid,'*-------------------------------------------------------------------------\n');
476  fprintf(fid,'*id name x y z a b c unit exp name\n');
477  fprintf(fid,'*-------------------------------------------------------------------------\n');
478  fprintf(fid,'parameter_of_modules={\n');
479  if isfield(HDR.FLT,'modules')
480  for k=1:size(HDR.FLT.modules.id,1),
481  fprintf(fid,'%04i %-13s %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %i %s\n',HDR.FLT.modules.id(k),HDR.FLT.modules.name{k},HDR.FLT.modules.XYZabc(k,:),HDR.FLT.modules.unit(k),HDR.FLT.modules.exp(k),HDR.FLT.modules.unitname{k});
482  end;
483  fprintf(fid,'}\n');
484  else
485  fprintf(fid,'0000 Magnetic 0.000 0.000 0.000 0.000 0.000 0.000 1.000 0 m\n');
486  fprintf(fid,'0007 Electric 0.000 0.000 0.000 0.000 0.000 0.000 1.000 0 m\n}\n');
487  end;
488  end;
489  fclose(fid);
490 
491  HDR.FILE.FID = fopen(fullfile(HDR.FILE.Path,HDR.FILE.Name),'wb','ieee-le');
492  HDR.FILE.OPEN = 2;
493  HDR.HeadLen = 0;
494 
495 
496 elseif any(HDR.FILE.PERMISSION=='a'),
497  HDR.FILE.FID = fopen(fullfile(HDR.FILE.Path,HDR.FILE.Name),'ab','ieee-le');
498  HDR.FILE.OPEN = 3;
499  HDR.HeadLen = 0;
500 
501 end;
502 
gdfdatatype
function gdfdatatype(in GDFTYP)
fltopen
function fltopen(in arg1, in arg3, in arg4, in arg5, in arg6)
physicalunits
function physicalunits(in arg1)
str2double
function str2double(in s, in cdelim, in rdelim, in ddelim)
leadidcodexyz
function leadidcodexyz(in arg1)