Code covered by the BSD License  

Highlights from
A MATLAB Script for Predicting Lunar Eclipses

A MATLAB Script for Predicting Lunar Eclipses

by

 

06 Dec 2012 (Updated )

Predicting the local circumstances of lunar eclipses.

leclipse.m
% leclipse.m           December 5, 2012     

% lunar eclipses

% source ephemeris is DE421

% Celestial Computing with MATLAB

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all;

global rtd dtr htr iephem ephname km

global jdatei aunit

global radsun radmoon req obslat glon glat ht

% initialize jpl ephemeris

iephem = 1;

ephname = 'de421.bin';

km = 0;

% read leap seconds data file

readleap;

% conversion factor - astronomical unit to kilometers

aunit = 149597870.691;

% conversion factor - radians to degrees

rtd = 180 / pi;

% conversion factor - degrees to radians

dtr = pi / 180;

% conversion factor - hours to radians

htr = pi / 12;

% conversion factor - arc seconds to radians

atr = dtr / 3600;

% radius of the earth (au)

req = 6378.14 / aunit;

% radius of the sun (au)

radsun = 696000 / aunit;

% radius of the moon (au)

radmoon = 1738 / aunit;

% begin simulation

clc; home;

fprintf('\n\nlocal circumstances of lunar eclipses');
fprintf('\n=====================================\n');

% request calendar date

fprintf('\nplease input an initial UTC calendar date\n');

[month, day, year] = getdate;
   
jdutc = julian(month, day, year);
   
jdatei = jdutc;

% request search duration

while (1)
    
   fprintf('\n\nplease input the search duration (days)\n');

   ndays = input('? ');
   
   if (ndays > 0)
      break;
   end 
   
end

% request observer coordinates

[obslat, obslong, obsalt] = getobs;

% convert observer east longitude to degrees

glon = obslong * rtd;

% convert observer geodetic latitude to degrees

glat = obslat * rtd;

% convert observer altitude to meters

ht = 1000 * obsalt;

% define search parameters

ti = 0;

tf = ndays;

dt = 0.25;

dtsml = 0.1;

% find eclipse conditions

eclevent('eclfunc', 'eclprint', ti, tf, dt, dtsml)

fprintf('\n\n');

Contact us