function [] = create_primate_func_gii(data,outbase,hemi)
% Writes .func.gii file for macaque data, given hemisphere.
%
% Saad's original create_func_gii.m, his documentation below:
% ==============================================
% [] = create_dconn(data,outbase,hemi)
% hemi='L' or 'R'
%
% S Jbabdi 01/13
% % ==============================================

[folder, ~, ~] = fileparts(which('create_primate_func_gii'));
gii = gifti([folder filesep 'macaque_' hemi '.func.gii']);

for i=(length(gii.private.data)+1):size(data,2)
    gii.private.data{i}=gii.private.data{1};
end

for i=1:size(data,2)
    gii.private.data{i}.data=single(data(:,i));
    gii.private.data{i}.attributes.Intent='NIFTI_INTENT_NONE';
end

N=size(gii.cdata,1);
str=gii.private.data{1}.metadata(1).value;
str=strrep(str,num2str(N),num2str(size(gii.cdata,1)));
gii.private.data{1}.metadata(1).value=str;
gii.private.data{1}.attributes.Dim=N;

outbase=[outbase '.func.gii'];
save(gii,outbase);

end
