MNE-CPP  beta 1.0
main.cpp
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include <iostream>
43 #include <vector>
44 #include <math.h>
45 
46 
47 #include <fiff/fiff.h>
48 
49 
50 //*************************************************************************************************************
51 //=============================================================================================================
52 // QT INCLUDES
53 //=============================================================================================================
54 
55 #include <QtCore/QCoreApplication>
56 
57 
58 //*************************************************************************************************************
59 //=============================================================================================================
60 // USED NAMESPACES
61 //=============================================================================================================
62 
63 using namespace FIFFLIB;
64 
65 
66 //*************************************************************************************************************
67 //=============================================================================================================
68 // MAIN
69 //=============================================================================================================
70 
71 //=============================================================================================================
80 int main(int argc, char *argv[])
81 {
82  QCoreApplication a(argc, argv);
83 
84 // QFile t_fileIn("./MNE-sample-data/MEG/sample/sample_audvis_raw.fif");
85 // QFile t_fileIn("./MNE-sample-data/MEG/test_output.fif");
86  QFile t_fileIn("./MNE-sample-data/MEG/sample/sample_write/test_output.fif");
87 
88  QFile t_fileOut("./MNE-sample-data/MEG/sample/sample_write/test_output2.fif");
89 // QFile t_fileOut("./MNE-sample-data/MEG/test_output2.fif");
90 
91  //
92  // Setup for reading the raw data
93  //
94  FiffRawData raw(t_fileIn);
95 
96  //
97  // Set up pick list: MEG + STI 014 - bad channels
98  //
99  //
100  bool want_meg = true;
101  bool want_eeg = false;
102  bool want_stim = false;
103  QStringList include;
104  include << "STI 014";
105 
106 // MatrixXi picks = Fiff::pick_types(raw.info, want_meg, want_eeg, want_stim, include, raw.info.bads);
107  MatrixXi picks = raw.info.pick_types(want_meg, want_eeg, want_stim, include, raw.info.bads); // prefer member function
108  if(picks.cols() == 0)
109  {
110  include.clear();
111  include << "STI101" << "STI201" << "STI301";
112 // picks = Fiff::pick_types(raw.info, want_meg, want_eeg, want_stim, include, raw.info.bads);
113  picks = raw.info.pick_types(want_meg, want_eeg, want_stim, include, raw.info.bads);// prefer member function
114  if(picks.cols() == 0)
115  {
116  printf("channel list may need modification\n");
117  return -1;
118  }
119  }
120  //
121  RowVectorXd cals;
122 
123  FiffStream::SPtr outfid = Fiff::start_writing_raw(t_fileOut,raw.info, cals/*, picks*/);
124  //
125  // Set up the reading parameters
126  //
127  fiff_int_t from = raw.first_samp;
128  fiff_int_t to = raw.last_samp;
129  float quantum_sec = 10.0f;//read and write in 10 sec junks
130  fiff_int_t quantum = ceil(quantum_sec*raw.info.sfreq);
131  //
132  // To read the whole file at once set
133  //
134  //quantum = to - from + 1;
135  //
136  //
137  // Read and write all the data
138  //
139  bool first_buffer = true;
140 
141  fiff_int_t first, last;
142  MatrixXd data;
143  MatrixXd times;
144 
145  for(first = from; first < to; first+=quantum)
146  {
147  last = first+quantum-1;
148  if (last > to)
149  {
150  last = to;
151  }
152 
153  if (!raw.read_raw_segment(data,times,first,last/*,picks*/))
154  {
155  printf("error during read_raw_segment\n");
156  return -1;
157  }
158  //
159  // You can add your own miracle here
160  //
161  printf("Writing...");
162  if (first_buffer)
163  {
164  if (first > 0)
165  outfid->write_int(FIFF_FIRST_SAMPLE,&first);
166  first_buffer = false;
167  }
168  outfid->write_raw_buffer(data,cals);
169  printf("[done]\n");
170  }
171 
172  outfid->finish_writing_raw();
173 
174  printf("Finished\n");
175 
176  return 0;//a.exec();
177 }
178 
179 //*************************************************************************************************************
180 //=============================================================================================================
181 // STATIC DEFINITIONS
182 //=============================================================================================================
183 
184 
QSharedPointer< FiffStream > SPtr
Definition: fiff_stream.h:132
FIFF raw measurement data.
Definition: fiff_raw_data.h:94
Definition: fiff.h:98
static FiffStream::SPtr start_writing_raw(QIODevice &p_IODevice, const FiffInfo &info, RowVectorXd &cals, MatrixXi sel=defaultMatrixXi)
Definition: fiff.h:719
FIFF class declaration, which provides static wrapper functions to stay consistent with mne matlab to...