function [filename] = RunCable(ENV,LAYOUT)

filename = make_layout(ENV,LAYOUT);


cpp_cmd = ['cpp ESP.cab ' filename '.cab'];
system(cpp_cmd);

bom_cmd = ['cable_bom -in ESP.cab -out ' filename '.bom -bom'];
system(bom_cmd);

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

seg_name
seg_length
%seg_nodes

if(ENV.tf > 0)
  cable_cmd = ['cable -in ' filename  '.cab -out ' filename '.res -first -last -nodes '];
  for n = 1:length(seg_nodes)
    cable_cmd = [cable_cmd num2str(seg_nodes(n)) ' '];
  end
  cable_cmd = [cable_cmd ' -snap_dt 1 -sample ' num2str(ENV.dt) ' -quit'];
else
  cable_cmd = ['cable -in ' filename '.cab -out ' filename '.res -first -last'];
  %cable_cmd = [cable_cmd ' -initial initial.res'];
  cable_cmd = [cable_cmd ' -static -quit'];
end

disp(cable_cmd)

%cable_cmd = [cable_cmd ' | tee ' filename '.out'];
cable_cmd = [cable_cmd];
system(cable_cmd);

copy_cmd = ['cp ' filename '.res initial.res'];
system(copy_cmd);

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

load([filename '.mat']);
save('-mat',[filename '.mat']);

