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

getdate
function [m, d, y] = getdate

% interactive request and input of calendar date

% output

%  m = calendar month
%  d = calendar day
%  y = calendar year

% Celestial Computing with MATLAB

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

while (1)
  fprintf('\nplease input the calendar date');

  fprintf('\n(1 <= month <= 12, 1 <= day <= 31, year = all digits!)\n');

  cdstr = input('? ', 's');
  
  tl = size(cdstr);
  
  ci = findstr(cdstr, ',');
  
  % extract month, day and year
  
  m = str2num(cdstr(1:ci(1)-1));

  d = str2num(cdstr(ci(1)+1:ci(2)-1));

  y = str2num(cdstr(ci(2)+1:tl(2)));
  
  % check for valid inputs
  
  if (m >= 1 & m <= 12 & d >= 1 & d <= 31)
     break;
  end
end

Contact us