Home > vbmeg > external > mne > mne_ex_read_write_raw.m

mne_ex_read_write_raw

PURPOSE ^

SYNOPSIS ^

function mne_ex_read_write_raw(infile,outfile)

DESCRIPTION ^

 function mne_ex_read_write_raw(infile,outfile);

 Read and write raw data in 60-sec blocks

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mne_ex_read_write_raw(infile,outfile)
0002 %
0003 % function mne_ex_read_write_raw(infile,outfile);
0004 %
0005 % Read and write raw data in 60-sec blocks
0006 %
0007 
0008 %
0009 %   Author : Matti Hamalainen, MGH Martinos Center
0010 %   License : BSD 3-clause
0011 %
0012 
0013 
0014 global FIFF;
0015 if isempty(FIFF)
0016    FIFF = fiff_define_constants();
0017 end
0018 %
0019 me = 'MNE:mne_ex_read_write_raw';
0020 %
0021 if nargin ~= 2
0022     error(me,'Incorrect number of arguments');
0023 end
0024 %
0025 %   Setup for reading the raw data
0026 %
0027 try
0028     raw = fiff_setup_read_raw(infile);
0029 catch
0030     error(me,'%s',mne_omit_first_line(lasterr));
0031 end
0032 %raw.info.projs = [];
0033 %
0034 %   Set up pick list: MEG + STI 014 - bad channels
0035 %
0036 %
0037 want_meg   = true;
0038 want_eeg   = false;
0039 want_stim  = false;
0040 include{1} = 'STI 014';
0041 try
0042     picks = fiff_pick_types(raw.info,want_meg,want_eeg,want_stim,include,raw.info.bads);
0043 catch
0044     %
0045     %   Failure: Try MEG + STI101 + STI201 + STI301 - bad channels instead
0046     %
0047     include{1} = 'STI101';
0048     include{2} = 'STI201';
0049     include{3} = 'STI301';
0050     try
0051         picks = fiff_pick_types(raw.info,want_meg,want_eeg,want_stim,include,raw.info.bads);
0052     catch
0053         error(me,'%s (channel list may need modification)',mne_omit_first_line(lasterr));
0054     end
0055 end
0056 
0057 %
0058 [outfid,cals] = fiff_start_writing_raw(outfile,raw.info,picks);
0059 %
0060 %   Set up the reading parameters
0061 %
0062 from        = raw.first_samp;
0063 to          = raw.last_samp;
0064 quantum_sec = 10;
0065 quantum     = ceil(quantum_sec*raw.info.sfreq);
0066 %
0067 %   To read the whole file at once set
0068 %
0069 %quantum     = to - from + 1;
0070 %
0071 %
0072 %   Read and write all the data
0073 %
0074 first_buffer = true;
0075 for first = from:quantum:to
0076     last = first+quantum-1;
0077     if last > to
0078         last = to;
0079     end
0080     try
0081         [ data, times ] = fiff_read_raw_segment(raw,first,last,picks);
0082     catch
0083         fclose(raw.fid);
0084         fclose(outfid);
0085         error(me,'%s',mne_omit_first_line(lasterr));
0086     end
0087     %
0088     %   You can add your own miracle here
0089     %
0090     fprintf(1,'Writing...');
0091     if first_buffer
0092        if first > 0
0093            fiff_write_int(outfid,FIFF.FIFF_FIRST_SAMPLE,first);
0094        end
0095        first_buffer = false;
0096     end
0097     fiff_write_raw_buffer(outfid,data,cals);
0098     fprintf(1,'[done]\n');
0099 end
0100 
0101 fiff_finish_writing_raw(outfid);
0102 fclose(raw.fid);

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005