use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.
the class PoissonSeriesParser method parse.
/**
* Parse a stream.
* @param stream stream containing the IERS table
* @param name name of the resource file (for error messages only)
* @return parsed Poisson series
* @exception OrekitException if stream is null or the table cannot be parsed
*/
public PoissonSeries parse(final InputStream stream, final String name) throws OrekitException {
if (stream == null) {
throw new OrekitException(OrekitMessages.UNABLE_TO_FIND_FILE, name);
}
// the degrees section header should read something like:
// j = 0 Nb of terms = 1306
// or something like:
// j = 0 Number of terms = 1037
final Pattern degreeSectionHeaderPattern = Pattern.compile("^\\p{Space}*j\\p{Space}*=\\p{Space}*(\\p{Digit}+)" + "[\\p{Alpha}\\p{Space}]+=\\p{Space}*(\\p{Digit}+)\\p{Space}*$");
// regular lines are simply a space separated list of numbers
final StringBuilder builder = new StringBuilder("^\\p{Space}*");
for (int i = 0; i < fieldsPatterns.length; ++i) {
builder.append("(");
builder.append(fieldsPatterns[i]);
builder.append(")");
builder.append((i < fieldsPatterns.length - 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"));
int lineNumber = 0;
int expectedIndex = -1;
int nTerms = -1;
int count = 0;
int degree = 0;
// prepare the container for the parsed data
PolynomialNutation polynomial;
if (polynomialParser == null) {
// we don't expect any polynomial, we directly set the zero polynomial
polynomial = new PolynomialNutation(new double[0]);
} else {
// the dedicated parser will fill in the polynomial later
polynomial = null;
}
final Map<Long, SeriesTerm> series = new HashMap<Long, SeriesTerm>();
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', '-');
++lineNumber;
final Matcher regularMatcher = regularLinePattern.matcher(line);
if (regularMatcher.matches()) {
if (expectedIndex > 0) {
// we are in a file were terms are numbered, we check the index
if (Integer.parseInt(regularMatcher.group(1)) != expectedIndex) {
throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name, regularMatcher.group());
}
}
// get the Doodson multipliers as well as the Doodson number
final int cTau = (firstDoodson < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstDoodson));
final int cS = (firstDoodson < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstDoodson + 1));
final int cH = (firstDoodson < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstDoodson + 2));
final int cP = (firstDoodson < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstDoodson + 3));
final int cNprime = (firstDoodson < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstDoodson + 4));
final int cPs = (firstDoodson < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstDoodson + 5));
final int nDoodson = (doodson < 0) ? 0 : Integer.parseInt(regularMatcher.group(doodson).replaceAll("[.,]", ""));
// get the tide multiplier
int cGamma = (gamma < 0) ? 0 : Integer.parseInt(regularMatcher.group(gamma));
// get the Delaunay multipliers
int cL = Integer.parseInt(regularMatcher.group(firstDelaunay));
int cLPrime = Integer.parseInt(regularMatcher.group(firstDelaunay + 1));
int cF = Integer.parseInt(regularMatcher.group(firstDelaunay + 2));
int cD = Integer.parseInt(regularMatcher.group(firstDelaunay + 3));
int cOmega = Integer.parseInt(regularMatcher.group(firstDelaunay + 4));
// get the planetary multipliers
final int cMe = (firstPlanetary < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstPlanetary));
final int cVe = (firstPlanetary < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstPlanetary + 1));
final int cE = (firstPlanetary < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstPlanetary + 2));
final int cMa = (firstPlanetary < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstPlanetary + 3));
final int cJu = (firstPlanetary < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstPlanetary + 4));
final int cSa = (firstPlanetary < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstPlanetary + 5));
final int cUr = (firstPlanetary < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstPlanetary + 6));
final int cNe = (firstPlanetary < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstPlanetary + 7));
final int cPa = (firstPlanetary < 0) ? 0 : Integer.parseInt(regularMatcher.group(firstPlanetary + 8));
if (nDoodson > 0) {
// set up the traditional parameters corresponding to the Doodson arguments
cGamma = cTau;
cL = -cL;
cLPrime = -cLPrime;
cF = -cF;
cD = -cD;
cOmega = -cOmega;
// check Doodson number, Doodson multipliers and Delaunay multipliers consistency
if (nDoodson != doodsonToDoodsonNumber(cTau, cS, cH, cP, cNprime, cPs) || nDoodson != delaunayToDoodsonNumber(cGamma, cL, cLPrime, cF, cD, cOmega)) {
throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name, regularMatcher.group());
}
}
final long key = NutationCodec.encode(cGamma, cL, cLPrime, cF, cD, cOmega, cMe, cVe, cE, cMa, cJu, cSa, cUr, cNe, cPa);
// retrieved the term, or build it if it's the first time it is encountered in the file
final SeriesTerm term;
if (series.containsKey(key)) {
// the term was already known, from another degree
term = series.get(key);
} else {
// the term is a new one
term = SeriesTerm.buildTerm(cGamma, cL, cLPrime, cF, cD, cOmega, cMe, cVe, cE, cMa, cJu, cSa, cUr, cNe, cPa);
}
boolean nonZero = false;
for (int d = 0; d < sinCosColumns.length / 2; ++d) {
final double sinCoeff = parseCoefficient(regularMatcher, sinCosColumns[2 * d], sinCosFactors[2 * d]);
final double cosCoeff = parseCoefficient(regularMatcher, sinCosColumns[2 * d + 1], sinCosFactors[2 * d + 1]);
if (!Precision.equals(sinCoeff, 0.0, 0) || !Precision.equals(cosCoeff, 0.0, 0)) {
nonZero = true;
term.add(0, degree + d, sinCoeff, cosCoeff);
++count;
}
}
if (nonZero) {
series.put(key, term);
}
if (expectedIndex > 0) {
// we are in a file were terms are numbered
// we must update the expected value for next term
++expectedIndex;
}
} else {
final Matcher headerMatcher = degreeSectionHeaderPattern.matcher(line);
if (headerMatcher.matches()) {
// we have found a degree section header
final int nextDegree = Integer.parseInt(headerMatcher.group(1));
if ((nextDegree != degree + 1) && (degree != 0 || nextDegree != 0)) {
throw new OrekitException(OrekitMessages.MISSING_SERIE_J_IN_FILE, degree + 1, name, lineNumber);
}
if (nextDegree == 0) {
// in IERS files split in sections, all terms are numbered
// we can check the indices
expectedIndex = 1;
}
if (nextDegree > 0 && count != nTerms) {
// the previous degree does not have the expected number of terms
throw new OrekitException(OrekitMessages.NOT_A_SUPPORTED_IERS_DATA_FILE, name);
}
// remember the number of terms the upcoming sublist should have
nTerms = Integer.parseInt(headerMatcher.group(2));
count = 0;
degree = nextDegree;
} else if (polynomial == null) {
// look for the polynomial part
final double[] coefficients = polynomialParser.parse(line);
if (coefficients != null) {
polynomial = new PolynomialNutation(coefficients);
}
}
}
}
if (polynomial == null || series.isEmpty()) {
throw new OrekitException(OrekitMessages.NOT_A_SUPPORTED_IERS_DATA_FILE, name);
}
if (nTerms > 0 && count != nTerms) {
// the last degree does not have the expected number of terms
throw new OrekitException(OrekitMessages.NOT_A_SUPPORTED_IERS_DATA_FILE, name);
}
// build the series
return new PoissonSeries(polynomial, series);
} 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 OMMParser method parse.
/**
* {@inheritDoc}
*/
public OMMFile 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 OMMFile 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_OMM_VERS:
file.setFormatVersion(pi.keyValue.getDoubleValue());
break;
case MEAN_ELEMENT_THEORY:
file.getMetaData().setMeanElementTheory(pi.keyValue.getValue());
break;
case MEAN_MOTION:
file.setMeanMotion(pi.keyValue.getDoubleValue() * FastMath.PI / 43200.0);
break;
case EPHEMERIS_TYPE:
file.setTLERelatedParametersComment(pi.commentTmp);
pi.commentTmp.clear();
file.setEphemerisType(Integer.parseInt(pi.keyValue.getValue()));
break;
case CLASSIFICATION_TYPE:
file.setClassificationType(pi.keyValue.getValue().charAt(0));
break;
case NORAD_CAT_ID:
file.setNoradID(Integer.parseInt(pi.keyValue.getValue()));
break;
case ELEMENT_SET_NO:
file.setElementSetNo(pi.keyValue.getValue());
break;
case REV_AT_EPOCH:
file.setRevAtEpoch(Integer.parseInt(pi.keyValue.getValue()));
break;
case BSTAR:
file.setbStar(pi.keyValue.getDoubleValue());
break;
case MEAN_MOTION_DOT:
file.setMeanMotionDot(pi.keyValue.getDoubleValue() * FastMath.PI / 1.86624e9);
break;
case MEAN_MOTION_DDOT:
file.setMeanMotionDotDot(pi.keyValue.getDoubleValue() * FastMath.PI / 5.3747712e13);
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);
}
}
}
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 EcksteinHechlerPropagatorTest method wrongAttitude.
@Test(expected = OrekitException.class)
public void wrongAttitude() throws OrekitException {
KeplerianOrbit orbit = new KeplerianOrbit(1.0e10, 1.0e-4, 1.0e-2, 0, 0, 0, PositionAngle.TRUE, FramesFactory.getEME2000(), AbsoluteDate.J2000_EPOCH, 3.986004415e14);
AttitudeProvider wrongLaw = new AttitudeProvider() {
private static final long serialVersionUID = 5918362126173997016L;
public Attitude getAttitude(PVCoordinatesProvider pvProv, AbsoluteDate date, Frame frame) throws OrekitException {
throw new OrekitException(new DummyLocalizable("gasp"), new RuntimeException());
}
public <T extends RealFieldElement<T>> FieldAttitude<T> getAttitude(FieldPVCoordinatesProvider<T> pvProv, FieldAbsoluteDate<T> date, Frame frame) throws OrekitException {
throw new OrekitException(new DummyLocalizable("gasp"), new RuntimeException());
}
};
EcksteinHechlerPropagator propagator = new EcksteinHechlerPropagator(orbit, wrongLaw, provider);
propagator.propagate(AbsoluteDate.J2000_EPOCH.shiftedBy(10.0));
}
use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.
the class FieldKeplerianPropagatorTest method doTestWrappedAttitudeException.
private <T extends RealFieldElement<T>> void doTestWrappedAttitudeException(Field<T> field) throws OrekitException {
T zero = field.getZero();
final FieldKeplerianOrbit<T> orbit = new FieldKeplerianOrbit<>(zero.add(7.8e6), zero.add(0.032), zero.add(0.4), zero.add(0.1), zero.add(0.2), zero.add(0.3), PositionAngle.TRUE, FramesFactory.getEME2000(), new FieldAbsoluteDate<>(field), 3.986004415e14);
FieldKeplerianPropagator<T> propagator = new FieldKeplerianPropagator<>(orbit, new AttitudeProvider() {
private static final long serialVersionUID = 1L;
public Attitude getAttitude(PVCoordinatesProvider pvProv, AbsoluteDate date, Frame frame) throws OrekitException {
throw new OrekitException((Throwable) null, new DummyLocalizable("dummy error"));
}
public <Q extends RealFieldElement<Q>> FieldAttitude<Q> getAttitude(FieldPVCoordinatesProvider<Q> pvProv, FieldAbsoluteDate<Q> date, Frame frame) throws OrekitException {
throw new OrekitException((Throwable) null, new DummyLocalizable("dummy error"));
}
});
propagator.propagate(orbit.getDate().shiftedBy(10.09));
}
use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.
the class SolarInputs97to05 method read.
private void read(BufferedReader rFlux, BufferedReader rAp) throws IOException, OrekitException {
rFlux.readLine();
rFlux.readLine();
rFlux.readLine();
rFlux.readLine();
rAp.readLine();
String lineAp;
String[] flux;
String[] ap;
Calendar cal = new GregorianCalendar();
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
cal.set(0, 0, 0, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
AbsoluteDate date = null;
boolean first = true;
for (String lineFlux = rFlux.readLine(); lineFlux != null; lineFlux = rFlux.readLine()) {
flux = lineFlux.trim().split("\\s+");
lineAp = rAp.readLine();
if (lineAp == null) {
throw new OrekitException(new DummyLocalizable("inconsistent JB2006 and geomagnetic indices files"));
}
ap = lineAp.trim().split("\\s+");
int fluxYear = Integer.parseInt(flux[0]);
int fluxDay = Integer.parseInt(flux[1]);
int apYear = Integer.parseInt(ap[11]);
if (fluxDay != Integer.parseInt(ap[0])) {
throw new OrekitException(new DummyLocalizable("inconsistent JB2006 and geomagnetic indices files"));
}
if (((fluxYear < 2000) && ((fluxYear - 1900) != apYear)) || ((fluxYear >= 2000) && ((fluxYear - 2000) != apYear))) {
throw new OrekitException(new DummyLocalizable("inconsistent JB2006 and geomagnetic indices files"));
}
cal.set(Calendar.YEAR, fluxYear);
cal.set(Calendar.DAY_OF_YEAR, fluxDay);
date = new AbsoluteDate(cal.getTime(), TimeScalesFactory.getUTC());
if (first) {
first = false;
firstDate = date;
}
data.add(new LineParameters(date, new double[] { Double.parseDouble(ap[3]), Double.parseDouble(ap[4]), Double.parseDouble(ap[5]), Double.parseDouble(ap[6]), Double.parseDouble(ap[7]), Double.parseDouble(ap[8]), Double.parseDouble(ap[9]), Double.parseDouble(ap[10]) }, Double.parseDouble(flux[3]), Double.parseDouble(flux[4]), Double.parseDouble(flux[5]), Double.parseDouble(flux[6]), Double.parseDouble(flux[7]), Double.parseDouble(flux[8])));
}
lastDate = date;
}
Aggregations