%callplot (really callplotnf but too many letters for CD.) 
%program calls function gbplot to plot greene bomber acoustics data
% emat = file name in matlab workspace that has data to be plotted
%	 program assumes data file has seven parameter columns and n data columns as:
%		col 1:   Yearday.time
%		col 2:   latitude (degrees and fractions of degrees)
%		col 3:   longitude (- for Northern Hemisphere and West)
%		col 4:   Transducer frequency
%		col 5:   Minimum depth of acoustic bins (meters)
%  col 6:   Maximum depth of acoustic bins (meters)
%  col 7:   Depth interval of acoustic bins (meters)
%  col 8-n: Volume backscattering data (sv, not logged)
% Thus each row has a single time interval of acoustic data
% yint = equals the number of depth bins in data file and is deteremined
%        by maxdepth/depthint after mindepth set to 1 meter and maxdepth adjusted appropriately. 
% xint = equals the number of horizontal bins and is determined in the
%        the function
% figtitle = title to go on plot
%
% nplot = number of plots - max of four
%

 %set global variables
 %global lat lon emat trandist deltapos bottom xint yint
 global lat lon emat trandist deltapos bottom xint yint depthint mindepth maxdepth left step ic tflag mflag moc filename plhan plax
                                                                 
gfig= figure
nplot=input('input number of plots on figure  ','s');
nplot=str2num(nplot);
ic=1;
bottom = 0.1; % start of bottom plot - window 0,0 to 1.0,1.0
left = 0.1;
if nplot == 1
    step = .8;
end
if nplot == 2
    step = 0.4;
end
if nplot == 3
    step = 0.3;
end
if nplot == 4
    step = 0.2;
end


for ic = 1:nplot

filename=input('input name of matrix to plot  ','s');
load (filename);
%%%emat=eval(filename);
%whos
%pause
mindepth=emat(1,5);
maxdepth=emat(1,6);
if mindepth > 1
   excess=fix(emat(1,5));
   emat(:,5)=emat(:,5)-excess; % adjust depths so that min depth is between 0 and 1 m.
   emat(:,6)=emat(:,6)-excess;
   mindepth=emat(1,5);
   maxdepth=emat(1,6); %adjust maxdepth too
end
   depthint= emat(1,7); % size of depth interval in meters
   %yint=maxdepth/depthint;   % number of depth intervals
   yint = length(emat(1,1:end))-7;% number of depth intervals



%yint=input('input number of depth intervals  ','s')
%yint=str2num(yint);

tflag=input('input 1 if distance, 2 if time plot ','s');
tflag=str2num(tflag);

mflag=input('input 1 if moc overplot, 0 if no overplot ','s');
mflag=str2num(mflag);

if mflag==1
  moc=input('input moc tow number to plot on section ','s');
  moc=eval(moc);
else
   moc='none';
end

%find zero values of volume backscattering and set equal to 1.01e-10
lerow=length(emat(1,:))-7;
numrow=length(emat(:,1));
tmpcol=reshape(emat(:,8:length(emat(1,:))),lerow*numrow,1);
ifnd=find(tmpcol(:,1)==0);
te=ones(size(ifnd)).*(1.01e-10);
 if ifnd >0 
    tmpcol(ifnd,1)=te;
 end
 emat(:,8:length(emat(1,:))) = reshape(tmpcol, numrow,lerow);
%end find routine
%whos
%pause
plotgb
   %really plotgbnf but for the CD, must be shortened 
%plotgbnf(emat,yint,depthint,mindepth,maxdepth,left,bottom,step,ic,tflag,mflag,moc,filename);


bottom = bottom + step;
end
%end    % end of main program loop
%xlabel('Time(Yearday)')
%ylabel('Depth (meters)')
%rect=[.099,.099,.8,.85];
%h=axes('position',rect)
%set(h,'xcolor',[0,0,0]);%set xaxis to black
%set(h,'ycolor',[0,0,0]);%set yaxis to black
%axis('off')
%if tflag ==2
%   set(gca,'xlabel',text(1,1,'Time (year-day)'))
%   end
%if tflag ==1
   %set(gca,'xlabel',text(1,1,'Distance (meters)'))
%   xlabel('Distance (meters)')
%   end
   %set(gca,'ylabel',text(1,1,'Depth (m)'));
%   ylabel('Depth (m)')
%clear lon mflag rect step te tflag trandist yint
%clear bottom deltapos figlab h ic ifnd lat left
%clear emat depthint excess lastdepth maxdepth mindepth moc presentdepth j i
%return
for ic=1:nplot
  figlab=input('input label for figure  ','s');
  flab=gtext(figlab);
  set(flab,'fontweight','bold','color', 'w');
end
clear nplot ic
figtitle=input('input figure title  ','s');
ftitle=title(figtitle);
set(ftitle,'fontweight','bold');
ylab=gtext('Depth (m)');
set(ylab,'rotation',[90]);
set(ylab,'fontweight','bold');
if tflag ==1
   xlab=gtext('Distance (meters)');
 elseif tflag ==2
   xlab=gtext('Time (Yearday)');
end
  set(xlab,'fontweight','bold');
