function [blkprf, sel_dday] = cl_blkprf(fieldname, prefix)
% [blkprf, sel_dday] = cl_blkprf(fieldname, str);
% graphical tool to identify block and profile
% input:
%  fieldname could be 'amp', 'pg', 'u_meas', ...
%
% output: 
%  nlkprf is block and profile of selected dday
%  sel_dday is selected decimal day (and bin number)
%
%  writes formatted date and decimal day to stdout
%
%  action: click on locations where you want to know the block and profile
%         hit <CR> (while the figure is active) when through
%
% ASSUMES you are in a directory where getmat output exists (such as 
%       during a standard shipboard profile  editing session
%
% normally reads bare getmat output (w.mat, u.mat,...)
% second argument is an optional prefix
%
% example: 
% [blkprf, sel_dday] = cl_blkprf('pg');
% [blkprf, sel_dday] = cl_blkprf('uabs_sm', 'a_');


%broke this
% If you are doing 'autoedit' and have run aflagit_setup, a second argument
%       of 'gautoedit' will turn on flagging if it is on in autoedit
%


if ~exist('prefix')
   prefix = '';
end


%Jules 2000/11/13

if (nargin == 0)
   fieldname = 'pg';
   disp('assuming fieldname pg')
   help cl_blkprf
end


[data, config] = agetmat(prefix);
figure
cfg = aplotit(data, config, 'fn', fieldname);

axes(cfg.cur_ax)
disp('select points on the current plot to get block and profile')
sel_dday = ginput;
blkprf = zeros(size(sel_dday));


if (~isempty(sel_dday))
   sel_dday(:,2) = round(sel_dday(:,2));  % get whole numbers for bin
   
   for ddi = 1:length(sel_dday(:,1))   %decimal day counter
      [junk, bpi] = min(abs(data.dday - sel_dday(ddi,1)));
      blkprf(ddi,:) = data.iblkprf(bpi,:);
      cc = data.time(bpi,:);
      fprintf(' %s  (dday %10.7f)      bin %d\n',...
              to_date(cc(1),to_day(cc(1),cc),'s'),...
              data.dday(bpi), sel_dday(ddi,2))
   end
end

   

