
      SUBROUTINE mklnid(xlo, xhi, ylo, yhi, ktval, emlim, z, maxcmd, 
     &                  cmd, ncmd, labno, status)

      INTEGER maxcmd, ncmd, labno, status
      REAL ktval, emlim, z, xlo, xhi, ylo, yhi
      CHARACTER*(*) cmd(maxcmd)

c Subroutine to set up Label commands to write line identification labels.
c Works by calling the GTAPLN routine then converting the output.

c Arguments :
c      xlo       r         i: Low end of x-axis
c      xhi       r         i: High end of x-axis
c      ylo       r         i: Low end of y-axis
c      yhi       r         i: High end of y-axis
c      ktval     r         i: Temperature
c      emlim     r         i: Emission limit
c      z         r         i: Redshift for lines
c      maxcmd    i         i: Size of CMD array
c      cmd       c*(*)   i/o: Array of QDP commands
c      ncmd      i       i/o: Current number of QDP commands
c      labno     i       i/o: Current QDP label number
c      status    i         o: 0==OK

      REAL center, delta, zfact, pos
      INTEGER nlines, i

      CHARACTER retstr*7000, string*70, label*8, cpos*8
      LOGICAL qwave

      INTEGER lenact
      CHARACTER*4 xpgxop
      EXTERNAL lenact, xpgxop

c Find out whether we have wavelengths

      qwave = .FALSE.
      IF ( xpgxop() .EQ. 'wave' ) qwave = .TRUE.

c Find the line IDs

      zfact = 1. + z
      IF ( qwave ) THEN
         center = 0.5*(xlo+xhi) / Zfact
         delta  = 0.5*(xhi-xlo) / Zfact
      ELSE
         center = 0.5*(xlo+xhi) * Zfact
         delta  = 0.5*(xhi-xlo) * Zfact
      ENDIF

      CALL gtapln(center, delta, ktval, emlim, qwave, retstr, status)
      IF ( status .NE. 0 ) RETURN

c The output string has 70 characters for each line

      nlines = (LENACT(retstr)+1)/70
      nlines = MIN(nlines, MAXCMD-ncmd)

      DO i = 1, nlines

c PLT allows 60 numbered labels. If we end up with more than 55
c write a warning and end the loop (we leave 5 labels for other uses).

         IF ( labno .GT. 55 ) THEN
            CALL xwrite(
     &         'Too many labels for PLT - truncating after 55 lines', 5)
            GOTO 100
         ENDIF

         string = retstr(1+(i-1)*70:i*70)
         label = string(36:43)

         labno = labno + 1
         ncmd = ncmd + 1

         READ(string(23:30),*) pos
         IF ( qwave ) THEN
            pos = pos * Zfact
         ELSE
            pos = pos / Zfact
         ENDIF
         WRITE(cpos,'(f8.4)') pos

         WRITE(cmd(ncmd), '(a3,i3,a5,a8,1x,1pe10.3,a15,a1,a8,a1)')
     &     'LA ', labno, ' POS ', cpos, 
     &     (yhi-0.1*(yhi-ylo)), ' JUST L ROT 90 ', '"', label, 
     &     '"'

      ENDDO

 100  CONTINUE

      RETURN
      END








