11#! /usr/bin/env bash
2- env | grep ^DRYRUN= && DRYRUN=echo || DRYRUN=" "
2+ #
3+ # run dcm2niix with 3dNotes wrapper. check for existing file
4+ #
5+ # 20201016WF init
6+ # 20210113WF use rename-recent. nest into "main" (source for testing)
7+ # 2026 support .zip
8+
9+ [ -n " ${DRYRUN:- } " ] && DRYRUN=' echo' || DRYRUN=" "
310# when we are give, change value to "check"
411[ -v NOECHOCHECK ] && NOECHOCHECK=" check" || NOECHOCHECK=" "
512[ ! -v VERBOSE ] && VERBOSE=" "
613verbose (){ [ -n " $VERBOSE " ] && echo " $* " >&2 || : ; }
7- noquiet () { [ -z " ${MKNII_QUIET:- } " ] && echo " $* " || return 0; }
14+ noquiet () { [ -z " ${MKNII_QUIET:- } " ] && echo " $* " ; return 0; }
815
916set_dcm2niix (){
1017 DCM2NIIX=" ${DCM2NII:- dcm2niix} "
1118 command -v " $DCM2NIIX " > /dev/null || DCM2NIIX=dcm2niix_afni
1219 ! command -v " $DCM2NIIX " > /dev/null && warn " cannot find dcm2niix or dcm2niix_afni; try export DCM2NIIX=..." && exit 2
1320 return 0
14- }
15-
21+ }
1622
17- #
18- # run dcm2niix with 3dNotes wrapper. check for existing file
19- #
20- # 20201016WF init
21- # 20210113WF use rename-recent. nest into "main" (source for testing)
2223usage () {
2324cat << HEREDOC
2425USAGE:
@@ -149,9 +150,10 @@ main(){
149150 [ $# -ne 2 ] && echo " given $# not 2 arguments! '$* '" >&2 && usage
150151 nii_out=" $1 " ; shift
151152 dcm_folder=" $* " ; shift
153+ # not a definiative check. multi-echo might not catch here.
152154 [ -r " $nii_out " ] && noquiet " # have '$nii_out '" && exit 0
153- [ ${nii_out: (-7)} != " .nii.gz" ] &&
154- echo " ERROR: output must have .nii.gz extention!" >&2 && exit 1
155+ [ " ${nii_out: (-7)} " != " .nii.gz" ] &&
156+ echo " ERROR: output ' $nii_out ' must have .nii.gz extention!" >&2 && exit 1
155157
156158 if [[ $dcm_folder =~ .zip$ ]]; then
157159 unzip_tmp=$( mktemp -d ${TMPDIR:-/ tmp} /dcmzip_XXXX)
@@ -172,8 +174,9 @@ main(){
172174 outdir=" $( dirname " $nii_out " ) "
173175 [ ! -d " $outdir " ] && $DRYRUN mkdir -p " $outdir "
174176
175- # pretimestamp=$(mktemp /tmp/dcmnii_XXXXXX) # -newercm $pretimestamp
176177 # TODO: add trap to cleanup file?
178+ # pretimestamp=$(mktemp /tmp/dcmnii_XXXXXX) # -newercm $pretimestamp
179+
177180 $DRYRUN $DCM2NIIX -z y -b y -f " $outname " -o " $outdir " " $dcm_folder "
178181 [ -n " $DRYRUN " ] && exit 0
179182 # if above failed, script would bail (set -e)
0 commit comments