public static Calendar jauJd2cal(double dj1, double dj2) throws JSOFAIllegalParameter
    {
    /* Minimum and maximum allowed JD */
       final double djmin = -68569.5;
       final double djmax = 1e9;

       long jd, l, n, i, k;
       double dj, d1, d2, f1, f2, f, d;


    /* Verify date is acceptable. */
       dj = dj1 + dj2;
       if (dj < djmin || dj > djmax) throw new JSOFAIllegalParameter("input julian date out of range", -1);

    /* Copy the date, big then small, and re-align to midnight. */
       if (dj1 >= dj2) {
          d1 = dj1;
          d2 = dj2;
       } else {
          d1 = dj2;
          d2 = dj1;
       }
       d2 -= 0.5;

    /* Separate day and fraction. */
       f1 = fmod(d1, 1.0);
       f2 = fmod(d2, 1.0);
       f = fmod(f1 + f2, 1.0);
       if (f < 0.0) f += 1.0;
       d = floor(d1 - f1) + floor(d2 - f2) + floor(f1 + f2 - f);
       jd = (long) floor(d) + 1L;

    /* Express day in Gregorian calendar. */
       l = jd + 68569L;
       n = (4L * l) / 146097L;
       l -= (146097L * n + 3L) / 4L;
       i = (4000L * (l + 1L)) / 1461001L;
       l -= (1461L * i) / 4L - 31L;
       k = (80L * l) / 2447L;
       int id = (int) (l - (2447L * k) / 80L);
       l = k / 11L;
       int im = (int) (k + 2L - 12L * l);
       int iy = (int) (100L * (n - 49L) + i + l);
      

       return new Calendar(iy, im, id, f);

        }