%==================================================================
%==================================================================
clear all;
%
%	BatchHaraldMovie.m
%   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	[1999]
%
%
%	Function definition
%	
%
%
% FŸr dig 2 mŸssen zwei dinge geändert werden
% 1: [FilterEGISFileMat]=TransNetGeoHistIAPS(FilterTAWFileMat,TRStatus,83,84,1,GainFilePath,ZeroFilePath,0,[],2)
%  letzte Zahl legt din fest
% 2: line 530 und 531 	in in TransNetGeoHistIAPS.m

% 		TrialVecTmp([1:2:length(CondVec)-1])=TrialVec;
% 		TrialVecTmp([2:2:length(CondVec)])=TrialVec+83;	; ändern zu
% 		
% 		TrialVecTmp([2:2:length(CondVec)])=TrialVec;
% 		TrialVecTmp([1:2:length(CondVec)-1])=TrialVec-83;	
		
% 		TimeMsVecTmp([1:2:length(CondVec)-1])=TimeMsVec;
%		TimeMsVecTmp([2:2:length(CondVec)])=TimeMsVec+83*1000/SampRate; ändern zu
%
% 		TimeMsVecTmp([2:2:length(CondVec)])=TimeMsVec;
%		TimeMsVecTmp([1:2:length(CondVec)-1])=TimeMsVec-83*1000/SampRate; 
%=================================================================
%==================================================================

TRStatus=1; % wird Ÿbergeben in TransRawTaw(RAWFileMat,TRStatus,20);

%***************** TeilI: Batch-file******************************
%**************Read files names****************
fid=0;
		[FileTmp,PathTmp]=uigetfile('*.*','Open batch file: ',0,0);
			FilePathTmp=[PathTmp,FileTmp];
			[fid] = fopen(FilePathTmp, 'r');
			NFiles=0;
		while feof(fid) == 0;
		NFiles=NFiles+1;
%********************************************************
%****  first file     ********************
		line=fgetl(fid);
		RawFilePath=line;
			if NFiles==1
				RAWFileMat=char(RawFilePath);
			else
				RAWFileMat=char(RAWFileMat,RawFilePath);
			end
%********************************************************
		end		
		status = fclose(fid);
		FilterEGISFileMat=RAWFileMat;
		[NNetFiles,N]=size(RAWFileMat);
%********************************************************
%*************** Ende TeilI: Batch-file*************************
%********************************************************

%===============Calc TimeStatusVec====================================
TimeStatusVec=ones(225,1);
TimeStatusVec(111:225)=zeros(115,1);
%===============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(FilterEGISFileMat,TimeStatusVec,0,[],1,1,24,1,8,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(FilterEGISFileMat,TimeStatusVec,1,1,1,1,24,0,8,1,1);

