Home > src > createSample_Dialog.m

createSample_Dialog

PURPOSE ^

- create sample dialog

SYNOPSIS ^

function varargout = createSample_Dialog(varargin)

DESCRIPTION ^

 - create sample dialog

 copyright 2009-2012 Blair Armstrong, Christine Watson, David Plaut

    This file is part of SOS

    SOS is free software: you can redistribute it and/or modify
    it for academic and non-commercial purposes
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.  For commercial or for-profit
    uses, please contact the authors (sos@cnbc.cmu.edu).

    SOS is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % - create sample dialog
0002 %
0003 % copyright 2009-2012 Blair Armstrong, Christine Watson, David Plaut
0004 %
0005 %    This file is part of SOS
0006 %
0007 %    SOS is free software: you can redistribute it and/or modify
0008 %    it for academic and non-commercial purposes
0009 %    under the terms of the GNU General Public License as published by
0010 %    the Free Software Foundation, either version 3 of the License, or
0011 %    (at your option) any later version.  For commercial or for-profit
0012 %    uses, please contact the authors (sos@cnbc.cmu.edu).
0013 %
0014 %    SOS is distributed in the hope that it will be useful,
0015 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 %    GNU General Public License for more details.
0018 
0019 %    You should have received a copy of the GNU General Public License
0020 %    along with SOS (see COPYING.txt).
0021 %    If not, see <http://www.gnu.org/licenses/>.
0022 
0023 
0024 function varargout = createSample_Dialog(varargin)
0025 % CREATESAMPLE_DIALOG M-file for createSample_Dialog.fig
0026 %      CREATESAMPLE_DIALOG, by itself, creates a new CREATESAMPLE_DIALOG or raises the existing
0027 %      singleton*.
0028 %
0029 %      H = CREATESAMPLE_DIALOG returns the handle to a new CREATESAMPLE_DIALOG or the handle to
0030 %      the existing singleton*.
0031 %
0032 %      CREATESAMPLE_DIALOG('CALLBACK',hObject,eventData,handles,...) calls the local
0033 %      function named CALLBACK in CREATESAMPLE_DIALOG.M with the given input arguments.
0034 %
0035 %      CREATESAMPLE_DIALOG('Property','Value',...) creates a new CREATESAMPLE_DIALOG or raises the
0036 %      existing singleton*.  Starting from the left, property value pairs are
0037 %      applied to the GUI before createSample_Dialog_OpeningFcn gets called.  An
0038 %      unrecognized property name or invalid value makes property application
0039 %      stop.  All inputs are passed to createSample_Dialog_OpeningFcn via varargin.
0040 %
0041 %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
0042 %      instance to run (singleton)".
0043 %
0044 % See also: GUIDE, GUIDATA, GUIHANDLES
0045 
0046 % Edit the above text to modify the response to help createSample_Dialog
0047 
0048 % Last Modified by GUIDE v2.5 07-Sep-2010 10:06:25
0049 
0050 % Begin initialization code - DO NOT EDIT
0051 gui_Singleton = 1;
0052 gui_State = struct('gui_Name',       mfilename, ...
0053                    'gui_Singleton',  gui_Singleton, ...
0054                    'gui_OpeningFcn', @createSample_Dialog_OpeningFcn, ...
0055                    'gui_OutputFcn',  @createSample_Dialog_OutputFcn, ...
0056                    'gui_LayoutFcn',  [] , ...
0057                    'gui_Callback',   []);
0058 if nargin && ischar(varargin{1})
0059     gui_State.gui_Callback = str2func(varargin{1});
0060 end
0061 
0062 if nargout
0063     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0064 else
0065     gui_mainfcn(gui_State, varargin{:});
0066 end
0067 % End initialization code - DO NOT EDIT
0068 
0069 
0070 % --- Executes just before createSample_Dialog is made visible.
0071 function createSample_Dialog_OpeningFcn(hObject, eventdata, handles, varargin)
0072 % This function has no output args, see OutputFcn.
0073 % hObject    handle to figure
0074 % eventdata  reserved - to be defined in a future version of MATLAB
0075 % handles    structure with handles and user data (see GUIDATA)
0076 % varargin   command line arguments to createSample_Dialog (see VARARGIN)
0077 
0078 % Choose default command line output for createSample_Dialog
0079 handles.output = hObject;
0080 
0081 % Update handles structure
0082 guidata(hObject, handles);
0083 
0084 % UIWAIT makes createSample_Dialog wait for user response (see UIRESUME)
0085 % uiwait(handles.figure_createSample);
0086 
0087 
0088 % --- Outputs from this function are returned to the command line.
0089 function varargout = createSample_Dialog_OutputFcn(hObject, eventdata, handles) 
0090 % varargout  cell array for returning output args (see VARARGOUT);
0091 % hObject    handle to figure
0092 % eventdata  reserved - to be defined in a future version of MATLAB
0093 % handles    structure with handles and user data (see GUIDATA)
0094 
0095 % Get default command line output from handles structure
0096 varargout{1} = handles.output;
0097 
0098 
0099 % --- Executes on button press in pushbutton_setSampleSrc.
0100 function pushbutton_setSampleSrc_Callback(hObject, eventdata, handles)
0101 % hObject    handle to pushbutton_setSampleSrc (see GCBO)
0102 % eventdata  reserved - to be defined in a future version of MATLAB
0103 % handles    structure with handles and user data (see GUIDATA)
0104 
0105     % let user navigate to the script to run
0106     [fileName,pathName] = uigetfile('*','Run Script...');
0107     
0108     % check to make sure user didn't cancel (which cases fileName == 0)
0109     if fileName ~= 0
0110         fullName = strcat(pathName,fileName);
0111 
0112         set(handles.text_SampleSrc,'String',fullName);
0113     end
0114     
0115 
0116 % --- Executes on button press in pushbutton_createSample.
0117 function pushbutton_createSample_Callback(hObject, eventdata, handles)
0118 % hObject    handle to pushbutton_createSample (see GCBO)
0119 % eventdata  reserved - to be defined in a future version of MATLAB
0120 % handles    structure with handles and user data (see GUIDATA)
0121     
0122     makeObj = true;
0123     noSrc = false; % is there a sample src file
0124     
0125     % do basic validation on each variable
0126     
0127     %get number of items
0128     n = get(handles.edit_n,'String');
0129     valid = regexp(n,'^[1-9]+[0-9]*$');
0130     
0131 
0132     if isempty(valid)
0133         % name is not currently valid, tell the user.
0134         msgbox('Sample size must be a whole number > 0',...
0135                 'Invalid sample size!');
0136         makeObj = false;
0137     end
0138     
0139     % validate the object name
0140     varName = get(handles.edit_sampleName,'String');
0141     valid = regexp(varName,'^[a-zA-Z]+\w*$');
0142     
0143 
0144     % check if the pointer is valid, but only if n is valid so as to
0145     % not clutter the user with msgboxes
0146     if isempty(valid) && makeObj == true
0147         % name is not currently valid, tell the user.
0148         msgbox('Only letters, numbers, and underscores are permitted in the name of the sample object.  The first character must also be a letter.',...
0149                 'Invalid name!');
0150         makeObj = false;            
0151     end    
0152     
0153     % get src
0154     src = get(handles.text_SampleSrc,'String');
0155     
0156     if isempty(src)
0157         noSrc = true;
0158     end
0159     
0160 
0161     % get header and formatting switches, in string form
0162     % these data must always have reasonable values
0163     header = get(get(handles.uipanel_containsHeader,'SelectedObject'),...
0164                 'String');
0165     format = get(get(handles.uipanel_containsFormatting,'SelectedObject'),...
0166                 'String');            
0167     
0168     % the outfile will either have been set by the user to a reasonable
0169     % state via the GUI, or will be empty and the default value will be
0170     % substituted.
0171     outFile = get(handles.text_sampleOutfile,'String');
0172     
0173     % fill in outFile if it was left blank.
0174     if isempty(outFile)
0175         outFile = strcat(varName,'.out.txt');
0176     end
0177     
0178     if makeObj == true
0179         % a sample will be created:
0180         
0181         % the command to run to create a sample
0182         command = strcat(varName,'=','sample(',num2str(n),',''isHeader'',',...
0183                 header,',''isFormatting'',',format,',''outFile'',''',outFile,...
0184                 ''',''name'',','''',varName,''''); 
0185         
0186         %tweak the end of the command based on whether a partial sample
0187         %will be read in or not.
0188 
0189         if noSrc == true
0190             command = strcat(command,');');
0191         else
0192             command = strcat(command,',''fileName'',''',src,''');');
0193         end
0194         
0195         verbosePrint(['Executing command: ','''',command,''''],'createSample_Dialog_Create');
0196         evalin('base',command);
0197         
0198         close(handles.figure_createSample);
0199     end
0200     
0201 
0202 function edit_sampleName_Callback(hObject, eventdata, handles)
0203 % hObject    handle to edit_sampleName (see GCBO)
0204 % eventdata  reserved - to be defined in a future version of MATLAB
0205 % handles    structure with handles and user data (see GUIDATA)
0206 
0207 % Hints: get(hObject,'String') returns contents of edit_sampleName as text
0208 %        str2double(get(hObject,'String')) returns contents of edit_sampleName as a double
0209 
0210     varName = get(hObject,'String');
0211     
0212     %check to make sure that the name is a valid variable name:
0213     valid = regexp(varName,'^[a-zA-Z]+\w*$');
0214     
0215 
0216     if isempty(valid)
0217         % name is not currently valid, tell the user.
0218         msgbox('Only letters, numbers, and underscores are permitted in the name of the sample object.  The first character must also be a letter.',...
0219                 'Invalid name!');
0220     else
0221         % check to make sure that the new variable name doesn't already exist.
0222         command = strcat('whos(''',varName,''')');
0223         varExists = evalin('base',command);
0224 
0225 
0226         % if a variable with this name already exists, warns the user
0227         if isempty(varExists) == 0
0228             msgbox('A sample with this name already exists and will be overridden if you continue',...
0229                     'Sample exists!');
0230         end
0231     end
0232         
0233         
0234         
0235     
0236 % --- Executes during object creation, after setting all properties.
0237 function edit_sampleName_CreateFcn(hObject, eventdata, handles)
0238 % hObject    handle to edit_sampleName (see GCBO)
0239 % eventdata  reserved - to be defined in a future version of MATLAB
0240 % handles    empty - handles not created until after all CreateFcns called
0241 
0242 % Hint: edit controls usually have a white background on Windows.
0243 %       See ISPC and COMPUTER.
0244 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0245     set(hObject,'BackgroundColor','white');
0246 end
0247 
0248 
0249 
0250 function edit1_Callback(hObject, eventdata, handles)
0251 % hObject    handle to edit1 (see GCBO)
0252 % eventdata  reserved - to be defined in a future version of MATLAB
0253 % handles    structure with handles and user data (see GUIDATA)
0254 
0255 % Hints: get(hObject,'String') returns contents of edit1 as text
0256 %        str2double(get(hObject,'String')) returns contents of edit1 as a double
0257 
0258 
0259 % --- Executes during object creation, after setting all properties.
0260 function edit1_CreateFcn(hObject, eventdata, handles)
0261 % hObject    handle to edit1 (see GCBO)
0262 % eventdata  reserved - to be defined in a future version of MATLAB
0263 % handles    empty - handles not created until after all CreateFcns called
0264 
0265 % Hint: edit controls usually have a white background on Windows.
0266 %       See ISPC and COMPUTER.
0267 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0268     set(hObject,'BackgroundColor','white');
0269 end
0270 
0271 
0272 % --- Executes on button press in pushbutton_setSampleOutfile.
0273 function pushbutton_setSampleOutfile_Callback(hObject, eventdata, handles)
0274 % hObject    handle to pushbutton_setSampleOutfile (see GCBO)
0275 % eventdata  reserved - to be defined in a future version of MATLAB
0276 % handles    structure with handles and user data (see GUIDATA)
0277 
0278     [fileName,pathName] = uiputfile('*','Save optimized sample as...');
0279     
0280     % check to make sure user didn't cancel (which cases fileName == 0)
0281     if fileName ~= 0
0282         fullName = strcat(pathName,fileName);
0283     
0284         set(handles.text_sampleOutfile,'String',fullName);  
0285     end
0286 
0287 
0288 
0289 function edit_n_Callback(hObject, eventdata, handles)
0290 % hObject    handle to edit_n (see GCBO)
0291 % eventdata  reserved - to be defined in a future version of MATLAB
0292 % handles    structure with handles and user data (see GUIDATA)
0293 
0294 % Hints: get(hObject,'String') returns contents of edit_n as text
0295 %        str2double(get(hObject,'String')) returns contents of edit_n as a double
0296 
0297     varName = get(hObject,'String');
0298     
0299     %check to make sure that the name is a valid variable name:
0300     valid = regexp(varName,'^[1-9]+[0-9]*$');
0301     
0302 
0303     if isempty(valid)
0304         % name is not currently valid, tell the user.
0305         msgbox('Sample size must be a whole number > 0',...
0306                 'Invalid sample size!');
0307     end
0308 
0309 
0310 
0311 % --- Executes during object creation, after setting all properties.
0312 function edit_n_CreateFcn(hObject, eventdata, handles)
0313 % hObject    handle to edit_n (see GCBO)
0314 % eventdata  reserved - to be defined in a future version of MATLAB
0315 % handles    empty - handles not created until after all CreateFcns called
0316 
0317 % Hint: edit controls usually have a white background on Windows.
0318 %       See ISPC and COMPUTER.
0319 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0320     set(hObject,'BackgroundColor','white');
0321 end

Generated on Fri 27-Jan-2012 16:18:41 by m2html © 2005