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()));
}
}
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()));
}
}
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()));
}
}
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(), "");
}
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());
}
}
Aggregations