Guest User

Untitled

a guest
Sep 20th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.75 KB | None | 0 0
  1. %% SETUP VARIABLES
  2.  
  3. % load the sonar
  4. p = '\\storebox\Aquacoustic\Job Data\55562_Hydromax_Baltimore-County\Processed\Ready for Splitting\Mother''s Arms\47174 47175 47176 47178 47179 47180_001 CONCAT_dblchk.MAT'
  5. a = load(p)
  6.  
  7. xsect = a.xsect
  8. uconv = 0.3048
  9. runlengths = [ 269 202 601 100 92] .*uconv
  10. splits = zeros(1,numel(runlengths))
  11. deltas = Inf(1,numel(runlengths))
  12. thresh_2 = 1 %squared threshold for search function
  13.  
  14. %perform discrete integration of runlengths to find absolute payout of
  15. %potential split locations
  16. abspos = cumsum(runlengths)
  17.  
  18.  
  19. %we're going to need to reset these cable lengths to 0 for the output files
  20. %so we make an array for easily grabbing the offsets out of. it will have
  21. %one extra value we dont need at the end that we can just ignore
  22. offsets = [0 abspos]
  23.  
  24.  
  25. %%FIND THE SPLITS
  26.  
  27. %find the split locations (looking for profile that most closely
  28. %matches the absolute position)
  29.  
  30.  
  31. for i = 1:numel(xsect.img)
  32.     for j = 1:numel(runlengths)
  33.         delta = xsect.img(i).cable - abspos(j);
  34.         delta = delta*delta;
  35.         if(delta<thresh_2)
  36.             if(delta<deltas(j))
  37.                 splits(j) = i;
  38.                 deltas(j) = delta;
  39.             end
  40.         end
  41.     end
  42. end
  43.  
  44. %% build an array of indices for splitting
  45.  
  46. %start by padding the splits
  47. splits_1 = splits+1
  48. split_ind = reshape([splits;splits_1],1,[]) %this interleaves splits
  49.                                             %and split_1
  50.                                            
  51. split_ind = [1 split_ind numel(xsect.img)]  %this adds a 1 and N entry
  52.                                             %to split matrix
  53.  
  54. split_ind = reshape(split_ind',2,[])'
  55.  
  56.  
  57.  
  58. IN = xsect % we call the xsect var. "IN" now, the output var has to be called
  59.            % "xsect" so it will still load in sonar express
  60.  
  61. %% DO THE SPLITTING
  62.  for row = 1 : size(split_ind,1)
  63.      xsect = struct;   %create the output structure
  64.      
  65.      % these are just some variables that need to be saved
  66.      % with the file
  67.      xsect.currentStation = 1;
  68.      xsect.unit = IN.unit;
  69.      xsect.renderOptions = IN.renderOptions;
  70.      xsect.longVer = IN.longVer;
  71.  
  72.      %slice from the input
  73.      xsect.img = IN.img( split_ind(row,1):split_ind(row,2));
  74.      xsect.oper = IN.oper(split_ind(row,1):split_ind(row,2));
  75.      
  76.      %reset the payout (cable distance) so the segment starts
  77.      %at 0
  78.      for i=1:numel(xsect.img)
  79.         %cable length is stored in 2 places in the output
  80.         %structure
  81.         xsect.img(i).cable = xsect.img(i).cable - offsets(row)
  82.         xsect.oper(i).cable = xsect.oper(i).cable - offsets(row)
  83.      end
  84.      
  85.     %finally, save the segment
  86.      fprintf('Writing...\n');
  87.      save(sprintf('%s.part%.0f.mat',p,row),...
  88.         'xsect');
  89.  end
Add Comment
Please, Sign In to add comment