Search in sources :

Example 16 with DummyLocalizable

use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.

the class OEMParser method parse.

@Override
public OEMFile parse(final BufferedReader reader, final String fileName) throws OrekitException {
    try {
        // initialize internal data structures
        final ParseInfo pi = new ParseInfo();
        pi.fileName = fileName;
        final OEMFile file = pi.file;
        // set the additional data that has been configured prior the parsing by the user.
        pi.file.setMissionReferenceDate(getMissionReferenceDate());
        pi.file.setMuSet(getMu());
        pi.file.setConventions(getConventions());
        for (String line = reader.readLine(); line != null; line = reader.readLine()) {
            ++pi.lineNumber;
            if (line.trim().length() == 0) {
                continue;
            }
            pi.keyValue = new KeyValue(line, pi.lineNumber, pi.fileName);
            if (pi.keyValue.getKeyword() == null) {
                throw new OrekitException(OrekitMessages.CCSDS_UNEXPECTED_KEYWORD, pi.lineNumber, pi.fileName, line);
            }
            switch(pi.keyValue.getKeyword()) {
                case CCSDS_OEM_VERS:
                    file.setFormatVersion(pi.keyValue.getDoubleValue());
                    break;
                case META_START:
                    file.addEphemeridesBlock();
                    pi.lastEphemeridesBlock = file.getEphemeridesBlocks().get(file.getEphemeridesBlocks().size() - 1);
                    pi.lastEphemeridesBlock.getMetaData().setLaunchYear(getLaunchYear());
                    pi.lastEphemeridesBlock.getMetaData().setLaunchNumber(getLaunchNumber());
                    pi.lastEphemeridesBlock.getMetaData().setLaunchPiece(getLaunchPiece());
                    break;
                case START_TIME:
                    pi.lastEphemeridesBlock.setStartTime(parseDate(pi.keyValue.getValue(), pi.lastEphemeridesBlock.getMetaData().getTimeSystem()));
                    break;
                case USEABLE_START_TIME:
                    pi.lastEphemeridesBlock.setUseableStartTime(parseDate(pi.keyValue.getValue(), pi.lastEphemeridesBlock.getMetaData().getTimeSystem()));
                    break;
                case USEABLE_STOP_TIME:
                    pi.lastEphemeridesBlock.setUseableStopTime(parseDate(pi.keyValue.getValue(), pi.lastEphemeridesBlock.getMetaData().getTimeSystem()));
                    break;
                case STOP_TIME:
                    pi.lastEphemeridesBlock.setStopTime(parseDate(pi.keyValue.getValue(), pi.lastEphemeridesBlock.getMetaData().getTimeSystem()));
                    break;
                case INTERPOLATION:
                    pi.lastEphemeridesBlock.setInterpolationMethod(pi.keyValue.getValue());
                    break;
                case INTERPOLATION_DEGREE:
                    pi.lastEphemeridesBlock.setInterpolationDegree(Integer.parseInt(pi.keyValue.getValue()));
                    break;
                case META_STOP:
                    file.setMuUsed();
                    parseEphemeridesDataLines(reader, pi);
                    break;
                case COVARIANCE_START:
                    parseCovarianceDataLines(reader, pi);
                    break;
                default:
                    boolean parsed = false;
                    parsed = parsed || parseComment(pi.keyValue, pi.commentTmp);
                    parsed = parsed || parseHeaderEntry(pi.keyValue, file, pi.commentTmp);
                    if (pi.lastEphemeridesBlock != null) {
                        parsed = parsed || parseMetaDataEntry(pi.keyValue, pi.lastEphemeridesBlock.getMetaData(), pi.commentTmp);
                        if (parsed && pi.keyValue.getKeyword() == Keyword.REF_FRAME_EPOCH) {
                            pi.lastEphemeridesBlock.setHasRefFrameEpoch(true);
                        }
                    }
                    if (!parsed) {
                        throw new OrekitException(OrekitMessages.CCSDS_UNEXPECTED_KEYWORD, pi.lineNumber, pi.fileName, line);
                    }
            }
        }
        file.checkTimeSystems();
        return file;
    } catch (IOException ioe) {
        throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
    }
}
Also used : DummyLocalizable(org.hipparchus.exception.DummyLocalizable) OrekitException(org.orekit.errors.OrekitException) IOException(java.io.IOException)

Example 17 with DummyLocalizable

use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.

the class SimpleTimeStampedTableParser method parse.

/**
 * Parse a stream.
 * @param stream stream containing the table
 * @param name name of the resource file (for error messages only)
 * @return parsed table
 * @exception OrekitException if stream is null or the table cannot be parsed
 */
public List<T> parse(final InputStream stream, final String name) throws OrekitException {
    if (stream == null) {
        throw new OrekitException(OrekitMessages.UNABLE_TO_FIND_FILE, name);
    }
    // regular lines are simply a space separated list of numbers
    final StringBuilder builder = new StringBuilder("^\\p{Space}*");
    for (int i = 0; i < columns; ++i) {
        builder.append("(");
        builder.append(REAL_TYPE_PATTERN);
        builder.append(")");
        builder.append((i < columns - 1) ? "\\p{Space}+" : "\\p{Space}*$");
    }
    final Pattern regularLinePattern = Pattern.compile(builder.toString());
    try {
        // setup the reader
        final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        final List<T> table = new ArrayList<T>();
        for (String line = reader.readLine(); line != null; line = reader.readLine()) {
            // replace unicode minus sign ('−') by regular hyphen ('-') for parsing
            // such unicode characters occur in tables that are copy-pasted from PDF files
            line = line.replace('\u2212', '-');
            final Matcher regularMatcher = regularLinePattern.matcher(line);
            if (regularMatcher.matches()) {
                // we have found a regular data line
                final double[] rawFields = new double[columns];
                for (int i = 0; i < columns; ++i) {
                    rawFields[i] = Double.parseDouble(regularMatcher.group(i + 1));
                }
                table.add(converter.convert(rawFields));
            }
        }
        if (table.isEmpty()) {
            throw new OrekitException(OrekitMessages.NOT_A_SUPPORTED_IERS_DATA_FILE, name);
        }
        return table;
    } catch (IOException ioe) {
        throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
    }
}
Also used : DummyLocalizable(org.hipparchus.exception.DummyLocalizable) Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) OrekitException(org.orekit.errors.OrekitException)

Example 18 with DummyLocalizable

use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.

the class OPMParser method parse.

/**
 * {@inheritDoc}
 */
public OPMFile parse(final InputStream stream, final String fileName) throws OrekitException {
    try {
        final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
        // initialize internal data structures
        final ParseInfo pi = new ParseInfo();
        pi.fileName = fileName;
        final OPMFile file = pi.file;
        // set the additional data that has been configured prior the parsing by the user.
        pi.file.setMissionReferenceDate(getMissionReferenceDate());
        pi.file.setMuSet(getMu());
        pi.file.setConventions(getConventions());
        pi.file.getMetaData().setLaunchYear(getLaunchYear());
        pi.file.getMetaData().setLaunchNumber(getLaunchNumber());
        pi.file.getMetaData().setLaunchPiece(getLaunchPiece());
        for (String line = reader.readLine(); line != null; line = reader.readLine()) {
            ++pi.lineNumber;
            if (line.trim().length() == 0) {
                continue;
            }
            pi.keyValue = new KeyValue(line, pi.lineNumber, pi.fileName);
            if (pi.keyValue.getKeyword() == null) {
                throw new OrekitException(OrekitMessages.CCSDS_UNEXPECTED_KEYWORD, pi.lineNumber, pi.fileName, line);
            }
            switch(pi.keyValue.getKeyword()) {
                case CCSDS_OPM_VERS:
                    file.setFormatVersion(pi.keyValue.getDoubleValue());
                    break;
                case X:
                    pi.x = pi.keyValue.getDoubleValue() * 1000;
                    break;
                case Y:
                    pi.y = pi.keyValue.getDoubleValue() * 1000;
                    break;
                case Z:
                    pi.z = pi.keyValue.getDoubleValue() * 1000;
                    break;
                case X_DOT:
                    pi.x_dot = pi.keyValue.getDoubleValue() * 1000;
                    break;
                case Y_DOT:
                    pi.y_dot = pi.keyValue.getDoubleValue() * 1000;
                    break;
                case Z_DOT:
                    pi.z_dot = pi.keyValue.getDoubleValue() * 1000;
                    break;
                case MAN_EPOCH_IGNITION:
                    if (pi.maneuver != null) {
                        file.addManeuver(pi.maneuver);
                    }
                    pi.maneuver = new OPMFile.Maneuver();
                    pi.maneuver.setEpochIgnition(parseDate(pi.keyValue.getValue(), file.getMetaData().getTimeSystem()));
                    if (!pi.commentTmp.isEmpty()) {
                        pi.maneuver.setComment(pi.commentTmp);
                        pi.commentTmp.clear();
                    }
                    break;
                case MAN_DURATION:
                    pi.maneuver.setDuration(pi.keyValue.getDoubleValue());
                    break;
                case MAN_DELTA_MASS:
                    pi.maneuver.setDeltaMass(pi.keyValue.getDoubleValue());
                    break;
                case MAN_REF_FRAME:
                    final CCSDSFrame manFrame = parseCCSDSFrame(pi.keyValue.getValue());
                    if (manFrame.isLof()) {
                        pi.maneuver.setRefLofType(manFrame.getLofType());
                    } else {
                        pi.maneuver.setRefFrame(manFrame.getFrame(getConventions(), isSimpleEOP()));
                    }
                    break;
                case MAN_DV_1:
                    pi.maneuver.setdV(new Vector3D(pi.keyValue.getDoubleValue() * 1000, pi.maneuver.getDV().getY(), pi.maneuver.getDV().getZ()));
                    break;
                case MAN_DV_2:
                    pi.maneuver.setdV(new Vector3D(pi.maneuver.getDV().getX(), pi.keyValue.getDoubleValue() * 1000, pi.maneuver.getDV().getZ()));
                    break;
                case MAN_DV_3:
                    pi.maneuver.setdV(new Vector3D(pi.maneuver.getDV().getX(), pi.maneuver.getDV().getY(), pi.keyValue.getDoubleValue() * 1000));
                    break;
                default:
                    boolean parsed = false;
                    parsed = parsed || parseComment(pi.keyValue, pi.commentTmp);
                    parsed = parsed || parseHeaderEntry(pi.keyValue, file, pi.commentTmp);
                    parsed = parsed || parseMetaDataEntry(pi.keyValue, file.getMetaData(), pi.commentTmp);
                    parsed = parsed || parseGeneralStateDataEntry(pi.keyValue, file, pi.commentTmp);
                    if (!parsed) {
                        throw new OrekitException(OrekitMessages.CCSDS_UNEXPECTED_KEYWORD, pi.lineNumber, pi.fileName, line);
                    }
            }
        }
        file.setPosition(new Vector3D(pi.x, pi.y, pi.z));
        file.setVelocity(new Vector3D(pi.x_dot, pi.y_dot, pi.z_dot));
        if (pi.maneuver != null) {
            file.addManeuver(pi.maneuver);
        }
        reader.close();
        return file;
    } catch (IOException ioe) {
        throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
    }
}
Also used : DummyLocalizable(org.hipparchus.exception.DummyLocalizable) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) BufferedReader(java.io.BufferedReader) OrekitException(org.orekit.errors.OrekitException)

Example 19 with DummyLocalizable

use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.

the class OrekitExceptionTest method testNullString.

/**
 * Check {@link OrekitException#getMessage()} does not throw a NPE.
 */
@Test
public void testNullString() {
    // action
    OrekitException exception = new OrekitException(new DummyLocalizable(null));
    // verify
    Assert.assertEquals(exception.getMessage(), "");
}
Also used : DummyLocalizable(org.hipparchus.exception.DummyLocalizable) Test(org.junit.Test)

Example 20 with DummyLocalizable

use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.

the class FieldEcksteinHechlerPropagatorTest method doWrongAttitude.

private <T extends RealFieldElement<T>> void doWrongAttitude(Field<T> field) throws OrekitException {
    T zero = field.getZero();
    FieldAbsoluteDate<T> date = new FieldAbsoluteDate<>(field);
    FieldKeplerianOrbit<T> orbit = new FieldKeplerianOrbit<>(zero.add(1.0e10), zero.add(1.0e-4), zero.add(1.0e-2), zero, zero, zero, PositionAngle.TRUE, FramesFactory.getEME2000(), date, 3.986004415e14);
    final DummyLocalizable gasp = new DummyLocalizable("gasp");
    AttitudeProvider wrongLaw = new AttitudeProvider() {

        private static final long serialVersionUID = 1L;

        @Override
        public Attitude getAttitude(PVCoordinatesProvider pvProv, AbsoluteDate date, Frame frame) throws OrekitException {
            throw new OrekitException(gasp, new RuntimeException());
        }

        @Override
        public <Q extends RealFieldElement<Q>> FieldAttitude<Q> getAttitude(FieldPVCoordinatesProvider<Q> pvProv, FieldAbsoluteDate<Q> date, Frame frame) throws OrekitException {
            throw new OrekitException(gasp, new RuntimeException());
        }
    };
    try {
        FieldEcksteinHechlerPropagator<T> propagator = new FieldEcksteinHechlerPropagator<>(orbit, wrongLaw, provider);
        propagator.propagate(date.shiftedBy(10.0));
        Assert.fail("an exception should have been thrown");
    } catch (OrekitException oe) {
        Assert.assertSame(gasp, oe.getSpecifier());
    }
}
Also used : DummyLocalizable(org.hipparchus.exception.DummyLocalizable) Frame(org.orekit.frames.Frame) TopocentricFrame(org.orekit.frames.TopocentricFrame) RealFieldElement(org.hipparchus.RealFieldElement) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) FieldKeplerianOrbit(org.orekit.orbits.FieldKeplerianOrbit) FieldPVCoordinatesProvider(org.orekit.utils.FieldPVCoordinatesProvider) PVCoordinatesProvider(org.orekit.utils.PVCoordinatesProvider) FieldPVCoordinatesProvider(org.orekit.utils.FieldPVCoordinatesProvider) OrekitException(org.orekit.errors.OrekitException) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AttitudeProvider(org.orekit.attitudes.AttitudeProvider)

Aggregations

DummyLocalizable (org.hipparchus.exception.DummyLocalizable)22 OrekitException (org.orekit.errors.OrekitException)21 IOException (java.io.IOException)10 AbsoluteDate (org.orekit.time.AbsoluteDate)8 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)7 BufferedReader (java.io.BufferedReader)6 InputStreamReader (java.io.InputStreamReader)6 Test (org.junit.Test)6 AttitudeProvider (org.orekit.attitudes.AttitudeProvider)6 Frame (org.orekit.frames.Frame)6 TopocentricFrame (org.orekit.frames.TopocentricFrame)6 FieldPVCoordinatesProvider (org.orekit.utils.FieldPVCoordinatesProvider)6 PVCoordinatesProvider (org.orekit.utils.PVCoordinatesProvider)6 Matcher (java.util.regex.Matcher)4 RealFieldElement (org.hipparchus.RealFieldElement)4 FieldKeplerianOrbit (org.orekit.orbits.FieldKeplerianOrbit)4 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)4 InputStream (java.io.InputStream)3 Pattern (java.util.regex.Pattern)3 File (java.io.File)2