1#!/bin/tcsh
2
3@global_parse `basename $0` "$*" ; if ($status) exit 0
4
5#set version   = "0.0";  set rev_dat   = "Oct 18, 2018"
6#  + this used to be part of @chauffeur_afni, but now is separated
7#    into its own separate @djunct_* program
8#
9#set version   = "0.1";  set rev_dat   = "Oct 18, 2018"
10#  + optionify
11#
12set version   = "0.2";  set rev_dat   = "Jan 25, 2019"
13#  + [PT] bug fix for when subbrick selection is used on an inset;
14#         shoutout to, C. Cunningham for spotting the trouble.
15#
16# ================================================================
17
18set Nwin = ""    # number of slices to divide each viewplane into
19set ulay = ""    # dset in question
20
21# ------------------- process options, a la rr ----------------------
22
23if ( $#argv == 0 ) goto SHOW_HELP
24
25set ac = 1
26while ( $ac <= $#argv )
27    # terminal options
28    if ( ("$argv[$ac]" == "-h" ) || ("$argv[$ac]" == "-help" )) then
29        goto SHOW_HELP
30    endif
31    if ( "$argv[$ac]" == "-ver" ) then
32        goto SHOW_VERSION
33    endif
34
35    #  ---------- inputs: required ---------------
36
37    if ( "$argv[$ac]" == "-inset" ) then
38        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
39        @ ac += 1
40        set ulay = "$argv[$ac]"
41
42    else if ( "$argv[$ac]" == "-nwin" ) then
43        if ( $ac >= $#argv ) goto FAIL_MISSING_ARG
44        @ ac += 1
45        @ Nwin = "$argv[$ac]"
46
47    else
48        echo "\n\n** ERROR: unexpected option #$ac = '$argv[$ac]'\n\n"
49        goto BAD_EXIT
50
51    endif
52    @ ac += 1
53end
54
55# --------------------------- inputs -------------------------------
56
57if ( "$ulay" == "" ) then
58    echo "** ERROR: missing input dset! Use '-inset ..'"
59    goto BAD_EXIT
60endif
61
62if ( $Nwin == "" ) then
63    echo "** ERROR: missing number of windows (= num of slices)!"
64    echo "          Use '-nwin ..'"
65    goto BAD_EXIT
66endif
67
68# ----------------------------- ugh ---------------------------------
69
70# needed to deal with orientation permutability : AIL, LAI, PSR, etc.
71
72set listori = ( 'R' 'L' 'A' 'P' 'I' 'S' )
73set listind = (  1   1   2   2   3   3  )
74
75# just the initializing value
76set gapord = ( 0 0 0 )
77
78# ---------------------------- calcs --------------------------------
79
80# always determine dim from ulay, because that's how montaging works!
81set Dim  = `3dinfo -n4 "$ulay"`
82
83# silly stuff to deal with orientation
84set ori  = `3dinfo -orient "$ulay"`
85set ori0 = `echo $ori | awk '{print substr($0,1,1)}'`
86set ori1 = `echo $ori | awk '{print substr($0,2,1)}'`
87set ori2 = `echo $ori | awk '{print substr($0,3,1)}'`
88set all_ori = ( $ori0 $ori1 $ori2 )
89set order  = ()
90foreach oo ( $all_ori )
91    foreach i ( `seq 1 1 ${#listori}` )
92        if ( $oo == "$listori[${i}]" ) then
93            set order  = ( $order ${listind[$i]} )
94            break
95        endif
96    end
97end
98# echo "++ Cryptic info: $ori -> $all_ori -> $order"
99# echo "++ Dimensions (xyzt): $Dim"
100
101foreach i ( `seq 1 1 3` )
102    if ( $gapord[$order[$i]] <= 0 ) then
103        @ gapord[$order[$i]] = $Dim[$i] / ( $Nwin )
104        if ( $gapord[$order[$i]] <= 0 ) then
105            @ gapord[$order[$i]] = 1
106        endif
107    endif
108end
109
110# finish:
111echo $gapord
112
113
114goto GOOD_EXIT
115
116# ========================================================================
117# ========================================================================
118
119SHOW_HELP:
120cat << EOF
121-------------------------------------------------------------------------
122
123OVERVIEW ~1~
124
125Just a tiny adjunct program for @chauffeur_afni.
126
127Small program to calculate how to evenly space a certain number of
128slices within each view plane of a dset.  Returns three numbers: the
129'delta slices' in the three view planes (in the order of the input
130dset's orientation).
131
132++ constructed by PA Taylor (NIMH, NIH, USA).
133
134# =========================================================================
135
136COMMAND OPTIONS ~1~
137
138-help, -h          :see helpfile (here!)
139-ver               :see version number
140
141-inset   UUU       :name of input dset (req).
142
143-nwin    NN        :number of windows (i.e., slices) that you want
144                    across each view plane (req).
145
146EOF
147
148# ----------------------------------------------------------------------
149
150    goto GOOD_EXIT
151
152SHOW_VERSION:
153   echo "version  $version (${rev_dat})"
154   goto GOOD_EXIT
155
156FAIL_MISSING_ARG:
157    echo "** ERROR! Missing an argument after option flag: '$argv[$ac]'"
158    goto BAD_EXIT
159
160BAD_EXIT:
161    exit 1
162
163GOOD_EXIT:
164    exit 0
165