ismagnetic=false;  %set to true for magnetic source
resolution=20;
Courant=0.5;
w=1;
t0=5;

fd='ehexample';
fs=dir([fd '/z*.h5']);
z=hdf5read([fd '/' fs(1).name],'/z');
fs=dir([fd '/ex*.h5']);
E=hdf5read([fd '/' fs(1).name],'/ex');
fs=dir([fd '/hy*.h5']);
H=hdf5read([fd '/' fs(1).name],'/hy');
t=sscanf(fs.name,'hy-%f.h5');
dt=Courant/resolution;

if ~ismagnetic,
  plot(z,E); hold on; plot(z,H.*sign(z),'g');
else  
  plot(z,E.*sign(z)); hold on; plot(z,H,'g');
end

j=@(t) exp(-(t-t0).^2/(2*w^2)).*-(t-t0)/w^2;
if ismagnetic, delay=0; else delay=dt; end

plot(z,-j(t-delay-abs(z))/2,'b:');
plot(z,-j(t-delay-0.5*dt-abs(z))/2,'g:');
legend('E (meep)','H (meep)','E (analytical)','H (analytical)');
