function varargout = preproOEG16(fcn, varargin) % Preprocessor Function of OEG16 Fromat: Normal.. % This Format Read OEG16. % And Plug-in Format Version 1.0 % % ** CREATE BASIC INFORMATION ** % Syntax: % basic_info = preproOEG16('createBasicIno'); % Return Information for OSP Application. % basic_info is structure that fields are % DispName : Display Name : String % Version : Version of the function % OpenKind : Kind of Open Function % IO_Kind : Kind of I/O Function % % ** Check If the file is in format. ** % Syntax: % [flag,msg] = preproOEG16('CheckFile',filename) % flag : true : In format (Available) % false : Out of Format. % msg : if false, reason why Out of Format. % filename : Full-Path of the File % % ** get Information of file ** % Syntax: % str = preproOEG16('getFileInfo',filename); % str : File Infromation. % Cell array of string. % filename : Full-Path of the File. % % ** get Information of This Function ** % Syntax: % str = preproOEG16('getFunctionInfo') % str : Information of the function. % Cell array of string. % % ** execute ** % Syntax: % [hdata, data] = preproOEG16('Execute', filename) % Continuous Data. % % OT_LOCAL_DATA = preproOEG16('ExecuteOld', filename) % OT_LOCAL_DATA : Version 1.0 Inner Data-Format. % Thsi will be removed % % See also OSPFILTERDATAFCN. % ====================================================================== % Copyright(c) 2020, % National Institute of Advanced Industrial Science and Technology % % Released under the MIT license % https://opensource.org/licenses/MIT % ====================================================================== % == History == % OEG-17APD format loading routine % DATE:03.04.20 % WRITTEN:M.Ohashi % % Inprot form Upper ot_datalod. % create : 2020.06.01 % $Id: preproOEG16.m 382 2020-06-01 00:01:28Z Ohashi $ %======== Launch Switch ======== if strcmp(fcn,'createBasicInfo'), varargout{1} = createBasicInfo; return; end if nargout, [varargout{1:nargout}] = feval(fcn, varargin{:}); else feval(fcn, varargin{:}); end if 0 % Entry function createBasicInfo; getFunctionInfo; CheckFile; getFileInfo; Execute; % ExecuteOEG; end return; %=============================== %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function basicInfo= createBasicInfo % ** CREATE BASIC INFORMATION ** % Syntax: % basic_info = preproOEG16('createBasicIno'); % Return Information for OSP Application. % basic_info is structure that fields are % DispName : Display Name : String % Version : Version of the function % OpenKind : Kind of Open Function % IO_Kind : Kind of I/O Function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% basicInfo.DispName ='OEG16'; basicInfo.Version =1.0; basicInfo.OpenKind =1; basicInfo.IO_Kind =1; % get Revision rver = '$Revision: 1.0 $';%- **@**** 20200601 [s,e]= regexp(rver, '[0-9.]'); try basicInfo.Version = str2double(rver(s(1):e(end))); catch basicInfo.Version =1.0; end return; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function fs=getFilterSpec % ** CREATE BASIC INFORMATION ** % Syntax: % filterspec = preproOEG16('getFilterSpec'); % Return FilterSpec of File-Select-Dilalogs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fs={'*.dat;','OEG16 Text File'}; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function str = getFunctionInfo % get Information of This Function % str : Information of the function. % Cell array of string. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% bi = createBasicInfo; dd = '$Date: 2020/06/01 15:00:00 $'; dd([1:6, end]) = []; str={'=== OEG16 Format ===', ... [' Revision : ' num2str(bi.Version)], ... [' Date : ' dd], ... ' ------------------------ ', ... ' Text Type', ... ' 1st Line : Header .... ', ... ' ------------------------ '}; return; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [flag, msg] = CheckFile(filename) % Syntax: % [flag,msg] = preproOEG16('CheckFile',filename) % flag : true : In format (Available) % false : Out of Format. % msg : if false, reason why Out of Format. % filename : Full-Path of the File %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [pname, fname,ext] = fileparts(filename); % Check Extension if strcmpi(ext,'.dat')==0, % Extend msg='Extension Error'; flag = false; return; end msg=''; flag=true; %-------------------------------- % Check 1st Line %-------------------------------- line_01=textread(filename,'%s%*[^\n]',1,'whitespace',''''); flag = strcmp(line_01{1},'[Start/Stop Time]'); if flag==false, msg='1 Line is not OEG16_Header'; end return; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function str =getFileInfo(filename) % ** get Information of file ** % Syntax: % str = % str : File Infromation. % Cell array of string. % filename : Full-Path of the File. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% str=textread(filename,'%s',19,'headerlines',0,'delimiter','='); str =[[' Format OEG16 : ' filename]; cellstr(str)]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [hdata, data] =Execute(filename) % ** execute ** % Syntax: % [hdata, data] = preproOEG16('Execute', filename) % Continuous Data. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% global mType; data =ExecuteOEG(filename); [data,hdata]=ot2ucdata(data); hdata.Pos.ver=2.0; if mType==1, %2x6 hdata.Pos.D2.P=[8,40;14,46;14,34;20,40;26,46;26,34;32,40;38,46;38,34;44,40;50,46;50,34;56,40;62,46;62,34;68,40;]; hdata.Pos.Group.ChData={1:16}; hdata.Pos.Group.mode=-1; hdata.Pos.Group.OriginalCh=[1:16]; end hdata.Pos.D3.P=[],hdata.Pos.D3.Base=[]; return; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function OT_LOCAL_DATA =ExecuteOEG(filename) % OT_LOCAL_DATA = preproOEG16('ExecuteOEG', filename) % OT_LOCAL_DATA : Version 1.0 Inner Data-Format. % Thsi will be removed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% global mType; [pathname, fname, ext] = fileparts(filename); FORMAT_VER=2.0; dum=textread(filename, '%s%*[^\n]',1, 'headerlines',20,'whitespace','''');%[CH_CONFIG] flag = strcmp(dum{1},'[CH_CONFIG]'); if flag==true, CONF_LINE=21,FMOD_LINE=24,D_LINE=25; else CONF_LINE=17,FMOD_LINE=20,D_LINE=21; end measmode=-1,mType=1,chcnt=16,adn=chcnt*2,dtcnt=73; chnum=adn/2; opmode=99; plnum=1; adnmpn=1:adn; for i=1:adn adrng(i)=2.50; % A/D gain of each channel 2.50[V] end soft_version=3.0; id='';%dum{1}; dum=textread(filename, '%*4c%s',1, 'headerlines',12,'delimiter','='); subjectname=dum{1}; comment='';%dum{1}; age_str= textread(filename, '%*3c%s',1, 'headerlines',13, .... 'delimiter','='); tmp=age_str{1}; age(1)=str2double(tmp); for ii=2:4 age(ii)=0; end sex_str=textread(filename, '%*6c%s',1, 'headerlines',14, ... 'delimiter','='); switch(sex_str{1}) case 'Male', sex=0; case 'Female', sex=1; end date=textread(filename, '%*5c%s',1, 'headerlines',1,'delimiter','='); for i=1:adn if rem(i,2)==1,in_per_num=840.0;else in_per_num=770.0;end %str2double(dum{i+1}(l_per+1:r_per-1)); wlen(i)=in_per_num; end for i=1:adn amprng(i)=1.0;%str2double(dum(i+1,:)); end for i=1:adn d_gain(i)=1.0;%str2double(dum(i+1,:)); end %load sampling period[s] smpl_period_s=textread(filename, '%*60c%s',1, 'headerlines',FMOD_LINE,'delimiter',';'); %FAST/FINE (24/20) if strcmpi(smpl_period_s{1},{'FAST]'})==1 ,smpl_period=0.08192;else smpl_period=0.65536;end % Stimulation Information [dum]=textread(filename,'%s',2,'headerlines',5,'delimiter','='); if strcmpi(dum{2},'Event-Related') StimMode = 1; % Event-Related else StimMode = 2; % Block end %load repeart count repeat=textread(filename, '%*12c%d',1, 'headerlines',10, ... 'delimiter','='); %load data % read all row as number of data [dum4] = textread(filename, '%4c%*[^\n]','headerlines',D_LINE);%data (25/21) datanum=length(dum4); %データ数 evth=hex2dec(dum4);%'00xx'-->dec for i=1:datanum, evt=evth(i);%xxyy evt1=evt/256;%xx if bitand(evt,1)==1,evtn=1; elseif bitand(evt,2)==2, evtn=2; elseif bitand(evt,4)==4, evtn=3; elseif bitand(evt,8)==8, evtn=4; elseif bitand(evt,16)==16, evtn=5; else evtn=0; end if evt1>0 , if (evt1>=100)&(evt1<=109),evtn=6; elseif (evt1>=1)&(evt1<=49),evtn=7; elseif (evt1>=50)&(evt1<=99),evtn=8; else evtn=9; end end evth(i)=evtn; end clear dum4; chcfg0 = textread(filename, '%s',chcnt,'headerlines',CONF_LINE,'delimiter',','); %CH_CONFIG (21/17) chcfg='' l=length(chcfg0); j=1; for i=1:l if str2num(chcfg0{i})~=0,chcfg{j}=chcfg0{i},j=j+1;end end chcfg=chcfg'; chcnt=length(chcfg); cht=''; for i=1:dtcnt, cht=[cht {'%*f,'}];end %dtcnt=73 {'%*f,'}....{'%*f,'} for i=1:chcnt, %i:論理CH(1-16) ii=str2num(chcfg{i}); %ii:物理CH(1-36) cht{ii*2}='%f,'; cht{ii*2+1}='%f,'; end cht{dtcnt}='%f'; cht{1}='%*x,'; st=cell2mat(cht); %NEW fid=fopen(filename); try % for i=1:D_LINE,fgetl(fid);end %1-D_LINE (25/21):読み飛ばし data_mark0=fscanf(fid,st,[chcnt*2, datanum]);%data_mark0 catch fclose(fid); rethrow(lasterror); end fclose(fid); for i=1:chcnt ii=str2num(chcfg{i}); a(ii)=i; end; l=length(a); b=0; j=1; for i=1:l aa=a(i); if aa>0,b(aa)=j,j=j+1;end end for i=1:chcnt ii=b(i);%ii:物理CH data_mark(i*2-1,:)=data_mark0(ii*2-1,:); data_mark(i*2,:)=data_mark0(ii*2,:); end; data=data_mark'; %転置(縦=dtanum方向,横=CH方向) stim=evth; time=[0:smpl_period:(datanum-1)*smpl_period]; % convert sec to msec smpl_period=1000*smpl_period; % Make OT_LOCAL_DATA from file data. SCRIPT_OTDATALOAD; return;