function [Answer,Canceled] = inputsdlg(Prompt, Title, Formats, DefAns, Options)
%INPUTSDLG Enhanced input dialog box supporting multiple data types
% ANSWER = INPUTSDLG(PROMPT) creates a modal dialog box that returns user
% input for multiple prompts in the cell array ANSWER. PROMPT is a 1-D
% cell array containing the PROMPT strings.
%
% Alternatively, PROMPT can have up to 4 columns. The first column
% sppecifies the prompt string. The second column to specify the struct
% field names to output ANSWER as a structure. The third column specifies
% units (i.e., post-fix labels to the right of controls) to display. The
% fourth column specifies the tooltip string. The tooltip string is ignored
% for text type.
%
% INPUTSDLG uses UIWAIT to suspend execution until the user responds.
%
% ANSWER = INPUTSDLG(PROMPT,NAME) specifies the title for the dialog.
%
% Note that INPUTSDLG(PROMPT) & INPUTSDLG(PROMPT,NAME) are similar to the
% standard INPUTDLG function, except for the dialog layout.
%
% ANSWER = INPUTSDLG(PROMPT,NAME,FORMATS) can be used to specify the type
% of parameters to display with FORMATS matrix of structures. The dimension
% of FORMATS defines how PROMPT items are laid out in the dialog box. For
% example, if PROMPT has 6 elements and the size of FORMATS is 2x3 then,
% the items are shown in 2 rows, 3 columns format. The items in PROMPT
% correspond to a horizontal traversal of FORMATS.
%
% The fields in FORMATS structure are:
%
% type - Type of control ['check',{'edit'},'list','range','text',
% 'color','table','button','none']
% style - UI control type used. One of:
% {'checkbox'}, for 'check' type
% {'edit'} for 'edit' type
% {'listbox','popupmenu','radiobutton','togglebutton'}
% for 'list' type
% {'slider'} for 'range' type
% {'text'} for 'text' type
% {'edit'} for 'color' type
% {'pushbutton'} for 'button' and 'color' types
% {'table'} for 'table' type
% format - Data format: ['text','date','float','integer','logical',
% 'vector','file','dir']
% limits - [min max] (see below for details)
% required - 'on' - control must have an answer
% {'off'} - control may return empty answer
% items - Type 'edit', Format 'file': File flter spec
% Type 'list': Selection items (cell of strings)
% Type 'table': Names of columns (cell of strings)
% Type 'range': Slider step size spec [minor major]
% size - [width height] in pixels. Set to <=0 to auto-size.
% enable - Defines how to respond to mouse button clicks, including which
% callback routines execute. One of:
% {'on'} - UI control is operational.
% 'inactive' ?UI control is not operational, but looks the
% same as when Enable is on.
% 'off' ?UI uicontrol is not operational and its image
% is grayed out.
% margin - A scalar or 2-element vector specifying the margin between control
% and its labels in pixels.
% labelloc - Prompt label location:
% {'lefttop'} - left of control, aligned to top
% 'leftmiddle' - left of control, aligned to middle
% 'leftbottom' - left of control, aligned to bottom
% 'topleft' - above control, aligned left
% 'topcenter' - above control, aligned center
% 'topright' - above control, aligned right
% unitsloc - Units label location:
% {'righttop'} - right of control, aligned to top
% 'rightmiddle' - right of control, aligned to middle
% 'rightbottom' - right of control, aligned to bottom
% 'bottomleft' - below control, aligned left
% 'bottomcenter' - below control, aligned center
% 'bottomright' - below control, aligned right
% callback - Defines callback funcion, a routine that executes whenever
% you activate the uicontrol object. For the controls with
% separate dialog, their callback functions are executed after
% the dialog is closed. The callback function must be given as
% a function handle with following syntax:
%
% my_callbackfcn(hobj,evt,handles,k)
%
% where hobj and evt are the passed-through standard MATLAB
% callback arguments, handles is a Nx3 array of dialog
% objects. Here, the n-th row corresponds to the n-th PROMPT,
% and handles(n,1) is the calling object handle (i.e., same as
% hobj). handles(n,2) are the prompt texts and handles(n,3)
% are the prompt unit texts.
%
% For example, Formats(n,m).callback.ButtonDownFcn sets the
% the button-press callback function.
% span - Defines size of objects in fields [rows columns]
%
% A missing field (either missing from FORMATS struct or the field value is
% left empty for an element) will be filled with a default field value.
%
% FORMATS type field defines what type of prompt item to be shown.
%
% type Description
% -------------------------------------------------------------------
% edit Standard edit box (single or multi-line mode)
% check Check box for boolean item
% list Chose from a list of items ('listbox' style allows multiple item
% selection)
% range Use slider to chose a value over a range
% text Static text (e.g., for instructions)
% color Color selection using 'uisetcolor'
% button Execute function defined in 'callback'
% table Uitable
% none A placeholder. May be used for its neighboring item to extend
% over multiple columns or rows (i.e., "to merge cells")
%
% The allowed data format depends on the type of the field:
%
% type allowed format
% --------------------------------------------
% check {logical}, integer, text
% edit {text}, date, float, integer, file, dir, vector
% list {integer}, text
% range {float}
% color {float}, integer
% table (a cell string to specify ColumnFormat of uiTable)
% button any data format allowed
%
% Formats 'file' and 'dir' for 'edit' type uses the standard UIGETFILE,
% UIPUTFILE, and UIGETDIR functions to retrieve a file or directory name.
%
% The role of limits field varies depending on other parameters:
%
% style role of limits
% ---------------------------------------------------
% checkbox If data format is integer, limits(1) is the ANSWER value
% if the check box is not selected box is not selected and
% limits(2) is the ANSWER if the check box is selected. If
% data format is text, its limits field must be given as a
% cellstring array.
% edit:text
% If diff(limits)>0, text aligns with the prompt label. If
% diff(limits)<0, tet aligns with the control.
% edit::date
% limits must be a free-format date format string or a
% scalar value specifying the date format. Supported format
% numbers are: 0,1,2,6,13,14,15,16,23. The default date
% format is 2 ('mm/dd/yy'). See the tables in DATESTR help
% for the format definitions. As long as the user entry is
% a valid date/time expression, the dialog box
% automatically converts to the assigned fo