169 QFile file(fileName);
170 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
171 qWarning() <<
"MNEDescriptionParser: cannot open" << fileName;
175 QTextStream in(&file);
178 bool expectBrace =
false;
179 bool bminSet =
false, bmaxSet =
false;
180 bool inAverage =
false;
181 bool inCategory =
false;
185 while (!(word = nextWord(in)).isEmpty()) {
190 qWarning() <<
"MNEDescriptionParser: expected '{', got" << word;
197 qWarning() <<
"MNEDescriptionParser: unexpected '{'";
205 if (currentCat.
comment.isEmpty()) {
206 qWarning() <<
"MNEDescriptionParser: category name missing";
209 if (currentCat.
tmin >= currentCat.
tmax) {
210 qWarning() <<
"MNEDescriptionParser: illegal time range for" << currentCat.
comment;
213 if (currentCat.
events.isEmpty()) {
214 qWarning() <<
"MNEDescriptionParser: no events for" << currentCat.
comment;
222 bminSet = bmaxSet =
false;
223 }
else if (inAverage) {
232 if (word.compare(
"average", Qt::CaseInsensitive) == 0) {
233 if (inAverage || inCategory) {
234 qWarning() <<
"MNEDescriptionParser: nested average";
243 if (word.compare(
"category", Qt::CaseInsensitive) == 0 ||
244 word.compare(
"condition", Qt::CaseInsensitive) == 0) {
245 if (!inAverage || inCategory) {
246 qWarning() <<
"MNEDescriptionParser: misplaced category";
251 bminSet = bmaxSet =
false;
256 if (word.compare(
"name", Qt::CaseInsensitive) == 0) {
257 QString val = nextWord(in);
258 if (val.isEmpty()) { qWarning() <<
"MNEDescriptionParser: name requires a value";
return false; }
259 if (inCategory) currentCat.
comment = val;
260 else if (inAverage) desc.
comment = val;
261 else { qWarning() <<
"MNEDescriptionParser: misplaced name";
return false; }
266 if (word.compare(
"outfile", Qt::CaseInsensitive) == 0) {
267 QString val = nextWord(in);
268 if (val.isEmpty()) { qWarning() <<
"MNEDescriptionParser: outfile requires a value";
return false; }
269 if (inAverage && !inCategory) desc.
filename = val;
270 else { qWarning() <<
"MNEDescriptionParser: misplaced outfile";
return false; }
275 if (word.compare(
"eventfile", Qt::CaseInsensitive) == 0) {
276 QString val = nextWord(in);
277 if (val.isEmpty()) { qWarning() <<
"MNEDescriptionParser: eventfile requires a value";
return false; }
278 if (inAverage && !inCategory) desc.
eventFile = val;
279 else { qWarning() <<
"MNEDescriptionParser: misplaced eventfile";
return false; }
284 if (word.compare(
"logfile", Qt::CaseInsensitive) == 0) {
285 QString val = nextWord(in);
286 if (val.isEmpty()) { qWarning() <<
"MNEDescriptionParser: logfile requires a value";
return false; }
287 if (inAverage && !inCategory) desc.
logFile = val;
288 else { qWarning() <<
"MNEDescriptionParser: misplaced logfile";
return false; }
293 if (word.compare(
"fixskew", Qt::CaseInsensitive) == 0) {
294 if (inAverage && !inCategory) desc.
fixSkew =
true;
295 else { qWarning() <<
"MNEDescriptionParser: misplaced fixskew";
return false; }
300 if (word.compare(
"tmin", Qt::CaseInsensitive) == 0) {
301 float fval;
if (!getFloat(in, fval))
return false;
302 if (inCategory) currentCat.
tmin = fval;
303 else { qWarning() <<
"MNEDescriptionParser: misplaced tmin";
return false; }
306 if (word.compare(
"tmax", Qt::CaseInsensitive) == 0) {
307 float fval;
if (!getFloat(in, fval))
return false;
308 if (inCategory) currentCat.
tmax = fval;
309 else { qWarning() <<
"MNEDescriptionParser: misplaced tmax";
return false; }
312 if (word.compare(
"basemin", Qt::CaseInsensitive) == 0 ||
313 word.compare(
"bmin", Qt::CaseInsensitive) == 0) {
314 float fval;
if (!getFloat(in, fval))
return false;
315 if (inCategory) { currentCat.
bmin = fval; bminSet =
true; }
316 else { qWarning() <<
"MNEDescriptionParser: misplaced basemin";
return false; }
319 if (word.compare(
"basemax", Qt::CaseInsensitive) == 0 ||
320 word.compare(
"bmax", Qt::CaseInsensitive) == 0) {
321 float fval;
if (!getFloat(in, fval))
return false;
322 if (inCategory) { currentCat.
bmax = fval; bmaxSet =
true; }
323 else { qWarning() <<
"MNEDescriptionParser: misplaced basemax";
return false; }
326 if (word.compare(
"event", Qt::CaseInsensitive) == 0) {
327 int ival;
if (!getInt(in, ival))
return false;
328 if (ival <= 0) { qWarning() <<
"MNEDescriptionParser: event numbers must be positive";
return false; }
329 if (inCategory) currentCat.
events.append(
static_cast<unsigned int>(ival));
330 else { qWarning() <<
"MNEDescriptionParser: misplaced event";
return false; }
333 if (word.compare(
"nextevent", Qt::CaseInsensitive) == 0) {
334 int ival;
if (!getInt(in, ival))
return false;
335 if (ival <= 0) { qWarning() <<
"MNEDescriptionParser: nextevent must be positive";
return false; }
336 if (inCategory) currentCat.
nextEvent =
static_cast<unsigned int>(ival);
337 else { qWarning() <<
"MNEDescriptionParser: misplaced nextevent";
return false; }
340 if (word.compare(
"prevevent", Qt::CaseInsensitive) == 0) {
341 int ival;
if (!getInt(in, ival))
return false;
342 if (ival <= 0) { qWarning() <<
"MNEDescriptionParser: prevevent must be positive";
return false; }
343 if (inCategory) currentCat.
prevEvent =
static_cast<unsigned int>(ival);
344 else { qWarning() <<
"MNEDescriptionParser: misplaced prevevent";
return false; }
347 if (word.compare(
"ignore", Qt::CaseInsensitive) == 0) {
348 int ival;
if (!getInt(in, ival))
return false;
349 if (inCategory) currentCat.
ignore =
static_cast<unsigned int>(ival);
350 else { qWarning() <<
"MNEDescriptionParser: misplaced ignore";
return false; }
353 if (word.compare(
"prevignore", Qt::CaseInsensitive) == 0) {
354 int ival;
if (!getInt(in, ival))
return false;
355 if (inCategory) currentCat.
prevIgnore =
static_cast<unsigned int>(ival);
356 else { qWarning() <<
"MNEDescriptionParser: misplaced prevignore";
return false; }
359 if (word.compare(
"nextignore", Qt::CaseInsensitive) == 0) {
360 int ival;
if (!getInt(in, ival))
return false;
361 if (inCategory) currentCat.
nextIgnore =
static_cast<unsigned int>(ival);
362 else { qWarning() <<
"MNEDescriptionParser: misplaced nextignore";
return false; }
365 if (word.compare(
"mask", Qt::CaseInsensitive) == 0) {
366 int ival;
if (!getInt(in, ival))
return false;
367 if (ival <= 0) { qWarning() <<
"MNEDescriptionParser: mask must be positive";
return false; }
368 if (inCategory) { currentCat.
ignore =
static_cast<unsigned int>(ival); currentCat.
ignore = ~currentCat.ignore; }
369 else { qWarning() <<
"MNEDescriptionParser: misplaced mask";
return false; }
372 if (word.compare(
"prevmask", Qt::CaseInsensitive) == 0) {
373 int ival;
if (!getInt(in, ival))
return false;
374 if (inCategory) { currentCat.
prevIgnore =
static_cast<unsigned int>(ival); currentCat.
prevIgnore = ~currentCat.prevIgnore; }
375 else { qWarning() <<
"MNEDescriptionParser: misplaced prevmask";
return false; }
378 if (word.compare(
"nextmask", Qt::CaseInsensitive) == 0) {
379 int ival;
if (!getInt(in, ival))
return false;
380 if (inCategory) { currentCat.
nextIgnore =
static_cast<unsigned int>(ival); currentCat.
nextIgnore = ~currentCat.nextIgnore; }
381 else { qWarning() <<
"MNEDescriptionParser: misplaced nextmask";
return false; }
384 if (word.compare(
"delay", Qt::CaseInsensitive) == 0) {
385 float fval;
if (!getFloat(in, fval))
return false;
386 if (inCategory) currentCat.
delay = fval;
387 else { qWarning() <<
"MNEDescriptionParser: misplaced delay";
return false; }
390 if (word.compare(
"stderr", Qt::CaseInsensitive) == 0) {
391 if (inCategory) currentCat.
doStdErr =
true;
392 else { qWarning() <<
"MNEDescriptionParser: misplaced stderr";
return false; }
395 if (word.compare(
"abs", Qt::CaseInsensitive) == 0) {
396 if (inCategory) currentCat.
doAbs =
true;
397 else { qWarning() <<
"MNEDescriptionParser: misplaced abs";
return false; }
400 if (word.compare(
"color", Qt::CaseInsensitive) == 0) {
402 if (!getFloat(in, r) || !getFloat(in, g) || !getFloat(in, b))
return false;
403 if (inCategory) { currentCat.
color[0] = r; currentCat.
color[1] = g; currentCat.
color[2] = b; }
404 else { qWarning() <<
"MNEDescriptionParser: misplaced color";
return false; }
409 if (inAverage && !inCategory) {
411 if (parseRejectionParam(word, in, desc.
rej, parseOk)) {
412 if (!parseOk)
return false;
417 qWarning() <<
"MNEDescriptionParser: unknown keyword" << word <<
"in" << fileName;
421 qWarning() <<
"MNEDescriptionParser: no categories found in" << fileName;
434 QFile file(fileName);
435 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
436 qWarning() <<
"MNEDescriptionParser: cannot open" << fileName;
440 QTextStream in(&file);
443 bool expectBrace =
false;
444 bool bminSet =
false, bmaxSet =
false;
450 while (!(word = nextWord(in)).isEmpty()) {
455 qWarning() <<
"MNEDescriptionParser: expected '{', got" << word;
462 qWarning() <<
"MNEDescriptionParser: unexpected '{'";
469 if (currentDef.
tmin >= currentDef.
tmax) {
470 qWarning() <<
"MNEDescriptionParser: illegal time range in def";
473 desc.
defs.append(currentDef);
476 bminSet = bmaxSet =
false;
484 if (word.compare(
"cov", Qt::CaseInsensitive) == 0) {
485 if (inCov || inDef) {
486 qWarning() <<
"MNEDescriptionParser: nested cov";
494 if (word.compare(
"def", Qt::CaseInsensitive) == 0) {
495 if (!inCov || inDef) {
496 qWarning() <<
"MNEDescriptionParser: misplaced def";
501 bminSet = bmaxSet =
false;
506 if (word.compare(
"outfile", Qt::CaseInsensitive) == 0) {
507 QString val = nextWord(in);
508 if (inCov && !inDef) desc.
filename = val;
509 else { qWarning() <<
"MNEDescriptionParser: misplaced outfile";
return false; }
512 if (word.compare(
"eventfile", Qt::CaseInsensitive) == 0) {
513 QString val = nextWord(in);
514 if (inCov && !inDef) desc.
eventFile = val;
515 else { qWarning() <<
"MNEDescriptionParser: misplaced eventfile";
return false; }
518 if (word.compare(
"logfile", Qt::CaseInsensitive) == 0) {
519 QString val = nextWord(in);
520 if (inCov && !inDef) desc.
logFile = val;
521 else { qWarning() <<
"MNEDescriptionParser: misplaced logfile";
return false; }
524 if (word.compare(
"keepsamplemean", Qt::CaseInsensitive) == 0) {
526 else { qWarning() <<
"MNEDescriptionParser: misplaced keepsamplemean";
return false; }
529 if (word.compare(
"fixskew", Qt::CaseInsensitive) == 0) {
530 if (inCov && !inDef) desc.
fixSkew =
true;
531 else { qWarning() <<
"MNEDescriptionParser: misplaced fixskew";
return false; }
536 if (word.compare(
"tmin", Qt::CaseInsensitive) == 0) {
537 float fval;
if (!getFloat(in, fval))
return false;
538 if (inDef) currentDef.
tmin = fval;
539 else { qWarning() <<
"MNEDescriptionParser: misplaced tmin";
return false; }
542 if (word.compare(
"tmax", Qt::CaseInsensitive) == 0) {
543 float fval;
if (!getFloat(in, fval))
return false;
544 if (inDef) currentDef.
tmax = fval;
545 else { qWarning() <<
"MNEDescriptionParser: misplaced tmax";
return false; }
548 if (word.compare(
"basemin", Qt::CaseInsensitive) == 0 ||
549 word.compare(
"bmin", Qt::CaseInsensitive) == 0) {
550 float fval;
if (!getFloat(in, fval))
return false;
551 if (inDef) { currentDef.
bmin = fval; bminSet =
true; }
552 else { qWarning() <<
"MNEDescriptionParser: misplaced basemin";
return false; }
555 if (word.compare(
"basemax", Qt::CaseInsensitive) == 0 ||
556 word.compare(
"bmax", Qt::CaseInsensitive) == 0) {
557 float fval;
if (!getFloat(in, fval))
return false;
558 if (inDef) { currentDef.
bmax = fval; bmaxSet =
true; }
559 else { qWarning() <<
"MNEDescriptionParser: misplaced basemax";
return false; }
562 if (word.compare(
"event", Qt::CaseInsensitive) == 0) {
563 int ival;
if (!getInt(in, ival))
return false;
564 if (ival <= 0) { qWarning() <<
"MNEDescriptionParser: event must be positive";
return false; }
565 if (inDef) currentDef.
events.append(
static_cast<unsigned int>(ival));
566 else { qWarning() <<
"MNEDescriptionParser: misplaced event";
return false; }
569 if (word.compare(
"ignore", Qt::CaseInsensitive) == 0) {
570 int ival;
if (!getInt(in, ival))
return false;
571 if (inDef) currentDef.
ignore =
static_cast<unsigned int>(ival);
572 else { qWarning() <<
"MNEDescriptionParser: misplaced ignore";
return false; }
575 if (word.compare(
"mask", Qt::CaseInsensitive) == 0) {
576 int ival;
if (!getInt(in, ival))
return false;
577 if (inDef) { currentDef.
ignore =
static_cast<unsigned int>(ival); currentDef.
ignore = ~currentDef.ignore; }
578 else { qWarning() <<
"MNEDescriptionParser: misplaced mask";
return false; }
581 if (word.compare(
"delay", Qt::CaseInsensitive) == 0) {
582 float fval;
if (!getFloat(in, fval))
return false;
583 if (inDef) currentDef.
delay = fval;
584 else { qWarning() <<
"MNEDescriptionParser: misplaced delay";
return false; }
589 if (inCov && !inDef) {
591 if (parseRejectionParam(word, in, desc.
rej, parseOk)) {
592 if (!parseOk)
return false;
597 qWarning() <<
"MNEDescriptionParser: unknown keyword" << word <<
"in" << fileName;