public static int jauJdcalf(int ndp, double dj1, double dj2, int iymdf[])
    {
       int j;
       double denom, d1, d2, f1, f2, f;


    /* Denominator of fraction (e.g. 100 for 2 decimal places). */
       if ((ndp >= 0) && (ndp <= 9)) {
          j = 0;
          denom = pow(10.0, ndp);
       } else {
          j = 1;
          denom = 1.0;
       }

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

    /* Separate days and fractions. */
       f1 = fmod(d1, 1.0);
       f2 = fmod(d2, 1.0);
       d1 = floor(d1 - f1);
       d2 = floor(d2 - f2);

    /* Round the total fraction to the specified number of places. */
       f = floor((f1 + f2) * denom) / denom;

    /* Re-assemble the rounded date and re-align to noon. */
       d2 += f + 0.5;

       /* Convert to Gregorian Calendar. */
       try {
           Calendar cal = jauJd2cal(d1, d2);
           iymdf[0] = cal.iy;
           iymdf[1] = cal.im;
           iymdf[2] = cal.id;
           iymdf[3] = (int) (cal.fd * denom);
       } catch (JSOFAIllegalParameter e) {
           j = -1;
       }

    /* Return the status. */
       return j;

        }