Code covered by the BSD License  

Highlights from
Rise and Set of the Sun, Moon and Planets

Rise and Set of the Sun, Moon and Planets

by

 

05 Dec 2012 (Updated )

Topocentric rise and set of the Sun, Moon and planets. Source ephemeris is DE421 with NOVAS routines

riseset.m
% riseset.m            December 5, 2012

% rise and set of the sun, moon and planets

% source ephemeris is DE421

% Celestial Computing with MATLAB

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

clear all;

global iephem itarg icent aunit km ephname

global jdatei obslat glon glat ht rootflg

rtd = 180 / pi;

dtr = pi / 180;

% define target body name vector

pdata = ['Mercury'; ...
    'Venus  '; ...
    'Earth  '; ...
    'Mars   '; ...
    'Jupiter'; ...
    'Saturn '; ...
    'Uranus '; ...
    'Neptune'; ...
    'Pluto  '; ...
    'Sun    '; ...
    'Moon   '];

tname = cellstr(pdata);

% initialize jpl ephemeris

iephem = 1;

ephname = 'de421.bin';

% define earth as central body

icent = 3;

% request output in au and au/day

km = 0;

% read leap seconds data file

readleap;

% conversion factor - astronomical unit to kilometers

aunit = 149597870.691;

% begin simulation

clc; home;

fprintf('\n\nrise and set of the sun, moon and planets');
fprintf('\n=========================================\n');

% request calendar date

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

[month, day, year] = getdate;

jdutc = julian(month, day, year);

% initial UTC Julian date

jdatei = jdutc;

% request search duration

while (1)
    
    fprintf('\nplease input the search duration (days)\n');
    
    ndays = input('? ');
    
    if (ndays > 0)
        break;
    end
    
end

% select target body

while(1)
    
    fprintf('\n    target body menu\n');
    
    fprintf('\n  <1> Mercury');
    fprintf('\n  <2> Venus');
    fprintf('\n  <3> Earth');
    fprintf('\n  <4> Mars');
    fprintf('\n  <5> Jupiter');
    fprintf('\n  <6> Saturn');
    fprintf('\n  <7> Uranus');
    fprintf('\n  <8> Neptune');
    fprintf('\n  <9> Pluto');
    fprintf('\n  <10> Sun');
    fprintf('\n  <11> Moon');
    
    fprintf('\n\nplease select the target body\n\n');
    
    itarg = input('? ');
    
    if (itarg >= 1 && itarg <= 11)
        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;

[d, m, s, latstr] = deg2dms (glat);

[d, m, s, longstr] = deg2dms (glon);

fprintf('\n\nrise and set of the sun, moon and planets');
fprintf('\n=========================================\n\n');

disp(tname(itarg));

fprintf('\nobserver latitude        ');

disp(latstr);

fprintf('\nobserver east longitude  ');

disp(longstr);

fprintf('\nobserver altitude      %14.4f meters\n', 1000 * obsalt);

% define search parameters

ti = 0;

tf = ndays;

dt = 0.1;

dtsml = 0.01;

rootflg = 0;

% find rise and set conditions

oevent1 ('rsfunc', 'rsprint', ti, tf, dt, dtsml)

fprintf('\n\n');

Contact us