function [z,x,E] = metalrefl (inci)
% Plots the electric field distribution near a metal surface,
% with a skin depth of 1/(6*pi) of a vacuum wavelength
%
%  Input: inci = angle of incidence in radians
%
%  Output:
%  z: sampling points along surface normal
%  x: sampling points along metal surface
%  E: matrix of field values
x  = -9.95:.1:9.95;  % 200 samples along metal surface
zl = -9.95:.1:-.05;  % 100 samples on vacuum side 
zr =  0.05:.1:4.95;  %  50 samples on metal side
z  =  [zl,zr];
n2 =  3 - 3*i;     % complex refractive index of metal
cos0  =  cos(inci);
sin0  =  sin(inci); 
sin2  =  sin0./n2;
cos2  =  sqrt(1 - sin2.^2);
ncos2 =  n2.*cos2;
% Fresnel's equations:
E1 =  (cos0 - ncos2)./(cos0 + ncos2); % reflected amplitude   
E2 =  2.*cos0./(cos0 + ncos2); % transmitted amplitude
[Z,X] =  meshgrid(zl,x); % first lefthand side   
E  =  exp(-i.*sin0.*X - i.*cos0.*Z) + E1.*exp(-i.*sin0.*X + i.*cos0.*Z);
[Z,X] =  meshgrid(zr,x); % then righthand side
Et =  E2.*exp(-i.*sin0.*X - i.*ncos2.*Z);
E  =  [E,Et];   
mesh (abs(E), angle(E));   
return



