Home > vbmeg > external > mne > fiff_write_raw_segment.m

fiff_write_raw_segment

PURPOSE ^

FIFF_WRITE_RAW_SEGMENT Write chunck of raw data to disk

SYNOPSIS ^

function fiff_write_raw_segment(fname, raw, from, to, sel, drop_small_buffer, buffer_size)

DESCRIPTION ^

   FIFF_WRITE_RAW_SEGMENT   Write chunck of raw data to disk
       [] = FIFF_WRITE_RAW_SEGMENT(FNAME, RAW, FROM, TO, SEL)

   The functions reads data from a file specified by raw
   which is obtained with fiff_setup_read_raw

 fname                - the name of the file where to write
 raw                  - structure returned by fiff_setup_read_raw
 from                 - first sample to include. If omitted, defaults to the
                        first sample in data
 to                   - last sample to include. If omitted, defaults to the last
                        sample in data
 sel                  - optional channel selection vector
 drop_small_buffer    - optional bool to say if the last data buffer is dropped
                        to make sure all buffers have the same size
                        (required by maxfilter)
 buffer_size          - float (size of data buffers)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fiff_write_raw_segment(fname, raw, from, to, sel, drop_small_buffer, buffer_size)
0002 %   FIFF_WRITE_RAW_SEGMENT   Write chunck of raw data to disk
0003 %       [] = FIFF_WRITE_RAW_SEGMENT(FNAME, RAW, FROM, TO, SEL)
0004 %
0005 %   The functions reads data from a file specified by raw
0006 %   which is obtained with fiff_setup_read_raw
0007 %
0008 % fname                - the name of the file where to write
0009 % raw                  - structure returned by fiff_setup_read_raw
0010 % from                 - first sample to include. If omitted, defaults to the
0011 %                        first sample in data
0012 % to                   - last sample to include. If omitted, defaults to the last
0013 %                        sample in data
0014 % sel                  - optional channel selection vector
0015 % drop_small_buffer    - optional bool to say if the last data buffer is dropped
0016 %                        to make sure all buffers have the same size
0017 %                        (required by maxfilter)
0018 % buffer_size          - float (size of data buffers)
0019 
0020 %
0021 %   Author : Alexandre Gramfort, MGH Martinos Center
0022 %   License : BSD 3 - clause
0023 %
0024 
0025 global FIFF;
0026 if isempty(FIFF)
0027     FIFF = fiff_define_constants();
0028 end
0029 %
0030 me = 'MNE:fiff_write_raw_segment';
0031 %
0032 if nargin < 2
0033     error(me, 'Incorrect number of arguments');
0034 end
0035 if nargin < 3 | isempty(from)
0036     from = raw.first_samp;
0037 end
0038 if nargin < 4 | isempty(to)
0039     to = raw.last_samp;
0040 end
0041 if nargin < 5 | isempty(sel)
0042     sel = 1:raw.info.nchan;
0043 end
0044 if nargin < 6
0045     drop_small_buffer = false;
0046 end
0047 if nargin < 7
0048     buffer_size_sec = 25; % read by chunks of 30 seconds
0049     buffer_size = ceil(buffer_size_sec * raw.info.sfreq);
0050 end
0051 %
0052 [outfid, cals] = fiff_start_writing_raw(fname, raw.info, sel);
0053 %
0054 first_buffer = true;
0055 for first = from:buffer_size:to
0056     last = first + buffer_size - 1;
0057     if last > to
0058         last = to;
0059     end
0060     try
0061         [ data, times ] = fiff_read_raw_segment(raw, first, last, sel);
0062     catch
0063         fclose(raw.fid);
0064         fclose(outfid);
0065         error(me, '%s', mne_omit_first_line(lasterr));
0066     end
0067     if drop_small_buffer && first_buffer == false && length(times) < buffer_size
0068         fprintf(1, 'Skipping due to small buffer ... [done]\n');
0069         break
0070     end
0071     %
0072     %   You can add your own miracle here
0073     %
0074     fprintf(1, 'Writing...');
0075     if first_buffer
0076         if first > 0
0077             fiff_write_int(outfid, FIFF.FIFF_FIRST_SAMPLE, first);
0078         end
0079         first_buffer = false;
0080     end
0081     fiff_write_raw_buffer(outfid, data, cals);
0082     fprintf(1, '[done]\n');
0083 end
0084 
0085 fiff_finish_writing_raw(outfid);

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