% MATLBA help on serial ports - % http://www.mathworks.com/access/helpdesk/help/toolbox/instrument/f20-38496.html function [X,H] = profilometerGUI(varargin) % allows function to be called inside another function/script to load % profilometer data if ~isempty(varargin) if length(varargin)==1 || length(varargin)==2 % import data from filename filename = cell2mat(varargin(1)); file = fopen(filename,'r'); datac = fscanf(file,'%c'); fclose(file); % organize data to be analyzed datanl = find(datac == sprintf('\n')); datanl = [1,datanl]; for k=1:length(datanl)-1 data(k) = {datac(datanl(k):datanl(k+1)-1)}; end if isempty(datac) data = {' '}; else data(end+1) = {' '}; end % verify data is either a profilometer scan or concatenated data if length(data)>3 tooShort = false; checkLine1 = cell2mat(data(1)); checkLine2 = cell2mat(data(2)); checkLine3 = cell2mat(data(3)); checkLine4 = cell2mat(data(4)); else tooShort = true; end % if .txt data is profilometer data if ~tooShort && length(checkLine1)>3 && checkLine1(4)=='/' && length(checkLine2)>5 && strcmpi(checkLine2(2:6),'VERT.') && length(checkLine3)>2 && checkLine3(3)=='L' && length(checkLine3)>2 && length(checkLine4)>2 && checkLine4(3)=='R' % scanmode (for um or nm) scanmode = cell2mat(data(2)); if find(scanmode=='u') scanmode = 1; % microns (um) Ylabel = 'height (\mum)'; app = 'um'; appval = 200; else scanmode = 1e2; % nanometers (nm) Ylabel = 'height (nm)'; app = 'nm'; appval = 2; end X = []; H = []; for n=14:length(data)-2; % range for data datac = cell2mat(data(n)); datacindx = isspace(datac); datacindx = abs(datacindx-1); X = [X;str2num(datac(1:6))]; % um or nm htemp = []; for k=12:length(datac) if datacindx(k) == 1 % if there is data (no blank space) htemp = [htemp,datac(k)]; elseif datacindx(k)==0 && ~isempty(htemp) % if there is no data (blank space) H = [H,str2num(htemp)]; % builds height data from scan htemp = []; end if k==length(datac) && datacindx(k)==1 H = [H,str2num(htemp)]; htemp = []; end end end H = H.*scanmode; X = [X(1):(X(2)-X(1))/10:((X(2)-X(1))/10)*(length(H)-1)]; % builds position from scan else disp('Specified filename does not contain profilometer data.'); end if length(varargin)==1 return end else disp('Improper number of entries into profilometerGUI.m') return end if length(varargin)==2 plotBoolean = cell2mat(varargin(2)); if plotBoolean==0 || plotBoolean==1 if plotBoolean==1 figure(1) clf plot(X,H) xlabel('position (\mum)') ylabel(Ylabel) return else return end else disp('Plot indicator must be either ''1'' or ''0''.') return end end end warning('off') % returns resolution of the computer currently in use screenDim = get(0,'screensize'); % places program in center of screen Xdim = 700; Ydim = 600; Xstart = (screenDim(3)-Xdim)/2; Ystart = (screenDim(4)-Ydim)/2; h.colorMain = [0.85 0.85 0.85]; h.colorSecondary = [0.75 0.75 0.75]; % Defines the figure size for the GUI h.fig = figure('position',[Xstart Ystart Xdim Ydim],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain,... 'DockControls','off',... 'Name','Profilometer GUI'); % Finds a list of all .txt and .TXT files crdir = pwd; crdirindx = [find(crdir == '/'),find(crdir == '\')]; crdirindx = sortrows(crdirindx); if length(crdirindx) > 0&& ~strcmpi(crdir,'\') crdir = crdir(crdirindx(end)+1:end); end listtmp = dir; listtmp = struct2cell(listtmp); listtmp = listtmp(1,1:end); list = []; for k=1:length(listtmp) foo = cell2mat(listtmp(k)); if length(foo) >= 4 ext = foo(end-3:end); if strcmpi(ext,'.txt') list = [list;{foo}]; end end end list = sortrows(list); % ensures list is alphabetical % find directories listtmp1 = struct2cell(dir); dirsindx = listtmp1(4,:); dirsindx = find(cell2mat(dirsindx) == 1); %length(dirsindx) for k=length(dirsindx):-1:1 dirname = listtmp(dirsindx(k)); dirname = ['<',cell2mat(dirname),'>']; list = [{dirname};list]; end h.list = list; % set the axes for the plot set(gca,'units','points','position',[40 130 390 292.5]); % sets location and size of plot box on % sets the menu for the program h.menuFile = uimenu(h.fig,'Label','File'); h.menuFileScan = uimenu(h.menuFile,'Label','Scan Data','Accelerator','i'); h.menuFileOpen = uimenu(h.menuFile,'Label','Open File','Accelerator','o'); h.menuFileSave = uimenu(h.menuFile,'Label','Save'); h.menuFileSaveData = uimenu(h.menuFileSave,'Label','Data','Accelerator','s'); h.menuFileSavePlot = uimenu(h.menuFileSave,'Label','Plot','Accelerator','p'); h.menuFileQuit = uimenu(h.menuFile,'Label','Quit','Accelerator','q'); h.menuEdit = uimenu(h.fig,'Label','Edit'); h.menuEditLevel = uimenu(h.menuEdit,'Label','Level','Accelerator','l'); h.menuEditZero = uimenu(h.menuEdit,'Label','Zero','Accelerator','z'); h.menuEditReset = uimenu(h.menuEdit,'Label','Reset','Accelerator','r'); h.menuAnalyze = uimenu(h.fig,'Label','Analyze'); h.menuAnalyzeConcatenate = uimenu(h.menuAnalyze,'Label','Concatenate','Accelerator','a'); h.menuHelp = uimenu(h.fig,'Label','Help'); h.menuHelpHelp = uimenu(h.menuHelp,'Label','Help Document','Accelerator','h'); h.menuHelpAbout = uimenu(h.menuHelp,'Label','About'); % Scanning push button h.frameScan = uicontrol('style','frame',... 'position',[590 485 100 70],... 'BackgroundColor',h.colorSecondary); h.buttonScan = uicontrol('style','pushbutton',... 'position',[600,520,80,25],... 'string','Scan',... 'BackgroundColor',h.colorMain); h.scanStatusFrame = uicontrol('style','frame',... 'position',[609,496,62,16]); h.scanStatus = uicontrol('style','tex',... 'position',[610,497,60,14],... 'BackgroundColor',[0.75 0.75 0.95],... 'string','idle'); % Leveling push button h.buttonLevel = uicontrol('style','pushbutton',... 'position',[600,440,80,25],... 'string','Level',... 'BackgroundColor',h.colorSecondary); % Zeroing push button h.buttonZero = uicontrol('style','pushbutton',... 'position',[600,400,80,25],... 'string','Zero',... 'BackgroundColor',h.colorSecondary); % Reset push button h.buttonReset = uicontrol('style','pushbutton',... 'position',[600,360,80,25],... 'string','Reset',... 'BackgroundColor',h.colorSecondary); % Concatenate button h.buttonConcatenate = uicontrol('style','pushbutton',... 'position',[600 320 80 25],... 'string','Concatenate',... 'BackgroundColor',h.colorSecondary); % main subframe for data h.panelMain = uicontrol('style','frame',... 'position',[95,20,440,110],... 'BackgroundColor',h.colorSecondary); h.panelLeftCursor = uicontrol('style','frame',... 'position',[100 90 210 30],... 'BackgroundColor',h.colorSecondary,... 'ForegroundColor',[0.4 0.4 0.4]); h.panelRightCursor = uicontrol('style','frame',... 'position',[319 90 210 30],... 'BackgroundColor',h.colorSecondary,... 'ForegroundColor',[0.4 0.4 0.4]); % titles for position data h.leftCursorTitle = uicontrol('style','tex',... 'position',[167,115,75,12],... 'string','Left Cursor',... 'FontWeight','bold',... 'BackgroundColor',h.colorSecondary); h.leftCursorTitle = uicontrol('style','tex',... 'position',[384,115,82,12],... 'string','Right Cursor',... 'FontWeight','bold',... 'BackgroundColor',h.colorSecondary); % left cursor x point h.showXpointl = uicontrol('style','edit',... 'position',[105,95,95,18],... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain); % left cursor y point h.showYpointl = uicontrol('style','edit',... 'position',[208,95,95,18],... 'HorizontalAlignment','left',... 'Enable','inactive',... 'BackgroundColor',h.colorMain); % right cursor x point h.showXpointr = uicontrol('style','edit',... 'position',[325,95,95,18],... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain); % right cursor y point h.showYpointr = uicontrol('style','edit',... 'position',[428,95,95,18],... 'HorizontalAlignment','left',... 'Enable','inactive',... 'BackgroundColor',h.colorMain); % x diff data h.showXdiffTitle1 = uicontrol('style','tex',... 'position',[125,60,9,14],... 'FontName','symbol',... 'string','D',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorSecondary); h.showXdiffTitle2 = uicontrol('style','tex',... 'position',[134,60,9,14],... 'string','X',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorSecondary); h.showXdiff = uicontrol('style','edit',... 'position',[146,60,80,18],... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain); h.XDiffLockBox = uicontrol('style','checkbox',... 'position',[230,62,90,14],... 'BackgroundColor',h.colorSecondary,... 'string','lock spacing'); % y diff data h.showYdiffTitle1 = uicontrol('style','tex',... 'position',[125,30,9,14],... 'FontName','symbol',... 'string','D',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorSecondary); h.showYdiffTitle2 = uicontrol('style','tex',... 'position',[134,30,9,14],... 'string','H',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorSecondary); h.showYdiff = uicontrol('style','edit',... 'position',[146,30,80,18],... 'HorizontalAlignment','left',... 'Enable','inactive',... 'BackgroundColor',h.colorMain); % Average data h.avgTitle = uicontrol('style','tex',... 'position',[345,67,50,14],... 'string','Average',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorSecondary); h.showAvg = uicontrol('style','edit',... 'position',[415,67,80,18],... 'HorizontalAlignment','left',... 'Enable','inactive',... 'BackgroundColor',h.colorMain); % Deviation data h.devTitle = uicontrol('style','tex',... 'position',[345,47,60,14],... 'string','Deviation',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorSecondary); h.showDev = uicontrol('style','edit',... 'position',[415,47,80,18],... 'HorizontalAlignment','left',... 'Enable','inactive',... 'BackgroundColor',h.colorMain); % Ra data h.raTitle = uicontrol('style','tex',... 'position',[345,27,18,14],... 'string','Ra',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorSecondary); h.showRa = uicontrol('style','edit',... 'position',[415,27,80,18],... 'HorizontalAlignment','left',... 'Enable','inactive',... 'BackgroundColor',h.colorMain); hObject = h.fig; eventdata = []; % callbacks set(h.buttonScan,'callback',{@scanData,h}); set(h.menuFileOpen,'callback',{@loadFile,h}); set(h.menuFileQuit,'callback',{@quitProgram,h}); set(h.menuFileScan,'callback',{@scanData,h}); set(h.menuHelpHelp,'callback',{@helpDoc,h}); set(h.menuHelpAbout,'callback',{@helpAbout,h}); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % causes figure to close when user presses "esc" % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function escFigure(src,evnt,hObject,eventdata,h) mainKey = evnt.Key; if strcmpi(mainKey,'escape') cancelFig(hObject,eventdata,h); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Loads the file clicked from h.listFiles % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function loadListFile(hObject,eventdata,h) val = get(h.listFiles,'value'); str = get(h.listFiles,'string'); filename = str(val); click = get(h.fig,'SelectionType'); % "normal" is left-click and "open" is double left-click if strcmpi(click,'open') % if file or directory was double-clicked [X H scanmode] = loadFile2(hObject,eventdata,h,filename); if (X+H+scanmode) ~= 0 h.lpoint = X(1); h.rpoint = X(end); h.X = X; h.H = H; h.filename = filename; h.scanmode = scanmode; plotData(hObject,eventdata,h,filename,X,H,scanmode); end end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Loads the file selected from h.listFiles % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function loadFile(hObject,eventdata,h) startPos = get(h.fig,'position'); hh.fig = figure('position',[startPos(1)+(startPos(3)-400)/2 startPos(2)+(startPos(4)-380)/2 400 380],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain,... 'Name','Load Data'); [filelist,dirlist] = loadFilesDirs(hObject,eventdata,h); h.curdir = pwd; % shows current directory % Text that displays current working directory hh.currentPath = uicontrol('style','tex',... 'position',[20 350 35 16],... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'BackgroundColor',h.colorMain,... 'string','Path:'); hh.currentDirectoryFrame = uicontrol('style','frame',... 'position',[59 349 320 18]); hh.currentDirectory = uicontrol('style','tex',... 'position',[60 350 318 16],... 'HorizontalAlignment','left',... 'BackgroundColor','white',... 'string',h.curdir); % Panel showing folders hh.showFoldersText = uicontrol('style','tex',... 'position',[20 320 180 16],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'string','Folders'); hh.listFolders = uicontrol('style','listbox',... 'position',[20 120 180 200],... 'BackgroundColor','white',... 'string',dirlist); % Panel showing files hh.showFoldersText = uicontrol('style','tex',... 'position',[220 320 160 16],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'string','Files'); hh.listFiles = uicontrol('style','listbox',... 'position',[220 120 160 200],... 'BackgroundColor','white',... 'string',filelist); % Field where user can enter a filename hh.textField = uicontrol('style','edit',... 'position',[20,60,200,24],... 'HorizontalAlignment','left',... 'BackgroundColor','white'); if isempty(filelist) set(hh.textField,'string',''); else set(hh.textField,'string',cell2mat(filelist(1))); end % Button to save filename hh.fileNameTitle = uicontrol('style','tex',... 'position',[20 90 65 14],... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain,... 'string','File Name'); hh.fileName = uicontrol('style','pushbutton',... 'position',[20,20,60,24],... 'BackgroundColor',h.colorSecondary,... 'string','load'); % Button to cancel save hh.buttonCancel = uicontrol('style','pushbutton',... 'position',[90,20,60,24],... 'BackgroundColor',h.colorSecondary,... 'string','cancel'); % set(hh.fileName,'callback',{@saveFile,h,hh,X,H,scanmode}); set(hh.fileName,'callback',{@executeListBox,h,hh}); set(hh.buttonCancel,'callback',{@cancelFig,hh}); set(hh.listFolders,'callback',{@loadListDir,hh}); set(hh.listFiles,'callback',{@executeListBox,h,hh}); set(hh.fig,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % handles single- and double-click on list boxes % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function executeListBox(hObject,eventdata,h,hh) str = get(hObject,'string'); val = get(hObject,'value'); if iscell(str(val)) % if input is a selected file and not clicked "load" button filename = str(val); set(hh.textField,'string',cell2mat(filename)); end click = get(gcbf,'SelectionType'); % "normal" is left-click, "alt" is right-click closed = false; if strcmpi(click,'open') && exist('filename') set(hh.buttonCancel,'callback',{@cancelFig,hh}); set(hh.listFolders,'callback',{@loadListDir,hh}); set(hh.listFiles,'callback',{@executeListBox,h,hh}); set(hh.fig,'Visible','off'); loadData(hObject,eventdata,h,filename); closed = true; elseif ~exist('filename') set(hh.buttonCancel,'callback',{@cancelFig,hh}); set(hh.listFolders,'callback',{@loadListDir,hh}); set(hh.listFiles,'callback',{@executeListBox,h,hh}); filename = get(hh.textField,'string'); set(hh.fig,'Visible','off'); loadData(hObject,eventdata,h,{filename}); closed = true; end if ~closed guidata(hObject,hh); set(hh.buttonCancel,'callback',{@cancelFig,hh}); set(hh.listFolders,'callback',{@loadListDir,hh}); set(hh.listFiles,'callback',{@executeListBox,h,hh}); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % handles single- and double-click on list boxes % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function executeListBoxSave(hObject,eventdata,h,hh) str = get(hObject,'string'); val = get(hObject,'value'); filename = str(val); filenamestr = cell2mat(filename); filenamestr = filenamestr(1:end-4); set(hh.textField,'string',filenamestr); click = get(gcbf,'SelectionType'); % "normal" is left-click, "alt" is right-click closed = false; if strcmpi(click,'open') set(hh.buttonCancel,'callback',{@cancelFig,hh}); set(hh.listFolders,'callback',{@loadListDir,hh}); set(hh.listFiles,'callback',{@executeListBoxSave,h,hh}); X = h.X; H = h.H; scanmode = h.scanmode; h.filename = filename; filext = cell2mat(filename); filext = filext(end-2:end); if strcmpi(filext,'txt') saveFile(hObject,eventdata,h,hh,X,H,scanmode); else saveImageFile(hObject,eventdata,h,hh,X,H,scanmode); end closed = true; end if ~closed guidata(hObject,hh); set(hh.buttonCancel,'callback',{@cancelFig,hh}); set(hh.listFolders,'callback',{@loadListDir,hh}); set(hh.listFiles,'callback',{@executeListBoxSave,h,hh}); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % handles single- and double-click on list boxes % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function executeListBoxSaveConcat(hObject,eventdata,h,hh) str = get(hObject,'string'); val = get(hObject,'value'); filename = str(val); filenamestr = cell2mat(filename); filenamestr = filenamestr(1:end-4); set(hh.textField,'string',filenamestr); click = get(gcbf,'SelectionType'); % "normal" is left-click, "alt" is right-click closed = false; if strcmpi(click,'open') set(hh.buttonCancel,'callback',{@cancelFig,hh}); set(hh.listFolders,'callback',{@loadListDir,hh}); set(hh.listFiles,'callback',{@executeListBoxSaveConcat,h,hh}); X = h.X; H = h.H; scanmode = h.scanmode; h.filename = filename; filext = cell2mat(filename); filext = filext(end-2:end); saveConcatenateFile(hObject,eventdata,h,hh,X,H,scanmode); closed = true; end if ~closed guidata(hObject,hh); set(hh.buttonCancel,'callback',{@cancelFig,hh}); set(hh.listFolders,'callback',{@loadListDir,hh}); set(hh.listFiles,'callback',{@executeListBoxSaveConcat,h,hh}); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Loads data from selected file in loadFile % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function loadData(hObject,eventdata,h,filename) % uncheck "lock spacing" box set(h.XDiffLockBox,'value',0); file = fopen(cell2mat(filename),'r'); datac = fscanf(file,'%c'); fclose(file); % organize data to be analyzed datanl = find(datac == sprintf('\n')); datanl = [1,datanl]; for k=1:length(datanl)-1 data(k) = {datac(datanl(k):datanl(k+1)-1)}; end if isempty(datac) data = {' '}; else data(end+1) = {' '}; end % verify data is either a profilometer scan or concatenated data if length(data)>3 tooShort = false; checkLine1 = cell2mat(data(1)); checkLine2 = cell2mat(data(2)); checkLine3 = cell2mat(data(3)); checkLine4 = cell2mat(data(4)); else tooShort = true; end % if .txt data is profilometer data if ~tooShort && length(checkLine1)>3 && checkLine1(4)=='/' && length(checkLine2)>5 && strcmpi(checkLine2(2:6),'VERT.') && length(checkLine3)>2 && checkLine3(3)=='L' && length(checkLine3)>2 && length(checkLine4)>2 && checkLine4(3)=='R' % scanmode (for um or nm) scanmode = cell2mat(data(2)); if find(scanmode=='u') scanmode = 1; % microns (um) ylabel('height (\mum)'); app = 'um'; appval = 200; else scanmode = 1e2; % nanometers (nm) ylabel('height (nm)'); app = 'nm'; appval = 2; end X = []; H = []; for n=14:length(data)-2; % range for data datac = cell2mat(data(n)); datacindx = isspace(datac); datacindx = abs(datacindx-1); X = [X;str2num(datac(1:6))]; % um or nm htemp = []; for k=12:length(datac) if datacindx(k) == 1 % if there is data (no blank space) htemp = [htemp,datac(k)]; elseif datacindx(k)==0 && ~isempty(htemp) % if there is no data (blank space) H = [H,str2num(htemp)]; % builds height data from scan htemp = []; end if k==length(datac) && datacindx(k)==1 H = [H,str2num(htemp)]; htemp = []; end end end H = H.*scanmode; X = [X(1):(X(2)-X(1))/10:((X(2)-X(1))/10)*(length(H)-1)]; % builds position from scan h.H = H; h.X = X; h.scanmode = scanmode; h.filename = filename; h.lpoint = X(1); h.rpoint = X(end); % set values to be restored when user clicks "reset" h.fileReset = filename; h.XReset = X; h.HReset = H; h.scanmodeReset = scanmode; plotData(hObject,eventdata,h,filename,X,H,scanmode); % if .txt is concatenated data elseif ~tooShort && length(checkLine1)>34 && strcmpi(checkLine1(1:35),'***********************************') && strcmpi(checkLine2(2:31),'Concatenated Profilometer Data') && strcmpi(checkLine4(2:36),'***********************************') % find the spacing between sets tempVal = cell2mat(data(6)); tempSpc = isspace(tempVal(21:end)); tempIndx = find(tempSpc == 1); dX = str2num(tempVal(21:20+tempIndx(1))); % spacing between sets (um) % find the units used (whether um or nm) tempVal = cell2mat(data(7)); units = tempVal(10:11); % units used (um or nm) % sets scanmode if strcmpi(units,'nm') scanmode = 1000; elseif strcmpi(units,'um') scanmode = 1; end % load set numbers, left horizontal position, right horizontal % position, height difference, average height, height deviation, and % surface roughness k = 12; lineVal = cell2mat(data(k)); setNum = []; HL = []; HR = []; Hdiff = []; Havg = []; Hstd = []; HRa = []; while length(lineVal)>1 setNum = [setNum,str2num(lineVal(2:9))]; HL = [HL,str2num(lineVal(10:17))]; HR = [HR,str2num(lineVal(18:25))]; Hdiff = [Hdiff,str2num(lineVal(26:33))]; Havg = [Havg,str2num(lineVal(34:41))]; Hstd = [Hstd,str2num(lineVal(42:49))]; HRa = [HRa,str2num(lineVal(50:57))]; k = k+1; lineVal = cell2mat(data(k)); end startXH = k+6; % loads X and H X = []; H = []; for k=1:length(setNum) n = startXH; lineVal = cell2mat(data(n)); startIndxX = 2+16*(k-1); startIndxH = 10+16*(k-1); lineValX = str2num(lineVal(startIndxX:startIndxX+7)); lineValH = str2num(lineVal(startIndxH:startIndxH+7)); Xtemp = []; while ~isempty(lineValH) Xtemp = [Xtemp,lineValX]; H = [H,lineValH]; n = n+1; if n>length(data)-1 lineValX = ''; lineValH = ''; else lineVal = cell2mat(data(n)); lineValX = str2num(lineVal(startIndxX:startIndxX+7)); lineValH = str2num(lineVal(startIndxH:startIndxH+7)); end end Xtemp = Xtemp - min(Xtemp); % includes spacing between sets to correctly set X if isempty(X) X = [X,Xtemp]; else X = [X,Xtemp + X(end) + dX]; end end % fix this later? h.Xalt = [0:1:length(Hdiff)-1]; if dX > 0 % creates X array for statistical data (Hdiff, Havg, etc.) Xalt = [0:dX:dX*(length(Hdiff)-1)]; h.Xalt = Xalt; end h.setNum = setNum; h.HL = HL; h.HR = HR; h.Hdiff = Hdiff; h.Havg = Havg; h.Hstd = Hstd; h.Hra = HRa; % set initial points for left and right bars h.lpoint = X(1); h.rpoint = X(end); startPos = get(h.fig,'position'); hh.figSelectParameters = figure('position',[startPos(1)+(startPos(3)-200)/2 startPos(2)+(startPos(4)-170)/2 200 170],... 'menubar','none',... 'numbertitle','off',... 'Color',h.colorMain,... 'Name','Select Parameters'); hh.selectParamText = uicontrol('style','tex',... 'position',[20 150 160 14],... 'BackgroundColor',h.colorMain,... 'FontWeight','bold',... 'HorizontalAlignment','center',... 'string','Select parameters to plot'); hh.checkboxHL = uicontrol('style','checkbox',... 'position',[30 120 60 14],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'string','Hl'); hh.checkboxHR = uicontrol('style','checkbox',... 'position',[30 100 60 14],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'string','Hr'); hh.checkboxHdiff = uicontrol('style','checkbox',... 'position',[30 80 60 14],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'string','Hdiff'); hh.checkboxHavg = uicontrol('style','checkbox',... 'position',[100 120 60 14],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'string','Havg'); hh.checkboxHdev = uicontrol('style','checkbox',... 'position',[100 100 60 14],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'string','Hdev'); hh.checkboxRa = uicontrol('style','checkbox',... 'position',[100 80 60 14],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'string','Ra'); hh.checkboxH = uicontrol('style','checkbox',... 'position',[30 60 60 14],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'string','H'); hh.paramPlotButton = uicontrol('style','pushbutton',... 'position',[100 20 70 25],... 'BackgroundColor',h.colorSecondary,... 'string','plot data'); hh.paramCancelButton = uicontrol('style','pushbutton',... 'position',[20 20 70 25],... 'BackgroundColor',h.colorSecondary,... 'string','cancel'); h.plotHl = false; h.plotHr = false; h.plotHdiff = false; h.plotHavg = false; h.plotHdev = false; h.plotRa = false; h.plotH = false; set(hh.paramCancelButton,'callback',{@cancelFig,hh}); set(hh.checkboxHL,'callback',{@paramHl,h,hh,filename,X,H,scanmode}); set(hh.checkboxHR,'callback',{@paramHr,h,hh,filename,X,H,scanmode}); set(hh.checkboxHdiff,'callback',{@paramHdiff,h,hh,filename,X,H,scanmode}); set(hh.checkboxHavg,'callback',{@paramHavg,h,hh,filename,X,H,scanmode}); set(hh.checkboxHdev,'callback',{@paramHavg,h,hh,filename,X,H,scanmode}); set(hh.checkboxRa,'callback',{@paramHavg,h,hh,filename,X,H,scanmode}); set(hh.checkboxH,'callback',{@paramH,h,hh,filename,X,H,scanmode}); set(hh.figSelectParameters,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); % if this is not a recognized .txt file else startPos = get(h.fig,'position'); hh.fig = figure('position',[startPos(1)+(startPos(3)-200)/2 startPos(2)+(startPos(4)-100)/2 200 100],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain,... 'Name','Invalid File'); hh.badTxtText = uicontrol('style','tex',... 'position',[10,10,180,80],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','center',... 'string','File does not contain profilometer scan data or concatenated data'); hh.badTxtPushbutton = uicontrol('style','pushbutton',... 'position',[65 10 70 25],... 'BackgroundColor',h.colorSecondary,... 'string','OK'); set(hh.badTxtPushbutton,'callback',{@cancelFig,hh}); set(hh.fig,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Loads the directory clicked from listbox % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function loadListDir(hObject,eventdata,h) val = get(hObject,'value'); str = get(hObject,'string'); dirname = str(val); click = get(h.fig,'SelectionType'); % "normal" is left-click and "open" is double left-click if strcmpi(click,'open') % if directory was double-clicked dirname = cell2mat(dirname); cd(dirname); [filelist,dirlist] = loadFilesDirs(hObject,eventdata,h); crdir = pwd; if ~isempty(filelist) svldmode = get(h.fig,'Name'); if strcmpi(svldmode,'Save Data') % for save data removes .txt filename = cell2mat(filelist(1)); filename = filename(1:end-4); set(h.textField,'string',filename); else % includes .txt for load mode set(h.textField,'string',cell2mat(filelist(1))); end end set(h.currentDirectory,'string',crdir); set(h.listFolders,'Value',1) set(h.listFolders,'string',dirlist); set(h.listFiles,'Value',1); set(h.listFiles,'string',filelist); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Loads the directory clicked from listbox % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function loadImageListDir(hObject,eventdata,h) val = get(hObject,'value'); str = get(hObject,'string'); dirname = str(val); click = get(h.fig,'SelectionType'); % "normal" is left-click and "open" is double left-click if strcmpi(click,'open') % if directory was double-clicked dirname = cell2mat(dirname); cd(dirname); [filelist,dirlist] = loadImageFilesDirs(hObject,eventdata,h); crdir = pwd; if ~isempty(filelist) svldmode = get(h.fig,'Name'); if strcmpi(svldmode,'Save Data') % for save data removes .txt filename = cell2mat(filelist(1)); filename = filename(1:end-4); set(h.textField,'string',filename); else % includes .txt for load mode set(h.textField,'string',cell2mat(filelist(1))); end end set(h.currentDirectory,'string',crdir); set(h.listFolders,'Value',1) set(h.listFolders,'string',dirlist); set(h.listFiles,'Value',1); set(h.listFiles,'string',filelist); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % load local files and directories % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [filelist,dirlist] = loadFilesDirs(hObject,eventdata,h) listtmp = dir; listtmp = struct2cell(listtmp); listtmp = listtmp(1,1:end); crdir = pwd; % finds files % Finds a list of all .txt and .TXT files filelist = []; for k=1:length(listtmp) foo = cell2mat(listtmp(k)); if length(foo) >= 4 ext = foo(end-3:end); if strcmpi(ext,'.txt') filelist = [filelist;{foo}]; end end end filelist = sortrows(filelist); % ensures list is alphabetical % find directories listtmp1 = struct2cell(dir); dirsindx = listtmp1(4,:); dirsindx = find(cell2mat(dirsindx) == 1); dirlist = []; %length(dirsindx) for k=length(dirsindx):-1:1 dirname = listtmp(dirsindx(k)); dirlist = [dirname,dirlist]; end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % load local image files and directories % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [filelist,dirlist] = loadImageFilesDirs(hObject,eventdata,h) listtmp = dir; listtmp = struct2cell(listtmp); listtmp = listtmp(1,1:end); crdir = pwd; % finds files % Finds a list of all .txt and .TXT files filelist = []; for k=1:length(listtmp) foo = cell2mat(listtmp(k)); if length(foo) >= 4 ext = foo(end-3:end); if strcmpi(ext,'.jpg') || strcmpi(ext,'.png') || strcmpi(ext,'.tif') || strcmpi(ext,'.eps') || strcmpi(ext,'.pdf') || strcmpi(ext,'.fig') filelist = [filelist;{foo}]; end end end filelist = sortrows(filelist); % ensures list is alphabetical % find directories listtmp1 = struct2cell(dir); dirsindx = listtmp1(4,:); dirsindx = find(cell2mat(dirsindx) == 1); dirlist = []; %length(dirsindx) for k=length(dirsindx):-1:1 dirname = listtmp(dirsindx(k)); dirlist = [dirname,dirlist]; end guidata(hObject,h); %%%%%%%%%%%%%%%%%% % plots the data % %%%%%%%%%%%%%%%%%% function plotData(hObject,eventdata,h,filename,X,H,scanmode) % means the data to be plotted is concatenated data if isfield(h,'plotHl') if h.plotHl H = h.HL; X = h.Xalt; elseif h.plotHr H = h.HR; X = h.Xalt; elseif h.plotHdiff H = h.Hdiff; X = h.Xalt; elseif h.plotHavg H = h.Havg; X = h.Xalt; elseif h.plotHdev && ~h.plotHavg H = h.Hstd; X = h.Xalt; elseif h.plotRa H = h.Hra; X = h.Xalt; end cancelFig(hObject,eventdata,h); end figure(h.fig); xl = h.lpoint; % left bar xr = h.rpoint; % right bar h.indxl = find(X == xl); h.indxr = find(X == xr); h.X = X; % stores X value h.H = H; % stores Y value h.filename = filename; % stores filename h.scanmode = scanmode; % stores scanmode % scanmode if scanmode == 1 ylabel('height (\mum)') app = 'um'; appval = 200; else ylabel('height (nm)') app = 'nm'; appval = 2; end % plots the current figure along with vertical line cla padAxis = false; if isfield(h,'plotHl') && h.plotHavg && h.plotHdev && ~h.plotRa h.plot = errorbar(X,H,h.Hstd,'ob'); padAxis = true; elseif isfield(h,'plotHl') && h.plotHavg && h.plotRa && ~h.plotHdev h.plot = errorbar(X,H,h.Hra,'ob'); padAxis = true; elseif isfield(h,'plotHl') && h.plotHavg && h.plotHdev && h.plotRa hold on h.plot = errorbar(X,H,h.Hra,'or'); h.plot = errorbar(X,H,h.Hstd,'ob'); hold off legend('R_a','\sigma','location','Best'); legend boxoff; padAxis = true; else h.plot = plot(X,H,'LineWidth',1,'Color','b'); end ylim = get(gca,'YLim'); if min(H) > 0 && ~padAxis axis([min(X),max(X),0,ylim(2)]); elseif min(H) > 0 && padAxis % adds padding for errorbar data axis([min(X) - 0.1*max(X),max(X) + 0.1*max(X),0,ylim(2)]); elseif min(H) < 0 && padAxis % adds padding for errorbar data axis([min(X) - 0.1*max(X),max(X) + 0.1*max(X),ylim(1),ylim(2)]); else axis([min(X),max(X),ylim(1),ylim(2)]); end set(h.plot,'HitTest','off'); set(gca,'ButtonDownFcn',{@clickFigure,h,X,H,filename,scanmode}) title(filename,'FontWeight','bold','Interpreter','none','FontSize',11) xlabel('position (\mum)','FontSize',11) ylabel(['height (',app,')'],'FontSize',11) hpoints = get(gca,'YLim'); h.linel = line([xl xl],[hpoints(1) hpoints(2)],'Color','black','LineStyle','--'); h.liner = line([xr xr],[hpoints(1) hpoints(2)],'Color','black','LineStyle','--'); box on % bar position data set(h.showXpointl,'string',['x = ',num2str(X(h.indxl)),' um']); set(h.showYpointl,'string',['h = ',num2str(H(h.indxl)),' ',app]); set(h.showXpointr,'string',['x = ',num2str(X(h.indxr)),' um']); set(h.showYpointr,'string',['h = ',num2str(H(h.indxr)),' ',app]); % x diff and y diff data xDiff = abs(X(h.indxr) - X(h.indxl)); yDiff = H(h.indxr) - H(h.indxl); set(h.showXdiff,'string',[num2str(xDiff),' um']); set(h.showYdiff,'string',[num2str(yDiff),' ',app]); if h.indxr < h.indxl foo = h.indxl; h.indxl = h.indxr; h.indxr = foo; end % Ra data Ra = abs(H(h.indxl) - mean(H(h.indxl:h.indxr))); Ra = round(Ra*appval)/appval; set(h.showRa,'string',[num2str(Ra),' ',app]); h.Ra = Ra; % average data Havg = mean(H(h.indxl:h.indxr)); Havg = round(Havg*appval)/appval; set(h.showAvg,'string',[num2str(Havg),' ',app]); h.Havg = Havg; % deviation data Hstd = std(H(h.indxl:h.indxr)); Hstd = round(Hstd*appval)/appval; set(h.showDev,'string',[num2str(Hstd),' ',app]); h.Hstd = Hstd; % sets callback for level button set(h.buttonLevel,'callback',{@levelData,h,X,H,filename,scanmode}); % sets callback for zero button set(h.buttonZero,'callback',{@zeroData,h,X,H,filename,scanmode}); % sets callback for save button set(h.buttonReset,'callback',{@resetData,h,filename}); % sets callback for lock spacing check box set(h.XDiffLockBox,'callback',{@lockSpacing,h}); % sets callback for the concatenate button set(h.buttonConcatenate,'callback',{@concatenateMenu,h,X,H,filename,scanmode}); % sets callback for user-entered position for left bar set(h.showXpointl,'callback',{@setLeftCursorX,h,X,H,filename,scanmode}); % sets callback for user-entered position for right bar set(h.showXpointr,'callback',{@setRightCursorX,h,X,H,filename,scanmode}); % sets callback for user-entered xdiff data set(h.showXdiff,'callback',{@setXDiff,h,X,H,filename,scanmode}); set(h.menuEditLevel,'callback',{@levelData,h,X,H,filename,scanmode}); set(h.menuEditZero,'callback',{@zeroData,h,X,H,filename,scanmode}); set(h.menuEditReset,'callback',{@resetData,h,filename}); set(h.menuAnalyzeConcatenate,'callback',{@concatenateMenu,h,X,H,filename,scanmode}); set(h.menuFileSaveData,'callback',{@saveData,h,X,H,filename,scanmode}); set(h.menuFileSavePlot,'callback',{@savePlot,h}); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % When the figure is clicked % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function clickFigure(hObject,eventdata,h,X,H,filename,scanmode) h.clickdata = get(gca,'Currentpoint'); click = get(gcbf,'SelectionType'); % "normal" is left-click, "alt" is right-click xsel=h.clickdata(1,1); % selected x point ysel=h.clickdata(1,2); % selected y point % Finds closest x and h point corresponding to clicked point xtemp = abs(xsel - X); xtempindx = find(xtemp == min(xtemp)); xsel = X(xtempindx); ysel = H(xtempindx); % Shows the currently selected x point if strcmpi(click,'normal') || strcmpi(click,'open') % left-click set(h.showXpointl,'string',['x = ',num2str(xsel),' um']) h.lpoint = xsel; if get(h.XDiffLockBox,'value')==1 && (h.lpoint+h.Xdiff)<=X(end) % if "lock spacing" is checked h.rpoint = h.lpoint + h.Xdiff; tmp = abs(X-h.rpoint); tmpIndx = find(tmp == min(tmp)); h.rpoint = X(tmpIndx); elseif get(h.XDiffLockBox,'value')==1 && (h.lpoint+X(h.Xspacing))>X(end) h.rpoint = X(end); end else % right-click set(h.showXpointr,'string',['x = ',num2str(xsel),' um']) h.rpoint = xsel; if get(h.XDiffLockBox,'value')==1 && (h.rpoint-X(h.Xspacing))>=X(1) % if "lock spacing" is checked h.lpoint = h.rpoint - X(h.Xspacing); tmp = abs(X-h.lpoint); tmpIndx = find(tmp == min(tmp)); h.lpoint = X(tmpIndx); elseif get(h.XDiffLockBox,'value')==1 && (h.rpoint-X(h.Xspacing)) h.rpoint foo = h.lpoint; h.lpoint = h.rpoint; h.rpoint = foo; end h.Xspacing = abs(h.indxr - h.indxl) + 1; h.Xdiff = abs(h.X(h.indxr) - h.X(h.indxl)); plotData(hObject,eventdata,h,h.filename,h.X,h.H,h.scanmode); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Resets the current plot to the original values % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function resetData(hObject,eventdata,h,filename) % creates left and right bars xl = h.lpoint; xr = h.rpoint; %filename = get(h.fileReset,'string'); scanmode = h.scanmodeReset; X = h.XReset; H = h.HReset; % keeps left and right bars in the same spot after resetting the plot set(h.showXpointl,'string',xl); set(h.showXpointr,'string',xr); h.H = H; h.X = X; plotData(hObject,eventdata,h,filename,X,H,scanmode); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Allows user to directly enter XL value % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function setLeftCursorX(hObject,eventdata,h,X,H,filename,scanmode) dX = X(2) - X(1); % if 1 "lock spacing" box is checked, if 0 "lock spacing" box is unchecked lockTrue = get(h.XDiffLockBox,'value'); inputString = get(hObject,'string'); inputIndx = []; for k=1:length(inputString) if inputString(k)=='-' || inputString(k)=='0' || inputString(k)=='1' || inputString(k)=='2' || inputString(k)=='3' || inputString(k)=='4' || inputString(k)=='5' || inputString(k)=='6' || inputString(k)=='7' || inputString(k)=='8' || inputString(k)=='9' || inputString(k)=='.' inputIndx(k) = 1; else inputIndx(k) = 0; end end inputValue = []; startVal = false; for k=1:length(inputIndx) if inputIndx(k) inputValue = [inputValue,inputString(k)]; startVal = true; elseif ~inputIndx(k) && startVal break end end if isempty(inputValue) || strcmpi(inputValue,'-') || str2num(inputValue)<0 inputValue = '0'; elseif str2num(inputValue)>X(end) inputValue = num2str(X(end)); end inputValue = str2num(inputValue); inputValue = (round(inputValue/dX))*dX; h.lpoint = inputValue; if lockTrue lockSpacing(hObject,eventdata,h); else plotData(hObject,eventdata,h,filename,X,H,scanmode); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Allows user to directly enter XR value % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function setRightCursorX(hObject,eventdata,h,X,H,filename,scanmode) dX = X(2) - X(1); % if 1 "lock spacing" box is checked, if 0 "lock spacing" box is unchecked lockTrue = get(h.XDiffLockBox,'value'); inputString = get(hObject,'string'); inputIndx = []; for k=1:length(inputString) if inputString(k)=='-' || inputString(k)=='0' || inputString(k)=='1' || inputString(k)=='2' || inputString(k)=='3' || inputString(k)=='4' || inputString(k)=='5' || inputString(k)=='6' || inputString(k)=='7' || inputString(k)=='8' || inputString(k)=='9' || inputString(k)=='.' inputIndx(k) = 1; else inputIndx(k) = 0; end end inputValue = []; startVal = false; for k=1:length(inputIndx) if inputIndx(k) inputValue = [inputValue,inputString(k)]; startVal = true; elseif ~inputIndx(k) && startVal break end end if isempty(inputValue) || strcmpi(inputValue,'-') || str2num(inputValue)<0 inputValue = '0'; elseif str2num(inputValue)>X(end) inputValue = num2str(X(end)); end inputValue = str2num(inputValue); inputValue = (round(inputValue/dX))*dX; h.rpoint = inputValue; if lockTrue lockSpacing(hObject,eventdata,h); else plotData(hObject,eventdata,h,filename,X,H,scanmode); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Allows user to directly enter xdiff value % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function setXDiff(hObject,eventdata,h,X,H,filename,scanmode) dX = X(2) - X(1); % if 1 "lock spacing" box is checked, if 0 "lock spacing" box is unchecked lockTrue = get(h.XDiffLockBox,'value'); inputString = get(hObject,'string'); inputIndx = []; for k=1:length(inputString) if inputString(k)=='-' || inputString(k)=='0' || inputString(k)=='1' || inputString(k)=='2' || inputString(k)=='3' || inputString(k)=='4' || inputString(k)=='5' || inputString(k)=='6' || inputString(k)=='7' || inputString(k)=='8' || inputString(k)=='9' inputIndx(k) = 1; else inputIndx(k) = 0; end end inputValue = []; startVal = false; for k=1:length(inputIndx) if inputIndx(k) inputValue = [inputValue,inputString(k)]; startVal = true; elseif ~inputIndx(k) && startVal break end end if isempty(inputValue) || strcmpi(inputValue,'-') || str2num(inputValue)<0 inputValue = '0'; elseif str2num(inputValue)>X(end) inputValue = num2str(X(end)); end inputValue = str2num(inputValue); inputValue = round(inputValue/10)*10; if (h.lpoint + inputValue)>X(end) h.rpoint = X(end); else h.rpoint = h.lpoint + inputValue; end if lockTrue lockSpacing(hObject,eventdata,h); else plotData(hObject,eventdata,h,filename,X,H,scanmode); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Levels the data by the left and right bars % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function levelData(hObject,eventdata,h,X,H,filename,scanmode) % creates left and right bars xl = h.lpoint; xr = h.rpoint; indx(1) = find(xl == X); indx(2) = find(xr == X); pfit = polyfit(X(indx),H(indx),1); pfit = polyval(pfit,X); if scanmode == 1 appval = 200; ylabel('height (\mum)') app = 'um'; else appval = 2; ylabel('height (nm)') app = 'nm'; end H = H - pfit; H = round(H*appval)./appval; h.H = H; h.X = X; plotData(hObject,eventdata,h,filename,X,H,scanmode); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Makes the point of the left bar zero % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function zeroData(hObject,eventdata,h,X,H,filename,scanmode) % creates left and right bars xl = h.lpoint; xr = h.rpoint; indxl = find(xl == X); indxr = find(xr == X); H = H - H(indxl); % scan mode if scanmode == 1 ylabel('height (\mum)') app = 'um'; appval = 200; else ylabel('height (nm)') app = 'nm'; appval = 2; end h.H = H; h.X = X; plotData(hObject,eventdata,h,filename,X,H,scanmode); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % scans in data from the profilometer % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function scanData(hObject,eventdata,h) % selects the appropriate serial port depending on the computer % architecture compType = computer; if strcmpi(compType,'GLNX86') || strcmpi(compType,'GLNXI64') || strcmpi(compType,'HPUX') % if Linux or Unix port = '/dev/ttyS0'; elseif strcmpi(compType,'SOL2') % if Solaris port = '/dev/term/a'; elseif strcmpi(compType,'MAC') % if Mac OS X port = '/dev/tty.KeySerial1'; elseif strcmpi(compType,'PCWIN') % if Microsoft Windows port = 'COM1'; end status = get(h.scanStatus,'string'); if strcmpi(status,'waiting'); % cancels active scan % closes serial port and returns resources fclose(h.serialOne); delete(h.serialOne); clear h.serialOne; set(h.scanStatus,'BackgroundColor',[0.75 0.75 0.95]); set(h.scanStatus,'string','idle'); else set(h.scanStatus,'BackgroundColor',[1 1 0]); set(h.scanStatus,'string','waiting'); % creates serial port object h.serialOne = serial(port,'BaudRate',38400,'Terminator','CR','Timeout',1); set(h.menuFileQuit,'callback',{@quitProgram,h}); set(h.buttonScan,'callback',{@scanData,h}); %h.serialOne.ReadAsyncMode = 'manual'; s.BytesAvailableFcnCount = 40; h.serialOne.BytesAvailableFcnMode = 'byte'; h.serialOne.BytesAvailableFcn = {@scanDataRead,h}; % opens serial port fopen(h.serialOne); %fprintf(h.serialOne,'*IDN?') % queries identification of device end set(h.menuFileQuit,'callback',{@quitProgram,h}); set(h.buttonScan,'callback',{@scanData,h}); set(h.menuFileScan,'callback',{@scanData,h}); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % scans in data from the profilometer % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function scanDataRead(hObject,eventdata,h) set(h.scanStatus,'BackgroundColor',[0 1 0]); set(h.scanStatus,'string','active'); % disables scan button while data is being read in set(h.buttonScan,'Enable','off'); % creates a delay to allow time for the changes above to take place pause(0.1); b1 = 0; while 1 b2 = h.serialOne.BytesAvailable; % stores value of currently available bytes if h.serialOne.BytesAvailable == 0 && exist('data') && (b1+b2)==0 % once all data is scanned break else temp = fscanf(h.serialOne,'%c'); % scan data from serial port if ~isempty(temp) && exist('data') disp(temp) data = [data;temp]; elseif ~isempty(temp) && ~exist('data') disp(temp) data = {temp}; end end b1 = b2; % stores last data stream to see if two adjacent data streams are empty (means data scan is done) end fclose(h.serialOne); delete(h.serialOne); clear h.serialOne; set(h.scanStatus,'BackgroundColor',[0.75 0.75 0.95]); set(h.scanStatus,'string','idle'); set(h.buttonScan,'Enable','on'); scanmode = cell2mat(data(2)); if find(scanmode=='u') scanmode = 1; % microns (um) else scanmode = 1e2; % nanometers (nm) end X = []; H = []; for n=14:length(data)-2; % range for data datac = cell2mat(data(n)); datacindx = isspace(datac); datacindx = abs(datacindx-1); X = [X;str2num(datac(1:6))]; % um or nm htemp = []; for k=12:length(datac) if datacindx(k) == 1 % if there is data (no blank space) htemp = [htemp,datac(k)]; elseif abs((datacindx(k) - datacindx(k-1))) == 1 % if there is no data (blank space) H = [H,str2num(htemp)]; % builds height data from scan htemp = []; end end end H = H.*scanmode; X = [X(1):(X(2)-X(1))/10:((X(2)-X(1))/10)*(length(H)-1)]; % builds position from scan filename = {'[SCANNED DATA]'}; h.lpoint = X(1); h.rpoint = X(end); h.XReset = X; h.HReset = H; h.scanmodeReset = scanmode; % arbitrarily reassign hObject since it has been closed (the serial port) hObject = h.scanStatus; plotData(hObject,eventdata,h,filename,X,H,scanmode) set(h.menuFileQuit,'callback',{@quitProgram,h}); set(h.buttonScan,'callback',{@scanData,h}); set(h.menuFileScan,'callback',{@scanData,h}); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Saves current plotted data to specified file % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function saveData(hObject,eventdata,h,X,H,filename,scanmode) if length(filename)==3 % saving concatenated data concatenateSave = true; imageSave = false; figureTitle = 'Save Data'; filename = filename(1); [filelist,dirlist] = loadFilesDirs(hObject,eventdata,h); elseif length(filename)==2 % saving plot as an image imageSave = true; concatenateSave = false; figureTitle = 'Save Plot'; filename = filename(1); [filelist,dirlist] = loadImageFilesDirs(hObject,eventdata,h); else % saving data as a text file imageSave = false; concatenateSave = false; figureTitle = 'Save Data'; [filelist,dirlist] = loadFilesDirs(hObject,eventdata,h); end if isfield(h,'fig') startPos = get(h.fig,'position'); else startPos = h.startPos; end hh.fig = figure('position',[startPos(1)+(startPos(3)-400)/2 startPos(2)+(startPos(4)-380)/2 400 380],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain,... 'Name',figureTitle); filename = cell2mat(filename); filename = filename(1:end-4); h.curdir = pwd; % shows current directory % Text that displays current working directory hh.currentPath = uicontrol('style','tex',... 'position',[20 350 35 16],... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'BackgroundColor',h.colorMain,... 'string','Path:'); hh.currentDirectoryFrame = uicontrol('style','frame',... 'position',[59 349 320 18]); hh.currentDirectory = uicontrol('style','tex',... 'position',[60 350 318 16],... 'HorizontalAlignment','left',... 'BackgroundColor','white',... 'string',h.curdir); % Panel showing folders hh.saveShowFoldersText = uicontrol('style','tex',... 'position',[20 320 180 16],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'string','Folders'); hh.listFolders = uicontrol('style','listbox',... 'position',[20 120 180 200],... 'BackgroundColor','white',... 'string',dirlist); % Panel showing files hh.showFoldersText = uicontrol('style','tex',... 'position',[220 320 160 16],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'string','Files'); hh.listFiles = uicontrol('style','listbox',... 'position',[220 120 160 200],... 'BackgroundColor','white',... 'string',filelist); if ~isempty(filelist) topFile = cell2mat(filelist(1)); topFile = topFile(1:end-4); else topFile = ''; end % Field where user can enter a filename hh.textField = uicontrol('style','edit',... 'position',[20,60,200,24],... 'HorizontalAlignment','left',... 'BackgroundColor','white',... 'string',topFile); % Button to save filename hh.fileNameTitle = uicontrol('style','tex',... 'position',[20 90 65 14],... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain,... 'string','File Name'); hh.fileNameTitle2 = uicontrol('style','tex',... 'position',[85 90 200 14],... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain,... 'string','(don''t include file extension)'); hh.fileName = uicontrol('style','pushbutton',... 'position',[20,20,60,24],... 'BackgroundColor',h.colorSecondary,... 'string','save'); % Button to cancel save hh.buttonCancel = uicontrol('style','pushbutton',... 'position',[90,20,60,24],... 'BackgroundColor',h.colorSecondary,... 'string','cancel'); set(hh.listFiles,'callback',{@executeListBoxSave,h,hh}); set(hh.buttonCancel,'callback',{@cancelFig,hh}); set(hh.fig,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); if concatenateSave % saving concatenation data' set(hh.listFiles,'callback',{@executeListBoxSaveConcat,h,hh}); set(hh.fileName,'callback',{@saveConcatenateFile,h,hh,X,H,scanmode}); set(hh.listFolders,'callback',{@loadListDir,hh}); elseif imageSave % saving an image set(hh.listFiles,'callback',{@executeListBoxSave,h,hh}); set(hh.fileName,'callback',{@saveImageFile,h,hh,X,H,scanmode}); set(hh.listFolders,'callback',{@loadImageListDir,hh}); else % saving profilometer data set(hh.listFiles,'callback',{@executeListBoxSave,h,hh}); set(hh.fileName,'callback',{@saveFile,h,hh,X,H,scanmode}); set(hh.listFolders,'callback',{@loadListDir,hh}); end % reload callbacks guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%% % Saves seleced filename % %%%%%%%%%%%%%%%%%%%%%%%%%% function saveFile(hObject,eventdata,h,hh,X,H,scanmode) filename = get(hh.textField,'string'); filename = [filename,'.txt']; files = dir; files = struct2cell(files); files = files(1,:); cancel = false; for k=1:length(files) % if filename conflicts, it gives user option to overwrite if strcmpi(files(k),filename) cancel = true; startPos = get(h.fig,'position'); hhh.fig = figure('position',[startPos(1)+(startPos(3)-200)/2 startPos(2)+(startPos(4)-100)/2 200 100],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain,... 'Name','warning'); hhh.existMessage = uicontrol('style','tex',... 'position',[20 50 160 30],... 'BackgroundColor',h.colorMain,... 'string',{[filename,' already exists!'];'Do you wish to overwrite?'}); hhh.buttonYesSave = uicontrol('style','pushbutton',... 'position',[15 20 80 24],... 'string','yes'); hhh.buttonNoSave = uicontrol('style','pushbutton',... 'position',[105 20 80 24],... 'string','no'); set(hhh.buttonNoSave,'callback',{@selectNoSave,hhh}); set(hhh.buttonYesSave,'callback',{@selectYesSave,hhh,hh,h,filename,X,H,scanmode}); set(hhh.fig,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); break end end if ~cancel % if filename does not conflict and has not been saved createOutputFile(hObject,eventdata,h,filename,X,H,scanmode); guidata(hObject,h); set(hh.fig,'Visible','off'); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%% % Saves seleced filename % %%%%%%%%%%%%%%%%%%%%%%%%%% function saveConcatenateFile(hObject,eventdata,h,hh,X,H,scanmode) filename = get(hh.textField,'string'); filename = [filename,'.txt']; files = dir; files = struct2cell(files); files = files(1,:); cancel = false; for k=1:length(files) % if filename conflicts, it gives user option to overwrite if strcmpi(files(k),filename) cancel = true; startPos = get(h.fig,'position'); hhh.fig = figure('position',[startPos(1)+(startPos(3)-200)/2 startPos(2)+(startPos(4)-100)/2 200 100],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain,... 'Name','warning'); hhh.existMessage = uicontrol('style','tex',... 'position',[20 50 160 30],... 'BackgroundColor',h.colorMain,... 'string',{[filename,' already exists!'];'Do you wish to overwrite?'}); hhh.buttonYesSave = uicontrol('style','pushbutton',... 'position',[15 20 80 24],... 'string','yes'); hhh.buttonNoSave = uicontrol('style','pushbutton',... 'position',[105 20 80 24],... 'string','no'); set(hhh.buttonNoSave,'callback',{@selectNoSave,hhh}); set(hhh.buttonYesSave,'callback',{@selectYesSaveConcat,hhh,hh,h,filename,X,H,scanmode}); set(hhh.fig,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); break end end if ~cancel % if filename does not conflict and has not been saved createOutputConcatFile(hObject,eventdata,h,filename,X,H,scanmode); guidata(hObject,h); set(hh.fig,'Visible','off'); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Saves seleced image filename % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function saveImageFile(hObject,eventdata,h,hh,X,H,scanmode) filename = get(hh.textField,'string'); files = dir; files = struct2cell(files); files = files(1,:); % finds the user-selected file type for the image file fileType = get(h.fileJPG,'value'); fileType = [fileType,get(h.filePNG,'value')]; fileType = [fileType,get(h.fileTIF,'value')]; fileType = [fileType,get(h.fileEPS,'value')]; fileType = [fileType,get(h.filePDF,'value')]; fileType = [fileType,get(h.fileFIG,'value')]; fileTypeStr = [{'.jpg'};{'.png'};{'.tif'};{'.eps'};{'.pdf'};{'.fig'}]; fileTypeIndx = find(fileType==1); fileEnd = fileTypeStr(fileTypeIndx,:); fileEnd = cell2mat(fileEnd); filename = [filename,fileEnd]; % appends image file ending cancel = false; for k=1:length(files) % if filename conflicts, it gives user option to overwrite if strcmpi(files(k),filename) cancel = true; if isfield(h,'fig') startPos = get(h.fig,'position'); else startPos = h.startPos; end hhh.fig = figure('position',[startPos(1)+(startPos(3)-200)/2 startPos(2)+(startPos(4)-100)/2 200 100],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain,... 'Name','warning'); hhh.existMessage = uicontrol('style','tex',... 'position',[20 50 160 30],... 'BackgroundColor',h.colorMain,... 'string',{[filename,' already exists!'];'Do you wish to overwrite?'}); hhh.buttonYesSave = uicontrol('style','pushbutton',... 'position',[15 20 80 24],... 'string','yes'); hhh.buttonNoSave = uicontrol('style','pushbutton',... 'position',[105 20 80 24],... 'string','no'); set(hhh.buttonNoSave,'callback',{@selectNoSave,hhh}); set(hhh.buttonYesSave,'callback',{@selectYesSave,hhh,hh,h,filename,X,H,scanmode}); set(hhh.fig,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); break end end if ~cancel % if filename does not conflict and has not been saved createImageOutputFile(hObject,eventdata,h,hh,filename,X,H,scanmode); guidata(hObject,h); set(hh.fig,'Visible','off'); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%% % Cancel file save % %%%%%%%%%%%%%%%%%%%% function cancelFig(hObject,eventdata,h) set(gcf,'Visible','off'); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%% % Cancel file save 2 % %%%%%%%%%%%%%%%%%%%%%% function cancelFig2(hObject,eventdata,h) set(h.fig2,'Visible','off'); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % if user selects not to overwrite file % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function selectNoSave(hObject,eventdata,h) guidata(hObject,h); set(h.fig,'Visible','off'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % if user selects to overwrite file % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function selectYesSave(hObject,eventdata,hhh,hh,h,filename,X,H,scanmode) % removes old file first [filelist,dirlist] = loadFilesDirs(hObject,eventdata,h); for k=1:length(filelist) if strcmpi(filename,cell2mat(filelist(k))) delete(cell2mat(filelist(k))); end end if strcmpi(filename(end-2:end),'txt') createOutputFile(hObject,eventdata,h,filename,X,H,scanmode); % reload callbacks set(h.menuFileOpen,'callback',{@loadFile,h}); set(h.buttonScan,'callback',{@scanData,h}); else createImageOutputFile(hObject,eventdata,h,hh,filename,X,H,scanmode); end guidata(hObject,hhh); set(hhh.fig,'Visible','off'); set(hh.fig,'Visible','off'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % if user selects to overwrite file % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function selectYesSaveConcat(hObject,eventdata,hhh,hh,h,filename,X,H,scanmode) % removes old file first [filelist,dirlist] = loadFilesDirs(hObject,eventdata,h); for k=1:length(filelist) if strcmpi(filename,cell2mat(filelist(k))) delete(cell2mat(filelist(k))); end end createOutputConcatFile(hObject,eventdata,h,filename,X,H,scanmode); % reload callbacks set(h.menuFileOpen,'callback',{@loadFile,h}); set(h.buttonScan,'callback',{@scanData,h}); guidata(hObject,hhh); set(hhh.fig,'Visible','off'); set(hh.fig,'Visible','off'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % saves the current plot as an image % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function savePlot(hObject,eventdata,h) % create figure to allow user to specify plot options startPos = get(h.fig,'position'); hh.fig2 = figure('position',[startPos(1)+(startPos(3)-560)/2 startPos(2)+(startPos(4)-456)/2 560 456],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain,... 'Name','Figure Options'); % panel for filetypes hh.fileTypePanel = uibuttongroup('units','points',... 'position',[10 10 50 108],... 'BackgroundColor',h.colorSecondary); hh.fileTypeText = uicontrol('style','tex',... 'position',[0,130,80,14],... 'string','Filetype',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain,... 'parent',hh.fileTypePanel); hh.fileJPG = uicontrol('style','radiobutton',... 'position',[8 110 45 14],... 'string','jpg',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.fileTypePanel); hh.filePNG = uicontrol('style','radiobutton',... 'position',[8 90 45 14],... 'string','png',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.fileTypePanel); hh.fileTIF = uicontrol('style','radiobutton',... 'position',[8 70 45 14],... 'string','tif',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.fileTypePanel); hh.fileEPS = uicontrol('style','radiobutton',... 'position',[8 50 45 14],... 'string','eps',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.fileTypePanel); hh.filePDF = uicontrol('style','radiobutton',... 'position',[8 30 45 14],... 'string','pdf',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.fileTypePanel); hh.fileFIG = uicontrol('style','radiobutton',... 'position',[8 10 45 14],... 'string','fig',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.fileTypePanel); % panel for resolution hh.resolutionPanel = uibuttongroup('units','points',... 'position',[80 10 50 108],... 'BackgroundColor',h.colorSecondary); hh.resolutionText = uicontrol('style','tex',... 'position',[0,130,80,14],... 'string','Resolution',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain,... 'parent',hh.resolutionPanel); hh.file72 = uicontrol('style','radiobutton',... 'position',[8 110 45 14],... 'string','72',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.resolutionPanel); hh.file150 = uicontrol('style','radiobutton',... 'position',[8 90 45 14],... 'string','150',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.resolutionPanel); hh.file300 = uicontrol('style','radiobutton',... 'position',[8 70 45 14],... 'string','300',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.resolutionPanel); hh.file600 = uicontrol('style','radiobutton',... 'position',[8 50 45 14],... 'string','600',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.resolutionPanel); % panel for plot size hh.plotSizePanel = uibuttongroup('units','point',... 'position',[150 10 90 60],... 'BackgroundColor',h.colorSecondary); hh.plotSizeText = uicontrol('style','tex',... 'position',[0,130,80,14],... 'string','Size',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain,... 'parent',hh.plotSizePanel); hh.sizeXlabel = uicontrol('style','tex',... 'position',[0 107 12 14],... 'string','X',... 'FontWeight','bold',... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'parent',hh.plotSizePanel); hh.sizeYlabel = uicontrol('style','tex',... 'position',[0 82 12 14],... 'string','Y',... 'FontWeight','bold',... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'parent',hh.plotSizePanel); hh.sizeXinput = uicontrol('style','edit',... 'position',[20 105 80 20],... 'BackgroundColor','white',... 'HorizontalAlignment','left',... 'string','512',... 'parent',hh.plotSizePanel); hh.sizeYinput = uicontrol('style','edit',... 'position',[20 80 80 20],... 'BackgroundColor','white',... 'HorizontalAlignment','left',... 'string','384',... 'parent',hh.plotSizePanel); hh.plotSizePixel = uicontrol('style','radiobutton',... 'position',[8 48 90 20],... 'string','points',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.plotSizePanel); hh.plotSizeInches = uicontrol('style','radiobutton',... 'position',[8 28 90 14],... 'string','inches',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.plotSizePanel); hh.plotSizeCentimeters = uicontrol('style','radiobutton',... 'position',[8 8 90 14],... 'string','centimeters',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.plotSizePanel); % panel for font type and size hh.fileTypeText = uicontrol('style','tex',... 'units','points',... 'string','Font Type',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain,... 'position',[260 128 70 14]); hh.fileTypeChoose = uicontrol('style','popupmenu',... 'units','points',... 'position',[260 110 120 20],... 'string',[{'Times New Roman'};{'Arial'}],... 'value',2,... 'BackgroundColor','white'); hh.fileTypeText = uicontrol('style','tex',... 'units','points',... 'string','Font Size',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain,... 'position',[260 94 50 14]); hh.fileSizeChoose = uicontrol('style','popupmenu',... 'units','points',... 'position',[260 76 42 20],... 'string',[{'6'};{'8'};{'10'};{'12'};{'14'};{'16'};{'18'};{'24'};{'32'};{'40'};{'48'};{'56'};{'64'}],... 'Value',3,... 'BackgroundColor','white'); % panel for creating a figure title hh.figureTitleText = uicontrol('style','tex',... 'units','points',... 'string','Figure Title',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain,... 'position',[260 60 70 14]); hh.figureTitleInput = uicontrol('style','edit',... 'units','points',... 'position',[260 42 145 20],... 'HorizontalAlignment','left',... 'BackgroundColor','white'); % panel for statistical information hh.statisticsPanel = uibuttongroup('units','points',... 'position',[285 155 120 160],... 'BackgroundColor',h.colorSecondary); hh.statisticsText = uicontrol('style','tex',... 'position',[0,190,80,14],... 'string','Statistics',... 'FontWeight','bold',... 'HorizontalAlignment','left',... 'BackgroundColor',h.colorMain,... 'parent',hh.statisticsPanel); hh.statisticsLeftPosX = uicontrol('style','checkbox',... 'position',[8 170 110 14],... 'string','left X position',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.statisticsPanel); hh.statisticsRightPosX = uicontrol('style','checkbox',... 'position',[8 150 110 14],... 'string','right X position',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.statisticsPanel); hh.statisticsLeftPoxY = uicontrol('style','checkbox',... 'position',[8 130 110 14],... 'string','left H position',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.statisticsPanel); hh.statisticsRightPosY = uicontrol('style','checkbox',... 'position',[8 110 110 14],... 'string','right H position',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.statisticsPanel); hh.statisticsXdiff = uicontrol('style','checkbox',... 'position',[8 90 110 14],... 'string','Δ X',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.statisticsPanel); hh.statisticsYdiff = uicontrol('style','checkbox',... 'position',[8 70 110 14],... 'string','Δ H',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.statisticsPanel); hh.statisticsAverage = uicontrol('style','checkbox',... 'position',[8 50 110 14],... 'string','average',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.statisticsPanel); hh.statisticsDeviation = uicontrol('style','checkbox',... 'position',[8 30 110 14],... 'string','deviation',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.statisticsPanel); hh.statisticsRa = uicontrol('style','checkbox',... 'position',[8 10 110 14],... 'string','Ra',... 'BackgroundColor',h.colorSecondary,... 'parent',hh.statisticsPanel); % button to save plot as an image hh.savePlotImageButton = uicontrol('style','pushbutton',... 'units','points',... 'position',[260 10 68 25],... 'string','save'); % button to cancel save hh.cancelPlotImageButton = uicontrol('style','pushbutton',... 'units','points',... 'position',[338 10 68 25],... 'string','cancel'); hh.prevUnit = get(hh.plotSizePixel,'string'); set(hh.sizeXinput,'callback',{@sizeXRatio,h,hh}); set(hh.sizeYinput,'callback',{@sizeYRatio,h,hh}); set(hh.plotSizePixel,'callback',{@changePixel,hh}); set(hh.plotSizeInches,'callback',{@changeInches,hh}); set(hh.plotSizeCentimeters,'callback',{@changeCentimeters,hh}); set(hh.fig2,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); set(gca,'units','points','position',[35 160 213 160]); % sets location and size of plot box on filename = h.filename; filename = [filename;{'0'}]; hh.scanmode = h.scanmode; hh.filename = h.filename; hh.lpoint = h.lpoint; hh.rpoint = h.rpoint; hh.indxl = h.indxl; hh.indxr = h.indxr; hh.X = h.X; hh.H = h.H; hh.Ra = h.Ra; hh.Havg = h.Havg; hh.Hstd = h.Hstd; hh.startPos = get(h.fig,'position'); if isfield(h,'plotHl'); hh.plotHl = h.plotHl; hh.plotHavg = h.plotHavg; hh.plotHdev = h.plotHdev; hh.plotRa = h.plotRa; hh.Hra = h.Hra; end miniPlot(hObject,eventdata,h,hh); hh.colorMain = h.colorMain; hh.colorSecondary = h.colorSecondary; set(hh.savePlotImageButton,'callback',{@saveData,hh,h.X,h.H,filename,h.scanmode}); set(hh.cancelPlotImageButton,'callback',{@cancelFig2,hh}); set(hh.figureTitleInput,'callback',{@miniPlot,h,hh}); set(hh.statisticsLeftPosX,'callback',{@miniPlot,h,hh}); set(hh.statisticsRightPosX,'callback',{@miniPlot,h,hh}); set(hh.statisticsLeftPoxY,'callback',{@miniPlot,h,hh}); set(hh.statisticsRightPosY,'callback',{@miniPlot,h,hh}); set(hh.statisticsXdiff,'callback',{@miniPlot,h,hh}); set(hh.statisticsYdiff,'callback',{@miniPlot,h,hh}); set(hh.statisticsAverage,'callback',{@miniPlot,h,hh}); set(hh.statisticsDeviation,'callback',{@miniPlot,h,hh}); set(hh.statisticsRa,'callback',{@miniPlot,h,hh}); set(hh.fileTypeChoose,'callback',{@miniPlot,h,hh}); set(hh.fileSizeChoose,'callback',{@miniPlot,h,hh}); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % creates the preview plot when saving the plot as a figure % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function miniPlot(hObject,eventdata,h,hh) figure(hh.fig2); % scanmode if h.scanmode == 1 ylabel('height (\mum)') app = '\mum'; appval = 200; else ylabel('height (nm)') app = 'nm'; appval = 2; end % finds selected image dimensions and units Xdim = get(hh.sizeXinput,'string'); Xdim = str2num(Xdim); Ydim = get(hh.sizeYinput,'string'); Ydim = str2num(Ydim); units = get(hh.plotSizePixel,'value'); units = [units,get(hh.plotSizeInches,'value')]; units = [units,get(hh.plotSizeCentimeters,'value')]; unitsStr = [{'points'};{'inches'};{'centimeters'}]; unitsIndx = find(units==1); units = cell2mat(unitsStr(unitsIndx,:)); % make the mini plot reflect what the large one will look like if strcmpi(units,'points') resizeRatio = 240/Xdim; elseif strcmpi(units,'inches') resizeRatio = (10/3)/Xdim; elseif strcmpi(units,'centimeters') resizeRatio = (8.467)/Xdim; end % finds selected font type and size fontType = get(hh.fileTypeChoose,'string'); fontTypeIndx = get(hh.fileTypeChoose,'value'); fontSize = get(hh.fileSizeChoose,'string'); fontSizeIndx = get(hh.fileSizeChoose,'value'); fontType = fontType(fontTypeIndx,:); fontType = cell2mat(fontType); fontSize = fontSize(fontSizeIndx,:); fontSize = cell2mat(fontSize); fontSize = str2num(fontSize); fontSize = fontSize*resizeRatio; if fontSize<1.5 fontSize = 1.5; end % Finds selected statistical options plotText = []; plotBars = false; % sets left X position if get(hh.statisticsLeftPosX,'value')==1 plotBars = true; plotText = [plotText;{['X_l = ',num2str(h.lpoint),' \mum']}]; end % sets right X position if get(hh.statisticsRightPosX,'value')==1 plotBars = true; plotText = [plotText;{['X_r = ',num2str(h.rpoint),' \mum']}]; end % sets left H position if get(hh.statisticsLeftPoxY,'value')==1 plotBars = true; plotText = [plotText;{['H_l = ',num2str(h.H(h.indxl)),' ',app]}]; end % sets right H position if get(hh.statisticsRightPosY,'value')==1 plotBars = true; plotText = [plotText;{['H_r = ',num2str(h.H(h.indxr)),' ',app]}]; end % sets X difference if get(hh.statisticsXdiff,'value')==1 plotBars = true; plotText = [plotText;{['\DeltaX = ',num2str(abs(h.rpoint-h.lpoint)),' \mum']}]; end % sets Y difference if get(hh.statisticsYdiff,'value')==1 plotBars = true; plotText = [plotText;{['\DeltaH = ',num2str(h.H(h.indxr) - h.H(h.indxl)),' ',app]}]; end % sets average value if get(hh.statisticsAverage,'value')==1 plotBars = true; plotText = [plotText;{['H_{avg} = ',num2str(h.Havg),' ',app]}]; end % sets deviation value if get(hh.statisticsDeviation,'value')==1 plotBars = true; plotText = [plotText;{['\sigma = ',num2str(h.Hstd),' ',app]}]; end % sets surface roughness value if get(hh.statisticsRa,'value')==1 plotBars = true; plotText = [plotText;{['R_a = ',num2str(h.Ra),' ',app]}]; end % create the mini preview plot if isempty(plotText) set(gca,'units','points','position',[35 160 213 160]); % sets location and size of plot else set(gca,'units','points','position',[35 160 205 160]); % sets location and size of plot end cla box on hold on padAxis = false; if isfield(h,'plotHl') && h.plotHavg && h.plotHdev && ~h.plotRa h.plot = errorbar(h.X,h.H,h.Hstd,'ob'); padAxis = true; elseif isfield(h,'plotHl') && h.plotHavg && h.plotRa && ~h.plotHdev h.plot = errorbar(h.X,h.H,h.Hra,'ob'); padAxis = true; elseif isfield(h,'plotHl') && h.plotHavg && h.plotHdev && h.plotRa h.plot = errorbar(h.X,h.H,h.Hra,'or'); h.plot = errorbar(h.X,h.H,h.Hstd,'ob'); legend('R_a','\sigma','location','Best'); legend boxoff; padAxis = true; else h.plot = plot(h.X,h.H,'LineWidth',1,'Color','b'); end ylim = get(gca,'YLim'); if min(h.H) > 0 && ~padAxis axis([min(h.X),max(h.X),0,ylim(2)]); elseif min(h.H) > 0 && padAxis % adds padding for errorbar data axis([min(h.X) - 0.1*max(h.X),max(h.X) + 0.1*max(h.X),0,ylim(2)]); elseif min(h.H) < 0 && padAxis % adds padding for errorbar data axis([min(h.X) - 0.1*max(h.X),max(X) + 0.1*max(h.X),ylim(1),ylim(2)]); else axis([min(h.X),max(h.X),ylim(1),ylim(2)]); end ylim = get(gca,'YLim'); xlim = get(gca,'XLim'); if plotBars line([h.lpoint,h.lpoint],ylim,'LineStyle','--','Color','k') line([h.rpoint,h.rpoint],ylim,'LineStyle','--','Color','k') end hold off title(get(hh.figureTitleInput,'string'),'FontSize',fontSize*(11/10),'FontName',fontType,'FontWeight','bold') xlabel('position (\mum)','FontSize',fontSize,'FontName',fontType) ylabel(['height (',app,')'],'FontSize',fontSize,'FontName',fontType) set(gca,'FontSize',fontSize,'FontName',fontType) for k=1:length(plotText) text(1.02,1-k*(0.050*((fontSize/resizeRatio)/10)),cell2mat(plotText(k)),'Units','normalized','FontSize',fontSize,'FontName',fontType); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%% % change values to pixels % %%%%%%%%%%%%%%%%%%%%%%%%%%% function changePixel(hObject,eventdata,h) set(h.plotSizePixel,'value',1); % finds selected image dimensions and units Xdim = get(h.sizeXinput,'string'); Xdim = str2num(Xdim); Ydim = get(h.sizeYinput,'string'); Ydim = str2num(Ydim); if strcmpi(h.prevUnit,'inches') % converts from inches to points Xdim = Xdim*72; Ydim = Ydim*72; Xdim = sprintf('%.0f',Xdim); Ydim = sprintf('%.0f',Ydim); set(h.sizeXinput,'string',Xdim); set(h.sizeYinput,'string',Ydim); elseif strcmpi(h.prevUnit,'centimeters') % converts from centimeters to points Xdim = Xdim*28.35; Ydim = Ydim*28.35; Xdim = sprintf('%.0f',Xdim); Ydim = sprintf('%.0f',Ydim); set(h.sizeXinput,'string',Xdim); set(h.sizeYinput,'string',Ydim); end h.prevUnit = 'points'; set(h.plotSizePixel,'callback',{@changePixel,h}); set(h.plotSizeInches,'callback',{@changeInches,h}); set(h.plotSizeCentimeters,'callback',{@changeCentimeters,h}); guidata(hObject,h) %%%%%%%%%%%%%%%%%%%%%%%%%%% % change values to inches % %%%%%%%%%%%%%%%%%%%%%%%%%%% function changeInches(hObject,eventdata,h) set(h.plotSizeInches,'value',1); % finds selected image dimensions and units Xdim = get(h.sizeXinput,'string'); Xdim = str2num(Xdim); Ydim = get(h.sizeYinput,'string'); Ydim = str2num(Ydim); if strcmpi(h.prevUnit,'points') % converts from points to inches Xdim = Xdim/72; Ydim = Ydim/72; Xdim = sprintf('%.2f',Xdim); Ydim = sprintf('%.2f',Ydim); set(h.sizeXinput,'string',Xdim); set(h.sizeYinput,'string',Ydim); elseif strcmpi(h.prevUnit,'centimeters') % converts from centimeters to inches Xdim = Xdim/2.54; Ydim = Ydim/2.54; Xdim = sprintf('%.2f',Xdim); Ydim = sprintf('%.2f',Ydim); set(h.sizeXinput,'string',Xdim); set(h.sizeYinput,'string',Ydim); end h.prevUnit = 'inches'; set(h.plotSizePixel,'callback',{@changePixel,h}); set(h.plotSizeInches,'callback',{@changeInches,h}); set(h.plotSizeCentimeters,'callback',{@changeCentimeters,h}); guidata(hObject,h) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % change values to centimeters % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function changeCentimeters(hObject,eventdata,h) set(h.plotSizeCentimeters,'value',1); % finds selected image dimensions and units Xdim = get(h.sizeXinput,'string'); Xdim = str2num(Xdim); Ydim = get(h.sizeYinput,'string'); Ydim = str2num(Ydim); if strcmpi(h.prevUnit,'inches') % converts from inches to centimeters Xdim = Xdim*2.54; Ydim = Ydim*2.54; Xdim = sprintf('%.2f',Xdim); Ydim = sprintf('%.2f',Ydim); set(h.sizeXinput,'string',Xdim); set(h.sizeYinput,'string',Ydim); elseif strcmpi(h.prevUnit,'points') % converts from points to centimeters Xdim = Xdim/28.35; Ydim = Ydim/28.35; Xdim = sprintf('%.2f',Xdim); Ydim = sprintf('%.2f',Ydim); set(h.sizeXinput,'string',Xdim); set(h.sizeYinput,'string',Ydim); end h.prevUnit = 'centimeters'; set(h.plotSizePixel,'callback',{@changePixel,h}); set(h.plotSizeInches,'callback',{@changeInches,h}); set(h.plotSizeCentimeters,'callback',{@changeCentimeters,h}); guidata(hObject,h) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % keeps a 4:3 ratio for the dimensions of the plot to be saved % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function sizeXRatio(hObject,eventdata,h,hh) xvalue = get(hObject,'string'); xvalue = str2num(xvalue); set(hh.sizeYinput,'string',num2str(xvalue*(3/4))); miniPlot(hObject,eventdata,h,hh); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % keeps a 4:3 ratio for the dimensions of the plot to be saved % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function sizeYRatio(hObject,eventdata,h,hh) xvalue = get(hObject,'string'); xvalue = str2num(xvalue); set(hh.sizeXinput,'string',num2str(xvalue*(4/3))); miniPlot(hObject,eventdata,h,hh); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%% % create image output file % %%%%%%%%%%%%%%%%%%%%%%%%%%%% function createImageOutputFile(hObject,eventdata,h,hh,filename,X,H,scanmode) % scanmode if scanmode == 1 ylabel('height (\mum)') app = 'um'; appval = 200; else ylabel('height (nm)') app = 'nm'; appval = 2; end % finds the user-selected file type for the image file fileType = get(h.fileJPG,'value'); fileType = [fileType,get(h.filePNG,'value')]; fileType = [fileType,get(h.fileTIF,'value')]; fileType = [fileType,get(h.fileEPS,'value')]; fileType = [fileType,get(h.filePDF,'value')]; fileType = [fileType,get(h.fileFIG,'value')]; fileTypeStr = [{'-djpeg'};{'-dpng'};{'-dtiff'};{'-depsc'};{'-dpdf'};{'fig'}]; fileTypeIndx = find(fileType==1); fileEnd = fileTypeStr(fileTypeIndx,:); fileEnd = cell2mat(fileEnd); %filename = [filename,'.',fileEnd]; % finds the selected resolution resolution = get(h.file72,'value'); resolution = [resolution,get(h.file150,'value')]; resolution = [resolution,get(h.file300,'value')]; resolution = [resolution,get(h.file600,'value')]; resolutionArr = [{'-r72'};{'-r150'};{'-r300'};{'-r600'}]; resolutionIndx = find(resolution==1); resolution = resolutionArr(resolutionIndx); resolution = cell2mat(resolution); % finds selected image dimensions and units Xdim = get(h.sizeXinput,'string'); Xdim = str2num(Xdim); Ydim = get(h.sizeYinput,'string'); Ydim = str2num(Ydim); units = get(h.plotSizePixel,'value'); units = [units,get(h.plotSizeInches,'value')]; units = [units,get(h.plotSizeCentimeters,'value')]; unitsStr = [{'points'};{'inches'};{'centimeters'}]; unitsIndx = find(units==1); units = cell2mat(unitsStr(unitsIndx,:)); % finds selected font type and size fontType = get(h.fileTypeChoose,'string'); fontTypeIndx = get(h.fileTypeChoose,'value'); fontSize = get(h.fileSizeChoose,'string'); fontSizeIndx = get(h.fileSizeChoose,'value'); fontType = fontType(fontTypeIndx,:); fontType = cell2mat(fontType); fontSize = fontSize(fontSizeIndx,:); fontSize = cell2mat(fontSize); fontSize = str2num(fontSize); % Finds selected statistical options plotText = []; plotBars = false; % sets left X position if get(h.statisticsLeftPosX,'value')==1 plotBars = true; plotText = [plotText;{['X_l = ',num2str(h.lpoint),' \mum']}]; %plotText = [plotText,' X_l = ',num2str(h.lpoint),' \mum']; end % sets right X position if get(h.statisticsRightPosX,'value')==1 plotBars = true; plotText = [plotText;{['X_r = ',num2str(h.rpoint),' \mum']}]; %plotText = [plotText,' X_r = ',num2str(h.rpoint),' \mum']; end % sets left H position if get(h.statisticsLeftPoxY,'value')==1 plotBars = true; plotText = [plotText;{['H_l = ',num2str(h.H(h.indxl)),' ',app]}]; %plotText = [plotText,' H_l = ',num2str(h.H(h.indxl)),' ',app]; end % sets right H position if get(h.statisticsRightPosY,'value')==1 plotBars = true; plotText = [plotText;{['H_r = ',num2str(h.H(h.indxr)),' ',app]}]; %plotText = [plotText,' H_r = ',num2str(h.H(h.indxr)),' ',app]; end % sets X difference if get(h.statisticsXdiff,'value')==1 plotBars = true; plotText = [plotText;{['\DeltaX = ',num2str(abs(h.rpoint-h.lpoint)),' \mum']}]; %plotText = [plotText,' \DeltaX = ',num2str(abs(h.rpoint-h.lpoint)),' \mum']; end % sets Y difference if get(h.statisticsYdiff,'value')==1 plotBars = true; plotText = [plotText;{['\DeltaH = ',num2str(h.H(h.indxr) - h.H(h.indxl)),' ',app]}]; %plotText = [plotText,' \DeltaH = ',num2str(h.H(h.indxr) - h.H(h.indxl)),' ',app]; end % sets average value if get(h.statisticsAverage,'value')==1 plotBars = true; plotText = [plotText;{['H_{avg} = ',num2str(h.Havg),' ',app]}]; %plotText = [plotText,' H_{avg} = ',num2str(h.Havg),' ',app]; end % sets deviation value if get(h.statisticsDeviation,'value')==1 plotBars = true; plotText = [plotText;{['\sigma = ',num2str(h.Hstd),' ',app]}]; %plotText = [plotText,' \sigma = ',num2str(h.Hstd),' ',app]; end % sets surface roughness value if get(h.statisticsRa,'value')==1 plotBars = true; plotText = [plotText;{['R_a = ',num2str(h.Ra),' ',app]}]; %plotText = [plotText,' R_a = ',num2str(h.Ra),' ',app]; end % create plot hhh.fig = figure('units',units,... 'position',[0 0 Xdim Ydim],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain); cla hold on if isempty(plotText) % expands axes to fill full figure set(gca,'units','normalized','position',[0.13 0.11 0.78 0.82]); % sets location and size of plot else % shrinks axes to fit data along bottom of figure % set(gca,'units','normalized','position',[0.13 0.21 0.78 0.72]); set(gca,'units','normalized','position',[0.10 0.11 0.68 0.82]); end padAxis = false; if isfield(h,'plotHl') && h.plotHavg && h.plotHdev && ~h.plotRa h.plot = errorbar(h.X,h.H,h.Hstd,'ob'); padAxis = true; elseif isfield(h,'plotHl') && h.plotHavg && h.plotRa && ~h.plotHdev h.plot = errorbar(h.X,h.H,h.Hra,'ob'); padAxis = true; elseif isfield(h,'plotHl') && h.plotHavg && h.plotHdev && h.plotRa h.plot = errorbar(h.X,h.H,h.Hra,'or'); h.plot = errorbar(h.X,h.H,h.Hstd,'ob'); legend('R_a','\sigma','location','Best'); legend boxoff; padAxis = true; else h.plot = plot(h.X,h.H,'LineWidth',1,'Color','b'); end ylim = get(gca,'YLim'); if min(h.H) > 0 && ~padAxis axis([min(h.X),max(h.X),0,ylim(2)]); elseif min(h.H) > 0 && padAxis % adds padding for errorbar data axis([min(h.X) - 0.1*max(h.X),max(h.X) + 0.1*max(h.X),0,ylim(2)]); elseif min(h.H) < 0 && padAxis % adds padding for errorbar data axis([min(h.X) - 0.1*max(h.X),max(X) + 0.1*max(h.X),ylim(1),ylim(2)]); else axis([min(h.X),max(h.X),ylim(1),ylim(2)]); end box on grid on ylim = get(gca,'YLim'); xlim = get(gca,'XLim'); if plotBars line([h.lpoint,h.lpoint],ylim,'LineStyle','--','Color','k') line([h.rpoint,h.rpoint],ylim,'LineStyle','--','Color','k') end hold off title(get(h.figureTitleInput,'string'),'FontSize',fontSize*(11/10),'FontName',fontType,'FontWeight','bold') xlabel('position (\mum)','FontSize',fontSize,'FontName',fontType) ylabel(['height (',app,')'],'FontSize',fontSize,'FontName',fontType) set(gca,'FontSize',fontSize,'FontName',fontType) for k=1:length(plotText) text(1.02,1-k*(0.050*(fontSize/10)),cell2mat(plotText(k)),'Units','normalized','FontSize',fontSize,'FontName',fontType); end if strcmpi('fig',fileEnd) hgsave(hhh.fig,filename); else print(hhh.fig,fileEnd,resolution,filename); end set(hhh.fig,'Visible','off'); set(h.fig2,'Visible','off'); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%% % create output file % %%%%%%%%%%%%%%%%%%%%%% function createOutputFile(hObject,eventdata,h,filename,X,H,scanmode) dt = date; dy = dt(1:2); % day mn = dt(4:6); % month tm = clock; % time hr = num2str(tm(4)); % hour mi = num2str(tm(5)); % minute % format hour and minute to be two-digit if length(hr)<2 hr = ['0',hr]; end if length(mi)<2 mi = ['0',mi]; end % determine the current month switch mn case 'Jan' mn = '01'; case 'Feb' mn = '02'; case 'Mar' mn = '03'; case 'Apr' mn = '04'; case 'May' mn = '05'; case 'Jun' mn = '06'; case 'Jul' mn = '07'; case 'Aug' mn = '08'; case 'Sep' mn = '09'; case 'Oct' mn = '10'; case 'Nov' mn = '11'; case 'Dec' mn = '12'; end % builds scan menu entries scan2 = ' 2000 .2 1 '; scan3 = ' 400 1 5 '; scan4 = ' 80 5 25 '; % scans per micron spm = 1/X(2)-X(1); % determines which scan menu was used %if X(end) == 10000 if X(end) > 2000 time = '40 s'; appmenu = 1; %elseif X(end) == 2000 elseif X(end)>400 && X(end)<=2000 appmenu = 2; scan2(1,[1,6]) = '*'; if spm==0.2 time = ' 8 s'; scan2(1,[6,9]) = '*'; else time = '40 s'; scan2(1,[10,12]) = '*'; end %elseif X(end) == 400 elseif X(end)>80 && X(end)<=400 appmenu = 3; scan3(1,[2,6]) = '*'; if spm==1 time = ' 8 s'; scan3(1,[7,9]) = '*'; else time = '40 s'; scan3(1,[10,12]) = '*'; end %elseif X(end) == 80 elseif X(end)>=0 && X(end)<=80 appmenu = 4; scan4(1,[3,6]) = '*'; if spm==5 time = ' 8 s'; scan4(1,[7,9]) = '*'; else time = '40 s'; scan4(1,[9,12]) = '*'; end end % scanmode if scanmode == 1 ylabel('height (\mum)') app = 'um'; app1 = 'nm'; appval = 200; con = 1e3; % nm if appmenu == 1 scan1 = '10000* .2*'; else scan1 = '10000 .2 '; end else ylabel('height (nm)') app = 'KA'; app1 = ' A'; app1s = '*A'; appmenu = appmenu - 1; appval = 2; con = 1e1; % A scan1 = ' '; end % creates left bar xl = get(h.showXpointl,'string'); xl = xl(5:end); xls = isspace(xl); indx = find (xls==1); xl = str2num(xl(1:indx-1)); % find left vertical point Lindx = find(X == xl); LH = H(Lindx)*con; if abs(LH/1000) > 1 if scanmode==1 LV = num2str(LH*1e-3); % um app1 = 'um'; app1s = app1; else LV = num2str(LH*1e-3); % kA app1 = 'KA'; app1s = app1; end else if scanmode==1 LV = num2str(LH*1e0); % nm app1 = 'nm'; app1s = app1; else LV = num2str(LH*1e0); % A app1 = ' A'; app1s = '*A'; end end LVs = LV; templngth = length(LV); for k=1:(6-templngth) if templngth < 4 && k==1 LV = [LV,'.']; LVs = [LVs,'.']; else LV = [' ',LV]; LVs = ['*',LVs]; end end LV = [LV,app1]; LVs = [LVs,app1s,'*']; % find left horizontal point LH = X(Lindx); LH = num2str(LH); LHs = LH; for k=1:7-length(LH) LH = [' ',LH]; LHs = ['*',LHs]; end LH = [LH,'um']; LHs = [LHs,'um*']; % creates right bar xr = get(h.showXpointr,'string'); xr = xr(5:end); xrs = isspace(xr); indx = find (xrs==1); xr = str2num(xr(1:indx-1)); % find right vertical point Rindx = find(X == xr); RH = H(Rindx)*con; if abs(RH/1000) > 1 if scanmode==1 RV = num2str(RH*1e-3); % um app1 = 'um'; app1s = app1; else RV = num2str(RH*1e-3); % kA app1 = 'KA'; app1s = app1; end else if scanmode==1 RV = num2str(RH*1e0); % nm app1 = 'nm'; app1s = app1; else RV = num2str(RH*1e0); % A app1 = ' A'; app1s = '*A'; end end RVs = RV; templngth = length(RV); for k=1:(6-templngth) if templngth < 4 && k==1 RV = [RV,'.']; RVS = [RVs,'.']; else RV = [' ',RV]; RVs = ['*',RVs]; end end RV = [RV,app1]; RVs = [RVs,app1s,'*']; % find right horizontal point RH = X(Rindx); RH = num2str(RH); for k=1:7-length(RH) RH = [' ',RH]; end RH = [RH,'um']; % get average avg = get(h.showAvg,'string'); avgindx = find(isspace(avg) == 1); avg = avg(1:avgindx(1)); avg = str2num(avg)*con; if abs(avg/1000) > 1 if scanmode==1 avg = num2str(avg*1e-3); % um app1 = 'um'; else avg = num2str(avg*1e-3); % kA app1 = 'KA'; end else if scanmode==1 avg = num2str(avg*1e0); % nm app1 = 'nm'; else avg = num2str(avg*1e0); % A app1 = ' A'; app1s = '*A'; end end templngth = length(avg); for k=1:(6-templngth) if templngth < 4 && k==1 avg = [avg,'.']; else avg = [' ',avg]; end end avg = [avg,app1]; % get surface roughness Ra = get(h.showRa,'string'); Raindx = find(isspace(Ra) == 1); Ra = Ra(1:Raindx(1)); Ra = str2num(Ra)*con; if abs(Ra/1000) > 1 if scanmode==1 Ra = num2str(Ra*1e-3); % um app1 = 'um'; else Ra = num2str(Ra*1e-3); % kA app1 = 'KA'; end else if scanmode==1 Ra = num2str(Ra*1e0); % nm app1 = 'nm'; else Ra = num2str(Ra*1e0); % A app1 = ' A'; app1s = '*A'; end end templngth = length(Ra); for k=1:(6-templngth) if templngth < 4 && k==1 Ra = [Ra,'.']; else Ra = [' ',Ra]; end end Ra = [Ra,app1]; % get vertical displacement Ydiff = get(h.showYdiff,'string'); Ydiffindx = find(isspace(Ydiff) == 1); Ydiff = Ydiff(1:Ydiffindx(1)); Ydiff = str2num(Ydiff)*con; if abs(Ydiff/1000) > 1 if scanmode==1 Ydiff = num2str(Ydiff*1e-3); % um app1 = 'um'; else Ydiff = num2str(Ydiff*1e-3); % kA app1 = 'KA'; end else if scanmode==1 Ydiff = num2str(Ydiff*1e0); % nm app1 = 'nm'; else Ydiff = num2str(Ydiff*1e0); % A app1 = ' A'; app1s = '*A'; end end templngth = length(Ydiff); for k=1:(6-templngth) if templngth < 4 && k==1 Ydiff = [Ydiff,'.']; else Ydiff = [' ',Ydiff]; end end Ydiff = [Ydiff,app1]; % set the horizontal menu title horzmenu = num2str(X(end)); templngth = length(horzmenu); for k=1:(5-templngth) horzmenu = ['*',horzmenu]; end horzmenu = [horzmenu,'um']; % create new .txt file in same format as received from the profilometer dataout = [' ',mn,'/',dy,' ',hr,':',mi,' ID# ',sprintf('\n')]; dataout = [dataout,'VERT.***5',app,'* SCAN MENU ',num2str(appmenu),' ',sprintf('\n')]; dataout = [dataout,' L ',LV,' um s/um ',sprintf('\n')]; dataout = [dataout,' R ',RV,' ',scan1,' ',sprintf('\n')]; dataout = [dataout,' ',LVs,' ',scan2,' ',sprintf('\n')]; dataout = [dataout,'Avg',avg,' ',scan3,' ',sprintf('\n')]; dataout = [dataout,'TIR',Ydiff,' ',scan4,' ',sprintf('\n')]; dataout = [dataout,'Ra ',Ra,' ',sprintf('\n')]; dataout = [dataout,'HORIZ',horzmenu,' SCAN t=',time,' ',sprintf('\n')]; dataout = [dataout,' L',LH,' DIR. --> ',sprintf('\n')]; dataout = [dataout,' R',RH,' ',sprintf('\n')]; dataout = [dataout,' ',LHs,' STYLUS 25mg ',sprintf('\n')]; dataout = [dataout,'Area=? ? ? LEVEL ',sprintf('\n')]; numrows = ceil(length(X)/10); xvals = [0:10/spm:X(end)]; % load X and H values into file for k=1:numrows % build X values if xvals(k)<10 tempval = num2str(xvals(k)); if length(tempval)>1 tempval = [' ',tempval,'0um:']; else tempval = [' ',tempval,'.00um:']; end elseif xvals(k)>9 && xvals(k)<100 tempval = num2str(xvals(k)); if length(tempval)>2 tempval = [tempval,'0um:']; else tempval = [tempval,'.00um:']; end elseif xvals(k)>99 & xvals(k)<1000 tempval = num2str(xvals(k)); if length(tempval)>3 tempval = [tempval,'um:']; else tempval = [tempval,'.0um:']; end elseif xvals(k)>999 & xvals(k)<10000 tempval = num2str(xvals(k)); tempval = [tempval,'.um:']; elseif xvals(k) > 9999 tempval = num2str(xvals(k)); tempval = [tempval,'um:']; end % build H values if k==numrows % for the last data row Htemp = H((k-1)*10+1:end).*con.*1e-3; else % for all data rows but the last one Htemp = H((k-1)*10+1:10*k).*con.*1e-3; end Hvals = []; for n=1:length(Htemp) preapp = []; if Htemp(n) >= 0 preapp = [' ']; end tempH = sprintf('%01d',Htemp(n)); tempH = sprintf('%.3f',str2num(tempH)); tempH = [preapp,tempH,' ']; Hvals = [Hvals,tempH]; end %end % load them all together... dataout = [dataout,tempval,' ',Hvals,' ',sprintf('\n')]; end dataout = [dataout,'-------------------------------------------------------------------------------- ',sprintf('\n')]; % save completed data to specified file f1 = fopen(filename,'w'); fprintf(f1,dataout); fclose(f1); [filelist,dirlist] = loadFilesDirs(hObject,eventdata,h); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % creates and saves the file for concatenated data % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function createOutputConcatFile(hObject,eventdata,h,filename,X,H,scanmode) % finds whether units are um or nm units = get(h.concatenateMenuHL,'string'); units = units(5:6); setNum = get(h.concatenateValSet,'string'); HL = get(h.concatenateValHL,'string'); HR = get(h.concatenateValHR,'string'); Hdiff = get(h.concatenateValHdiff,'string'); Havg = get(h.concatenateValHavg,'string'); Hdev = get(h.concatenateValHdev,'string'); Ra = get(h.concatenateValRa,'string'); Xspacing = get(h.concatenateSpacingField,'string'); outputFile = ['***********************************',sprintf('\n')]; outputFile = [outputFile,'Concatenated Profilometer Data',sprintf('\n')]; outputFile = [outputFile,date,sprintf('\n')]; outputFile = [outputFile,'***********************************',sprintf('\n')]; outputFile = [outputFile,sprintf('\n')]; outputFile = [outputFile,'data set spacing = ',Xspacing,' um',sprintf('\n')]; outputFile = [outputFile,'units = ',units,sprintf('\n')]; outputFile = [outputFile,sprintf('\n')]; outputFile = [outputFile,'--------------------------------------------------------',sprintf('\n')]; outputFile = [outputFile,'set Hl Hr Hdiff Havg Hdev Ra',sprintf('\n')]; outputFile = [outputFile,'--------------------------------------------------------',sprintf('\n')]; for k=1:length(HL) % create set column tempNum = cell2mat(setNum(k)); if str2num(tempNum)<1000 && str2num(tempNum)>99 tempNum = [' ',tempNum]; elseif str2num(tempNum)<100 && str2num(tempNum)>9 tempNum = [' ',tempNum]; elseif str2num(tempNum)<10 tempNum = [' ',tempNum]; end outputFile = [outputFile,tempNum,' ']; % create Hl column tempHL = cell2mat(HL(k)); spc = ''; for n=1:(8-length(tempHL)) spc = [spc,' ']; end outputFile = [outputFile,tempHL,spc]; % create Hr column tempHR = cell2mat(HR(k)); spc = ''; for n=1:(8-length(tempHR)) spc = [spc,' ']; end outputFile = [outputFile,tempHR,spc]; % create Hdiff column tempHdiff = cell2mat(Hdiff(k)); spc = ''; for n=1:(8-length(tempHdiff)) spc = [spc,' ']; end outputFile = [outputFile,tempHdiff,spc]; % create Havg column tempHavg = cell2mat(Havg(k)); spc = ''; for n=1:(8-length(tempHavg)) spc = [spc,' ']; end outputFile = [outputFile,tempHavg,spc]; % create Hdev column tempHdev = cell2mat(Hdev(k)); spc = ''; for n=1:(8-length(tempHdev)) spc = [spc,' ']; end outputFile = [outputFile,tempHdev,spc]; % create Ra column tempRa = cell2mat(Ra(k)); spc = ''; for n=1:(8-length(tempRa)) spc = [spc,' ']; end outputFile = [outputFile,tempRa,spc]; outputFile = [outputFile,sprintf('\n')]; end outputFile = [outputFile,sprintf('\n')]; outputFile = [outputFile,'SETS',sprintf('\n')]; outputFile = [outputFile,'-----------------------------------------------------------------',sprintf('\n')]; for k=1:length(setNum) % create columns with set numbers tempNum = cell2mat(setNum(k)); spc = ''; for n=1:(16-length(tempNum)) spc = [spc,' ']; end outputFile = [outputFile,tempNum,spc]; end outputFile = [outputFile,sprintf('\n')]; for k=1:length(setNum) % creates X and H labels for corresponding sets outputFile = [outputFile,'X H ']; end outputFile = [outputFile,sprintf('\n')]; outputFile = [outputFile,'-----------------------------------------------------------------',sprintf('\n')]; % creates an array with the length of each data set for k=1:length(setNum) tempX = cell2mat(h.Xconcat(k,:)); tempX = str2num(tempX); dataLength(k) = length(tempX); end for k=1:max(dataLength) for n=1:length(setNum) tempX = cell2mat(h.Xconcat(n,:)); tempX = str2num(tempX); tempH = cell2mat(h.Hconcat(n,:)); tempH = str2num(tempH); if dataLength(n) < k tempX = ' '; tempH = ' '; else tempX = num2str(tempX(k)); tempH = num2str(tempH(k)); end spc = ''; for p=1:(8-length(tempX)) tempX = [tempX,' ']; end for p=1:(8-length(tempH)) tempH = [tempH,' ']; end outputFile = [outputFile,tempX,tempH]; end outputFile = [outputFile,sprintf('\n')]; end % writes file f1 = fopen(filename,'w'); fprintf(f1,outputFile); fclose(f1); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % menu for concatenating data % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function concatenateMenu(hObject,eventdata,h,X,H,filename,scanmode) if isfield(h,'concatenateFig') && strcmpi(get(h.concatenateFig,'Visible'),'on') % if the menu already exists % if new data isn't on same scale as original data appval = 1; if h.scanmodeCon~=scanmode if scanmode == 1 appval = 1e3; % convert um to nm else appval = 1e-3; % convert nm to um end end if h.indxl>h.indxr h.Hconcat = [h.Hconcat;{num2str(H(h.indxr:h.indxl))}]; h.Xconcat = [h.Xconcat;{num2str(X(h.indxr:h.indxl))}]; else h.Hconcat = [h.Hconcat;{num2str(H(h.indxl:h.indxr))}]; h.Xconcat = [h.Xconcat;{num2str(X(h.indxl:h.indxr))}]; end incrVal = 0; % value to stretch by % set data h.setNum = h.setNum + 1; setSetStr = get(h.concatenateValSet,'string'); setSetPos = get(h.concatenateValSet,'position'); setSetPan = get(h.concatenatePanelSet,'position'); % HL data setHLStr = get(h.concatenateValHL,'string'); setHLPos = get(h.concatenateValHL,'position'); setHLPan = get(h.concatenatePanelHL,'position'); % HR data setHRStr = get(h.concatenateValHR,'string'); setHRPos = get(h.concatenateValHR,'position'); setHRPan = get(h.concatenatePanelHR,'position'); % Hdiff data setHdiffStr = get(h.concatenateValHdiff,'string'); setHdiffPos = get(h.concatenateValHdiff,'position'); setHdiffPan = get(h.concatenatePanelHdiff,'position'); % Havg data setHavgStr = get(h.concatenateValHavg,'string'); setHavgPos = get(h.concatenateValHavg,'position'); setHavgPan = get(h.concatenatePanelHavg,'position'); % Hdev data setHdevStr = get(h.concatenateValHdev,'string'); setHdevPos = get(h.concatenateValHdev,'position'); setHdevPan = get(h.concatenatePanelHdev,'position'); % Ra data setRaStr = get(h.concatenateValRa,'string'); setRaPos = get(h.concatenateValRa,'position'); setRaPan = get(h.concatenatePanelRa,'position'); if setSetPan(2)<=60 % resizes the window to allow for scrolling figureSize = get(h.concatenateFig,'position'); slideFramePos = get(h.concatenateFrame2,'position'); slideFramePos(4) = slideFramePos(4) + (15/figureSize(4)); slideFramePos(2) = slideFramePos(2) - (15/figureSize(4)); set(h.concatenateFrame2,'position',slideFramePos); incrVal = 15; end % set data setSetStr = [setSetStr;{num2str(h.setNum)}]; setSetPos = [setSetPos(1),setSetPos(2)-15+incrVal,setSetPos(3),setSetPos(4)+15]; setSetPan = [setSetPan(1),setSetPan(2)-15+incrVal,setSetPan(3),setSetPan(4)+15]; set(h.concatenateValSet,'string',setSetStr,'position',setSetPos); set(h.concatenatePanelSet,'position',setSetPan); % HL data setHLStr = [setHLStr;{num2str(H(h.indxl)*appval)}]; setHLPos = [setHLPos(1),setHLPos(2)-15+incrVal,setHLPos(3),setHLPos(4)+15]; setHLPan = [setHLPan(1),setHLPan(2)-15+incrVal,setHLPan(3),setHLPan(4)+15]; set(h.concatenateValHL,'string',setHLStr,'position',setHLPos); set(h.concatenatePanelHL,'position',setHLPan); % HR data setHRStr = [setHRStr;{num2str(H(h.indxr)*appval)}]; setHRPos = [setHRPos(1),setHRPos(2)-15+incrVal,setHRPos(3),setHRPos(4)+15]; setHRPan = [setHRPan(1),setHRPan(2)-15+incrVal,setHRPan(3),setHRPan(4)+15]; set(h.concatenateValHR,'string',setHRStr,'position',setHRPos); set(h.concatenatePanelHR,'position',setHRPan); % Hdiff data setHdiffStr = [setHdiffStr;{num2str(H(h.indxr)*appval - H(h.indxl)*appval)}]; setHdiffPos = [setHdiffPos(1),setHdiffPos(2)-15+incrVal,setHdiffPos(3),setHdiffPos(4)+15]; setHdiffPan = [setHdiffPan(1),setHdiffPan(2)-15+incrVal,setHdiffPan(3),setHdiffPan(4)+15]; set(h.concatenateValHdiff,'string',setHdiffStr,'position',setHdiffPos); set(h.concatenatePanelHdiff,'position',setHdiffPan); % Havg data setHavgStr = [setHavgStr;{num2str(h.Havg*appval)}]; setHavgPos = [setHavgPos(1),setHavgPos(2)-15+incrVal,setHavgPos(3),setHavgPos(4)+15]; setHavgPan = [setHavgPan(1),setHavgPan(2)-15+incrVal,setHavgPan(3),setHavgPan(4)+15]; set(h.concatenateValHavg,'string',setHavgStr,'position',setHavgPos); set(h.concatenatePanelHavg,'position',setHavgPan); % Hdev data setHdevStr = [setHdevStr;{num2str(h.Hstd*appval)}]; setHdevPos = [setHdevPos(1),setHdevPos(2)-15+incrVal,setHdevPos(3),setHdevPos(4)+15]; setHdevPan = [setHdevPan(1),setHdevPan(2)-15+incrVal,setHdevPan(3),setHdevPan(4)+15]; set(h.concatenateValHdev,'string',setHdevStr,'position',setHdevPos); set(h.concatenatePanelHdev,'position',setHdevPan); % Ra data setRaStr = [setRaStr;{num2str(h.Ra*appval)}]; setRaPos = [setRaPos(1),setRaPos(2)-15+incrVal,setRaPos(3),setRaPos(4)+15]; setRaPan = [setRaPan(1),setRaPan(2)-15+incrVal,setRaPan(3),setRaPan(4)+15]; set(h.concatenateValRa,'string',setRaStr,'position',setRaPos); set(h.concatenatePanelRa,'position',setRaPan); else % creates the menu for the first time % scanmode h.scanmodeCon = scanmode; if scanmode == 1 h.appCon = 'um'; else h.appCon = 'nm'; end startPos = get(h.fig,'position'); h.concatenateFig = figure('position',[startPos(1)+startPos(3)-100 startPos(2)-100 510 400],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain,... 'Visible','on',... 'Name','Concatenate Data'); h.setNum = 1; if h.indxl>h.indxr h.Hconcat = {num2str(H(h.indxr:h.indxl))}; h.Xconcat = {num2str(X(h.indxr:h.indxl))}; else h.Hconcat = {num2str(H(h.indxl:h.indxr))}; h.Xconcat = {num2str(X(h.indxl:h.indxr))}; end % creates frame h.concatenateFrame1 = uipanel('position',[0 0 1 1],... 'BackgroundColor',h.colorMain); h.concatenateFrame2 = uipanel('position',[-0.005 0 1 1],... 'BackgroundColor',h.colorMain,... 'Parent',h.concatenateFrame1); h.concatenateFrame2Slide = uicontrol('style','slider',... 'parent',h.concatenateFrame1,... 'units','normalized',... 'value',1,... 'position',[0.97 43/400 0.03 1-(43/400)]); % fixed labels for each column h.concatenateBlankPanel = uicontrol('style','tex',... 'position',[0 380 496 21],... 'BackgroundColor',h.colorMain,... 'parent',h.concatenateFrame1); h.concatenateBlankPanel2 = uicontrol('style','frame',... 'position',[1 1 509 44],... 'BackgroundColor',h.colorMain,... 'parent',h.concatenateFrame1); h.concatenateSaveButton = uicontrol('style','pushbutton',... 'position',[350 10 70 25],... 'string','save',... 'parent',h.concatenateFrame1); h.concatenateCloseButton = uicontrol('style','pushbutton',... 'position',[430 10 70 25],... 'string','close',... 'parent',h.concatenateFrame1); h.concatenateSpacingField = uicontrol('style','edit',... 'position',[270 10 70 25],... 'string','0',... 'HorizontalAlignment','left',... 'BackgroundColor','white',... 'parent',h.concatenateFrame1); h.concatenateSpacingTitle = uicontrol('style','tex',... 'position',[70 15 190 14],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'parent',h.concatenateFrame1,... 'string','spacing between data sets (um):'); h.concatenateMenuSet = uicontrol('style','tex',... 'position',[7,380,32,16],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'string','set',... 'parent',h.concatenateFrame1); h.concatenateMenuHL = uicontrol('style','tex',... 'position',[47,380,67,16],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'string',['Hl (',h.appCon,')'],... 'parent',h.concatenateFrame1); h.concatenateMenuHR = uicontrol('style','tex',... 'position',[122,380,67,16],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'string',['Hr (',h.appCon,')'],... 'parent',h.concatenateFrame1); h.concatenateMenuHdiff = uicontrol('style','tex',... 'position',[197,380,67,16],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'string',['Hdiff (',h.appCon,')'],... 'parent',h.concatenateFrame1); h.concatenateMenuHavg = uicontrol('style','tex',... 'position',[272,380,67,16],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'string',['Havg (',h.appCon,')'],... 'parent',h.concatenateFrame1); h.concatenateMenuHdev = uicontrol('style','tex',... 'position',[347,380,67,16],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'string',['Hdev (',h.appCon,')'],... 'parent',h.concatenateFrame1); h.concatenateMenuRa = uicontrol('style','tex',... 'position',[422,380,67,16],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'string',['Ra (',h.appCon,')'],... 'parent',h.concatenateFrame1); % creates the panel for set number h.concatenatePanelSet = uicontrol('style','frame',... 'position',[10,360,32,17],... 'parent',h.concatenateFrame2); h.concatenateValSet = uicontrol('style','tex',... 'position',[11,361,30,15],... 'BackgroundColor','white',... 'HorizontalAlignment','left',... 'string',{num2str(h.setNum)},... 'parent',h.concatenateFrame2); % creates the panel for left H position h.concatenatePanelHL = uicontrol('style','frame',... 'position',[50,360,67,17],... 'parent',h.concatenateFrame2); h.concatenateValHL = uicontrol('style','tex',... 'position',[51,361,65,15],... 'BackgroundColor','white',... 'HorizontalAlignment','left',... 'string',{num2str(H(h.indxl))},... 'parent',h.concatenateFrame2); % creates the panel for right H position h.concatenatePanelHR = uicontrol('style','frame',... 'position',[125,360,67,17],... 'parent',h.concatenateFrame2); h.concatenateValHR = uicontrol('style','tex',... 'position',[126,361,65,15],... 'BackgroundColor','white',... 'HorizontalAlignment','left',... 'string',{num2str(H(h.indxr))},... 'parent',h.concatenateFrame2); % creates the panel for Hdiff h.concatenatePanelHdiff = uicontrol('style','frame',... 'position',[200,360,67,17],... 'parent',h.concatenateFrame2); h.concatenateValHdiff = uicontrol('style','tex',... 'position',[201,361,65,15],... 'BackgroundColor','white',... 'HorizontalAlignment','left',... 'string',{num2str(H(h.indxr) - H(h.indxl))},... 'parent',h.concatenateFrame2); % creates the panel for Havg h.concatenatePanelHavg = uicontrol('style','frame',... 'position',[275,360,67,17],... 'parent',h.concatenateFrame2); h.concatenateValHavg = uicontrol('style','tex',... 'position',[276,361,65,15],... 'BackgroundColor','white',... 'HorizontalAlignment','left',... 'string',{num2str(h.Havg)},... 'parent',h.concatenateFrame2); % creates the panel for Hdev h.concatenatePanelHdev = uicontrol('style','frame',... 'position',[350,360,67,17],... 'parent',h.concatenateFrame2); h.concatenateValHdev = uicontrol('style','tex',... 'position',[351,361,65,15],... 'BackgroundColor','white',... 'HorizontalAlignment','left',... 'string',{num2str(h.Hstd)},... 'parent',h.concatenateFrame2); % creates the panel for Ra h.concatenatePanelRa = uicontrol('style','frame',... 'position',[425,360,67,17],... 'parent',h.concatenateFrame2); h.concatenateValRa = uicontrol('style','tex',... 'position',[426,361,65,15],... 'BackgroundColor','white',... 'HorizontalAlignment','left',... 'string',{num2str(h.Ra)},... 'parent',h.concatenateFrame2); end set(h.concatenateFig,'CloseRequestFcn',{@closeHardFig,h}); set(h.concatenateFrame2Slide,'callback',{@scrollBar,h}); % ensures latest handles are reloaded plotData(hObject,eventdata,h,filename,X,H,scanmode); filename = [filename,{'0'},{'0'}]; set(h.menuFileOpen,'callback',{@loadFile,h}); set(h.buttonScan,'callback',{@scanData,h}); set(h.menuFileQuit,'callback',{@quitProgram,h}); set(h.concatenateCloseButton,'callback',{@cancelFig,h}); set(h.concatenateSaveButton,'callback',{@saveData,h,X,H,filename,scanmode}); set(h.concatenateFig,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % clears h.concatenateFig so the concatenate menu can be reloaded % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function closeHardFig(hObject,eventdata,h) set(h.concatenateFig,'Visible','off'); rmfield(h,'concatenateFig'); % sets arbitrary value for hObject to return handle h hObject = h.showXdiffTitle1; guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % function to control scrollbar % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function scrollBar(hObject,eventdata,h) % gets the current position of the sliding frame sliderPos = get(h.concatenateFrame2,'position'); % gets the current position of the slider (between 0 and 1) val = get(hObject,'Value'); % sets new position based on scrollbar position change = [sliderPos(1),(1-sliderPos(4))*val,sliderPos(3),sliderPos(4)]; set(h.concatenateFrame2,'units','normalized','position',change); %plotData(hObject,eventdata,h,h.filename,h.X,h.H,h.scanmode); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % if "Hl" checkbox is selected % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function paramHl(hObject,eventdata,h,hh,filename,X,H,scanmode) % if checked = 1, box is checked; if checked = 0, box is unchecked checked = get(hObject,'value'); if checked % box checked set(hh.checkboxHR,'Enable','off'); set(hh.checkboxHdiff,'Enable','off'); set(hh.checkboxHavg,'Enable','off'); set(hh.checkboxHdev,'Enable','off'); set(hh.checkboxRa,'Enable','off'); set(hh.checkboxH,'Enable','off'); h.lpoint = h.Xalt(1); h.rpoint = h.Xalt(end); h.plotHl = true; else % box unchecked set(hh.checkboxHR,'Enable','on'); set(hh.checkboxHdiff,'Enable','on'); set(hh.checkboxHavg,'Enable','on'); set(hh.checkboxHdev,'Enable','on'); set(hh.checkboxRa,'Enable','on'); set(hh.checkboxH,'Enable','on'); h.lpoint = X(1); h.rpoint = X(end); h.plotHl = false; end set(hh.paramPlotButton,'callback',{@plotData,h,filename,X,H,scanmode}); guidata(hObject,h) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % if "Hr" checkbox is selected % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function paramHr(hObject,eventdata,h,hh,filename,X,H,scanmode) % if checked = 1, box is checked; if checked = 0, box is unchecked checked = get(hObject,'value'); if checked % box checked set(hh.checkboxHL,'Enable','off'); set(hh.checkboxHdiff,'Enable','off'); set(hh.checkboxHavg,'Enable','off'); set(hh.checkboxHdev,'Enable','off'); set(hh.checkboxRa,'Enable','off'); set(hh.checkboxH,'Enable','off'); h.lpoint = h.Xalt(1); h.rpoint = h.Xalt(end); h.plotHr = true; else % box unchecked set(hh.checkboxHL,'Enable','on'); set(hh.checkboxHdiff,'Enable','on'); set(hh.checkboxHavg,'Enable','on'); set(hh.checkboxHdev,'Enable','on'); set(hh.checkboxRa,'Enable','on'); set(hh.checkboxH,'Enable','on'); h.lpoint = X(1); h.rpoint = X(end); h.plotHr = false; end set(hh.paramPlotButton,'callback',{@plotData,h,filename,X,H,scanmode}); guidata(hObject,h) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % if "Hdiff" checkbox is selected % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function paramHdiff(hObject,eventdata,h,hh,filename,X,H,scanmode) % if checked = 1, box is checked; if checked = 0, box is unchecked checked = get(hObject,'value'); if checked % box checked set(hh.checkboxHL,'Enable','off'); set(hh.checkboxHR,'Enable','off'); set(hh.checkboxHavg,'Enable','off'); set(hh.checkboxHdev,'Enable','off'); set(hh.checkboxRa,'Enable','off'); set(hh.checkboxH,'Enable','off'); h.lpoint = h.Xalt(1); h.rpoint = h.Xalt(end); h.plotHdiff = true; else % box unchecked set(hh.checkboxHL,'Enable','on'); set(hh.checkboxHR,'Enable','on'); set(hh.checkboxHavg,'Enable','on'); set(hh.checkboxHdev,'Enable','on'); set(hh.checkboxRa,'Enable','on'); set(hh.checkboxH,'Enable','on'); h.lpoint = X(1); h.rpoint = X(end); hh.plotHdiff = false; end set(hh.paramPlotButton,'callback',{@plotData,h,filename,X,H,scanmode}); guidata(hObject,h) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % if "Havg" checkbox is selected % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function paramHavg(hObject,eventdata,h,hh,filename,X,H,scanmode) % if checked = 1, box is checked; if checked = 0, box is unchecked checked = get(hObject,'value'); val1 = get(hh.checkboxHavg,'value'); val2 = get(hh.checkboxHdev,'value'); val3 = get(hh.checkboxRa,'value'); totVal = val1+val2+val3; if get(hh.checkboxHavg,'value') h.plotHavg = true; elseif ~get(hh.checkboxHavg,'value') h.plotHavg = false; end if get(hh.checkboxHdev,'value') h.plotHdev = true; elseif ~get(hh.checkboxHdev,'value') h.plotHdev = false; end if get(hh.checkboxRa,'value') h.plotRa = true; elseif ~get(hh.checkboxRa,'value') h.plotRa = false; end if checked % box checked set(hh.checkboxHL,'Enable','off'); set(hh.checkboxHR,'Enable','off'); set(hh.checkboxHdiff,'Enable','off'); set(hh.checkboxH,'Enable','off'); h.lpoint = h.Xalt(1); h.rpoint = h.Xalt(end); elseif totVal == 0 % box unchecked set(hh.checkboxHL,'Enable','on'); set(hh.checkboxHR,'Enable','on'); set(hh.checkboxHdiff,'Enable','on'); set(hh.checkboxH,'Enable','on'); h.lpoint = X(1); h.rpoint = X(end); end set(hh.paramPlotButton,'callback',{@plotData,h,filename,X,H,scanmode}); guidata(hObject,h) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % if "H" checkbox is selected % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function paramH(hObject,eventdata,h,hh,filename,X,H,scanmode) % if checked = 1, box is checked; if checked = 0, box is unchecked checked = get(hObject,'value'); if checked % box checked set(hh.checkboxHL,'Enable','off'); set(hh.checkboxHR,'Enable','off'); set(hh.checkboxHdiff,'Enable','off'); set(hh.checkboxHavg,'Enable','off'); set(hh.checkboxHdev,'Enable','off'); set(hh.checkboxRa,'Enable','off'); h.lpoint = h.Xalt(1); h.rpoint = h.Xalt(end); h.plotH = true; else % box unchecked set(hh.checkboxHL,'Enable','on'); set(hh.checkboxHR,'Enable','on'); set(hh.checkboxHdiff,'Enable','on'); set(hh.checkboxHavg,'Enable','on'); set(hh.checkboxHdev,'Enable','on'); set(hh.checkboxRa,'Enable','on'); h.lpoint = X(1); h.rpoint = X(end); h.plotH = false; end set(hh.paramPlotButton,'callback',{@plotData,h,filename,X,H,scanmode}); guidata(hObject,h) %%%%%%%%%%%%%%%%%%%%%%%%%%% % opens the help document % %%%%%%%%%%%%%%%%%%%%%%%%%%% function helpDoc(hObject,eventdata,h) compType = computer; if strcmpi(compType,'GLNX86') || strcmpi(compType,'GLNXI64') || strcmpi(compType,'HPUX') % if Linux or Unix port = '/dev/ttyS0'; elseif strcmpi(compType,'SOL2') % if Solaris port = '/dev/term/a'; elseif strcmpi(compType,'MAC') % if Mac OS X port = '/dev/tty.KeySerial1'; elseif strcmpi(compType,'PCWIN') % if Microsoft Windows port = 'COM1'; end helpFile = which('help.pdf'); cantOpen = false; if ~isempty(helpFile) if strcmpi(compType,'GLNX86') || strcmpi(compType,'GLNXI64') || strcmpi(compType,'HPUX') || strcmpi(compType,'MAC') % for Linux, Unix, Mac [a,b] = system(['xdg-open "',helpFile,'" &']); if ~isempty(b) cantOpen = true; end elseif strcmpi(compType,'PCWIN') % for Microsoft Windows [a,b] = system(['start "',helpFile,'"']); if ~isempty(b) cantOpen = true; end end else % can't find help.pdf startPos = get(h.fig,'position'); h.cantFindFig = figure('position',[startPos(1)+(startPos(3)-200)/2 startPos(2)+(startPos(4)-100)/2 200 100],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain,... 'Name','Cannot Locate'); h.cantFindText = uicontrol('style','tex',... 'position',[10,10,180,80],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','center',... 'string','The help document ''help.pdf'' could not be located.'); h.cantFindPushbutton = uicontrol('style','pushbutton',... 'position',[65 10 70 25],... 'BackgroundColor',h.colorSecondary,... 'string','OK'); set(h.cantFindPushbutton,'callback',{@cancelFig,h}); set(h.cantFindFig,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); end startPos = get(h.fig,'position'); if cantOpen h.cantOpenFig = figure('position',[startPos(1)+(startPos(3)-200)/2 startPos(2)+(startPos(4)-100)/2 200 100],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color',h.colorMain,... 'Name','Cannot Open'); h.cantOpenText = uicontrol('style','tex',... 'position',[10,10,180,80],... 'BackgroundColor',h.colorMain,... 'HorizontalAlignment','center',... 'string','An appropriate application was not identified to open the help document.'); h.cantOpenPushbutton = uicontrol('style','pushbutton',... 'position',[65 10 70 25],... 'BackgroundColor',h.colorSecondary,... 'string','OK'); set(h.cantOpenPushbutton,'callback',{@cancelFig,h}); set(h.cantOpenFig,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); end guidata(hObject,h); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % opens information about Profilometer GUI % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function helpAbout(hObject,eventdata,h) startPos = get(h.fig,'position'); h.figHelpAbout = figure('position',[startPos(1)+(startPos(3)-300)/2 startPos(2)+(startPos(4)-332)/2 300 332],... 'menubar','none',... 'numbertitle','off',... 'resize','off',... 'Color','white',... 'DockControls','off',... 'Name','About Profilometer GUI'); h.helpAboutTitle = uicontrol('style','tex',... 'position',[20 302 280 14],... 'parent',h.figHelpAbout,... 'BackGroundColor','white',... 'HorizontalAlignment','left',... 'FontWeight','bold',... 'FontSize',12,... 'string','Profilometer GUI 0.1'); h.helpAboutDate = uicontrol('style','tex',... 'position',[20 282 280 14],... 'parent',h.figHelpAbout,... 'BackGroundColor','white',... 'HorizontalAlignment','left',... 'FontSize',10,... 'string','December 22, 2009'); h.helpAboutAuthor = uicontrol('style','tex',... 'position',[20 242 280 14],... 'parent',h.figHelpAbout,... 'BackGroundColor','white',... 'HorizontalAlignment','left',... 'FontSize',10,... 'string','Mark Hamblin'); h.helpAboutEmail = uicontrol('style','tex',... 'position',[20 222 280 14],... 'parent',h.figHelpAbout,... 'BackGroundColor','white',... 'HorizontalAlignment','left',... 'FontSize',10,... 'string','marknhamblin@gmail.com'); h.helpAboutLab = uicontrol('style','tex',... 'position',[20 202 280 14],... 'parent',h.figHelpAbout,... 'BackGroundColor','white',... 'HorizontalAlignment','left',... 'FontSize',10,... 'string','Integrated Microfabrication Laboratory'); h.helpAboutInst = uicontrol('style','tex',... 'position',[20 182 280 14],... 'parent',h.figHelpAbout,... 'BackGroundColor','white',... 'HorizontalAlignment','left',... 'FontSize',10,... 'string','Brigham Young University'); h.helpAboutLocation = uicontrol('style','tex',... 'position',[20 162 280 14],... 'parent',h.figHelpAbout,... 'BackGroundColor','white',... 'HorizontalAlignment','left',... 'FontSize',10,... 'string','Provo, UT 84602'); h.helpAboutCreate = uicontrol('style','tex',... 'position',[20 122 280 14],... 'parent',h.figHelpAbout,... 'BackGroundColor','white',... 'HorizontalAlignment','left',... 'FontSize',10,... 'string','Created using Matlab 7.0 (R14)'); h.helpAboutPurpose = uicontrol('style','tex',... 'position',[20 20 260 76],... 'parent',h.figHelpAbout,... 'BackGroundColor','white',... 'HorizontalAlignment','left',... 'FontSize',10,... 'string','Profilometer GUI is designed to read-in data from a serial port connected to a Tencor AlphaStep 200. Profilometer GUI can also analyze saved data files as well as concatenate measurements into a single file.'); set(h.figHelpAbout,'KeyPressFcn',{@escFigure,hObject,eventdata,h}); guidata(hObject,h); %%%%%%%%%%%%%%%%%%%% % quit the program % %%%%%%%%%%%%%%%%%%%% function quitProgram(hObject,eventdata,h) % ensures that serial port is closed before program ends status = get(h.scanStatus,'string'); if strcmpi(status,'waiting'); % cancels active scan % closes serial port and returns resources fclose(h.serialOne); delete(h.serialOne); clear h.serialOne; set(h.scanStatus,'BackgroundColor',[0.75 0.75 0.95]); set(h.scanStatus,'string','idle'); end close(h.fig);