#! /bin/tcsh -f

#
# isnifti - checks whether the passed file is a nifti file
#  exit status 0 - not an nifit
#  exit status 1 - is a nifit
#  exit status 2 - is a gzipped nifit
#  exit status 255 - some error
#
#  First looks for a .nii extension (exits 1 if so)
#  Then  looks for a .nii.gz extension (exits 2 if so)
#
# Original Author: REPLACE_WITH_FULL_NAME_OF_CREATING_AUTHOR
# CVS Revision Info:
#    $Author: nicks $
#    $Date: 2011/03/02 20:16:39 $
#    $Revision: 1.5 $
#
# Copyright © 2011 The General Hospital Corporation (Boston, MA) "MGH"
#
# Terms and conditions for use, reproduction, distribution and contribution
# are found in the 'FreeSurfer Software License Agreement' contained
# in the file 'LICENSE' found in the FreeSurfer distribution, and here:
#
# https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense
#
# Reporting: freesurfer@nmr.mgh.harvard.edu
#
#

set VERSION = '$Id: isnifti,v 1.5 2011/03/02 20:16:39 nicks Exp $'

if($#argv != 1) then
  echo "isnifti filename"
  exit 255;
endif
set fname = $argv[1];

# Determine from extension
set baseimg = `basename $fname`;
set base = `basename $fname .nii`;
set newfname = $base.nii
if($baseimg == $newfname) exit 1;

# Determine from extension
set baseimg = `basename $fname`;
set base = `basename $fname .nii.gz`;
set newfname = $base.nii.gz
if($baseimg == $newfname) exit 2;

exit 0

