#!/bin/sh

if [ $# -ne 1 ]
then
echo "correct_nifti_header <input>"
echo "This script takes one input nifti file, unzips it (if filename ends .gz ) and then pads 4 bytes after the 348 byte header."
echo ""
echo "CAUTION! Only use this script on nifti files reported to be 4 (and only 4) bytes shorter than expected"
exit 1
fi
ZIP=0
if [ ${1:(-3)} = ".gz" ]
then
echo "unzipping"
name=${1/.gz}
gunzip $name
ZIP=1
else 
echo "non-zipped file"
name=$1
fi
echo "adding 4 bytes"
add4bytes $name tmpbak
mv tmpbak $name
if [ $ZIP = "1" ]
then
echo "zipping file"
gzip $name
fi
echo "done"