<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.ivoa.net/xml/prop/VOQuantity" 
           xmlns:voq="http://www.ivoa.net/xml/prop/VOQuantity" 
	   xmlns:xs="http://www.w3.org/2001/XMLSchema" 
	   elementFormDefault="qualified" attributeFormDefault="unqualified">
  <!-- To Do:
    *  put Value & Error into group?
    *  define metric prefixes
    *  display => value 
    -->
  <xs:annotation>
    <xs:appinfo>
      <dictionaryVersion>0.1</dictionaryVersion>
      <shortName>VOQuantity</shortName>
      <version>0.1</version>
      <targetPrefix>voq</targetPrefix>
      <schemaPrefix>xs</schemaPrefix>
    </xs:appinfo>
    <xs:documentation>
    This schema defines a generic container for real-valued quantities 
    that may have associated units and errors.  It also includes a few 
    examples of how the schema can be extended to specific quantities
    that can be encoded with custom tags.  
    </xs:documentation>
  </xs:annotation>

  <!-- Reusable Types -->
  <xs:simpleType name="normalizedPercent">
    <xs:annotation>
      <xs:documentation>
      a value representing percent that is restricted to the range [0,100]
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:float">
      <xs:minInclusive value="0.0"/>
      <xs:maxInclusive value="100.0"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="dimensionlessQuantity">
    <xs:sequence>
      <xs:element ref="voq:Value" minOccurs="0"/>
      <xs:element ref="voq:Error" minOccurs="0"/>
    </xs:sequence>

    <xs:attribute name="display" type="xs:string" use="optional">
      <xs:annotation>
        <xs:documentation>
        a formatted version of the quantity intended for display
        </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="genericQuantity">
    <xs:complexContent>
      <xs:extension base="voq:dimensionlessQuantity">
        <xs:sequence>
          <xs:element name="Unit" type="voq:unit" nillable="true"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="unit">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="prefix" type="xs:string" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

  <xs:element name="Value" type="xs:double">
    <xs:annotation>
      <xs:documentation>
      the decimal value of a quantity
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="Unit" type="voq:unit">
    <xs:annotation>
      <xs:documentation>
      the unit or dimension associated with a quantity
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="Error" abstract="true">
    <xs:annotation>
      <xs:documentation>
      a description of the error associated with the quantity
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="Sigma" type="xs:double" substitutionGroup="voq:Error">
    <xs:annotation>
      <xs:documentation>
      The error associated with the quantity expressed in terms of a 
      statistical standard deviation.
      </xs:documentation>
    </xs:annotation>
  </xs:element>

  <xs:element name="ErrorRange" substitutionGroup="voq:Error">
    <xs:annotation>
      <xs:documentation>
      a range of values surrounding a quantity's value reflecting 
      confidence
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="minus" type="xs:double"/>
        <xs:element name="plus" type="xs:double"/>
      </xs:sequence>
      <xs:attribute name="confidence" type="voq:normalizedPercent" 
		    use="optional" default="99.7">
        <xs:annotation>
	  <xs:documentation>
	  The percent confidence that the true value falls within 
	  the error range.
	  </xs:documentation>
        </xs:annotation>
      </xs:attribute>
    </xs:complexType>
  </xs:element>

  <xs:element name="Quantity">
    <xs:annotation>
      <xs:documentation>
            a measurable value that can have an associated unit and/or error
            </xs:documentation>
    </xs:annotation>

    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="voq:genericQuantity">

          <xs:attribute name="name" type="xs:string">
            <xs:annotation>
              <xs:documentation>
              the name of the quantity; the thing that the value measures
              </xs:documentation>
            </xs:annotation>
          </xs:attribute>

        </xs:extension>
      </xs:complexContent>
    </xs:complexType>

  </xs:element>

  <xs:element name="Quantities">
    <xs:annotation>
      <xs:documentation>
      a list of quantities.
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="voq:Quantity" minOccurs="0" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <!-- 
       specific quantity types and element 
    -->

  <!-- Length -->
  <xs:complexType name="lengthUnit">
    <xs:simpleContent>
      <xs:restriction base="voq:unit">
        <xs:enumeration value="m"/>
        <xs:enumeration value="pc"/>
        <xs:enumeration value="lt-yr"/>
      </xs:restriction>
    </xs:simpleContent>
  </xs:complexType>

  <xs:element name="Length" substitutionGroup="voq:Quantity">
    <xs:annotation>
      <xs:documentation>
      a length or distance quantity
      </xs:documentation>
    </xs:annotation>

    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="voq:dimensionlessQuantity">
          <xs:sequence>
            <xs:element name="Unit" type="voq:lengthUnit" nillable="true"/>
          </xs:sequence>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>

  </xs:element>

  <!-- Flux -->
  <xs:complexType name="fluxUnit">
    <xs:simpleContent>
      <xs:restriction base="voq:unit">
        <xs:enumeration value="Jy"/>
      </xs:restriction>
    </xs:simpleContent>
  </xs:complexType>

  <xs:element name="Flux" substitutionGroup="voq:Quantity">

    <xs:annotation>
      <xs:documentation>
      an energy flux quantity; i.e. an amount energy per unit
      frequency passing through a unit area.
      </xs:documentation>
    </xs:annotation>

    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="voq:dimensionlessQuantity">
          <xs:sequence>
            <xs:element name="Unit" type="voq:fluxUnit" nillable="true"/>
          </xs:sequence>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:element>

  <!-- Frequency -->
  <xs:complexType name="freqUnit">
    <xs:simpleContent>
      <xs:restriction base="voq:unit">
        <xs:enumeration value="m"/>
        <xs:enumeration value="Hz"/>
        <xs:enumeration value="eV"/>
      </xs:restriction>
    </xs:simpleContent>
  </xs:complexType>

  <xs:element name="Frequency" substitutionGroup="voq:Quantity">
    <xs:annotation>
      <xs:documentation>
      a measure of wave periodicity, usually of electromagnetic radiation
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:complexContent>
        <xs:extension base="voq:dimensionlessQuantity">
          <xs:sequence>
            <xs:element name="Unit" type="voq:freqUnit" nillable="true"/>
          </xs:sequence>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:element>
</xs:schema>

