Commit 6427ccba authored by Bryan Cazabonne's avatar Bryan Cazabonne
Browse files

Merge branch 'issue-844' into release-11.0

parents 0584cca7 80ed27c3
......@@ -18,9 +18,9 @@ package org.orekit.files.ilrs;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.hipparchus.geometry.euclidean.threed.Vector3D;
import org.orekit.files.general.EphemerisFile;
......@@ -54,8 +54,8 @@ public class CPF implements EphemerisFile<CPF.CPFCoordinate, CPF.CPFEphemeris> {
/** CPF file header. */
private CPFHeader header;
/** List containing satellite information. */
private CPFEphemeris ephemeris;
/** Map containing satellite information. */
private Map<String, CPFEphemeris> ephemeris;
/** List of comments contained in the file. */
private List<String> comments;
......@@ -65,7 +65,7 @@ public class CPF implements EphemerisFile<CPF.CPFCoordinate, CPF.CPFEphemeris> {
*/
public CPF() {
this.mu = Double.NaN;
this.ephemeris = new CPFEphemeris();
this.ephemeris = new ConcurrentHashMap<>();
this.header = new CPFHeader();
this.comments = new ArrayList<>();
}
......@@ -75,12 +75,8 @@ public class CPF implements EphemerisFile<CPF.CPFCoordinate, CPF.CPFEphemeris> {
*/
@Override
public Map<String, CPFEphemeris> getSatellites() {
// Initialise an empty map
final Map<String, CPFEphemeris> satellites = new HashMap<>();
// Add the value
satellites.put(ephemeris.getId(), ephemeris);
// Return the map
return Collections.unmodifiableMap(satellites);
return Collections.unmodifiableMap(ephemeris);
}
/**
......@@ -110,9 +106,35 @@ public class CPF implements EphemerisFile<CPF.CPFCoordinate, CPF.CPFEphemeris> {
/**
* Adds a new P/V coordinate to the satellite.
* @param coord the P/V coordinate of the satellite
* @deprecated as of 11.0.1, replaced by {@link #addSatelliteCoordinates(String, CPFCoordinate)}
*/
@Deprecated
public void addSatelliteCoordinate(final CPFCoordinate coord) {
ephemeris.coordinates.add(coord);
final String id = header.getIlrsSatelliteId();
createIfNeeded(id);
ephemeris.get(id).coordinates.add(coord);
}
/**
* Adds a set of P/V coordinates to the satellite.
* @param id satellite ILRS identifier
* @param coord set of coordinates
* @since 11.0.1
*/
public void addSatelliteCoordinates(final String id, final List<CPFCoordinate> coord) {
createIfNeeded(id);
ephemeris.get(id).coordinates.addAll(coord);
}
/**
* Add a new P/V coordinates to the satellite.
* @param id satellite ILRS identifier
* @param coord the P/V coordinate of the satellite
* @since 11.0.1
*/
public void addSatelliteCoordinate(final String id, final CPFCoordinate coord) {
createIfNeeded(id);
ephemeris.get(id).coordinates.add(coord);
}
/**
......@@ -147,19 +169,46 @@ public class CPF implements EphemerisFile<CPF.CPFCoordinate, CPF.CPFEphemeris> {
this.filter = filter;
}
/**
* Create the satellite ephemeris corresponding to the given ID (if needed).
* @param id satellite ILRS identifier
*/
private void createIfNeeded(final String id) {
if (ephemeris.get(id) == null) {
ephemeris.put(id, new CPFEphemeris(id));
}
}
/** An ephemeris entry for a single satellite contains in a CPF file. */
public class CPFEphemeris
implements EphemerisFile.SatelliteEphemeris<CPFCoordinate, CPFEphemeris>,
EphemerisFile.EphemerisSegment<CPFCoordinate> {
/** Satellite ID. */
private final String id;
/** Ephemeris Data. */
private final List<CPFCoordinate> coordinates;
/** Constructor. */
/**
* Constructor.
* @deprecated as of 11.0.1, replaced by
*/
@Deprecated
public CPFEphemeris() {
this(null);
}
/**
* Constructor.
* @param id satellite ID
*/
public CPFEphemeris(final String id) {
this.id = id;
this.coordinates = new ArrayList<>();
}
/** {@inheritDoc} */
@Override
public Frame getFrame() {
......@@ -187,7 +236,7 @@ public class CPF implements EphemerisFile<CPF.CPFCoordinate, CPF.CPFEphemeris> {
/** {@inheritDoc} */
@Override
public String getId() {
return header.getIlrsSatelliteId();
return id == null ? header.getIlrsSatelliteId() : id;
}
/** {@inheritDoc} */
......
......@@ -478,7 +478,7 @@ public class CPFParser implements EphemerisFileParser<CPF> {
// CPF coordinate
final CPF.CPFCoordinate coordinate = new CPF.CPFCoordinate(date, position, leap);
pi.file.addSatelliteCoordinate(coordinate);
pi.file.addSatelliteCoordinate(pi.file.getHeader().getIlrsSatelliteId(), coordinate);
}
......
......@@ -28,8 +28,10 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import org.hipparchus.geometry.euclidean.threed.Vector3D;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -41,6 +43,8 @@ import org.orekit.errors.OrekitIllegalArgumentException;
import org.orekit.errors.OrekitMessages;
import org.orekit.files.ilrs.CPF.CPFCoordinate;
import org.orekit.files.ilrs.CPF.CPFEphemeris;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.DateComponents;
import org.orekit.time.TimeScalesFactory;
public class CPFWriterTest {
......@@ -136,6 +140,102 @@ public class CPFWriterTest {
}
}
/** Test for issue #844 (https://gitlab.orekit.org/orekit/orekit/-/issues/844). */
@Test
public void testIssue844() throws IOException {
// Create header
final CPFHeader header = new CPFHeader();
header.setSource("orekit");
header.setStep(300);
header.setStartEpoch(AbsoluteDate.J2000_EPOCH.shiftedBy(-300.0));
header.setEndEpoch(AbsoluteDate.J2000_EPOCH.shiftedBy(300.0));
header.setIlrsSatelliteId("070595");
header.setName("tag");
header.setNoradId("0705");
header.setProductionEpoch(new DateComponents(2000, 1, 2));
header.setProductionHour(12);
header.setSequenceNumber(0705);
header.setSic("0705");
final CPFHeader headerV1 = header;
headerV1.setVersion(1);
// Writer
final CPFWriter writer = new CPFWriter(headerV1, TimeScalesFactory.getUTC());
// Create an empty CPF file
final CPF cpf = new CPF();
// Fast check
assertEquals(0, cpf.getSatellites().size());
// Add coordinates
final int leap = 0;
cpf.addSatelliteCoordinate(header.getIlrsSatelliteId(), new CPFCoordinate(AbsoluteDate.J2000_EPOCH.shiftedBy(-300.0), Vector3D.PLUS_I, leap));
cpf.addSatelliteCoordinate(header.getIlrsSatelliteId(), new CPFCoordinate(AbsoluteDate.J2000_EPOCH, Vector3D.PLUS_J, leap));
cpf.addSatelliteCoordinate(header.getIlrsSatelliteId(), new CPFCoordinate(AbsoluteDate.J2000_EPOCH.shiftedBy(300.0), Vector3D.PLUS_K, leap));
// Write the file
String tempCPFFilePath = tempFolder.newFile("TestWriteCPF.cpf").toString();
writer.write(tempCPFFilePath, cpf);
// Verify
final List<CPFCoordinate> coordinatesInFile = cpf.getSatellites().get(header.getIlrsSatelliteId()).getCoordinates();
assertEquals(0.0, Vector3D.PLUS_I.distance(coordinatesInFile.get(0).getPosition()), 1.0e-10);
assertEquals(0.0, Vector3D.PLUS_J.distance(coordinatesInFile.get(1).getPosition()), 1.0e-10);
assertEquals(0.0, Vector3D.PLUS_K.distance(coordinatesInFile.get(2).getPosition()), 1.0e-10);
}
/** Test for issue #844 (https://gitlab.orekit.org/orekit/orekit/-/issues/844). */
@Test
public void testIssue844Bis() throws IOException {
// Create header
final CPFHeader header = new CPFHeader();
header.setSource("orekit");
header.setStep(300);
header.setStartEpoch(AbsoluteDate.J2000_EPOCH.shiftedBy(-300.0));
header.setEndEpoch(AbsoluteDate.J2000_EPOCH.shiftedBy(300.0));
header.setIlrsSatelliteId("070595");
header.setName("tag");
header.setNoradId("0705");
header.setProductionEpoch(new DateComponents(2000, 1, 2));
header.setProductionHour(12);
header.setSequenceNumber(0705);
header.setSic("0705");
final CPFHeader headerV1 = header;
headerV1.setVersion(1);
// Writer
final CPFWriter writer = new CPFWriter(headerV1, TimeScalesFactory.getUTC());
// Create an empty CPF file
final CPF cpf = new CPF();
// Fast check
assertEquals(0, cpf.getSatellites().size());
// Add coordinates
final int leap = 0;
final List<CPFCoordinate> coordinates = new ArrayList<>();
coordinates.add(new CPFCoordinate(AbsoluteDate.J2000_EPOCH.shiftedBy(-300.0), Vector3D.PLUS_I, leap));
coordinates.add(new CPFCoordinate(AbsoluteDate.J2000_EPOCH, Vector3D.PLUS_J, leap));
coordinates.add(new CPFCoordinate(AbsoluteDate.J2000_EPOCH.shiftedBy(300.0), Vector3D.PLUS_K, leap));
cpf.addSatelliteCoordinates(header.getIlrsSatelliteId(), coordinates);
// Write the file
String tempCPFFilePath = tempFolder.newFile("TestWriteCPF.cpf").toString();
writer.write(tempCPFFilePath, cpf);
// Verify
final List<CPFCoordinate> coordinatesInFile = cpf.getSatellites().get(header.getIlrsSatelliteId()).getCoordinates();
assertEquals(0.0, Vector3D.PLUS_I.distance(coordinatesInFile.get(0).getPosition()), 1.0e-10);
assertEquals(0.0, Vector3D.PLUS_J.distance(coordinatesInFile.get(1).getPosition()), 1.0e-10);
assertEquals(0.0, Vector3D.PLUS_K.distance(coordinatesInFile.get(2).getPosition()), 1.0e-10);
}
public static void compareCpfFiles(CPF file1, CPF file2) {
// Header
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment