close all
clear all

name = 'DelMar_hamilton_v2';


%Current Profile Estimates from ADCP data
%profile_z = [0 -5 -10 -20 -40 -60 -80 -102];
%mean_profile = [17 17 17 15.5 12.5 10 9 9];   % Mean Profile
%max_obs_profile = [92 92 92 75 65 65 65 65];  % Max Observed Profile

  LAYOUT.title = name;
  
  ENV.depth = 100;

tf = [300]
for  n = 1:length(tf) 
  ENV.tf = tf(n)

  ENV.ramptime = 30;

ESP_wetweight = [-220  760 1550];  %Newtons
pigmass = [200 100 20];  %kg
net = (pigmass*9.81+ESP_wetweight)/4.45

if(ENV.tf == 0)
  waveAmp = [1];
  wavePer = [10];
else
  waveAmp = [4.8/2 2/2]
  wavePer = [9 14];
end


for config = 1 %1:length(ESP_wetweight)
 LAYOUT.pigmass = pigmass(config);
 LAYOUT.ESP_wetweight = ESP_wetweight(config);

  for LAYOUT.hose =  [1] % 2 3];  %1 = Soft  2 = Nominal  3 = Stiff

if(ENV.tf == 0)
  currentscale = [2:.5:4.5];
else
   currentscale = 2
end

  for k = 1:length(currentscale)

  ENV.currentscale = currentscale(k);


  ENV.xcurrent = NaN(8,2);
  ENV.xcurrent(1,:) = [0 .17];
  ENV.xcurrent(2,:) = [5 .17];
  ENV.xcurrent(3,:) = [10 .17];
  ENV.xcurrent(4,:) = [20 .155];
  ENV.xcurrent(5,:) = [40 .125];
  ENV.xcurrent(6,:) = [60 .1];
  ENV.xcurrent(7,:) = [80 .09];
  ENV.xcurrent(8,:) = [100 .09];

for seastate = 1:length(waveAmp)
  ENV.xwaveamp = waveAmp(seastate);
  ENV.xwaveperiod = wavePer(seastate);

  ENV.xwavephase = 0;
  ENV.xwind = 5*ENV.currentscale;


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

  LAYOUT.stretch_hose_length = 10.0;
  a = 1.9;
  LAYOUT.strain_factor = (1-4*a/(3*LAYOUT.stretch_hose_length));
 
   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);

   cmd = ['grep -e ^[0-9][0-9][0-9][0-9] ' filenm '.bom > ' filenm '.modbom'];
    system(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
    if(ENV.tf > 0)
       cable_cmd = [cable_cmd ' -snap_dt 1 -sample ' num2str(ENV.dt) ' -quit'];
    else
       cable_cmd = [cable_cmd '-static -quit'];
    end

    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

end
end

end
end
    load([filenm '.mat']);

 





