Home > eeg > egis > scripts > extract_ns_file.m

extract_ns_file

PURPOSE ^

status= extract_ns_file(seconds,rawfname);

SYNOPSIS ^

function status= extract_ns_file(seconds,rawfname);

DESCRIPTION ^

status= extract_ns_file(seconds,rawfname);
seconds = seconds from start of file to grab data, e.g., [1:4] or
  [5] or [97:111]
rawfname = filename (optional)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status= extract_ns_file(seconds,rawfname);
0002 %status= extract_ns_file(seconds,rawfname);
0003 %seconds = seconds from start of file to grab data, e.g., [1:4] or
0004 %  [5] or [97:111]
0005 %rawfname = filename (optional)
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;

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