0001 function status=laplacian_ses(bad_chan,infname)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 status = -1;
0014
0015 if ~((nargin == 1)|(nargin == 2)|(nargin == 0))
0016 error('Number of input arguments must be either 1 2 or 0 moron.');
0017 end
0018
0019 srcfid = -1;
0020 destfid = -1;
0021 if nargin == 0
0022 bad_chan = [];
0023 end;
0024
0025 if nargin == 2
0026 srcfid = fopen(infname, 'r');
0027 if srcfid == -1
0028 error(['Could not open input file ' infname '.']);
0029 end
0030 outfname = [infname '_lap'];
0031 destfid = fopen(outfname, 'wb');
0032 if destfid == -1
0033 temp =fclose(srcfid);
0034 error(['Could not open output file ' outfname '.']);
0035 end
0036
0037 else
0038 while srcfid == -1
0039 [srcfid, infname]=get_fid('r','*', 'Open Session File:');
0040 end
0041 outfname = [infname '_lap'];
0042 destfid = fopen(outfname, 'wb');
0043 if destfid == -1
0044 temp =fclose(srcfid);
0045 error(['Could not open output file ' outfname '.']);
0046 end
0047 end
0048 end
0049
0050
0051 ses_hdr_offsets_v;
0052
0053 [fhdr,chdr,ename,czeros,cgains,cnames,fcom,ftext, coff]=rd_egis_hdr_v(srcfid);
0054
0055
0056
0057 frewind(srcfid);
0058 [temp, countin] = fread(srcfid, fhdr(LHeader), 'char');
0059 countout = fwrite(destfid, temp, 'char');
0060 if countin ~= countout
0061 error('Error copying header information');
0062 end
0063
0064 [xelec,yelec,zelec] = electrodes(fhdr(NChan)+1);
0065 ses_mask = artifact_edit(infname, fhdr, chdr,0);
0066
0067
0068 for c=1:fhdr(NCells)
0069 disp(['Processing cell: ' int2str(c)]);
0070
0071
0072 for t=1:chdr(c,NObs)
0073 ses_mask_cell_offset = sum(chdr(1:c, NTrials)) - chdr(c,NTrials);
0074 ref_trialdata = zeros(chdr(c,NPoints), fhdr(NChan));
0075 if sum(ses_mask(ses_mask_cell_offset + t,:)) > min_good_chan
0076 trialdata = rd_onetr_allch(srcfid, coff(c), t, fhdr(NChan), chdr(c, NPoints));
0077 avref_trialdata= average_reference(trialdata, ses_mask(ses_mask_cell_offset + t,:));
0078 lap_trialdata = zeros(size(avref_trialdata,1),size(avref_trialdata,2));
0079
0080 good_chan = find(ses_mask(ses_mask_cell_offset + t,:));
0081 lap_trialdata = laplacian_trial(trialdata,good_chan,xelec,yelec,zelec)
0082 ref_trialdata = rereference(lap_trialdata);
0083 end;
0084 fwrite(destfid, ref_trialdata', 'int16');
0085 end
0086 end
0087
0088 disp('Finished running laplacian_ses. Have a nice day');
0089 temp=fclose(srcfid);
0090 temp=fclose(destfid);
0091 status = 1;