%
%  Name:   mplot1
%
%  Usage:  mplot1
%
%  This m-file the data in a grid
% 
%  Version SWD970731

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This matlab source code was originally     %
% developed as part of "DIAMOND" at          %
% Los Alamos National Laboratory. It may     %
% be copied, modified, and distributed in    %
% any form, provided:                        %
%  a) This notice accompanies the files and  %
%     appears near the top of all source     %
%     code files.                            %
%  b) No payment or commercial services are  %
%     received in exchange for the code.     %
%                                            %
% Original copyright is reserved by the      %
% Regents of the University of California,   %
% in addition to Scott W. Doebling, Phillip  %
% J. Cornwell, Erik G. Straser, and Charles  %
% R. Farrar.                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%holdaxes = haxes;

%clear haxes

hplttl = HANDLES.hplttl;

cf = DATA{1}.cf;
sp = DATA{1}.sp;
nlines = DATA{1}.nlines;
G = DATA{1}.G;
respDOF = DATA{1}.respDOF;
refDOF = DATA{1}.refDOF;

fmin=cf-sp/2;
   fmax=cf+sp/2;
   df=sp/(nlines-1);
   freq=fmin:df:fmax;

     fminm = fmin;
     fmaxm = fmax;
     
     hlegax = [];
     
     
     iref = 1;
     
     % Initialize plot tool
     iyscale = 1;
     iylog = 1;
     nfunc = 1;
     
     set(hplttl(11),'string','Primary Data')
set(hplttl(14),'value',iyscale)
	set(hplttl(15),'value',iylog)



mplot1h=figure;
set(mplot1h,'Name','Diamond: Multiplot1');
set(mplot1h,'NumberTitle','off');
set(mplot1h,'menubar','none');
set(mplot1h,'Units','normal');
%
%  Calculate some values.  This routine assumes the input to be
%  plotted is G.
%
fmin=cf-sp/2;
fmax=cf+sp/2;
df=sp/(nlines-1);
freq=fmin:df:fmax;

Gmag=abs(G);
amin=min(Gmag(:));
amax=max(Gmag(:));

%========================================================
%  set up all the uicontrols
%========================================================
%
% bar along the top
%
mplottitle=['filename = ',filename,',  number of DOF = ',int2str(size(respDOF,1))];
mplottith=uicontrol(mplot1h, ...
     'style','text', ...
     'units','normal', ...
     'pos',[.00 .96 1 .04], ...
     'string',mplottitle);
%
% Extremely long callback string
%
callstr=str2mat(['numrow=str2num(get(numrowh,''string''));', ...
      'numcol=str2num(get(numcolh,''string''));', ...
      'nstart=str2num(get(nstarth,''string''));', ...
      'numplot=numrow*numcol;' ...
      'if exist(''haxes'')==1, if ishandle(haxes(1)), delete(haxes), end, end,',...
      'clear haxes,',...
 'if (numplot+nstart-1)>=size(respDOF,1),', ...
   'numplot=size(respDOF,1)-nstart+1;end;' ...
   'for i=1:numplot,', ...
   ' nplotdof = i+nstart-1;',...
   'subplot(numrow,numcol,i),semilogy(freq,abs(Gmag(:,nplotdof,iref)));', ...
   'haxes(i) = gca;',...
   'txt=[''DOF = '',respDOF(nplotdof,:)];', ...
   'text((fmin+fmax)/2,amin*2.3,txt);', ...
   'axis([fmin fmax amin amax]);', ...
   'h=get(gca,''Children'');', ...
   'set(h(1),''FontSize'',8);', ...
   'set(gca,''FontSize'',8);', ...
   'title([''Resp DOF #'',num2str(nplotdof)]),',...
   'end;', ...
   'hallaxes = haxes;',...
   'flim = get(haxes(1),''xlim'');',...
   'set(hplttl(3),''string'',num2str(flim(1))),',...
  	'set(hplttl(5),''string'',num2str(flim(2))),',...
 'hout=suptitle([''filename = '',filename]);', ...
 'set(mplottith,''visible'',''off'');', ...
 'set(mplotprinth,''visible'',''on'')']);
%
%  Number of columns
%
numcolth= uicontrol(mplot1h, ...
       'style','text', ...
       'units','normal', ...
       'pos',[.01 .01 .10 .04], ...
       'string','Columns');
numcolh=uicontrol(mplot1h, ...
       'style','edit', ...
       'units','normal', ...
       'pos',[.11 .01 .05 .04], ...
       'string','1', ...
       'back','white');
%
%  Number of rows
%
numcolth= uicontrol(mplot1h, ...
       'style','text', ...
       'units','normal', ...
       'pos',[.19 .01 .1 .04], ...
       'string','Rows');
numrowh=uicontrol(mplot1h, ...
      'style','edit', ...
      'units','normal', ...
      'pos',[.29 .01 .05 .04], ...
      'string','1', ...
      'back','white');
   
%
%  Starting Response channel
%
nstartth= uicontrol(mplot1h, ...
       'style','text', ...
       'units','normal', ...
       'pos',[.37 .01 .06 .04], ...
       'string','start');
nstarth=uicontrol(mplot1h, ...
      'style','edit', ...
      'units','normal', ...
      'pos',[.43 .01 .05 .04], ...
      'string','1', ...
      'back','white');
%
% Plot pushbutton
%
mplotith=uicontrol(mplot1h, ...
      'style','push', ...
      'units','normal', ...
      'pos',[.49 .01 .1 .04], ...
      'string','plot', ...
      'callback','eval(callstr)');
%
% Minimum Frequency
%
%fminth= uicontrol(mplot1h, ...
%      'style','text', ...
%      'units','normal', ...
%      'pos',[.61 .01 .07 .04], ...
%      'string','fmin');
%fminh=uicontrol(mplot1h, ...
%      'style','edit', ...
%      'units','normal', ...
%      'pos',[.68 .01 .07 .04], ...
%      'string',num2str(fmin),'back','white');
%
% Maximum Frequency
%
%fmaxth= uicontrol(mplot1h, ...
%      'style','text', ...
%      'units','normal', ...
%      'pos',[.76 .01 .07 .04], ...
%      'string','fmax');
%fmaxh=uicontrol(mplot1h, ...
%      'style','edit', ...
%      'units','normal', ...
%      'pos',[.83 .01 .07 .04], ...
%      'string',num2str(fmax),'back','white');
%
% Exit button
%
mplotexith=uicontrol(mplot1h, ...
      'style','push', ...
      'units','normal',... 
      'pos',[.92 .01 .1 .04], ...
      'string','close',...
      'callback','close(mplot1h),');

%
%  Print button
%
mplotprinth=uicontrol(mplot1h, ...
      'style','push', ...
      'units','normal',... 
      'pos',[.88 .91 .1 .04], ...
      'string','print',...
      'visible','off', ...
      'callback',['if numcol < numrow,',...
                     'orient tall;', ...
                   'else,' ...
                     'orient landscape;', ...
                   'end; print;orient portrait;']);
  
%
%  Plot Tools button
%

%hmppt = uicontrol(mplot1h,...
%	'style','push',...
%	'position',[0.75 0.01 0.1 0.04],...
%  'visible','off',...
%	'call',['defmphline,',...
%		'  if exist(''iptline'')~=1, iptline =1; end,',...
%		'set(hplttl(11),''value'',iptline),',...
%		'eval(get(hplttl(11),''call'')),',...
%		'set(hplttl(1),''visible'',''on''),figure(hplttl(1))']);

hireflab = uicontrol(mplot1h, ...
   'style','text', ...
   'units','normal', ...
   'pos',[.76 .01 .07 .04], ...
   'string','Ref #');

hirefed =uicontrol(mplot1h, ...
      'style','edit', ...
      'units','normal', ...
      'pos',[.83 .01 .07 .04], ...
      'string',num2str(iref), ...
      'back','white',...
      'callback',['iref=str2num(get(hirefed,''string''));',...
         ' if isempty(iref), , disp(''Ref # out of Range''),',...
         '    iref = 1; set(hirefed,''string'',num2str(iref)),',...
         ' elseif iref > size(refDOF,1), disp(''Ref # out of Range''),',...
         '    iref = size(refDOF,1); set(hirefed,''string'',num2str(iref)),',...
         ' elseif iref < 1, disp(''Ref # out of Range''),',...
         '    iref = 1; set(hirefed,''string'',num2str(iref)),',...
         'end,']);