aboutsummaryrefslogtreecommitdiff
path: root/vendor/voclient/libvoclient/examples/skyportal1_java
blob: fb2c6d5abfcea0c6cf04e558e5a300ba0f48190b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

import voclient.*;
import dalclient.*;


/**
 */
public class skyportal1 {
    private static final double DEF_RA  = 16.031;
    private static final double DEF_DEC = -0.891;

    public static void main(String args[]) throws Exception 
    {
	double  ra = DEF_RA, 
	       dec = DEF_DEC;
	int    arg = 0;


	if (args.length == 0) {
	    // Built-in no-args unit test.
	} else if (args.length >= 3) {
	    ra = Double.parseDouble(args[arg++]);
	    dec = Double.parseDouble(args[arg++]);
	} else {
	    System.out.println ("Usage: skyportal1 ra dec");
	    System.exit(1);
	}

	querySkyPortal (ra, dec);	// make the query
    }


    /** Simple test routine to query a SkyPortal and summarize results.
     */
    static void querySkyPortal (double ra, double dec) throws Exception 
    {

        String qry = " SELECT o.objId, o.ra,o.dec, o.type,t.objId,t.j_m,o.z " +
	       	     " FROM SDSS:PhotoPrimary o, " +
		     " TWOMASS:PhotoPrimary t WHERE XMATCH(o,t)<2.5 " +
		     " AND Region('Circle J2000 " + ra + " " + dec + " .10') " +
		     " AND( o.z- t.j_m)>1 " ;

	// Get a new connection to the service.
	VOCSkyPortal sp = new VOCSkyPortal (qry);

	// Execute the query and fetch results.
	sp.executeCSV();

	QueryResponse qr = sp.execute();
	if (qr.getRecordCount() <= 0) {
	    System.out.println("no records found");
	    System.exit(1);
	}

	// Summarize query response.
	{
	    int nrec = qr.getRecordCount();
	    QueryRecord r = qr.getRecord(0);
	    int nattr = (r != null) ? r.getAttributeCount() : 0;
	    System.out.println("# returns " + nrec + " records containing " +
		nattr + " attributes each");
	    System.out.println("# --- Summary output ---");
	}

	// Summarize and print selected query results.
	for (int i=0;  i < qr.getRecordCount();  i++) {
	    QueryRecord r = qr.getRecord(i);
	    String s_id, s_ra, s_dec, s_class;
	    QRAttribute v;

	    s_id = ((v = r.getAttribute("sdss_objid")) != null) ?
		v.stringValue() : "<none>";
	    s_ra = ((v = r.getAttribute("sdss_ra")) != null) ?
		v.stringValue() : "<unknown>";
	    s_dec = ((v = r.getAttribute("sdss_dec")) != null) ?
		v.stringValue() : "<unknown>";
	    s_class = ((v = r.getAttribute("sdss_type")) != null) ?
		v.stringValue() : "<unknown>";

	    System.out.println("id=" + s_id + "\tra=" + s_ra +
		"\tdec=" + s_dec + "\tclass=" + s_class);
	}
    }
}