Example #1
0
YMD
jd2ymd(JD jd)
{
    YMD ymd;
    double j;
    double x;
    int y, m, d;

    j = jdGetDay(jd);
    j2gcal(&y, &m, &d, j);
    ymdSetYear(ymd, y);
    ymdSetMonth(ymd, m);
    ymdSetDay(ymd, (double)d);

    x = (j - floor(j));
    /*
    ** we do this next step because the rounding of j in j2gcal()
    ** either credits or debits us with 12 hours
    */
    if (x < 0.5) {
	x += 0.5;
    } else {
	x -= 0.5;
    }
    ymdIncDay(ymd, x);

    /* pick up the hours, minutes, and seconds */
    ymd.hms = jd.hms;

    return(ymd);
}
Example #2
0
YMD
ymd2ymd(YMD ymd)
{
    double j;	/* julian day number */
    double x;
    int y, m, d;

    j = ymd2j(ymd);

    j2gcal(&y, &m, &d, j);
    ymdSetYear(ymd, y);
    ymdSetMonth(ymd, m);
    ymdSetDay(ymd, d);

    x = j - floor(j);
    /*
    ** we do this next step because the rounding of j in j2gcal()
    ** either credits or debits us with 12 hours
    */
    if (x < 0.5) {
	x += 0.5;
    } else {
	x -= 0.5;
    }

    /* promote the hours */
    x = (x - floor(x)) * 24.0;
    ymdSetHours(ymd, floor(x));

    /* promote the minutes */
    x = (x - floor(x)) * 60.0;
    ymdSetMinutes(ymd, floor(x));

    /* promote the seconds */
    x = (x - floor(x)) * 60.0;
    ymdSetSeconds(ymd, x);

    return(ymd);
}
Example #3
0
int main(){
  YMD ymd;
  double t = 0.0;
  #define L 9
  double y[L][6] = {
    {1858.0, 11.0, 17.0, 0.0, 0.0, 0.0},
    {1949.0, 12.0, 31.923459, 0.0, 0.0, 0.0},
    {2000.0, 1.0, 1.0, 0.0, 0.0, 0.0},
    {1984.0, 1.0, 1.0, 0.0, 0.0, 0.0},
    {1984.0, 1.0, 0.0, 0.0, 0.0, 0.0},
    {1984.0, 12.0, 31.0, 23.0, 59.0, 60.0},
    {1985.0, 1.0, 1.0, 0.0, 0.0, 0.0},
    {1985.0, 1.0, 0.0, 0.0, 0.0, 0.0},
    {1985.0, 12.0, 31.0, 23.0, 59.0, 60.0}
  };

  for(int i=0; i < L; i++){
    ymdSetYear(ymd, (int)y[i][0]);
    ymdSetMonth(ymd, (int)y[i][1]);
    ymdSetDay(ymd, y[i][2]);
    ymdSetHours(ymd, y[i][3]);
    ymdSetMinutes(ymd, y[i][4]);
    ymdSetSeconds(ymd, y[i][5]);

    printf("%4d %2d %10.6f %10.6f %10.6f %10.6f\n", ymdGetYear(ymd),
           ymdGetMonth(ymd), ymdGetDay(ymd), ymdGetHours(ymd),
           ymdGetMinutes(ymd), ymdGetSeconds(ymd));
    
    t = ymd2y(ymd);

    printf("%13.8f\n\n", t);
  }

  return 0;

}