%
%  Name:   makeDOF
%
%  Usage:  makeDOF
%
%  This m-file allows the user to map the
%  measurement channels to the response DOF and
%  reference DOF
% 
%  Version SWD970522
%
%  Author(s): Phillip Cornwell, cornwell@lanl.gov
%	modified by Scott W. Doebling, doebling@lanl.gov
%
%  Institution: Los Alamos National Laboratory,
%               ESA-EA
%
%  Copyright (c) 1996-1997, The Regents of the University
%       of California. (See top level of code for
%       full copyright statement.)
%
%  

if exist('respDOF')~=1, respDOF = []; end
 
if exist('nmeaschan')~=1,
   if exist('G') == 1,
      nmeaschan = size(G,1)/nlines;
   elseif ~isempty(respDOF),
      nmeaschan = size(respDOF,1);
   else
      nmeaschan = 1;   
   end
end


if exist('nrefchan') ~= 1,
   if exist('refDOF'),
      nref = find(refDOF(1,1) == respDOF(:,1) & abs(refDOF(1,2)) == abs(respDOF(:,2)));
      if ~isempty(nref),
         nrefchan = nref;
      else
         nrefchan = nmeaschan;
      end
   else
      nrefchan = nmeaschan;
   end
end

if exist('dofdiropt') ~=1,
   dofdiropt = 3;
end

%
% buttons for the respDOF window
%

hrdof=figure( ...
	'Name','measDOF', ...
	'NumberTitle','off', ...
	'Units','normal', ...
	'Position',[0.5 0.3 0.45 0.7],...
	'menubar','none',...
	'resize','off');

%
%  List box for number of measurement channels
%

top = 0.13;
left = 0.30;
btnwd = 0.4;
btnht = 0.05;
spacing = 0.01;

btnnum=0;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht 3*btnwd/4 btnht];
   uicontrol(...
      'style','text', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string','# Meas. Chan:');
         
btnnum=0;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left+3*btnwd/4 ypos-btnht btnwd/4 btnht];
hmeaschan=uicontrol(...
      'style','edit', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string',num2str(nmeaschan), ...
      'backgroundcolor','w', ...
       'callback',['nmeaschan = str2num(get(hmeaschan,''string''));']);

btnnum=1;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left ypos-btnht 3*btnwd/4 btnht];
   uicontrol(...
      'style','text', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'backgroundcolor',[1 1 1], ...
      'string','Ref. Chan:');
         
btnnum=1;
ypos=top-(btnnum)*(btnht+spacing);
btnpos=[left+3*btnwd/4 ypos-btnht btnwd/4 btnht];
hrefchan=uicontrol(...
      'style','edit', ...
      'unit','normalized', ...
      'position',btnpos, ...
      'string',num2str(nrefchan), ...
      'backgroundcolor',[1 1 1], ...
       'callback',['nrefchan = str2num(get(hrefchan,''string''));',...
			 'disp([''Ref. Channel set to '',num2str(nrefchan)]),']);

%
% Display listbox
%    
    
hchanlist=uicontrol(hrdof, ...
	'style','listbox', ...
	'units','normal', ...
	'pos',[0 .15 .95 .8], ...
	'back','white',...
   'String','uninitialized',...
   'fontname','Courier');


%
%  automatic generation button for nodes
%
hautogen = uicontrol(hrdof, ...
	'style','push', ...
	'units','normal', ...
	'pos',[.71 .08 .28 .05], ...
	'string','Auto number', ...
   'callback',['nodenum=(1:nmeaschan)''; ', ...
      'respDOF = [ [1:nmeaschan]'' dofdiropt*ones(nmeaschan,1)];',...
		'listdof']);
%
%  automatic generation button for directions
%
hdir=uicontrol(hrdof, ...
	'style','popup', ...
	'units','normal', ...
	'pos',[.71 .01 .25 .05], ...
	'string',' x  |  y  |  z', ...
	'value',dofdiropt, ...
   'callback','dofdiropt=get(hdir,''value'');');
   
%   
% Edit button
%
  uicontrol('style','push', ...
	'units','normal', ...
	'pos',[.04 .08 .25 .05], ...
	'string','Edit', ...
	'callback','editdof');

%
% Close button
%
  uicontrol('style','push', ...
	'units','normal', ...
	'pos',[.04 .015 .25 .05], ...
	'string','Close', ...
   'callback',['refDOF = respDOF(nrefchan,:);',...
      'close(hrdof)']);


%
%  Initialize listbox
%

listdof


