CD-Section: Setting LDM Parameter Values
C The data in the Laue data module must only be accessed via a set of
C supplied routines to make its use independent of the actual way the
C data are held. There is a set of routines available for setting
C the parameter values. Each LDM parameter has its
C own routine which should be used where efficient access is required.
C There is also a general routine to set a parameter value by giving the
C keyword and a value string. For parameters with real values there is also
C the following distinction made. When a value is set by the explicit routine, 
C then subsequent o/p will be done with the default number of decimal places
C for that parameter; when set via the keyword and string values the
C subsequent o/p will use the same number of decimal places as the given
C string. This is intended so that any unrefined values can basically be
C output as they were originally input in order to clarify the parameters
C file. 
CD-end

C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LDM_SET          **
C**************************
C
CD-Routine: General Routine to Set LDM Parameter Value - LDM_SET
C This routine is used to set an LDM parameter value given the full
C LDM keyword and a value string. Any pack/plate specifications are
C checked and the parameter value is also checked for validity.
CD-end
CD-Fortran:
      SUBROUTINE LDM_SET (KEYWORD, IPACK, IPLATE, VALSTR, 
     +                    IERR, ERRSTR)
CD-end
      INCLUDE 'implicit_none.finc'
C
C Purpose: Set an LDM parameter value using the parsed keyword
C          information and value string
C
C Author:  John W. Campbell, June 1993
C
C Arguments:
C
      CHARACTER*(*) KEYWORD
      INTEGER IPACK
      INTEGER IPLATE
      CHARACTER*(*) VALSTR
      INTEGER IERR
      CHARACTER*(*) ERRSTR

CD-Parameters:
C  KEYWORD   c  (R)  Full keyword string (upper case)
C  IPACK     i  (R)  Pack number or 0=all packs 
C                    (if relevant for the parameter)
C  IPLATE    i  (R)  Plate number or 0=all plates 
C                    (if relevant for the parameter)
C  VALSTR    c  (R)  The string containing the parameter value
C  IERR      i  (W)  Error flag = 0 OK
C                               =-1 Invalid pack specification
C                               =-2 Invalid plate specification
C                               =-3 Invalid LDM keyword
C                               =-4 Invalid polynomial coefficient no.
C                               =-4 Memory allocation error
C                               = 1 Invalid code/string or syntax error in
C                                   number
C                               = 2 Invalid value - must be >=0.0 (>=0)
C                               = 3 Invalid value - must be >0.0 (>0)
C                               = 4 Invalid value - must be <=0.0 (<=0)
C                               = 5 Invalid value - must be <0.0 (<0)
C                               = 6 Other out of range number
C                               = 7 Invalid value for extended LDM keyword
C  ERRSTR    c  (W)  Returns string for error message (max. 80 chars)
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 LDM_FVAL
      INTEGER LDM_IVAL
      INTEGER LDM_SPD_PAR
      INTEGER KDMSTR
      INTEGER LENSTR
C
C====== LOCALS:
C
      REAL FP
      REAL VAL(2)
      INTEGER IV
      INTEGER ND
      INTEGER KERR
      INTEGER ICOEFF
      INTEGER IVAL(2)
      INTEGER FVAL(2)

C     REAL FP         !Floating point value for parameter
C     REAL VAL(2)     !Floating point values array
C     INTEGER IV      !Integer value for parameter
C     INTEGER ND      !No. of decimal places input (-ve if E format)
C     INTEGER KERR    !Error flag
C     INTEGER ICOEFF  !Coeffcient number
C     INTEGER IVAL(2) !Integer values array (dummy)
C     INTEGER FVAL(2) !Real values array (dummy)
C
C-------------------------------------------------------------------------------
C
C====== Initialisations
C
      IERR = 0
      ERRSTR = ' '
C
C====== Find keyword and set value
C

      IF (KEYWORD.EQ.'CRYSTAL') THEN
         CALL LDM_SET_CRYST (VALSTR, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'TITLE') THEN
         CALL LDM_SET_TITLE (VALSTR, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'SYSTEM') THEN
         CALL LDM_SET_SYST (VALSTR, 0, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'LATTICE') THEN
         CALL LDM_SET_LATT(VALSTR, 0, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'SYMMETRY') THEN
         CALL LDM_SET_SYMM (VALSTR, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'BEAM_AXIS') THEN
         CALL LDM_SET_BEAM (VALSTR, 0, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'ROTATION_AXIS') THEN
         CALL LDM_SET_ROT (VALSTR, 0, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'IMAGE_TYPE') THEN
         CALL LDM_SET_IMTYP (VALSTR, 0, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'IMAGE_DATA') THEN
         CALL LDM_SET_IMDAT (VALSTR, 0, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'DGEOM') THEN
         CALL LDM_SET_DGEOM (VALSTR, 0, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'AXORD') THEN
         CALL LDM_SET_AXORD (VALSTR, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'FIDTYPE') THEN
         CALL LDM_SET_FIDT (VALSTR, 0, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'FIDX1') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_FIDX1 (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_FIDX1 = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'FIDY1') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_FIDY1 (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_FIDY1 = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'FIDX2') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_FIDX2 (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_FIDX2 = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'FIDY2') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_FIDY2 (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_FIDY2 = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'FIDX3') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_FIDX3 (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_FIDX3 = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'FIDY3') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_FIDY3 (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_FIDY3 = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'NXRAST') THEN
         IF (LDM_IVAL (VALSTR, IV, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_NXRAS (IV, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'NYRAST') THEN
         IF (LDM_IVAL (VALSTR, IV, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_NYRAS (IV, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'RASTER_SIZE') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_RAST (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_RAST = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'RMIN') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_RMIN (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_RMIN = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'RMAX') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_RMAX (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_RMAX = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'XLOW') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_XLOW (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_XLOW = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'XHIGH') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_XHIGH (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_XHIGH = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'YLOW') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_YLOW (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_YLOW = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'YHIGH') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_YHIGH (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_YHIGH = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'DISTORTION_TYPE') THEN
         CALL LDM_SET_DSTOR (VALSTR, 0, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'FTHRESH') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_FTHR (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_FTHR = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'FIDBOX') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_FBOX (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_FBOX = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'STHRESH') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_STHR (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_STHR = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'OVERLOAD_PIXEL') THEN
         IF (LDM_IVAL (VALSTR, IV, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_OVPIX (IV, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'NUMPACK') THEN
         IF (LDM_IVAL (VALSTR, IV, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_NUMP (IV, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'NPLATES') THEN
         IF (LDM_IVAL (VALSTR, IV, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_NPLAT (IV, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'TEMPLATE') THEN
         CALL LDM_SET_TEMPL (VALSTR, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPOT_EPSILON') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_EPS (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_EPS = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'DTILT') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_DTILT (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_DTILT = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'N1OD') THEN
         IF (LDM_IVAL (VALSTR, IV, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_N1OD (IV, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'G1OD') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_G1OD (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_G1OD = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'BASEOD') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_BASE (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_BASE = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'NONLINEARITY') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_NONL (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_NONL = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'DSPIN') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_DSPIN (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_DSPIN = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'SPINDLE') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SPIN (IPACK, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PK (IPACK, ND_SPIN, ND, LDM_MAXPK)
         RETURN
      ELSE IF (KEYWORD.EQ.'PACK_ID') THEN
         IF (LDM_IVAL (VALSTR, IV, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_PID (IPACK, IV, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'KEYPLATE') THEN
         IF (LDM_IVAL (VALSTR, IV, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_KEYP (IPACK, IV, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'FILENAME') THEN
         CALL LDM_SET_FNAME (IPACK, IPLATE, VALSTR, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'X_CEN_F') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_XCENF (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_XCENF, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'Y_CEN_F') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_YCENF (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_YCENF, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPACING') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SPAC (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPAC, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'A') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_A (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_A = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'B') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_B (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_B = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'C') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_C (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_C = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'ALPHA') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_ALPHA (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_ALPHA = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'BETA') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_BETA (FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         ND_BETA = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'GAMMA') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         IF (IERR.NE.0) RETURN
         CALL LDM_SET_GAMMA (FP, IERR, ERRSTR)
         ND_GAMMA = ND
         RETURN
      ELSE IF (KEYWORD.EQ.'LMIN') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_LMIN (IPACK, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PK (IPACK, ND_LMIN, ND, LDM_MAXPK)
         RETURN
      ELSE IF (KEYWORD.EQ.'LMAX') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_LMAX (IPACK, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PK (IPACK, ND_LMAX, ND, LDM_MAXPK)
         RETURN
      ELSE IF (KEYWORD.EQ.'DMIN') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_DMIN (IPACK, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PK (IPACK, ND_DMIN, ND, LDM_MAXPK)
         RETURN
      ELSE IF (KEYWORD.EQ.'PHIX') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_PHIX (IPACK, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PK (IPACK, ND_PHIX, ND, LDM_MAXPK)
         RETURN
      ELSE IF (KEYWORD.EQ.'PHIY') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_PHIY (IPACK, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PK (IPACK, ND_PHIY, ND, LDM_MAXPK)
         RETURN
      ELSE IF (KEYWORD.EQ.'PHIZ') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_PHIZ (IPACK, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PK (IPACK, ND_PHIZ, ND, LDM_MAXPK)
         RETURN
      ELSE IF (KEYWORD.EQ.'CTOF') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_CTOF (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_CTOF, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'Y_SCALE') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_YSCAL (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_YSCAL, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPOT_LENGTH') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SPOTL (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPOTL, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPOT_WIDTH') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SPOTW (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPOTW, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPOT_FACTOR') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SPOTF (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPOTF, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPOT_BORDER') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SPOTB (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPOTB, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPOT_DELTA') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SPOTD (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPOTD, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'X_C') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_XC (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_XC, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'Y_C') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_YC (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_YC, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'W_C') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_WC (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_WC, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'TWIST') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_TWIST (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_TWIST, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'TILT') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_TILT (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_TILT, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'BULGE') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_BULGE (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_BULGE, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'ROFF') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_ROFF (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_ROFF, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'TOFF') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_TOFF (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_TOFF, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPDXY') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SPDXY (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPDXY, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPDX_N') THEN
         IF (LDM_IVAL (VALSTR, IV, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SPDXN (IPACK, IPLATE, IV, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPDX_MIN') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SXMIN (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPDXMIN, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPDX_MAX') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SXMAX (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPDXMAX, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (LDM_SPD_PAR(1,KEYWORD).GT.0) THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         ICOEFF = LDM_SPD_PAR(1,KEYWORD)
         VAL(1) = FP
         CALL LDM_SET_SPDX (ICOEFF, IPACK, IPLATE, VAL, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPDX(1,1,ICOEFF), ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPDY_N') THEN
         IF (LDM_IVAL (VALSTR, IV, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SPDYN (IPACK, IPLATE, IV, IERR, ERRSTR)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPDY_MIN') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SYMIN (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPDYMIN, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'SPDY_MAX') THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_SYMAX (IPACK, IPLATE, FP, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPDYMAX, ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (LDM_SPD_PAR(2,KEYWORD).GT.0) THEN
         IF (LDM_FVAL (VALSTR, FP, ND, IERR, ERRSTR).NE.0) RETURN
         ICOEFF = LDM_SPD_PAR(2,KEYWORD)
         VAL(1) = FP
         CALL LDM_SET_SPDY (ICOEFF, IPACK, IPLATE, VAL, IERR, ERRSTR)
         IF (IERR.NE.0) RETURN
         CALL LDM_NDSET_PL (IPACK, IPLATE, ND_SPDY(1,1,ICOEFF), ND,
     +                      LDM_MAXPK, LDM_MAXPL)
         RETURN
      ELSE IF (KEYWORD.EQ.'RFL') THEN
         IF (LDM_IVAL (VALSTR, IV, IERR, ERRSTR).NE.0) RETURN
         CALL LDM_SET_RFL (IPACK, IPLATE, IV, IERR, ERRSTR)
         RETURN
      ELSE
         IF (EXTENDED) THEN
            CALL KDMF_SETVALUE (KDX_EXT, KDMSTR(KEYWORD), 
     +                          LENSTR(KEYWORD), IPACK, IPLATE, 
     +                          KDMSTR(VALSTR), LENSTR(VALSTR), 
     +                          IVAL, FVAL, 0,
     +                          KDMSTR(ERRSTR), LEN(ERRSTR), KERR)
            IERR = KERR
            IF (IERR.EQ.-3) ERRSTR = 'Invalid LDM (extended) keyword'
            IF (KERR.EQ.-4) IERR = -5
            IF (KERR.EQ.2) IERR = 7
         ELSE
            IERR = -3
            ERRSTR = 'Invalid LDM keyword'
         END IF
      END IF     
      RETURN
      END
