<?xml version="1.0" encoding="UTF-8"?>
<!-- VO matrix (n-dimensional) quantity schema Version 0.91 -->
<xsd:schema targetNamespace="http://www.ivoa.net/Quantity" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            xmlns:coord="http://www.ivoa.net/xml/STC/stc-v1.20" 
            xmlns:acc="http://www.ivoa.net/Accuracy" 
            xmlns:map="http://www.ivoa.net/Mappings" 
            xmlns:p="http://www.ivoa.net/Publications" 
            xmlns:unit="http://www.ivoa.net/Units" 
            xmlns:ucd="http://www.ivoa.net/UCD1+" 
            xmlns:q="http://www.data-model.net/Quantity"
            xmlns="http://www.ivoa.net/Quantity" 
            elementFormDefault="qualified"
>
	<xsd:import namespace="http://www.data-model.net/Quantity" schemaLocation="QML_04.xsd"/>
	<xsd:import namespace="http://www.ivoa.net/Accuracy" schemaLocation="VOAccuracy.xsd"/>
	<xsd:import namespace="http://www.ivoa.net/xml/STC/stc-v1.20" schemaLocation="VOCoordinateSystems.xsd"/>
	<xsd:import namespace="http://www.ivoa.net/Mappings" schemaLocation="VOMappings.xsd"/>
        <xsd:import namespace="http://www.ivoa.net/Publications" schemaLocation="VO_publications.xsd"/>
	<xsd:import namespace="http://www.ivoa.net/UCD1+" schemaLocation="UCD1plus.xsd"/>
	<xsd:import namespace="http://www.ivoa.net/Units" schemaLocation="VOUnits.xsd"/>
	<xsd:annotation>
	        <xsd:documentation> VOQuantity.xsd -- VO Quantity schema.</xsd:documentation>
	</xsd:annotation>

  <!-- attributes that all quantities (sans refQuantities) have -->
  <!-- the quantity type .. all quantities inherit from this -->
       <xsd:attributeGroup name="ComponentAttribs">
           <xsd:attributeGroup ref="q:ComponentAttribs"/>
       </xsd:attributeGroup>

        <xsd:attributeGroup name="AtomicQuantityAttribs">
           <xsd:attributeGroup ref="q:AtomicQuantityAttribs"/>
        </xsd:attributeGroup>

        <xsd:attributeGroup name="CompositeQuantityAttribs">
           <xsd:attributeGroup ref="q:CompositeQuantityAttribs"/>
        </xsd:attributeGroup>

        <xsd:attributeGroup name="ListQuantityAttribs">
           <xsd:attributeGroup ref="q:ListQuantityAttribs"/>
        </xsd:attributeGroup>

        <xsd:attributeGroup name="QuantityAttribs">
           <xsd:attributeGroup ref="q:QuantityAttribs"/>
        </xsd:attributeGroup>

  <!-- Quantity container -->
  <xsd:complexType name="QuantityContainer">
      <xsd:complexContent>
		<xsd:extension base="q:QuantityContainer"/>
      </xsd:complexContent>
  </xsd:complexType>

<!--
  <xsd:complexType name="QuantityType">
	<xsd:complexContent>
	 	<xsd:extension base="q:QuantityType"/>
	</xsd:complexContent>
  </xsd:complexType>
-->

<!-- fix: needs to be restriction -->
	<xsd:complexType name="CompositeQuantityType">
		<xsd:complexContent>
			<xsd:restriction base="q:CompositeQuantityType">
                           <xsd:sequence>
                                   <!-- allow insertion of other q's and notes here as data -->
                                   <xsd:choice minOccurs="0" maxOccurs="unbounded">
                                      <xsd:element ref="QuantityGroup"/>
                                      <xsd:element ref="ListQuantityGroup"/>
                                      <xsd:element ref="p:NoteGroup"/>
                                      <xsd:element ref="p:references"/>
                                   </xsd:choice>
				   <xsd:element ref="ucd:UCDGroup" minOccurs="0" maxOccurs="1"/>
                                   <xsd:sequence>
				       <xsd:element ref="axes" minOccurs="0" maxOccurs="unbounded"/>
                                   </xsd:sequence>
                           </xsd:sequence>
                           <xsd:attributeGroup ref="CompositeQuantityAttribs"/>
			</xsd:restriction>
		</xsd:complexContent>
	</xsd:complexType>

        <!-- a "frame" is essentially a component of a vector. -->
        <xsd:complexType name="ComponentType">
            <xsd:complexContent>
                <xsd:restriction base="q:ComponentType">
        
                  <xsd:sequence>
        
<!-- allow insertion of other q's here as meta-data? no for now -->
<!--
                    <xsd:choice minOccurs="0" maxOccurs="unbounded">
                        <xsd:element ref="QuantityGroup"/>
                        <xsd:element ref="ListQuantityGroup"/>
                        <xsd:element ref="p:NoteGroup"/>
                        <xsd:element ref="p:references"/>
                    </xsd:choice>
-->
                    <!-- special named meta-data : the ucd and coordSystem. We
                         have restricted these to no more than one instance allowed -->
                    <xsd:element ref="ucd:UCDGroup" minOccurs="0" maxOccurs="1"/>
                    <xsd:choice minOccurs="0" maxOccurs="1">
                         <xsd:element ref="coord:CoordSystemType"/>
                         <xsd:element ref="coord:CoordSystemRef"/>
                    </xsd:choice>

                    <!-- units/dataType section -->
                    <xsd:choice>
                      <!-- type 1 : scalar needs dataType + units -->
                      <xsd:sequence>
                         <xsd:element ref="unit:UnitsGroup" minOccurs="0"/>
                         <xsd:element ref="ScalarDataTypeGroup" minOccurs="0" maxOccurs="1"/>
                       </xsd:sequence>
                     <!-- type 2 : vector needs dataType only -->
                     <xsd:element ref="vector"/>
                    </xsd:choice>
                  </xsd:sequence>
                  <xsd:attributeGroup ref="ComponentAttribs"/>
                </xsd:restriction>
            </xsd:complexContent>
          </xsd:complexType>

	<xsd:complexType name="MatrixQuantityType">
		<xsd:complexContent>
			<xsd:restriction base="q:MatrixQuantityType">
				<xsd:sequence>

                                        <!-- allow insertion of other q's and notes here as meta-data -->
                                        <xsd:choice minOccurs="0" maxOccurs="unbounded">
                                           <xsd:element ref="QuantityGroup"/>
                                           <xsd:element ref="ListQuantityGroup"/>
                                           <xsd:element ref="p:NoteGroup"/>
                                           <xsd:element ref="p:references"/>
                                        </xsd:choice>
					<!-- special named meta-data : the ucd and coordSystem. We
                                             have restricted these to no more than one instance allowed -->
					<xsd:element ref="ucd:UCDGroup" minOccurs="0" maxOccurs="1"/>
					<xsd:choice minOccurs="0" maxOccurs="1">
                                            <xsd:element ref="coord:CoordSystemType"/>
                                            <xsd:element ref="coord:CoordSystemRef"/>
					</xsd:choice>

					<!-- specification of the (apparent) dimensionality. Done this way, we insure
                                             the axes will always appear after the other meta-data. 
                                          -->
					<xsd:sequence>
						<xsd:element ref="axes" minOccurs="0" maxOccurs="unbounded"/>
					</xsd:sequence>
					<!-- data section. various groupings -->
					<!-- number data -->
					<xsd:sequence>
						<!-- dataTYpe/Units. Only certain combos can exist -->
						<xsd:choice>
							<!-- type 1 : scalar needs dataType + units -->
							<xsd:sequence>
								<xsd:element ref="unit:UnitsGroup" minOccurs="0"/>
                                                                <xsd:element ref="ScalarDataTypeGroup" minOccurs="0" maxOccurs="1"/>
							</xsd:sequence>
							<!-- type 2 : vector needs dataType only -->
							<xsd:element ref="vector"/>
						</xsd:choice>
						<xsd:choice>
							<xsd:element ref="ValueGroup"/>
							<xsd:element ref="values"/>
							<xsd:element name="mapping" type="map:MappingContainer"/>
						</xsd:choice>
                                                <xsd:element ref="altValues" minOccurs="0"/>
					</xsd:sequence>
				</xsd:sequence>
				<xsd:attributeGroup ref="ListQuantityAttribs"/>
			</xsd:restriction>
		</xsd:complexContent>
	</xsd:complexType>

	<!-- list quantity .. a list of values -->
	<xsd:complexType name="ListQuantityType">
		<xsd:complexContent>
			<xsd:restriction base="q:ListQuantityType">
				<xsd:sequence>

                                        <!-- allow insertion of other q's and notes here as meta-data -->
                                        <xsd:choice minOccurs="0" maxOccurs="unbounded">
                                           <xsd:element ref="QuantityGroup"/>
                                           <xsd:element ref="ListQuantityGroup"/>
                                           <xsd:element ref="p:NoteGroup"/>
                                           <xsd:element ref="p:references"/>
                                        </xsd:choice>
                                        <!-- special named meta-data : the ucd and coordSystem. We
                                             have restricted these to no more than one instance allowed -->
                                        <xsd:element ref="ucd:UCDGroup" minOccurs="0" maxOccurs="1"/>
                                        <xsd:choice minOccurs="0" maxOccurs="1">
                        <xsd:element ref="coord:CoordSystemType"/>
                         <xsd:element ref="coord:CoordSystemRef"/>
                                        </xsd:choice>

					<!-- number data -->
					<xsd:sequence>
						<!-- dataTYpe/Units. Only certain combos can exist -->
						<xsd:choice>
							<!-- type 1 : scalar needs dataType + units -->
							<xsd:sequence>
								<xsd:element ref="unit:UnitsGroup" minOccurs="0"/>
                                                                <xsd:element ref="ScalarDataTypeGroup" minOccurs="0" maxOccurs="1"/>
							</xsd:sequence>
							<!-- type 1 : vector needs dataType only -->
							<xsd:element ref="vector"/> 
						</xsd:choice>
						<xsd:choice>
							<xsd:element ref="ValueGroup"/>
							<xsd:element ref="values"/>
							<xsd:element name="mapping" type="map:MappingContainer"/>
						</xsd:choice>
					</xsd:sequence>
				</xsd:sequence>
				<xsd:attributeGroup ref="ListQuantityAttribs"/>
			</xsd:restriction>
		</xsd:complexContent>
	</xsd:complexType>
	<xsd:complexType name="AtomicQuantityType">
		<xsd:annotation>
			<xsd:documentation>The atomic quantity .. a single "value" only </xsd:documentation>
		</xsd:annotation>
		<xsd:complexContent>
			<xsd:restriction base="q:AtomicQuantityType">
				<xsd:sequence>

                                        <!-- allow insertion of other q's and notes here as meta-data -->
                                        <xsd:choice minOccurs="0" maxOccurs="unbounded">
                                           <xsd:element ref="QuantityGroup"/>
                                           <xsd:element ref="ListQuantityGroup"/>
                                           <xsd:element ref="p:NoteGroup"/>
                                           <xsd:element ref="p:references"/>
                                        </xsd:choice>
                                        <!-- special named meta-data : the ucd and coordSystem. We
                                             have restricted these to no more than one instance allowed -->
                                        <xsd:element ref="ucd:UCDGroup" minOccurs="0" maxOccurs="1"/>
                                        <xsd:choice minOccurs="0" maxOccurs="1">
                        <xsd:element ref="coord:CoordSystemType"/>
                         <xsd:element ref="coord:CoordSystemRef"/>
                                        </xsd:choice>

					<!-- number data -->
					<xsd:sequence>
						<!-- dataTYpe/Units. Only certain combos can exist -->
						<xsd:choice>
							<!-- type 1 : scalar needs dataType + units -->
							<xsd:sequence>
								<xsd:element ref="unit:UnitsGroup" minOccurs="0"/>
                                                                <xsd:element ref="ScalarDataTypeGroup" minOccurs="0" maxOccurs="1"/>
							</xsd:sequence>
							<!-- type 1 : vector needs dataType only -->
							<xsd:element ref="vector"/> 
						</xsd:choice>
						<xsd:element ref="ValueGroup"/>
					</xsd:sequence>
				</xsd:sequence>
				<xsd:attributeGroup ref="q:AtomicQuantityAttribs"/>
			</xsd:restriction>
		</xsd:complexContent>
	</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="q:TrivialQuantityType"/>
		</xsd:complexContent>
	</xsd:complexType>

	<!-- a container for axes (which are listQ's) -->
	<xsd:complexType name="AxesContainerType">
		<xsd:complexContent>
			<xsd:restriction base="q:AxisFrameType">
                            <!-- allow insertion of other q's and notes here as meta-data -->
                            <xsd:choice minOccurs="1" maxOccurs="unbounded">
                               <xsd:element ref="refQuantity"/>
                               <xsd:element ref="ListQuantityGroup"/>
                               <xsd:element ref="p:NoteGroup"/>
                            </xsd:choice>
                            <xsd:attributeGroup ref="ListQuantityAttribs"/>
			</xsd:restriction>
		</xsd:complexContent>
	</xsd:complexType>

       <!-- a container for altValues (which are listQ's) -->
        <xsd:complexType name="AltValuesContainerType">
                <xsd:complexContent>
                        <xsd:restriction base="q:AltValuesContainerType">
                            <xsd:sequence>
                               <xsd:element ref="ListQuantityGroup" minOccurs="1" maxOccurs="unbounded"/>
                            </xsd:sequence>
                        </xsd:restriction>
                </xsd:complexContent>
        </xsd:complexType>


   <!-- some (abstract) group declarations -->
  <xsd:element name="QuantityGroup" type="q:QuantityType" abstract="true"/>
  <xsd:element name="ScalarDataTypeGroup" type="q:ScalarDataType" abstract="true"/>
  <xsd:element name="ValueGroup" type="q:valueType" abstract="true"/>
  <xsd:element name="ListQuantityGroup" type="q:ListQuantityType" abstract="true"/>
  <xsd:element name="ComponentGroup" type="q:AbstractComponentType" abstract="true"/>

	<!-- Some quantity element declarations. Ayy of these *could*
       serve as the root node of an instance document. Would be pointless 
       to use refQuantity in this manner.
          -->
	<xsd:element name="atomicQuantity" type="AtomicQuantityType" substitutionGroup="QuantityGroup"/>
	<xsd:element name="compositeQuantity" type="CompositeQuantityType" substitutionGroup="QuantityGroup"/>
	<xsd:element name="component" type="ComponentType" substitutionGroup="ComponentGroup"/>
	<xsd:element name="listQuantity" type="ListQuantityType" substitutionGroup="ListQuantityGroup"/>
	<xsd:element name="matrixQuantity" type="MatrixQuantityType" substitutionGroup="QuantityGroup"/>
	<xsd:element name="quantity" type="MatrixQuantityType" substitutionGroup="QuantityGroup"/>
	<xsd:element name="trivialQuantity" type="TrivialQuantityType" substitutionGroup="QuantityGroup"/>
	<xsd:element name="refQuantity" type="refQuantityType" substitutionGroup="QuantityGroup"/>
	<xsd:element name="value" type="ValueType" substitutionGroup="ValueGroup"/>
        <xsd:element name="values" type="ValuesContainerType"/>

        <!-- other element (re) declarations. Done mostly for the purposes of serialization
             appearance and inheritance in other schema -->
	<xsd:element name="axes" type="AxesContainerType" substitutionGroup="QuantityGroup"/>
        <xsd:element name="float" type="floatType" substitutionGroup="ScalarDataTypeGroup"/>
        <xsd:element name="integer" type="integerType" substitutionGroup="ScalarDataTypeGroup"/>
        <xsd:element name="string" type="stringType" substitutionGroup="ScalarDataTypeGroup"/>
        <xsd:element name="sexigesimal" type="sexigesimalType" substitutionGroup="ScalarDataTypeGroup"/>
        <xsd:element name="date" type="dateType" substitutionGroup="ScalarDataTypeGroup"/>
        <xsd:element name="vector" type="vectorType"/>
        <xsd:element name="altValues" type="AltValuesContainerType"/>

        <!-- data types -->
        <xsd:complexType name="floatType">
            <xsd:complexContent>
               <xsd:extension base="q:floatType"/>
            </xsd:complexContent>
        </xsd:complexType>

        <xsd:complexType name="integerType">
            <xsd:complexContent>
               <xsd:extension base="q:integerType"/>
            </xsd:complexContent>
        </xsd:complexType>

        <xsd:complexType name="stringType">
            <xsd:complexContent>
               <xsd:extension base="q:stringType"/>
            </xsd:complexContent>
        </xsd:complexType>

        <xsd:complexType name="vectorType">
            <xsd:complexContent>
               <xsd:restriction base="q:vectorType">
                  <xsd:sequence maxOccurs="unbounded">
                     <xsd:element ref="ComponentGroup" maxOccurs="unbounded"/>
                  </xsd:sequence>
               </xsd:restriction>
            </xsd:complexContent>
        </xsd:complexType>

	<!-- special string type: a field with 2 colons which separate
       numbers as "int:int:float" Perhaps: We need to couple this with a 
       value restriction, so that suppled values in quantites with
       this are restricted to correct pattern (easy to do for BQ,
	but difficult for advanced Q's). 
    -->
	<xsd:complexType name="sexigesimalType">
		<xsd:complexContent>
<!-- FIX : should have regex/restriction here -->
			<xsd:extension base="stringType"/>
		</xsd:complexContent>
	</xsd:complexType>
	<!-- special string type: a field with 2 dashes which separate
       numbers as "int-int-int", the year-month-day. We need
       to be more stringent/clear about acceptable dates. This is
       preliminary. 
    -->
	<xsd:complexType name="dateType">
		<xsd:complexContent>
			<xsd:extension base="stringType"/>
		</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="q:refQuantityType"/>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- treatment of data..allow all sorts of tagging for cells -->
  <xsd:complexType name="ValueType">
    <xsd:simpleContent>
      <xsd:extension base="q:valueType"/>
    </xsd:simpleContent>
  </xsd:complexType>

  <xsd:complexType name="ValuesContainerType" mixed="true">
    <xsd:complexContent>
      <xsd:restriction base="q:ValuesContainer">
           <xsd:sequence>
                  <xsd:element ref="ValueGroup" minOccurs="0" maxOccurs="unbounded"/>
           </xsd:sequence>
      </xsd:restriction>
    </xsd:complexContent>
  </xsd:complexType>

</xsd:schema>
