Skip to content
Snippets Groups Projects
fslchfiletype 1.18 KiB
#!/bin/sh

#   data format conversion script (between various nifti and Analyze flavours)
#
#   Mark Jenkinson
#   FMRIB Image Analysis Group
#
#   Copyright (C) 1999-2008 University of Oxford
#
#   SHCOPYRIGHT

if [ $# -lt 2 ] ; then
  echo "Usage: $0 <filetype> <filename> [filename2]" ;
  echo " "
  echo "  Changes the file type of the image file, or copies to new file"
  echo "  Valid values of filetype are ANALYZE, NIFTI, NIFTI_PAIR,"
  echo "                                 ANALYZE_GZ, NIFTI_GZ, NIFTI_PAIR_GZ"
  exit 1 ;
fi


oldfile=`$FSLDIR/bin/remove_ext $2`

if [ $# -ge 3 ] ; then
  newfile=`$FSLDIR/bin/remove_ext $3`
  inplace=0
else
  newfile=`$FSLDIR/bin/tmpnam`
  inplace=1
fi

# do the copy / type conversion
$FSLDIR/bin/fslchfiletype_exe $1 $oldfile $newfile

# for inplace stuff remove and copy old one
# exact mechanism is to be careful not to remove old IF a new one isn't writable in this place (eg over quota)
if [ $inplace = 1 ] ; then
  if [ `$FSLDIR/bin/imtest $newfile` = 1 ] ; then 
      $FSLDIR/bin/immv $newfile ${oldfile}TMP
      if [ `$FSLDIR/bin/imtest ${oldfile}TMP` = 1 ] ; then 
	  $FSLDIR/bin/imrm $oldfile 
	  $FSLDIR/bin/immv ${oldfile}TMP $oldfile
      fi
  fi
fi