function notice(varargin)
%NOTICE Message box.
%  NOTICE(Message) creates a message box that automatically wraps the
%  Message to fit an appropriately sized Figure.  Message is a string
%  vector, string matrix or cell array.
%
%  NOTICE(Message,Title) specifies the title of the message box.
%
%  NOTICE(Message, ... ,Duration) scalar specifies duration of pause
%  before notice is removed. Time in seconds (1.5 = default)
  
%  Modeled after msgbox.m   12/'00


% Check input
%-------------------------------------------------------------------------
if nargin<1,error('Too few input arguments for NOTICE.');end  
  
BodyTextString=varargin{1};
if ~iscell(BodyTextString),BodyTextString=cellstr(BodyTextString);end

if nargin>3, error('Too many input arguments for NOTICE.'); end

Duration = 1.5 ;
switch nargin,
  case 1,
    TitleString=' ';   
  case 2,
     if isnumeric(varargin{2}) 
        Duration = (varargin{2});
        TitleString = ' '; 
     else,
        TitleString = varargin{2};
     end     
  case 3,
     if isnumeric(varargin{3})
        TitleString = varargin{2}; 
        Duration = varargin{3};
     else
        error('Invalid "Duration" entered');
        help notice;
        return;
     end
end  %switch
  

% Set positions
%-------------------------------------------------------------------------
MsgOff=7;
FigWidth=125;
MsgTxtWidth=FigWidth + MsgOff;
FigHeight=50;

MsgTxtXOffset=MsgOff;
MsgTxtYOffset=MsgOff;
MsgTxtHeight=FigHeight-MsgOff-MsgTxtYOffset;

% Create
%-------------------------------------------------------------------------
BoxHandle=dialog(                               ...
   'Name'            ,TitleString             , ...
   'Pointer'         ,'arrow'                 , ...
   'Units'           ,'points'                , ...
   'Visible'         ,'off'                   , ...
   'WindowStyle'     ,'modal'                 , ...
   'Color'           ,[.92 .92 .97]           , ...
   'HandleVisibility','callback'                ...
   );

Font.FontUnits='points';
Font.FontSize=get(0,'FactoryUIControlFontSize')+4;
                                   
MsgHandle=uicontrol(BoxHandle     , Font, ...
   'Style'              ,'text'         , ...
   'Units'              ,'points'       , ...
   'Position'           ,[MsgTxtXOffset   ...
                            MsgTxtYOffset ...
                            MsgTxtWidth   ...
                            MsgTxtHeight  ...
                         ]              , ...
   'String'             ,' '            , ...
   'HorizontalAlignment','left'         , ...    
   'BackgroundColor'    ,[.92 .92 .97]  , ...
   'ForegroundColor'    ,'k'              ...
   );


[WrapString,NewMsgTxtPos]=textwrap(MsgHandle,BodyTextString,75);
NumLines=size(WrapString,1);

MsgTxtWidth=max(MsgTxtWidth,NewMsgTxtPos(3))+5;
MsgTxtHeight=max(MsgTxtHeight,NewMsgTxtPos(4));

FigWidth=MsgTxtWidth+2*MsgOff;  
MsgTxtYOffset=MsgOff*4;
FigHeight=MsgTxtYOffset+MsgTxtHeight+MsgOff;  

DefFigPos=get(0,'DefaultFigurePosition');
DefFigPos(3:4)=[FigWidth FigHeight];

ScreenUnits=get(0,'Units');
set(0,'Units','points');
ScreenSize=get(0,'ScreenSize');
set(0,'Units',ScreenUnits);

DefFigPos(1)=(ScreenSize(3)-FigWidth)/2;
DefFigPos(2)=(ScreenSize(4)-FigHeight)/2;

drawnow;
set(BoxHandle,'Position',DefFigPos);
  
delete(MsgHandle);
AxesHandle=axes('Parent',BoxHandle,'Position',[0 0 1 1],'Visible','off');

MsgHandle=text( ...
    'Parent'              ,AxesHandle                        , ...
    'Units'               ,'points'                          , ...
    'HorizontalAlignment' ,'left'                            , ...
    'VerticalAlignment'   ,'bottom'                          , ...
    'HandleVisibility'    ,'callback'                        , ...
    'Position'            ,[MsgTxtXOffset MsgTxtYOffset+5 0] , ...
    'String'              ,WrapString                        , ...
    'FontWeight'          ,'normal'                          , ...
    'FontSize'            , 13				     , ...
    'Interpreter'         ,'none'                              ...
    );

set(BoxHandle,'HandleVisibility','callback','Visible','on');
pause(Duration);
delete(BoxHandle);






