#include <math.h>
#include <stdlib.h>

long dateToJulian(int mm, int id, int iyyy)  {

  long jul;
  int ja,jy,jm;
  const long gregorian = (15+31L*(10+12L*1582));
  
  if (iyyy < 0) ++iyyy;
  if (mm > 2)  {
      jy=iyyy;
      jm=mm+1;
  }
  else  {
      jy=iyyy-1;
      jm=mm+13;
  }
  
  jul = (long) (floor(365.25*jy)+floor(30.6001*jm)+id+1720995);
  
  if (id+31L*(mm+12L*iyyy) >= gregorian)  {
      ja=(int)(0.01*jy);
      jul += (long)(2-ja+(int) (0.25*ja));
  }
 
  return(jul);
}

