function pdeshow;

plt = 0;


   tau = 0.02;
   n = 35;
   a = 1; 
   State = 'Restart';
   InitDev = '0';
   InitVel = '0';
   Forse = '0';
   BorderCond = '15*(x-y)*sin(2*pi*t)';
   ZMax = 30;
   ZMin = -30;
   Color = [0, 0.25 0.5];
   Color = [.95, .8, 0];

   Fig = openfig('pdeshow.fig');
   handles = guihandles(Fig);
   
   StartRestartButton = handles.StartRestartButton;
   PauseResumeButton = handles.PauseResumeButton;
   RegionsList = handles.RegionsList;
   Axes = handles.Axes;
   InitialVelocityEdit = handles.InitialVelocityEdit;
   BorderConditionEdit = handles.BorderConditionEdit;
   ForseEdit = handles.ForseEdit;
   CloseStopButton = handles.CloseStopButton;
   InitialDeviationEdit = handles.InitialDeviationEdit;
   AEdit = handles.AEdit;
   TauEdit = handles.TauEdit;
   NEdit = handles.NEdit;
   MethodList = handles.MethodList;
   EquationTypeList = handles.EquationTypeList;
   DrawBorderRadio = handles.DrawBorderRadio;
   ZMaxEdit = handles.ZMaxEdit;
   ZMinEdit = handles.ZMinEdit;
   TimeText = handles.TimeText;
   ColorButton = handles.ColorButton;

   set(Fig, 'Name','PDE Show', 'NumberTitle','Off', ...
     'MenuBar', 'None');

   set(StartRestartButton, ...
     'String','Start', ...
     'CallBack', @StartRestart);

   set(CloseStopButton, ...
     'String','Close', ...
     'CallBack', @CloseStop);

   set(PauseResumeButton, ...
     'Visible','Off', ...
     'CallBack', @PauseResume);

   set(TauEdit, 'String', num2str(tau));

   set(NEdit, 'String', num2str(n));

   set(RegionsList, 'String', {'Square', 'L shape', ...
     'Circled L', 'Disc', 'Annulus', 'Heart', 'Butterfly'});

   set(EquationTypeList, 'String', {'Wave', 'Heat'});

   set(MethodList, 'String', {'Explicit', 'Implicit'});

   set(BorderConditionEdit, 'String', BorderCond);

   set(InitialVelocityEdit, 'String', InitVel);

   set(ForseEdit, 'String', Forse);

   set(InitialDeviationEdit, 'String', InitDev);

   set(AEdit, 'String', num2str(a));

   set(DrawBorderRadio, 'Value', 0);

   set(ZMaxEdit, 'String', num2str(ZMax));

   set(ZMinEdit, 'String', num2str(ZMin));

   set(ColorButton, 'CallBack', @ColorButtonCallBack);


   function RunDrawing

     while isequal(State, 'Restart')

       State = 'ContinueProcess';

       tau = str2num(get(TauEdit, 'String'));
       n = str2num(get(NEdit, 'String'));
       h = 1/n;
       n = n + 1;

       regions_list = get(RegionsList, 'String');
       region_char = regions_list{get(RegionsList, 'value')}(1);

       EquationType = get(EquationTypeList, 'Value');
       Method = get(MethodList, 'Value');

       DrawBorder = get(DrawBorderRadio, 'Value');

   %U = 30*sin(X.^2 + Y.^2);
   %U = atan(cos(pi/2*X))
       [X, Y] = meshgrid(0:h:1);

       % initial conditions:

       InitDev = inline([get(InitialDeviationEdit, 'String'),'+0*x+0*y']);
       U = feval(InitDev, X, Y);

       InitVel = inline([get(InitialVelocityEdit, 'String'),'+0*x+0*y']);
       dUdt = feval(InitVel, X, Y);

       a = str2num(get(AEdit, 'String'));
       dUdt = feval(InitVel, X, Y);

       R = numgrid(region_char, n);  % region grid
       B = numgridborder(R);          % border grid
       A = -delsq(R);

       Region = R > 0;
       region = R(Region);
       Border = B > 0;
       border = B(Border);

       len = max(max(R));

       u_cur = zeros(len, 1);
       u_cur(region) = U(Region);
       dudt = zeros(len, 1);
       dudt(region) = dUdt(Region);
       u_prev = u_cur - tau * dudt;

       if EquationType == 2
         u_cur(:) = 1;
       end;

       t = 0;

       if ~DrawBorder
          U(:) = NaN;
       end;


       plt = surf(X, Y, U, ...
         'EdgeColor', 'None', ...
         'FaceAlpha', .8, ...
         'FaceLighting', 'Phong', ...
         'Parent', Axes);
       %set(Axes, 'Color', [0 0 0]);
       ZMax =  str2num(get(ZMaxEdit, 'String')); 
       ZMin =  str2num(get(ZMinEdit, 'String')); 
       set(Axes, 'ZLim', [ZMin ZMax], ...
         'Visible', 'Off');
       %axis square;
       %axis off;

       if EquationType == 1
         set(plt, 'FaceColor', Color);
       else
         set(plt, 'FaceColor', 'Interp');
         colormap autumn;
       end;

       camlight;
       camlight(45,-90);
       camlight(-137, -88);
       az = -180;
       lght = camlight(az, 50);

       rotate3d;

       while 1
        if isequal(State, 'ContinueProcess') ...
           || isequal(State, 'Resume')

              U(Region) = full(u_cur(region));
              set(plt, 'ZData', U);

              t = t + tau; 
              set(TimeText, 'String', ['t = ', num2str(t)]);

              forse = inline([get(ForseEdit, 'String'),'+0*x+0*y+0*t']);
              f = feval(forse, t, X(Region), Y(Region));

              if EquationType == 1 %wave
                if Method == 1
                  u_new = 2*u_cur - u_prev + tau^2*a^2/h^2 * A * u_cur + a^2*tau^2*f; 
                else
                  u_new = (speye(size(A)) - tau^2*a^2/h^2 * A ) \ (2*u_cur - u_prev + a^2*tau^2*f);
                end;
              else %heat
                if Method == 1
                  u_new = u_cur + tau^2*a^2/h^2 * A * u_cur + a^2*tau^2*f;  
                else
                  u_new = (speye(size(A)) - tau^2*a^2/h^2 * A ) \ u_cur + a^2*tau^2*f;
                end;
              end;

              u_prev = u_cur;
              u_cur = u_new;

              BorderCond = inline([get(BorderConditionEdit, 'String'),'+0*x+0*y+0*t']);
              if DrawBorder
                U = feval(BorderCond, t, X, Y);
                u_cur(border) = U(Border);
              else 
                u_cur(border) = feval(BorderCond, t, X(Border), Y(Border));
              end;

              drawnow;

         elseif ~isequal(State, 'Pause')
              break;
         end;

         az = az + .5;
         lightangle(lght, az, 50)

         drawnow;
       end;
     end;
   end;

   function StartRestart(varargin)

     if isequal(get(StartRestartButton, 'String'), 'Start')
       State = 'Restart';
       set(StartRestartButton, 'String', 'Restart');
       set(CloseStopButton, 'String', 'Stop');
       set(PauseResumeButton, 'Visible', 'On', 'String', 'Pause');
       RunDrawing;
     else
       State = 'Restart';
       set(PauseResumeButton, 'String', 'Pause');
     end;
   end;

 
   function CloseStop(varargin)

     if isequal(get(CloseStopButton, 'String'), 'Close')
         close(Fig);
     else
         State = 'Stop';
         set(CloseStopButton, 'String', 'Close');
         set(PauseResumeButton, 'Visible', 'Off');
         set(StartRestartButton, 'String', 'Start');
     end;
   end;

   function PauseResume(varargin)

     if isequal(get(PauseResumeButton, 'String'), 'Pause')
         State = 'Pause';
         set(PauseResumeButton, 'String', 'Resume');
     else
         State = 'Resume';
         set(PauseResumeButton, 'String', 'Pause');
     end;
   end;

   function ColorButtonCallBack(varargin)

     Color = uisetcolor(Color, 'Set Color for Surface');
     set(plt, 'FaceColor', Color);

   end;
   

end
  
