Commit cb1eb853 authored by Luc Maisonobe's avatar Luc Maisonobe

Improved test coverage.

parent 28daf9e9
...@@ -92,9 +92,6 @@ public class GlobalPressureTemperature2Model implements WeatherModel { ...@@ -92,9 +92,6 @@ public class GlobalPressureTemperature2Model implements WeatherModel {
/** Shared lazily loaded grid. */ /** Shared lazily loaded grid. */
private static final AtomicReference<Grid> SHARED_GRID = new AtomicReference<>(null); private static final AtomicReference<Grid> SHARED_GRID = new AtomicReference<>(null);
/** Regular expression for supported file name. */
private final String supportedNames;
/** South-West grid entry. */ /** South-West grid entry. */
private final GridEntry southWest; private final GridEntry southWest;
...@@ -142,13 +139,12 @@ public class GlobalPressureTemperature2Model implements WeatherModel { ...@@ -142,13 +139,12 @@ public class GlobalPressureTemperature2Model implements WeatherModel {
*/ */
public GlobalPressureTemperature2Model(final String supportedNames, final double latitude, public GlobalPressureTemperature2Model(final String supportedNames, final double latitude,
final double longitude, final Geoid geoid) { final double longitude, final Geoid geoid) {
this.coefficientsA = null; this.coefficientsA = null;
this.temperature = Double.NaN; this.temperature = Double.NaN;
this.pressure = Double.NaN; this.pressure = Double.NaN;
this.e0 = Double.NaN; this.e0 = Double.NaN;
this.supportedNames = supportedNames; this.geoid = geoid;
this.geoid = geoid; this.latitude = latitude;
this.latitude = latitude;
// get the lazily loaded shared grid // get the lazily loaded shared grid
Grid grid = SHARED_GRID.get(); Grid grid = SHARED_GRID.get();
...@@ -213,13 +209,6 @@ public class GlobalPressureTemperature2Model implements WeatherModel { ...@@ -213,13 +209,6 @@ public class GlobalPressureTemperature2Model implements WeatherModel {
return e0; return e0;
} }
/** Returns the supported names of the loader.
* @return the supported names
*/
public String getSupportedNames() {
return supportedNames;
}
@Override @Override
public void weatherParameters(final double stationHeight, final AbsoluteDate currentDate) { public void weatherParameters(final double stationHeight, final AbsoluteDate currentDate) {
...@@ -393,23 +382,23 @@ public class GlobalPressureTemperature2Model implements WeatherModel { ...@@ -393,23 +382,23 @@ public class GlobalPressureTemperature2Model implements WeatherModel {
entries[latitudeIndex][longitudeIndex] = entry; entries[latitudeIndex][longitudeIndex] = entry;
} }
// wrap the grid around the Earth in longitude // finalize the grid
for (int latitudeIndex = 0; latitudeIndex < nA; ++latitudeIndex) {
final GridEntry reference = entries[latitudeIndex][0];
entries[latitudeIndex][nO - 1] = new GridEntry(reference.latitude, reference.latKey,
reference.longitude + 2 * FastMath.PI,
reference.lonKey + DEG_TO_MAS * 360,
reference.hS, reference.pressure0, reference.temperature0,
reference.qv0, reference.dT, reference.ah, reference.aw);
}
// check for missing entries
for (final GridEntry[] row : entries) { for (final GridEntry[] row : entries) {
for (final GridEntry entry : row) {
if (entry == null) { // check for missing entries
for (int longitudeIndex = 0; longitudeIndex < nO - 1; ++longitudeIndex) {
if (row[longitudeIndex] == null) {
throw new OrekitException(OrekitMessages.IRREGULAR_OR_INCOMPLETE_GRID, name); throw new OrekitException(OrekitMessages.IRREGULAR_OR_INCOMPLETE_GRID, name);
} }
} }
// wrap the grid around the Earth in longitude
row[nO - 1] = new GridEntry(row[0].latitude, row[0].latKey,
row[0].longitude + 2 * FastMath.PI,
row[0].lonKey + DEG_TO_MAS * 360,
row[0].hS, row[0].pressure0, row[0].temperature0,
row[0].qv0, row[0].dT, row[0].ah, row[0].aw);
} }
} }
......
...@@ -173,4 +173,29 @@ public class GlobalPressureTemperature2ModelTest { ...@@ -173,4 +173,29 @@ public class GlobalPressureTemperature2ModelTest {
} }
} }
@Test
public void testCorruptedIrregularGrid() {
Utils.setDataRoot("regular-data:potential:gpt2-grid");
GravityFieldFactory.addPotentialCoefficientsReader(new GRGSFormatReader("grim4s4_gr", true));
final double latitude = FastMath.toRadians(14.0);
final double longitude = FastMath.toRadians(68.5);
// Date is not used here
final Geoid geoid = new Geoid(GravityFieldFactory.getNormalizedProvider(12, 12),
ReferenceEllipsoid.getWgs84(FramesFactory.getITRF(IERSConventions.IERS_2010, true)));
final String fileName = "corrupted-irregular-grid-gpt2_5.grd";
try {
new GlobalPressureTemperature2Model(fileName, latitude, longitude, geoid);
Assert.fail("An exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.IRREGULAR_OR_INCOMPLETE_GRID, oe.getSpecifier());
Assert.assertTrue(((String) oe.getParts()[0]).endsWith(fileName));
}
}
} }
% This is not an original GPT2 grid, it has been edited for test purposes and should not be used except for test
% lat lon p:a0 A1 B1 A2 B2 T:a0 A1 B1 A2 B2 Q:a0 A1 B1 A2 B2 dT:a0 A1 B1 A2 B2 undu Hs h:a0 A1 B1 A2 B2 w:a0 A1 B1 A2 B2
17.5 67.5 100913 30 -28 9 -14 283.4 -9.1 -2.9 -0.0 0.3 6.02 -2.61 -1.33 0.29 0.32 -4.6 1.0 -0.3 -0.1 -0.0 41.28 52.71 1.2352 -0.0211 -0.0108 0.0008 0.0009 0.5583 -0.0126 -0.0125 0.0040 0.0012
17.5 72.5 100434 46 -48 -8 -16 282.7 -10.0 -3.0 0.0 0.2 5.88 -2.85 -1.38 0.39 0.36 -4.3 1.1 -0.2 -0.2 0.1 34.11 93.18 1.2344 -0.0225 -0.0111 0.0010 0.0007 0.5578 -0.0120 -0.0115 0.0049 0.0017
12.5 67.4999 89942 -161 -172 56 16 281.0 -8.4 -3.1 0.1 0.1 5.13 -2.91 -1.20 0.34 0.34 -6.5 0.6 -0.2 0.2 -0.1 47.30 1024.64 1.2395 -0.0209 -0.0110 0.0010 0.0008 0.5243 -0.0055 -0.0101 0.0041 0.0011
12.5 72.5 99762 183 -97 41 -6 284.8 -10.5 -2.7 -0.3 0.1 6.21 -3.28 -1.34 0.41 0.22 -5.4 1.6 -0.0 0.0 0.1 44.86 160.75 1.2406 -0.0219 -0.0106 0.0008 0.0005 0.5649 -0.0088 -0.0096 0.0044 0.0026
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