use of org.orekit.time.DateComponents in project Orekit by CS-SI.
the class GRGSFormatReader method loadData.
/**
* {@inheritDoc}
*/
public void loadData(final InputStream input, final String name) throws IOException, ParseException, OrekitException {
// reset the indicator before loading any data
setReadComplete(false);
referenceDate = null;
cDot.clear();
sDot.clear();
// FIELD - GRIM5, VERSION : C1, november 1999
// AE 1/F GM OMEGA
// 0.63781364600000E+070.29825765000000E+030.39860044150000E+150.72921150000000E-04
// REFERENCE DATE : 1997.00
// MAXIMAL DEGREE : 120 Sigmas calibration factor : .5000E+01 (applied)
// L M DOT CBAR SBAR SIGMA C SIGMA S
// 2 0DOT 0.13637590952454E-10 0.00000000000000E+00 .143968E-11 .000000E+00
// 3 0DOT 0.28175700027753E-11 0.00000000000000E+00 .496704E-12 .000000E+00
// 4 0DOT 0.12249148508277E-10 0.00000000000000E+00 .129977E-11 .000000E+00
// 0 0 .99999999988600E+00 .00000000000000E+00 .153900E-09 .000000E+00
// 2 0 -0.48416511550920E-03 0.00000000000000E+00 .204904E-10 .000000E+00
final BufferedReader r = new BufferedReader(new InputStreamReader(input, "UTF-8"));
int lineNumber = 0;
double[][] c = null;
double[][] s = null;
for (String line = r.readLine(); line != null; line = r.readLine()) {
++lineNumber;
// match current header or data line
final Matcher matcher = LINES[FastMath.min(LINES.length, lineNumber) - 1].matcher(line);
if (!matcher.matches()) {
throw new OrekitParseException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name, line);
}
if (lineNumber == 3) {
// header line defining ae, 1/f, GM and Omega
setAe(parseDouble(matcher.group(1)));
setMu(parseDouble(matcher.group(3)));
} else if (lineNumber == 4) {
// header line containing the reference date
referenceDate = new DateComponents(Integer.parseInt(matcher.group(1)), 1, 1);
} else if (lineNumber == 5) {
// header line defining max degree
final int degree = FastMath.min(getMaxParseDegree(), Integer.parseInt(matcher.group(1)));
final int order = FastMath.min(getMaxParseOrder(), degree);
c = buildTriangularArray(degree, order, missingCoefficientsAllowed() ? 0.0 : Double.NaN);
s = buildTriangularArray(degree, order, missingCoefficientsAllowed() ? 0.0 : Double.NaN);
} else if (lineNumber > 6) {
// data line
final int i = Integer.parseInt(matcher.group(1).trim());
final int j = Integer.parseInt(matcher.group(2).trim());
if (i < c.length && j < c[i].length) {
if ("DOT".equals(matcher.group(3).trim())) {
// store the secular drift coefficients
extendListOfLists(cDot, i, j, 0.0);
extendListOfLists(sDot, i, j, 0.0);
parseCoefficient(matcher.group(4), cDot, i, j, "Cdot", name);
parseCoefficient(matcher.group(5), sDot, i, j, "Sdot", name);
} else {
// store the constant coefficients
parseCoefficient(matcher.group(4), c, i, j, "C", name);
parseCoefficient(matcher.group(5), s, i, j, "S", name);
}
}
}
}
if (missingCoefficientsAllowed() && c.length > 0 && c[0].length > 0) {
// ensure at least the (0, 0) element is properly set
if (Precision.equals(c[0][0], 0.0, 0)) {
c[0][0] = 1.0;
}
}
setRawCoefficients(true, c, s, name);
setTideSystem(TideSystem.UNKNOWN);
setReadComplete(true);
}
use of org.orekit.time.DateComponents 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();
}
use of org.orekit.time.DateComponents in project Orekit by CS-SI.
the class SHMFormatReader method loadData.
/**
* {@inheritDoc}
*/
public void loadData(final InputStream input, final String name) throws IOException, ParseException, OrekitException {
// reset the indicator before loading any data
setReadComplete(false);
referenceDate = null;
cDot.clear();
sDot.clear();
boolean normalized = false;
TideSystem tideSystem = TideSystem.UNKNOWN;
final BufferedReader r = new BufferedReader(new InputStreamReader(input, "UTF-8"));
boolean okEarth = false;
boolean okSHM = false;
boolean okCoeffs = false;
double[][] c = null;
double[][] s = null;
String line = r.readLine();
if ((line != null) && "FIRST ".equals(line.substring(0, 6)) && "SHM ".equals(line.substring(49, 56))) {
for (line = r.readLine(); line != null; line = r.readLine()) {
if (line.length() >= 6) {
final String[] tab = line.split("\\s+");
// read the earth values
if ("EARTH".equals(tab[0])) {
setMu(parseDouble(tab[1]));
setAe(parseDouble(tab[2]));
okEarth = true;
}
// initialize the arrays
if ("SHM".equals(tab[0])) {
final int degree = FastMath.min(getMaxParseDegree(), Integer.parseInt(tab[1]));
final int order = FastMath.min(getMaxParseOrder(), degree);
c = buildTriangularArray(degree, order, missingCoefficientsAllowed() ? 0.0 : Double.NaN);
s = buildTriangularArray(degree, order, missingCoefficientsAllowed() ? 0.0 : Double.NaN);
final String lowerCaseLine = line.toLowerCase(Locale.US);
normalized = lowerCaseLine.contains("fully normalized");
if (lowerCaseLine.contains("exclusive permanent tide")) {
tideSystem = TideSystem.TIDE_FREE;
} else {
tideSystem = TideSystem.UNKNOWN;
}
okSHM = true;
}
// fill the arrays
if (GRCOEF.equals(line.substring(0, 6)) || GRCOF2.equals(tab[0]) || GRDOTA.equals(tab[0])) {
final int i = Integer.parseInt(tab[1]);
final int j = Integer.parseInt(tab[2]);
if (i < c.length && j < c[i].length) {
if (GRDOTA.equals(tab[0])) {
// store the secular drift coefficients
extendListOfLists(cDot, i, j, 0.0);
extendListOfLists(sDot, i, j, 0.0);
parseCoefficient(tab[3], cDot, i, j, "Cdot", name);
parseCoefficient(tab[4], sDot, i, j, "Sdot", name);
// check the reference date (format yyyymmdd)
final DateComponents localRef = new DateComponents(Integer.parseInt(tab[7].substring(0, 4)), Integer.parseInt(tab[7].substring(4, 6)), Integer.parseInt(tab[7].substring(6, 8)));
if (referenceDate == null) {
// first reference found, store it
referenceDate = localRef;
} else if (!referenceDate.equals(localRef)) {
throw new OrekitException(OrekitMessages.SEVERAL_REFERENCE_DATES_IN_GRAVITY_FIELD, referenceDate, localRef, name);
}
} else {
// store the constant coefficients
parseCoefficient(tab[3], c, i, j, "C", name);
parseCoefficient(tab[4], s, i, j, "S", name);
okCoeffs = true;
}
}
}
}
}
}
if (missingCoefficientsAllowed() && c.length > 0 && c[0].length > 0) {
// ensure at least the (0, 0) element is properly set
if (Precision.equals(c[0][0], 0.0, 0)) {
c[0][0] = 1.0;
}
}
if (!(okEarth && okSHM && okCoeffs)) {
String loaderName = getClass().getName();
loaderName = loaderName.substring(loaderName.lastIndexOf('.') + 1);
throw new OrekitException(OrekitMessages.UNEXPECTED_FILE_FORMAT_ERROR_FOR_LOADER, name, loaderName);
}
setRawCoefficients(normalized, c, s, name);
setTideSystem(tideSystem);
setReadComplete(true);
}
use of org.orekit.time.DateComponents in project Orekit by CS-SI.
the class ConstantThrustManeuverTest method testRoughBehaviour.
@Test
public void testRoughBehaviour() throws OrekitException {
final double isp = 318;
final double mass = 2500;
final double a = 24396159;
final double e = 0.72831215;
final double i = FastMath.toRadians(7);
final double omega = FastMath.toRadians(180);
final double OMEGA = FastMath.toRadians(261);
final double lv = 0;
final double duration = 3653.99;
final double f = 420;
final double delta = FastMath.toRadians(-7.4978);
final double alpha = FastMath.toRadians(351);
final AttitudeProvider law = new InertialProvider(new Rotation(new Vector3D(alpha, delta), Vector3D.PLUS_I));
final AbsoluteDate initDate = new AbsoluteDate(new DateComponents(2004, 01, 01), new TimeComponents(23, 30, 00.000), TimeScalesFactory.getUTC());
final Orbit orbit = new KeplerianOrbit(a, e, i, omega, OMEGA, lv, PositionAngle.TRUE, FramesFactory.getEME2000(), initDate, mu);
final SpacecraftState initialState = new SpacecraftState(orbit, law.getAttitude(orbit, orbit.getDate(), orbit.getFrame()), mass);
final AbsoluteDate fireDate = new AbsoluteDate(new DateComponents(2004, 01, 02), new TimeComponents(04, 15, 34.080), TimeScalesFactory.getUTC());
final ConstantThrustManeuver maneuver = new ConstantThrustManeuver(fireDate, duration, f, isp, Vector3D.PLUS_I);
Assert.assertEquals(f, maneuver.getThrust(), 1.0e-10);
Assert.assertEquals(isp, maneuver.getISP(), 1.0e-10);
double[] absTolerance = { 0.001, 1.0e-9, 1.0e-9, 1.0e-6, 1.0e-6, 1.0e-6, 0.001 };
double[] relTolerance = { 1.0e-7, 1.0e-4, 1.0e-4, 1.0e-7, 1.0e-7, 1.0e-7, 1.0e-7 };
AdaptiveStepsizeIntegrator integrator = new DormandPrince853Integrator(0.001, 1000, absTolerance, relTolerance);
integrator.setInitialStepSize(60);
final NumericalPropagator propagator = new NumericalPropagator(integrator);
propagator.setInitialState(initialState);
propagator.setAttitudeProvider(law);
propagator.addForceModel(maneuver);
final SpacecraftState finalorb = propagator.propagate(fireDate.shiftedBy(3800));
final double massTolerance = FastMath.abs(maneuver.getFlowRate()) * maneuver.getEventsDetectors().findFirst().get().getThreshold();
Assert.assertEquals(2007.8824544261233, finalorb.getMass(), massTolerance);
Assert.assertEquals(2.6872, FastMath.toDegrees(MathUtils.normalizeAngle(finalorb.getI(), FastMath.PI)), 1e-4);
Assert.assertEquals(28970, finalorb.getA() / 1000, 1);
}
use of org.orekit.time.DateComponents in project Orekit by CS-SI.
the class ConstantThrustManeuverTest method testNegativeDuration.
@Test
public void testNegativeDuration() throws OrekitException {
AbsoluteDate date = new AbsoluteDate(new DateComponents(2004, 01, 01), new TimeComponents(23, 30, 00.000), TimeScalesFactory.getUTC());
ConstantThrustManeuver maneuver = new ConstantThrustManeuver(date, -10.0, 400.0, 300.0, Vector3D.PLUS_K, "1A-");
ParameterDriver[] drivers = maneuver.getParametersDrivers();
Assert.assertEquals(2, drivers.length);
Assert.assertEquals("1A-thrust", drivers[0].getName());
Assert.assertEquals("1A-flow rate", drivers[1].getName());
EventDetector[] switches = maneuver.getEventsDetectors().toArray(EventDetector[]::new);
Orbit o1 = dummyOrbit(date.shiftedBy(-11.0));
Assert.assertTrue(switches[0].g(new SpacecraftState(o1)) < 0);
Orbit o2 = dummyOrbit(date.shiftedBy(-9.0));
Assert.assertTrue(switches[0].g(new SpacecraftState(o2)) > 0);
Orbit o3 = dummyOrbit(date.shiftedBy(-1.0));
Assert.assertTrue(switches[1].g(new SpacecraftState(o3)) < 0);
Orbit o4 = dummyOrbit(date.shiftedBy(1.0));
Assert.assertTrue(switches[1].g(new SpacecraftState(o4)) > 0);
}
Aggregations