function PDESpecDraw(action,flag)

persistent specdraw_what specdraw_draw;
persistent specdraw_editx1 specdraw_editx2 specdraw_edity1 specdraw_edity2;
persistent specdraw_labelx1 specdraw_labelx2 specdraw_labely1 specdraw_labely2;
%persistent xmin xmax ymin ymax;

if(nargin<1)
  action='initialize';
end

if(strcmp(lower(action),'initialize'))
  specdraw_fig=figure;
  position=get(specdraw_fig,'Position');
  position=[position(1) position(2)+(1-.5)*position(4) ... 
            .3*position(3) .5*position(4)];
  set(specdraw_fig...
      ...%,'Visible','off'...
      ,'Tag','specdraw_fig'...
      ,'NumberTitle','off'...
      ,'Name','SpecifiedDraw'...
      ,'resize','on'...
      ,'MenuBar','none'...
      ,'Position',position...  
    );

specdraw_what=...
  uicontrol(specdraw_fig...
	    ,'Tag','specdraw_what'...
	    ,'Style','popupmenu'...
	    ,'Units','normalized'...
	    ,'Position',[0 .8 1 .2]...
	    ,'String','Rectangle|Ellipse'...
	    ,'FontUnits','normalized'...
	    ,'FontSize',.5 ...
	    ,'CallBack','PDESpecDraw(''specdraw_what'');'...
	    );

specdraw_draw=...
  uicontrol(specdraw_fig...
	    ,'Tag','specdraw_draw'...
	    ,'Style','pushbutton'...
	    ,'Units','normalized'...
	    ,'Position',[0 0 1 .2]...
	    ,'String','Draw'...
	    ,'FontUnits','normalized'...
	    ,'FontSize',.5 ...
	    ,'CallBack','PDESpecDraw(''specdraw_draw'');' ...
	    );

specdraw_editx1=...
  uicontrol(specdraw_fig...
	    ,'Tag','specdraw_editx1'...
	    ,'Style','Edit'...
	    ,'Units','normalized'...
	    ,'Position',[0 .5 .5 .2]...
	    ,'BackGroundColor',[1 1 1]...
	    ,'FontUnits','normalized'...
	    ,'FontSize',.5 ...
	    ,'String',num2str(0) ...
	    ,'CallBack','PDESpecDraw(''bound'',1);'...
	    );

specdraw_editx2=...
  uicontrol(specdraw_fig...
	    ,'Tag','specdraw_editx2'...
	    ,'Style','Edit'...
	    ,'Units','normalized'...
	    ,'Position',[0 .2 .5 .2]...
	    ,'BackGroundColor',[1 1 1]...
	    ,'FontUnits','normalized'...
	    ,'FontSize',.5 ...
	    ,'String',num2str(0) ...
	    ,'CallBack','PDESpecDraw(''bound'',2);'...
	    );

specdraw_edity1=...
  uicontrol(specdraw_fig...
	    ,'Tag','specdraw_edity1'...
	    ,'Style','Edit'...
	    ,'Units','normalized'...
	    ,'Position',[.5 .5 .5 .2]...
	    ,'BackGroundColor',[1 1 1]...
	    ,'FontUnits','normalized'...
	    ,'FontSize',.5 ...
	    ,'String',num2str(0) ...
	    ,'CallBack','PDESpecDraw(''bound'',3);'...
	    );

specdraw_edity2=...
  uicontrol(specdraw_fig...
	    ,'Tag','specdraw_edity2'...
	    ,'Style','Edit'...
	    ,'Units','normalized'...
	    ,'Position',[.5 .2 .5 .2]...
	    ,'BackGroundColor',[1 1 1]...
	    ,'FontUnits','normalized'...
	    ,'FontSize',.5 ...
	    ,'String',num2str(0) ...
	    ,'CallBack','PDESpecDraw(''bound'',4);'...
	    );

specdraw_labelx1=...
  uicontrol(specdraw_fig...
	    ,'Tag','specdraw_labelx1'...
	    ,'Style','text'...
	    ,'Units','normalized'...
	    ,'Position',[0 .7 .5 .1]...
	    ,'String','x-left'...
	    ,'FontUnits','normalized'...
	    ,'FontSize',.8 ...
	    );

specdraw_labelx2=...
  uicontrol(specdraw_fig...
	    ,'Tag','specdraw_labelx2'...
	    ,'Style','text'...
	    ,'Units','normalized'...
	    ,'Position',[0 .4 .5 .1]...
	    ,'String','x-right'...
	    ,'FontUnits','normalized'...
	    ,'FontSize',.8 ...
	    );

specdraw_labely1=...
  uicontrol(specdraw_fig...
	    ,'Tag','specdraw_labely1'...
	    ,'Style','text'...
	    ,'Units','normalized'...
	    ,'Position',[.5 .7 .5 .1]...
	    ,'String','y-top'...
	    ,'FontUnits','normalized'...
	    ,'FontSize',.8 ...
	    );

specdraw_labely2=...
  uicontrol(specdraw_fig...
	    ,'Tag','specdraw_labely2'...
	    ,'Style','text'...
	    ,'Units','normalized'...
	    ,'Position',[.5 .4 .5 .1]...
	    ,'String','y-bottom'...
	    ,'FontUnits','normalized'...
	    ,'FontSize',.8 ...
	    );


elseif(strcmp(lower(action),'bound'))
  pde_ax=findobj(allchild(0),'Tag','PDEAxes');
  limits=get(pde_ax,'Xlim');
  xmin=limits(1); xmax=limits(2);
  limits=get(pde_ax,'YLim');
  ymin=limits(1); ymax=limits(2);

  iwhat=get(specdraw_what,'value');
  if(iwhat==1)
    switch(flag)
     case 1
      x1=str2num(get(specdraw_editx1,'String'));
      if(length(x1)==0); x1=0; end 
      x1=min(max(x1,xmin),xmax);
      set(specdraw_editx1,'String',num2str(x1));
    case 2
      x2=str2num(get(specdraw_editx2,'String'));
      if(length(x2)==0); x2=0; end 
      x2=min(max(x2,xmin),xmax);
      set(specdraw_editx2,'String',num2str(x2));
    case 3
      y1=str2num(get(specdraw_edity1,'String'));
      if(length(y1)==0); y1=0; end
      y1=min(max(y1,ymin),ymax);
      set(specdraw_edity1,'String',num2str(y1));
    case 4
      y2=str2num(get(specdraw_edity2,'String'));
      if(length(y2)==0); y2=0; end
      y2=min(max(y2,ymin),ymax);
      set(specdraw_edity2,'String',num2str(y2));
    end
  elseif(iwhat==2)
    switch(flag)
     case 1
      x1=str2num(get(specdraw_editx1,'String'));
      if(length(x1)==0); x1=0; end 
      x1=min(max(x1,xmin),xmax);
      set(specdraw_editx1,'String',num2str(x1));
    case 2
      x1=str2num(get(specdraw_editx1,'String'));
      x2=str2num(get(specdraw_editx2,'String'));
      if(length(x2)==0); x2=0; else; x2=abs(x2); end
      x2=min([x2 xmax-x1 x1-xmin]);
      set(specdraw_editx2,'String',num2str(x2));
    case 3
      y1=str2num(get(specdraw_edity1,'String'));
      if(length(y1)==0); y1=0; end
      y1=min(max(y1,ymin),ymax);
      set(specdraw_edity1,'String',num2str(y1));
    case 4
      y1=str2num(get(specdraw_edity1,'String'));
      y2=str2num(get(specdraw_edity2,'String'));
      if(length(y2)==0); y2=0; else; y2=abs(y2); end
      y2=min([y2 ymax-y1 y1-ymin]);
      set(specdraw_edity2,'String',num2str(y2));
    end
  end
elseif(strcmp(lower(action),'specdraw_what'))
   set(specdraw_editx1,'String',num2str(0));
   set(specdraw_editx2,'String',num2str(0));
   set(specdraw_edity1,'String',num2str(0));
   set(specdraw_edity2,'String',num2str(0));
  iwhat=get(specdraw_what,'value');
  if(iwhat==1) 
    set(specdraw_labelx1,'String','x-left'); 
    set(specdraw_labelx2,'String','x-right'); 
    set(specdraw_labely1,'String','y-top'); 
    set(specdraw_labely2,'String','y-bottom'); 
  elseif(iwhat==2)
    set(specdraw_labelx1,'String','x-center'); 
    set(specdraw_labelx2,'String','x-radius'); 
    set(specdraw_labely1,'String','y-center'); 
    set(specdraw_labely2,'String','y-radius');
  end
elseif(strcmp(lower(action),'specdraw_draw'))
  iwhat=get(specdraw_what,'value');
  x1=str2num(get(specdraw_editx1,'String'));
  x2=str2num(get(specdraw_editx2,'String'));
  y1=str2num(get(specdraw_edity1,'String'));
  y2=str2num(get(specdraw_edity2,'String'));
  if(iwhat==1) %draw rectangle
    if((x1~=x2)&(y1~=y2))
      xy=[x1 x2 y1 y2];
      pderect(xy);
    else
      disp('For a rectangle x-left cannot equal x-right and y-top cannot equal y-bottom');
    end  
  elseif(iwhat==2) %draw ellipse
    if((x2>0)&(y2>0)) 
      pdeellip(x1,y1,x2,y2);
    else
      disp('For an ellipse x-radius and y-radius must be greater than zero'); 
    end 
  end
end

return
