function ltpdv_buildMathPanel(panH, mainfig)

Gproperties = getappdata(mainfig, 'Gproperties');

% Sizes
pmarg   = 0.025;           % Margin size
pw      = 0.5 - 2*pmarg;   % Panel width
ph      = 0.3;            % Panel height
bheight = 0.2;             % Button height
bwidth  = 0.2;            % Button width
BUTTON_FONT = 12;
%--------------------- Calculator pad
pl = pmarg;
pb = 0.5 + pmarg;
% Panel
pan =  uipanel(panH, 'Title','Calculator  ','FontSize', Gproperties.fontsize,...
   'BackgroundColor', [0.4 0.4 0.4],...
   'ForegroundColor', 'w',...
   'Position',[pl pb pw ph], 'Units', 'normalized');

% Buttons
buts = {'+', '-', './', '.*', '.^', '*', '/', '^'};
bl = pmarg;
bb = 1-pmarg-bheight;
for j=1:numel(buts)
   bh = uicontrol(pan, 'String',buts{j},...
      'Callback', {@ltpdv_calc_btn, mainfig, 2}, ...
      'Units', 'normalized', 'Fontsize', BUTTON_FONT, ...
      'Position',[bl bb bwidth bheight]);
   % move
   bl = bl + bwidth + pmarg;
   if bl + bwidth > (1-pmarg)
      bl = pmarg;
      bb = bb - bheight - pmarg;
   end
end

%----------------------- Stats panel
pl = 0.5 + pmarg;
pb = 0.5 + pmarg;
% Panel
pan =  uipanel(panH, 'Title','Stats  ','FontSize', Gproperties.fontsize,...
   'BackgroundColor', [0.4 0.4 0.4],...
   'ForegroundColor', 'w',...
   'Position',[pl pb pw ph], 'Units', 'normalized');

% Buttons
buts = {'mean', 'median', 'sum', 'std', 'var'};
bl = pmarg;
bb = 1-pmarg-bheight;
for j=1:numel(buts)
   bh = uicontrol(pan, 'String',buts{j},...
      'Callback', {@ltpdv_calc_btn, mainfig, 1}, ...
      'Units', 'normalized', 'Fontsize', BUTTON_FONT, ...
      'Position',[bl bb bwidth bheight]);
   % move
   bl = bl + bwidth + pmarg;
   if bl + bwidth > (1-pmarg)
      bl = pmarg;
      bb = bb - bheight - pmarg;
   end
end

%----------------------- Trig panel
pl = pmarg;
pb = pmarg;
% Panel
pan =  uipanel(panH, 'Title','Trig  ','FontSize', Gproperties.fontsize,...
   'BackgroundColor', [0.4 0.4 0.4],...
   'ForegroundColor', 'w',...
   'Position',[pl pb pw ph], 'Units', 'normalized');

% Buttons
buts = {'sin', 'asin', 'cos', 'acos', 'tan', 'atan', 'log', 'log10', 'exp'};
bl = pmarg;
bb = 1-pmarg-bheight;
for j=1:numel(buts)
   bh = uicontrol(pan, 'String',buts{j},...
      'Callback', {@ltpdv_calc_btn, mainfig, 1}, ...
      'Units', 'normalized', 'Fontsize', BUTTON_FONT, ...
      'Position',[bl bb bwidth bheight]);
   % move
   bl = bl + bwidth + pmarg;
   if bl + bwidth > (1-pmarg)
      bl = pmarg;
      bb = bb - bheight - pmarg;
   end
end

%----------------------- Misc panel
pl = 0.5 + pmarg;
pb = pmarg;
% Panel
pan =  uipanel(panH, 'Title','Misc  ','FontSize', Gproperties.fontsize,...
   'BackgroundColor', [0.4 0.4 0.4],...
   'ForegroundColor', 'w',...
   'Position',[pl pb pw ph], 'Units', 'normalized');

% Buttons
buts = {'sqrt', 'real', 'imag', 'conj', 'abs', 'phase'};
bl = pmarg;
bb = 1-pmarg-bheight;
for j=1:numel(buts)
   bh = uicontrol(pan, 'String',buts{j},...
      'Callback', {@ltpdv_calc_btn, mainfig, 1}, ...
      'Units', 'normalized', 'Fontsize', BUTTON_FONT, ...
      'Position',[bl bb bwidth bheight]);
   % move
   bl = bl + bwidth + pmarg;
   if bl + bwidth > (1-pmarg)
      bl = pmarg;
      bb = bb - bheight - pmarg;
   end
end

