function Jday=date_to_Jday(month,day,iileap)
%
% Call Jday=date_to_Jday(month,day,iileap);
%
% month     = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'}
%             or the month number;
% day       = day of month;
% iileap    = 1 for leap years, or year itself (2001, e.g.);
%
% See also date_from_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.
Jday=-1;
if nargin<3, iileap=0; end
%
if iileap>1,
    iileap=mod(iileap,4)==0;
%    disp(['Computed leap year flag: ',int2str(iileap)]); 
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
if size(month,1)>size(month,2), day0=day0'; end
%
if ischar(month),
	months={'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'};
    jmo=find(strncmpi(months,month,3));
	if isempty(jmo), 
        disp(['Invalid month: ',month]); disp([' Valid months =  ']); 
        disp(months); error('Quitting'); 
        return;
	end
else
    jmo=month;
    if jmo<1 | jmo>12, 
        disp(['Illegal month number: ',int2str(jmo)]);
        return;
    end
end
Jday=day0(jmo) + day;
