@@ -14,6 +14,9 @@ xquery version "3.0";
1414 :)
1515module namespace jmmc-simbad="http://exist.jmmc.fr/jmmc-resources/simbad" ;
1616
17+ import module namespace jmmc-tap="http://exist.jmmc.fr/jmmc-resources/tap" at "jmmc-tap.xql" ;
18+
19+
1720declare namespace votable="http://www.ivoa.net/xml/VOTable/v1.3" ;
1821declare namespace http="http://expath.org/ns/http-client" ;
1922
@@ -97,6 +100,61 @@ declare %private function jmmc-simbad:escape($str as xs:string) as xs:string {
97100 replace ($str, "'" , "''" )
98101};
99102
103+ (:~
104+ : Try to identify somes targets from the given identifiers on CDS Simbad.
105+ :
106+ : @param $identifiers the target names
107+ : @return a votable with one row per identifier and simbad info (name, ra, dec, pmra, pmdec, id) if found.
108+ :)
109+ declare function jmmc-simbad:votable4identifiers ($identifiers as xs:string*){
110+ let $table :=
111+ <table>
112+ <tr><th>identifier</th></tr>
113+ {
114+ for $identifier in $identifiers
115+ return <tr><td>{$identifier}</td></tr>
116+ }
117+ </table>
118+ let $name := "whynot"
119+ let $votable := jmmc-tap:table2votable ($table, $name)
120+
121+ let $query := "SELECT whynot.*, main_id AS name, ra, dec, pmra, pmdec, oid AS id " ||
122+ "FROM basic JOIN ident ON oidref=oid RIGHT JOIN TAP_UPLOAD.whynot as whynot ON id=my_identifier"
123+ return
124+ jmmc-tap:tap-adql-query ($jmmc-simbad:TAP-SYNC, $query, $votable, count ($identifiers), "votable/td" )
125+ };
126+
127+ (:~
128+ : Try to identify somes targets from the given identifiers on CDS Simbad.
129+ :
130+ : @param $identifiers the target names
131+ : @return a map of identifiers / targets (same format as resolve-by-name) value is empty if identifier is unknown on Simbad.
132+ :)
133+ declare function jmmc-simbad:resolve-by-names ($identifiers as xs:string*) as item ()* {
134+ let $votable := jmmc-simbad:votable4identifiers ($identifiers)
135+ let $map := map:merge (
136+ for $tr in $votable//*:TR
137+ let $my_identifier := data ($tr/*:TD[1 ])
138+ let $id := data ($tr/*:TD[7 ])
139+ let $target := if (exists ($id)) then
140+ <target>
141+ {
142+ element {"name" } {data ($tr/*:TD[2 ])}
143+ ,element {"ra" } {data ($tr/*:TD[3 ])}
144+ ,element {"dec" } {data ($tr/*:TD[4 ])}
145+ ,element {"pmra" } {data ($tr/*:TD[5 ])}
146+ ,element {"pmdec" } {data ($tr/*:TD[6 ])}
147+ ,element {"id" } {data ($tr/*:TD[7 ])}
148+ }
149+ </target>
150+ else
151+ ()
152+ return map:entry ($my_identifier, $target)
153+ )
154+ return $map
155+ };
156+
157+
100158(:~
101159 : Try to identify a target from its name with Simbad.
102160 :
@@ -118,7 +176,7 @@ declare function jmmc-simbad:resolve-by-name($identifier as xs:string) as item()
118176declare function jmmc-simbad:resolve-by-name ($identifier as xs:string, $ra as xs:double?, $dec as xs:double?) as item ()* {
119177 let $do-dist := ($ra and $dec)
120178 let $query :=
121- "SELECT oid AS id , ra, dec, main_id AS name, pmra, pmdec " || (if ($do-dist) then ", DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', " || $ra || ", " || $dec || ")) AS dist " else " " ) ||
179+ "SELECT main_id AS name , ra, dec, pmra, pmdec, oid AS id " || (if ($do-dist) then ", DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', " || $ra || ", " || $dec || ")) AS dist " else " " ) ||
122180 "FROM basic JOIN ident ON oidref=oid " ||
123181 "WHERE id = '" || jmmc-simbad:escape ($identifier) || "' " ||
124182 (if ($do-dist) then "ORDER BY dist" else "" )
@@ -136,7 +194,7 @@ declare function jmmc-simbad:resolve-by-name($identifier as xs:string, $ra as xs
136194 :)
137195declare function jmmc-simbad:resolve-by-coords ($ra as xs:double, $dec as xs:double, $radius as xs:double) as item ()* {
138196 jmmc-simbad:resolve (
139- "SELECT oid AS id , ra, dec, main_id AS name , DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', " || $ra || ", " || $dec || ")) AS dist , pmra, pmdec " ||
197+ "SELECT main_id AS name , ra, dec, pmra, pmdec, oid AS id , DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', " || $ra || ", " || $dec || ")) AS dist " ||
140198 "FROM basic " ||
141199 "WHERE CONTAINS(POINT('ICRS', ra, dec), CIRCLE('ICRS', " || $ra || ", " || $dec || ", " || $radius || " )) = 1 " ||
142200 "ORDER BY dist" )
0 commit comments