1#!/bin/tcsh -fe
2
3# written by Ben Jung (June 30, 2020)
4# additional contact people about NMT issues:
5#    * Adam Messinger (re. template/data itself)
6#    * Daniel Glen (of course)
7#    * Paul Taylor
8
9set stat = 0
10set sdir = $PWD
11
12goto PARSE
13RET_PARSE:
14if ("$nmt_ver" =~ 2*) then
15    set template = NMT_v${nmt_ver}_${sym}
16else
17    set template = NMT_v${nmt_ver}
18endif
19
20if ( -d ${install_dir}/$template) then
21  if (${overwrite} == "0") then
22    echo ""
23    echo "ERROR:"
24    echo "   Directory ${install_dir}/$template exists already"
25    echo "   If you want to reinstall the NMT, add -overwrite"
26    echo "   to your @Install_NMT command"
27    echo ""
28    goto END
29  else if (${overwrite} == "1") then
30    echo "WARNING: Removing currently installed ${install_dir}/$template"
31    \rm -r ${install_dir}/$template
32  endif
33endif
34
35if ($use_curl == -1) then
36   which curl
37   if ($status) then
38      set use_curl = 0;
39   else
40      set use_curl = 1;
41   endif
42endif
43
44cd ${install_dir}
45
46echo "Downloading https://afni.nimh.nih.gov/pub/dist/atlases/macaque/nmt/${template}.tgz"
47if ($use_curl == 0) then
48   wget https://afni.nimh.nih.gov/pub/dist/atlases/macaque/nmt/${template}.tgz
49else
50   curl -O https://afni.nimh.nih.gov/pub/dist/atlases/macaque/nmt/${template}.tgz
51endif
52
53\tar -xvzf $template.tgz
54\rm $template.tgz
55
56cd $template
57
58cat <<EOF
59
60********************************************************
61Please read ${install_dir}/$template/README.txt for more information
62about this template
63********************************************************
64
65EOF
66
67### PT: user has to set up the specific format of the dataset they
68### want to be in the env vars: *_05mm, *_fh, or 'default'.  This
69### won't work anymore
70#if ($set_env == 1) then
71#  set atlas_dir = ${install_dir}
72#  @AfniEnv -set AFNI_SUPP_ATLAS_DIR $atlas_dir
73#  @AfniEnv -set AFNI_WHEREAMI_DEC_PLACES 2
74#  @AfniEnv -set AFNI_TEMPLATE_SPACE_LIST NMT,NMT2,D99_Macaque,D99_Macaque_book
75#  @AfniEnv -set AFNI_WEBBY_WAMI YES
76#endif
77
78cd -
79
80
81goto END
82
83PARSE:
84
85#------------------------ process user options --------------------------
86set use_curl = -1
87set nmt_ver = 2.1
88set sym = sym
89set install_dir = ${sdir}
90set overwrite = 0
91set ac = 1
92set set_env = 0
93while ($ac <= $#argv)
94   if ("$argv[$ac]" == "-help" || "$argv[$ac]" == "-h") then
95       goto HELP
96
97   else if ("$argv[$ac]" == "-curl") then
98        set use_curl = 1
99
100   else if ("$argv[$ac]" == "-wget") then
101        set use_curl = 0
102
103   else if ("$argv[$ac]" == "-install_dir") then
104       set this_opt = "$argv[$ac]"
105       @ ac ++
106       if ( $ac > $#argv ) then
107           echo "** missing parameter for option '${this_opt}'"
108           exit 1
109       endif
110       set install_dir =  $argv[$ac]
111
112   else if ("$argv[$ac]" == "-overwrite") then
113       set overwrite = "1"
114
115   else if ("$argv[$ac]" == "-nmt_ver") then
116       set this_opt = "$argv[$ac]"
117       @ ac ++
118       if ( $ac > $#argv ) then
119           echo "** missing parameter for option '${this_opt}'"
120           exit 1
121       endif
122       set nmt_ver = $argv[$ac]
123       if (($nmt_ver != "1.2")  && \
124           ($nmt_ver != "1.3")  && \
125           ($nmt_ver != "2.0")  && \
126           ($nmt_ver != "2.1")) then
127             echo "nmt_ver $nmt_ver is not a valid choice"
128             exit 1
129       endif
130
131   else if ("$argv[$ac]" == "-sym") then
132       set this_opt = "$argv[$ac]"
133       @ ac ++
134       if ( $ac > $#argv ) then
135           echo "** missing parameter for option '${this_opt}'"
136           exit 1
137       endif
138       set sym = $argv[$ac]
139       if ($sym == "symmetric") then
140         set sym = sym
141       else if ($sym == "asymmetric") then
142         set sym = asym
143       endif
144
145   else if ("$argv[$ac]" == "-set_env") then
146       #set set_env = "1"
147       echo "+* WARNING: '-set_env' is no longer a usable option"
148       echo "   Instead, after the datadownload has completed,"
149       echo "   Run the setup*.tcsh script in your NMT data directory"
150       echo "   of choice to setup the AFNI environment vars."
151
152   else
153       echo "Error: Option or parameter '$argv[$ac]' not understood"
154       goto END
155   endif
156   @ ac ++
157end
158
159goto RET_PARSE
160
161HELP:
162cat << EOF
163
164   Overview ~1~
165
166   Installs the NIMH Macaque Template (NMT) with the accompanying
167   Cortical Hierarchy Atlas of the Rhesus Macaque (CHARM).
168
169   Note there are multiple versions and variants of the template to
170   choose from (see the "-ver .." and "-sym .." options, below), with
171   the default being the ${sym}metric NMT v${nmt_ver}.
172
173   The NMT v2 and the CHARM are described in:
174
175      Jung B, Taylor PA, Seidlitz PA, Sponheim C, Perkins P, Glen DR,
176      Messinger A (2021). A Comprehensive Macaque FMRI Pipeline and
177      Hierarchical Atlas. NeuroImage 235:117997.
178      https://doi.org/10.1016/j.neuroimage.2021.117997.
179      
180   while the previous template versions (the NMT v1.2 and NMT v1.3) are
181   described in:
182
183      Seidlitz J, Sponheim C, Glen DR, Ye FQ, Saleem KS, Leopold DA,
184      Ungerleider L, Messinger A (2018). A Population MRI Brain
185      Template and Analysis Tools for the Macaque. NeuroImage 170:
186      121–31. doi: 10.1016/j.neuroimage.2017.04.063.
187
188   ** Please cite Jung et al. (2021) and/or Seidlitz et al. (2018) if
189   you make use of the respective templates in your work. **
190
191   After the archive is downloaded and unpacked (as the directory
192   "NMT_*", depending on your selected version+variant), see its
193   README.txt for details.
194
195   --------------------------------------------------------------------------
196
197   Options ~1~
198
199   -install_dir DD  :the install location for the NMT
200                     (default = the PWD)
201
202   -nmt_ver VV      :the version of the NMT you wish to install
203                     (default = ${nmt_ver}; valid = 2.1, 2.0, 1.3, 1.2)
204
205   -sym SS          :the NMT v2 has both a symmetric and asymmetric variant.
206                     Specify the desired variant SS as either "sym" or
207                     "asym".  Option is valid for the NMT v2 only--in
208                     other cases it is ignored. (default = "${sym}")
209
210   -overwrite       :allows the script to remove a pre-existing NMT directory
211
212   -wget            :use wget to download archive. Script chooses by default
213                     with preference for curl
214
215   -curl            :use curl to download archive. Script chooses by default
216                     with preference for curl
217
218   -help            :repeats this message
219
220   --------------------------------------------------------------------------
221
222   Questions/contact ~1~
223
224   If you have any NMT or CHARM questions, please contact:
225
226     Adam Messinger : messinga @ nih.gov
227     Ben Jung       : benjamin.jung @ nih.gov
228
229   For demo or processing (@animal_warper, afni_proc.py, etc.) questions,
230   please contact:
231
232     Daniel Glen    : glend @ mail.nih.gov
233     Paul Taylor    : paul.taylor @ nih.gov
234
235   or ask on the AFNI Message Board.
236
237EOF
238
239   goto END
240
241BEND:
242   echo "Failed"
243   set stat = 1
244   goto END
245
246END:
247   exit $stat
248