Search in sources :

Example 1 with TimeStamped

use of org.orekit.time.TimeStamped in project Orekit by CS-SI.

the class SolarInputs97to05 method findClosestLine.

private void findClosestLine(AbsoluteDate date) throws OrekitException {
    if ((date.durationFrom(firstDate) < 0) || (date.durationFrom(lastDate) > Constants.JULIAN_DAY)) {
        throw new OrekitException(OrekitMessages.OUT_OF_RANGE_EPHEMERIDES_DATE, date, firstDate, lastDate);
    }
    // don't search if the cached selection is fine
    if ((currentParam != null) && (date.durationFrom(currentParam.date) >= 0) && (date.durationFrom(currentParam.date) < Constants.JULIAN_DAY)) {
        return;
    }
    LineParameters before = new LineParameters(date.shiftedBy(-Constants.JULIAN_DAY), null, 0, 0, 0, 0, 0, 0);
    // search starting from entries a few steps before the target date
    SortedSet<TimeStamped> tailSet = data.tailSet(before);
    if (tailSet != null) {
        currentParam = (LineParameters) tailSet.first();
        if (currentParam.date.durationFrom(date) == -Constants.JULIAN_DAY) {
            currentParam = (LineParameters) data.tailSet(date).first();
        }
    } else {
        throw new OrekitException(new DummyLocalizable("unable to find data for date {0}"), date);
    }
}
Also used : TimeStamped(org.orekit.time.TimeStamped) DummyLocalizable(org.hipparchus.exception.DummyLocalizable) OrekitException(org.orekit.errors.OrekitException)

Example 2 with TimeStamped

use of org.orekit.time.TimeStamped in project Orekit by CS-SI.

the class MarshallSolarActivityFutureEstimation method loadData.

/**
 * {@inheritDoc}
 */
public void loadData(final InputStream input, final String name) throws IOException, ParseException, OrekitException {
    // select the groups we want to store
    final int f107Group;
    final int apGroup;
    switch(strengthLevel) {
        case STRONG:
            f107Group = 3;
            apGroup = 6;
            break;
        case AVERAGE:
            f107Group = 4;
            apGroup = 7;
            break;
        default:
            f107Group = 5;
            apGroup = 8;
            break;
    }
    // read the data
    final BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
    boolean inData = false;
    final TimeScale utc = TimeScalesFactory.getUTC();
    DateComponents fileDate = null;
    for (String line = reader.readLine(); line != null; line = reader.readLine()) {
        line = line.trim();
        if (line.length() > 0) {
            final Matcher matcher = dataPattern.matcher(line);
            if (matcher.matches()) {
                // we are in the data section
                inData = true;
                // extract the data from the line
                final int year = Integer.parseInt(matcher.group(1));
                final Month month = Month.parseMonth(matcher.group(2));
                final AbsoluteDate date = new AbsoluteDate(year, month, 1, utc);
                if (fileDate == null) {
                    // so we compute the file date by adding 6 months to its first entry
                    if (month.getNumber() > 6) {
                        fileDate = new DateComponents(year + 1, month.getNumber() - 6, 1);
                    } else {
                        fileDate = new DateComponents(year, month.getNumber() + 6, 1);
                    }
                }
                // check if there is already an entry for this date or not
                boolean addEntry = false;
                final Iterator<TimeStamped> iterator = data.tailSet(date).iterator();
                if (iterator.hasNext()) {
                    final LineParameters existingEntry = (LineParameters) iterator.next();
                    if (existingEntry.getDate().equals(date)) {
                        // there is an entry for this date
                        if (existingEntry.getFileDate().compareTo(fileDate) < 0) {
                            // the entry was read from an earlier file
                            // we replace it with the new entry as it is fresher
                            iterator.remove();
                            addEntry = true;
                        }
                    } else {
                        // it is the first entry we get for this date
                        addEntry = true;
                    }
                } else {
                    // it is the first entry we get for this date
                    addEntry = true;
                }
                if (addEntry) {
                    // we must add the new entry
                    data.add(new LineParameters(fileDate, date, Double.parseDouble(matcher.group(f107Group)), Double.parseDouble(matcher.group(apGroup))));
                }
            } else {
                if (inData) {
                    // we consider the file is corrupted
                    throw new OrekitException(OrekitMessages.NOT_A_MARSHALL_SOLAR_ACTIVITY_FUTURE_ESTIMATION_FILE, name);
                }
            }
        }
    }
    if (data.isEmpty()) {
        throw new OrekitException(OrekitMessages.NOT_A_MARSHALL_SOLAR_ACTIVITY_FUTURE_ESTIMATION_FILE, name);
    }
    firstDate = data.first().getDate();
    lastDate = data.last().getDate();
}
Also used : InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) DateComponents(org.orekit.time.DateComponents) TimeScale(org.orekit.time.TimeScale) AbsoluteDate(org.orekit.time.AbsoluteDate) TimeStamped(org.orekit.time.TimeStamped) Month(org.orekit.time.Month) BufferedReader(java.io.BufferedReader) OrekitException(org.orekit.errors.OrekitException)

Example 3 with TimeStamped

use of org.orekit.time.TimeStamped in project Orekit by CS-SI.

the class AbstractFilesLoaderTest method getMaxGap.

protected int getMaxGap(SortedSet<? extends TimeStamped> history) {
    double maxGap = 0;
    TimeStamped previous = null;
    for (final TimeStamped current : history) {
        if (previous != null) {
            maxGap = FastMath.max(maxGap, current.getDate().durationFrom(previous.getDate()));
        }
        previous = current;
    }
    return (int) FastMath.round(maxGap / Constants.JULIAN_DAY);
}
Also used : TimeStamped(org.orekit.time.TimeStamped)

Aggregations

TimeStamped (org.orekit.time.TimeStamped)3 OrekitException (org.orekit.errors.OrekitException)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Matcher (java.util.regex.Matcher)1 DummyLocalizable (org.hipparchus.exception.DummyLocalizable)1 AbsoluteDate (org.orekit.time.AbsoluteDate)1 DateComponents (org.orekit.time.DateComponents)1 Month (org.orekit.time.Month)1 TimeScale (org.orekit.time.TimeScale)1