function [ yyyymmdd ] = convertDoy2MonthDay( yyyyddd )
%CONVERTDOY2MONTHDAY Converts from day-of-year to month and day format
%   Considers leap years.    
%   Inputs:
%   yyyyddd = 2-column matrix of years and day-of-year (i.e. [1,365])
%   Outputs:
%   yyyymmdd = 3-column matrix of years, months, and day-of-month 

year = yyyyddd(:,1);
doy = yyyyddd(:,2);

yyyymmdd = [];
for i = 1:length(doy)
    
    if mod(year(i),4) == 0
        leftBrks=[1    32    61    92   122   153   183   214   245   275   306   336];
        rightBrks=[31   60    91   121   152   182   213   244   274   305   335   366];
    else
        leftBrks=[1    32    60    91   121   152   182   213   244   274   305   335];
        rightBrks=[31   59    90   120   151   181   212   243   273   304   334   365];
    end
    
    month = doy(i) >= leftBrks & doy(i) <= rightBrks;
    day = doy(i) - leftBrks(month) + 1;
    
    yyyymmdd(i,:) = [year(i) find(month) day];
    
end


end

