% This script plots spherical harmonics
% it requires Fred Simons package SLEPIAN.
clear;
close all;
addpath(fullfile('~/sw/MMASS-1.0.1/'));
mkdir('LEGENDRE'); % necessary for temporary files
fs=14; % font size for plotting

% INPUT SECTION: define degree and order of perturbation
lperturb = 2;
mperturb = 0; % between -lperturb and lperturb

assert( lperturb >= 0 && mperturb >= -lperturb && mperturb <= lperturb);
% CALCULATION SECTION
% call addmon to get lmcosi matrix
[dems,dels,mz,lmcosi,mzi,mzo,bigm,bigl,rinm,ronm,demin]=addmon(lperturb+1,NaN);

% identify correct place in lmcosi matrix to make coefficient nonzero
row = find( lmcosi(:,1) == lperturb & lmcosi(:,2) == mperturb );

if( mperturb >= 0 )
    lmcosi(row,3) = 1;
else
    lmcosi(row,4) = 1;
end

% PLOTTING SECTION

[r,lon,lat,Plm] = plm2xyz( lmcosi,1.0); 
figure;
contourf(lon,lat,r,256,'Color','none'); colorbar;
xlabel('Longitude','FontSize',fs);
ylabel('Latitude','FontSize',fs);
set(gca,'FontSize',fs)
axis equal tight;