close all
clear all

name = 'CCE2_hamilton_v1';



  LAYOUT.title = name;


condition = 2;

Conditions{1}.xwaveamp = 1;
Conditions{1}.xwaveperiod = 12;
Conditions{1}.xwavephase = 0;
Conditions{1}.xwind = 8;
Conditions{1}.currentscale = 1;

Conditions{2}.xwaveamp = 4;
Conditions{2}.xwaveperiod = 15;
Conditions{2}.xwavephase = 0;
Conditions{2}.xwind = 21;
Conditions{2}.currentscale = 1;

Conditions{3}.xwaveamp = 1;
Conditions{3}.xwaveperiod = 12;
Conditions{3}.xwavephase = 0;
Conditions{3}.xwind = 8;
Conditions{3}.currentscale = 0.5;

Conditions{4}.xwaveamp = 4;
Conditions{4}.xwaveperiod = 15;
Conditions{4}.xwavephase = 0;
Conditions{4}.xwind = 21;
Conditions{4}.currentscale = 0.5;


ENV = Conditions{condition};  


  %1 = Catenary w/ stretch hose
  %2 = Catenary w/ EM Chain
  %3 = Taut w/ stretch hose, 
  %4 = Catenary w/stretch hose and buoyant ESP

  for LAYOUT.config = [1]



  ENV.depth = 770;
  ENV.tf = 330; 
  ENV.dt = .02;
  ENV.ramptime = 30;

  ENV.xcurrent = NaN(4,2);
  ENV.xcurrent(1,:) = [0 0.515];
  ENV.xcurrent(2,:) = [20 0.515];
  ENV.xcurrent(3,:) = [100 0.1];
  ENV.xcurrent(4,:) = [770 0.1];

  ENV.dynamiclambda = -0.5;
 
  ENV.forcing_type =  'wave-follower'; %'velocity';  % -or- 'wave-follower'
 
  ENV.input_type = 'random';  % regular -or- 'random'

  
   LAYOUT.config
 
   filenm = make_layout(ENV,LAYOUT,name)


    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']);

 





