close all
clear all

node_sp = 1;

cabfile_name = 'SpringMassModel';

ENV.depth = 100;
ENV.xcurrent = 0.1;
ENV.xwind = 0.1;

LAYOUT.title = cabfile_name;

dt = 15;  %meters
h = 1;  %meters
LAYOUT.Ku = 270;  %N/m
LAYOUT.Kl = 62;  %N/m
W_weight = -200*4.45;  %N (negative means heavy in water
LAYOUT.Lu = 10;  %meters



LAYOUT.mass = 390;



[LAYOUT.Ll LAYOUT.EAu LAYOUT.EAl] = ComputeUnstrechedLowerLength(W_weight,LAYOUT.Ku,LAYOUT.Kl,LAYOUT.Lu,ENV.depth,dt,h)

LAYOUT.n_upper_nodes = round(LAYOUT.Lu/node_sp);
LAYOUT.n_lower_nodes = round(LAYOUT.Ll/node_sp);

   
   for ENV.amp = 1 %:4;
   for ENV.period = 3:1:20;
   
   ENV.dt = .05;
   ENV.steps = 0;    
   ENV.tf = 1*5*ENV.period;
   
   ENV.input_type = 'velocity';
   
   filenm = make_layout(ENV,LAYOUT,cabfile_name)


   cmd = ['cp ' cabfile_name '.spec ' filenm '.spec'];
   system(cmd);

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

    ver_cmd = ['cable -version 2> ' filenm '.ver'];
    system(ver_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 ' '];  %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'];

    if(ENV.tf == 0)
      cable_cmd = [cable_cmd ' -static'];
    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);

    %cmd = ['rm ' filenm '.res'];
    %system(cmd);

    cmd = ['gzip -f ' filenm '.out'];
    system(cmd);

    cmd = ['rm ' cabfile_name '.spec'];
    system(cmd);

    Results = load([filenm '.mat']);
    figure
    plot(Results.t,Results.z_t)

end
end

 





