0001 function mne_ex_read_write_raw(infile,outfile)
0002
0003
0004
0005
0006
0007
0008
0009
0010
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
0026
0027 try
0028 raw = fiff_setup_read_raw(infile);
0029 catch
0030 error(me,'%s',mne_omit_first_line(lasterr));
0031 end
0032
0033
0034
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
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
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
0068
0069
0070
0071
0072
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
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);