function [month,day]=date_from_Jday(Jday,iileap,iiwr)
%
% Call [month,day]=date_from_Jday(Jday,iileap,iiwr);
%
% Jday      = Julian day of year;
% iileap    = 1 for leap years, or year itself (2001, e.g.);
%
% OUTPUT:
% month     = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'};
% day       = day of month;
%
% See also date_to Jday
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
if nargin<2, iileap=0; end
if nargin<3, iiwr=1; end
%
if iileap>1,
    year=iileap;
    iileap=mod(year,4)==0;
    if iiwr,
        disp(['Computing leap year flag: year = ',int2str(year),' ==> iileap = ',int2str(iileap)]);
    end
elseif iileap<0,
    error('Illegal iileap'); 
end
%
if ~iileap,
    day0=cumsum([0 31 28 31 30 31 30 31 31 30 31 30 31]);
else
    day0=cumsum([0 31 29 31 30 31 30 31 31 30 31 30 31]);
end
months={'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'};
%
for jmonth=1:12,
    if Jday<=day0(jmonth+1), break; end
end
month=months{jmonth};
day=Jday - day0(jmonth);
