Code covered by the BSD License  

Highlights from
spec file reader

image thumbnail
from spec file reader by Zhang Jiang
Monitor, read, save scans from SPEC files and calculate true reflectivity.

showmotorposition
function showmotorposition
% SHOWMOTORPOSITION Called by specr to show the current motor positions

hFigSpecr = findall(0,'Tag','specr_Fig');
settings = getappdata(hFigSpecr,'settings');

% --- open GUI to display the selected scans
h = findall(0,'Tag','figSpecrShowMotorPos');
if ~isempty(h)
    figure(h);
    hTable = findall(h,'tag','figspecrshowmotorpos_table');    
else
    p0      = get(hFigSpecr,'position');    % main figure position
    p1(3)   = 500;              % p1 is the setting figure position
    p1(4)   = 400;
    p1(1)   = p0(1)+p0(3)/2-p1(3)/2-20;
    p1(2)   = p0(2)+p0(4)/2-p1(4)/2-30;
    h = figure(...
        'Units','pixels',...
        'MenuBar','none',...
        'Units','pixels',...
        'Name','Spec Reader - Current Motor Position',...
        'NumberTitle','off',...
        'IntegerHandle','off',...
        'Position',p1,...
        'ResizeFcn',@resizefcn,...
        'HandleVisibility','callback',...
        'Tag','figSpecrShowMotorPos',...
        'WindowStyle','normal',...
        'UserData',[]);
    tableSize = [10 60 p1(3)-20 p1(4)-70];    
    hTable = uitable(...
        'Parent',h,...
        'Units','pixels',...
        'Tag','figspecrshowmotorpos_table',...
        'Position',tableSize);
    hPushbuttonOutput = uicontrol(...
        'Parent',h,...
        'Style','pushbutton',...
        'String','Save to Workspace',...
        'tag','figspecrshowmotorpos_pushbuttonOutput',...
        'Position',[p1(3)-310 20 120 25],...
        'callback',@pushbuttonOutputCallbackFcn);        
    hPushbuttonRefresh = uicontrol(...
        'Parent',h,...
        'Style','pushbutton',...
        'String','Refresh',...
        'tag','figspecrshowmotorpos_pushbuttonRefresh',...
        'Position',[p1(3)-180 20 50 25],...
        'callback','showmotorposition;');    
    hPushbuttonClose = uicontrol(...
        'Parent',h,...
        'Style','pushbutton',...
        'String','Close',...
        'tag','figspecrshowmotorpos_pushbuttonClose',...
        'Position',[p1(3)-90 20 50 25],...
        'Callback','delete(gcf);');
end

file = settings.file;
scan = settings.scan;

if isempty(file) | isempty(scan) | ~isfield(scan,'selection') | isempty(scan.selection{1})
    return;
end

% --- display motor positions in table
%colName = cell(1,length(scan.selectionIndex)+1);
colFormat = cell(1,length(scan.selectionIndex)+1);
colEditable = false(1,length(scan.selectionIndex)+1);
tableData = cell(length(scan.motorName),length(scan.selectionIndex)+1);
colName{1} = 'name/scan#';
colFormat{1} = 'char';
tableData(:,1) = scan.motorName';
for iCol = 1:length(scan.selectionIndex)
    colName{iCol+1} = num2str(scan.selectionIndex(iCol));
    colFormat{iCol+1} = 'numeric';
    tableData(:,iCol+1) = num2cell(scan.selection{iCol}.motorPos');
end
set(hTable,...
    'columnName',colName,...
    'columnFormat',colFormat,...
    'columnEditable',colEditable,...
    'RearrangeableColumn','on',...
    'Data',tableData,...
    'Userdata',scan.selectionIndex);


%================================================================
% --- toolbar mousetracking callback function
%================================================================
function pushbuttonOutputCallbackFcn(hObject,eventdata)
hTable = findall(gcbf,'Tag','figspecrshowmotorpos_table');
tableData = get(hTable,'Data');
if isempty(tableData)
    return;
end
motorPosOutput.scan = get(hTable,'userdata');
motorPosOutput.name = tableData(:,1);
motorPosOutput.pos = cell2mat(tableData(:,2:end));
assignin('base','specrMotor',motorPosOutput);


%=================================================================
% --- figure resizefcn function
%=================================================================
function resizefcn(hObject,eventdata)
h = gcbo;
p1 = get(h,'Position');
panelSize = [10 60 p1(3)-20 p1(4)-70];
try
    set(findobj(h,'tag','figspecrshowmotorpos_table'),'position',panelSize);
    set(findobj(h,'tag','figspecrshowmotorpos_pushbuttonOutput'),'position',[p1(3)-310 20 120 25]);    
    set(findobj(h,'tag','figspecrshowmotorpos_pushbuttonRefresh'),'position',[p1(3)-180 20 80 25]);
    set(findobj(h,'tag','figspecrshowmotorpos_pushbuttonClose'),'position',[p1(3)-90 20 80 25]);
catch
end

Contact us at files@mathworks.com