0001 function status=make_gave_diff(cell_map, infname, outfname);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 status = -1;
0020
0021
0022 if ~((nargin == 1)|(nargin == 3))
0023 error('Number of input arguments must be either 1, or 3.');
0024 end
0025
0026
0027 destfid = -1;
0028 srcfid = -1;
0029
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
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)
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
0082
0083 disp('Done Running gave_diff.');
0084 fclose('all');
0085 status=1;
0086
0087
0088