close all
clear all

tf = 240;
dt = .05;

sw_density = 1025;


%Pierson Moskowitz Spectrum
           H_S = [1 2 3];  %meters
           PER = [6.0 7.5 9.0];  %Seconds
           SPD = [0 0 0];  %meters/sec
          

AMP = H_S/2;   %height -> amp

 
node_sp = .5; %Node spacing in meters
 
suffix = 'PTO';   
 
path = ['./',suffix,'/'];
  
if(exist(path) == 7)
    fprintf(['Directory ',path,' exists\n\n']);
else
    fprintf(['Directory ',path,' does not exist, will create\n\n']);
    mkdir(path);
end
  
  suffix
  path
  
%fprintf('Hit any key to continue');
%pause
  
PTO_k = 1750;  %lbs/m
depth = 30;

PTO_b = 14000;  %N/(m/s)

for run_num = 3:3

wave_amp = AMP(run_num);
wave_per = PER(run_num);
wind_spd = SPD(run_num);

results_filenm = [path,'Res-',num2str(depth),'d-',num2str(PTO_k),'k-',num2str(wave_amp),'A-',num2str(wave_per),'T-',num2str(wind_spd),'W-',num2str(PTO_b),'b']

layout  %Writes details into ".spec" file that's included into command file .cab file

 WHOI_PATH = '/projectLibrary/901015_MooringTechnologyCollaboration/WHOI_Cable-2.0/';
 fid = fopen('run_cable_cmd','w'); %Open or create new file for writing. Discard existing contents, if any
 
 
 cmd_string = [WHOI_PATH 'cable -in PTO.cab -out Res.crs  -quit -sample .1 -last -nodes ',num2str(nodes_of_interest,'%5d'),' -snap_dt 1'];
 fprintf(fid,'%s\n',cmd_string);
 cmd_string = [WHOI_PATH 'res2mat -in Res.crs -out Res.mat -totals -lbs'];
 fprintf(fid,'%s\n',cmd_string);
 cmd_string = ['mv Res.crs ',results_filenm,'.crs'];
 fprintf(fid,'%s\n',cmd_string);
 cmd_string = ['mv Res.mat ',results_filenm,'.mat'];
 fprintf(fid,'%s\n',cmd_string);

 fclose(fid);   %Need to close the file so run script can delete when complete
 
 fprintf('Cable should start running on whitebird shortly, \n   it may take a few seconds (up to 30 or so) to start up due to some issues with the NFS mounts\n');
 
 ii = 0;
 while exist('run_cable_cmd','file')  %Wait here until 'run_cable_cmd' is deleted, indicating that the cable run is complete.
   fprintf('.'); 
   ii = ii+1;
   if(ii == 20)
       fprintf('\n');
       ii = 0;
   end
   pause(1);
 end
 
 fprintf('Cable has completed running\n');
 
end

