function showscan
% SHOWSCAN Called by specr to show the current scan data.
hFigSpecr = findall(0,'Tag','specr_Fig');
settings = getappdata(hFigSpecr,'settings');
% --- open GUI to display the selected scans
h = findall(0,'Tag','figSpecrShowScan');
if ~isempty(h)
figure(h);
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;
p1(2) = p0(2)+p0(4)/2-p1(4)/2;
h = figure(...
'Units','pixels',...
'MenuBar','none',...
'Units','pixels',...
'Name','Spec Reader - Current Scan',...
'NumberTitle','off',...
'IntegerHandle','off',...
'Position',p1,...
'ResizeFcn',@resizefcn,...
'HandleVisibility','callback',...
'Tag','figSpecrShowScan',...
'WindowStyle','normal',...
'UserData',[]);
panelSize = [10 60 p1(3)-20 p1(4)-70];
hPanel1 = uipanel(...
'Parent',h,...
'BackgroundColor',get(h,'Color'),...
'Title','Select Scan',...
'Units','pixels',...
'Tag','figspecrshowscan_panel1',...
'Position',panelSize);
hPopupmenu1 = uicontrol(...
'Parent',hPanel1,...
'Style','popupmenu',...
'HorizontalAlignment','left',...
'BackgroundColor','w',...
'Position',[10 panelSize(4)-40 panelSize(3)-20 20],...
'String','No scan selected',...
'Value',1,...
'callback',@callback_popupmenu1,...
'Tag','figspecrshowscan_popupmenu1');
hEdit2 = uicontrol(...
'Parent',hPanel1,...
'Style','edit',...
'BackgroundColor','w',...
'Position',[10 10 panelSize(3)-20 panelSize(4)-60],...
'String',{'';'';'';'';'';'No scan selected.'},...
'Max',2,...
'Min',0,...
'HorizontalAlignment','center',...
'Tag','figspecrshowscan_edit2');
hPushbuttonRefresh = uicontrol(...
'Parent',h,...
'Style','pushbutton',...
'String','Refresh',...
'tag','figspecrshowscan_pushbuttonRefresh',...
'Position',[20 20 50 25],...
'callback','showscan;');
hPushbuttonClose = uicontrol(...
'Parent',h,...
'Style','pushbutton',...
'String','Close',...
'tag','figspecrshowscan_pushbuttonClose',...
'Position',[p1(3)/2+10 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
% --- load the scan text
selection = scan.selectionIndex;
scanHead = cell(length(selection),1);
scanText = cell(length(selection),1);
[fid,message] = fopen(file);
for iSelection = 1:length(selection)
fseek(fid,scan.fidPos(selection(iSelection)),'bof');
scanHead{iSelection} = fgetl(fid);
scanText{iSelection} = scanHead{iSelection};
if selection(iSelection) < length(scan.fidPos) % if not the last scan
while ftell(fid) < scan.fidPos(selection(iSelection)+1)
scanText{iSelection} = [scanText{iSelection};{fgetl(fid)}];
end
else % if the last scan
while ~feof(fid)
scanText{iSelection} = [scanText{iSelection};{fgetl(fid)}];
end
end
end
setappdata(h,'scanText',scanText);
hPopupmenu1 = findobj(h,'Tag','figspecrshowscan_popupmenu1');
hEdit2 = findobj(h,'Tag','figspecrshowscan_edit2');
set(hPopupmenu1,'String',scanHead,'value',1);
set(hEdit2,'String',scanText{1},'HorizontalAlignment','left');
%================================================================
% --- callback of popupmenu1
%================================================================
function callback_popupmenu1(hObject,eventdata)
h = findall(0,'Tag','figSpecrShowScan');
hPopupmenu1 = findobj(h,'Tag','figspecrshowscan_popupmenu1');
hEdit2 = findobj(h,'Tag','figspecrshowscan_edit2');
scanText = getappdata(h,'scanText');
set(hEdit2,'String',scanText{get(hPopupmenu1,'value')});
return;
%=================================================================
% --- 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','figspecrshowscan_panel1'),'position',panelSize);
set(findobj(h,'tag','figspecrshowscan_popupmenu1'),'position',[10 panelSize(4)-40 panelSize(3)-20 20]);
set(findobj(h,'tag','figspecrshowscan_edit2'),'position',[10 10 panelSize(3)-20 panelSize(4)-60]);
set(findobj(h,'tag','figspecrshowscan_pushbuttonRefresh'),'position',[p1(3)-20-160 20 80 25]);
set(findobj(h,'tag','figspecrshowscan_pushbuttonClose'),'position',[p1(3)-10-80 20 80 25]);
catch
end