193 QFile file(fileName);
194 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
195 qWarning() <<
"MNEDescriptionParser: cannot open" << fileName;
199 QTextStream in(&file);
202 bool expectBrace =
false;
203 bool bminSet =
false, bmaxSet =
false;
204 bool inAverage =
false;
205 bool inCategory =
false;
209 while (!(word = nextWord(in)).isEmpty()) {
214 qWarning() <<
"MNEDescriptionParser: expected '{', got" << word;
221 qWarning() <<
"MNEDescriptionParser: unexpected '{'";
229 if (currentCat.
comment.isEmpty()) {
230 qWarning() <<
"MNEDescriptionParser: category name missing";
233 if (currentCat.
tmin >= currentCat.
tmax) {
234 qWarning() <<
"MNEDescriptionParser: illegal time range for" << currentCat.
comment;
237 if (currentCat.
events.isEmpty()) {
238 qWarning() <<
"MNEDescriptionParser: no events for" << currentCat.
comment;
242 qWarning() <<
"MNEDescriptionParser: illegal baseline for" << currentCat.
comment;
252 bminSet = bmaxSet =
false;
253 }
else if (inAverage) {
263 if (word.compare(
"average", Qt::CaseInsensitive) == 0) {
264 if (inAverage || inCategory) {
265 qWarning() <<
"MNEDescriptionParser: nested average";
274 if (word.compare(
"category", Qt::CaseInsensitive) == 0 ||
275 word.compare(
"condition", Qt::CaseInsensitive) == 0) {
276 if (!inAverage || inCategory) {
277 qWarning() <<
"MNEDescriptionParser: misplaced category";
282 bminSet = bmaxSet =
false;
287 if (word.compare(
"name", Qt::CaseInsensitive) == 0) {
288 QString val = nextWord(in);
290 qWarning() <<
"MNEDescriptionParser: name requires a value";
298 qWarning() <<
"MNEDescriptionParser: misplaced name";
305 if (word.compare(
"outfile", Qt::CaseInsensitive) == 0) {
306 QString val = nextWord(in);
308 qWarning() <<
"MNEDescriptionParser: outfile requires a value";
311 if (inAverage && !inCategory)
314 qWarning() <<
"MNEDescriptionParser: misplaced outfile";
321 if (word.compare(
"eventfile", Qt::CaseInsensitive) == 0) {
322 QString val = nextWord(in);
324 qWarning() <<
"MNEDescriptionParser: eventfile requires a value";
327 if (inAverage && !inCategory)
330 qWarning() <<
"MNEDescriptionParser: misplaced eventfile";
337 if (word.compare(
"logfile", Qt::CaseInsensitive) == 0) {
338 QString val = nextWord(in);
340 qWarning() <<
"MNEDescriptionParser: logfile requires a value";
343 if (inAverage && !inCategory)
346 qWarning() <<
"MNEDescriptionParser: misplaced logfile";
353 if (word.compare(
"fixskew", Qt::CaseInsensitive) == 0) {
354 if (inAverage && !inCategory)
357 qWarning() <<
"MNEDescriptionParser: misplaced fixskew";
364 if (word.compare(
"tmin", Qt::CaseInsensitive) == 0) {
366 if (!getFloat(in, fval))
369 currentCat.
tmin = fval;
371 qWarning() <<
"MNEDescriptionParser: misplaced tmin";
376 if (word.compare(
"tmax", Qt::CaseInsensitive) == 0) {
378 if (!getFloat(in, fval))
381 currentCat.
tmax = fval;
383 qWarning() <<
"MNEDescriptionParser: misplaced tmax";
388 if (word.compare(
"basemin", Qt::CaseInsensitive) == 0 ||
389 word.compare(
"bmin", Qt::CaseInsensitive) == 0) {
391 if (!getFloat(in, fval))
394 currentCat.
bmin = fval;
397 qWarning() <<
"MNEDescriptionParser: misplaced basemin";
402 if (word.compare(
"basemax", Qt::CaseInsensitive) == 0 ||
403 word.compare(
"bmax", Qt::CaseInsensitive) == 0) {
405 if (!getFloat(in, fval))
408 currentCat.
bmax = fval;
411 qWarning() <<
"MNEDescriptionParser: misplaced basemax";
416 if (word.compare(
"event", Qt::CaseInsensitive) == 0) {
418 if (!getInt(in, ival))
421 qWarning() <<
"MNEDescriptionParser: event numbers must be positive";
425 currentCat.
events.append(
static_cast<unsigned int>(ival));
427 qWarning() <<
"MNEDescriptionParser: misplaced event";
432 if (word.compare(
"nextevent", Qt::CaseInsensitive) == 0) {
434 if (!getInt(in, ival))
437 qWarning() <<
"MNEDescriptionParser: nextevent must be positive";
441 currentCat.
nextEvent =
static_cast<unsigned int>(ival);
443 qWarning() <<
"MNEDescriptionParser: misplaced nextevent";
448 if (word.compare(
"prevevent", Qt::CaseInsensitive) == 0) {
450 if (!getInt(in, ival))
453 qWarning() <<
"MNEDescriptionParser: prevevent must be positive";
457 currentCat.
prevEvent =
static_cast<unsigned int>(ival);
459 qWarning() <<
"MNEDescriptionParser: misplaced prevevent";
464 if (word.compare(
"ignore", Qt::CaseInsensitive) == 0) {
466 if (!getInt(in, ival))
469 qWarning() <<
"MNEDescriptionParser: ignore numbers must be positive or zero";
473 currentCat.
ignore =
static_cast<unsigned int>(ival);
475 qWarning() <<
"MNEDescriptionParser: misplaced ignore";
480 if (word.compare(
"prevignore", Qt::CaseInsensitive) == 0) {
482 if (!getInt(in, ival))
485 qWarning() <<
"MNEDescriptionParser: ignore numbers must be positive or zero";
489 currentCat.
prevIgnore =
static_cast<unsigned int>(ival);
491 qWarning() <<
"MNEDescriptionParser: misplaced prevignore";
496 if (word.compare(
"nextignore", Qt::CaseInsensitive) == 0) {
498 if (!getInt(in, ival))
501 qWarning() <<
"MNEDescriptionParser: ignore numbers must be positive or zero";
505 currentCat.
nextIgnore =
static_cast<unsigned int>(ival);
507 qWarning() <<
"MNEDescriptionParser: misplaced nextignore";
512 if (word.compare(
"mask", Qt::CaseInsensitive) == 0) {
514 if (!getInt(in, ival))
517 qWarning() <<
"MNEDescriptionParser: mask must be positive";
521 currentCat.
ignore =
static_cast<unsigned int>(ival);
522 currentCat.
ignore = ~currentCat.ignore;
524 qWarning() <<
"MNEDescriptionParser: misplaced mask";
529 if (word.compare(
"prevmask", Qt::CaseInsensitive) == 0) {
531 if (!getInt(in, ival))
534 qWarning() <<
"MNEDescriptionParser: mask numbers must be positive";
538 currentCat.
prevIgnore =
static_cast<unsigned int>(ival);
539 currentCat.
prevIgnore = ~currentCat.prevIgnore;
541 qWarning() <<
"MNEDescriptionParser: misplaced prevmask";
546 if (word.compare(
"nextmask", Qt::CaseInsensitive) == 0) {
548 if (!getInt(in, ival))
551 qWarning() <<
"MNEDescriptionParser: mask numbers must be positive";
555 currentCat.
nextIgnore =
static_cast<unsigned int>(ival);
556 currentCat.
nextIgnore = ~currentCat.nextIgnore;
558 qWarning() <<
"MNEDescriptionParser: misplaced nextmask";
563 if (word.compare(
"delay", Qt::CaseInsensitive) == 0) {
565 if (!getFloat(in, fval))
568 currentCat.
delay = fval;
570 qWarning() <<
"MNEDescriptionParser: misplaced delay";
575 if (word.compare(
"stderr", Qt::CaseInsensitive) == 0) {
579 qWarning() <<
"MNEDescriptionParser: misplaced stderr";
584 if (word.compare(
"abs", Qt::CaseInsensitive) == 0) {
586 currentCat.
doAbs =
true;
588 qWarning() <<
"MNEDescriptionParser: misplaced abs";
593 if (word.compare(
"color", Qt::CaseInsensitive) == 0) {
595 if (!getFloat(in, r) || !getFloat(in, g) || !getFloat(in, b))
597 if (r < 0.0f || r > 1.0f || g < 0.0f || g > 1.0f || b < 0.0f || b > 1.0f) {
598 qWarning() <<
"MNEDescriptionParser: color components must be within 0 ... 1";
602 currentCat.
color[0] = r;
603 currentCat.
color[1] = g;
604 currentCat.
color[2] = b;
606 qWarning() <<
"MNEDescriptionParser: misplaced color";
614 if (parseRejectionParam(word, in, desc.
rej, parseOk)) {
615 if (!(inAverage && !inCategory)) {
616 qWarning() <<
"MNEDescriptionParser: misplaced" << word;
624 qWarning() <<
"MNEDescriptionParser: unknown keyword" << word <<
"in" << fileName;
628 qWarning() <<
"MNEDescriptionParser: no categories found in" << fileName;
641 QFile file(fileName);
642 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
643 qWarning() <<
"MNEDescriptionParser: cannot open" << fileName;
647 QTextStream in(&file);
650 bool expectBrace =
false;
651 bool bminSet =
false, bmaxSet =
false;
653 bool seenCov =
false;
658 while (!(word = nextWord(in)).isEmpty()) {
663 qWarning() <<
"MNEDescriptionParser: expected '{', got" << word;
670 qWarning() <<
"MNEDescriptionParser: unexpected '{'";
677 if (currentDef.
tmin >= currentDef.
tmax) {
678 qWarning() <<
"MNEDescriptionParser: illegal time range in def";
682 qWarning() <<
"MNEDescriptionParser: illegal baseline in def";
685 desc.
defs.append(currentDef);
688 bminSet = bmaxSet =
false;
696 if (word.compare(
"cov", Qt::CaseInsensitive) == 0) {
697 if (inCov || inDef) {
698 qWarning() <<
"MNEDescriptionParser: nested cov";
707 if (word.compare(
"def", Qt::CaseInsensitive) == 0) {
708 if (!inCov || inDef) {
709 qWarning() <<
"MNEDescriptionParser: misplaced def";
714 bminSet = bmaxSet =
false;
719 if (word.compare(
"outfile", Qt::CaseInsensitive) == 0) {
720 QString val = nextWord(in);
722 qWarning() <<
"MNEDescriptionParser: outfile requires a value";
728 qWarning() <<
"MNEDescriptionParser: misplaced outfile";
733 if (word.compare(
"eventfile", Qt::CaseInsensitive) == 0) {
734 QString val = nextWord(in);
736 qWarning() <<
"MNEDescriptionParser: eventfile requires a value";
742 qWarning() <<
"MNEDescriptionParser: misplaced eventfile";
747 if (word.compare(
"logfile", Qt::CaseInsensitive) == 0) {
748 QString val = nextWord(in);
750 qWarning() <<
"MNEDescriptionParser: logfile requires a value";
756 qWarning() <<
"MNEDescriptionParser: misplaced logfile";
761 if (word.compare(
"keepsamplemean", Qt::CaseInsensitive) == 0) {
765 qWarning() <<
"MNEDescriptionParser: misplaced keepsamplemean";
770 if (word.compare(
"fixskew", Qt::CaseInsensitive) == 0) {
774 qWarning() <<
"MNEDescriptionParser: misplaced fixskew";
781 if (word.compare(
"tmin", Qt::CaseInsensitive) == 0) {
783 if (!getFloat(in, fval))
786 currentDef.
tmin = fval;
788 qWarning() <<
"MNEDescriptionParser: misplaced tmin";
793 if (word.compare(
"tmax", Qt::CaseInsensitive) == 0) {
795 if (!getFloat(in, fval))
798 currentDef.
tmax = fval;
800 qWarning() <<
"MNEDescriptionParser: misplaced tmax";
805 if (word.compare(
"basemin", Qt::CaseInsensitive) == 0 ||
806 word.compare(
"bmin", Qt::CaseInsensitive) == 0) {
808 if (!getFloat(in, fval))
811 currentDef.
bmin = fval;
814 qWarning() <<
"MNEDescriptionParser: misplaced basemin";
819 if (word.compare(
"basemax", Qt::CaseInsensitive) == 0 ||
820 word.compare(
"bmax", Qt::CaseInsensitive) == 0) {
822 if (!getFloat(in, fval))
825 currentDef.
bmax = fval;
828 qWarning() <<
"MNEDescriptionParser: misplaced basemax";
833 if (word.compare(
"event", Qt::CaseInsensitive) == 0) {
835 if (!getInt(in, ival))
838 qWarning() <<
"MNEDescriptionParser: event must be positive";
842 currentDef.
events.append(
static_cast<unsigned int>(ival));
844 qWarning() <<
"MNEDescriptionParser: misplaced event";
849 if (word.compare(
"ignore", Qt::CaseInsensitive) == 0) {
851 if (!getInt(in, ival))
854 qWarning() <<
"MNEDescriptionParser: ignore numbers must be positive or zero";
858 currentDef.
ignore =
static_cast<unsigned int>(ival);
860 qWarning() <<
"MNEDescriptionParser: misplaced ignore";
865 if (word.compare(
"mask", Qt::CaseInsensitive) == 0) {
867 if (!getInt(in, ival))
870 qWarning() <<
"MNEDescriptionParser: mask numbers must be positive";
874 currentDef.
ignore =
static_cast<unsigned int>(ival);
875 currentDef.
ignore = ~currentDef.ignore;
877 qWarning() <<
"MNEDescriptionParser: misplaced mask";
882 if (word.compare(
"delay", Qt::CaseInsensitive) == 0) {
884 if (!getFloat(in, fval))
887 currentDef.
delay = fval;
889 qWarning() <<
"MNEDescriptionParser: misplaced delay";
897 if (parseRejectionParam(word, in, desc.
rej, parseOk)) {
898 if (!(inCov && !inDef)) {
899 qWarning() <<
"MNEDescriptionParser: misplaced" << word;
907 qWarning() <<
"MNEDescriptionParser: unknown keyword" << word <<
"in" << fileName;
911 qWarning() <<
"MNEDescriptionParser: nothing useful read from" << fileName;