1#!/bin/tcsh
2
3@global_parse `basename $0` "$*" ; if ($status) exit 0
4
5# !!! comment about movie/mpeg stuff! gifsicle, etc.
6
7# !!!? control loop speed?
8
9# written by PA Taylor (NIMH, NIH)
10# filter sets of acquired DWIs with accompanying bvals/vecs
11
12# --------------------- revision history -------------------------
13#
14# Jan, 2017
15#   + rename
16#
17# Jan 27, 2017
18#   + new opts
19#   + switch to 1dDW_Grad_o_Mat++
20#
21#set version = "2.5"
22#set rev_dat = "Feb 20, 2017"
23
24#   + add snapshotting with @djunct_*_imager
25#
26#set version = "2.6"; set rev_dat = "Feb 23, 2017"
27#   + add movie-making with @djunct_*_imager
28#
29#set version = "2.7"; set rev_dat = "Apr 17, 2017"
30#   + I/O standardization
31#   + cut back to just a single directory at once.
32#     -> Simplifies life (for everyone, really, it's not just
33#        laziness by the author (well, only *partially* the latter))
34#
35#set version = "2.8"; set rev_dat = "Apr 19, 2017"
36#   + more I/O work
37#   + more general outputting, when scaling/not scaling
38#
39#set version = "2.8"; set rev_dat = "Apr 19, 2017"
40#   + changed input notation
41#   + fixed help example
42#
43#set version = "2.9"; set rev_dat = "June 2, 2017"
44#   + changed output mat/vec/bval extensions from 'txt' -> 'dat';
45#     should me more uniform with other fat* funcs
46#
47#set version = "3.0"; set rev_dat = "July 27, 2017"
48#   + fixed some I/O issues with rowvecs and separate bvals
49#
50#set version = "3.1"; set rev_dat = "Sep 04, 2017"
51#   + work with new @chauffeur*, -prefix only
52#   + update help file format for more autoprompting of opts
53#
54#set version = "3.2"; set rev_dat = "Jan 09, 2018"
55#   + new -select_file option
56#   + whine if *no* selection string entered
57#
58#set version = "3.3"; set rev_dat = "Feb 13, 2018"
59#   + allow for *multiple* input files or strings after "-select ..."
60#     or "-select_file"
61#
62#set version = "3.3b"; set rev_dat = "Feb 15, 2018"
63#   + fixed output path for $ogoods
64#
65#set version = "3.4"; set rev_dat = "Feb 20, 2018"
66#   + update QC snapshotting and output dir; file names/locs
67#
68#set version = "3.5"; set rev_dat = "Mar 5, 2018"
69#   + update QC snapshotting and output dir; file names/locs
70#
71#set version = "3.6"; set rev_dat = "Mar 14, 2018"
72#   + bug fix: program would crash if bval was used, because the
73#     selector wasn't being copied in the correct location; thanks for
74#     finding, G. Cabras!
75#
76#set version = "3.7"; set rev_dat = "May 22, 2018"
77#   + bug fix: was doing union, not intersection, of lists of string
78#     selectors.  NOW intersecting.
79#
80set version   = "3.8";   set rev_dat   = "Feb 12, 2019"
81#     + [PT] change "checks" to use '3dinfo -prefix ...' as a better
82#            methodology
83#
84# ----------------------------------------------------------------
85
86set this_prog = "fat_proc_filter_dwis"
87set tpname    = "${this_prog:gas/fat_proc_//}"
88set here      = $PWD
89
90# ----------------- find AFNI and set viewer ---------------------
91
92# find AFNI binaries directory and viewer location
93set adir      = ""
94which afni >& /dev/null
95if ( $status ) then
96    echo "** Cannot find 'afni' (?!)."
97    goto BAD_EXIT
98else
99    set aa   = `which afni`
100    set adir = $aa:h
101endif
102
103# default location of viewer: user could modify!
104set my_viewer    = "$adir/@chauffeur_afni"
105set my_viewer_4d = "$adir/@djunct_4d_imager"
106
107# ----------------------- set defaults --------------------------
108
109set idwi     = ""                 # necessary input: DWI dset
110set invecmat = ( "" "" "" "" )    # switches+names for bvecs and bvals
111set outvecmat = ( "" "" "" "" )    # switches+names for bvecs and bvals
112set do_unit_mag = ""
113set opref    = ""
114set odir     = ""
115set KEEP     = ""
116set KEEP3    = ""
117set ll2       = "{"               # for column selection (def guess)
118set rr2       = "}"               # for column selection (def guess)
119set ll4       = ""                # empty
120set rr4       = ""                # empty
121
122set DO_VIEWER = "1"
123set movie     = ""
124set output_cmd = 1               # def: output copy of this command
125set cmd_file   = ""              # def: same name as viewer
126set qc_prefix  = ""              # def: autoname; user can enter
127set postfix    = "_"             # stick into name
128
129set keepsel    = ()              # one or more strings of keepers
130
131
132# ------------------- process options, a la rr ----------------------
133
134if ( $#argv == 0 ) goto SHOW_HELP
135
136set ac = 1
137while ( $ac <= $#argv )
138    # terminal options
139    if ( ("$argv[$ac]" == "-h" ) || ("$argv[$ac]" == "-help" )) then
140        goto SHOW_HELP
141    endif
142    if ( "$argv[$ac]" == "-ver" ) then
143        goto SHOW_VERSION
144    endif
145
146    # -------------- input opts --------------------
147    # here, specify NIFTI *files*, not directories
148    if ( "$argv[$ac]" == "-in_dwi" ) then
149        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
150        @ ac += 1
151        set idwi = "$argv[$ac]"
152
153#    else if ( "$argv[$ac]" == "-select" ) then
154#        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
155#        @ ac += 1
156#        set KEEP = "$argv[$ac]"
157#
158#    # [PT: Jan 09, 2018] well, just take in a file directly
159#    else if ( "$argv[$ac]" == "-select_file" ) then
160#        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
161#        @ ac += 1
162#        set KEEPfile = "$argv[$ac]"
163
164    # [PT: Feb 13, 2018] new input: can have multiple good lists to
165    # merge
166    else if ( "$argv[$ac]" == "-select" ) then
167        set i0 = $ac
168        # check that this ain't the end of argv[] entries
169        if ( $i0 == $#argv ) then
170            echo "** ERROR: need at least one dset after $argv[$ac]!"
171            goto BAD_EXIT
172        else
173            # check that next argv[] member isn't a new option: shd be
174            # a dset
175            @ i0 += 1
176            set c0 = ""
177            while ( ( $i0 <= $#argv ) && ( "$c0" != "-" )  )
178                set keepsel = ( $keepsel "$argv[$i0]" )
179                @ ac += 1
180
181                @ i0 += 1
182                if ( $i0 <= $#argv ) then
183                    set c0 = `echo $argv[$i0] | awk '{print substr($0,1,1)}'`
184                endif
185            end
186
187            if ( $#keepsel == 0 ) then
188                echo "** ERROR: need at least one dset after $argv[$ac]!"
189                goto BAD_EXIT
190            else
191                echo "++ User has listed $#keepsel followers_NN dsets"
192            endif
193        endif
194
195    # [PT: Feb 13, 2018] new input: can have multiple good lists to
196    # merge; this is the file input version, just cat the file names
197    else if ( "$argv[$ac]" == "-select_file" ) then
198        set i0 = $ac
199        # check that this ain't the end of argv[] entries
200        if ( $i0 == $#argv ) then
201            echo "** ERROR: need at least one dset after $argv[$ac]!"
202            goto BAD_EXIT
203        else
204            # check that next argv[] member isn't a new option: shd be
205            # a dset
206            @ i0 += 1
207            set c0 = ""
208            while ( ( $i0 <= $#argv ) && ( "$c0" != "-" )  )
209                set keepsel = ( $keepsel `cat "$argv[$i0]"` )
210                @ ac += 1
211
212                @ i0 += 1
213                if ( $i0 <= $#argv ) then
214                    set c0 = `echo $argv[$i0] | awk '{print substr($0,1,1)}'`
215                endif
216            end
217
218            if ( $#keepsel == 0 ) then
219                echo "** ERROR: need at least one dset after $argv[$ac]!"
220                goto BAD_EXIT
221            else
222                echo "++ User has listed $#keepsel followers_NN dsets"
223            endif
224        endif
225
226    # ------------- input vecmat and bval --------------
227    else if ( "$argv[$ac]" == "-in_col_matA" ) then
228        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
229        set invecmat[1]  = $argv[$ac]
230        @ ac += 1
231        set invecmat[2]  = "$argv[$ac]"
232        # output postfix; [1] and [3] sorted out, below
233        set outvecmat[2] = "_matA.dat"
234
235    else if ( "$argv[$ac]" == "-in_col_matT" ) then
236        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
237        set invecmat[1]  = $argv[$ac]
238        @ ac += 1
239        set invecmat[2]  = "$argv[$ac]"
240        # output postfix; [1] and [3] sorted out, below
241        set outvecmat[2] = "_matT.dat"
242
243    else if ( "$argv[$ac]" == "-in_col_vec" ) then
244        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
245        set invecmat[1]  = $argv[$ac]
246        @ ac += 1
247        set invecmat[2]  = "$argv[$ac]"
248        # output postfix; [1] and [3] sorted out, below
249        set outvecmat[2] = "_cvec.dat"
250
251    else if ( "$argv[$ac]" == "-in_row_vec" ) then
252        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
253        set invecmat[1]  = $argv[$ac]
254        @ ac += 1
255        set invecmat[2]  = "$argv[$ac]"
256        # output postfix; [1] and [3] sorted out, below
257        set outvecmat[2] = "_rvec.dat"
258        set ll2       = "["
259        set rr2       = "]"
260
261    # not necessary; default is just empty
262    else if ( "$argv[$ac]" == "-in_bvals" ) then
263        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
264        set invecmat[3]  = $argv[$ac]
265        @ ac += 1
266        set invecmat[4]  = "$argv[$ac]"
267        # output postfix; [1] and [3] sorted out, below
268        set outvecmat[4] = "_bval.dat"
269        # ugh, have to see if this is row or col
270        set aa = `1d_tool.py -show_rows_cols -infile $invecmat[4]`
271        if ( ${aa[3]:gas/,//} < ${aa[6]:gas/,//} ) then
272            # -> is rows
273            set ll4 = "["
274            set rr4 = "]"
275            set outvecmat[3] = "-out_row_bval_sep"
276        else
277            # -> is cols
278            set ll4 = "{"
279            set rr4 = "}"
280            set outvecmat[3] = "-out_col_bval_sep"
281        endif
282
283    else if ( "$argv[$ac]" == "-unit_mag_out" ) then
284        set do_unit_mag = "-unit_mag_out"
285
286    # -------------- output opts --------------------
287    else if ( "$argv[$ac]" == "-prefix" ) then
288        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
289        @ ac += 1
290        set opref = "$argv[$ac]"
291
292    else if ( "$argv[$ac]" == "-do_movie" ) then
293        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
294        @ ac += 1
295        set movie = "$argv[$ac]"
296        if ( ( $movie == "MPEG" ) || ( $movie == "AGIF" ) ) then
297            echo "++ OK, will make a movie of type $movie."
298        else
299            echo "** ERROR: '$movie' is NOT an allowed movie format!"
300            echo "      -> must be either 'MPEG' or 'AGIF'"
301            goto BAD_EXIT
302        endif
303        # replace with both here for calling @dj*
304        set movie = "-do_movie $movie"
305
306    # -------------- qc stuff ----------------
307
308    else if ( "$argv[$ac]" == "-qc_prefix" ) then
309        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
310        @ ac += 1
311        set qc_prefix = "$argv[$ac]"
312
313    else if ( "$argv[$ac]" == "-no_qc_view" ) then
314        set DO_VIEWER = "0"
315
316    else if ( "$argv[$ac]" == "-no_cmd_out" ) then
317        set output_cmd = 0
318
319    else
320        echo "** unexpected option #$ac = '$argv[$ac]'"
321        goto BAD_EXIT
322    endif
323
324    @ ac += 1
325end
326
327# =======================================================================
328# ============================ ** SETUP ** ==============================
329# =======================================================================
330
331# ============================ input files ==============================
332
333echo "++ Start script version: $version"
334
335# NEED these two inputs
336if ( "$idwi" == "" ) then
337    echo "** ERROR: no DWI file input?"
338    goto BAD_EXIT
339else if ( "$invecmat[2]" == "" ) then
340    echo "** ERROR: no gradient/matrix file input?"
341    goto BAD_EXIT
342endif
343
344# make sure we can read DWI OK
345set check = `3dinfo -prefix "$idwi"`
346if ( "$check" == "NO-DSET" ) then
347    echo "** ERROR: can't find inset file:  $idwi"
348    goto BAD_EXIT
349else
350    echo "++ Found inset DWI file:   $idwi"
351endif
352
353# use this to combine string selector of "goods"
354set Ndwi = `3dinfo -nvi "$idwi"`
355
356# check for vec/mat file ???????????????/
357if ( 0 ) then
358if ( -f "$invecmat[2]" ) then
359    echo "++ Found input vec/mat file:  $invecmat[2]"
360else
361    echo "** ERROR: can't find entered vec/mat file $invecmat[2]"
362    goto BAD_EXIT
363endif
364endif
365
366# -------------------------------
367
368if ( ( "$keepsel" == "" ) ) then
369    echo "** ERROR: need SOME selection string!"
370    echo "          Use either '-select ...' or '-select_file ...'"
371    goto BAD_EXIT
372endif
373
374# ========================= output/working dir ==========================
375
376if ( "$opref" == "" ) then
377    echo "** ERROR: need '-prefix ...' option provided!"
378    echo "   See the helpfile for more information."
379    goto BAD_EXIT
380else
381    set odir = `dirname $opref`
382    set opref = `basename $opref`
383    echo ""
384    echo "++ Based on prefix, the output directory will be:"
385    echo "     $odir"
386    echo "++ Based on prefix, the output prefix will be:"
387    echo "     $opref"
388    echo ""
389endif
390
391# check output directory, use input one if nothing given
392
393# default output dir, if nothing input.
394if ( ! -e "$odir" ) then
395    echo "+* Output directory didn't exist.  Trying to make '$odir' now."
396    mkdir "$odir"
397endif
398
399if ( 0 ) then
400# and put working directory as subdirectory.
401set wdir = $odir/$wdir
402
403# make the working directory
404if ( ! -e $wdir ) then
405    echo "++ Making working directory: $wdir"
406    mkdir $wdir
407else
408    echo "+* WARNING: Somehow found a premade working directory (?):"
409    echo "      $wdir"
410
411    # don't clean preexisting directories-- could be user mistake.
412    echo "   NB: will *not* clean it afterwards."
413    set DO_CLEAN = "0"
414endif
415endif
416
417# file names for lots of outputs
418set ocmd   = "${opref}_cmd.txt"         # name for output command
419set omata  = "${opref}_bmatA.dat"       # name for full afni bmatrix
420set omatt  = "${opref}_bmatT.dat"       # name for full afni bmatrix
421set obvec  = "${opref}_bvec.dat"        # name for full afni grads
422set obval  = "${opref}_bval.dat"        # name for full afni bvals
423set odwi   = "${opref}_dwi.nii.gz"      # name for dwis
424set ogoods = "${opref}_goodfinal.txt"   # name for output good list
425
426# file *types* for output (grad/matrix stuff); [2,4] are filled above
427set outvecmat[1] = ${invecmat[1]:gas/in/out/}
428# [PT: Jul, 2017]: now comes from inp --->
429#set outvecmat[3] = ${invecmat[3]:gas/in/out/}
430set outvecmat[2] = "$odir/${opref}$outvecmat[2]"
431
432if ( "$outvecmat[4]" != "" ) then
433    set outvecmat[4] = "$odir/${opref}$outvecmat[4]"
434endif
435
436# in case someone wants just unit-mag vec|mat, we don't want to lose
437# the bvalue info!
438if ( "$do_unit_mag" != "" ) then
439    if ( "$outvecmat[3]" == "" ) then
440        set outvecmat[3] = "-out_col_bval_sep"
441        set outvecmat[4] = "$odir/${opref}_bval.dat"
442    endif
443endif
444
445# =======================================================================
446# =========================== ** PROCESS ** =============================
447# =======================================================================
448
449echo "\n-----> STARTING $this_prog ---->"
450
451# ---------------------------- CMD ---------------------------------
452
453echo "\n\nThis command:"
454echo "$this_prog $argv\n\n"
455
456if ( "$cmd_file" == "" ) then
457    set cmd_file = "$odir/$ocmd"
458endif
459
460# copy original command:
461# dump copy of command into workdir/..
462if ( $output_cmd == 1 ) then
463    echo "++ Echoing the command to: $cmd_file"
464
465    set rec_afni_ver = `afni -ver`
466    echo "### AFNI version:"  > $cmd_file
467    echo "# $rec_afni_ver\n"            >> $cmd_file
468
469    echo "### Executed from the directory location:"  >> $cmd_file
470    echo "# $here\n"            >> $cmd_file
471    echo "### The command was:" >> $cmd_file
472    echo "# $this_prog $argv"   >> $cmd_file
473    echo "\n"                   >> $cmd_file
474endif
475
476# =================== Combine all good lists ============================
477
478echo "++ User input $#keepsel selector strings to merge:"
479foreach ii ( `seq 1 1 $#keepsel` )
480    echo "       $keepsel[$ii]"
481end
482
483# Combine all good lists
484adjunct_combine_str.py $odir/$ogoods $Ndwi $keepsel
485
486set KEEP = `cat "$odir/$ogoods"`
487echo "++ String selectors merged:\n\t $KEEP"
488echo "   and then saved into file:\n\t $odir/$ogoods"
489
490# and use it again
491if ( "$invecmat[4]" != "" ) then
492    set KEEP3 = "$KEEP"
493endif
494
495# ======================== convert dicoms ===============================
496
497if ( 1 ) then
498
499    # make grads ...
500    1dDW_Grad_o_Mat++                                     \
501        -overwrite                                        \
502        -echo_edu                                         \
503        "$invecmat[1]" "$invecmat[2]""$ll2""$KEEP""$rr2"  \
504        $do_unit_mag                                      \
505        "$outvecmat[1]" "$outvecmat[2]"                   \
506        "$outvecmat[3]" "$outvecmat[4]"                   \
507        "$invecmat[3]" "$invecmat[4]""$ll4""$KEEP3""$rr4"
508    # NB: the above works somewhat cheatingly by having the empty
509    # strings at the end of the function call.
510
511    3dcalc   -echo_edu                                           \
512        -a     $idwi"[${KEEP}]"                                  \
513        -expr "(a)"                                              \
514        -prefix $odir/${opref}.nii.gz                            \
515        -overwrite
516
517    # Feb,2017: take images!
518    if ( "$DO_VIEWER" == "1" ) then
519        echo "++ Make AP images."
520        set img_pref = "${opref}"
521
522        if ( ! -e "$odir/QC" ) then
523            mkdir "$odir/QC"
524        endif
525
526        $my_viewer_4d  \
527            -inset  $odir/${opref}.nii.gz      \
528            -prefix "$odir/QC/$img_pref"
529
530        if ( "$movie" != "" ) then
531            $my_viewer_4d \
532                -inset  $odir/${opref}.nii.gz  \
533                -prefix "$odir/QC/$img_pref"      \
534                $movie
535        endif
536    endif
537endif
538
539goto GOOD_EXIT
540
541# ========================================================================
542# ========================================================================
543
544SHOW_HELP:
545cat << EOF
546# -----------------------------------------------------------------------
547
548    The purpose of this function is to help filter out user-found and
549    user-defined bad volumes from DWI data sets.  
550
551    If a bad volume is found, then it should be removed from the 4D
552    dset, and it also has to be removed from the gradient list and
553    the bvalue list.  In addition, if the user is processing DWI data
554    that was acquired with two sets of phase encodings for EPI
555    distortion correction, then one wants to remove the same volume
556    *from both sets*.  This script is designed to help facilitate this
557    process in a scriptable manner (the script still has to be run twice,
558    but hopefully with easy enough syntax to avoid confusion/bugs).
559
560    The user has to input 
561
562        1) a 4D volumetric data sets of N DWIs (NAME.nii.gz),
563
564        2) and accompanying bvalue/bmatrix/bvector values that they
565           want to be parsed; this could be a unit-magn bvec file + a
566           file of bvalues, or it could be a single file of scaled
567           vector|matrix values.
568
569    The output will be in similar format to what was input (i.e., the
570    type of bvector|bmatrix files matching what was input), but with a
571    different prefix name and/or directory, and everything filtered in
572    a consistent manner *hopefully*.
573
574    Check out the function "fat_proc_select_vols" for a nice, GUI way
575    to select the bad DWIs you want to get rid of and to build a
576    selector nicely (courtesy of J. Rajendra).
577
578    REQUIRES: AFNI.
579
580    Ver. $version (PA Taylor, ${rev_dat})
581
582# -----------------------------------------------------------------------
583
584  RUNNING: 
585
586    $this_prog  \
587        -in_dwi    DDD                     \
588        -select   'SSS'                    \
589        {-select_file SF}                  \
590        -prefix   PPP                      \
591        {-in_col_matA|-in_col_matT|        \
592         -in_col_vec|-in_row_vec} FFF      \
593        {-in_bvals BBB}                    \
594        {-unit_mag_out}                    \
595        {-qc_prefix  QCPREF}               \
596        {-no_cmd_out}                      \
597        {-no_qc_view}                      \
598        {-do_movie AGIF|MPEG}
599
600  where:
601  -in_dwi  DDD      :name of a 4D file of DWIs (required).
602
603  -in_col_matA |
604  -in_col_matT |
605  -in_col_vec  |
606  -in_row_vec  FFF  :one of these options must be used to input 
607                     a bvec/bmat file from the gradients. Required.
608                     Same type of output file is returned.
609
610  -in_bvals BBB     :if the bvec/bmat is a file of unit-magnitude values,
611                     then the bvalues can be input, as well (optional).
612
613  -select 'SSS'     :a string of indices and index ranges for
614                     selecting which volumes/grads/bvals to *keep*.
615                     This is done in a generic form of the typical
616                     AFNI format, and index counting starts at 0 and
617                     the 'last' brick could be specified as '\$'.  An
618                     example for skipping the index-4 and index-6
619                     volumes in a data set: 
620                        '0..3,5,7..\$' 
621                     This string gets applied to the volume, bval|bvec|bmat
622                     files for an input set. Either this or '-select_file ..',
623                     below, is required.
624                     NB: there are neither square nor curly brackets used
625                     here!
626                     NB2: Always use single or double quotes around the
627                     selector expression. 
628                     NB3: User can enter a list of strings here, such as:
629                       '0..3,5,7..\$' '1..3,6..\$' 
630                     which then get joined by intersection.
631       or
632  -select_file SF   :where SF is a file name whose only contents are a nice 
633                     string of indices and index ranges for selecting which
634                     volumes/grads/bvals to *keep*.  Like, literally just
635                        0..3,5,7..\$
636                     sitting alone in a file-- no apostrophes needed/wanted.
637                     User can enter more than one file here, to be joined
638                     by intersection.
639
640  -prefix    PPP    :output prefix for all the volumes and text files.
641                     Required.
642
643  -unit_mag_out     :if one wants to prevent an input bvalue file being
644                     applied to unit-magnitude gradients|vecs|matrices,
645                     or if one just wants to ensure that the output grad
646                     information is unit magnitude, use this option.  If
647                     this is used with just a vec/matrix file input, then
648                     a b-value file will also be output (so b-value info
649                     wouldn't be lost at this moment).  Optional.
650
651  -qc_prefix QCPREF :can set the prefix of the QC image files separately
652                     (default is '$opref').
653   -no_qc_view      :can turn off generating QC image files (why?)
654   -no_cmd_out      :don't save the command line call of this program
655                     and the location where it was run (otherwise, it is
656                     saved by default in the ODIR/).
657
658    -do_movie AGIF | MPEG
659                    :one can use this option with either of the given
660                     arguments to output a movie of the newly created
661                     dset.  Only those arguments can be used at
662                     present.
663
664# -----------------------------------------------------------------------
665
666  EXAMPLES:
667
668    1) ... with selector via the command line (again, note the single
669       apostrophes around the selector!):
670
671        $this_prog  \
672            -in_dwi       UNFILT_AP/AP.nii.gz       \
673            -in_col_matT  UNFILT_AP/AP_bmatT.dat    \
674            -select       '0..5,8,20..\$'           \
675            -prefix       FILT_AP/AP 
676
677    
678    2) ... with selector via file contents (where there would *not* be
679       apostrophes in the string sitting in the file):
680
681        $this_prog  \
682            -in_dwi       UNFILT_AP/AP.nii.gz           \
683            -in_col_matT  UNFILT_AP/AP_bmatT.dat        \
684            -select_file  UNFILT_AP/dwi_sel_goods.txt   \
685            -prefix       FILT_AP/AP 
686
687# -----------------------------------------------------------------------
688
689EOF
690    goto GOOD_EXIT
691
692SHOW_VERSION:
693   echo "version  $version (${rev_dat})"
694   goto GOOD_EXIT
695
696FAIL_MISSING_ARG:
697    echo "** ERROR! Missing an argument after option flag: '$argv[$ac]'"
698    goto BAD_EXIT
699
700BAD_EXIT:
701   exit 1
702
703GOOD_EXIT:
704   exit 0
705