History of AFNI updates  

|
January 17, 2005 11:14AM
Feng,

Here's a bash script that I use. Some things you will have to fix up - like orientation, endian, paths, $dtype ...

--------------------------------------------------------------------- begin script -------
#!/usr/bin/bash

## function to return the absolute value as $ABSVAL
abs ()
{
isneg=$(( $(( $(( $(echo "if ( $1 > 0 ) 1" | bc) + 0 )) * 2 )) - 1 ))
ABSVAL=$(echo "$1 * $isneg" | bc)
}

program=`basename $0`
usage="USAGE: ${program} afnifile"
dtype="+orig"
RM=/bin/rm

if [ $# -ne 1 ]
then
echo $usage
exit
fi

base=$1
head=${base}${dtype}.HEAD
sbase=`echo ${base} | sed "s/\./_/g"`
spr=${sbase}.spr
sdt=${sbase}.sdt

if [ ! -f ${head} ]
then
echo "ERROR: could not find header file: ${head}"
exit
fi

brik=${base}${dtype}.BRIK
if [ ! -f ${brik} ]
then
brik=${base}${dtype}.BRIK.gz
if [ ! -f ${brik} ]
then
echo "ERROR: could not find ${base} brik file"
exit
else
gzip="Y"
fi
else
gzip="N"
fi

nx=`3dAttribute DATASET_DIMENSIONS ${head} | awk '{print $1}'`
ny=`3dAttribute DATASET_DIMENSIONS ${head} | awk '{print $2}'`
nz=`3dAttribute DATASET_DIMENSIONS ${head} | awk '{print $3}'`
nt=`3dAttribute DATASET_RANK ${head} | awk '{print $2}'`
echo "nx,ny,nz,nt: ${nx} ${ny} ${nz} ${nt}"

datatype=`3dAttribute BRICK_TYPES ${head} | awk '{print $1}'`
echo "Datatype: ${datatype}"
case ${datatype} in
"0" ) dtypename="BYTE";;
"1" ) dtypename="WORD";;
"3" ) dtypename="REAL";;
"5" ) dtypename="COMPLEX";;
* ) echo "ERROR in datatype: ${datatype}"; exit;
esac

xinterval=`3dAttribute DELTA ${head} | awk '{print $1}'`
abs ${xinterval}
xinterval=${ABSVAL}
yinterval=`3dAttribute DELTA ${head} | awk '{print $2}'`
abs ${yinterval}
yinterval=${ABSVAL}
zinterval=`3dAttribute DELTA ${head} | awk '{print $3}'`
abs ${zinterval}
zinterval=${ABSVAL}
echo "intervals: ${xinterval} ${yinterval} ${zinterval}"

xfov=`echo "${xinterval}*${nx}"| bc`
yfov=`echo "${yinterval}*${ny}"| bc`
zfov=`echo "${zinterval}*${nz}"| bc`
echo "FOV: ${xfov} ${yfov} ${zfov}"

xorigin=`3dAttribute ORIGIN ${head} | awk '{print $1}'`
yorigin=`3dAttribute ORIGIN ${head} | awk '{print $2}'`
zorigin=`3dAttribute ORIGIN ${head} | awk '{print $3}'`
echo "origins: ${xorigin} ${yorigin} ${zorigin}"

echo "files: ${spr} ${sdt}"
if [ -f ${spr} -o -f ${sdt} ]
then
echo "spr and/or sdt file already exists"
read -p "okay to overwrite (y/n)? " answer
answer=`echo ${answer} | tr "[:lower:]" "[:upper:]"`
if [ ${answer} != "Y" ]
then
echo "Exiting!"
exit
fi
${RM} ${spr} &> /dev/null
${RM} ${sdt} &> /dev/null
fi

echo "Writing spr file"
echo "numDim: 4" > ${spr}
echo "dim: ${nx} ${ny} ${nz} ${nt}" >> ${spr}
echo "dataType: ${dtypename}" >> ${spr}
echo "interval: ${xinterval} ${yinterval} ${zinterval} 1" >> ${spr}
echo "origin: ${xorigin} ${yorigin} ${zorigin} 0" >> ${spr}
echo "fov: ${xfov} ${yfov} ${zfov}" >> ${spr}
echo "sdtOrient: axis" >> ${spr}
echo "endian: ieee-be" >> ${spr}

if [ ${gzip} == "Y" ]
then
echo "Spawning gunzip"
gunzip -c ${brik} > ${sdt}
else
ln -s ${brik} ${sdt}
fi

exit
----------------------------------------------------------------- end script -----------

Subject Author Posted

from AFNI back to sdt

feng luo January 12, 2005 03:35PM

Re: from AFNI back to sdt

Robert Cox January 12, 2005 04:15PM

Re: from AFNI back to sdt

Vince Hradil January 17, 2005 11:14AM