#+
    # MODIS2CNES : Convert MODIS date format to CNES JULIAN DAYS (YYYYDDD or YYYYDDDHHMM)
    # 
    # @author: Renaud DUSSURGET (LER PAC/IFREMER)
    # @history: Created by RD on 29/10/2012
    #
    #-
347266
def modis2cnes(modis_date):
    

    if not isinstance(modis_date,list) : modis_date=[modis_date]

    if len(modis_date[0]) ==  7 :
        obj=[datetime.datetime.strptime(d,"%Y%j") for d in modis_date] 
    else :
        obj=[datetime.datetime.strptime(d,"%Y%j%H%M") for d in modis_date]
    
#    str,obj=cnes_convert(modis_date)
    dat=[o.strftime("%d/%m/%Y-%H:%M") for o in obj]
    
    return cnes_convert(dat)
302211
def to_jd(year, month, day):
    ''''''
    legal_date(year, month, day)
    gyear = year + YEAR_EPOCH - 1

    return (
        gregorian.EPOCH - 1 + (365 * (gyear - 1)) +
        floor((gyear - 1) / 4) + (-floor((gyear - 1) / 100)) +
        floor((gyear - 1) / 400) + (month - 1) * 28 + day
    )
1311590
def julian_date(year, month=1, day=1, hour=0, minute=0, second=0.0):
    """"""
    return julian_day(year, month, day) - 0.5 + (
        second + minute * 60.0 + hour * 3600.0) / DAY_S
760001
@Override
    public final D transform(long utcDays) {

        long s1 = this.winterOnOrBefore(utcDays);
        long s2 = this.winterOnOrBefore(s1 + 370);
        long m12 = this.newMoonOnOrAfter(s1 + 1);
        long nextM11 = this.newMoonBefore(s2 + 1);
        long m = this.newMoonBefore(utcDays + 1);
        boolean leapYearInSui = (lunations(m12, nextM11) == 12);

        long me = lunations(m12, m); // might be negative

        if (leapYearInSui && this.hasLeapMonth(m12, m)) {
            me--;
        }

        int month = (int) Math.floorMod(me, 12);

        if (month == 0) {
            month = 12;
        }

        long elapsedYears =
            (long) Math.floor(1.5 - (month / 12.0) + ((utcDays - EPOCH_CHINESE) / MEAN_TROPICAL_YEAR));

        int cycle = (int) Math.floorDiv(elapsedYears - 1, 60) + 1;
        int yearOfCycle = (int) Math.floorMod(elapsedYears, 60);

        if (yearOfCycle == 0) {
            yearOfCycle = 60;
        }

        int dayOfMonth = (int) (utcDays - m + 1);
        EastAsianMonth eam = EastAsianMonth.valueOf(month);

        if (leapYearInSui && this.hasNoMajorSolarTerm(m) && !this.hasLeapMonth(m12, this.newMoonBefore(m))) {
            eam = eam.withLeap();
        }

        return this.create(cycle, yearOfCycle, eam, dayOfMonth, utcDays);

    }
508556
def julian_day(year, n):
    
    if n > 59 and isleap(year):
        n += 1
    return datetime(year, 1, 1) + timedelta(n - 1)
620251
public function jdToYmd($julian_day)
    {
        $year  = (int) ((30 * ($julian_day - 1948440) + 10646) / 10631);
        $month = (int) ((11 * ($julian_day - $year * 354 - (int) ((3 + 11 * $year) / 30) - 1948086) + 330) / 325);
        $day   = $julian_day - 29 * ($month - 1) - (int) ((6 * $month - 1) / 11) - $year * 354 - (int) ((3 + 11 * $year) / 30) - 1948085;

        return array($year, $month, $day);
    }
1343359
def to_jd(year, week, day):
    ''''''
    return day + n_weeks(SUN, gregorian.to_jd(year - 1, 12, 28), week)
1369959
public static function jdToGregorian($julian_day)
    {
        // PHP has different limits on 32 and 64 bit systems.
        $MAX_JD = PHP_INT_SIZE == 4 ? 536838866 : 2305843009213661906;

        return self::jdToCalendar(self::$gregorian_calendar, $julian_day, 1, $MAX_JD);
    }
1198602
def equinox(date, eop_correction=True, terms=106, kinematic=True):
    
    epsilon_bar, delta_psi, delta_eps = _nutation(date, eop_correction, terms)

    equin = delta_psi * 3600. * np.cos(np.deg2rad(epsilon_bar))

    if date.d >= 50506 and kinematic:
        # Starting 1992-02-27, we apply the effect of the moon
        ttt = date.change_scale('TT').julian_century
        om_m = 125.04455501 - (5 * 360. + 134.1361851) * ttt\
            + 0.0020756 * ttt ** 2 + 2.139e-6 * ttt ** 3

        equin += 0.00264 * np.sin(np.deg2rad(om_m)) + 6.3e-5 * np.sin(np.deg2rad(2 * om_m))

    # print("equinox = {}\n".format(equin / 3600))
    return equin / 3600.
678633
public static function calToJd($calendar_id, $month, $day, $year)
    {
        switch ($calendar_id) {
            case CAL_FRENCH:
                return self::frenchToJd($month, $day, $year);

            case CAL_GREGORIAN:
                return self::gregorianToJd($month, $day, $year);

            case CAL_JEWISH:
                return self::jewishToJd($month, $day, $year);

            case CAL_JULIAN:
                return self::julianToJd($month, $day, $year);

            default:
                return trigger_error('invalid calendar ID ' . $calendar_id . '.', E_USER_WARNING);
        }
    }
1197858
public static JulianDate getJulianEasterSunday (final int nYear)
  {
    final int a = nYear % 4;
    final int b = nYear % 7;
    final int c = nYear % 19;
    final int d = (19 * c + 15) % 30;
    final int e = (2 * a + 4 * b - d + 34) % 7;
    final int x = d + e + 114;
    final int nMonth = x / 31;
    final int nDay = (x % 31) + 1;
    return JulianDate.of (nYear, (nMonth == 3 ? Month.MARCH : Month.APRIL).getValue (), nDay);
  }
852549
def nexrad_to_datetime(julian_date, ms_midnight):
    """"""
    # Subtracting one from julian_date is because epoch date is 1
    return datetime.datetime.utcfromtimestamp((julian_date - 1) * day + ms_midnight * milli)
4764
def to_jd(year, month, day):
    ''''''
    return (day + ceil(29.5 * (month - 1)) + (year - 1) * 354 + trunc((3 + (11 * year)) / 30) + EPOCH) - 1
1336558
function (date) {
                if (date instanceof Date === false) {
                    throw new ArgumentError(
                        Logger.logMessage(Logger.LEVEL_SEVERE, "SunPosition", "getAsCelestialLocation",
                            "missingDate"));
                }

                var julianDate = this.computeJulianDate(date);

                //number of days (positive or negative) since Greenwich noon, Terrestrial Time, on 1 January 2000 (J2000.0)
                var numDays = julianDate - 2451545;

                var meanLongitude = WWMath.normalizeAngle360(280.460 + 0.9856474 * numDays);

                var meanAnomaly = WWMath.normalizeAngle360(357.528 + 0.9856003 * numDays) * Angle.DEGREES_TO_RADIANS;

                var eclipticLongitude = meanLongitude + 1.915 * Math.sin(meanAnomaly) + 0.02 * Math.sin(2 * meanAnomaly);
                var eclipticLongitudeRad = eclipticLongitude * Angle.DEGREES_TO_RADIANS;

                var obliquityOfTheEcliptic = (23.439 - 0.0000004 * numDays) * Angle.DEGREES_TO_RADIANS;

                var declination = Math.asin(Math.sin(obliquityOfTheEcliptic) * Math.sin(eclipticLongitudeRad)) *
                    Angle.RADIANS_TO_DEGREES;

                var rightAscension = Math.atan(Math.cos(obliquityOfTheEcliptic) * Math.tan(eclipticLongitudeRad)) *
                    Angle.RADIANS_TO_DEGREES;

                //compensate for atan result
                if (eclipticLongitude >= 90 && eclipticLongitude < 270) {
                    rightAscension += 180;
                }
                rightAscension = WWMath.normalizeAngle360(rightAscension);

                return {
                    declination: declination,
                    rightAscension: rightAscension
                };
            }
460244
def day_of_year(date = self)
      date.month == 1 ? date.day : (DAYS_IN_YEAR[date.month - 2] + date.day)
    end
182484
def _iso_to_gregorian(iso_year, iso_week, iso_day):
    ""
    year_start = _iso_year_start(iso_year)
    return year_start + dt.timedelta(days=iso_day-1, weeks=iso_week-1)
1070595
protected function jdToGreg($julian) 
    {
        $julian = $julian - 1721119;
        $calc1  = 4 * $julian - 1;
        $year   = floor($calc1 / 146097);
        $julian = floor($calc1 - 146097 * $year);
        $day    = floor($julian / 4);
        $calc2  = 4 * $day + 3;
        $julian = floor($calc2 / 1461);
        $day    = $calc2 - 1461 * $julian;
        $day    = floor(($day + 4) / 4);
        $calc3  = 5 * $day - 3;
        $month  = floor($calc3 / 153);
        $day    = $calc3 - 153 * $month;
        $day    = floor(($day + 5) / 5);
        $year   = 100 * $year + $julian;
        
        if ($month < 10) {
            $month = $month + 3;
        } else {
            $month = $month - 9;
            $year  = $year + 1;
        }
        
        /* 
        Just to mimic the PHP JDToGregorian output
        If year is less than 1, subtract one to convert from
        a zero based date system to the common era system in
        which the year -1 (1 B.C.E) is followed by year 1 (1 C.E.)
        */
        
        if ($year < 1) {
            $year--;
        }

        return $month.'/'.$day.'/'.$year;
    }