function writeGML(dag,labels,dirsave)

%number of nodes
nvar=size(dag,1);

fid=fopen(fullfile(dirsave ,'network.gml'),'w');

fprintf(fid,'graph\n[directed 1\n');

%node labels
for k=1:nvar
    fprintf(fid,'node\n[ id %d \nlabel "%s" \n]\n', k, labels{k});
end


for k=1:nvar
    for j=1:nvar

        if dag(k,j)  %edge
            fprintf(fid,'edge\n [ source %d\n target %d\n', k, j);
            fprintf(fid,'graphics\n [\n targetArrow "standard" \n] \n]\n');

        end
    end
end

fprintf(fid,']');

fclose(fid);