% fileout.m
% Write the files out in proper format
%filename = 'debouch'

fid = fopen([filename,'.nod'],'wt');
fprintf(fid,' %6i %9.4f %9.4f\n',meshnod');
fclose(fid);

fid = fopen([filename,'.ele'],'wt');
fprintf(fid,' %8i %8i %8i %8i \n',meshele');
fclose(fid);

 
fid = fopen([filename,'.bat'],'wt');
fprintf(fid,' %6i %9.4f\n',bathy');
fclose(fid);

if exist('meshcd')
  fid = fopen([filename,'.cd'],'wt');
  fprintf(fid,' %6i %9.4f\n',meshcd');
  fclose(fid);
end



fid = fopen([filename,'.bel'],'wt');
fprintf(fid,[filename,'.bel  stuff \n']);
fprintf(fid,' n such \n');
fprintf(fid,'%8i %8i %8i %8i %8i\n',bndele');
fclose(fid);

fid = fopen([filename,'.bcs.s2c'],'wt');
fprintf(fid,[filename,'.bel \n']);
fprintf(fid,' M2 Elevation BCs 1000km long wave \n');
fprintf(fid,'   .1405E-03 \n');
[m,n]=size(bcs);
if n==4
fprintf(fid,' %6i %9.6f %10.6f %6i\n',bcs');
end
if n==3
fprintf(fid,' %6i %9.6f %10.6f \n',bcs');
end

fclose(fid);


ef = ['save ',filename,'all.mat meshnod meshele bathy meshcd bndele bcs filename'];
disp(ef)
eval(ef)

