<?xml version="1.0" encoding="UTF-8"?>
<!-- basic quanity schema -->
<xsd:schema 
	    targetNamespace="http://ivoa.org/Quantity"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:acc="http://ivoa.org/Accuracy"
            xmlns:coord="http://ivoa.org/CoordinateSystems"
            xmlns="http://ivoa.org/Quantity"
	    elementFormDefault="notqualified"
>

	<xsd:import namespace="http://ivoa.org/Accuracy" schemaLocation="BasicAccuracy.xsd"/>
	<xsd:import namespace="http://ivoa.org/CoordinateSystems" schemaLocation="CoordinateSystems.xsd"/>

        <xsd:annotation>
                <xsd:documentation>BasicQuantity.xsd - basic atomic quantity
                                  serialization for IVOA.org
                                  first draft Feb. 20 2004 (brian thomas; thomas@astro.umd.edu)
                </xsd:documentation>
        </xsd:annotation>

	<!-- attributes that all quantities (sans refQuantities) have -->
	<xsd:attributeGroup name="frameAttribs">
		<xsd:attribute name="name" type="xsd:string"/>
		<xsd:attribute name="description" type="xsd:string"/>
	</xsd:attributeGroup>

	<xsd:attributeGroup name="quantityAttribs">
		<xsd:attributeGroup ref="frameAttribs"/>
		<xsd:attribute name="qid" type="xsd:ID"/>
	</xsd:attributeGroup>

	<!-- the quantity type .. all quantities inherit from this -->
        <xsd:complexType name="QuantityType">
		<!-- no content type, as we need to allow both simple and complexContent types -->
	</xsd:complexType>

	<!-- trivial quantity..can hold pcdata within as well as name/desc attribs -->
        <xsd:complexType name="trivialQuantityType" mixed="true">
		<xsd:complexContent>
			<xsd:extension base="QuantityType">
				<xsd:attributeGroup ref="quantityAttribs"/>
			</xsd:extension>
		</xsd:complexContent>
	</xsd:complexType>

	<!-- this type of quantity just references other types, allows some 
	     compresson of the document -->
	<xsd:complexType name="refQuantityType">
                <xsd:complexContent>
			<xsd:extension base="QuantityType">
				<xsd:attribute name="qidRef" type="xsd:IDREF" use="required"/>
			</xsd:extension>
                </xsd:complexContent>
	</xsd:complexType>

       <!-- basic quantity adds in some child nodes -->
        <xsd:complexType name="basicQuantityType">
                <xsd:complexContent>
                        <xsd:extension base="QuantityType">
                                <!-- has child elements -->
                                <xsd:sequence>

                                        <!-- arbitrary (quantity) metadata (only basic quantites or lower allowed) -->
                                        <xsd:element name="metaData" type="QuantityContainer" minOccurs="0" />
                                        <!-- special named meta-data : the ucd -->
                                        <xsd:element name="ucd" type="trivialQuantityType" minOccurs="0" />
                                        <!-- special named meta-data : the coordSystem -->
                                        <xsd:element name="coordSystem" type="coord:CoordSystemsContainer" minOccurs="0"/>

                                        <!-- units/data type section -->
                                        <xsd:choice minOccurs="0" maxOccurs="1">
                                                <xsd:sequence>
                                                        <!-- special named meta-data : the units. ONLY with float/int/string types -->
                                        		<xsd:choice minOccurs="0" maxOccurs="1">
                                                        	<xsd:element name="units" type="trivialQuantityType"/>
                                                        	<xsd:element name="unitless" type="unitlessType"/>
                                        		</xsd:choice>
                                                        <!-- basic data types, int/float/string -->
                                                        <xsd:choice minOccurs="0" maxOccurs="1">
                                                                <xsd:element name="float" type="floatType"/>
                                                                <xsd:element name="integer" type="integerType"/>
                                                                <xsd:element name="string" type="stringType"/>
                                                        </xsd:choice>
                                                </xsd:sequence>
                                                <!-- special dataType..no units for vector.. that is
                                                     information is contained within its "frame" components -->
                                                <xsd:element name="vector" type="vectorType"/>
                                        </xsd:choice>

					<!-- no mapping for basic quantity? -->
                        		<xsd:element ref="ValueCellGroup" maxOccurs="unbounded"/>

                                        <!-- accuracy section (only basic or lower quantities allowed) -->
                                        <xsd:element name="accuracy" type="acc:AccuracyContainer" minOccurs="0" />

                                </xsd:sequence>
                                <xsd:attributeGroup ref="quantityAttribs"/>
                                <xsd:attribute name="size" type="xsd:positiveInteger" default="1"/>
                        </xsd:extension>
                </xsd:complexContent>
        </xsd:complexType>

	<!-- the quantity (abstract) group declarations -->
	<xsd:element name="QuantityGroup" abstract="true" type="QuantityType"/>
	<xsd:element name="FrameGroup" abstract="true" type="FrameType"/>

	<!-- Some quantity element declarations. Either trivial or basic of these *could*
             serve as the root node of an instance document. Would be pointless to use refQuantity
	     in this manner.
          -->
	<xsd:element name="trivialQuantity" substitutionGroup="QuantityGroup" type="trivialQuantityType"/>
	<xsd:element name="basicQuantity" substitutionGroup="QuantityGroup" type="basicQuantityType"/>
	<xsd:element name="refQuantity" substitutionGroup="QuantityGroup" type="refQuantityType"/>

	<!-- a 'vanilla' frame declaration -->
	<xsd:element name="frame" substitutionGroup="FrameGroup" type="FrameType"/>

	<!-- Quantity container -->
	<xsd:complexType name="QuantityContainer">
		<xsd:sequence>
			<xsd:element ref="QuantityGroup" maxOccurs="unbounded"/>
		</xsd:sequence>
	</xsd:complexType>
 
	<!-- data types -->
        <xsd:complexType name="integerType">
                <xsd:attribute name="type" default="decimal">
                        <xsd:simpleType>
                                <xsd:restriction base="xsd:NMTOKEN">
                                        <xsd:enumeration value="decimal"/>
                                        <xsd:enumeration value="octal"/>
                                        <xsd:enumeration value="hexadecimal"/>
                                </xsd:restriction>
                        </xsd:simpleType>
                </xsd:attribute>
                <xsd:attribute name="width" type="xsd:NMTOKEN"/> <!-- use="required"/>
-->
                <xsd:attribute name="signed" default="yes">
                        <xsd:simpleType>
                                <xsd:restriction base="xsd:NMTOKEN">
                                        <xsd:enumeration value="yes"/>
                                        <xsd:enumeration value="no"/>
                                </xsd:restriction>
                        </xsd:simpleType>
                </xsd:attribute>
                <xsd:attribute name="noDataValue" type="xsd:long"/>
        </xsd:complexType>

        <xsd:complexType name="floatType">
                <xsd:attribute name="width" type="xsd:NMTOKEN"/><!-- use="required"/>
-->
                <xsd:attribute name="precision" type="xsd:NMTOKEN"/> <!-- use="required"/>
-->
                <xsd:attribute name="exponent" type="xsd:NMTOKEN" default="0"/>
                <xsd:attribute name="noDataValue" type="xsd:double"/>
        </xsd:complexType>

        <xsd:complexType name="stringType">
                <xsd:attribute name="width" type="xsd:NMTOKEN" default="-1"/>
                <xsd:attribute name="noDataValue" type="xsd:string"/>
        </xsd:complexType>

        <xsd:complexType name="vectorType">
                <xsd:sequence minOccurs="1" maxOccurs="unbounded">
			<xsd:element ref="FrameGroup" maxOccurs="unbounded"/>
                </xsd:sequence>
        </xsd:complexType>

	<!-- unitless -->
	<xsd:complexType name="unitlessType"/>

	<!-- a component/frame -->
        <xsd:complexType name="FrameType">
		<xsd:sequence>
			<!-- arbitrary (quantity) metadata (only basic quantites or lower allowed) -->
			<xsd:element name="metaData" type="QuantityContainer" minOccurs="0" />
			<!-- special named meta-data : the ucd -->
			<xsd:element name="ucd" type="trivialQuantityType" minOccurs="0" />
			<!-- special named meta-data : the coordSystem -->
			<xsd:element name="coordSystem" type="coord:CoordSystemsContainer" minOccurs="0"/>
			<!-- units/dataType section -->
			<xsd:choice minOccurs="0" maxOccurs="1">
				<xsd:sequence>
					<!-- special named meta-data : the units. ONLY with float/int/string types -->
                                        <xsd:choice minOccurs="0" maxOccurs="1">
						<xsd:element name="units" type="trivialQuantityType"/>
						<xsd:element name="unitless" type="unitlessType"/>
                                        </xsd:choice>
					<!-- basic data types, int/float/string -->
					<xsd:choice minOccurs="0" maxOccurs="1">
						<xsd:element name="float" type="floatType"/>
						<xsd:element name="integer" type="integerType"/>
						<xsd:element name="string" type="stringType"/>
					</xsd:choice>
				</xsd:sequence>
				<!-- special dataType..no units for vector.. that is
				     information is contained within its "frame" components -->
				<xsd:element name="vector" type="vectorType"/>
			</xsd:choice>
		</xsd:sequence>
		<xsd:attributeGroup ref="frameAttribs"/>
        </xsd:complexType>

       <!-- treatment of data..allow all sorts of tagging for cells -->
        <xsd:element name="ValueCellGroup" abstract="true" type="valueCellType"/>

        <xsd:complexType name="valueCellType">
                <xsd:simpleContent>
                        <xsd:extension base="xsd:string"/>
                </xsd:simpleContent>
        </xsd:complexType>

        <xsd:complexType name="ValueContainer">
                <xsd:sequence>
                        <xsd:element ref="ValueCellGroup" maxOccurs="unbounded"/>
                </xsd:sequence>
        </xsd:complexType>

        <!-- the default value (cell) element -->
        <xsd:element name="value" substitutionGroup="ValueCellGroup" type="valueCellType"/>

	<!-- no mappings for basic quantity, correct? -->
</xsd:schema>

