C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LDM_WRITE        **
C**************************
C
CD-Routine: Write LDM Parameters Data - LDM_WRITE
C This is used to write out the current LDM parameters data to a data file
C or to a terminal. The data may be listed in different degrees of detail 
C though any non-default parameter values are always written. A special option 
C is available for use, in conjunction with the routines LDM_CH_RESET and
C LDM_ANY_CH, to write out parameter values changed since a flag was set
C at a particular point in a program.
CD-end
CD-Fortran:
      SUBROUTINE LDM_WRITE (IUNOUT, IOPTYP)
CD-end
      INCLUDE 'implicit_none.finc'
C
C Purpose: 
C
C Author:  John W. Campbell, June 1993
C
C Arguments:
C
      INTEGER IUNOUT
      INTEGER IOPTYP

CD-Parameters:
C IUNOUT  i (R)   Unit number for output (if <0 then terminal output is 
C                 required on unit -IUNOUT)
C IOPTYP  i (R)   Type of output = 1 minimum, do not o/p parameters with 
C                                    default values
C                                = 2 standard output (selected parameters
C                                    with default values will be included)
C                                = 3 full (all parameters will be included)     
C                                = 4 all individual values given for 
C                                    plate/pack parameters.
C                                < 0 write changed parameter values since 
C                                    last reset of flag for channel 
C                                    -IOPTYP (1-16) (see LDM_CH_RESET)
CD-end
C
C====== Parameter statements
C 

C
C====== GLOBALS:
C
      INCLUDE 'ldm_data.finc'
      INCLUDE 'ldm_extended.finc'
      EXTERNAL LDM_BDAT
C
C====== FUNCTION TYPES:
C
      INTEGER LENSTR
      INTEGER KDMSTR
      LOGICAL LDM_SAME_PK
      LOGICAL LDM_SAME_PL
      LOGICAL LDM_SAME_SPD
      EXTERNAL LDM_OPFUN
C
C====== LOCALS:
C
      LOGICAL CHANGES
      LOGICAL TERM
      LOGICAL DFINC
      LOGICAL DF
      LOGICAL PRDF
      LOGICAL SAME
      LOGICAL OPSYM
      INTEGER I
      INTEGER J
      INTEGER IOP
      INTEGER IUN
      INTEGER ICHAN
      INTEGER LL
      INTEGER II
      INTEGER IVAL
      INTEGER ND
      INTEGER IERR
      INTEGER ISPAC
      INTEGER IFLAG
      INTEGER ITYP
      INTEGER IFIDS
      INTEGER IDISTOR
      INTEGER IMTT       
      INTEGER NPK
      INTEGER NPL
      INTEGER IPK1
      INTEGER IPK2
      INTEGER NSPDX
      INTEGER NSPDY
      INTEGER ICOEFF
      INTEGER ICHANGED
      INTEGER IREDUCE
      INTEGER IP
      INTEGER KERR
      INTEGER NUM_EXT
      INTEGER NSS(LDM_MAXPK)
      REAL VALUE
      REAL EP
      REAL SPACT
      REAL DDSPIN
      REAL SPIN1
      REAL SPIN2
      REAL CTOF1
      REAL CTOF2
      REAL SVAL(LDM_MAXSPD)
      CHARACTER*120 VALSTR
      CHARACTER*1 ERRSTR
      CHARACTER*80 STR
      CHARACTER*80 LIN
      CHARACTER*20 KEYWORD
     
C     LOGICAL CHANGES         !Write changed parameter values flag
C     LOGICAL TERM            !Terminal o/p flag
C     LOGICAL DFINC           !Default increments only flag
C     LOGICAL DF              !Default values only flag
C     LOGICAL PRDF            !Print default values flag
C     LOGICAL SAME            !Check for same values
C     LOGICAL OPSYM           !Output symmetry flag
C     INTEGER I               !Temp/loop variable
C     INTEGER J               !Temp/loop variable
C     INTEGER IOP             !Write option = 1 Non-default or changed values
C                                           = 2 standard selection of values
C                                           = 3 all parameters
C                                           = 4 all parameters and all 
C                                               individual pack/plate parameters
C     INTEGER IUN             !Unit no. for o/p
C     INTEGER ICHAN           !Channel no. for changes (0 if none)
C     INTEGER LL              !Length (significant) of a character string
C     INTEGER II              !Length (significant) of a character string
C     INTEGER IVAL            !Integer parameter value
C     INTEGER ND              !No. of decimal places flag
C     INTEGER IERR            !Error flag
C     INTEGER ISPAC           !Spaces before next item
C     INTEGER IFLAG           !Parameter value status flag
C     INTEGER ITYP            !Parameter value type flag
C     INTEGER IFIDS           !Fid type =0 no = 1 yes
C     INTEGER IDISTOR         !Distortion type 1=std, 2=roff/toff, 3=spdxy
C     INTEGER IMTT            !Image type 1=film , 2=ip
C     INTEGER NPK             !No. of packs (set to 1 if no packs)
C     INTEGER NPL             !No. of plates
C     INTEGER IPK1            !Temp store of pack number
C     INTEGER IPK2            !Temp store of pack number
C     INTEGER NSPDX           !Polynomial order for spdx
C     INTEGER NSPDY           !Polynomial order for spdy
C     INTEGER ICOEFF          !Polynomial term power
C     INTEGER ICHANGED        !Changed flag for extended parameters
C     INTEGER IREDUCE         !Reduced o/p flag for extended parameters
C     INTEGER IP              !Extended parameters loop counter
C     INTEGER KERR            !Error flag
C     INTEGER NUM_EXT         !No. of extra parameters in extended LDM
C     INTEGER NSS(LDM_MAXPK)  !Array of nos. of plates/pack for KDMF_OUTPUT
C     REAL VALUE              !Parameter value (real)
C     REAL EP                 !Small value for equality checks
C     REAL SPACT              !Temp value of plate spacing
C     REAL DDSPIN             !Temp value of DSPIN parameter
C     REAL SPIN1              !Temp spindle value
C     REAL SPIN2              !Temp spindle value
C     REAL CTOF1              !Temp ctof value
C     REAL CTOF2              !Temp ctof value
C     REAL SVAL(LDM_MAXSPD)   !SPDX,SPDY coefficients
C     CHARACTER*120 VALSTR    !Parameter value string
C     CHARACTER*1 ERRSTR      !Error string (dummy)
C     CHARACTER*80 STR        !String for output line or temp string
C     CHARACTER*80 LIN        !String for output line
C     CHARACTER*20 KEYWORD    !Keyword string
C
C-------------------------------------------------------------------------------
C
C===== Initialisations
C
      IF (IOPTYP.GT.0) THEN
         CHANGES = .FALSE.
         ICHAN = 0
         IOP = IOPTYP
      ELSE
         CHANGES = .TRUE.
         ICHAN = -IOPTYP
         IOP = 1
         IF (ICHAN.LT.1.OR.ICHAN.GT.16) RETURN
      END IF
      IF (IUNOUT.GT.0) THEN
         IUN = IUNOUT
         TERM = .FALSE.
      ELSE
         IUN = -IUNOUT
         TERM = .TRUE.
      END IF
C
C===== CRYSTAL
C
      CALL LDM_GET ('CRYSTAL', 0, 0, VALSTR, VALUE, ND, IVAL, 
     +               IFLAG, ITYP, IERR, ERRSTR)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_CRYST, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0) THEN
         LL = LENSTR(VALSTR)
         IF (TERM) THEN
            WRITE (IUN,1000) 'CRYSTAL '//VALSTR(1:LL)
         ELSE
            STR = 'CRYSTAL '//VALSTR(1:LL)
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         END IF
      END IF
C
C====== TITLE
C
      CALL LDM_GET ('TITLE', 0, 0, VALSTR, VALUE, ND, IVAL, 
     +               IFLAG, ITYP, IERR, ERRSTR)
      IF (CHANGES) CALL LDM_CHANGED(ICHAN, CH_TITLE, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0) THEN
         LL = LENSTR(VALSTR)
         IF (LL.GT.74) THEN
            IF (TERM) THEN
               WRITE (IUN,1000) 'TITLE '//VALSTR(1:73)//'-'
               WRITE (IUN,1000) VALSTR(74:LL)
            ELSE
               STR = 'TITLE '//VALSTR(1:73)//'-'
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
               STR = VALSTR(74:LL)
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            END IF
         ELSE
            IF (TERM) THEN
               WRITE (IUN,1000) 'TITLE '//VALSTR(1:LL)
            ELSE
               STR = 'TITLE '//VALSTR(1:LL)
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            END IF
         END IF
      END IF
C
C====== SYSTEM, LATTICE
C
      STR = ' '
      ISPAC = 0
      CALL LDM_GET ('SYSTEM', 0, 0, VALSTR, VALUE,ND, IVAL, 
     +              IFLAG, ITYP, IERR, ERRSTR)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_SYST, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'SYSTEM',ISPAC)
         ISPAC = 1
         CALL STR_ADDS (STR,VALSTR,1)
      END IF
      CALL LDM_GET ('LATTICE', 0, 0, VALSTR, VALUE, ND, IVAL, 
     +              IFLAG, ITYP, IERR, ERRSTR)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_LATT, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'LATTICE',ISPAC)
         ISPAC = 1
         CALL STR_ADDS (STR,VALSTR,1)
      END IF
      IF (STR.NE.' ') THEN
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== SYMMETRY   Special case
C     
      OPSYM = .FALSE.
      IF (CHANGES) THEN
         IFLAG = 0
         CALL LDM_CHANGED (ICHAN, CH_SYMM, IFLAG)
         IF (IFLAG.GT.0) OPSYM = .TRUE.
      ELSE
         IF (IOP.GT.2.OR.IS_SYMM.GT.0) OPSYM = .TRUE.
      END IF
      IF (OPSYM) THEN
         IF (NSPGRP.GT.0.OR.SPGNAM.NE.' ') THEN
            STR = 'SYMM'
            IF (NSPGRP.GT.0) THEN
               CALL STR_ADDI (STR, NSPGRP, 1)
            ELSE
               CALL STR_ADDS (STR, SPGNAM, 1)
            END IF
            IF (TERM) THEN
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            ELSE
               WRITE(IUN,1000) STR(1:LENSTR(STR))
            END IF
         ELSE
            IF (NSYM.GT.0) THEN
               DO 10 I = 1, NSYM
                  STR = 'SYMM'
                  CALL LDM_SYMM_STR (I, STR(6:))
                  IF (TERM) THEN
                     CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
                  ELSE
                     WRITE(IUN,1000) STR(1:LENSTR(STR))
                  END IF
10             CONTINUE
            END IF
         END IF
      END IF
C
C====== BEAM_AXIS, ROTATION_AXIS
C
      STR = ' '
      ISPAC = 0
      CALL LDM_GET ('BEAM_AXIS', 0, 0, VALSTR, VALUE, ND, IVAL, 
     +              IFLAG, ITYP, IERR, ERRSTR)       
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_BEAM, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'BEAM_AXIS',ISPAC)
         ISPAC = 1
         CALL STR_ADDS (STR,VALSTR,1)
      END IF
      CALL LDM_GET ('ROTATION_AXIS', 0, 0, VALSTR, VALUE, ND, IVAL, 
     +               IFLAG, ITYP, IERR, ERRSTR)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_ROT, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'ROTATION_AXIS',ISPAC)
         ISPAC = 1
         CALL STR_ADDS (STR,VALSTR,1)
      END IF
      IF (STR.NE.' ') THEN
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C===== IMAGE_TYPE
C
      CALL LDM_GET ('IMAGE_TYPE', 0, 0, VALSTR, VALUE, ND, IMTT,
     +               IFLAG, ITYP, IERR, ERRSTR)      
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_IMTYP, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         LL = LENSTR(VALSTR)
         STR = 'IMAGE_TYPE '//VALSTR(1:LL)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C===== IMAGE_DATA
C
      CALL LDM_GET ('IMAGE_DATA', 0, 0, VALSTR, VALUE, ND, IVAL,
     +               IFLAG, ITYP, IERR, ERRSTR)      
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_IMDAT, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         LL = LENSTR(VALSTR)
         STR = 'IMAGE_DATA '//VALSTR(1:LL)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C===== DGEOM
C
      CALL LDM_GET ('DGEOM', 0, 0, VALSTR, VALUE, ND, IVAL,
     +               IFLAG, ITYP, IERR, ERRSTR)      
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_DGEOM, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         LL = LENSTR(VALSTR)
         STR = 'DGEOM '//VALSTR(1:LL)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C===== AXORD
C
      CALL LDM_GET ('AXORD', 0, 0, VALSTR, VALUE, ND, IVAL, 
     +              IFLAG, ITYP, IERR, ERRSTR)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_AXORD, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0) THEN
         LL = LENSTR(VALSTR)
         STR = 'AXORD '//VALSTR(1:LL)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C===== FIDTYPE
C
      CALL LDM_GET ('FIDTYPE', 0, 0, VALSTR, VALUE, ND, IFIDS, 
     +              IFLAG, ITYP, IERR, ERRSTR)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_FIDT, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0) THEN
         LL = LENSTR(VALSTR)
         STR = 'FIDTYPE '//VALSTR(1:LL)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== FIDX1, FIDY1, FIDX2, FIDY2, FIDX3, FIDY3
C
      STR = ' '
      ISPAC = 0
      CALL LDM_GET_FIDX1 (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_FIDX1, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0.OR.(.NOT.CHANGES.AND.IFIDS.EQ.1)) THEN
         CALL STR_ADDS (STR,'FIDX1',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_FIDY1 (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_FIDY1, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0.OR.(.NOT.CHANGES.AND.IFIDS.EQ.1)) THEN         
         CALL STR_ADDS (STR,'FIDY1',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_FIDX2 (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_FIDX2, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0.OR.(.NOT.CHANGES.AND.IFIDS.EQ.1)) THEN
         CALL STR_ADDS (STR,'FIDX2',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_FIDY2 (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_FIDY2, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0.OR.(.NOT.CHANGES.AND.IFIDS.EQ.1)) THEN
         CALL STR_ADDS (STR,'FIDY2',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_FIDX3 (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_FIDX3, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0.OR.(.NOT.CHANGES.AND.IFIDS.EQ.1)) THEN
         CALL STR_ADDS (STR,'FIDX3',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_FIDY3 (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_FIDY3, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0.OR.(.NOT.CHANGES.AND.IFIDS.EQ.1)) THEN
         CALL STR_ADDS (STR,'FIDY3',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      IF (STR.NE.' ') THEN
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== NXRAST, NYRAST
C
      STR = ' '
      ISPAC = 0
      CALL LDM_GET_NXRAS (IVAL, IFLAG)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_NXRAS, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'NXRAST',ISPAC)
         ISPAC = 1
         CALL STR_ADDI (STR,IVAL, 1)
      END IF
      CALL LDM_GET_NYRAS (IVAL, IFLAG)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_NYRAS, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'NYRAST',ISPAC)
         ISPAC = 1
         CALL STR_ADDI (STR,IVAL, 1)
      END IF
      IF (STR.NE.' ') THEN
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== RASTER_SIZE
C
      CALL LDM_GET_RAST (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_RAST, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         STR = 'RASTER_SIZE'
         CALL STR_ADDF (STR, VALUE, ND, 1)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== RMIN, RMAX
C
      STR = ' '
      ISPAC = 0
      CALL LDM_GET_RMIN (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_RMIN, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'RMIN',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_RMAX (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_RMAX, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'RMAX',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      IF (STR.NE.' ') THEN
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== XLOW, XHIGH, YLOW, YHIGH
C
      STR = ' '
      ISPAC = 0
      CALL LDM_GET_XLOW (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_XLOW, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'XLOW',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_XHIGH (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_XHIGH, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'XHIGH',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_YLOW (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_YLOW, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'YLOW',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_YHIGH (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_YHIGH, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'YHIGH',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      IF (STR.NE.' ') THEN
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C===== DISTORTION_TYPE
C
      CALL LDM_GET ('DISTORTION_TYPE', 0, 0, VALSTR, VALUE, ND,
     +               IDISTOR, IFLAG, ITYP, IERR, ERRSTR)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_DSTOR, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         LL = LENSTR(VALSTR)
         STR = 'DISTORTION_TYPE '//VALSTR(1:LL)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== FTHRESH, FIDBOX, STHRESH
C
      STR = ' '
      ISPAC = 0
      CALL LDM_GET_FTHR (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_FTHR, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'FTHRESH',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_FBOX (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_FBOX, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'FIDBOX',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_STHR (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_STHR, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'STHRESH',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      IF (STR.NE.' ') THEN
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== OVERLOAD_PIXEL
C
      CALL LDM_GET_OVPIX (IVAL, IFLAG)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_OVPIX, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0) THEN
         STR = 'OVERLOAD_PIXEL'
         CALL STR_ADDI (STR, IVAL, 1)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== NUMPACK, NPLATES
C
      STR = ' '
      ISPAC = 0
      CALL LDM_GET_NUMP (IVAL, IFLAG)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_NUMP, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'NUMPACK',ISPAC)
         ISPAC = 1
         CALL STR_ADDI (STR,IVAL, 1)
      END IF
      CALL LDM_GET_NPLAT (IVAL, IFLAG)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_NPLAT, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'NPLATES',ISPAC)
         ISPAC = 1
         CALL STR_ADDI (STR,IVAL, 1)
      END IF
      IF (STR.NE.' ') THEN
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C===== TEMPLATE
C
      CALL LDM_GET ('TEMPLATE', 0, 0, VALSTR, VALUE, ND, IVAL, 
     +              IFLAG, ITYP, IERR, ERRSTR)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_TEMPL, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         LL = LENSTR(VALSTR)
         STR = 'TEMPLATE '//VALSTR(1:LL)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== SPOT_EPSILON
C
      CALL LDM_GET_EPS (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_EPS, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         STR = 'SPOT_EPSILON'
         CALL STR_ADDF (STR, VALUE, ND, 1)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== DTILT
C
      CALL LDM_GET_DTILT (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_DTILT, IFLAG)
      IF (IOP.GT.2.OR.IFLAG.GT.0) THEN
         STR = 'DTILT'
         CALL STR_ADDF (STR, VALUE, ND, 1)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== N1OD, G1OD, BASEOD, NONLINEARITY
C
      STR = ' '
      ISPAC = 0
      CALL LDM_GET_N1OD (IVAL, IFLAG)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_N1OD, IFLAG)
      IF ((IMTT.EQ.1.AND.IOP.GT.1).OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'N1OD',ISPAC)
         ISPAC = 1
         CALL STR_ADDI (STR,IVAL, 1)
      END IF
      CALL LDM_GET_G1OD (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_G1OD, IFLAG)
      IF ((IMTT.EQ.1.AND.IOP.GT.1).OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'G1OD',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_BASE (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_BASE, IFLAG)
      IF ((IMTT.EQ.1.AND.IOP.GT.1).OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'BASEOD',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_NONL (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_NONL, IFLAG)
      IF ((IMTT.EQ.1.AND.IOP.GT.1).OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'NONLINEARITY',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      IF (STR.NE.' ') THEN
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== Assume minimum of 1 pack for pack/plate params
C
      CALL LDM_GET_NUMP (NPK, IFLAG)
      IF (NPK.LT.1) NPK = 1
      CALL LDM_GET_NPLAT (NPL, IFLAG)
C
C====== DSPIN   
C
      CALL LDM_GET_DSPIN (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_DSPIN, IFLAG)
      IF ((NPK.GT.1.AND.IOP.GT.1).OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
         STR = 'DSPIN'
         CALL STR_ADDF (STR, VALUE, ND, 1)
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== SPINDLE  Note: Special treatment because of DSPIN increment of
C                      globally input values
C
      DFINC = .TRUE.
      IF (NPK.GT.1.AND..NOT.CHANGES) THEN
         CALL LDM_GET_DSPIN (DDSPIN, IFLAG, ND)
         EP = 1.0E-04
         DFINC = .TRUE.
         DO 100 I = 2, NPK
            CALL LDM_GET_SPIN (I, SPIN2, IFLAG, ND, IERR, ERRSTR)
            CALL LDM_GET_SPIN (I-1, SPIN1, IFLAG, ND, IERR, ERRSTR)
            IF (ABS((SPIN2-SPIN1)-DDSPIN).GT.EP) DFINC = .FALSE.
100      CONTINUE
      END IF
      IF (DFINC.AND.IOP.NE.4.AND..NOT.CHANGES) THEN
         CALL LDM_GET_SPIN (1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            STR = 'SPINDLE'
            CALL STR_ADDF (STR, VALUE, ND, 1)
            IF (TERM) THEN
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            ELSE
               WRITE(IUN,1000) STR(1:LENSTR(STR))
            END IF
         END IF
      ELSE
         LIN = ' '
         DO 110 I = 1, NPK
            CALL LDM_GET_SPIN (I, VALUE, IFLAG, ND, 
     +                            IERR, ERRSTR)
            IF (CHANGES) THEN
               CALL LDM_CHANGED (ICHAN, CH_SPIN(I), IFLAG)
               IF (IFLAG.EQ.0) GO TO 110
            END IF
            STR = 'SPINDLE['
            CALL STR_ADDI (STR, I, 0)
            CALL STR_ADDS (STR, ']',0)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
110      CONTINUE
         IF (LIN.NE.' ') THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,LIN(1:LENSTR(LIN)),1)
            ELSE
               WRITE(IUN,1000) LIN(1:LENSTR(LIN))
            END IF
         END IF
      END IF
C
C====== PACK_ID  (Note: Special treatment because of auto-incrementing on
C                       global input)
C
      DFINC = .TRUE.
      IF (NPK.GT.1.AND..NOT.CHANGES) THEN
         DFINC = .TRUE.
         DO 120 I = 2, NPK
            CALL LDM_GET_PID (I, IPK2, IFLAG, IERR, ERRSTR)
            CALL LDM_GET_PID (I-1, IPK1, IFLAG, IERR, ERRSTR)
            IF (IPK2-IPK1.NE.1) DFINC = .FALSE.
120      CONTINUE
      END IF
      IF (DFINC.AND.IOP.NE.4.AND..NOT.CHANGES) THEN
         CALL LDM_GET_PID (1, IVAL, IFLAG, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            STR = 'PACK_ID'
            CALL STR_ADDI (STR, IVAL, 1)
            IF (TERM) THEN
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            ELSE
               WRITE(IUN,1000) STR(1:LENSTR(STR))
            END IF
         END IF
      ELSE
         LIN = ' '
         DO 130 I = 1, NPK
            CALL LDM_GET_PID (I, IVAL, IFLAG, IERR, ERRSTR)
            IF (CHANGES) THEN
               CALL LDM_CHANGED (ICHAN, CH_PID(I), IFLAG)
               IF (IFLAG.EQ.0) GO TO 130
            END IF
            STR = 'PACK_ID['
            CALL STR_ADDI (STR, I, 0)
            CALL STR_ADDS (STR, ']',0)
            CALL STR_ADDI (STR, IVAL, 1)
            CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
130      CONTINUE
         IF (LIN.NE.' ') THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,LIN(1:LENSTR(LIN)),1)
            ELSE
               WRITE(IUN,1000) LIN(1:LENSTR(LIN))
            END IF
         END IF
      END IF
C
C====== Key plate
C
      PRDF = .FALSE.
      IF (IOP.GT.2) PRDF = .TRUE.
      CALL LDM_WRI_PK (IUNOUT, 'KEYPLATE', CH_KEYP, NPK, PRDF, IOPTYP)
C
C====== FILENAME
C
      DF = .TRUE.
      IF (.NOT.CHANGES) THEN
         DO 150 I = 1, NPK
            DO 140 J = 1, NPL
               CALL LDM_GET_FNAME (I, J, VALSTR, IFLAG, IERR, ERRSTR)
               IF (IFLAG.GT.0) DF = .FALSE.
140         CONTINUE
150      CONTINUE
      END IF
      IF (DF.AND..NOT.CHANGES) THEN
         IF (IOP.EQ.3) THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,'FILENAME',1)
            ELSE
               WRITE(IUN,1000) 'FILENAME'
            END IF
         END IF
      ELSE
         DO 170 I = 1, NPK
            DO 160 J = 1, NPL
               CALL LDM_GET_FNAME (I, J, VALSTR, IFLAG, IERR, ERRSTR)
               IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_FNAME(I,J), 
     +                                        IFLAG)
               IF (IOP.GT.3.OR.IFLAG.GT.0) THEN
                  LL = LENSTR(VALSTR)
                  STR = 'FILENAME['
                  CALL STR_ADDI (STR, I, 0)
                  CALL STR_ADDS (STR, ']', 0)
                  CALL STR_ADDS (STR, '[', 0)
                  CALL STR_ADDI (STR, J, 0)
                  CALL STR_ADDS (STR, ']', 0)
                  II = LENSTR(STR)
                  IF (LL.GT.80-II-1) THEN
                     STR = 'FILENAME '//VALSTR(1:80-II-2)//'-'
                     IF (TERM) THEN
                        CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
                     ELSE
                        WRITE(IUN,1000) STR(1:LENSTR(STR))
                     END IF
                     STR = VALSTR(80-II-1:LL)
                     IF (TERM) THEN
                        CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
                     ELSE
                        WRITE(IUN,1000) STR(1:LENSTR(STR))
                     END IF
                  ELSE
                     CALL STR_ADDS (STR,VALSTR,1)
                     IF (TERM) THEN
                        CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
                     ELSE
                        WRITE(IUN,1000) STR(1:LENSTR(STR))
                     END IF
                  END IF
               END IF
160         CONTINUE
170      CONTINUE
      END IF
C
C====== X_CEN_F, Y_CEN_F
C            
      IF ((LDM_SAME_PL('X_CEN_F', NPK, NPL).AND.
     +    LDM_SAME_PL('Y_CEN_F', NPK, NPL).AND.IOP.NE.4)
     +    .AND..NOT.CHANGES) THEN
         STR = ' '
         ISPAC = 0
         CALL LDM_GET_XCENF (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'X_CEN_F', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_YCENF (1, 1,VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'Y_CEN_F', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         IF (STR.NE.' ') THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            ELSE
               WRITE(IUN,1000) STR(1:LENSTR(STR))
            END IF
         END IF
      ELSE
         PRDF = .FALSE.
         IF (IOP.GT.1) PRDF = .TRUE.
         CALL LDM_WRF_PL (IUNOUT, 'X_CEN_F', CH_XCENF, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
         CALL LDM_WRF_PL (IUNOUT, 'Y_CEN_F', CH_YCENF, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
      END IF
C
C====== SPACING
C
      PRDF = .FALSE.
      IF (IOP.GT.2.OR.(NPL.GT.1.AND.IOP.GT.1)) PRDF = .TRUE.
      CALL LDM_WRF_PL (IUNOUT, 'SPACING', CH_SPAC, LDM_MAXPK,
     +                 NPK, NPL, PRDF, IOPTYP)
C
C====== A, B, C, ALPHA, BETA, GAMMA
C
      STR = ' '
      ISPAC = 0
      CALL LDM_GET_A (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_A, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'A',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_B (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_B, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'B',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_C (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_C, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'C',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_ALPHA (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_ALPHA, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'ALPHA',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_BETA (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_BETA, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'BETA',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      CALL LDM_GET_GAMMA (VALUE, IFLAG, ND)
      IF (CHANGES) CALL LDM_CHANGED (ICHAN, CH_GAMMA, IFLAG)
      IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
         CALL STR_ADDS (STR,'GAMMA',ISPAC)
         ISPAC = 1
         CALL STR_ADDF (STR,VALUE, ND, 1)
      END IF
      IF (STR.NE.' ') THEN
         IF (TERM) THEN
            CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
         ELSE
            WRITE(IUN,1000) STR(1:LENSTR(STR))
         END IF
      END IF
C
C====== LMIN, LMAX, DMIN
C
      IF ((LDM_SAME_PK('LMIN', NPK).AND.
     +    LDM_SAME_PK('LMAX', NPK).AND.
     +    LDM_SAME_PK('DMIN', NPK).AND.IOP.NE.4)
     +    .AND..NOT.CHANGES) THEN
         STR = ' '
         ISPAC = 0
         CALL LDM_GET_LMIN (1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'LMIN', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_LMAX (1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'LMAX', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_DMIN (1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'DMIN', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         IF (STR.NE.' ') THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            ELSE
               WRITE(IUN,1000) STR(1:LENSTR(STR))
            END IF
         END IF
      ELSE
         PRDF = .FALSE.
         IF (IOP.GT.1) PRDF = .TRUE.
         CALL LDM_WRF_PK (IUNOUT, 'LMIN', CH_LMIN, NPK, PRDF, IOPTYP)
         CALL LDM_WRF_PK (IUNOUT, 'LMAX', CH_LMAX, NPK, PRDF, IOPTYP)
         CALL LDM_WRF_PK (IUNOUT, 'DMIN', CH_DMIN, NPK, PRDF, IOPTYP)
      END IF
C
C====== PHIX, PHIY, PHIZ
C
      IF ((LDM_SAME_PK('PHIX', NPK).AND.
     +    LDM_SAME_PK('PHIY', NPK).AND.
     +    LDM_SAME_PK('PHIZ', NPK).AND.IOP.NE.4)
     +    .AND..NOT.CHANGES) THEN
         STR = ' '
         ISPAC = 0
         CALL LDM_GET_PHIX (1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'PHIX', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_PHIY (1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'PHIY', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_PHIZ (1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'PHIZ', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         IF (STR.NE.' ') THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            ELSE
               WRITE(IUN,1000) STR(1:LENSTR(STR))
            END IF
         END IF
      ELSE
         PRDF = .FALSE.
         IF (IOP.GT.1) PRDF = .TRUE.
         CALL LDM_WRF_PK (IUNOUT, 'PHIX', CH_PHIX, NPK, PRDF, IOPTYP)
         CALL LDM_WRF_PK (IUNOUT, 'PHIY', CH_PHIY, NPK, PRDF, IOPTYP)
         CALL LDM_WRF_PK (IUNOUT, 'PHIZ', CH_PHIZ, NPK, PRDF, IOPTYP)
      END IF
C
C====== CTOF Note: Special treatment because of 'SPACING' values increments
C                  for globally input values
C       
      DFINC = .TRUE.
      SAME = .TRUE.
      IF ((NPK.GT.1.OR.NPL.GT.1).AND..NOT.CHANGES) THEN
         EP = 1.0E-04
         DFINC = .TRUE.
         SAME = .TRUE.
         CALL LDM_GET_CTOF (1, 1, CTOF1, IFLAG, ND, IERR, ERRSTR)
         IF (NPK.GT.0) THEN
            DO 175 I = 2, NPK
               CALL LDM_GET_CTOF (I, 1, CTOF2, IFLAG, ND, IERR, 
     +                            ERRSTR)
            IF (ABS(CTOF2-CTOF1).GT.EP) SAME = .FALSE.
175         CONTINUE
         END IF
         EP = 1.0E-04
         IF (SAME) THEN
            DO 190 I = 1, NPK
               DO 180 J = 2, NPL
                  CALL LDM_GET_SPAC (I, J, SPACT, IFLAG, ND, 
     +                                  IERR, ERRSTR)
                  CALL LDM_GET_CTOF (I, J, CTOF2, IFLAG, ND, IERR, 
     +                               ERRSTR)
                  CALL LDM_GET_CTOF (I, J-1, CTOF1, IFLAG, ND, 
     +                                  IERR, ERRSTR)
                  IF (ABS((CTOF2-CTOF1)-SPACT).GT.EP) DFINC = .FALSE.
180            CONTINUE
190         CONTINUE
         END IF
      END IF
      IF (SAME.AND.DFINC.AND.IOP.NE.4.AND..NOT.CHANGES) THEN
         CALL LDM_GET_CTOF (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            STR = 'CTOF'
            CALL STR_ADDF (STR, VALUE, ND, 1)
            IF (TERM) THEN
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            ELSE
               WRITE(IUN,1000) STR(1:LENSTR(STR))
            END IF
         END IF
      ELSE
         DO 230 I = 1, NPK
            DFINC = .TRUE.
            EP = 1.0E-09
            IF (NPL.GT.1.AND..NOT.CHANGES) THEN
               DO 200 J = 2, NPL
                  CALL LDM_GET_SPAC (I, J, SPACT, IFLAG, ND, 
     +                               IERR, ERRSTR)
                  CALL LDM_GET_CTOF (I, J, CTOF2, IFLAG, ND, IERR, 
     +                               ERRSTR)
                  CALL LDM_GET_CTOF (I, J-1, CTOF1, IFLAG, ND, 
     +                               IERR, ERRSTR)
                  IF (ABS((CTOF2-CTOF1)-SPACT).GT.EP) DFINC = .FALSE.
200            CONTINUE
            END IF
            IF (DFINC.AND.IOP.NE.4.AND..NOT.CHANGES) THEN
               CALL LDM_GET_CTOF (I, 1, VALUE, IFLAG, ND, 
     +                               IERR, ERRSTR)
               STR = 'CTOF['
               CALL STR_ADDI (STR,I,0)
               CALL STR_ADDS (STR,']',0)
               CALL STR_ADDF (STR, VALUE, ND, 1)
               IF (TERM) THEN
                  CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
               ELSE
                  WRITE(IUN,1000) STR(1:LENSTR(STR))
               END IF
            ELSE
               LIN = ' '
               DO 210 J = 1, NPL
                  CALL LDM_GET_CTOF (I, J, VALUE, IFLAG, ND, 
     +                               IERR, ERRSTR)
                  IF (CHANGES) THEN
                     CALL LDM_CHANGED (ICHAN, CH_CTOF(I,J), IFLAG)
                     IF (IFLAG.EQ.0) GO TO 210
                  END IF
                  STR = 'CTOF['
                  CALL STR_ADDI (STR, I, 0)
                  CALL STR_ADDS (STR, ']',0)
                  CALL STR_ADDS (STR, '[',0)
                  CALL STR_ADDI (STR, J, 0)
                  CALL STR_ADDS (STR,']',0)
                  CALL STR_ADDF (STR, VALUE, ND, 1)
                  CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
210            CONTINUE
               IF (LIN.NE.' ') THEN
                  IF (TERM) THEN
                     CALL TTSEND (IUN,LIN(1:LENSTR(LIN)),1)
                  ELSE
                     WRITE(IUN,1000) LIN(1:LENSTR(LIN))
                  END IF
               END IF
            END IF
230      CONTINUE
      END IF
C
C====== Y_SCALE
C            
      PRDF = .FALSE.
      IF (IOP.GT.1) PRDF = .TRUE.
      CALL LDM_WRF_PL (IUNOUT, 'Y_SCALE', CH_YSCAL, LDM_MAXPK,
     +                 NPK, NPL, PRDF, IOPTYP)
C
C====== SPOT_LENGTH, SPOT_WIDTH, SPOT_FACTOR, SPOT_BORDER
C            
      IF ((LDM_SAME_PL('SPOT_LENGTH', NPK, NPL).AND.
     +    LDM_SAME_PL('SPOT_WIDTH', NPK, NPL).AND.
     +    LDM_SAME_PL('SPOT_FACTOR', NPK, NPL).AND.
     +    LDM_SAME_PL('SPOT_BORDER', NPK, NPL).AND.IOP.NE.4)
     +    .AND..NOT.CHANGES) THEN
         STR = ' '
         ISPAC = 0
         CALL LDM_GET_SPOTL (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'SPOT_LENGTH', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_SPOTW (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'SPOT_WIDTH', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_SPOTF (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'SPOT_FACTOR', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_SPOTB (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'SPOT_BORDER', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         IF (STR.NE.' ') THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            ELSE
               WRITE(IUN,1000) STR(1:LENSTR(STR))
            END IF
         END IF
      ELSE
         PRDF = .FALSE.
         IF (IOP.GT.1) PRDF = .TRUE.
         CALL LDM_WRF_PL (IUNOUT, 'SPOT_LENGTH', CH_SPOTL, LDM_MAXPK, 
     +                    NPK, NPL, PRDF, IOPTYP)
         CALL LDM_WRF_PL (IUNOUT, 'SPOT_WIDTH', CH_SPOTW, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
         CALL LDM_WRF_PL (IUNOUT, 'SPOT_FACTOR', CH_SPOTF, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
         CALL LDM_WRF_PL (IUNOUT, 'SPOT_BORDER', CH_SPOTB, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
      END IF
C
C====== SPOT_DELTA
C
      PRDF = .FALSE.
      IF (IOP.GT.1) PRDF = .TRUE.
      CALL LDM_WRF_PL (IUNOUT, 'SPOT_DELTA', CH_SPOTD, LDM_MAXPK,
     +                 NPK, NPL, PRDF, IOPTYP)
C
C====== X_C, Y_C, W_C
C            
      IF ((LDM_SAME_PL('X_C', NPK, NPL).AND.
     +    LDM_SAME_PL('Y_C', NPK, NPL).AND.
     +    LDM_SAME_PL('W_C', NPK, NPL).AND.IOP.NE.4)
     +    .AND..NOT.CHANGES) THEN
         STR = ' '
         ISPAC = 0
         CALL LDM_GET_XC (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'X_C', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_YC (1, 1,VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'Y_C', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_WC (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'W_C', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         IF (STR.NE.' ') THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            ELSE
               WRITE(IUN,1000) STR(1:LENSTR(STR))
            END IF
         END IF
      ELSE
         PRDF = .FALSE.
         IF (IOP.GT.1) PRDF = .TRUE.
         CALL LDM_WRF_PL (IUNOUT, 'X_C', CH_XC, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
         CALL LDM_WRF_PL (IUNOUT, 'Y_C', CH_YC, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
         CALL LDM_WRF_PL (IUNOUT, 'W_C', CH_WC, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
      END IF
C
C====== TWIST, TILT, BULGE, ROFF, TOFF
C            
      IF ((LDM_SAME_PL('TWIST', NPK, NPL).AND.
     +    LDM_SAME_PL('TILT', NPK, NPL).AND.
     +    LDM_SAME_PL('BULGE', NPK, NPL).AND.
     +    LDM_SAME_PL('ROFF', NPK, NPL).AND.
     +    LDM_SAME_PL('TOFF', NPK, NPL).AND.IOP.NE.4)
     +    .AND..NOT.CHANGES) THEN
         STR = ' '
         ISPAC = 0
         CALL LDM_GET_TWIST (1, 1,VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'TWIST', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_TILT (1, 1,VALUE, IFLAG, ND, IERR, ERRSTR)
         IF (IOP.GT.1.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'TILT', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_BULGE (1, 1,VALUE, IFLAG, ND, IERR, ERRSTR)
         IF ((IDISTOR.EQ.1.AND.IOP.GT.1).OR.
     +        IOP.GT.2.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'BULGE', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_ROFF (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF ((IDISTOR.EQ.2.AND.IOP.GT.1).OR.
     +        IOP.GT.2.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'ROFF', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         CALL LDM_GET_TOFF (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF ((IDISTOR.EQ.2.AND.IOP.GT.1).OR.
     +        IOP.GT.2.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'TOFF', ISPAC)
            CALL STR_ADDF (STR, VALUE, ND, 1)
            ISPAC = 1
         END IF
         IF (STR.NE.' ') THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            ELSE
               WRITE(IUN,1000) STR(1:LENSTR(STR))
            END IF
         END IF
      ELSE
         PRDF = .FALSE.
         IF (IOP.GT.1) PRDF = .TRUE.
         CALL LDM_WRF_PL (IUNOUT, 'TWIST', CH_TWIST, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
         CALL LDM_WRF_PL (IUNOUT, 'TILT', CH_TILT, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
         PRDF = .FALSE.
         IF ((IDISTOR.EQ.1.AND.IOP.GT.1).OR.IOP.GT.2) PRDF = .TRUE.
         CALL LDM_WRF_PL (IUNOUT, 'BULGE', CH_BULGE, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
         PRDF = .FALSE.
         IF ((IDISTOR.EQ.2.AND.IOP.GT.1).OR.IOP.GT.2) PRDF = .TRUE.
         CALL LDM_WRF_PL (IUNOUT, 'ROFF', CH_ROFF, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
         CALL LDM_WRF_PL (IUNOUT, 'TOFF', CH_TOFF, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
      END IF
C
C====== SPDXY
C
      IF (LDM_SAME_PL('SPDXY', NPK, NPL).AND..NOT.CHANGES) THEN
         STR = ' '
         CALL LDM_GET_SPDXY (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF ((IDISTOR.EQ.3.AND.IOP.GT.1).OR.
     +        IOP.GT.2.OR.IFLAG.GT.0) THEN
            CALL STR_ADDS (STR, 'SPDXY', 0)
            CALL STR_ADDF (STR, VALUE, ND, 1)
         END IF
         IF (STR.NE.' ') THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,STR(1:LENSTR(STR)),1)
            ELSE
               WRITE(IUN,1000) STR(1:LENSTR(STR))
            END IF
         END IF
      ELSE
         PRDF = .FALSE.
         IF ((IDISTOR.EQ.3.AND.IOP.GT.1).OR.IOP.GT.2) PRDF = .TRUE.
         CALL LDM_WRF_PL (IUNOUT, 'SPDXY', CH_SPDXY, LDM_MAXPK,
     +                    NPK, NPL, PRDF, IOPTYP)
      END IF
C
C====== SPDX
C
      SAME = .TRUE.
      IF (.NOT.LDM_SAME_PL('SPDX_N', NPK, NPL)) SAME = .FALSE.
      IF (.NOT.LDM_SAME_PL('SPDX_MIN', NPK, NPL)) SAME = .FALSE.
      IF (.NOT.LDM_SAME_PL('SPDX_MAX', NPK, NPL)) SAME = .FALSE.
      DO 235 ICOEFF = 1, LDM_MAXSPD
         KEYWORD = 'SPDX'
         CALL STR_ADDI(KEYWORD,ICOEFF,0)
         IF (.NOT.LDM_SAME_PL(KEYWORD, NPK, NPL)) SAME = .FALSE.
235   CONTINUE
      IF ((SAME.AND.IOP.NE.4).AND..NOT.CHANGES) THEN
         LIN = ' '
         CALL LDM_GET_SPDXN (1, 1, IVAL, IFLAG, IERR, ERRSTR)
         NSPDX = IVAL
         IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +      .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
            STR ='SPDX_N'
            CALL STR_ADDI (STR, IVAL, 1)
            CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
         END IF
         CALL LDM_GET_SXMIN (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +      .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
            STR ='SPDX_MIN'
            CALL STR_ADDF (STR, VALUE, ND, 1)
            CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
         END IF
         CALL LDM_GET_SXMAX (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +      .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
            STR ='SPDX_MAX'
            CALL STR_ADDF (STR, VALUE, ND, 1)
            CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
         END IF
         DO 240 ICOEFF = 1, LDM_MAXSPD
            IF (ICOEFF.GT.1.AND.NSPDX.LT.ICOEFF) GO TO 240
            CALL LDM_GET_SPDX (ICOEFF, 1, 1, SVAL, IFLAG, ND, IERR, 
     +                         ERRSTR)
            IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +         .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
               STR ='SPDX'
               CALL STR_ADDI(STR,ICOEFF,0)
               CALL STR_ADDF (STR, SVAL(1), ND, 1)
               CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
            END IF
240      CONTINUE
         IF (LIN.NE.' ') THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,LIN(1:LENSTR(LIN)),1)
            ELSE
               WRITE(IUN,1000) LIN(1:LENSTR(LIN))
            END IF
         END IF
      ELSE
         DO 300 I = 1, NPK
            IF (LDM_SAME_SPD (I, 1, NPL).AND.IOP.NE.4
     +          .AND..NOT.CHANGES) THEN
               LIN = ' '
               CALL LDM_GET_SPDXN (I, 1, IVAL, IFLAG, IERR, ERRSTR)
               NSPDX = IVAL
               IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +            .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                  STR ='SPDX_N['
                  CALL STR_ADDI (STR, I, 0)
                  CALL STR_ADDS (STR, ']', 0)
                  CALL STR_ADDI (STR, IVAL, 1)
                  CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
               END IF
               CALL LDM_GET_SXMIN (I, 1, VALUE, IFLAG, ND, IERR, 
     +                               ERRSTR)
               IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +            .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                  STR ='SPDX_MIN['
                  CALL STR_ADDI (STR, I, 0)
                  CALL STR_ADDS (STR, ']', 0)
                  CALL STR_ADDF (STR, VALUE, ND, 1)
                  CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
               END IF
               CALL LDM_GET_SXMAX (I, 1, VALUE, IFLAG, ND, IERR, 
     +                               ERRSTR)
               IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +            .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                  STR ='SPDX_MAX['
                  CALL STR_ADDI (STR, I, 0)
                  CALL STR_ADDS (STR, ']', 0)
                  CALL STR_ADDF (STR, VALUE, ND, 1)
                  CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
               END IF
               DO 245 ICOEFF = 1, LDM_MAXSPD
                  IF (ICOEFF.GT.1.AND.NSPDX.LT.ICOEFF) GO TO 245
                  CALL LDM_GET_SPDX (ICOEFF, I, 1, SVAL, IFLAG, ND,
     +                                 IERR, ERRSTR)
                  IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +               .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                     STR ='SPDX'
                     CALL STR_ADDI(STR,ICOEFF,0)
                     CALL STR_ADDS(STR,'[',0)
                     CALL STR_ADDI (STR, I, 0)
                     CALL STR_ADDS (STR, ']', 0)
                     CALL STR_ADDF (STR, SVAL(1), ND, 1)
                     CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
                  END IF
245            CONTINUE
               IF (LIN.NE.' ') THEN
                  IF (TERM) THEN
                     CALL TTSEND (IUN,LIN(1:LENSTR(LIN)),1)
                  ELSE
                     WRITE(IUN,1000) LIN(1:LENSTR(LIN))
                  END IF
               END IF
            ELSE
               DO 250 J = 1, NPL
                  LIN = ' '
                  CALL LDM_GET_SPDXN (I, J, IVAL, IFLAG, IERR, ERRSTR)
                  IF (CHANGES) 
     +                CALL LDM_CHANGED (ICHAN, CH_SPDXN(I,J), IFLAG)
                  NSPDX = IVAL
                  IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +               .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                     STR ='SPDX_N['
                     CALL STR_ADDI (STR, I, 0)
                     CALL STR_ADDS (STR, '][', 0)
                     CALL STR_ADDI (STR, J, 0)
                     CALL STR_ADDS (STR,']', 0)
                     CALL STR_ADDI (STR, IVAL, 1)
                     CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
                  END IF
                  CALL LDM_GET_SXMIN (I, J, VALUE, IFLAG, ND, 
     +                                IERR, ERRSTR)
                  IF (CHANGES) 
     +                CALL LDM_CHANGED (ICHAN, CH_SPDXMIN(I,J), IFLAG)
                  IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +               .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                     STR ='SPDX_MIN['
                     CALL STR_ADDI (STR, I, 0)
                     CALL STR_ADDS (STR, '][', 0)
                     CALL STR_ADDI (STR, J, 0)
                     CALL STR_ADDS (STR,']', 0)
                     CALL STR_ADDF (STR, VALUE, ND, 1)
                     CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
                  END IF
                  CALL LDM_GET_SXMAX (I, J, VALUE, IFLAG, ND, 
     +                                IERR, ERRSTR)
                  IF (CHANGES) 
     +                CALL LDM_CHANGED (ICHAN, CH_SPDXMIN(I,J), IFLAG)
                  IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +               .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                     STR ='SPDX_MAX['
                     CALL STR_ADDI (STR, I, 0)
                     CALL STR_ADDS (STR, '][', 0)
                     CALL STR_ADDI (STR, J, 0)
                     CALL STR_ADDS (STR,']', 0)
                     CALL STR_ADDF (STR, VALUE, ND, 1)
                     CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
                  END IF
                  DO 248 ICOEFF = 1, LDM_MAXSPD
                     IF (ICOEFF.GT.1.AND.NSPDX.LT.ICOEFF) GO TO 248
                     CALL LDM_GET_SPDX (ICOEFF, I, J, SVAL, IFLAG, ND, 
     +                                IERR, ERRSTR)
                     IF (CHANGES) 
     +                   CALL LDM_CHANGED (ICHAN, CH_SPDX(I,J,ICOEFF), 
     +                                     IFLAG)
                     IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +                  .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                        STR ='SPDX'
                        CALL STR_ADDI(STR,ICOEFF,0)
                        CALL STR_ADDS(STR,'[',0)
                        CALL STR_ADDI (STR, I, 0)
                        CALL STR_ADDS (STR, '][', 0)
                        CALL STR_ADDI (STR, J, 0)
                        CALL STR_ADDS (STR,']', 0)
                        CALL STR_ADDF (STR, SVAL(1), ND, 1)
                        CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
                     END IF
248               CONTINUE
                  IF (LIN.NE.' ') THEN
                     IF (TERM) THEN
                        CALL TTSEND (IUN,LIN(1:LENSTR(LIN)),1)
                     ELSE
                        WRITE(IUN,1000) LIN(1:LENSTR(LIN))
                     END IF
                  END IF
250            CONTINUE
            END IF
300      CONTINUE
      END IF
C
C====== SPDY
C
      SAME = .TRUE.
      IF (.NOT.LDM_SAME_PL('SPDY_N', NPK, NPL)) SAME = .FALSE.
      IF (.NOT.LDM_SAME_PL('SPDY_MIN', NPK, NPL)) SAME = .FALSE.
      IF (.NOT.LDM_SAME_PL('SPDY_MAX', NPK, NPL)) SAME = .FALSE.
      DO 305 ICOEFF = 1, LDM_MAXSPD
         KEYWORD = 'SPDY'
         CALL STR_ADDI(KEYWORD,ICOEFF,0)
         IF (.NOT.LDM_SAME_PL(KEYWORD, NPK, NPL)) SAME = .FALSE.
305   CONTINUE
      IF ((SAME.AND.IOP.NE.4).AND..NOT.CHANGES) THEN
         LIN = ' '
         CALL LDM_GET_SPDYN (1, 1, IVAL, IFLAG, IERR, ERRSTR)
         NSPDY = IVAL
         IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +      .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
            STR ='SPDY_N'
            CALL STR_ADDI (STR, IVAL, 1)
            CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
         END IF
         CALL LDM_GET_SYMIN (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +      .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
            STR ='SPDY_MIN'
            CALL STR_ADDF (STR, VALUE, ND, 1)
            CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
         END IF
         CALL LDM_GET_SYMAX (1, 1, VALUE, IFLAG, ND, IERR, ERRSTR)
         IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +      .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
            STR ='SPDY_MAX'
            CALL STR_ADDF (STR, VALUE, ND, 1)
            CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
         END IF
         DO 310 ICOEFF = 1, LDM_MAXSPD
            IF (ICOEFF.GT.1.AND.NSPDY.LT.ICOEFF) GO TO 310
            CALL LDM_GET_SPDY (ICOEFF, 1, 1, SVAL, IFLAG, ND, IERR, 
     +                           ERRSTR)
            IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +         .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
               STR ='SPDY'
               CALL STR_ADDI(STR,ICOEFF,0)
               CALL STR_ADDF (STR, SVAL(1), ND, 1)
               CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
            END IF
310      CONTINUE
         IF (LIN.NE.' ') THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,LIN(1:LENSTR(LIN)),1)
            ELSE
               WRITE(IUN,1000) LIN(1:LENSTR(LIN))
            END IF
         END IF
      ELSE
         DO 400 I = 1, NPK
            IF (LDM_SAME_SPD (I, 2, NPL).AND.IOP.NE.4
     +          .AND..NOT.CHANGES) THEN
               LIN = ' '
               CALL LDM_GET_SPDYN (I, 1, IVAL, IFLAG, IERR, ERRSTR)
               NSPDY = IVAL
               IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +            .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                  STR ='SPDY_N['
                  CALL STR_ADDI (STR, I, 0)
                  CALL STR_ADDS (STR, ']', 0)
                  CALL STR_ADDI (STR, IVAL, 1)
                  CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
               END IF
               CALL LDM_GET_SYMIN (I, 1, VALUE, IFLAG, ND, IERR, 
     +                               ERRSTR)
               IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +            .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                  STR ='SPDY_MIN['
                  CALL STR_ADDI (STR, I, 0)
                  CALL STR_ADDS (STR, ']', 0)
                  CALL STR_ADDF (STR, VALUE, ND, 1)
                  CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
               END IF
               CALL LDM_GET_SYMAX (I, 1, VALUE, IFLAG, ND, IERR, 
     +                               ERRSTR)
               IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +            .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                  STR ='SPDY_MAX['
                  CALL STR_ADDI (STR, I, 0)
                  CALL STR_ADDS (STR, ']', 0)
                  CALL STR_ADDF (STR, VALUE, ND, 1)
                  CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
               END IF
               DO 320 ICOEFF = 1, LDM_MAXSPD
                  IF (ICOEFF.GT.1.AND.NSPDY.LT.ICOEFF) GO TO 320
                  CALL LDM_GET_SPDY (ICOEFF, I, 1, SVAL, IFLAG, ND, 
     +                                 IERR, ERRSTR)
                  IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +               .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                     STR ='SPDY'
                     CALL STR_ADDI(STR,ICOEFF,0)
                     CALL STR_ADDS(STR,'[',0)
                     CALL STR_ADDI (STR, I, 0)
                     CALL STR_ADDS (STR, ']', 0)
                     CALL STR_ADDF (STR, SVAL(1), ND, 1)
                     CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
                  END IF
320            CONTINUE
               IF (LIN.NE.' ') THEN
                  IF (TERM) THEN
                     CALL TTSEND (IUN,LIN(1:LENSTR(LIN)),1)
                  ELSE
                     WRITE(IUN,1000) LIN(1:LENSTR(LIN))
                  END IF
               END IF
            ELSE
               DO 350 J = 1, NPL
                  LIN = ' '
                  CALL LDM_GET_SPDYN (I, J, IVAL, IFLAG, IERR, ERRSTR)
                  IF (CHANGES) 
     +                CALL LDM_CHANGED (ICHAN, CH_SPDYN(I,J), IFLAG)
                  NSPDY = IVAL
                  IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +               .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                     STR ='SPDY_N['
                     CALL STR_ADDI (STR, I, 0)
                     CALL STR_ADDS (STR, '][', 0)
                     CALL STR_ADDI (STR, J, 0)
                     CALL STR_ADDS (STR,']', 0)
                     CALL STR_ADDI (STR, IVAL, 1)
                     CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
                  END IF
                  CALL LDM_GET_SYMIN (I, J, VALUE, IFLAG, ND, 
     +                                IERR, ERRSTR)
                  IF (CHANGES) 
     +                CALL LDM_CHANGED (ICHAN, CH_SPDYMIN(I,J), IFLAG)
                  IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +               .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                     STR ='SPDY_MIN['
                     CALL STR_ADDI (STR, I, 0)
                     CALL STR_ADDS (STR, '][', 0)
                     CALL STR_ADDI (STR, J, 0)
                     CALL STR_ADDS (STR,']', 0)
                     CALL STR_ADDF (STR, VALUE, ND, 1)
                     CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
                  END IF
                  CALL LDM_GET_SYMAX (I, J, VALUE, IFLAG, ND, 
     +                                IERR, ERRSTR)
                  IF (CHANGES) 
     +                CALL LDM_CHANGED (ICHAN, CH_SPDYMIN(I,J), IFLAG)
                  IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +               .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                     STR ='SPDY_MAX['
                     CALL STR_ADDI (STR, I, 0)
                     CALL STR_ADDS (STR, '][', 0)
                     CALL STR_ADDI (STR, J, 0)
                     CALL STR_ADDS (STR,']', 0)
                     CALL STR_ADDF (STR, VALUE, ND, 1)
                     CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
                  END IF
                  DO 330 ICOEFF = 1, LDM_MAXSPD
                     IF (ICOEFF.GT.1.AND.NSPDY.LT.ICOEFF) GO TO 330
                     CALL LDM_GET_SPDY (ICOEFF, I, J, SVAL, IFLAG,
     +                                    ND, IERR, ERRSTR)
                     IF (CHANGES) 
     +                   CALL LDM_CHANGED (ICHAN, CH_SPDY(I,J,ICOEFF), 
     +                                     IFLAG)
                     IF ((IDISTOR.EQ.3.AND.IOP.GT.1)
     +                 .OR.IOP.GT.2.OR.IFLAG.GT.0) THEN
                        STR ='SPDY'
                        CALL STR_ADDI(STR,ICOEFF,0)
                        CALL STR_ADDS(STR,'[',0)
                        CALL STR_ADDI (STR, I, 0)
                        CALL STR_ADDS (STR, '][', 0)
                        CALL STR_ADDI (STR, J, 0)
                        CALL STR_ADDS (STR,']', 0)
                        CALL STR_ADDF (STR, SVAL(1), ND, 1)
                        CALL LDM_ADDOUT (LIN, STR, IUN, TERM)
                     END IF
330               CONTINUE
                  IF (LIN.NE.' ') THEN
                     IF (TERM) THEN
                        CALL TTSEND (IUN,LIN(1:LENSTR(LIN)),1)
                     ELSE
                        WRITE(IUN,1000) LIN(1:LENSTR(LIN))
                     END IF
                  END IF
350            CONTINUE
            END IF
400      CONTINUE
      END IF
C
C====== RFL
C            
      PRDF = .FALSE.
      IF (IOP.GT.1) PRDF = .TRUE.
      CALL LDM_WRI_PL (IUNOUT, 'RFL', CH_RFL, LDM_MAXPK,
     +                 NPK, NPL, PRDF, IOPTYP)
C
C====== Write out any additionally defined KDM parameters
C
      IREDUCE = 0
      IF (IOP.EQ.3) IREDUCE = 1
      IF (IOP.EQ.2) IREDUCE = 2
      IF (IOP.EQ.1) IREDUCE = 3
      ICHANGED = 0
      KUNIT = IUNOUT
      IF (CHANGES) ICHANGED = ICHAN
      CALL KDMF_NUMPARS (KDX_EXT, NUM_EXT, IERR)
      IF (IERR.NE.0) RETURN

      IF (NUM_EXT.LE.0) RETURN
      DO 480 I = 1, NPK
         NSS(I) = NPL
 480  CONTINUE
      DO 500 IP = 1, NUM_EXT
         CALL KDMF_PARNAME (KDX_EXT, IP, KDMSTR(KEYWORD), 50, KERR)
         IF (KERR.NE.0) GO TO 500
         CALL KDMF_OUTPUT (KDX_EXT, KDMSTR(KEYWORD), LENSTR(KEYWORD),
     +                     ICHANGED, IREDUCE, NPK, NSS,
     +                     KDMSTR(OUTSTR), 2050,
     +                     LDM_OPFUN, KDMSTR(ERRSTR), 2, KERR)
 500  CONTINUE
      
      RETURN
C
C====== Format statements
C
1000  FORMAT (A)
      END
