function wrtmerg(fnam,dat,hdr)
% function wrtmerg(fnam,dat,hdr)
%
% Program to output a file that has the first
% row containing the column headers (letters)
% and then the data array in tab delimited
% format.
%
% fnam = file output name
% dat = data array (n,m)
% hdr = array containing the column headers (n,k)
%
% Written by Andrew H Barnard, OSU, 1996.
%
fid=fopen(fnam,'w');
info=size(dat);
nvar=info(1);
ndep=info(2);


for i=1:nvar

if i == nvar
fprintf(fid,'%s\n',hdr(i,:));
else
fprintf(fid,'%s\t',hdr(i,:));
end

end

for j=1:ndep

for i=1:nvar

if i== nvar
fprintf(fid,'%f\n',dat(i,j));
else
fprintf(fid,'%f\t',dat(i,j));
end
end
end
