function w = day_number_to_month ( d1, m1, y1 )

  y = 1900;
  m = 1;
  d = 1;
  w = 2;

  while ( y ~= y1 | m ~= m1 | d ~= d1 )

    d = d + 1;
    w = w + 1;
    w = mod ( w, 7 );

    if ( month_length ( m, y ) < d )

      d = 1;
      m = m + 1;

      if ( 12 < m )
        m = 1;
        y = y + 1;
      end
    end

  end

  return
end
function value = month_length ( m, y )

  days = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
  value = days ( m );
  if ( m == 2 & year_is_leap ( y ) )
    value = 29;
  end

  return
end
function value = year_is_leap ( y )

  if ( mod ( y, 4 ) ~= 0 )
    value = 0;
  elseif ( mod ( y, 100 ) ~= 0 )
    value = 1;
  elseif ( mod ( y, 400 ) ~= 0 )
    value = 0;
  else
    value = 1;
  end

  return
end
