0001 function status= extract_ns_file(seconds,rawfname);
0002
0003
0004
0005
0006
0007 if nargin < 1
0008 error('seconds not specified');
0009 end;
0010
0011 if nargin < 2
0012 [fid, fname, pathname] = get_fid('rb','*.*');
0013 rawfname = [fname];
0014 else
0015 fid = fopen(rawfname,'rb');
0016 end;
0017
0018 outfname = [rawfname '_ext_' int2str(min(seconds)) '_' int2str(max(seconds))]
0019 outfid = fopen(outfname,'wb');
0020 [header_array, EventCodes,Samp_Rate, NChan, scale, NSamp, NEvent] = rd_fragger_hdr(fid);
0021 header_array(14) = size(seconds,2)*Samp_Rate;
0022 wt_fragger_hdr(outfid,header_array,EventCodes);
0023 max_seconds = fix(NSamp/Samp_Rate);
0024 if max(seconds) > max_seconds
0025 fclose('all');
0026 error('seconds greater than file length');
0027 end;
0028 trialdata = zeros(NChan+NEvent,Samp_Rate);
0029
0030 skip_bytes = Samp_Rate*(seconds(1)-1)*(NChan+NEvent)*2;
0031
0032 fseek(fid,skip_bytes,'cof');
0033 for i = 1:size(seconds,2)
0034 trialdata = fread(fid,[NChan+NEvent,Samp_Rate],'int16');
0035 fwrite(outfid,trialdata,'int16');
0036 end
0037 fclose('all');
0038 status = 1;