// (C)2007 Attila Kovacs <attila@submm.caltech.edu>



import java.text.*;

public class JulianEpoch extends CoordinateEpoch {

	public JulianEpoch() { }

	public JulianEpoch(double epoch) { super(epoch); }

	public double getJulianYear() { return year; }

	public double getBesselianYear() { return BesselianEpoch.getYearForMJD(getMJD()); }

	public BesselianEpoch getBesselianEpoch() { 
		return new BesselianEpoch(getBesselianYear());
	}

	public void setMJD(double MJD) {
		year = getYearForMJD(MJD);
	}

	public double getMJD() {
		return getMJDForYear(year);
	}
	
	//  J = 2000.0 + (JD - 2451545.0) / 365.25
	public static double getYearForMJD(double MJD) {
		return 2000.0 + (MJD - MJD2000) / julianYear;
	}

	public static double getMJDForYear(double year) {
		return (year - 2000.0)*julianYear + MJD2000;
	}
	
	// JD 2451545.0
	public final static double MJD2000 = 51544.5;


	public String toString() { return toString(Util.f1); }
	
	public String toString(NumberFormat nf) {
		return "J" + nf.format(year);
	}
	
	public void parse(String text) throws NumberFormatException, IllegalArgumentException {
		if(text.charAt(0) == 'J') year = Double.parseDouble(text.substring(1));
		else if(text.charAt(0) == 'B') year = getYearForMJD(BesselianEpoch.getMJDForYear(Double.parseDouble(text.substring(1))));
		else year = Double.parseDouble(text);
	}	
	

}
