Commit 8cce4593 authored by GC's avatar GC
Browse files

First commit concerning issue-790.

- Added CPFWriter constructor with optional velocity flag
- Added writeEphemerisLine method with optional velocity flag
parent 120ad8ff
......@@ -51,16 +51,30 @@ public class CPFWriter implements EphemerisFileWriter {
/** Time scale for dates. */
private final TimeScale timescale;
/** Flag for optional velocity record. */
private final boolean velocityFlag;
/**
* Constructor.
* @param header container for header data
* @param timescale time scale for dates
*/
public CPFWriter(final CPFHeader header, final TimeScale timescale) {
this(header, timescale, false);
}
/**
* Constructor.
* @param header container for header data
* @param timescale time scale for dates
* @param velocityFlag the flag for the optional velocity record
*/
public CPFWriter(final CPFHeader header, final TimeScale timescale, final boolean velocityFlag) {
this.header = header;
this.timescale = timescale;
}
this.velocityFlag = velocityFlag;
}
/** {@inheritDoc} */
@Override
......@@ -93,7 +107,7 @@ public class CPFWriter implements EphemerisFileWriter {
final Segment segmentWriter = cpfWriter.newSegment(header.getRefFrame());
// Loop on coordinates
for (final TimeStampedPVCoordinates coordinates : segment.getCoordinates()) {
segmentWriter.writeEphemerisLine(coordinates);
segmentWriter.writeEphemerisLine(coordinates, velocityFlag);
}
}
......
......@@ -91,6 +91,9 @@ public class StreamingCpfWriter {
/** Real 17.3 Format. */
private static final String F17_3 = "%17.3f";
/** Real 19.6 Format. */
private static final String F19_6 = "%19.6f";
/** Space. */
private static final String SPACE = " ";
......@@ -278,7 +281,7 @@ public class StreamingCpfWriter {
}
/**
* Write a single ephemeris line This method does not
* Write a single ephemeris line with position record. This method does not
* write the velocity terms.
*
* @param pv the time, position, and velocity to write.
......@@ -286,6 +289,18 @@ public class StreamingCpfWriter {
*/
public void writeEphemerisLine(final TimeStampedPVCoordinates pv)
throws IOException {
writeEphemerisLine(pv, false);
}
/**
* Write two ephemeris lines with position and velocity records.
*
* @param pv the time, position, and velocity to write.
* @param velocityFlag flag for the optional velocity record.
* @throws IOException if the output stream throws one while writing.
*/
public void writeEphemerisLine(final TimeStampedPVCoordinates pv, final boolean velocityFlag)
throws IOException {
// Record type and direction flag
writeValue(writer, A2, "10", true);
......@@ -309,6 +324,23 @@ public class StreamingCpfWriter {
// New line
writer.append(NEW_LINE);
// Write the velocity record
if (velocityFlag) {
// Record type and direction flag
writeValue(writer, A2, "20", true);
writeValue(writer, I1, DEFAULT_DIRECTION_FLAG, true);
// Velocity
final Vector3D velocity = pv.getVelocity();
writeValue(writer, F19_6, velocity.getX(), true);
writeValue(writer, F19_6, velocity.getY(), true);
writeValue(writer, F19_6, velocity.getZ(), false);
// New line
writer.append(NEW_LINE);
}
}
}
......
Supports Markdown
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