function [] = h5demo(iMirror)

OR1=4202.5; %outer radius of M1
IR1=2533; %inner radius of M1
OR3=2533; %outer radius of M3
IR3=533.5; %inner radius of M3

if iMirror==1
    % test#1
    h5file='internalData/SWest/140620 LSST M1 at focus mirror 0 set1 burst1 morph comp.h5';
    OR=OR1;IR=IR1;
elseif iMirror==3
    % test#2
    h5file='internalData/SWest/140620 LSST M3 at focus mirror 0 burst1 morph comp.h5';
    OR=OR3;IR=IR3;
end

%read in the surface map after force and thermal compensation
map = hdf5read(h5file,'/dataset');
figure(1);colormap jet;
imagesc(map);colorbar; axis xy square;
title('surface map (in micron) after thermal and force compensation');

%data that defines the pixel grid
centerRow = hdf5read(h5file,'/dataset','centerRow');
centerCol = hdf5read(h5file,'/dataset','centerCol');
pixelSize = hdf5read(h5file,'/dataset','pixelSize'); % m

%read in the forces
forces=hdf5read(h5file,'/measurement0/segmentForces/data');
%read in positions of the actuators
forcePosi=hdf5read(h5file,'/measurement0/segmentForces/position');
    
figure(2);colormap jet;
clf;
scatter(forcePosi(1,:),forcePosi(2,:),round(abs(forces)*1e4)/1e2,forces,'fill');colorbar;axis xy square;
title('actuator forces');
xlabel('x');
ylabel('y');

% forceLoca is a list of strings, '301 ', '302 ', etc, for the actuator
% ID numbers
forceLoca=hdf5read(h5file,'/measurement0/segmentForces/location');
fprintf('%s\n',forceLoca(1).Data);

%read in temperature measured by the TCs
temps=hdf5read(h5file,'/measurement0/segmentTemps/data');
%read in positions of the TCs
tempPosi=hdf5read(h5file,'/measurement0/segmentTemps/position');
figure(3);colormap jet;
subplot(1,2,1);
scatter(tempPosi(1,:),tempPosi(2,:),round(abs(temps)*1e4)/1e2,temps,'fill');colorbar;axis xy square;
title('temperature in 2D');
subplot(1,2,2);
scatter3(tempPosi(1,:),tempPosi(2,:),temps);
title('temprature in 3D');

%read in SOML thermal and force
%compensation map (in the form of
%annular Zernike coefficients)
mlcompz=h5read(h5file,'/compensated');
%the following reordering is needed because SOML order of Zernikes differ
%from Noll/Mahajan
zidx=[1 2 3 5 6 4 9 8 10 7 13 12 14 11 15];
mlfcompz=mlcompz(6,zidx);
mltcompz=mlcompz(5,zidx);

%define the pixel grid
[rows, cols] = size(map);
xVec = 1:cols;
xVec = (xVec - centerCol) * pixelSize; % m
yVec = 1:rows;
yVec = (yVec - centerRow) * pixelSize; % m, increasing upward
[x,y] = meshgrid(xVec,yVec); % rows x cols
xnorm=x*1000/OR;
ynorm=y*1000/OR;
rnorm=sqrt(xnorm.^2+ynorm.^2);
idxnan=rnorm>1|rnorm<IR/OR;
xnorm(idxnan)=nan;
ynorm(idxnan)=nan;

%synthesize the SOML compensation maps
fcompMapZ=ZernikeAnnularEval(mlfcompz,xnorm,ynorm,IR/OR);
tcompMapZ=ZernikeAnnularEval(mltcompz,xnorm,ynorm,IR/OR);
figure(4);colormap jet;
subplot(1,2,1);imagesc(fcompMapZ);colorbar;axis xy square;
title('SOML force compensation map');
subplot(1,2,2);imagesc(tcompMapZ);colorbar;axis xy square;
title('SOML thermal compensation map');

numTerms=15;
%decompose the synthesized maps back into Zernikes
mlfcompz1=ZernikeAnnularFit(fcompMapZ(~idxnan),xnorm(~idxnan),ynorm(~idxnan),numTerms,IR/OR);

mltcompz1=ZernikeAnnularFit(tcompMapZ(~idxnan),xnorm(~idxnan),ynorm(~idxnan),numTerms,IR/OR);

figure(5);
subplot(2,1,1);
plot(1:numTerms,mlfcompz,'-ro',1:numTerms,mlfcompz1,'-b*');
grid on;title('SOML force compensation annular Zernike coefficients');
xlabel('Zernike order');
ylabel('coefficients (in micron)');
legend({'from SOML','from annular Zernike fit'},'Location','Best');

subplot(2,1,2);
plot(1:numTerms,mltcompz,'-ro',1:numTerms,mltcompz1,'-b*');
grid on;title('SOML thermal compensation annular Zernike coefficients');
xlabel('Zernike order');
ylabel('coefficients (in micron)');
legend({'from SOML','from annular Zernike fit'},'Location','Best');


end
