use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.
the class TDMParser method parseXml.
/**
* Parse a CCSDS Tracking Data Message with XML format.
* @param stream stream containing message
* @param fileName name of the file containing the message (for error messages)
* @return parsed file content in a TDMFile object
* @exception OrekitException if Tracking Date Message cannot be parsed
*/
public TDMFile parseXml(final InputStream stream, final String fileName) throws OrekitException {
try {
// Create the handler
final XMLHandler handler = new XMLHandler(new ParseInfo(this.getMissionReferenceDate(), this.getConventions(), this.isSimpleEOP(), fileName));
// Create the XML SAX parser factory
final SAXParserFactory factory = SAXParserFactory.newInstance();
// Build the parser and read the xml file
final SAXParser parser = factory.newSAXParser();
parser.parse(stream, handler);
// Get the content of the file
final TDMFile tdmFile = handler.parseInfo.tdmFile;
// Check time systems consistency
tdmFile.checkTimeSystems();
return tdmFile;
} catch (ParserConfigurationException | SAXException | IOException e) {
// throw caught exception as an OrekitException
throw new OrekitException(e, new DummyLocalizable(e.getMessage()));
}
}
use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.
the class DTM2000 method readcoefficients.
/**
* Store the DTM model elements coefficients in internal arrays.
* @exception OrekitException if some resource file reading error occurs
*/
private static void readcoefficients() throws OrekitException {
final int size = NLATM + 1;
tt = new double[size];
h = new double[size];
he = new double[size];
o = new double[size];
az2 = new double[size];
o2 = new double[size];
az = new double[size];
t0 = new double[size];
tp = new double[size];
final InputStream in = DTM2000.class.getResourceAsStream(DTM2000);
if (in == null) {
throw new OrekitException(OrekitMessages.UNABLE_TO_FIND_RESOURCE, DTM2000);
}
BufferedReader r = null;
try {
r = new BufferedReader(new InputStreamReader(in, "UTF-8"));
r.readLine();
r.readLine();
for (String line = r.readLine(); line != null; line = r.readLine()) {
final int num = Integer.parseInt(line.substring(0, 4).replace(' ', '0'));
line = line.substring(4);
tt[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
line = line.substring(13 + 9);
h[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
line = line.substring(13 + 9);
he[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
line = line.substring(13 + 9);
o[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
line = line.substring(13 + 9);
az2[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
line = line.substring(13 + 9);
o2[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
line = line.substring(13 + 9);
az[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
line = line.substring(13 + 9);
t0[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
line = line.substring(13 + 9);
tp[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
}
} catch (IOException ioe) {
throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
} finally {
if (r != null) {
try {
r.close();
} 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 ClasspathCrawler method feed.
/**
* {@inheritDoc}
*/
public boolean feed(final Pattern supported, final DataLoader visitor) throws OrekitException {
try {
OrekitException delayedException = null;
boolean loaded = false;
for (final String name : listElements) {
try {
if (visitor.stillAcceptsData()) {
if (ZIP_ARCHIVE_PATTERN.matcher(name).matches()) {
// browse inside the zip/jar file
final DataProvider zipProvider = new ZipJarCrawler(name);
loaded = zipProvider.feed(supported, visitor) || loaded;
} else {
// remove suffix from gzip files
final Matcher gzipMatcher = GZIP_FILE_PATTERN.matcher(name);
final String baseName = gzipMatcher.matches() ? gzipMatcher.group(1) : name;
if (supported.matcher(baseName).matches()) {
final InputStream stream = classLoader.getResourceAsStream(name);
final URI uri = classLoader.getResource(name).toURI();
// visit the current file
if (gzipMatcher.matches()) {
visitor.loadData(new GZIPInputStream(stream), uri.toString());
} else {
visitor.loadData(stream, uri.toString());
}
stream.close();
loaded = true;
}
}
}
} catch (OrekitException oe) {
// maybe the next path component will be able to provide data
// wait until all components have been tried
delayedException = oe;
} catch (URISyntaxException use) {
// this should bever happen
throw new OrekitException(use, LocalizedCoreFormats.SIMPLE_MESSAGE, use.getMessage());
}
}
if (!loaded && delayedException != null) {
throw delayedException;
}
return loaded;
} catch (IOException ioe) {
throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
} catch (ParseException pe) {
throw new OrekitException(pe, new DummyLocalizable(pe.getMessage()));
}
}
use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.
the class NetworkCrawler method feed.
/**
* {@inheritDoc}
*/
public boolean feed(final Pattern supported, final DataLoader visitor) throws OrekitException {
try {
OrekitException delayedException = null;
boolean loaded = false;
for (URL url : urls) {
try {
if (visitor.stillAcceptsData()) {
final String name = url.toURI().toString();
final String fileName = new File(url.getPath()).getName();
if (ZIP_ARCHIVE_PATTERN.matcher(fileName).matches()) {
// browse inside the zip/jar file
new ZipJarCrawler(url).feed(supported, visitor);
loaded = true;
} else {
// remove suffix from gzip files
final Matcher gzipMatcher = GZIP_FILE_PATTERN.matcher(fileName);
final String baseName = gzipMatcher.matches() ? gzipMatcher.group(1) : fileName;
if (supported.matcher(baseName).matches()) {
final InputStream stream = getStream(url);
// visit the current file
if (gzipMatcher.matches()) {
visitor.loadData(new GZIPInputStream(stream), name);
} else {
visitor.loadData(stream, name);
}
stream.close();
loaded = true;
}
}
}
} catch (OrekitException oe) {
// maybe the next path component will be able to provide data
// wait until all components have been tried
delayedException = oe;
}
}
if (!loaded && delayedException != null) {
throw delayedException;
}
return loaded;
} catch (URISyntaxException | IOException | ParseException e) {
throw new OrekitException(e, new DummyLocalizable(e.getMessage()));
}
}
use of org.hipparchus.exception.DummyLocalizable in project Orekit by CS-SI.
the class FundamentalNutationArguments method parseCoefficients.
/**
* Parse coefficients.
* @param stream stream containing the IERS table
* @param name name of the resource file (for error messages only)
* @return list of coefficients arrays
* @exception OrekitException if stream is null or the table cannot be parsed
*/
private static List<double[]> parseCoefficients(final InputStream stream, final String name) throws OrekitException {
if (stream == null) {
throw new OrekitException(OrekitMessages.UNABLE_TO_FIND_FILE, name);
}
try {
final DefinitionParser definitionParser = new DefinitionParser();
// setup the reader
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
int lineNumber = 0;
// look for the reference date and the 14 polynomials
final int n = FundamentalName.values().length;
final Map<FundamentalName, double[]> polynomials = new HashMap<FundamentalName, double[]>(n);
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
lineNumber++;
if (definitionParser.parseDefinition(line, lineNumber, name)) {
polynomials.put(definitionParser.getParsedName(), definitionParser.getParsedPolynomial());
}
}
final List<double[]> coefficients = new ArrayList<double[]>(n);
coefficients.add(getCoefficients(FundamentalName.L, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.L_PRIME, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.F, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.D, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.OMEGA, polynomials, name));
if (polynomials.containsKey(FundamentalName.L_ME)) {
// IERS conventions 2003 and later provide planetary nutation arguments
coefficients.add(getCoefficients(FundamentalName.L_ME, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.L_VE, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.L_E, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.L_MA, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.L_J, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.L_SA, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.L_U, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.L_NE, polynomials, name));
coefficients.add(getCoefficients(FundamentalName.PA, polynomials, name));
} else {
// IERS conventions 1996 and earlier don't provide planetary nutation arguments
final double[] zero = new double[] { 0.0 };
while (coefficients.size() < n) {
coefficients.add(zero);
}
}
return coefficients;
} catch (IOException ioe) {
throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
}
}
Aggregations