Code covered by the BSD License

# A MATLAB Script for Predicting Lunar Eclipses

### David Eagle (view profile)

06 Dec 2012 (Updated )

Predicting the local circumstances of lunar eclipses.

eclprint(iflag, jdutc)
```function eclprint(iflag, jdutc)

% print lunar eclipse conditions

% required by leclipse.m

% Celestial Computing with MATLAB

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

global rtd dtr htr jdsaved

global obslat glon glat ht stlocl

% convert julian day to calendar date
% and universal time strings

[cdstr, utstr] = jd2str(jdutc);

if (iflag == 1)

fprintf('\nbegin penumbral phase of lunar eclipse');
fprintf('\n--------------------------------------\n\n');

jdsaved = jdutc;

end

if (iflag == 2)

fprintf('\ngreatest eclipse conditions');
fprintf('\n---------------------------\n\n');

end

if (iflag == 3)

fprintf('\nend penumbral phase of lunar eclipse');
fprintf('\n------------------------------------\n\n');

end

fprintf('calendar date             ');

disp(cdstr);

fprintf('\nuniversal time            ');

disp(utstr);

fprintf('\n');

fprintf('UTC Julian date           %10.4f \n', jdutc);

% display topocentric angles and slant range

jdtdt = utc2tdt(jdutc);

[ramoon, decmoon, rmmoon] = applan1(jdtdt, jdutc, 11, 3, 1, glon, glat, ht);

% apparent hour angle

hangle = stlocl - (htr * ramoon);

% topocentric elevation of the moon (degrees)

elevation = rtd * asin(sin(obslat) * sin(dtr * decmoon) ...
+ cos(obslat) * cos(dtr * decmoon) * cos(hangle));

% topocentric azimuth of the moon (degrees)

tmp1 = sin(hangle);

tmp2 = cos(hangle) * sin(obslat) - tan(dtr * decmoon) * cos(obslat);

azimuth = mod(180 + rtd * atan3(tmp1, tmp2), 360);

[d, m, s, azimstr] = deg2dms (azimuth);

[d, m, s, elevstr] = deg2dms (elevation);

fprintf('\nlunar azimuth angle        ');

disp(azimstr);

fprintf('\nlunar elevation angle      ');

disp(elevstr);

% determine event duration

if (iflag == 3)

deltat = 24 * (jdutc - jdsaved);

[h, m, s, hmsstr] = hrs2hms (deltat);

fprintf('\n\nevent duration             ');

disp(hmsstr);

end

```