!
! $Id$
!
Write (6,*) "      ---> inc/startXML/subscanListSubscansXML.f90 "
Write (6,*) "iiSegment:            ", iiSegment
Write (6,*) "number of segments:   ", nSegments
!
Call pakoXMLwriteStartElement("RESOURCE","subscans",                  &
     &                         comment="generated by paKo",           &
     &                         space ="before",                       &
     &                         error=errorXML)
!
inOtfSubscan = .False.
!
Do ii = 1,nSegments, 1
   !
!D    Write (6,*) ' Segment #:   ', ii
!D    Write (6,*) ' newsubscan:  ', segList(ii)%newSubscan
!D    Write (6,*) segList(ii)%ssType
   !
   If      (segList(ii)%ssType .Eq. ss%cc) Then
      Include 'inc/startXML/segCalColdXML.inc'
      !
   Else If (segList(ii)%ssType .Eq. ss%ca) Then
      Include 'inc/startXML/segCalAmbientXML.inc'
      !
   Else If (segList(ii)%ssType .Eq. ss%cs) Then
      Include 'inc/startXML/segCalSkyXML.inc'
      !
   Else If (segList(ii)%ssType.Eq.ss%on .And.                          &
        &       segList(ii)%segType.Eq.seg%track) Then
      Write (messageText,*)  "  subscan #:   ", ii," ",        &
           &        segList(ii)%ssType," ", segList(ii)%segType," ",segList(ii)%pStart
      Call pakoMESSAGE(priorityI,severityI,"OnOff Start",messageText)
      Include 'inc/startXML/trackXML.inc'
   Else If (segList(ii)%ssType.Eq.ss%ref .And.                          &
        &       segList(ii)%segType.Eq.seg%track) Then
      Write (messageText,*)  "  subscan #:   ", ii," ",        &
           &        segList(ii)%ssType," ", segList(ii)%segType," ",segList(ii)%pStart
      Call pakoMESSAGE(priorityI,severityI,"OnOff Start",messageText)
      Include 'inc/startXML/trackXML.inc'
   End If
   !
   ! ***    OTF subscan
   If (segList(ii)%ssType.Eq.ss%otf) Then
      !
      ! ***       start of OTF subscan
      If (segList(ii)%newSubscan) Then
         inOtfSubscan = .True.
         Call pakoXMLwriteStartElement("RESOURCE","subscan",          &
              &                         error=errorXML)
         valueC = segList(ii)%ssType
         Call pakoXMLcase(valueC,error=errorXML)
         If (valueC.Eq."OTF") valueC="onTheFly"
         Call pakoXMLwriteElement("PARAM","type",valueC,              &
              &                         dataType="char",              &
              &                         error=errorXML)
         valueC = segList(ii)%systemName
         Call pakoXMLcase(valueC,error=errorXML)
         If (valueC.Eq."horizontalT") valueC="horizontalTrue"
         Call pakoXMLwriteElement("PARAM","systemOffset",valueC,      &
              &                         dataType="char",              &
              &                         error=errorXML)
         ! TBD:     Write (valueC,*) segList(ii)%tRecord
         ! TBD:     Call pakoXMLwriteElement("PARAM","tRecord",valueC,&
         ! TBD:  &                  dataType="char",                  &
         ! TBD:  &                  error=errorXML)
         Call pakoXMLwriteStartElement("RESOURCE","segments",         &
              &                         error=errorXML)
      End If
      !
      ! ***       OTF segments
      If (segList(ii)%ssType.Eq.ss%otf .And.                          &
           &       segList(ii)%segType.Eq.seg%track) Then
         Include 'inc/startXML/segTrackXML.inc'
      End If
      !
      If (segList(ii)%ssType.Eq.ss%otf .And.                          &
           &       segList(ii)%segType.Eq.seg%linear) Then
         Include 'inc/startXML/segLinearXML.inc'
      End If
      !
      If (segList(ii)%ssType.Eq.ss%otf .And.                          &
           &       segList(ii)%segType.Eq.seg%circle) Then
         Include 'inc/startXML/segCircleXML.inc'
      End If
      !
      If (segList(ii)%ssType.Eq.ss%otf .And.                          &
           &       segList(ii)%segType.Eq.seg%curve) Then
         Include 'inc/startXML/segCurveXML.inc'
      End If
      !
      ! ***       end of OTF subscan
      If (ii.Eq.iiSegment .Or.                                        &
           &  ii.Lt.iiSegment .And. segList(ii+1)%newSubscan) Then
         Call pakoXMLwriteEndElement("RESOURCE","segments",           &
              &                         error=errorXML)
         Call pakoXMLwriteEndElement("RESOURCE","subscan",            &
              &                         error=errorXML)
         inOtfSubscan = .False.
      End If
      !
   End If
   !
End Do
!
Call pakoXMLwriteEndElement("RESOURCE","subscans",                    &
     &                         error=errorXML)
!
