Commit 3b3d256e authored by xtof's avatar xtof

feat : add module jours julien

parent bc6548b7
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.josast</groupId>
<artifactId>JOSAST-parent</artifactId>
<version>0.0.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ModuleJourJulien</artifactId>
<name>Module Jour Julien</name>
<packaging>jar</packaging>
<properties>
<!-- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<java.16.home>${env.JAVA_HOME}</java.16.home>
<kaitai-maven-plugin-version>0.1.5</kaitai-maven-plugin-version>
</properties>
<dependencies>
<dependency>
<groupId>org.josast</groupId>
<artifactId>ModuleConfig</artifactId>
<version>0.2</version>
</dependency>
<dependency>
<groupId>org.josast</groupId>
<artifactId>ModuleUtil</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package org.josast.util.date;
/**
* give main characteristics of a day
*
* @author XTOPHE
* @version $Revision: 1.1 $
*/
public class Day {
//~ Static fields/initializers ----------------------------------------
/** number of second in a day : 86400 */
public static final double SEC_PER_DAY = 86400.0;
/** number minutes by day */
public static final double MIN_PER_DAY = 1440.0;
//~ Constructors ------------------------------------------------------
/**
* Creates a new Day object.
*/
private Day() {
}
}
package org.josast.util.date;
/**
*
* <b>Description : generic container for a date. </b>
*
*
* <p>Projet : JOSAST <BR>
*
* <br>
*
* @author <a href="mailto:mercier.josast@avmdti.org">mercier</a>
* @version 1.0
* <p><b><i> Source Update </b></i></p>
* <br> Version : date : name : comments
* <br> V1 : 1 avr. 2005 : C. Mercier : create file
* <p>
*
*/
public class GenericDate {
//~ Instance fields ---------------------------------------------------
/** DOCUMENT ME! */
private int _year;
/** DOCUMENT ME! */
private int _month;
/** DOCUMENT ME! */
private int _day;
/** DOCUMENT ME! */
private int _hour;
/** DOCUMENT ME! */
private int _minute;
/** DOCUMENT ME! */
private int _seconde;
//~ Constructors ------------------------------------------------------
/**
* Creates a new GenericDate object.
* <br> no verification on the input value <br>
*
* @param year 4 digit
*
* @param month 1 to 12
*
* @param day 1 to 31
*
* @param hour 1 to 24
*
* @param minute 1 to 59
* !
* @param seconde 1 to 59
*
*/
public GenericDate(int year, int month, int day, int hour, int minute,
int seconde) {
_year = year;
_month = month;
_day = day;
_hour = hour;
_minute = minute;
_seconde = seconde;
}
/**
* Creates a new GenericDate object.
*
* @param JulianDate julian day
*
*/
public GenericDate(double JulianDate) {
GenericDate Gd = JulianDay.convertToGenericDate(JulianDate);
_year = Gd._year;
_month = Gd._month;
_day = Gd._day;
_hour = Gd._hour;
_minute = Gd._minute;
_seconde = Gd._seconde;
}
//~ Methods -----------------------------------------------------------
/**
* return the julian day
*
* @return return julian day
*/
public double getJulianDay() {
return (JulianDay.convertToJulianDay(_year, _month, _day, _hour,
_minute, _seconde));
}
/**
*
* @return day
*/
public int get_day() {
return _day;
}
/**
*
*
* @return hours
*/
public int get_hour() {
return _hour;
}
/**
*
* @return minute
*/
public int get_minute() {
return _minute;
}
/**
*
* @return month
*/
public int get_month() {
return _month;
}
/**
*
* @return seconde
*/
public int get_seconde() {
return _seconde;
}
/**
*
*
* @return year
*/
public int get_year() {
return _year;
}
/**
*
* @param _day day
*
*/
public void set_day(int _day) {
this._day = _day;
}
/**
*
*
* @param _hour hour
*
*/
public void set_hour(int _hour) {
this._hour = _hour;
}
/**
*
* @param _minute minute
*/
public void set_minute(int _minute) {
this._minute = _minute;
}
/**
*
* @param _month month
*/
public void set_month(int _month) {
this._month = _month;
}
/**
*
* @param _seconde seconde
*/
public void set_seconde(int _seconde) {
this._seconde = _seconde;
}
/**
*
* @param _year year
*
*/
public void set_year(int _year) {
this._year = _year;
}
/**
* print generic date with the following format dd mm yy hh mn ss
* @return string
*/
public String toString() {
return (" " + _day + " " + _month + " " + _year + " " + _hour
+ " " + _minute + " " + _seconde);
}
}
package org.josast.util.date;
/**
*
* <b>Description : julian day with Y2000 reference</b>
*
*
* <p>Projet : JOSAST <BR>
*
*
* <p>for more information contact <a href="mailto:josast@avmdti.org">josast@avmdti.org</a></p>
* @author <a href="mailto:mercier.josast@avmdti.org">mercier</a>
* @version 1.0
* <p><b><i> Source Update </b></i></p>
* <br> Version : date : name : comments
* <br> V1 : 1 avr. 2005 : C. Mercier : create file
* <p>
* @deprecated since 1 1 2005
*
*/
public class JulianDay2000 {
private JulianDay2000 () {};
//~ Methods -----------------------------------------------------------
/**
*
* @see JulianDay#convertToJulianDay2000(int annee, int mois, int jour,int heure, int minute, int seconde)
*/
public static double getTime(int year, int month, int day, int hours,
int minutes, int secondes) {
int d = ((367 * year) - ((7 * (year + ((month + 9) / 12))) / 4)
+ ((275 * month) / 9) + day) - 730530;
return (d + ((hours + (minutes / 60.0) + (secondes / 3600.0)) / 24.0));
}
}
\ No newline at end of file
package org.josast.util.date;
import org.avmdti.josast.util.*;
/**
* <b>Calculate Greenwich Mean Sidereal Time for the Julian date.</b><BR>
*
* <p>
* <b>date </b>7 aot 2003
* </p>
*
* <p>
* <b><i> Source Update </i></b>
* </p>
* <br> date : name : comments <br>
* V1 : mercier : create file <br>
*
* <br>
*
* Explanatory Supplement to the Astronomical Almanac, page 50. // Orbital
* Coordinate Systems, Part III, Dr. T.S. Kelso, Satellite Times, // Nov/Dec
* 1995
*
* <p></p>
*
* @author XTOPHE <a href="mailto:josast@avmdti.org">josast at
* avmdti.org</a>
* @version 1.0
*/
/**
*
*
*
*/
public class SideralTime {
private static final double OMEGA_E = 1.00273790934; // earth rotation per
/**
*
* Calculate Greenwich Mean Sidereal Time for the Julian date. The return
* value is the angle, in radians, measuring eastward from the Vernal
* Equinox to the prime meridian. This angle is also referred to as "ThetaG"
* (Theta GMST).
*
* <br> References: The 1992 Astronomical Almanac, page B6.
* Explanatory Supplement to the Astronomical Almanac, page 50. // Orbital
* Coordinate Systems, Part III, Dr. T.S. Kelso, Satellite Times, // Nov/Dec
* 1995
*
* @param m_Date
* julian date
* @return Greenwich Mean Sidereal Time (in radian)
*/
public static double CalculGMST(double m_Date) {
double UT = MathTools.fmod(m_Date + 0.5, 1.0);
double TU = (JulianDay.FromJan1_12h_2000(m_Date) - UT) / 36525.0;
double GMST = 24110.54841 + TU
* (8640184.812866 + TU * (0.093104 - TU * 6.2e-06));
GMST = MathTools.fmod(GMST + Day.SEC_PER_DAY * OMEGA_E * UT,
Day.SEC_PER_DAY);
if (GMST < 0.0)
GMST += Day.SEC_PER_DAY; // "wrap" negative modulo value
return (Math.PI * 2 * (GMST / Day.SEC_PER_DAY));
}
/**
* Calculate Local Mean Sidereal Time for given longitude (for this date).
* The longitude is assumed to be in radians measured west from Greenwich.
* The return value is the angle, in radians, measuring eastward from the
* Vernal Equinox to the given longitude.
*
* @param longitude (in radian)
* @param M_Date Julian date
* @return Local Mean Sidereal Time (in radian)
*/
public static double toLMST(double lon, double M_Date) {
return MathTools.fmod(CalculGMST(M_Date) + lon, Math.PI * 2);
}
}
\ No newline at end of file
package org.josast.util.date;
import org.josast.util.date.GenericDate;
import junit.framework.TestCase;
/**
* DOCUMENT ME!
*
* @author $author$
* @version $Revision: 1.1 $
*/
public class GenericDateTest extends TestCase {
//~ Constructors ------------------------------------------------------
/**
* Creates a new GenericDateTest object.
*
* @param arg0 DOCUMENT ME!
*/
public GenericDateTest(String arg0) {
super(arg0);
}
//~ Methods -----------------------------------------------------------
/**
* <br> create a date with Generic Date with Date, Month, Day ..
* <br> compare to the expected Julian Day
* <br> create a date with Generic date with Julian Day value
* <br> compare to the expected Julian Day
*/
public void testGetJulianDay() {
GenericDate Gd = new GenericDate(1950, 5, 19, 22, 30, 00);
GenericDateTest.assertEquals(2433421.4375, Gd.getJulianDay(), 0);
GenericDate Gd2 = new GenericDate(2433421.4375);
GenericDateTest.assertEquals(2433421.4375, Gd2.getJulianDay(), 0);
GenericDateTest.assertEquals(1950, Gd2.get_year());
GenericDateTest.assertEquals(5, Gd2.get_month());
GenericDateTest.assertEquals(19, Gd2.get_day());
GenericDateTest.assertEquals(22, Gd2.get_hour());
GenericDateTest.assertEquals(30, Gd2.get_minute());
GenericDateTest.assertEquals(00, Gd2.get_seconde());
}
}
package org.josast.util.date;
import junit.framework.Assert;
import junit.framework.TestCase;
import java.util.GregorianCalendar;
import org.josast.util.date.JulianDay;
/**
* DOCUMENT ME!
*
* @author $author$
* @version $Revision: 1.2 $
*/
public class JulianDayTest extends TestCase {
//~ Static fields/initializers ----------------------------------------
private static final int DAY19 = 19;
private static final int MONTH4 = 4;
private static final int YEAR1990 = 1990;
private static final double JULIANDAY1941990 = 3543.0;
//~ Constructors ------------------------------------------------------
/**
* Creates a new JulianDayTest object.
*
* @param arg0 DOCUMENT ME!
*/
public JulianDayTest(String arg0) {
super(arg0);
}
//~ Methods -----------------------------------------------------------
/**
* DOCUMENT ME!
*
* @throws Exception DOCUMENT ME!
*/
protected void setUp() throws Exception {
super.setUp();
}
/**
* DOCUMENT ME!
*
* @throws Exception DOCUMENT ME!
*/
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* <br> unit test for Julian day convertion from Gregorian Calendar
* <br> Date used for the test :
* <br> - 1957 10 4 19 26 24 julian day value expected 2436116.31
* <br> - 333 1 27 12 0 0 julian day value expected 1842713.0,
*/
public void testconvertToJulianDayGC() {
GregorianCalendar valeur = new GregorianCalendar(1957, GregorianCalendar.OCTOBER, 4,
19, 26, 24);
GregorianCalendar valeur1 = new GregorianCalendar(333, GregorianCalendar.JANUARY, 27, 12,
0, 0);
Assert.assertEquals(1842713.0,
JulianDay.convertToJulianDay(valeur1), 0);
Assert.assertEquals(2436116.31,
JulianDay.convertToJulianDay(valeur), 0);
}
/**
* unit test for Julian day convertion from a given date
* <br> 333 1 27 12 0 0 julian day value expected 1842713.0
* <br> -584 5 28 0 0 0 julian day value expected 1507899.5
* <br> 1957 10 4 19 26, julian day value expected 24 2436116.31
* <br> 2000 1 1 12 0 0 julian day value expected 2451545.0
* <br> -4712 1 1 12 0 0 julian day value expected 0.0
* <br> 1999 1 1 0 0 0 julian day value expected 2451179.5
* <br> 1987 1 27 0 0 0 julian day value expected 2446822.5
*/
public void testconvertToJulianDay() {
Assert.assertEquals(1842713.0,
JulianDay.convertToJulianDay(333, 1, 27, 12, 0, 0), 0);
Assert.assertEquals(1507899.5,
JulianDay.convertToJulianDay(-584, 5, 28, 0, 0, 0), 0);
Assert.assertEquals(2436116.31,
JulianDay.convertToJulianDay(1957, 10, 4, 19, 26, 24),
0);
Assert.assertEquals(2451545.0,
JulianDay.convertToJulianDay(2000, 1, 1, 12, 0, 0), 0);
Assert.assertEquals(0.0,
JulianDay.convertToJulianDay(-4712, 1, 1, 12, 0, 0), 0);
Assert.assertEquals(2451179.5,
JulianDay.convertToJulianDay(1999, 1, 1, 0, 0, 0), 0);
Assert.assertEquals(2446822.5,
JulianDay.convertToJulianDay(1987, 1, 27, 0, 0, 0), 0);
}
/**
* Unit test to addDays
* <br> original date 1954 6 28 0, 0, 0
* <br> add 1 day
* <br> expected results 1954 6 29 0 0 0
*
*/
public void testaddJours() {
GregorianCalendar valeur = new GregorianCalendar(1954, 6, 29, 0,
0, 0);
GregorianCalendar valeur2 = new GregorianCalendar(1954, 6, 28, 0,
0, 0);
GregorianCalendar resultat = JulianDay.addDays(valeur2, 1);
Assert.assertEquals(valeur.getTimeInMillis(),
resultat.getTimeInMillis());
}
/**
* Unit Tes from a Gregorian value
* <br> 333 1 27 12 0 0 julian day value expected 1842713.0
* <br> -584 5 28 0 0 0 julian day value expected 1507899.5
* <br> 1957 10 4 19 26, julian day value expected 24 2436116.31
*/
public void testconvertToGregorianCalendar() {
GregorianCalendar valeur = new GregorianCalendar(1957, GregorianCalendar.OCTOBER, 4,
19, 26, 24);
GregorianCalendar resultat = JulianDay.convertToGregorianCalendar(2436116.31);
Assert.assertEquals(valeur.getTimeInMillis(),
resultat.getTimeInMillis());
GregorianCalendar valeur1 = new GregorianCalendar(333,GregorianCalendar.JANUARY, 27, 12,
0, 0);
GregorianCalendar resultat1 = JulianDay.convertToGregorianCalendar(1842713.0);
Assert.assertEquals(valeur1.getTimeInMillis(),
resultat1.getTimeInMillis());
GregorianCalendar valeur2 = new GregorianCalendar(-584, GregorianCalendar.MAY, 28, 0,
0, 0);
GregorianCalendar resultat2 = JulianDay.convertToGregorianCalendar(1507899.5);
Assert.assertEquals(valeur2.getTimeInMillis(),
resultat2.getTimeInMillis());
}
/**
* unit test for
*/
public void testdiffdate() {
GregorianCalendar J1 = new GregorianCalendar(1835, 11, 16, 0, 0, 0);
GregorianCalendar J2 = new GregorianCalendar(1910, MONTH4, 20, 0,
0, 0);
Assert.assertEquals(27183, JulianDay.diffdate(J2, J1), 0);
// new test for bug ?
//Le problme rencontr est que lorsque j'essais de soustraire 1940-02-29 et 1940-01-01 j'ai comme rsultat 57 alors que je m'attends avoir 59.
J1 = new GregorianCalendar(1940, GregorianCalendar.FEBRUARY, 29, 0, 0, 0);
J2 = new GregorianCalendar(1940, GregorianCalendar.JANUARY, 1, 0, 0, 0);
Assert.assertEquals(59, JulianDay.diffdate(J1, J2), 0);
}
/**
* DOCUMENT ME!
*/
public final void testconvertToJulianDay2000() {
// 19 april 1990, at 0:00 UT
Assert.assertEquals(-JULIANDAY1941990,
JulianDay.convertToJulianDay2000(YEAR1990, MONTH4, DAY19, 0,
0, 0), 0);
}
}
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