% Bridget Smith-Konter
% matlab script to calculate beta angles 
% checked this routine by verifying Nimmo beta angles (see /Tiger_Stripes_Stuff/Test_Beta)
% note that a 180 degree phase change in beta is okay, as cos/sin of (2*beta) is what we want


load FILENAME_elon_plat.txt

long=FILENAME_elon_plat(:,1);
lat=FILENAME_elon_plat(:,2);
lat_reg=-(lat)+90;

ll=length(long); % reverse order to match Nimmo scheme (top-down, instead of bottom-up)


figure(1)
subplot(2,2,1),plot(long,lat_reg,'r*',long,lat_reg,'k')
grid
xlabel('degrees longitude')
ylabel('degrees latitude')
title('SATELLITE_NAME')

% calculate angles, don't forget to scale dx by cos of latitude!
i=1:length(long)-1;
dx(i)=(long(i+1)-long(i)).*cosd(lat_reg(i));
dy(i)=lat_reg(i+1)-lat_reg(i);
theta(1)=0;
theta(i+1)=180 + (atan2(dx(i), dy(i))*180/pi)



ll=length(long);
output=[long lat theta']';
fid=fopen('FILENAME_elon_plat_beta.txt','w');
fprintf(fid,'%6.4f %6.4f %6.4f\n',output);
st=fclose(fid);



