Auto bt
Jump to navigation
Jump to search
Picks points for the downcast matrix for PRR/C-OPS/CERBERUS
function auto_bt(varargin) %Erik Stassinos 2-26-2014 %to automate picking tops and bottoms of casts %this is needed for the CERBERUS where multiple casts are done %prrstrip(1,prr_lcd,'Master_FrameNumber','LuZDepth') example function call %==populate list_prr fid=fopen('list_prr.txt','r'); list_prr = []; badfilectr =0; tmpfile=fullfile(pwd,'goprrbt_tmp'); while fid, check=fgetl(fid); if check == -1, break, end list_prr=[list_prr; check]; end %==check if files are present for i=1:size(list_prr,1) [s,m]=unix(['ls ',list_prr(i,:)]); if s badfilectr=badfilectr+1; end end clear i if badfilectr if badfilectr==1 msg=sprintf('%i missing prr file.',badfilectr); disp(msg) error('Your prrlist includes a file not in pwd.') else msg=sprintf('%i missing prr files.',badfilectr); disp(msg) error('Your prrlist includes files not in pwd.') end end clear s m badfilectr msg %===end check if files are present for i=1:size(list_prr,1) prr_lcd=list_prr(i,:); prr_strip=[prr_lcd '.strip']; var_1 = varargin{1}; var_2 = varargin{2}; prrstrip(1,prr_lcd,var_1,var_2) %pull columnds to create two variable file %prrstrip(1,prr_lcd,'FrameCount','LuZDepth') [fileA,headA]=read_strip(prr_strip); depth = fileA(:,2); index = fileA(:,1); %time %shallowest points on shallow depth rowmn = find(fileA(:,2) == max(fileA(:,2)));%shallowest point--use this to start %downcast deepest point rowdcmx = find(fileA(:,2) == min(fileA(rowmn:end,2))); rowmx = find(fileA(:,2) == min(fileA(:,2)));%deepest point %==========visualize points===================== plot(index,depth) %plot all the data hold on plot(index(rowmx:rowmn),depth(rowmx:rowmn),'g-.') %plot deepest to shallowest green hold on plot(index(rowmn:rowdcmx),depth(rowmn:rowdcmx),'r-.') %plot downcast only red %=========end visualize===================== %========creat bt file===================== fid=fopen( 'bt.pts', 'w' ); %create bt.pts file fprintf(fid,'castid index 1mer_time 1depth\n'); bt_pts = [[rowmn(1);rowdcmx(1)], [index(rowmn(1));index(rowdcmx(1))],[sqrt((depth(rowmn(1)))^2);sqrt((depth(rowdcmx(1)))^2)]]; %assemble parameters for castid %btpts is index, time, depth %id is number of casts processed---- always going to be one per file at %this time bt_castname=[ prr_lcd(1:9),'dt','1']; %castdir is dt db for downcast top or bottom fprintf(fid,'%s %1.7e %1.7e %1.7e \n',bt_castname,bt_pts(1,:)); %print castID matrix fprintf(fid,'%s %1.7e %1.7e %1.7e \n',bt_castname,bt_pts(2,:)); fclose(fid); eval(['!mv ' prr_lcd ' ' tmpfile]) unix(sprintf('sed ''-e /<sampled_parameters>/ r bt.pts'' -e//N %s > %s',tmpfile,prr_lcd)) % eval([ '!awk < ' prr_lcd ' > ' tmpfile... % ' ''$1=="<sampled_parameters>"{system("cat bt.pts")}{print $0}''']) % eval([ '!mv ' tmpfile ' ' prr_lcd ]); end