close all
clear all

g = 9.81;

T = .5:.5:40;
ka = (4*pi^2)./(g*T.^2);


node_Spacing = .25;

for draft = [.15] % 5 4 3 2 1 .8 .6 .4 .2 .1];

  filename = ['t_cyl_d' num2str(draft)];

  sp_z = ceil(draft/node_Spacing);
  sp_r = ceil(1.0/node_Spacing);
  sp_th = round((2*pi/node_Spacing)/4);

  fid = fopen('t_cyl.spec','w');
  str = ['#define DDD  ' num2str(draft,4) '\n'];   fprintf(fid,str);
  str = ['#define DHALF  ' num2str(draft/2,4) '\n'];   fprintf(fid,str);
  str = ['#define SP_Z  ' num2str(sp_z) '\n'];   fprintf(fid,str);
  str = ['#define SP_R  ' num2str(sp_r) '\n'];   fprintf(fid,str);
  str = ['#define SP_TH  ' num2str(sp_th) '\n'];   fprintf(fid,str);

  str = ['#define NUM_WAVENUMS  ' num2str(length(ka)) '\n'];   fprintf(fid,str);

  fclose(fid);


  cmd = ['cpp t_cyl_template.mgen | grep -v "#" > ' filename '.mgen'];
  system(cmd);

  fid = fopen([filename '.mgen'],'a');
  for i = length(ka):-1:1
    str = [num2str(ka(i)) '\n']; fprintf(fid,str);
  end
  str = '\n'; fprintf(fid,str);
  str = ['Run conditions \n']; fprintf(fid,str);
  str = ['-1.000000     1.000000     0.000000    2    1    0    0']; fprintf(fid,str);
  fclose(fid);

  cmd = ['./m_gen < ' filename '.mgen > ' filename '.msh'];
  system(cmd);

  cmd = ['./plot_stdin < ' filename '.msh > ' filename '.plt'];
  system(cmd);

  cmd = ['./wdra3d < ' filename '.msh > ' filename '.out'];
  system(cmd);
end
