188 QFile file(fileName);
189 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
190 qWarning() <<
"MNEDescriptionParser: cannot open" << fileName;
194 QTextStream in(&file);
197 bool expectBrace =
false;
198 bool bminSet =
false, bmaxSet =
false;
199 bool inAverage =
false;
200 bool inCategory =
false;
204 while (!(word = nextWord(in)).isEmpty()) {
209 qWarning() <<
"MNEDescriptionParser: expected '{', got" << word;
216 qWarning() <<
"MNEDescriptionParser: unexpected '{'";
224 if (currentCat.
comment.isEmpty()) {
225 qWarning() <<
"MNEDescriptionParser: category name missing";
228 if (currentCat.
tmin >= currentCat.
tmax) {
229 qWarning() <<
"MNEDescriptionParser: illegal time range for" << currentCat.
comment;
232 if (currentCat.
events.isEmpty()) {
233 qWarning() <<
"MNEDescriptionParser: no events for" << currentCat.
comment;
241 bminSet = bmaxSet =
false;
242 }
else if (inAverage) {
251 if (word.compare(
"average", Qt::CaseInsensitive) == 0) {
252 if (inAverage || inCategory) {
253 qWarning() <<
"MNEDescriptionParser: nested average";
262 if (word.compare(
"category", Qt::CaseInsensitive) == 0 ||
263 word.compare(
"condition", Qt::CaseInsensitive) == 0) {
264 if (!inAverage || inCategory) {
265 qWarning() <<
"MNEDescriptionParser: misplaced category";
270 bminSet = bmaxSet =
false;
275 if (word.compare(
"name", Qt::CaseInsensitive) == 0) {
276 QString val = nextWord(in);
277 if (val.isEmpty()) { qWarning() <<
"MNEDescriptionParser: name requires a value";
return false; }
278 if (inCategory) currentCat.
comment = val;
279 else if (inAverage) desc.
comment = val;
280 else { qWarning() <<
"MNEDescriptionParser: misplaced name";
return false; }
285 if (word.compare(
"outfile", Qt::CaseInsensitive) == 0) {
286 QString val = nextWord(in);
287 if (val.isEmpty()) { qWarning() <<
"MNEDescriptionParser: outfile requires a value";
return false; }
288 if (inAverage && !inCategory) desc.
filename = val;
289 else { qWarning() <<
"MNEDescriptionParser: misplaced outfile";
return false; }
294 if (word.compare(
"eventfile", Qt::CaseInsensitive) == 0) {
295 QString val = nextWord(in);
296 if (val.isEmpty()) { qWarning() <<
"MNEDescriptionParser: eventfile requires a value";
return false; }
297 if (inAverage && !inCategory) desc.
eventFile = val;
298 else { qWarning() <<
"MNEDescriptionParser: misplaced eventfile";
return false; }
303 if (word.compare(
"logfile", Qt::CaseInsensitive) == 0) {
304 QString val = nextWord(in);
305 if (val.isEmpty()) { qWarning() <<
"MNEDescriptionParser: logfile requires a value";
return false; }
306 if (inAverage && !inCategory) desc.
logFile = val;
307 else { qWarning() <<
"MNEDescriptionParser: misplaced logfile";
return false; }
312 if (word.compare(
"fixskew", Qt::CaseInsensitive) == 0) {
313 if (inAverage && !inCategory) desc.
fixSkew =
true;
314 else { qWarning() <<
"MNEDescriptionParser: misplaced fixskew";
return false; }
319 if (word.compare(
"tmin", Qt::CaseInsensitive) == 0) {
320 float fval;
if (!getFloat(in, fval))
return false;
321 if (inCategory) currentCat.
tmin = fval;
322 else { qWarning() <<
"MNEDescriptionParser: misplaced tmin";
return false; }
325 if (word.compare(
"tmax", Qt::CaseInsensitive) == 0) {
326 float fval;
if (!getFloat(in, fval))
return false;
327 if (inCategory) currentCat.
tmax = fval;
328 else { qWarning() <<
"MNEDescriptionParser: misplaced tmax";
return false; }
331 if (word.compare(
"basemin", Qt::CaseInsensitive) == 0 ||
332 word.compare(
"bmin", Qt::CaseInsensitive) == 0) {
333 float fval;
if (!getFloat(in, fval))
return false;
334 if (inCategory) { currentCat.
bmin = fval; bminSet =
true; }
335 else { qWarning() <<
"MNEDescriptionParser: misplaced basemin";
return false; }
338 if (word.compare(
"basemax", Qt::CaseInsensitive) == 0 ||
339 word.compare(
"bmax", Qt::CaseInsensitive) == 0) {
340 float fval;
if (!getFloat(in, fval))
return false;
341 if (inCategory) { currentCat.
bmax = fval; bmaxSet =
true; }
342 else { qWarning() <<
"MNEDescriptionParser: misplaced basemax";
return false; }
345 if (word.compare(
"event", Qt::CaseInsensitive) == 0) {
346 int ival;
if (!getInt(in, ival))
return false;
347 if (ival <= 0) { qWarning() <<
"MNEDescriptionParser: event numbers must be positive";
return false; }
348 if (inCategory) currentCat.
events.append(
static_cast<unsigned int>(ival));
349 else { qWarning() <<
"MNEDescriptionParser: misplaced event";
return false; }
352 if (word.compare(
"nextevent", Qt::CaseInsensitive) == 0) {
353 int ival;
if (!getInt(in, ival))
return false;
354 if (ival <= 0) { qWarning() <<
"MNEDescriptionParser: nextevent must be positive";
return false; }
355 if (inCategory) currentCat.
nextEvent =
static_cast<unsigned int>(ival);
356 else { qWarning() <<
"MNEDescriptionParser: misplaced nextevent";
return false; }
359 if (word.compare(
"prevevent", Qt::CaseInsensitive) == 0) {
360 int ival;
if (!getInt(in, ival))
return false;
361 if (ival <= 0) { qWarning() <<
"MNEDescriptionParser: prevevent must be positive";
return false; }
362 if (inCategory) currentCat.
prevEvent =
static_cast<unsigned int>(ival);
363 else { qWarning() <<
"MNEDescriptionParser: misplaced prevevent";
return false; }
366 if (word.compare(
"ignore", Qt::CaseInsensitive) == 0) {
367 int ival;
if (!getInt(in, ival))
return false;
368 if (inCategory) currentCat.
ignore =
static_cast<unsigned int>(ival);
369 else { qWarning() <<
"MNEDescriptionParser: misplaced ignore";
return false; }
372 if (word.compare(
"prevignore", Qt::CaseInsensitive) == 0) {
373 int ival;
if (!getInt(in, ival))
return false;
374 if (inCategory) currentCat.
prevIgnore =
static_cast<unsigned int>(ival);
375 else { qWarning() <<
"MNEDescriptionParser: misplaced prevignore";
return false; }
378 if (word.compare(
"nextignore", Qt::CaseInsensitive) == 0) {
379 int ival;
if (!getInt(in, ival))
return false;
380 if (inCategory) currentCat.
nextIgnore =
static_cast<unsigned int>(ival);
381 else { qWarning() <<
"MNEDescriptionParser: misplaced nextignore";
return false; }
384 if (word.compare(
"mask", Qt::CaseInsensitive) == 0) {
385 int ival;
if (!getInt(in, ival))
return false;
386 if (ival <= 0) { qWarning() <<
"MNEDescriptionParser: mask must be positive";
return false; }
387 if (inCategory) { currentCat.
ignore =
static_cast<unsigned int>(ival); currentCat.
ignore = ~currentCat.ignore; }
388 else { qWarning() <<
"MNEDescriptionParser: misplaced mask";
return false; }
391 if (word.compare(
"prevmask", Qt::CaseInsensitive) == 0) {
392 int ival;
if (!getInt(in, ival))
return false;
393 if (inCategory) { currentCat.
prevIgnore =
static_cast<unsigned int>(ival); currentCat.
prevIgnore = ~currentCat.prevIgnore; }
394 else { qWarning() <<
"MNEDescriptionParser: misplaced prevmask";
return false; }
397 if (word.compare(
"nextmask", Qt::CaseInsensitive) == 0) {
398 int ival;
if (!getInt(in, ival))
return false;
399 if (inCategory) { currentCat.
nextIgnore =
static_cast<unsigned int>(ival); currentCat.
nextIgnore = ~currentCat.nextIgnore; }
400 else { qWarning() <<
"MNEDescriptionParser: misplaced nextmask";
return false; }
403 if (word.compare(
"delay", Qt::CaseInsensitive) == 0) {
404 float fval;
if (!getFloat(in, fval))
return false;
405 if (inCategory) currentCat.
delay = fval;
406 else { qWarning() <<
"MNEDescriptionParser: misplaced delay";
return false; }
409 if (word.compare(
"stderr", Qt::CaseInsensitive) == 0) {
410 if (inCategory) currentCat.
doStdErr =
true;
411 else { qWarning() <<
"MNEDescriptionParser: misplaced stderr";
return false; }
414 if (word.compare(
"abs", Qt::CaseInsensitive) == 0) {
415 if (inCategory) currentCat.
doAbs =
true;
416 else { qWarning() <<
"MNEDescriptionParser: misplaced abs";
return false; }
419 if (word.compare(
"color", Qt::CaseInsensitive) == 0) {
421 if (!getFloat(in, r) || !getFloat(in, g) || !getFloat(in, b))
return false;
422 if (inCategory) { currentCat.
color[0] = r; currentCat.
color[1] = g; currentCat.
color[2] = b; }
423 else { qWarning() <<
"MNEDescriptionParser: misplaced color";
return false; }
428 if (inAverage && !inCategory) {
430 if (parseRejectionParam(word, in, desc.
rej, parseOk)) {
431 if (!parseOk)
return false;
436 qWarning() <<
"MNEDescriptionParser: unknown keyword" << word <<
"in" << fileName;
440 qWarning() <<
"MNEDescriptionParser: no categories found in" << fileName;
453 QFile file(fileName);
454 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
455 qWarning() <<
"MNEDescriptionParser: cannot open" << fileName;
459 QTextStream in(&file);
462 bool expectBrace =
false;
463 bool bminSet =
false, bmaxSet =
false;
469 while (!(word = nextWord(in)).isEmpty()) {
474 qWarning() <<
"MNEDescriptionParser: expected '{', got" << word;
481 qWarning() <<
"MNEDescriptionParser: unexpected '{'";
488 if (currentDef.
tmin >= currentDef.
tmax) {
489 qWarning() <<
"MNEDescriptionParser: illegal time range in def";
492 desc.
defs.append(currentDef);
495 bminSet = bmaxSet =
false;
503 if (word.compare(
"cov", Qt::CaseInsensitive) == 0) {
504 if (inCov || inDef) {
505 qWarning() <<
"MNEDescriptionParser: nested cov";
513 if (word.compare(
"def", Qt::CaseInsensitive) == 0) {
514 if (!inCov || inDef) {
515 qWarning() <<
"MNEDescriptionParser: misplaced def";
520 bminSet = bmaxSet =
false;
525 if (word.compare(
"outfile", Qt::CaseInsensitive) == 0) {
526 QString val = nextWord(in);
527 if (inCov && !inDef) desc.
filename = val;
528 else { qWarning() <<
"MNEDescriptionParser: misplaced outfile";
return false; }
531 if (word.compare(
"eventfile", Qt::CaseInsensitive) == 0) {
532 QString val = nextWord(in);
533 if (inCov && !inDef) desc.
eventFile = val;
534 else { qWarning() <<
"MNEDescriptionParser: misplaced eventfile";
return false; }
537 if (word.compare(
"logfile", Qt::CaseInsensitive) == 0) {
538 QString val = nextWord(in);
539 if (inCov && !inDef) desc.
logFile = val;
540 else { qWarning() <<
"MNEDescriptionParser: misplaced logfile";
return false; }
543 if (word.compare(
"keepsamplemean", Qt::CaseInsensitive) == 0) {
545 else { qWarning() <<
"MNEDescriptionParser: misplaced keepsamplemean";
return false; }
548 if (word.compare(
"fixskew", Qt::CaseInsensitive) == 0) {
549 if (inCov && !inDef) desc.
fixSkew =
true;
550 else { qWarning() <<
"MNEDescriptionParser: misplaced fixskew";
return false; }
555 if (word.compare(
"tmin", Qt::CaseInsensitive) == 0) {
556 float fval;
if (!getFloat(in, fval))
return false;
557 if (inDef) currentDef.
tmin = fval;
558 else { qWarning() <<
"MNEDescriptionParser: misplaced tmin";
return false; }
561 if (word.compare(
"tmax", Qt::CaseInsensitive) == 0) {
562 float fval;
if (!getFloat(in, fval))
return false;
563 if (inDef) currentDef.
tmax = fval;
564 else { qWarning() <<
"MNEDescriptionParser: misplaced tmax";
return false; }
567 if (word.compare(
"basemin", Qt::CaseInsensitive) == 0 ||
568 word.compare(
"bmin", Qt::CaseInsensitive) == 0) {
569 float fval;
if (!getFloat(in, fval))
return false;
570 if (inDef) { currentDef.
bmin = fval; bminSet =
true; }
571 else { qWarning() <<
"MNEDescriptionParser: misplaced basemin";
return false; }
574 if (word.compare(
"basemax", Qt::CaseInsensitive) == 0 ||
575 word.compare(
"bmax", Qt::CaseInsensitive) == 0) {
576 float fval;
if (!getFloat(in, fval))
return false;
577 if (inDef) { currentDef.
bmax = fval; bmaxSet =
true; }
578 else { qWarning() <<
"MNEDescriptionParser: misplaced basemax";
return false; }
581 if (word.compare(
"event", Qt::CaseInsensitive) == 0) {
582 int ival;
if (!getInt(in, ival))
return false;
583 if (ival <= 0) { qWarning() <<
"MNEDescriptionParser: event must be positive";
return false; }
584 if (inDef) currentDef.
events.append(
static_cast<unsigned int>(ival));
585 else { qWarning() <<
"MNEDescriptionParser: misplaced event";
return false; }
588 if (word.compare(
"ignore", Qt::CaseInsensitive) == 0) {
589 int ival;
if (!getInt(in, ival))
return false;
590 if (inDef) currentDef.
ignore =
static_cast<unsigned int>(ival);
591 else { qWarning() <<
"MNEDescriptionParser: misplaced ignore";
return false; }
594 if (word.compare(
"mask", Qt::CaseInsensitive) == 0) {
595 int ival;
if (!getInt(in, ival))
return false;
596 if (inDef) { currentDef.
ignore =
static_cast<unsigned int>(ival); currentDef.
ignore = ~currentDef.ignore; }
597 else { qWarning() <<
"MNEDescriptionParser: misplaced mask";
return false; }
600 if (word.compare(
"delay", Qt::CaseInsensitive) == 0) {
601 float fval;
if (!getFloat(in, fval))
return false;
602 if (inDef) currentDef.
delay = fval;
603 else { qWarning() <<
"MNEDescriptionParser: misplaced delay";
return false; }
608 if (inCov && !inDef) {
610 if (parseRejectionParam(word, in, desc.
rej, parseOk)) {
611 if (!parseOk)
return false;
616 qWarning() <<
"MNEDescriptionParser: unknown keyword" << word <<
"in" << fileName;