Commit 5b8a1bac authored by Louis Aucouturier's avatar Louis Aucouturier
Browse files

Initial commit : Issue 886 CRD Parser rollover

- The solution retained is to add 2 variables to store the past
secOfDay, to check for day change, and the number of times a day change
has happenened.
- A test was implemented to check the days of the records parsed, using
a simplified version of the file provided by Clément Jonglez
parent 826358b8
......@@ -125,21 +125,21 @@ public class CRDParser {
final ParseInfo pi = new ParseInfo();
int lineNumber = 0;
Stream<LineParser> cdrParsers = Stream.of(LineParser.H1);
Stream<LineParser> crdParsers = Stream.of(LineParser.H1);
try (BufferedReader reader = new BufferedReader(source.getOpener().openReaderOnce())) {
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
++lineNumber;
final String l = line;
final Optional<LineParser> selected = cdrParsers.filter(p -> p.canHandle(l)).findFirst();
final Optional<LineParser> selected = crdParsers.filter(p -> p.canHandle(l)).findFirst();
if (selected.isPresent()) {
try {
selected.get().parse(line, pi);
} catch (StringIndexOutOfBoundsException | NumberFormatException e) {
throw new OrekitException(e,
OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE,
lineNumber, source.getName(), line);
OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE,
lineNumber, source.getName(), line);
}
cdrParsers = selected.get().allowedNext();
crdParsers = selected.get().allowedNext();
}
if (pi.done) {
// Return file
......@@ -153,6 +153,18 @@ public class CRDParser {
}
/**
* Computes if a day shift has happened comparing the current and past epoch, described by seconds in the day.
* This is useful as the data is sorted in the chronological order inside the file.
*
* @param lastSecOfDay
* @param secOfDay
* @return Boolean true if change in day.
*/
private static int checkRollover(final double lastSecOfDay, final double secOfDay) {
return (secOfDay > lastSecOfDay) ? 0 : 1;
}
/** Transient data used for parsing a CRD file. The data is kept in a
* separate data structure to make the parser thread-safe.
* <p><b>Note</b>: The class intentionally does not provide accessor
......@@ -349,8 +361,8 @@ public class CRDParser {
pi.startEpoch = new DateComponents(yearS, monthS, dayS);
pi.header.setStartEpoch(new AbsoluteDate(yearS, monthS, dayS,
hourS, minuteS, secondS,
pi.timeScale));
hourS, minuteS, secondS,
pi.timeScale));
// End epoch
final int yearE = Integer.parseInt(values[8]);
......@@ -361,8 +373,8 @@ public class CRDParser {
final double secondE = Integer.parseInt(values[13]);
pi.header.setEndEpoch(new AbsoluteDate(yearE, monthE, dayE,
hourE, minuteE, secondE,
pi.timeScale));
hourE, minuteE, secondE,
pi.timeScale));
// Data release
pi.header.setDataReleaseFlag(Integer.parseInt(values[14]));
......@@ -701,6 +713,12 @@ public class CRDParser {
/** Range Record (Full rate, Sampled Engineering/Quicklook). */
TEN("10") {
/** Storage for the last epoch parsed to compare with the current.*/
private double lastSecOfDay = 0;
/** Shift in days due to the rollover.*/
private int dayShift = 0;
/** {@inheritDoc} */
@Override
public void parse(final String line, final ParseInfo pi) {
......@@ -713,11 +731,14 @@ public class CRDParser {
final double timeOfFlight = Double.parseDouble(values[2]);
final int epochEvent = Integer.parseInt(values[4]);
// Check secOfDay for rollover
dayShift = dayShift + checkRollover(lastSecOfDay, secOfDay);
// Initialise a new Range measurement
final AbsoluteDate epoch = new AbsoluteDate(pi.startEpoch, new TimeComponents(secOfDay), pi.timeScale);
final AbsoluteDate epoch = new AbsoluteDate(pi.startEpoch, new TimeComponents(secOfDay), pi.timeScale).shiftedBy(dayShift * 86400);
final RangeMeasurement range = new RangeMeasurement(epoch, timeOfFlight, epochEvent);
pi.dataBlock.addRangeData(range);
lastSecOfDay = secOfDay;
}
/** {@inheritDoc} */
......@@ -731,6 +752,12 @@ public class CRDParser {
/** Range Record (Normal point). */
ELEVEN("11") {
/** Storage for the last epoch parsed to compare with the current.*/
private double lastSecOfDay = 0;
/** Shift in days due to the rollover.*/
private int dayShift = 0;
/** {@inheritDoc} */
@Override
public void parse(final String line, final ParseInfo pi) {
......@@ -744,8 +771,10 @@ public class CRDParser {
final int epochEvent = Integer.parseInt(values[4]);
final double snr = (pi.version == 2) ? Double.parseDouble(values[13]) : Double.NaN;
// Check secOfDay for rollover
dayShift = dayShift + checkRollover(lastSecOfDay, secOfDay);
// Initialise a new Range measurement
final AbsoluteDate epoch = new AbsoluteDate(pi.startEpoch, new TimeComponents(secOfDay), pi.timeScale);
final AbsoluteDate epoch = new AbsoluteDate(pi.startEpoch, new TimeComponents(secOfDay), pi.timeScale).shiftedBy(dayShift * 86400);
final RangeMeasurement range = new RangeMeasurement(epoch, timeOfFlight, epochEvent, snr);
pi.dataBlock.addRangeData(range);
......@@ -779,6 +808,12 @@ public class CRDParser {
/** Meteorological record. */
METEO("20") {
/** Storage for the last epoch parsed to compare with the current.*/
private double lastSecOfDay = 0;
/** Shift in days due to the rollover.*/
private int dayShift = 0;
/** {@inheritDoc} */
@Override
public void parse(final String line, final ParseInfo pi) {
......@@ -792,10 +827,12 @@ public class CRDParser {
final double temperature = Double.parseDouble(values[3]);
final double humidity = Double.parseDouble(values[4]);
// Initialise a new meteorological measurement
final AbsoluteDate epoch = new AbsoluteDate(pi.startEpoch, new TimeComponents(secOfDay), pi.timeScale);
// Check secOfDay for rollover
dayShift = dayShift + checkRollover(lastSecOfDay, secOfDay);
// Initialise a new Range measurement
final AbsoluteDate epoch = new AbsoluteDate(pi.startEpoch, new TimeComponents(secOfDay), pi.timeScale).shiftedBy(dayShift * 86400);
final MeteorologicalMeasurement meteo = new MeteorologicalMeasurement(epoch, pressure,
temperature, humidity);
temperature, humidity);
pi.dataBlock.addMeteoData(meteo);
}
......@@ -828,6 +865,12 @@ public class CRDParser {
/** Pointing Angle Record. */
ANGLES("30") {
/** Storage for the last epoch parsed to compare with the current.*/
private double lastSecOfDay = 0;
/** Shift in days due to the rollover.*/
private int dayShift = 0;
/** {@inheritDoc} */
@Override
public void parse(final String line, final ParseInfo pi) {
......@@ -852,12 +895,14 @@ public class CRDParser {
elevationRate = readDoubleWithNaN(values[8]);
}
// Check secOfDay for rollover
dayShift = dayShift + checkRollover(lastSecOfDay, secOfDay);
// Initialise a new angles measurement
final AbsoluteDate epoch = new AbsoluteDate(pi.startEpoch, new TimeComponents(secOfDay), pi.timeScale);
final AnglesMeasurement angles = new AnglesMeasurement(epoch, azmiuth, elevation,
directionFlag, orginFlag,
isRefractionCorrected,
azimuthRate, elevationRate);
directionFlag, orginFlag,
isRefractionCorrected,
azimuthRate, elevationRate);
pi.dataBlock.addAnglesData(angles);
}
......@@ -972,7 +1017,7 @@ public class CRDParser {
@Override
public Stream<LineParser> allowedNext() {
return Stream.of(H1, H2, H3, H4, H5, H8, H9, C0, C1, C2, C3, C4, C5, C6, C7, TEN, ELEVEN, TWELVE, METEO,
METEO_SUPP, ANGLES, CALIB, CALIB_DETAILS, CALIB_SHOT, STAT, COMPATIBILITY, COMMENTS);
METEO_SUPP, ANGLES, CALIB, CALIB_DETAILS, CALIB_SHOT, STAT, COMPATIBILITY, COMMENTS);
}
......
......@@ -26,6 +26,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.orekit.Utils;
import org.orekit.data.DataContext;
import org.orekit.data.DataSource;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitMessages;
......@@ -36,6 +37,8 @@ import org.orekit.files.ilrs.CRD.MeteorologicalMeasurement;
import org.orekit.files.ilrs.CRD.RangeMeasurement;
import org.orekit.files.ilrs.CRDConfiguration.TransponderConfiguration;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.DateComponents;
import org.orekit.time.TimeComponents;
import org.orekit.time.TimeScalesFactory;
public class CRDParserTest {
......@@ -556,6 +559,29 @@ public class CRDParserTest {
Assert.assertEquals("New experimental detector (transistor) in the START channel", file.getComments().get(5));
}
@Test
public void testIssue886() throws IOException {
final String ex = "/ilrs/glonass125_trunc.frd";
final CRD file = new CRDParser().parse(new DataSource(ex, () -> getClass().getResourceAsStream(ex)));
final CRDDataBlock block = file.getDataBlocks().get(0);
final List<RangeMeasurement> rangeBlock = block.getRangeData();
final RangeMeasurement rangeFirst = rangeBlock.get(0);
final RangeMeasurement rangeLast = rangeBlock.get(rangeBlock.size() - 1);
DateComponents startEpoch = new DateComponents(2019, 04, 21);
DateComponents lastEpoch = new DateComponents(2019, 04, 22);
double firstSecOfDay = 77387.019063653420;
double lastSecOfDay = 694.119563650340;
final AbsoluteDate firstDate = new AbsoluteDate(startEpoch, new TimeComponents(firstSecOfDay), DataContext.getDefault().getTimeScales().getUTC());
final AbsoluteDate lastDate = new AbsoluteDate(lastEpoch, new TimeComponents(lastSecOfDay), DataContext.getDefault().getTimeScales().getUTC());
Assert.assertEquals(firstDate, rangeFirst.getDate());
Assert.assertEquals(lastDate, rangeLast.getDate());
}
@Before
public void setUp() {
Utils.setDataRoot("regular-data");
......
H1 CRD 01 2020 12 01 06
H2 GRZL 7839 34 02 04
H3 glonass125 1100901 9125 37372 0 1
H4 0 2019 04 19 21 29 47 2019 04 20 00 12 00 1 0 0 0 1 0 2 0
C0 0 532.000 0902 2kHz C_SPAD1 GPS
C1 0 2kHz Nd:Van 1064 2000 0.400 10 10 1
C2 0 C_SPAD1 SPAD 532.0 20 5.0 400 +1V 10 0.3 35 300 WinClean2.2
C3 0 GPS HP58503A HP58503A Graz_Dassault NoSN 0.077
20 77387.000 970.22 287.53 39.2 1
20 720.000 970.41 285.84 40.2 1
40 77387.000 0 0902 10000 8390 1.742 111916.9 2.9 17.0 0.010 -0.651 -1.0 2 2 0
40 720.000 0 0902 10000 8000 1.742 111919.8 2.9 17.0 0.030 -0.673 -1.0 2 2 0
10 77387.019063653420 0.143461677858 0902 2 2 0 0 0
10 77387.090063657610 0.143461365733 0902 2 2 0 0 0
10 77388.997563663870 0.143452977259 0902 2 2 0 0 0
10 77391.000563651320 0.143444170781 0902 2 2 0 0 0
10 77391.283063657580 0.143442929505 0902 2 2 0 0 0
10 77391.556063670670 0.143441728802 0902 2 2 0 0 0
10 77392.200563652440 0.143438895855 0902 2 2 0 0 0
10 77392.374063657600 0.143438132585 0902 2 2 0 0 0
10 77392.633063659070 0.143436994198 0902 2 2 0 0 0
10 77392.665563672780 0.143436851848 0902 2 2 0 0 0
10 77393.748563651000 0.143432091173 0902 2 2 0 0 0
10 77393.927563652400 0.143431304356 0902 2 2 0 0 0
10 77393.948563661430 0.143431212246 0902 2 2 0 0 0
10 77393.950563659890 0.143431203597 0902 2 2 0 0 0
10 77394.011063663290 0.143430937426 0902 2 2 0 0 0
10 77394.049063660200 0.143430770120 0902 2 2 0 0 0
10 77394.081563651560 0.143430627700 0902 2 2 0 0 0
10 77394.082563657310 0.143430623462 0902 2 2 0 0 0
10 77394.096063653010 0.143430564025 0902 2 2 0 0 0
10 77394.099063660950 0.143430550160 0902 2 2 0 0 0
10 77394.127063659950 0.143430427738 0902 2 2 0 0 0
10 77394.152063652870 0.143430317751 0902 2 2 0 0 0
10 77394.152563655750 0.143430315149 0902 2 2 0 0 0
10 77394.154063653200 0.143430309119 0902 2 2 0 0 0
10 77394.208063650880 0.143430071812 0902 2 2 0 0 0
10 77394.439563671130 0.143429053713 0902 2 2 0 0 0
10 77394.794563652950 0.143427494096 0902 2 2 0 0 0
10 77394.796063650400 0.143427487277 0902 2 2 0 0 0
10 77394.800063651060 0.143427469644 0902 2 2 0 0 0
10 77394.850063649940 0.143427249708 0902 2 2 0 0 0
10 77395.133063649760 0.143426006258 0902 2 2 0 0 0
10 77395.200563659890 0.143425709011 0902 2 2 0 0 0
10 77395.304063655440 0.143425254862 0902 2 2 0 0 0
10 77395.436063652860 0.143424674343 0902 2 2 0 0 0
10 77395.505063658580 0.143424371088 0902 2 2 0 0 0
10 77396.580063676460 0.143419647002 0902 2 2 0 0 0
10 77396.959563653920 0.143417978855 0902 2 2 0 0 0
10 77397.042563658210 0.143417614190 0902 2 2 0 0 0
10 77397.176063653080 0.143417027472 0902 2 2 0 0 0
10 77397.185563663020 0.143416985813 0902 2 2 0 0 0
10 77397.316063649950 0.143416412675 0902 2 2 0 0 0
10 77397.351563660430 0.143416256917 0902 2 2 0 0 0
10 77397.382563652470 0.143416120388 0902 2 2 0 0 0
10 77397.396563652900 0.143416058916 0902 2 2 0 0 0
10 77397.456063663590 0.143415797824 0902 2 2 0 0 0
10 77397.469063656400 0.143415739847 0902 2 2 0 0 0
10 77397.482563653960 0.143415681139 0902 2 2 0 0 0
10 77397.508563652630 0.143415566762 0902 2 2 0 0 0
10 77397.514063663780 0.143415542719 0902 2 2 0 0 0
10 77397.585563657810 0.143415227932 0902 2 2 0 0 0
10 77397.594563649970 0.143415189049 0902 2 2 0 0 0
10 77397.597563657910 0.143415175819 0902 2 2 0 0 0
10 77397.623063655570 0.143415063264 0902 2 2 0 0 0
10 77397.662563649940 0.143414890111 0902 2 2 0 0 0
10 77397.667563658210 0.143414868203 0902 2 2 0 0 0
10 77397.671563658860 0.143414850080 0902 2 2 0 0 0
10 77397.675063652920 0.143414834748 0902 2 2 0 0 0
10 77397.675563657660 0.143414833111 0902 2 2 0 0 0
10 77397.682563651350 0.143414802147 0902 2 2 0 0 0
10 77397.685063652690 0.143414791203 0902 2 2 0 0 0
10 77397.685563657430 0.143414789130 0902 2 2 0 0 0
10 77397.698563650250 0.143414731519 0902 2 2 0 0 0
10 77397.706063659860 0.143414698542 0902 2 2 0 0 0
10 77397.744063660500 0.143414531986 0902 2 2 0 0 0
10 77397.753063652660 0.143414492498 0902 2 2 0 0 0
10 77397.758063660930 0.143414470083 0902 2 2 0 0 0
10 77397.763563659040 0.143414446004 0902 2 2 0 0 0
10 77397.770563650880 0.143414415310 0902 2 2 0 0 0
10 77397.840063661340 0.143414109652 0902 2 2 0 0 0
10 77397.844063660130 0.143414092688 0902 2 2 0 0 0
10 77397.845563655720 0.143414086037 0902 2 2 0 0 0
10 77397.869563655930 0.143413979974 0902 2 2 0 0 0
10 77397.876563662660 0.143413949679 0902 2 2 0 0 0
10 77397.885563654830 0.143413909995 0902 2 2 0 0 0
10 77397.893063653260 0.143413876750 0902 2 2 0 0 0
10 77397.898063657810 0.143413854867 0902 2 2 0 0 0
10 671.848563656210 0.136965827613 0902 2 2 0 0 0
10 672.077063662930 0.136966754102 0902 2 2 0 0 0
10 672.325063653290 0.136967758715 0902 2 2 0 0 0
10 673.034563653170 0.136970634791 0902 2 2 0 0 0
10 675.047063652430 0.136978795036 0902 2 2 0 0 0
10 675.899063650520 0.136982250310 0902 2 2 0 0 0
10 677.607563653960 0.136989181284 0902 2 2 0 0 0
10 678.429063670340 0.136992514663 0902 2 2 0 0 0
10 678.919563652950 0.136994505117 0902 2 2 0 0 0
10 688.554963653910 0.137033649123 0902 2 2 0 0 0
10 688.832163656130 0.137034776220 0902 2 2 0 0 0
10 689.053863655780 0.137035677495 0902 2 2 0 0 0
10 689.931963657960 0.137039249212 0902 2 2 0 0 0
10 690.064063670110 0.137039786435 0902 2 2 0 0 0
10 690.097563652320 0.137039922514 0902 2 2 0 0 0
10 690.179663674910 0.137040256435 0902 2 2 0 0 0
10 690.283763663840 0.137040679671 0902 2 2 0 0 0
10 690.384763656180 0.137041090940 0902 2 2 0 0 0
10 690.513863660400 0.137041615861 0902 2 2 0 0 0
10 690.550963653250 0.137041766631 0902 2 2 0 0 0
10 690.593463661150 0.137041939980 0902 2 2 0 0 0
10 690.597463650630 0.137041955833 0902 2 2 0 0 0
10 690.600963657720 0.137041970278 0902 2 2 0 0 0
10 690.779563656080 0.137042697046 0902 2 2 0 0 0
10 691.012763662260 0.137043645199 0902 2 2 0 0 0
10 691.019763663410 0.137043673674 0902 2 2 0 0 0
10 691.021763658150 0.137043681966 0902 2 2 0 0 0
10 691.024263668810 0.137043691983 0902 2 2 0 0 0
10 691.099863663320 0.137043999957 0902 2 2 0 0 0
10 691.188363652680 0.137044359563 0902 2 2 0 0 0
10 691.216363649820 0.137044473999 0902 2 2 0 0 0
10 691.546663653110 0.137045817872 0902 2 2 0 0 0
10 691.565663652490 0.137045894868 0902 2 2 0 0 0
10 691.583663657310 0.137045968106 0902 2 2 0 0 0
10 691.624663667750 0.137046135157 0902 2 2 0 0 0
10 691.644763655960 0.137046216576 0902 2 2 0 0 0
10 691.645763652400 0.137046221118 0902 2 2 0 0 0
10 691.668763672930 0.137046314768 0902 2 2 0 0 0
10 691.675763657320 0.137046342945 0902 2 2 0 0 0
10 691.698263667520 0.137046434359 0902 2 2 0 0 0
10 691.705263653770 0.137046462953 0902 2 2 0 0 0
10 691.705763651060 0.137046464721 0902 2 2 0 0 0
10 691.736263670030 0.137046589377 0902 2 2 0 0 0
10 691.817363653330 0.137046919111 0902 2 2 0 0 0
10 691.838363651190 0.137047004879 0902 2 2 0 0 0
10 691.839863659810 0.137047010537 0902 2 2 0 0 0
10 691.841363674030 0.137047016511 0902 2 2 0 0 0
10 692.033463658760 0.137047798473 0902 2 2 0 0 0
10 692.090563651170 0.137048030528 0902 2 2 0 0 0
10 692.158563660460 0.137048307286 0902 2 2 0 0 0
10 692.543363662440 0.137049873440 0902 2 2 0 0 0
10 692.551363674920 0.137049906024 0902 2 2 0 0 0
10 692.563363663850 0.137049954583 0902 2 2 0 0 0
10 692.765563672410 0.137050777508 0902 2 2 0 0 0
10 692.807063670830 0.137050946815 0902 2 2 0 0 0
10 692.813563656060 0.137050972962 0902 2 2 0 0 0
10 692.816563650970 0.137050985499 0902 2 2 0 0 0
10 692.832063658160 0.137051048639 0902 2 2 0 0 0
10 692.925163660200 0.137051426911 0902 2 2 0 0 0
10 692.937663663180 0.137051478062 0902 2 2 0 0 0
10 692.948163652790 0.137051520859 0902 2 2 0 0 0
10 692.952663658190 0.137051538894 0902 2 2 0 0 0
10 692.971663676200 0.137051616161 0902 2 2 0 0 0
10 692.999663658440 0.137051730663 0902 2 2 0 0 0
10 693.201363658530 0.137052551301 0902 2 2 0 0 0
10 693.387963658200 0.137053310614 0902 2 2 0 0 0
10 693.802763663230 0.137054999043 0902 2 2 0 0 0
10 693.883863663300 0.137055329176 0902 2 2 0 0 0
10 693.886363659050 0.137055339336 0902 2 2 0 0 0
10 693.898363661020 0.137055388199 0902 2 2 0 0 0
10 693.906863655890 0.137055422749 0902 2 2 0 0 0
10 693.925863659010 0.137055500664 0902 2 2 0 0 0
10 694.032463662330 0.137055934538 0902 2 2 0 0 0
10 694.119563650340 0.137056288730 0902 2 2 0 0 0
H8
H9
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