Home > eeg > egis > scripts > make_gave_diff.m

make_gave_diff

PURPOSE ^

function status=make_gave_diff(cell_map, infname, outfname);

SYNOPSIS ^

function status=make_gave_diff(cell_map, infname, outfname);

DESCRIPTION ^

function status=make_gave_diff(cell_map, infname, outfname);

This function creates a difference file with name outfname
from file infname using cell_map as a guide. If infname &
outfname are omitted, this function interactively prompts
for input and output files. The argument cell_map should
contain one row for each difference you wish to calculate
and put in the output file. The first column is the source
cell from the input file, and the second column is the
cell to be subtracted.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status=make_gave_diff(cell_map, infname, outfname);
0002 %function status=make_gave_diff(cell_map, infname, outfname);
0003 %
0004 %This function creates a difference file with name outfname
0005 %from file infname using cell_map as a guide. If infname &
0006 %outfname are omitted, this function interactively prompts
0007 %for input and output files. The argument cell_map should
0008 %contain one row for each difference you wish to calculate
0009 %and put in the output file. The first column is the source
0010 %cell from the input file, and the second column is the
0011 %cell to be subtracted.
0012 %
0013 
0014 %Modification History
0015 %
0016 %Created Dec. 1, 1995 by Brian C. Rakitin
0017 %
0018 
0019 status = -1;
0020 
0021 %Check number of input arguments
0022 if ~((nargin == 1)|(nargin == 3))
0023     error('Number of input arguments must be either 1, or 3.');
0024 end
0025 
0026 %Initialize fids
0027 destfid = -1;
0028 srcfid = -1;
0029 %First try batch mode
0030 if nargin == 3
0031     srcfid= fopen(infname(i,:), 'r');
0032     if srcfid== -1
0033         error(['Could not open input file' infname '.']);
0034     end
0035     destfid = fopen(outfname, 'wb');
0036     if destfid == -1
0037         temp =fclose(srcfid);
0038     error(['Could not open output file ' outfname '.']);
0039     end
0040 %Otherwise run interactive mode
0041 elseif nargin <= 3
0042     while srcfid == -1
0043         [srcfid, infname]=get_fid('r','*.gave*', 'Open Average File:');
0044     end
0045     while destfid == -1
0046         [destfid, outfname]=put_fid('wb','new.gave_diff','Save GAVE Diff. File As:');
0047     end
0048 end
0049 
0050 ave_hdr_offsets_v;
0051 [fhdr,chdr,ename,czeros,cgains,cnames,fcom,ftext, coff]=rd_egis_hdr_v(srcfid);
0052 newfhdr=fhdr;
0053 newchdr=chdr;
0054 
0055 if any(cell_map(:,1) > newfhdr(NCells))
0056     fclose('all');
0057     error('Value in source column of cell_map exceeds number of cells in input file.');
0058 end
0059 if any(cell_map(:,2) > newfhdr(NCells))
0060     fclose('all');
0061     error('Value in subtractor column of cell_map exceeds number of cells in input file.');
0062 end
0063 
0064 newfhdr(NCells)=size(cell_map,1);
0065 newchdr = newchdr(1:size(cell_map,1),:);
0066 newcnames = zeros(size(cell_map,1),80);
0067 for c=1:size(cell_map,1);
0068     tempstr=['Diff of Cells ' int2str(cell_map(c,1)) ' and ' int2str(cell_map(c,2))];
0069     newcnames(c,1:length(tempstr)) = tempstr;
0070 end
0071 wt_ave_hdr_v(destfid,newfhdr,newchdr,ename,newcnames,fcom,ftext);
0072 
0073 diffdata=zeros(newchdr(1,NSamps),newfhdr(NChan));
0074 for c=1:size(cell_map,1) %c is for cells that live in EGIS
0075     disp(['Computing difference of cells ' int2str(cell_map(c,1)) ' and ' int2str(cell_map(c,2)) '.'])
0076     sourcedata = rd_onetr_allch(srcfid, coff(cell_map(c,1)), 1, newfhdr(NChan), chdr(cell_map(c,1), NPoints));
0077     subtractor = rd_onetr_allch(srcfid, coff(cell_map(c,2)), 1, newfhdr(NChan), chdr(cell_map(c,2), NPoints));
0078     diffdata = sourcedata - subtractor;
0079     disp('Writing difference data to output file.');
0080     fwrite(destfid, diffdata, 'int16');
0081 end    %newcell=1:size(cell_map,1)
0082 
0083 disp('Done Running gave_diff.');
0084 fclose('all');
0085 status=1;
0086 
0087 
0088

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003