<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:complexType name="memoryType">
    <xsd:sequence>
      <xsd:element name="shortName" type="shortNameType"/>
      <xsd:element name="longName" type="longNameType" minOccurs="0"/>
      <xsd:element name="frequency" type="frequencyType"/>
      <xsd:element name="squelch" type="squelchType"
		   minOccurs="0" maxOccurs="3"/>
      <xsd:element name="squelchSetting" type="xsd:string" minOccurs="0"/>
      <xsd:element name="duplex" type="duplexType"/>
      <xsd:element name="offset" type="frequencyType"/>
      <xsd:element name="mode" type="modeType"/>
      <xsd:element name="tuningStep" type="frequencyType"/>
      <xsd:element name="skip" type="skipType" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="bank" type="bankInfoType" minOccurs="0" maxOccurs="1"/>
      <xsd:element name="dv" type="dvType" minOccurs="0"/>
    </xsd:sequence>
    <xsd:attribute name="location" type="xsd:nonNegativeInteger"/>
  </xsd:complexType>

  <xsd:simpleType name="shortNameType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[A-Z0-9/ >-]{0,6}"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:complexType name="frequencyType">
    <xsd:simpleContent>
      <xsd:extension base="xsd:decimal">
	<xsd:attribute name="units" type="freqUnitsType" use="required"/>
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>
  
  <xsd:simpleType name="freqUnitsType">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="Hz"/>
      <xsd:enumeration value="kHz"/>
      <xsd:enumeration value="MHz"/>
      <xsd:enumeration value="GHz"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="longNameType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[.A-Za-z0-9/ >-]{0,16}"/>
    </xsd:restriction>
  </xsd:simpleType>


  <xsd:complexType name="squelchType">
    <xsd:sequence>
      <xsd:element name="tone" type="xsd:decimal" minOccurs="0"/>
      <xsd:element name="code" type="xsd:positiveInteger" minOccurs="0"/>
      <xsd:element name="polarity" type="dtcsPolarityType" minOccurs="0"/>
    </xsd:sequence>
    <xsd:attribute name="id"/>
    <xsd:attribute name="type"/>
  </xsd:complexType>

  <xsd:simpleType name="dtcsPolarityType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[RN]{2}"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="duplexType">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="positive"/>
      <xsd:enumeration value="negative"/>
      <xsd:enumeration value="none"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="modeType">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="FM"/>
      <xsd:enumeration value="NFM"/>
      <xsd:enumeration value="WFM"/>
      <xsd:enumeration value="AM"/>
      <xsd:enumeration value="NAM"/>
      <xsd:enumeration value="DV"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:complexType name="dvType">
    <xsd:sequence>
      <xsd:element name="urcall" type="callsignType"/>
      <xsd:element name="rpt1call" type="callsignType"/>
      <xsd:element name="rpt2call" type="callsignType"/>
      <xsd:element name="digitalCode" type="digitalCodeType" minOccurs="0"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:simpleType name="callsignType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[A-Z0-9/ ]*"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="digitalCodeType">
    <xsd:restriction base="xsd:integer">
      <xsd:minInclusive value="0"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="skipType">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="S"/>
      <xsd:enumeration value="P"/>
      <xsd:enumeration value=""/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:complexType name="bankInfoType">
    <xsd:attribute name="bankId" type="xsd:nonNegativeInteger" use="required"/>
    <xsd:attribute name="bankIndex" type="xsd:nonNegativeInteger"/>
  </xsd:complexType>
  
</xsd:schema>
