Home > src > createPop_Dialog.m

createPop_Dialog

PURPOSE ^

- create population dialog

SYNOPSIS ^

function varargout = createPop_Dialog(varargin)

DESCRIPTION ^

 - create population 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 population 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 
0025 function varargout = createPop_Dialog(varargin)
0026 % CREATEPOP_DIALOG M-file for createPop_Dialog.fig
0027 %      CREATEPOP_DIALOG, by itself, creates a new CREATEPOP_DIALOG or raises the existing
0028 %      singleton*.
0029 %
0030 %      H = CREATEPOP_DIALOG returns the handle to a new CREATEPOP_DIALOG or the handle to
0031 %      the existing singleton*.
0032 %
0033 %      CREATEPOP_DIALOG('CALLBACK',hObject,eventData,handles,...) calls the local
0034 %      function named CALLBACK in CREATEPOP_DIALOG.M with the given input arguments.
0035 %
0036 %      CREATEPOP_DIALOG('Property','Value',...) creates a new CREATEPOP_DIALOG or raises the
0037 %      existing singleton*.  Starting from the left, property value pairs are
0038 %      applied to the GUI before createPop_Dialog_OpeningFcn gets called.  An
0039 %      unrecognized property name or invalid value makes property application
0040 %      stop.  All inputs are passed to createPop_Dialog_OpeningFcn via varargin.
0041 %
0042 %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
0043 %      instance to run (singleton)".
0044 %
0045 % See also: GUIDE, GUIDATA, GUIHANDLES
0046 
0047 % Edit the above text to modify the response to help createPop_Dialog
0048 
0049 % Last Modified by GUIDE v2.5 07-Sep-2010 10:08:10
0050 
0051 % Begin initialization code - DO NOT EDIT
0052 gui_Singleton = 1;
0053 gui_State = struct('gui_Name',       mfilename, ...
0054                    'gui_Singleton',  gui_Singleton, ...
0055                    'gui_OpeningFcn', @createPop_Dialog_OpeningFcn, ...
0056                    'gui_OutputFcn',  @createPop_Dialog_OutputFcn, ...
0057                    'gui_LayoutFcn',  [] , ...
0058                    'gui_Callback',   []);
0059 if nargin && ischar(varargin{1})
0060     gui_State.gui_Callback = str2func(varargin{1});
0061 end
0062 
0063 if nargout
0064     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0065 else
0066     gui_mainfcn(gui_State, varargin{:});
0067 end
0068 % End initialization code - DO NOT EDIT
0069 
0070 
0071 % --- Executes just before createPop_Dialog is made visible.
0072 function createPop_Dialog_OpeningFcn(hObject, eventdata, handles, varargin)
0073 % This function has no output args, see OutputFcn.
0074 % hObject    handle to figure
0075 % eventdata  reserved - to be defined in a future version of MATLAB
0076 % handles    structure with handles and user data (see GUIDATA)
0077 % varargin   command line arguments to createPop_Dialog (see VARARGIN)
0078 
0079 % Choose default command line output for createPop_Dialog
0080 handles.output = hObject;
0081 
0082 % Update handles structure
0083 guidata(hObject, handles);
0084 
0085 % UIWAIT makes createPop_Dialog wait for user response (see UIRESUME)
0086 % uiwait(handles.figure_createPop);
0087 
0088 
0089 % --- Outputs from this function are returned to the command line.
0090 function varargout = createPop_Dialog_OutputFcn(hObject, eventdata, handles) 
0091 % varargout  cell array for returning output args (see VARARGOUT);
0092 % hObject    handle to figure
0093 % eventdata  reserved - to be defined in a future version of MATLAB
0094 % handles    structure with handles and user data (see GUIDATA)
0095 
0096 % Get default command line output from handles structure
0097 varargout{1} = handles.output;
0098 
0099 
0100 % --- Executes on button press in pushbutton_setPopSrc.
0101 function pushbutton_setPopSrc_Callback(hObject, eventdata, handles)
0102 % hObject    handle to pushbutton_setPopSrc (see GCBO)
0103 % eventdata  reserved - to be defined in a future version of MATLAB
0104 % handles    structure with handles and user data (see GUIDATA)
0105 
0106     % let user navigate to the script to run
0107     [fileName,pathName] = uigetfile('*','Run Script...');
0108     
0109     % check to make sure user didn't cancel (which cases fileName == 0)
0110     if fileName ~= 0
0111         fullName = strcat(pathName,fileName);
0112 
0113         set(handles.text_PopSrc,'String',fullName);
0114     end
0115     
0116 
0117 % --- Executes on button press in pushbutton_createPop.
0118 function pushbutton_createPop_Callback(hObject, eventdata, handles)
0119 % hObject    handle to pushbutton_createPop (see GCBO)
0120 % eventdata  reserved - to be defined in a future version of MATLAB
0121 % handles    structure with handles and user data (see GUIDATA)
0122     
0123     makeObj = true;
0124     % do basic validation on each variable
0125     src = get(handles.text_PopSrc,'String');
0126     
0127     
0128     if isempty(src)
0129         msgbox('You must specify the source data for the population',...
0130                 'Missing source file!');        
0131        makeObj = false;  
0132     end
0133     
0134     
0135     varName = get(handles.edit_popName,'String');
0136 
0137     valid = regexp(varName,'^[a-zA-Z]+\w*$');
0138     
0139 
0140     % check if the pointer is valid, but only if the src is valid so as to
0141     % not clutter the user with msgboxes
0142     if isempty(valid) && makeObj == true
0143         % name is not currently valid, tell the user.
0144         msgbox('Only letters, numbers, and underscores are permitted in the name of the population object.  The first character must also be a letter.',...
0145                 'Invalid name!');
0146         makeObj = false;
0147             
0148     end
0149     
0150     
0151     % get header and formatting switches, in string form
0152     % these data must always have reasonable values
0153     header = get(get(handles.uipanel_containsHeader,'SelectedObject'),...
0154                 'String');
0155     format = get(get(handles.uipanel_containsFormatting,'SelectedObject'),...
0156                 'String');            
0157     
0158     % the outfile will either have been set by the user to a reasonable
0159     % state via the GUI, or will be empty and the default value will be
0160     % substituted.
0161     outFile = get(handles.text_resPopOutfile,'String');
0162     
0163     % fill in outFile if it was left blank.
0164     if isempty(outFile)
0165         outFile = strcat(varName,'.res.out.txt');
0166     end
0167     
0168     if makeObj == true
0169         % the command to run to create a population
0170         command = strcat(varName,'=','population(''',src,''',''isHeader'',',...
0171                 header,',''isFormatting'',',format,',''outFile'',''',outFile,...
0172                 ''',''name'',''',varName,''');'); %'',''isHeader''',...
0173               %  header);
0174 
0175         verbosePrint(['Executing command: ','''',command,''''],'createPop_Dialog_Create');
0176         evalin('base',command);
0177         
0178         
0179         
0180         close(handles.figure_createPop);
0181     end
0182     
0183 
0184 function edit_popName_Callback(hObject, eventdata, handles)
0185 % hObject    handle to edit_popName (see GCBO)
0186 % eventdata  reserved - to be defined in a future version of MATLAB
0187 % handles    structure with handles and user data (see GUIDATA)
0188 
0189 % Hints: get(hObject,'String') returns contents of edit_popName as text
0190 %        str2double(get(hObject,'String')) returns contents of edit_popName as a double
0191 
0192     varName = get(hObject,'String');
0193     
0194     %check to make sure that the name is a valid variable name:
0195     valid = regexp(varName,'^[a-zA-Z]+\w*$');
0196     
0197 
0198     if isempty(valid)
0199         % name is not currently valid, tell the user.
0200         msgbox('Only letters, numbers, and underscores are permitted in the name of the population object.  The first character must also be a letter.',...
0201                 'Invalid name!');
0202     else
0203         % check to make sure that the new variable name doesn't already exist.
0204         command = strcat('whos(''',varName,''')');
0205         varExists = evalin('base',command);
0206 
0207 
0208         % if a variable with this name already exists, warns the user
0209         if isempty(varExists) == 0
0210             msgbox('A population with this name already exists and will be overridden if you continue',...
0211                     'Population exists!');
0212         end
0213     end
0214         
0215         
0216         
0217     
0218 % --- Executes during object creation, after setting all properties.
0219 function edit_popName_CreateFcn(hObject, eventdata, handles)
0220 % hObject    handle to edit_popName (see GCBO)
0221 % eventdata  reserved - to be defined in a future version of MATLAB
0222 % handles    empty - handles not created until after all CreateFcns called
0223 
0224 % Hint: edit controls usually have a white background on Windows.
0225 %       See ISPC and COMPUTER.
0226 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0227     set(hObject,'BackgroundColor','white');
0228 end
0229 
0230 
0231 
0232 function edit1_Callback(hObject, eventdata, handles)
0233 % hObject    handle to edit1 (see GCBO)
0234 % eventdata  reserved - to be defined in a future version of MATLAB
0235 % handles    structure with handles and user data (see GUIDATA)
0236 
0237 % Hints: get(hObject,'String') returns contents of edit1 as text
0238 %        str2double(get(hObject,'String')) returns contents of edit1 as a double
0239 
0240 
0241 % --- Executes during object creation, after setting all properties.
0242 function edit1_CreateFcn(hObject, eventdata, handles)
0243 % hObject    handle to edit1 (see GCBO)
0244 % eventdata  reserved - to be defined in a future version of MATLAB
0245 % handles    empty - handles not created until after all CreateFcns called
0246 
0247 % Hint: edit controls usually have a white background on Windows.
0248 %       See ISPC and COMPUTER.
0249 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0250     set(hObject,'BackgroundColor','white');
0251 end
0252 
0253 
0254 % --- Executes on button press in pushbutton_setResPopOutfile.
0255 function pushbutton_setResPopOutfile_Callback(hObject, eventdata, handles)
0256 % hObject    handle to pushbutton_setResPopOutfile (see GCBO)
0257 % eventdata  reserved - to be defined in a future version of MATLAB
0258 % handles    structure with handles and user data (see GUIDATA)
0259 
0260     [fileName,pathName] = uiputfile('*','Save residual population as...');
0261     
0262     % check to make sure user didn't cancel (which cases fileName == 0)
0263     if fileName ~= 0
0264         fullName = strcat(pathName,fileName);
0265     
0266         set(handles.text_resPopOutfile,'String',fullName);  
0267     end

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