// return J2000 coords for supplied RA,Dec and system, B=B1950 J=J2000 G=galactic
package net.mar;
import java.awt.geom.Point2D;
import java.text.NumberFormat;
import java.util.Locale;

import jsky.coords.WorldCoords;
import jsky.coords.wcscon;
public class ParseCoords {
	String ra=null;
	String dec=null;
	String sys=null;
	String[] coordsString2000=new String[]{"-99","-99"};
	double[] coordsDouble2000 = new double[]{-99.,-99.};

    WorldCoords wc =new WorldCoords();
public ParseCoords (String userRA, String userDec, String userSys)throws AnException
{
	ra=userRA;
	dec=userDec;
	sys=userSys;
	try {
		wc = new WorldCoords(Double.parseDouble(ra),Double.parseDouble(dec));
		}
	catch (Exception e){
		try {
			wc = new WorldCoords(ra,dec);
			}
			catch (Exception ane) {
			throw new AnException("Check values of supplied coords.");
				 }
			 }
	Point2D.Double point=new Point2D.Double(wc.getX(),wc.getY());
	wcscon wcs=new wcscon();
	if (sys.equals("G")){
	point=wcscon.gal2fk5(point);
	//wcs.gal2fk5(point);
	}
	if (sys.equals("B")){
	//wcs.fk425(point);
	    point=wcscon.fk425(point);
	    
	}


	coordsDouble2000[0]=point.getX();
	coordsDouble2000[1]=point.getY();
	coordsString2000[0]=String.valueOf(coordsDouble2000[0]);
    coordsString2000[1]=String.valueOf(coordsDouble2000[1]);
}

public double[] getCoordsDouble2000(){
     return coordsDouble2000;
 }
public String[] getCoordsString2000(){
      return coordsString2000;
 }
public static String formatP(double dNumber,int places){
    NumberFormat nf =NumberFormat.getInstance(Locale.UK); 
    //DecimalFormat df = new DecimalFormat();
    nf.setMaximumFractionDigits(places);
    nf.setGroupingUsed(false);
    return nf.format(dNumber); 


    
}

}