function icatb_write_vol(V, data)
% Writes the images using the appropriate SPM functions

V = V(1);

[spmPath] = nic_getSPMPath(V(1));

oldDir = pwd;

% add appropriate spm path on top of path
addpath(spmPath);

try
    
    % Change directory to get appropriate functions
    cd(spmPath);

    %%%%%%%%%%% Enforce data type to be float32 %%%%%%%%%%%
    if length(V(1).dim) == 4
        V(1).dim(4) = 16;
    end

    if isfield(V(1), 'dt')
        V(1).dt(1) = 16;
    end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    % Add appropriate path to the file
    fName = V(1).fname;
    
    if isempty(fileparts(fName))
        fName = fullfile(oldDir, fName);
    end

    V(1).fname = fName;
    
    nic_spm_write_vol(V, data);

    cd(oldDir);

catch

    cd(oldDir);
    icatb_displayErrorMsg;

end

