1 #include "mrilib.h"
2 
main(int argc,char * argv[])3 int main( int argc , char *argv[] )
4 {
5    int nopt , nbad=0 ; char *vlist, *expr , *mess ;
6    int showgood=1;  /* 21 Mar 2016 [rickr] */
7 
8    /*-------------------------------------------------------------------------*/
9    if( argc < 2 || strcasecmp(argv[1],"-help") == 0 ){
10      printf("\n"
11 "The function of program GLTsymtest is to test a set of '-gltsym'\n"
12 "strings -- for use with 3dDeconvolve or 3dREMLfit -- for validity.\n"
13 "\n"
14 "Usage:  GLTsymtest [options] varlist expr [expr ...]\n"
15 "\n"
16 "   options (only 1 so far):\n"
17 "\n"
18 "      -badonly : output only BAD messages, rather than all\n"
19 "\n"
20 "* 'varlist' is a list of allowed variable names in the expression.\n"
21 "  These names can be separated by commans, semicolons, and/or\n"
22 "  spaces (varlist would have to be in quotes if it contains spaces).\n"
23 "\n"
24 "* Each 'expr' is a GLT symbolic expression, which should be in quotes\n"
25 "  since different components are separated by blanks.\n"
26 "\n"
27 "EXAMPLES\n"
28 "-------\n"
29 "  GLTsymtest -badonly 'Vrel Arel' 'Vrel -Arel' 'Verl + +aud'\n"
30 "\n"
31 "  GLTsymtest 'Vrel Arel' 'Vrel -Arel' 'Verl + +aud'\n"
32 "\n"
33 "  The first expression is good, but the second has both variable names\n"
34 "  mis-typed; the output from this program would include these messages:\n"
35 "\n"
36 "    ***** Scanned GLT messages *****\n"
37 "    ++ -gltsym is: 'Vrel -Arel'\n"
38 "    ++ INFO: Allowed variable list is 'Vrel Arel'\n"
39 "    ++ INFO: This gltsym appears to be OKAY :-)\n"
40 "\n"
41 "    ***** Scanned GLT messages *****\n"
42 "    ++ -gltsym is: 'Verl + +aud'\n"
43 "    ++ INFO: Allowed variable list is 'Vrel Arel'\n"
44 "    ++ INFO: -gltsym: isolated '+' is being ignored\n"
45 "    ** ERROR: -gltsym: can't match symbolic name 'Verl'\n"
46 "    ** ERROR: -gltsym: can't match symbolic name 'aud'\n"
47 "    ** SORRY: This gltsym appears to be BAD :-(\n"
48 "\n"
49 "NOTES\n"
50 "-----\n"
51 "* GLTsymtest does not check subscripts on variable names against the legal\n"
52 "  range for the name, since the information about the dimensionality of\n"
53 "  the beta vector associated with each name is not available here.\n"
54 "\n"
55 "* The exit status for this program is the number of expressions that had\n"
56 "  at least one ERROR message.  In the example above, this status would be 1.\n"
57 "\n"
58 "* The text output goes to stdout.\n"
59 "\n"
60 "\n"
61 "* Authored by RWCox on May Day 2015 to aid Rick Reynolds in detecting such\n"
62 "  problems, induced for example when his boss does someting stupid during\n"
63 "  an AFNI bootcamp in South Africa (a purely hypothetical case, I assure you).\n"
64 "\n"
65      ) ;
66      exit(0) ;
67    }
68    /*-------------------------------------------------------------------------*/
69 
70    mainENTRY("GLTsymtest"); machdep();
71 
72    /* 21 Mar 2016 */
73    for( nopt=1; nopt < argc; nopt++ ) {
74       if( ! strcmp(argv[nopt], "-badonly" ) ) showgood = 0;
75       else break;
76    }
77 
78    if( argc-nopt < 2 )
79      ERROR_exit("GLTsymtest: missing labels or GLTs (too few args)") ;
80 
81    vlist = argv[nopt] ;
82    for( nopt++ ; nopt < argc ; nopt++ ){
83      expr = argv[nopt] ;
84      mess = SYM_test_gltsym(vlist,expr) ;
85      if( mess != NULL ){
86        if( strstr(mess,"** ERROR:") != NULL ) {
87           nbad++ ;
88           puts(mess) ;
89        } else if ( showgood )
90           puts(mess) ;
91        free(mess) ;
92      }
93    }
94 
95    exit(nbad) ;
96 }
97