%==================================================================
%==================================================================
%
%	BatchTonKon
%
%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION.                                                                      
%	Markus Junghoefer	[2003]
%
%
%	Function definition
%	
%
%
%

clear all;
global evtags offset
NsFileMat = [];


%========Segmentation============================
PreTrig=25;
PostTrig=100;
BaseStart=1;
BaseEnd=25;


%=============Choose Files=====================================
[DefFilePath]=SetDefPath('r','*.cnt')
[NNsFiles,NsFileMat,NonUse,BatchFilePath]=ReadFileNames(NsFileMat,DefFilePath,'Choose .cnt file(s):')
if NNsFiles==0; return; end
SetDefPath('w',BatchFilePath);


%=======================Filter====================
% MaxMemory=100;
% LineFrequ=50;
% HighFiltStatus=0;
% HighFrequ=2;
% HighN=6;
% LowFiltStatus=1;
% LowFrequ=40;
% LowN=6;
% StopFiltStatus=0;
% StopFrequ=[LineFrequ-1 LineFrequ+1];
% StopN=6;
% [FiltNsFileMat]=FiltNeuroscanFiles(NsFileMat,LowFiltStatus,LowFrequ,LowN, ...
%                            HighFiltStatus,HighFrequ,HighN,StopFiltStatus,StopFrequ,StopN)
                       
                       
%==============Neuroscan2Egis=============================================================                      
%function [EgisFileMat,ConFileMat] = Neuroscan2Egis(NsFileMat,PreTrig,PostTrig,CellStatus,DownSample,...
%LowFiltStatus,LowFrequ,LowN,HighFiltStatus,HighFrequ,HighN,StopFiltStatus,StopFrequ,StopN)
[EgisFileMat,ConFileMat]=Neuroscan2EgisTonKon(NsFileMat,PreTrig,PostTrig,0)


%===============CalcAutoEditMat ohne avg ref EEG und ohne flat====================================
%[AEMFilePathMat]=CalcAutoEditMat(FileMat,TimeStatusVec,ch_CalcAvgRef,ch_UseSpecChan,...
%ch_CalcBaseline,BaseStartPoint,BaseEndPoint,ch_ChooseTimeInd,LFlatWin,ch_CalcFlaMat,ch_UseAWE);
[AEMFilePathMat]=CalcAutoEditMat(EgisFileMat,[],0,[],1,BaseStart,BaseEnd,1,10,0,0);

%======Such nach schlechten Kanaelen ==================================
%FindBadChan(AEMFilePathMat,AWELimesFac,BatchStatus);
FindBadChan(AEMFilePathMat,3,1);

%======Such nach schlechten trials ==================================
% [AWEFileMat]=FindBadChanTrial(FilePathMat,AWELimesFac,BatchStatus);
FindBadChanTrial(AEMFilePathMat,2.5,1);

%===============CalcAutoEditMat mit avg ref EEG und mit flat====================================
%[AEMFilePathMat]=CalcAutoEditMat(FileMat,TimeStatusVec,ch_CalcAvgRef,ch_UseSpecChan,...
%ch_CalcBaseline,BaseStartPoint,BaseEndPoint,ch_ChooseTimeInd,LFlatWin,ch_CalcFlaMat,ch_UseAWE);
[AEMFilePathMat]=CalcAutoEditMat(EgisFileMat,[],1,1,1,BaseStart,BaseEnd,0,8,1,1);
