close all
clear all


name = 'del_mar_hamilton_v0';



  LAYOUT.title = name;
  
  ENV.depth = 100;
  ENV.tf = 330; 
  ENV.dt = .01;
  ENV.ramptime = 30;
  ENV.xwaveamp = 2.5;
  ENV.xwaveperiod = 15;
  ENV.xwavephase = 0;
  ENV.xwind = 20;

  ENV.dynamiclambda = -0.5;

  ENV.currentscale = 1;
  ENV.xcurrent = NaN(6,2);
  ENV.xcurrent(1,:) = [0 1.0];
  ENV.xcurrent(2,:) = [5 1.0];
  ENV.xcurrent(3,:) = [10 0.9];
  ENV.xcurrent(4,:) = [20 0.45];
  ENV.xcurrent(5,:) = [50 0.3];
  ENV.xcurrent(6,:) = [75 0.2];
  ENV.xcurrent(6,:) = [100 0.05];
 
  ENV.forcing_type =  'velocity'; %'velocity';  % -or- 'wave-follower'
 
  ENV.input_type = 'random';  % -or- 'random'

  LAYOUT.config = 1;  %0 = no esp, no stretch-hose
		      %1 = esp directly in line with nilspin at 15m depth, no stretch-hose
		      %2 = esp directly in line with nilspin at 15m depth, 5m stretch hose below buoy.
  		      %3 = esp directly in line with nilspin at 15m depth, 15m stretch hose below buoy.

  for LAYOUT.config = [0 1 2]
  
   LAYOUT.config
 
   filenm = make_layout(ENV,LAYOUT,name);

   filenm


    cpp_cmd = ['cpp ' name '.cab ' filenm '.cab'];
    system(cpp_cmd);

    bom_cmd = ['cable -in ' filenm '.cab -out ' filenm '.bom -bom'];
    system(bom_cmd);

    [seg_name seg_length seg_n_nodes seg_nodes] = read_bom(filenm);

    cable_cmd = ['cable -in ' filenm '.cab -out ' filenm '.res -nodes '];
    cable_cmd = [cable_cmd num2str(1) ' '];  %List the anchor node specifically instead of using '-first -last'
    for n = length(seg_nodes):-1:1
      cable_cmd = [cable_cmd num2str(seg_nodes(n)) ' '];
    end
    cable_cmd = [cable_cmd ' -snap_dt 1 -sample ' num2str(ENV.dt) ' -quit'];
    cable_cmd = [cable_cmd ' | tee ' filenm '.out'];

    system(['echo ' cable_cmd ' > ' filenm '.cmd']);

    system(cable_cmd);

    res2mat_cmd = ['res2mat -in ' filenm '.res -out ' filenm '.mat -lbs -totals'];
    system(res2mat_cmd);

   end


    load([filenm '.mat']);

 





