/* ConeCaller.java * client code for reading cone service via http protocol */ package coneclient; import edu.jhu.pha.ivoa.*; import java.io.*; import java.text.*; import java.net.*; class ConeCaller { public static void main(String[] args) throws Exception{ int ind =0; String coneUrl="http://chart.stsci.edu/GSCVO/GSC22VO.jsp?"; double ra,dec,sr; if (args.length >= 3 ) { ra = Double.parseDouble(args[ind++]); dec = Double.parseDouble(args[ind++]); sr = Double.parseDouble(args[ind++]); if (ind < args.length) { coneUrl = args[ind++]; } callConeService(ra,dec,sr,coneUrl); } else { System.out.println("You need to supply ra,dec,sr,[coneURL] input paramaters."); System.exit(1); } } // Construct URL and perform http get request public static void callConeService(double ra, double dec, double sr, String coneUrl) throws Exception { URL cone = new URL(coneUrl + "RA="+ra+"&DEC="+dec+"&SR="+sr); System.out.println("Calling cone URL: " + cone); readVot(cone.openStream()); } // Shows sample of how to parse stream from Cone service http get and // output a row of the returned VOTable public static void readVot(InputStream is) throws Exception{ // Using JAVOT VOTable parser VOTWrap.VOTable vot = VOTWrap.createVOTable(is); int resCount = vot.getResourceCount(); System.out.println (" has "+ resCount +" resources"); // could be more than one resource with more than one table - but this is a simple example VOTWrap.Resource res = vot.getResource(0); // making assumption there is a table in here VOTWrap.Table tab = res.getTable(0); int fcount = tab.getFieldCount(); System.out.println (" There are "+ fcount +" fields:"); for (int f=0; f < fcount; f++) { VOTWrap.Field field = tab.getField(f); System.out.print (field.getID()+":"+field.getUCD()+" "); } System.out.println(); // get one line out System.out.println(); System.out.println("Println first row .."); VOTWrap.TR row = tab.getTableData().getTR(0); for (int f=0; f < fcount; f++) { VOTWrap.TD td = row.getTD(f); System.out.print (td.getPCDATA()+" "); } } }