function save_niigz(nii, filename)
% SAVE_NIIGZ write a gzipped nifti files
%   SAVE_NIIGZ(nii, filename) write nii nifti structure to filename file. 
%   filename should have a .nii extension (a .gz extension will be added on
%   top)
%
%   Requires:
%   save_nii as part of NIFTI library by Jimmy Shen.
% 
%   Example:
%   nii = make_nii(zeros(10, 10, 10));
%   save_niigz(nii, 'niftyfile.nii'); % write to file niftyfile.nii.gz
%
%   Author: Adrian V. Dalca, www.mit.edu/~adalca
%   Last Update: May, 2012.



% save the nii file
save_nii(nii, filename);

% gzip the file (which creates a .gz file) and delete the .nii file
gzip(filename);
delete(filename);
