<?xml version="1.0" encoding="UTF-8"?>

<resource schema="mwsc">

	<!-- upstream source organization is a bit silly in that they put
	data for essentially the same rows (with some NULLs) in the three
	files catalogue.dat, index.dat, and notes.dat.  To combine these,
	we write three different grammars and manually combine their results
	in import_main.  -->

	<meta name="creationDate">2013-12-16T12:00:00Z</meta>
	<meta name="schema-rank">100</meta>
	<meta name="title">Global Survey of Star Clusters in the Milky Way</meta>

	<meta name="description">
		MWSC presents a list of 3006 Milky Way Stellar Clusters (MWSC), found in the
		2MAst (2MASS with Astrometry) catalogue. The target list was compiled on the
		basis of present-day lists of open, globular and candidate clusters. For
		confirmed clusters we determined a homogeneous set of astrophysical
		parameters such as membership, angular radii of the main morphological
		parts, mean cluster proper motions, distances, reddenings, ages, tidal
		parameters, and sometimes radial velocities.
	</meta>

	<meta name="creator">
		Kharchenko, N.V.; Piskunov, A.E.; Roeser, S.; Schilbach, E.; Scholz, R.-D.
	</meta>

	<meta name="subject">surveys</meta>
	<meta name="subject">open-star-clusters</meta>
	<meta name="subject">stellar-kinematics</meta>
	<meta name="subject">galaxy-structure</meta>
	<meta name="subject">proper-motions</meta>

	<meta name="source">2013A&amp;A...558A..53K</meta>


	<table id="main" onDisk="true" primary="recno" adql="True">
		<meta name="description">A list of milky way stellar cluster
			candidates and objects, together with the notes and
			parameters from confirmed objects for the original publication.</meta>

		<index columns="rcluster"/>
		<index columns="dist"/>
		<index columns="logt"/>
		<index columns="fe_h"/>

		<stc>
			Position ICRS SPHER3 "raj2000" "dej2000" "dist"
				Size "rcluster" "rcluster" -1
				Velocity "pmra" "pmde" "rv" Error "e_pm" "e_pm" "e_rv"
		</stc>
		
		<stc>
			Position GALACTIC "glat" "glon"
		</stc>

		<column name="recno" type="text" required="True"
			ucd="meta.id;meta.main"
			tablehead="Id"
			description="MWSC sequential number (cluster catalog number)."
			verbLevel="1"/>

		<column name="name" type="text"
			ucd="meta.id"
			tablehead="Common Name"
			description="NGC, IC or other common designation"
			verbLevel="1"/>

		<column name="confirmation_flag" type="text" required="True"
			tablehead="Cluster?"
			description="Is this object a stellar cluster?  'dupe' indicates the
				object coincides with another cluster."
			verbLevel="1"/>

		<column name="object_type" type="text"
			ucd="src.class"
			tablehead="Source Classification"
			description="Object type"
			verbLevel="15"/>

		<column name="ot_certain" type="boolean"
			ucd="meta.code;src.class"
			tablehead="Type Certain?"
			description="True if the object type is confirmed, false if
				object type has candidate status."
			verbLevel="25">
			<values nullLiteral="False"/>
				<!-- sucks; should we do this differently? -->
		</column>

		<column name="source" type="text"
			ucd="meta.ref"
			tablehead="Source"
			description="Source for MWSC list and input parameters"
			verbLevel="1"
			displayHint="type=bibcode"/>

		<column name="source_type" type="text"
			ucd="src.class"
			tablehead="Src type"
			description="Object type from source"
			verbLevel="1" note="o"/>

		<column name="n_star" type="integer" required="True"
			ucd="meta.number"
			tablehead="N"
			description="Number of stars in MWSC sky area."
			verbLevel="1"/>

		<column name="raj2000" type="double precision"
			ucd="pos.eq.ra;meta.main" unit="deg"
			tablehead="RA"
			description="Adopted cluster centre in RA J2000.0"
			verbLevel="1"/>

		<column name="dej2000" type="double precision"
			ucd="pos.eq.dec;meta.main" unit="deg"
			tablehead="Dec"
			description="Adopted cluster centre in Dec J2000.0"
			verbLevel="1"/>

		<column name="glon" type="double precision"
			ucd="pos.galactic.lon" unit="deg"
			tablehead="l"
			description="Galactic longitude"
			verbLevel="20"/>

		<column name="glat" type="double precision"
			ucd="pos.galactic.lat" unit="deg"
			tablehead="b"
			description="Galactic latitude"
			verbLevel="20"/>

		<column name="rcore"
			ucd="phys.angSize;src" unit="deg"
			tablehead="R(core)"
			description="Angular radius of the core"
			verbLevel="5"/>

		<column name="rcenter"
			ucd="phys.angSize;src" unit="deg"
			tablehead="R(center)"
			description="Angular radius of the central part"
			verbLevel="5"/>

		<column name="rcluster"
			ucd="phys.angSize;src" unit="deg"
			tablehead="R(cluster)"
			description="Angular radius of the cluster">
			<values min="0.04" max="6.2"/>
		</column>

		<column name="pmra"
			ucd="pos.pm;pos.eq.ra;stat.mean" unit="deg/yr"
			tablehead="PM(RA)"
			description="Average proper motion in RA*cos(DE)"
			verbLevel="5"/>

		<column name="pmde"
			ucd="pos.pm;pos.eq.dec;stat.mean" unit="deg/yr"
			tablehead="PM(Dec)"
			description="Average proper motion in Declination"
			verbLevel="5"/>

		<column name="e_pm"
			ucd="stat.error;pos.pm;pos.eq.ra;stat.mean" unit="deg/yr"
			tablehead="e_PM"
			description="Error of proper motion"
			verbLevel="15"/>

		<column name="rv"
			ucd="spect.dopplerVeloc;pos.heliocentric;stat.mean" unit="km/s"
			tablehead="RV"
			description="Average radial velocity"
			verbLevel="5"/>

		<column name="e_rv"
			ucd="stat.error;spect.dopplerVeloc;pos.heliocentric;stat.mean" unit="km/s"
			tablehead="Err(RV)"
			description="Error of RV"
			verbLevel="15"/>

		<column name="n_rv" type="integer"
			ucd="meta.number;spect.dopplerVeloc;pos.heliocentric;stat.mean"
			unit="km/s"
			tablehead="n_RV"
			description="Number of stars used for RV"
			verbLevel="25">
			<values nullLiteral="0"/>
		</column>

		<column name="n1s_core" type="integer"
			ucd="meta.number" tablehead="|Core|"
			description="Number of most probable (1sigma) members within R(core)"
			verbLevel="15">
			<values nullLiteral="0"/>
		</column>

		<column name="n1s_center" type="integer"
			ucd="meta.number" tablehead="|Center|"
			description="Number of most probable (1sigma) members within R(center);
			these are the stars used to compute the average proper motion."
			verbLevel="15">
			<values nullLiteral="0"/>
		</column>
			
		<column name="n1s_cluster" type="integer"
			ucd="meta.number" tablehead="|Cluster|"
			description="Number of most probable (1sigma) members within
				R(cluster)"
			verbLevel="15">
			<values nullLiteral="0"/>
		</column>

		<column name="dist"
			ucd="pos.distance;pos.heliocentric" unit="pc"
			tablehead="D"
			description="Distance from the Sun"
			verbLevel="15">
			<values min="87.0" max="82535.0"/>
		</column>

		<column name="col_ex_opt"
			ucd="phot.color.excess;phot.color;em.opt.B;em.opt.V" unit="mag"
			tablehead="E(B-V)"
			description="Colour excess in (B-V)"
			verbLevel="15"/>

		<column name="dist_mod"
			ucd="phot.mag.distMod" unit="mag"
			tablehead="Ks-M_Ks"
			description="Apparent distance modulus in Ks"
			verbLevel="25"/>

		<column name="col_ex_j"
			ucd="phot.color.excess;phot.color;em.ir.J;em.ir.K" unit="mag"
			tablehead="E(J-Ks)"
			description=" Colour excess in (J-Ks)"
			verbLevel="25"/>

		<column name="col_ex_h"
			ucd="phot.color.excess;phot.color;em.ir.J;em.ir.H" unit="mag"
			tablehead="E(J-H)"
			description="Colour excess in (J-H)"
			verbLevel="25"/>

		<column name="delta_h"
			ucd="phot.mag;arith.diff" unit="mag"
			tablehead="ΔH"
			description="Correction to H mag of fitted isochrone, empirically
				introduced to achieve a better fit in the Ks vs. J-H CMD. (see
				2012A&amp;A...543A.156K)."
			verbLevel="25"/>

		<column name="logt"
			ucd="time.age;stat.mean" unit="log(yr)"
			tablehead="log(T)"
			description="Logarithm of average age"
			verbLevel="15">
			<values min="6.0" max="10.1"/>
		</column>

		<column name="e_logt"
			ucd="stat.error;time.age" unit="log(yr)"
			tablehead="Err.(log(T))"
			description="Error in logarithm of average age"
			verbLevel="25"/>

		<column name="nt" type="integer"
			ucd="meta.number" tablehead="N(T)"
			description="Number of stars used for log(T) calculation"
			verbLevel="25">
			<values nullLiteral="-1"/>
		</column>

		<column name="rc"
			ucd="phys.size.radius" unit="pc"
			tablehead="R_King"
			description="King core radius"
			verbLevel="15"/>

		<column name="e_rc"
			ucd="stat.error;phys.size.radius" unit="pc"
			tablehead="Err(R_King)"
			description="Error of King core radius"
			verbLevel="25"/>

		<column name="rt"
			ucd="phys.size.radius" unit="pc"
			tablehead="R_Tidal"
			description="King tidal radius"
			verbLevel="15"/>

		<column name="e_rt"
			ucd="stat.error;phys.size.radius" unit="pc"
			tablehead="Err(R_Tidal)"
			description="Error of King tidal radius"
			verbLevel="25"/>

		<column name="kingk"
			ucd="stat.fit.param" unit="pc**-2"
			tablehead="K"
			description="King normalization factor (a measure of the
				central density of the cluster, see 2007A&amp;A...468..151P"
			verbLevel="15"/>

		<column name="e_kingk"
			ucd="stat.error;stat.fit.param" unit="pc**-2"
			tablehead="Err(K)"
			description="Error of King normalization factor"
			verbLevel="25"/>

		<column name="fe_h"
			ucd="phys.abund.Fe"
			tablehead="[Fe/H]"
			description="Metallicity [Fe/H]; this is copied from
				2013arXiv1309.4325C
				or 2012A&amp;A...539A.125D.  Data for globular clusters is taken
				from the revised Harris (1996) catalogue, edition 2010, or
				newly determined."
			verbLevel="15">
			<values min="-2.155" max="90.128"/>
		</column>

		<column name="e_fe_h"
			ucd="stat.error;phys.abund.Fe"
			tablehead="Err([Fe/H])"
			description="Error of Metallicity"
			verbLevel="25"/>

		<column name="n_fe_h" type="smallint"
			ucd="meta.number"
			tablehead="N([Fe/H])"
			description="Number of objects in [Fe/H] calculation."
			verbLevel="25">
			<values nullLiteral="0"/>
		</column>

		<column name="note_text" type="text"
			ucd="meta.note"
			tablehead="Note"
			description="The text of the note for an object."
			verbLevel="1"/>

		<meta name="note" tag="o">
			The values in the source_type column have the following meanings:

			===== =============================================================
			 ass   stellar association
			 ast   Dias: possible asterism/dust hole/star cloud
			 dub   Dias: dubious, objects considered doubtful by the
			       DSS images inspection
			 emb   embedded open cluster/cluster associated with nebulosity
			 glo   globular cluster/possible globular cluster
			 irc   infrared cluster
			 irg   infrared stellar group
			 mog   Dias: possible moving group
			 non   Dias: "non-existent NGC"/ objects not found in DSS
			       images inspection
			 rem   Possible cluster remnant
			 var   clusters with variable extinction
			===== =============================================================
		</meta>
	</table>

	<data id="dummyWithGrammars" auto="False">
		<!-- syntax: I need some place in which to store the subordinate
		grammars -->
		<columnGrammar id="catalogue_grammar">
			<colDefs>
				recno: 1-4
				name: 6-22
				object_type:24
				ot_certain:25
				raj2000:26-34
				dej2000:35-42
				glon:43-50
				glat:51-58
				rcore:59-65
				rcenter:66-72
				rcluster:73-79
				pmra:80-86
				pmde:87-93
				e_pm:94-100
				rv:101-108
				e_rv:109-116
				n_rv:117-122
				n1s_core:123-128
				n1s_center:129-135
				n1s_cluster:136-142
				dist:143-150
				col_ex_opt:151-157
				dist_mod:158-164
				col_ex_j:165-171
				col_ex_h:172-178
				delta_h:179-185
				logt:186-192
				e_logt:193-199
				nt:200-203
				rc:204-211
				e_rc:212-219
				rt:220-227
				e_rt:228-235
				kingk:236-243
				e_kingk:244-251
				source:253-256
				source_type:258-260
				fe_h:262-269
				e_fe_h:270-276
				n_fe_h:277-280
			</colDefs>
		</columnGrammar>

		<embeddedGrammar id="notes_grammar">
			<iterator>
				<code>
					note_text = []
					for ln in open(self.sourceToken):
						id = ln[:4].strip()
						if not id:
							note_text.append(ln[28:].strip())
						else:
							if note_text:
								yield {"recno": curId, "note_text": " ".join(note_text)}
							curId = id
							note_text = [ln[28:].strip()]
					yield {"recno": curId, "note_text": " ".join(note_text)}
				</code>
			</iterator>
		</embeddedGrammar>

		<columnGrammar id="index_grammar">
			<colDefs>
				recno:  1-4
				name:  6-22
				confirmation_flag: 24-24
				object_type: 26-26
				ot_certain: 27-27
				source: 29-32
				source_type: 34-36
				n_star: 37-45
			</colDefs>
		</columnGrammar>
	</data>

	<data id="import_main">
		<sources>manually selected</sources>

		<embeddedGrammar id="grammar_main">
			<!-- join the results of the three grammars above based on
			the recno. -->
			<iterator>
				<code>
					# This piece is re-used in other RDs; we hence must make sure
					# we're resolving in this RD.
					baseRD = base.caches.getRD("mwsc/q")
					notesIterator = iter(baseRD.getById("notes_grammar").parse(
						rd.getAbsPath("data/notes.dat"), None))
					parsIterator = iter(baseRD.getById("catalogue_grammar").parse(
						rd.getAbsPath("data/catalogue.dat"), None))
					
					nextNotes = notesIterator.next()
					nextPars = parsIterator.next()

					parsNULL = {"rv": "999.99", "e_rv": "99.99",
						"rcore": "0.0", "rv": "999.99", "e_rv": "99.99",
						"e_logt": "0.000", "fe_h": "99.999", "e_fe_h": "9.990",
						"nt": "-1", "n_fe_h": "0", "n_rv": "0",
						"raj2000": None, "rc": "0.00", "e_rc": "0.00",
						"rt": "0.00", "e_rt": "0.00", "kingk": "0.00",
						"e_kingk": "0.00",}

					for row in baseRD.getById("index_grammar").parse(
							rd.getAbsPath("data/index.dat"), None):
						if nextNotes["recno"]==row["recno"]:
							try:
								row.update(nextNotes)
								nextNotes = notesIterator.next()
							except StopIteration:
								nextNotes = {"recno": None}

						if nextPars["recno"]==row["recno"]:
							try:
								row.update(nextPars)
								nextPars = parsIterator.next()
							except StopIteration:
								nextPars = {"recno": None}
						else:
							row.update(parsNULL)

						yield row
				</code>
			</iterator>
		</embeddedGrammar>

		<make table="main">
			<rowmaker idmaps="*" id="rmk_main">
				<apply name="map_typestat" procDef="//procs#dictMap">
					<bind key="mapping">{"o": True, "c": False, "": None}</bind>
					<bind key="key">"ot_certain"</bind>
				</apply>

				<apply name="map_object_type" procDef="//procs#dictMap">
					<bind key="mapping">{
						"a": "association",
						"g": "globular cluster",
						"m": "moving group",
						"n": "nebulosity/presence of nebulosity",
						"r": "remnant cluster",
						"s": "asterism",
						"": None}
					</bind>
					<bind key="key">"object_type"</bind>
				</apply>

				<apply name="map_confirmation_flag" procDef="//procs#dictMap">
					<bind key="mapping">{
						"=": "yes",
						":": "possibly",
						"-": "no",
						"&amp;": "dupe",
						}
					</bind>
					<bind key="key">"confirmation_flag"</bind>
				</apply>

				<apply name="map_source" procDef="//procs#dictMap">
					<bind key="mapping"><![CDATA[{
						"COCD": "2005yCat..34400403K",
						"DIAS": "2002A&A...389..871D",
						"DREM": "2002A&A...389..871D",
						"MELN": "2009MNRAS.400..518M",
						"FPRO": "2007MNRAS.374..399F",
						"FPOS": "2007MNRAS.374..399F",
						"BOPN": "2003A&A...400..533D",
						"BIRN": "2003A&A...400..533D",
						"LLEM": "2003ARA&A..41...57L",
						"BIEM": "2003A&A...404..223B",
						"HARR": "2010arXiv1012.3224H",
						"ARIn": None,
						"ARIa": None,
						"ARIs": None,
					}
					]]></bind>
					<bind key="key">"source"</bind>
				</apply>

				<apply name="fixBrokenNulls">
					<!-- this fixes some broken null values in the source -->
					<code>
						if vars["rv"]=='999.90':
							vars["rv"] = '999.99'
						if vars["e_rv"]=='99.90':
							vars["e_rv"] = '99.99'
					</code>
				</apply>

				<map key="rcore">parseWithNull(@rcore, float, "0.0")</map>
				<map key="rv">parseWithNull(@rv, float, "999.99")</map>
				<map key="e_rv">parseWithNull(@e_rv, float, "99.99")</map>
				<map key="e_logt">parseWithNull(@e_logt, float, "0.000")</map>
				<map key="fe_h">parseWithNull(@fe_h, float, "99.999")</map>
				<map key="e_fe_h">parseWithNull(@e_fe_h, float, "9.990")</map>
				<map key="nt">parseWithNull(@nt, int, "-1")</map>
				<map key="n_fe_h">parseWithNull(@n_fe_h, int, "0")</map>
				<map key="n_rv">parseWithNull(@n_rv, int, "0")</map>

				<map key="raj2000">scale(
					parseWithNull(@raj2000, float), 1/24.0*360)</map>

				<LOOP listItems="rc e_rc rt e_rt kingk e_kingk">
					<events>
						<map key="\item">parseWithNull(@\item, float, "0.00")</map>
					</events>
				</LOOP>

				<LOOP listItems="pmra pmde e_pm">
					<events>
						<map key="\item">scale(
							parseWithNull(@\item, float), DEG_MAS)</map>
					</events>
				</LOOP>


			</rowmaker>
		</make>
	</data>

	<coverage>
		<updater sourceTable="main" mocOrder="4"/>
		<spatial>2/86,165 3/17,19-20,22,25,28,46-47,49-51,56-58,202,207,218-219,221-223,225,228-229,240-241,244-245,325,327,333,336,338-339,369-370,374,377,380-382,448,450-451,454,456-457,460,472,478-479,581,583,589,591-594,600,606,613,615,620-621,623,626-627,634,642,649-654,658-659,664,668,671-672 4/28,53,64,66-67,72-74,84,86,92,94,96-98,107,109,111,116-118,120-122,124,132,139,149,151-152,156,166,169,174-176,178,181-183,192-193,208,210-211,214,218,221-222,237-238,240,242,248,251-252,254,268,270,293,384,388,392,394-395,399,417-418,422,426,430,589,600,604,625,645-646,649,775-776,779,781,783,793,800,804,806-807,813-815,818,824,847,854,861-866,871,880-881,896-898,905-907,909-911,920-922,925-926,929,944-945,968,970,973-974,984,987-990,992,1008,1011-1013,1015,1030,1040,1070,1193,1230,1285-1286,1292,1296-1297,1299,1304,1306,1312-1313,1331,1339-1342,1349-1350,1360,1363,1369-1371,1394,1396,1398-1400,1402,1404,1406,1425,1428-1430,1437,1439,1461,1463,1473-1475,1484-1485,1487-1488,1490-1491,1494,1501-1503,1505,1507,1514-1516,1518-1519,1532-1534,1541,1552,1568,1571,1617,1748-1749,1754,1780,1796,1798,1808-1810,1814,1822-1823,1832-1833,1835-1837,1839,1844-1846,1849,1851-1853,1856,1858-1861,1863-1864,1866,1874,1882,1885,1893-1896,1898,1900-1902,1904,1906-1909,1911,1921,1923,1925-1926,1937-1938,1940-1941,1943-1945,1962-1963,1984-1986,1988,1991-1993,1996,1999,2005-2006,2008,2014,2029,2032,2038,2054,2066,2068,2070,2082-2083,2099,2102,2116,2131,2140-2141,2158,2200,2309-2310,2313,2317,2319-2320,2323,2329-2331,2342,2345,2349,2353-2355,2361,2363,2385,2387-2388,2390,2392,2394,2404,2406-2408,2410-2414,2418,2422,2436-2438,2445,2447-2449,2451,2456-2457,2459,2470,2472,2477-2479,2489-2491,2496-2498,2500-2502,2528,2530-2531,2534,2540,2543,2546,2553,2555,2563,2566,2574-2576,2578,2581,2583,2586-2587,2589-2591,2593-2595,2620,2623-2626,2628-2629,2661,2663,2665,2668-2670,2676-2678,2681,2692,2694-2696,2698-2699,2701,2704,2706,2708,2713-2714,2717,2720-2721,2723,2725-2726,2740,2753,2755,2763,2768,2772,2776,2825,2871,2944-2945,2948,2952,2956,2976,2979,2981-2982,2984,2986,2988-2989,2991,2993-2995,2997-2998,3000,3002-3003,3007,3020,3027,3043,3059</spatial>
	</coverage>

	<table id="stars" onDisk="True"  mixin="//scs#q3cindex" adql="True">
		<meta name="description">Data on cluster stars.</meta>
		
		<foreignKey inTable="main" source="recno" metaOnly="True"/>
		<index columns="recno"/>
		
		<index columns="p_spat"/>
		<index columns="p_kin"/>
		<index columns="p_jks"/>
		<index columns="magV"/>
		<index columns="magJ"/>

		<stc>
			Position ICRS Epoch J2000.0 "raj2000" "dej2000"
				Velocity "pmra" "pmde"
		</stc>

		<column original="main.recno"
			tablehead="Cluster Id"
			description="MWSC number of the cluster containing the star."/>

		<column name="raj2000" type="double precision"
			unit="deg" ucd="pos.eq.ra;meta.main"
			tablehead="RA"
			description="Stellar Right Ascension J2000.0, epoch 2000.0"
			verbLevel="1"/>

		<column name="dej2000" type="double precision"
			unit="deg" ucd="pos.eq.dec;meta.main"
			tablehead="Dec"
			description="Stellar Declination J2000.0, epoch 2000.0"
			verbLevel="1"/>

		<column name="magB"
			unit="mag" ucd="phot.mag;em.opt.B"
			tablehead="m_B"
			description="B magnitude in Johnson system."
			verbLevel="15"/>

		<column name="magV"
			unit="mag" ucd="phot.mag;em.opt.V"
			tablehead="m_V"
			description="V magnitude in Johnson system."
			verbLevel="15">
			<values min="-32.636" max="32.7"/>
		</column>

		<LOOP>
			<csvItems>
				item, ucd
				J, J
				H, H
				Ks, K
			</csvItems>
			<events>
				<column name="mag\item"
					unit="mag" ucd="phot.mag;em.ir.\ucd"
					tablehead="m_\item"
					description="Magnitude in the 2MASS \item band"
					verbLevel="15"/>
				<column name="e_mag\item"
					unit="mag" ucd="stat.error;phot.mag;em.ir.\ucd"
					tablehead="Err. m_\item"
					description="Error in the magnitude in the 2MASS \item band"
					verbLevel="25"/>
			</events>
		</LOOP>

		<column name="pmra"
			ucd="pos.pm;pos.eq.ra" unit="deg/yr"
			tablehead="PM(RA)"
			description="Stellar proper motion in RA*cos(DE)"
			verbLevel="5"/>

		<column name="pmde"
			ucd="pos.pm;pos.eq.dec" unit="deg/yr"
			tablehead="PM(Dec)"
			description="Stellar proper motion in Declination"
			verbLevel="5"/>

		<column name="e_pm"
			ucd="stat.error;pos.pm;pos.eq.ra" unit="deg/yr"
			tablehead="e_PM"
			description="Error of stellar proper motion"
			verbLevel="15"/>

		<column name="rv"
			ucd="spect.dopplerVeloc;pos.heliocentric" unit="km/s"
			tablehead="RV"
			description="Stellar radial velocity"
			verbLevel="5"/>

		<column name="e_rv"
			ucd="stat.error;spect.dopplerVeloc;pos.heliocentric" unit="km/s"
			tablehead="Err(RV)"
			description="Error of RV"
			verbLevel="15"/>		
			
		<column name="qflg" type="char(3)"
			ucd="meta.code.qual;phot"
			tablehead="2MASS Phot. flag"
			description="2MASS JHK photometric quality flag"
			verbLevel="25"/>

		<column name="rflg" type="char(3)"
				ucd="meta.ref"
				tablehead="2MASS Qual."
				description="2MASS photometric read flag"
				verbLevel="25" note="r"/>

		<column name="bflg" type="char(3)"
			ucd="meta.code"
			tablehead="2MASS blend"
			description="2MASS photometric blend flag"
			verbLevel="25" note="b"/>

		<column name="twomassid" type="integer" required="true"
			ucd="meta.id.cross"
			tablehead="2MASS id"
			description="Unique identifier in 2MASS (pts_key)"
			verbLevel="25"/>

		<column name="ascc" type="integer"
			ucd="meta.id.cross"
			tablehead="ASCC 2.5 id"
			description="Identifier in ASCC 2.5"
			verbLevel="25">
			<values nullLiteral="0"/>
		</column>

		<column name="spectral" type="text"
			ucd="src.spType"
			tablehead="Spect."
			description="Spectral type and luminosity class"
			verbLevel="15"/>
		
		<column name="r_cl"
			unit="deg" ucd="pos.angDistance"
			tablehead="Ctr. dist."
			description="Angular distance from cluster centre"
			verbLevel="15"/>

		<column name="p_spat"
			unit="" ucd="stat.probability"
			tablehead="P_spat"
			description="Probability of membership from spatial properties"
			verbLevel="15">
			<values min="0.0" max="1.0"/>
		</column>

		<column name="p_kin"
			unit="" ucd="stat.probability"
			tablehead="P_kin"
			description="Probability of membership from kinetic properties"
			verbLevel="15">
			<values min="0.0" max="1.0"/>
		</column>

		<column name="p_jks"
			unit="" ucd="stat.probability"
			tablehead="P_(J,Ks)"
			description="Probability of membership from J, Ks photometry"
			verbLevel="15">
			<values min="0.0" max="1.0"/>
		</column>

		<column name="p_jh"
			unit="" ucd="stat.probability"
			tablehead="P_(J,H)"
			description="Probability of membership from J, H photometry"
			verbLevel="15"/>

		<meta name="note" tag="q"><![CDATA[
			qflag is the photometric quality flag (upstream ph_qual). Three character
			flag, one character per band [JHKs], that provides a summary of the net
			quality of the default photometry in each band, as derived from the Read
			Flag (rflg), measurement uncertainties ([jhk]_cmsig), scan
			signal-to-noise ratios ([jhk]_snr), frame-detection statistics (ndet),
			and profile-fit reduced chi-squared values ([jhk]_psfchi). The value for
			qflag is set for a band according to the precedence of the table below.
			For example, a source that is tested and meets the conditions for
			category "X" is not tested for subsequent qualities.

			"X"
				There is a detection at this location, but no valid brightness estimate
				can be extracted using any algorithm. rflg="9" and default magnitude
				is null.
			"U"
				Upper limit on magnitude. Source is not detected in this band
				(rflg="0"), or it is detected, but not resolved in a consistent
				fashion with other bands (rflg="6"). A value of qflag="U" does not
				necessarily mean that there is no flux detected in this band at the
				location. Whether or not flux has been detected can be determined from
				the value of rflg. When rflag="0", no flux has been detected. When
				rflg="6", flux has been detected at the location where the images
				were not deblended consistently in all three bands (JHKs).
			"F"
				This category includes rflg="1" or rflag="3" sources where a
				reliable estimate of the photometric error, [jhk]_cmsig, could not be
				determined. The uncertainties reported for these sources in [jhk]_cmsig
				and [jhk]_msigcom are flags and have numeric values >8.0.
			"E"
				This category includes detections where the goodness-of-fit quality of
				the profile-fit photometry was very poor (rflg=2 and
				[jhk]psf_chi>10.0), or detections where psf fit photometry did not
				converge and an aperture magnitude is reported (rflg=4), or
				detections where the number of frames was too small in relation to the
				number of frames in which a detection was geometrically possible
				(rflg="1" or rflag="2").
			"A"
				Detections in any brightness regime where valid measurements were made
				(rflg="1","2" or "3") with [jhk]\\_snr>10 AND [jhk]\\_cmsig<0.10857.
			"B"
				Detections in any brightness regime where valid measurements were made
				(rflg="1","2" or "3") with [jhk]\\_snr>7 AND [jhk]\\_cmsig<0.15510.
			"C"
				Detections in any brightness regime where valid measurements were made
				(rflg="1","2" or "3") with [jhk]_snr>5 AND [jhk]_cmsig<0.21714.
			"D"
				Detections in any brightness regime where valid measurements were made
				(rflg="1","2" or "3") with no [jhk]_snr or [jhk]_cmsig requirement.
		]]></meta>

		<meta name="note" tag="r"><![CDATA[
			rflg is upstream's Read flag (rd_flg). It is a three character flag,
			one character per band [JHKs], that indicates the origin of the default
			magnitudes and uncertainties in each band (j_m,h_m,k_m, j_cmsig, h_cmsig,
			k_cmsig). rflg values of "1", "2" or "3" generally indicate the best
			quality detections, photometry and astrometry (although other quality
			flags must be considered). Values of "0", "4", "6" and "9" in a band
			indicate either non-detections, or generally poor quality photometry and
			positions. The definitions of the rflg values are:

			"0"
				Source is not detected in this band. The default magnitude is the 95%
				confidence upper limit derived from a 4" radius aperture measurement
				taken at the position of the source on the Atlas Image. The sky
				background is estimated in an annular region with inner radius of 14"
				and outer radius of 20".
			"1"
				The default magnitude is derived from aperture photometry measurements
				on the 51 ms "Read_1" exposures. The aperture radius is 4", with the
				sky background measured in an annulus with an inner radius of 14" and
				an outer radius of 20". Used for sources that saturate one or more of
				the 1.3s "Read_2" exposures, but are not saturated on at least one of
				the 51 ms "Read_1" frames.
			"2"
				The default magnitude is derived from a profile-fitting measurement
				made on the 1.3 sec "Read_2" exposures. The profile-fit magnitudes are
				normalized to curve-of-growth-corrected aperture magnitudes. This is
				the most common type in the PSC, and is used for sources that have no
				saturated pixels in any of the 1.3 sec exposures.
			"3"
				The default magnitude is derived from a 1-d radial profile fitting
				measurement made on the 51 ms "Read_1" exposures. Used for very bright
				sources that saturate all of the 51 ms "Read 1" exposures.
			"4"
				The default magnitude is derived from curve-of-growth-corrected 4"
				radius aperture photometry measurements on the 1.3 s "Read_2"
				exposures. This is used for sources that are not saturated in any of
				the Read_2 frames, but where the profile-fitting measurements fail to
				converge to a solution. These magnitudes are the same as the standard
				aperture magnitudes (j_m_stdap, h_m_stdap, k_m_stdap), but when they
				are the default magnitudes, it generally implies that they are low
				quality measurements.
			"6"
				The default magnitude is the 95% confidence upper limit derived from a
				4" radius aperture measurement taken at the position of the source on
				the Atlas Image. The sky background is estimated in an annular region
				with inner radius of 14" and outer radius of 20". This is used for
				pairs of sources which are detected and resolved in another band, but
				are detected and not resolved in this band. This differs from a
				rflg="0" because in this case there is a detection of the source in
				this band, but it is not consistently resolved across all bands.
			"9"
				The default magnitude is the 95% confidence upper limit derived from a
				4" radius aperture measurement taken at the position of the source on
				the Atlas Image. The sky background is estimated in an annular region
				with inner radius of 14" and outer radius of 20". This is used for
				sources that were nominally detected in this band, but which could not
				have a useful brightness measurement from either profile fitting or
				aperture photometry. This often occurs in highly confused regions, or
				very near Tile edges where a significant fraction of the measurement
				aperture of sky annulus falls off the focal plane.
		]]></meta>

		<meta name="note" tag="b"><![CDATA[
			Blend flag (upstream's bl_flg). This is a three character flag, one
			character per band [JHKs], that indicates the number of components that
			were fit simultaneously when estimating the brightness of a source:

			"0"
				Source is not detected, or is inconsistently deblended in that band.
			"1"
				One component was fit to the source in R_2 profile-fitting photometry
				(rd_flg="2"), or default magnitudes are from aperture photometry
				(rd_flg="1" or "4") or saturated star 1-d radial profile-fitting
				(rd_flg="3").
			">1"
				More than one component was fit simultaneously during R2 profile-fit
				photometry, where the value of the field is the number of components
				simultaneously fit. The maximum number of components is 7 in any band
				for the PSC, so this bflg is always a three character flag.
				Multi-component fitting occurs only for profile-fitting, and only when
				more than one detection is found within ~5". Single detections that are
				not well-fit by a single PSF are not split.
		]]></meta>

	</table>

	<data id="import_stars">
		<sources pattern="data/stars/*.dat.bz2"/>
		<columnGrammar preFilter="bzcat" id="stars_grammar">
			<colDefs>
				raj2000:1-13
				dej2000:14-26
				magB:27-34
				magV:35-42
				magJ:43-50
				magH:51-58
				magKs:59-66
				e_magJ:67-73
				e_magH:74-80
				e_magKs:81-87
				pmra:88-97
				pmde:98-107
				e_pm:108-115
				rv:116-124
				e_rv:125-131
				qflg:133-135
				rflg:136-138
				bflg:139-141
				twomassid:142-155
				ascc:156-163
				spectral:165-184
				r_cl:186-193
				p_spat:194-195
				p_kin:196-203
				p_jks:204-211
				p_jh:212-219
				recno:220-224
			</colDefs>
		</columnGrammar>
		<make table="stars">
			<rowmaker idmaps="*" id="stars_rmk">
				<map key="raj2000">float(@raj2000)*360/24.</map>
				<map key="ascc" source="ascc" nullExpr="0"/>
				<map key="spectral">parseWithNull(@spectral, str, "")</map>

				<LOOP>
					<csvItems>
						col, null
						magB, -99.990
						magV, -99.990
						e_pm, -9.99
						rv,   999.99
						e_rv, -9.99
						pmra, 9999.90
						pmde, 9999.90
					</csvItems>
					<events>
						<var key="\col">parseWithNull(@\col, float, "\null")</var>
					</events>
				</LOOP>

				<LOOP listItems="pmra pmde e_pm">
					<events>
						<map key="\item">scale(@\item, DEG_MAS)</map>
					</events>
				</LOOP>

				<LOOP listItems="p_kin p_jks p_jh">
					<events>
						<map key="\item">float(@\item)/100.</map>
					</events>
				</LOOP>
			</rowmaker>
		</make>
	</data>

	<service id="clu" allowed="form,scs.xml,qp">
		<publish render="form" sets="ivo_managed,local"/>
		<publish render="scs.xml" sets="ivo_managed"/>
		<meta name="shortName">MWSC clusters</meta>
		<meta name="title">MWSC Star Cluster Search</meta>
		<meta name="_related" title="MWSC member search"
			>\internallink{\rdId/mem/form}</meta>
		<meta>
			testQuery.ra:0.0675
			testQuery.dec:60.933
			testQuery.sr:0.001
		</meta>

		<property name="queryField">recno</property>

		<scsCore queriedTable="main">
			<FEED source="//scs#coreDescs"/>
			<condDesc buildFrom="recno"/>
			<condDesc buildFrom="ot_certain"/>
			<condDesc buildFrom="name"/>
			<condDesc>
				<inputKey original="object_type">
					<values fromdb="object_type from mwsc.main"/>
				</inputKey>
			</condDesc>
			<condDesc buildFrom="rcluster"/>
			<condDesc buildFrom="dist"/>
			<condDesc buildFrom="logt"/>
			<condDesc buildFrom="fe_h"/>
		</scsCore>

		<outputTable verbLevel="20">
			<outputField name="members" type="text"
				ucd="meta.ref.url"
				tablehead="Members"
				description="Link to stars that are candiadate members of this cluster"
				select="'\internallink{mwsc/q/mem/qp}/'||recno||
					'?_FORMAT=VOTable&amp;MAXREC=100000'"
				verbLevel="1">
				<formatter>
					recno = data.split("?")[0].split("/")[-1]
					url = "\internallink{mwsc/q/mem/form}?recno=%s"%recno

					return T.a(href=url)["Search form"]
				</formatter>
			</outputField>
		</outputTable>

	</service>

	<service id="mem" allowed="form,scs.xml,qp">
		<publish render="form" sets="ivo_managed,local"/>
		<publish render="scs.xml" sets="ivo_managed"/>
		<meta name="shortName">MWSC stars</meta>
		<meta name="title">MWSC Member Search</meta>
		<meta name="_related" title="MWSC cluster search"
			>\internallink{\rdId/clu/form}</meta>
		<meta>
			testQuery.ra:0.0675
			testQuery.dec:60.933
			testQuery.sr:0.01
		</meta>

		<property name="queryField">recno</property>

		<scsCore queriedTable="stars">
      <FEED source="//scs#coreDescs"/>
      <condDesc buildFrom="p_spat"/>
      <condDesc buildFrom="p_kin"/>
      <condDesc buildFrom="p_jks"/>
			<condDesc buildFrom="recno"/>
			<condDesc buildFrom="magV"/>
			<condDesc buildFrom="magJ"/>
			<condDesc buildFrom="twomassid"/>
			<condDesc buildFrom="spectral"/>
		</scsCore>

		<outputTable verbLevel="20">
			<outputField name="cluster" type="text"
				ucd="meta.ref.url"
				tablehead="Cluster"
				description="Information on the cluster possibly containing this star"
				select="'\internallink{mwsc/q/clu/qp}/'||recno"
				verbLevel="1" displayHint="type=url"/>
		</outputTable>

	</service>

</resource>
