-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheval.cpp
6783 lines (5255 loc) · 187 KB
/
eval.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// --------------------------------------------------------------------
//
// This file is part of Luna.
//
// LUNA is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Luna is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Luna. If not, see <http://www.gnu.org/licenses/>.
//
// Please see LICENSE.txt for more details.
//
// --------------------------------------------------------------------
#include "eval.h"
#include "luna.h"
extern logger_t logger;
extern writer_t writer;
extern freezer_t freezer;
//
// cmd_t
//
cmd_t::cmd_t( const bool silent )
{
register_specials();
reset();
error = ! read( NULL , silent );
}
cmd_t::cmd_t( const std::string & str , const bool silent )
{
register_specials();
reset();
error = ! read( &str , silent );
}
void cmd_t::add_cmdline_cmd( const std::string & c )
{
cmdline_cmds.append( c + " " );
}
void cmd_t::reset()
{
cmds.clear();
params.clear();
line = "";
error = false;
will_quit = false;
}
void cmd_t::clear_static_members()
{
input = "";
cmdline_cmds = "";
stout_file = "";
append_stout_file = false;
vars.clear();
ivars.clear();
idmapper.clear();
signallist.clear();
label_aliases.clear();
primary_alias.clear();
primary_upper2orig.clear();
}
bool cmd_t::empty() const
{
return will_quit;
}
bool cmd_t::valid() const
{
if ( error ) return false;
/* for (int c=0;c<cmds.size();c++) */
/* if ( commands.find( cmds[c] ) == commands.end() ) return false; */
return true;
}
bool cmd_t::badline() const
{
return error;
}
std::string cmd_t::offending() const
{
return ( error ? line : "" );
}
int cmd_t::num_cmds() const
{
return cmds.size();
}
std::string cmd_t::cmd(const int i)
{
return cmds[i];
}
param_t & cmd_t::param(const int i)
{
return params[i];
}
bool cmd_t::process_edfs() const
{
// all commands process EDFs, /except/ the following
if ( cmds.size() == 1
&& ( cmds[0] == ""
|| cmds[0] == "."
|| Helper::iequals( cmds[0] , "DUMMY" )
|| Helper::iequals( cmds[0] , "INTERVALS" )
) )
return false;
return true;
}
bool cmd_t::is( const int n , const std::string & s ) const
{
if ( n < 0 || n >= cmds.size() ) Helper::halt( "bad command number" );
return Helper::iequals( cmds[n] , s );
}
std::string cmd_t::data() const
{
return input;
}
bool cmd_t::quit() const
{
return will_quit;
}
void cmd_t::quit(bool b)
{
will_quit = b;
}
void cmd_t::signal_alias( const std::string & s )
{
// the primary alias can occur multiple times, and have multiple
// labels that are mapped to it
// label_aliases[ ALIAS ] -> primary;
// primary_alias[ primary ] -> [ ALIASES ]
// primary_upper2orig[ PRIMARY ] -> primary
// however: two rules
// 1. many-to-one mapping means the same label cannot have multiple primary aliases
// 2. following, and on principle of no transitive properties, alias cannot have alias
// X|Y|Z
// X|A|B okay
// W|A bad, A already mapped
// V|X bad, X already mapped
// i.e. things can only occur once in the RHS, but multiple times in the LHS
// keep all RHS aliases as UPPERCASE
// but with case-insensitive matches
// x|Y|Y
// format canonical|alias1|alias2 , etc.
std::vector<std::string> tok = Helper::quoted_parse( s , "|" );
if ( tok.size() < 2 ) Helper::halt( "bad format for signal alias: canonical|alias 1|alias 2\n" + s );
const std::string primary = Helper::unquote( tok[0] );
// has the LHS primary already been an alias?
if ( label_aliases.find( Helper::toupper( primary ) ) != label_aliases.end() )
Helper::halt( primary + " specified as both primary alias and mapped term" );
for (int j=1;j<tok.size();j++)
{
// impose rules, use upper case version of all aliases
const std::string mapped = Helper::unquote( tok[j] );
const std::string uc_mapped = Helper::toupper( mapped );
if ( primary_upper2orig.find( uc_mapped ) != primary_upper2orig.end() )
Helper::halt( mapped + " specified as both primary alias and mapped term" );
// same alias cannot have multiple, different primaries
// although we track the case of the primary, do case-insensitive match
if ( label_aliases.find( uc_mapped ) != label_aliases.end() )
if ( ! Helper::iequals( primary , label_aliases[ uc_mapped ] ) )
Helper::halt( mapped + " specified twice (case-insensitive) in alias file w/ different primary aliases" );
// otherwise, set this alias, using UC version of the mapped term
label_aliases[ uc_mapped ] = primary;
primary_alias[ primary ].push_back( uc_mapped );
// also, for lookup/checks, track UC primary for case-insensitive matches
// but first check, if we have seen the primary before, it needs to be identical w.r.t. case
if ( primary_upper2orig.find( Helper::toupper( primary ) ) != primary_upper2orig.end() )
{
if ( primary_upper2orig[ Helper::toupper( primary ) ] != primary )
Helper::halt( "primary alias specified with varying case:"
+ primary_upper2orig[ Helper::toupper( primary ) ] + " and " + primary );
}
else
primary_upper2orig[ Helper::toupper( primary ) ] = primary;
}
}
const std::set<std::string> & cmd_t::signals()
{
return signallist;
}
void cmd_t::clear_signals()
{
signallist.clear();
}
std::string cmd_t::signal_string()
{
if ( signallist.size() == 0 ) return "*"; // i.e. all signals
std::stringstream ss;
std::set<std::string>::iterator ii = signallist.begin();
while ( ii != signallist.end() )
{
if ( ii != signallist.begin() ) ss << ",";
ss << *ii;
++ii;
}
return ss.str();
}
void cmd_t::populate_commands()
{
// redundant... now using cmddefs_t
}
// ----------------------------------------------------------------------------------------
//
// Process commands from STDIN
//
// ----------------------------------------------------------------------------------------
void cmd_t::dynamic_parse( const std::string & id )
{
// new version of cmd_t::replace_wildcards()
// which dynamically goes through and does
// - variable substitutions
// - loop unrolling
// - block conditionals
// in a single pass;
// no commands are evaluated, but this is called per-person to allow generic
// dynamic specification of scripts: i.e. variables cannot depend on the outputs
// of luna commands;
// dynamic_parse() should be a drop-in replacement for replace_wildcards()
// e.g. called from lunapi_t too
//
// all the main work is done in proc_all()
//
//
// main input == line (std::string)
// - will contain the original script
// - comments, newlines versus '&' have been taken care of
//
//
// If the script contains an ID wildcard, confirm that ID does not already contain the wildcard
//
if ( line.find( globals::indiv_wildcard ) != std::string::npos &&
id.find( globals::indiv_wildcard ) != std::string::npos )
Helper::halt( "ID " + id + " contains ID-wildcard character "
+ globals::indiv_wildcard + " (i.e. use wildcard=X to specify in a different one)" );
//
// Copy a set of variables, where any i-vars will overwrite an existing var
//
std::map<std::string,std::string> allvars = vars;
if ( ivars.find( id ) != ivars.end() )
{
const std::map<std::string,std::string> & newvars = ivars.find( id )->second;
std::map<std::string,std::string>::const_iterator vv = newvars.begin();
while ( vv != newvars.end() )
{
allvars[ vv->first ] = vv->second;
++vv;
}
}
//
// Parse into lines
//
std::vector<std::string> tok = Helper::quoted_parse( line , "\n" );
//
// expand loops, conditionals and varaibles
//
tok = cmd_t::proc_all( tok , &allvars );
//
// command(s): do this just for printing; real parsing will include variables, etc
//
params.clear();
cmds.clear();
for (int c=0;c<tok.size();c++)
{
std::vector<std::string> ctok = Helper::quoted_parse( tok[c] , "\t " );
// may be 0 if a line was a variable declaration
if ( ctok.size() >= 1 )
{
//std::cout << "adding [" << ctok[0] << "]\n";
cmds.push_back( ctok[0] );
param_t param;
for (int j=1;j<ctok.size();j++) param.parse( ctok[j] );
params.push_back( param );
}
}
// replace in all 'params' any instances of 'globals::indiv_wildcard' with 'id'
// ALSO, will expand any @{includes} from files (which may contain ^ ID wildcards
// in their names, e..g. CHEP bad-channels=@{aux/files/bad-^.txt}
for (int p = 0 ; p < params.size(); p++ )
params[p].update( id , globals::indiv_wildcard );
}
void cmd_t::replace_wildcards( const std::string & id )
{
// ***** REDUNDANT *****
// use the alternate form (defined above) instead of this legacy version
// - i.e. the code in this function can be removed when dynamic_parse()
// is well established
// ***** REDUNDANT *****
// ----> i.e. use dynamic_parse() instead
return dynamic_parse( id );
// all text below if commented out now
//
// get copy of original script; comments, newlines vesrus '&' will already have
// been taken care of
//
// std::string iline = line;
//
// If the script contains an ID wildcard, confirm that ID does not already contain the wildcard
//
// if ( iline.find( globals::indiv_wildcard ) != std::string::npos &&
// id.find( globals::indiv_wildcard ) != std::string::npos )
// Helper::halt( "ID " + id + " contains ID-wildcard character "
// + globals::indiv_wildcard + " (i.e. use wildcard=X to specify in a different one)" );
//
// Copy a set of variables, where any i-vars will overwrite an existing var
//
// std::map<std::string,std::string> allvars = vars;
// if ( ivars.find( id ) != ivars.end() )
// {
// const std::map<std::string,std::string> & newvars = ivars.find( id )->second;
// std::map<std::string,std::string>::const_iterator vv = newvars.begin();
// while ( vv != newvars.end() )
// {
// allvars[ vv->first ] = vv->second;
// ++vv;
// }
// }
//
// REMOVED: IF/NOT/FI (or ENDIF) are now the canonical options
// remove any conditional blocks, where variable should be var=1 (in) or var=0 (out)
// or a value for add=variable,var2 for var=1 var=2
//
// [[var1
// block
// ]]var1
// Helper::process_block_conditionals( &iline , allvars );
//
// Now go line-by-line, to allow variables defined on-the-fly to feature in
// expansions, i.e. to build up expansions
//
// std::vector<std::string> cline = Helper::parse( iline , "\n" );
// iline = "";
// for (int l=0; l<cline.size(); l++)
// {
// std::string currline = cline[l];
// //
// // swap in any variables (and allows for them being defined on-the-fly)
// //
// Helper::swap_in_variables( &currline , &allvars );
// //
// // expand [term][1:10] [ == (term)[list] ] or [list](term) sequences
// //
// Helper::expand_numerics( &currline );
// iline += currline + "\n";
// }
//
// Parse into commands/options
//
// std::vector<std::string> tok = Helper::quoted_parse( iline , "\n" );
//
// expand loops
//
// tok = cmd_t::proc_forloops( tok );
//
// command(s): do this just for printing; real parsing will include variables, etc
//
// params.clear();
// cmds.clear();
// for (int c=0;c<tok.size();c++)
// {
// std::vector<std::string> ctok = Helper::quoted_parse( tok[c] , "\t " );
// // may be 0 if a line was a variable declaration
// if ( ctok.size() >= 1 )
// {
// //std::cout << "adding [" << ctok[0] << "]\n";
// cmds.push_back( ctok[0] );
// param_t param;
// for (int j=1;j<ctok.size();j++) param.parse( ctok[j] );
// params.push_back( param );
// }
// }
// // replace in all 'params' any instances of 'globals::indiv_wildcard' with 'id'
// // ALSO, will expand any @{includes} from files (which may contain ^ ID wildcards
// // in their names, e..g. CHEP bad-channels=@{aux/files/bad-^.txt}
// for (int p = 0 ; p < params.size(); p++ )
// params[p].update( id , globals::indiv_wildcard );
}
bool cmd_t::read( const std::string * str , bool silent )
{
bool cmdline_mode = str == NULL;
if ( std::cin.eof() && cmdline_mode ) return false;
if ( (!cmdline_mode) && str->size() == 0 ) return false;
reset();
// CMD param=1 p=1,2,3 f=true out=o1 & CMD2 etc ;
// EITHER read from std::cin,
// OR from -s command line
// OR from a string (e.g. lunaR)
// Commands are delimited by & symbols (i.e. multi-line statements allowed)
// line continuations must start with + or ... (after whitespace)
// also, can have \ which means a continuation on the next line
// i.e replace \\n with space
std::istringstream allinput;
if ( ! cmdline_mode ) // read from 'str', such as R interface
{
// split by commands ('&' symbols), but allowing for & witin eval expressions
std::vector<std::string> tok = Helper::quoted_parse( *str , "&" );
std::stringstream ss;
for (int l=0;l<tok.size();l++)
{
if ( tok[l] == "" ) continue;
if ( l != 0 ) ss << " & ";
ss << tok[l];
}
allinput.str( ss.str() );
}
// read from std::cin
else if ( cmd_t::cmdline_cmds == "" )
{
std::stringstream ss;
bool first_cmd = true;
while ( 1 )
{
std::string s;
Helper::safe_getline( std::cin , s );
if ( std::cin.eof() ) break;
if ( s == "" ) continue;
s = Helper::ltrim( s ) ;
// is this a continuation line?
// ... or + as first character
bool continuation = s.substr(0,1) == "+" || s.substr(0,3) == "..." ;
if ( continuation )
{
if ( s.substr(0,1) == "+" ) s = s.substr(1);
else s = s.substr(3);
}
// only read up to a % comment, although this may be quoted
if ( s.find( "%" ) != std::string::npos )
{
bool inquote = false;
int comment_start = -1;
for (int i=0;i<s.size();i++)
{
if ( s[i] == '"' ) inquote = ! inquote;
if ( s[i] == '%' && ! inquote ) { comment_start = i; break; }
}
// remove comment
if ( comment_start != -1 )
s = s.substr( 0 , comment_start );
}
// trim leading/trailing whitespace
s = Helper::ltrim( s );
s = Helper::rtrim( s );
// anything left to add?
if ( s.size() > 0 )
{
if ( ! continuation )
{
if ( ! first_cmd ) ss << " & ";
first_cmd = false;
}
else
{
ss << " "; // spacer
}
// add actual non-empty command
ss << s ;
}
}
allinput.str( ss.str() );
}
// read from -s string
else
{
// allow multi-line commands via \ at end
allinput.str( Helper::search_replace( cmd_t::cmdline_cmds , "\\\n", " " ) );
}
// take everything
line = allinput.str();
// change any '&' (back) to '\n', unless they are quoted (" or #)
bool inquote = false;
for (int i=0;i<line.size();i++)
{
if ( line[i] == '"' ) inquote = ! inquote;
else if ( line[i] == '&' )
{
if ( ! inquote ) line[i] = '\n';
}
}
// skip comments between commands if line starts with '%' (or '\n')
bool recheck = true;
while (recheck)
{
if ( line[0] == '%' || line[0] == '\n' )
{
line = line.substr( line.find("\n")+1);
}
else recheck = false;
}
//
// Completed extracting 'line'
//
//
// Note... we used to do processing of command file here (global),
// but as we now use ivars as well as vars, hold on this till
// later, in update()
//
//
// Initial reporting of commands read
//
std::vector<std::string> tok = Helper::quoted_parse( line , "\n" );
if ( tok.size() == 0 )
{
quit(true);
return false;
}
//
// command(s): do this just for printing; real parsing will include variables, etc
//
for (int c=0;c<tok.size();c++)
{
std::vector<std::string> ctok = Helper::quoted_parse( tok[c] , "\t " );
// may be 0 if a line was a variable declaration
if ( ctok.size() >= 1 )
{
cmds.push_back( ctok[0] );
param_t param;
for (int j=1;j<ctok.size();j++) param.parse( ctok[j] );
params.push_back( param );
}
}
// summary
if ( ! silent )
{
logger << "input(s): " << input << "\n";
logger << "output : " << writer.name()
<< ( cmd_t::plaintext_mode ? " [dir for text-tables]" : "" )
<< "\n";
if ( signallist.size() > 0 )
{
logger << "signals :";
for (std::set<std::string>::iterator s=signallist.begin();
s!=signallist.end();s++)
logger << " " << *s ;
logger << "\n";
}
for (int i=0;i<cmds.size();i++)
{
if ( i==0 )
logger << "commands: ";
else
logger << " : ";
logger << "c" << i+1
<< "\t" << cmds[i] << "\t"
<< params[i].dump("","|")
<< "\n";
}
}
return true;
}
//
// Evaluate commands
//
bool cmd_t::eval( edf_t & edf )
{
//
// Conditional evaluation
//
int if_count = 0;
std::string if_condition = "";
//
// Loop over each command
//
for ( int c = 0 ; c < num_cmds() ; c++ )
{
// was a problem flag raised when loading the EDF?
if ( globals::problem ) return false;
//
// If this particular command did not explicitly specify
// signals, then add a wildcard, which will always take all
// in-memory channels
//
if ( ! param(c).has( "sig" ) )
param(c).add_hidden( "sig" , "*" );
//
// Print command
//
logger << " ..................................................................\n"
<< " CMD #" << c+1 << ": " << cmd(c) << "\n";
logger << " options: " << param(c).dump( "" , " " ) << "\n";
//
// Quit?
//
if ( is( c, "EXIT" ) ||
is( c, "STOP" ) ||
is( c, "QUIT" ) )
{
param_t p = param(c);
const bool req_problem = p.has( "if-problem" ) || p.has( "problem" );
const bool req_empty = p.has( "if-empty" ) || p.has( "empty" );
// just quit?
if ( ! ( req_problem || req_empty ) )
return true;
// else, only quit if we match a problem
if ( req_problem && globals::problem ) return true;
if ( req_empty && globals::empty ) return true;
// otherwise, carry on
logger << " not quitting as no problem flag has been set\n";
continue;
}
//
// Is the current mask empty? if so, skip unless this is a THAW
//
if ( globals::empty )
{
// not systematic, but some commands that do not access the EDF are okay
// to rerun - most importantly THAW...
bool skip = true;
if ( is( c, "THAW" ) ) skip = false;
else if ( is( c, "TAG" ) ) skip = false;
else if ( is( c, "HEADERS" ) ) skip = false;
else if ( is( c, "SET-VAR" ) ) skip = false;
else if ( is( c, "SET-HEADERS" ) ) skip = false;
else if ( is( c, "DESC" ) ) skip = false;
else if ( is( c, "ALIASES" ) ) skip = false;
else if ( is( c, "TYPES" ) ) skip = false;
else if ( is( c, "PREDICT" ) ) skip = false;
else if ( is( c, "REPORT" ) ) skip = false;
if ( skip )
{
logger << " ** skipping " << cmd(c) << " as there are no unmasked records\n";
continue;
}
}
//
// Check that epoch type is consistent w/ the command
//
if ( ! edf.timeline.check( cmd(c) ) )
Helper::halt( "cannot apply " + cmd(c) + " with non-standard epoch definitions" );
//
// Process command
//
writer.cmd( cmd(c) , c+1 , param(c).dump( "" , " " ) );
// use strata to keep track of tables by commands, with leading underscore to denote
// special status of this factor
writer.level( cmd(c) , "_" + cmd(c) );
//
// Now process the command
//
bool fnd = false;
if ( (!fnd) && is( c, "WRITE" ) ) { fnd = true; proc_write( edf, param(c) ); }
if ( (!fnd) && is( c, "EDF" ) ) { fnd = true; proc_force_edf( edf , param(c) ); }
if ( (!fnd) && is( c, "EDF-" ) ) { fnd = true; proc_edf_minus( edf , param(c) ); }
if ( (!fnd) && is( c, "EDF-MINUS" ) ) { fnd = true; proc_edf_minus( edf , param(c) ); }
if ( (!fnd) && is( c, "SET-TIMESTAMPS" ) ) { fnd = true; proc_set_timestamps( edf , param(c) ); }
if ( (!fnd) && is( c, "SUMMARY" ) ) { fnd = true; proc_summaries( edf , param(c) ); }
if ( (!fnd) && is( c, "HEADERS" ) ) { fnd = true; proc_headers( edf , param(c) ); }
if ( (!fnd) && is( c, "ALIASES" ) ) { fnd = true; proc_aliases( edf , param(c) ); }
if ( (!fnd) && is( c, "REPORT" ) ) { fnd = true; proc_report( edf , param(c) ); }
if ( (!fnd) && is( c, "SET-HEADERS" ) ) { fnd = true; proc_set_headers( edf , param(c) ); }
if ( (!fnd) && is( c, "SET-VAR" ) ) { fnd = true; proc_set_ivar( edf, param(c) ); }
if ( (!fnd) && is( c, "DESC" ) ) { fnd = true; proc_desc( edf , param(c) ); }
if ( (!fnd) && is( c, "TYPES" ) ) { fnd = true; proc_show_channel_map(); }
if ( (!fnd) && is( c, "VARS" ) ) { fnd = true; proc_dump_vars( edf , param(c) ); }
if ( (!fnd) && is( c, "STATS" ) ) { fnd = true; proc_stats( edf , param(c) ); }
if ( (!fnd) && is( c, "DUPES" ) ) { fnd = true; proc_dupes( edf, param(c) ); }
if ( (!fnd) && is( c, "REFERENCE" ) ) { fnd = true; proc_reference( edf , param(c) ); }
if ( (!fnd) && is( c, "DEREFERENCE" ) ) { fnd = true; proc_dereference( edf , param(c) ); }
if ( (!fnd) && is( c, "FLIP" ) ) { fnd = true; proc_flip( edf , param(c) ); }
if ( (!fnd) && is( c, "RECTIFY" ) ) { fnd = true; proc_rectify( edf , param(c) ); }
if ( (!fnd) && is( c, "REVERSE" ) ) { fnd = true; proc_reverse( edf , param(c) ); }
if ( (!fnd) && is( c, "CANONICAL" ) ) { fnd = true; proc_canonical( edf , param(c) ); }
if ( (!fnd) && is( c, "REMAP" ) ) { fnd = true; proc_remap_annots( edf , param(c) ); }
if ( (!fnd) && is( c, "uV" ) ) { fnd = true; proc_scale( edf , param(c) , "uV" ); }
if ( (!fnd) && is( c, "mV" ) ) { fnd = true; proc_scale( edf , param(c) , "mV" ); }
if ( (!fnd) && is( c, "MINMAX" ) ) { fnd = true; proc_minmax( edf , param(c) ); }
if ( (!fnd) && is( c, "SCALE" ) ) { fnd = true; proc_setscale( edf , param(c) ); }
if ( (!fnd) && is( c, "ROBUST-NORM" ) ) { fnd = true; proc_standardize( edf , param(c) ); }
if ( (!fnd) && is( c, "ROLLING-NORM" ) ) { fnd = true; proc_rolling_norm( edf, param(c) ); }
if ( (!fnd) && is( c, "ALTER" ) ) { fnd = true; proc_correct( edf , param(c) ); }
if ( (!fnd) && is( c, "RECORD-SIZE" ) ) { fnd = true; proc_rerecord( edf , param(c) ); }
if ( (!fnd) && is( c, "TIME-TRACK" ) ) { fnd = true; proc_timetrack( edf, param(c) ); }
if ( (!fnd) && is( c, "STAGE" ) ) { fnd = true; proc_sleep_stage( edf , param(c) , false ); }
if ( (!fnd) && is( c, "HYPNO" ) ) { fnd = true; proc_sleep_stage( edf , param(c) , true ); }
if ( (!fnd) && is( c, "SIG-CYCLES") ) { fnd = true; proc_ecycle( edf , param(c) ); }
if ( (!fnd) && is( c, "TSLIB" ) ) { fnd = true; pdc_t::construct_tslib( edf , param(c) ); }
if ( (!fnd) && is( c, "SSS" ) ) { fnd = true; pdc_t::simple_sleep_scorer( edf , param(c) ); }
if ( (!fnd) && is( c, "EXE" ) ) { fnd = true; pdc_t::similarity_matrix( edf , param(c) ); }
if ( (!fnd) && is( c, "DUMP" ) ) { fnd = true; proc_dump( edf, param(c) ); }
if ( (!fnd) && is( c, "DUMP-RECORDS" ) ) { fnd = true; proc_record_dump( edf , param(c) ); }
if ( (!fnd) && is( c, "RECS" ) ) { fnd = true; proc_record_table( edf , param(c) ); }
if ( (!fnd) && is( c, "SEGMENTS" ) ) { fnd = true; proc_dump_segs( edf , param(c) ); }
if ( (!fnd) && is( c, "DUMP-EPOCHS" ) ) { fnd = true; proc_epoch_dump( edf, param(c) ); } // REDUNDANT -> ANNOTS epoch
if ( (!fnd) && is( c, "ANNOTS" ) ) { fnd = true; proc_list_all_annots( edf, param(c) ); }
if ( (!fnd) && is( c, "ESPAN" ) ) { fnd = true; proc_espan( edf , param(c) ); }
if ( (!fnd) && is( c, "MAKE-ANNOTS" ) ) { fnd = true; proc_make_annots( edf , param(c) ); }
if ( (!fnd) && is( c, "WRITE-ANNOTS" ) ) { fnd = true; proc_write_annots( edf, param(c) ); }
if ( (!fnd) && is( c, "META" ) ) { fnd = true; proc_set_annot_metadata( edf, param(c) ); }
if ( (!fnd) && is( c, "OVERLAP") ) { fnd = true; proc_annotate( edf, param(c) ); }
if ( (!fnd) && is( c, "EXTEND" ) ) { fnd = true; proc_extend_annots( edf, param(c) ); }
if ( (!fnd) && is( c, "AXA") ) { fnd = true; proc_annot_crosstabs( edf, param(c) ); }
if ( (!fnd) && is( c, "A2S" ) ) { fnd = true; proc_annot2signal( edf, param(c) ); }
if ( (!fnd) && is( c, "S2A" ) ) { fnd = true; proc_signal2annot( edf, param(c) ); }
if ( (!fnd) && is( c, "A2C" ) ) { fnd = true; proc_annot2cache( edf , param(c) ); }
if ( (!fnd) && is( c, "C2A" ) ) { fnd = true; proc_cache2annot( edf , param(c) ); }
if ( (!fnd) && is( c, "SPANNING" ) ) { fnd = true; proc_list_spanning_annots( edf, param(c) ); }
if ( (!fnd) && is( c, "MEANS" ) ) { fnd = true; proc_sig_annot_mean( edf, param(c) ); }
if ( (!fnd) && is( c, "TABULATE" ) ) { fnd = true; proc_sig_tabulate( edf, param(c) ); }
if ( (!fnd) && is( c, "MATRIX" ) ) { fnd = true; proc_epoch_matrix( edf , param(c) ); }
if ( (!fnd) && is( c, "HEAD" ) ) { fnd = true; proc_head_matrix( edf , param(c) ); }
if ( (!fnd) && ( is( c, "RESTRUCTURE" ) || is( c, "RE" ) ) ) { fnd = true; proc_restructure( edf , param(c) ); }
if ( (!fnd) && is( c, "SIGNALS" ) ) { fnd = true; proc_drop_signals( edf , param(c) ); }
if ( (!fnd) && is( c, "RENAME" ) ) { fnd = true; proc_rename( edf, param(c) ); }
if ( (!fnd) && is( c, "ENFORCE-SR" ) ) { fnd = true; proc_enforce_signals( edf , param(c) ); }
if ( (!fnd) && is( c, "COPY" ) ) { fnd = true; proc_copy_signal( edf , param(c) ); }
if ( (!fnd) && is( c, "READ" ) ) { fnd = true; proc_read_signal( edf , param(c) ); }
if ( (!fnd) && is( c, "ORDER" ) ) { fnd = true; proc_order_signals( edf , param(c) ); }
if ( (!fnd) && is( c, "CONTAINS" ) ) { fnd = true; proc_has_signals( edf , param(c) ); }
if ( (!fnd) && ( is( c, "RMS" ) || is( c, "SIGSTATS" ) ) ) { fnd = true; proc_rms( edf, param(c) ); }
if ( (!fnd) && is( c, "MSE" ) ) { fnd = true; proc_mse( edf, param(c) ); }
if ( (!fnd) && is( c, "LZW" ) ) { fnd = true; proc_lzw( edf, param(c) ); }
if ( (!fnd) && is( c, "ZR" ) ) { fnd = true; proc_zratio( edf , param(c) ); }
if ( (!fnd) && is( c, "ANON" ) ) { fnd = true; proc_anon( edf , param(c) ); }
if ( (!fnd) && is( c, "EPOCH" ) ) { fnd = true; proc_epoch( edf, param(c) ); }
if ( (!fnd) && is( c, "ALIGN" ) ) { fnd = true; proc_align( edf , param(c) ); }
if ( (!fnd) && is( c, "SLICE" ) ) { fnd = true; proc_slice( edf , param(c) , 1 ); }
if ( (!fnd) && is( c, "ALIGN-EPOCHS" ) ) { fnd = true; proc_align_epochs( edf , param(c) ); }
if ( (!fnd) && is( c, "ALIGN-ANNOTS" ) ) { fnd = true; proc_align_annots( edf , param(c) ); }
if ( (!fnd) && is( c, "INSERT" ) ) { fnd = true; proc_insert( edf , param(c) ); }
if ( (!fnd) && is( c, "SUDS" ) ) { fnd = true; proc_suds( edf , param(c) ); }
if ( (!fnd) && is( c, "MAKE-SUDS" ) ) { fnd = true; proc_make_suds( edf , param(c) ); }
if ( (!fnd) && is( c, "RUN-POPS" ) ) { fnd = true; proc_runpops( edf , param(c) ); } // wrapper
if ( (!fnd) && is( c, "POPS" ) ) { fnd = true; proc_pops( edf , param(c) ); }
if ( (!fnd) && is( c, "EVAL-STAGES" ) ) { fnd = true; proc_eval_stages( edf , param(c) ); }
if ( (!fnd) && is( c, "SOAP" ) ) { fnd = true; proc_self_suds( edf , param(c) ); }
if ( (!fnd) && is( c, "COMPLETE" ) ) { fnd = true; proc_resoap( edf , param(c) ); }
if ( (!fnd) && is( c, "REBASE" ) ) { fnd = true; proc_rebase_soap( edf , param(c) ); } // e.g. 20->30s epochs using SOAP
if ( (!fnd) && is( c, "PLACE" ) ) { fnd = true; proc_place_soap( edf , param(c) ); } // e.g. find where should go
if ( (!fnd) && is( c, "TRANS" ) ) { fnd = true; proc_trans( edf , param(c) ); }
if ( (!fnd) && is( c, "EVAL" ) ) { fnd = true; proc_eval( edf, param(c) ); }
if ( (!fnd) && is( c, "DERIVE" ) ) { fnd = true; proc_derive( edf, param(c) ); }
if ( (!fnd) && is( c, "MASK" ) ) { fnd = true; proc_mask( edf, param(c) ); }
if ( (!fnd) && is( c, "COMBINE" ) ) { fnd = true; proc_combine( edf , param(c) ); }
if ( (!fnd) && is( c, "FREEZE" ) ) { fnd = true; proc_freeze( edf , param(c) ); }
if ( (!fnd) && is( c, "THAW" ) ) { fnd = true; proc_thaw( edf , param(c) ); }
if ( (!fnd) && is( c, "CLEAN-FREEZER")) { fnd = true; proc_clean_freezer( edf , param(c) ); }
if ( (!fnd) && is( c, "FILE-MASK" ) ) { fnd = true; proc_file_mask( edf , param(c) ); } // not supported/implemented
if ( (!fnd) && is( c, "DUMP-MASK" ) ) { fnd = true; proc_dump_mask( edf, param(c) ); }
if ( (!fnd) && is( c, "ANNOT-MASK" ) ) { fnd = true; proc_annot_mask( edf, param(c) ); }
if ( (!fnd) && is( c, "CHEP" ) ) { fnd = true; timeline_t::proc_chep( edf, param(c) ); }
if ( (!fnd) && is( c, "CHEP-MASK" ) ) { fnd = true; proc_chep_mask( edf, param(c) ); }
if ( (!fnd) && is( c, "EPOCH-ANNOT" ) ) { fnd = true; proc_file_annot( edf , param(c) ); }
if ( (!fnd) && is( c, "EPOCH-MASK" ) ) { fnd = true; proc_epoch_mask( edf, param(c) ); }
if ( (!fnd) && is( c, "HB" ) ) { fnd = true; proc_hypoxic_burden( edf, param(c) ); }
if ( (!fnd) && is( c, "FILTER" ) ) { fnd = true; proc_filter( edf, param(c) ); }
if ( (!fnd) && is( c, "FILTER-DESIGN" )) { fnd = true; proc_filter_design( edf, param(c) ); }
if ( (!fnd) && is( c, "MOVING-AVERAGE" )) { fnd = true; proc_moving_average( edf, param(c) ); }
if ( (!fnd) && is( c, "CWT-DESIGN" ) ) { fnd = true; proc_cwt_design( edf , param(c) ); }
if ( (!fnd) && is( c, "CWT" ) ) { fnd = true; proc_cwt( edf , param(c) ); }
if ( (!fnd) && is( c, "HILBERT" ) ) { fnd = true; proc_hilbert( edf , param(c) ); }
if ( (!fnd) && is( c, "SYNC" ) ) { fnd = true; proc_sync( edf , param(c) ); }
if ( (!fnd) && is( c, "TSYNC" ) ) { fnd = true; proc_tsync( edf , param(c) ); }
if ( (!fnd) && is( c, "XCORR" ) ) { fnd = true; proc_xcorr( edf, param(c) ); }
if ( (!fnd) && is( c, "TV" ) ) { fnd = true; proc_tv_denoise( edf , param(c) ); }
if ( (!fnd) && is( c, "OTSU" ) ) { fnd = true; proc_otsu( edf, param(c) ); }
if ( (!fnd) && is( c, "COVAR" ) ) { fnd = true; proc_covar( edf, param(c) ); }
if ( (!fnd) && is( c, "PSD" ) ) { fnd = true; proc_psd( edf, param(c) ); }
if ( (!fnd) && is( c, "FFT" ) ) { fnd = true; proc_fft( edf , param(c) ); }
if ( (!fnd) && is( c, "MTM" ) ) { fnd = true; proc_mtm( edf, param(c) ); }
if ( (!fnd) && is( c, "IRASA" ) ) { fnd = true; proc_irasa( edf, param(c) ); }
if ( (!fnd) && is( c, "1FNORM" ) ) { fnd = true; proc_1overf_norm( edf, param(c) ); }
if ( (!fnd) && is( c, "DYNAM" ) ) { fnd = true; proc_qdynam( edf , param(c) ); }
if ( (!fnd) && is( c, "PSC" ) ) { fnd = true; proc_psc( edf , param(c) ); }
if ( (!fnd) && is( c, "MS" ) ) { fnd = true; proc_microstates( edf , param(c) ); }
if ( (!fnd) && is( c, "ASYMM" ) ) { fnd = true; proc_asymm( edf , param(c) ); }
if ( (!fnd) && is( c, "TLOCK" ) ) { fnd = true; proc_tlock( edf , param(c) ); }
if ( (!fnd) && is( c, "TCLST" ) ) { fnd = true; proc_tclst( edf , param(c) ); }
if ( (!fnd) && is( c, "PERI" ) ) { fnd = true; proc_peri( edf , param(c) ); }
if ( (!fnd) && is( c, "PEAKS" ) ) { fnd = true; proc_peaks( edf , param(c) ); }
if ( (!fnd) && is( c, "Z-PEAKS" ) ) { fnd = true; proc_zpeaks( edf , param(c) ); }
if ( (!fnd) && is( c, "SEDF" ) ) { fnd = true; proc_sedf( edf , param(c) ); }
if ( (!fnd) && is( c, "FIP" ) ) { fnd = true; proc_fiplot( edf , param(c) ); }
if ( (!fnd) && is( c, "COH" ) ) { fnd = true; proc_coh( edf , param(c) ); }
if ( (!fnd) && is( c, "CC" ) ) { fnd = true; proc_conncoupl( edf , param(c) ); }
if ( (!fnd) && is( c, "CORREL" ) ) { fnd = true; proc_correl( edf , param(c) ); }
if ( (!fnd) && is( c, "PSI" ) ) { fnd = true; proc_psi( edf , param(c) ); }
if ( (!fnd) && is( c, "ACF" ) ) { fnd = true; proc_acf( edf , param(c) ); }
if ( (!fnd) && is( c, "GP" ) ) { fnd = true; gc_wrapper( edf , param(c) ); }
if ( (!fnd) && is( c, "ED" ) ) { fnd = true; proc_elec_distance( edf , param(c) ); }
if ( (!fnd) && is( c, "SVD" ) ) { fnd = true; proc_svd( edf, param(c) ); }
if ( (!fnd) && is( c, "ICA" ) ) { fnd = true; proc_ica( edf, param(c) ); }
if ( (!fnd) && is( c, "ADJUST" ) ) { fnd = true; proc_adjust( edf , param(c) ); }
if ( (!fnd) && is( c, "CLOCS" ) ) { fnd = true; proc_attach_clocs( edf , param(c) ); }
if ( (!fnd) && is( c, "L1OUT" ) ) { fnd = true; proc_leave_one_out( edf , param(c) ); }
if ( (!fnd) && is( c, "INTERPOLATE" ) ) { fnd = true; proc_chep_based_interpolation( edf, param(c) ); }
if ( (!fnd) && is( c, "SL" ) ) { fnd = true; proc_surface_laplacian( edf , param(c) ); }
if ( (!fnd) && is( c, "EMD" ) ) { fnd = true; proc_emd( edf , param(c) ); }
if ( (!fnd) && is( c, "DFA" ) ) { fnd = true; proc_dfa( edf , param(c) ); }
if ( (!fnd) && is( c, "MI" ) ) { fnd = true; proc_mi( edf, param(c) ); }
if ( (!fnd) && is( c, "HR" ) ) { fnd = true; proc_bpm( edf , param(c) ); }
if ( (!fnd) && is( c, "SUPPRESS-ECG" ) ) { fnd = true; proc_ecgsuppression( edf , param(c) ); }
if ( (!fnd) && is( c, "PAC" ) ) { fnd = true; proc_pac( edf , param(c) ); }
if ( (!fnd) && is( c, "CFC" ) ) { fnd = true; proc_cfc( edf , param(c) ); }
if ( (!fnd) && is( c, "GED" ) ) { fnd = true; proc_ged( edf , param(c) ); }