Commit 297fa470 authored by Luc Maisonobe's avatar Luc Maisonobe

Fixed a too early loading of UTC scale.

parent 225bb703
......@@ -31,9 +31,7 @@ import org.orekit.data.DataProvidersManager;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitMessages;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.DateTimeComponents;
import org.orekit.time.TimeScalesFactory;
import org.orekit.time.UTCScale;
import org.orekit.utils.Constants;
/** The Global Pressure and Temperature 2 (GPT2) model.
......@@ -80,9 +78,6 @@ public class GlobalPressureTemperature2Model implements DataLoader, WeatherModel
/** Ideal gas constant for dry air [J/kg/K]. */
private static final double R = 287.0;
/** Time scale factory for day of year computation. */
private static final UTCScale TIME_SCALE = TimeScalesFactory.getUTC();
/** Regular expression for supported file name. */
private String supportedNames;
......@@ -113,6 +108,9 @@ public class GlobalPressureTemperature2Model implements DataLoader, WeatherModel
/** Current date. */
private AbsoluteDate date;
/** Day of year. */
private int dayOfYear;
/** Constructor with supported names given by user.
* @param supportedNames supported names
* @param latitude geodetic latitude of the station, in radians
......@@ -183,8 +181,9 @@ public class GlobalPressureTemperature2Model implements DataLoader, WeatherModel
@Override
public void weatherParameters(final double stationHeight, final AbsoluteDate currentDate) {
this.date = currentDate;
this.height = stationHeight;
this.date = currentDate;
this.dayOfYear = currentDate.getComponents(TimeScalesFactory.getUTC()).getDate().getDayOfYear();
this.height = stationHeight;
DataProvidersManager.getInstance().feed(supportedNames, this);
}
......@@ -358,10 +357,7 @@ public class GlobalPressureTemperature2Model implements DataLoader, WeatherModel
final double b2 = Double.parseDouble(values[indexB2]);
// Temporal factors
// Day of year computation
final DateTimeComponents dtc = date.getComponents(TIME_SCALE);
final double dofyear = dtc.getDate().getDayOfYear();
final double coef = (dofyear / 365.25) * 2 * FastMath.PI;
final double coef = (dayOfYear / 365.25) * 2 * FastMath.PI;
final double cosCoef = FastMath.cos(coef);
final double sinCoef = FastMath.sin(coef);
final double cos2Coef = FastMath.cos(coef * 2.0);
......
......@@ -18,7 +18,6 @@ package org.orekit.models.earth;
import org.hipparchus.util.FastMath;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.orekit.Utils;
import org.orekit.errors.OrekitException;
......@@ -34,15 +33,12 @@ public class GlobalPressureTemperature2ModelTest {
private static double epsilon = 1.0e-12;
@Before
public void setUp() throws OrekitException {
Utils.setDataRoot("regular-data:potential");
GravityFieldFactory.addPotentialCoefficientsReader(new GRGSFormatReader("grim4s4_gr", true));
}
@Test
public void testWeatherParameters() {
Utils.setDataRoot("regular-data:potential:gpt2-grid");
GravityFieldFactory.addPotentialCoefficientsReader(new GRGSFormatReader("grim4s4_gr", true));
// Site Vienna: latitude: 48.20°N
// longitude: 16.37°E
// height: 156 m
......@@ -67,7 +63,6 @@ public class GlobalPressureTemperature2ModelTest {
ReferenceEllipsoid.getWgs84(FramesFactory.getITRF(IERSConventions.IERS_2010, true)));
final GlobalPressureTemperature2Model model = new GlobalPressureTemperature2Model(latitude, longitude, geoid);
Utils.setDataRoot("gpt2-grid");
model.weatherParameters(height, date);
final double a[] = model.getA();
......@@ -86,6 +81,9 @@ public class GlobalPressureTemperature2ModelTest {
@Test
public void testEquality() {
Utils.setDataRoot("regular-data:potential:gpt2-grid");
GravityFieldFactory.addPotentialCoefficientsReader(new GRGSFormatReader("grim4s4_gr", true));
// Commons parameters
final Geoid geoid = new Geoid(GravityFieldFactory.getNormalizedProvider(12, 12),
ReferenceEllipsoid.getWgs84(FramesFactory.getITRF(IERSConventions.IERS_2010, true)));
......@@ -107,7 +105,6 @@ public class GlobalPressureTemperature2ModelTest {
model1 = new GlobalPressureTemperature2Model(latitude, longitude1, geoid);
model2 = new GlobalPressureTemperature2Model(latitude, longitude2, geoid);
Utils.setDataRoot("gpt2-grid");
model1.weatherParameters(height, date);
model2.weatherParameters(height, date);
......@@ -154,6 +151,9 @@ public class GlobalPressureTemperature2ModelTest {
@Test
public void testCorruptedFileBadData() {
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(67.5);
final double height = 0.0;
......@@ -166,14 +166,14 @@ public class GlobalPressureTemperature2ModelTest {
final String fileName = "corrupted-bad-data-gpt2_5.grd";
final GlobalPressureTemperature2Model model = new GlobalPressureTemperature2Model(fileName, latitude, longitude, geoid);
Utils.setDataRoot("gpt2-grid");
try {
model.weatherParameters(height, date);
Assert.fail("An exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, oe.getSpecifier());
Assert.assertEquals(6, ((Integer) oe.getParts()[0]).intValue());
Assert.assertTrue(((String) oe.getParts()[1]).endsWith(fileName));
}
}
......
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