
CD-Section: Setting up the Laue Scaling Parameters LSP
C A routine is provided to defines a set of Laue Scaling Parameters 
C (LSP) which together with the Laue Scaling Module (LSM) parameters 
C (and SYMM parameters) form a complete set of parameters for use in 
C a standalone Laue scaling program. It makes use of the Keyword
C Data Module (KDM) for defining and handling the keyworded data.
CD-end

C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C***********************
C**     LSM_SETLSP    **
C***********************
C
C 
CD-Routine: Set up LSP Parameters - LSM_SETLSP
C This routine defines a set of Laue scaling parameters which together with 
C the Laue Scaling Module (LSM) parameters (and SYMM parameters) form a 
C complete set of parameters for use in a standalone Laue scaling, 
C normalisation and absorption correction program.
CD-end
CD-Fortran:
      SUBROUTINE LSM_SETLSP (KDX) 
CD-end
C
      INCLUDE 'implicit_none.finc'
C
C
C Purpose: Set up LSP parameters
C
C Author:  Steffi Arzt, July 1997
C
C Arguments:
C
      INTEGER KDX

CD-Parameters:
C  KDX       i (W)   Returns the index of the keyword set of LSP parameters
CD-end
C
C Implementation note: Get maximum no. of packs and plates from
C                      LSM function LSM_MAXPKPL

C
C====== PARAMETERS:
C
      INCLUDE 'limits.finc'
C
C====== GLOBALS:
C
      INCLUDE 'lsm_flags.finc'
C
C====== FUNCTION TYPES:
C
      INTEGER KDMSTR
      INTEGER LENSTR
C
C====== LOCALS:
C
      INTEGER IERR
      INTEGER MAXCYCLE
      INTEGER I_DEFLT(10)
      REAL IMAGE_SIZE_DEFLT(2)
      REAL F_DEFLT(10)   
      REAL LATT_CONS_DFLT(6)
      REAL SIGREJ_DFLT
      CHARACTER*80 STR   
      CHARACTER*1 DUMMY_STR
      CHARACTER*20 TITL_STR
      CHARACTER*3 FILE_STR(2)
      CHARACTER*8 DET_STR(2)
      CHARACTER*7 OUTFILE_NAME
      CHARACTER*15 REFMTZ_STR(4)
      CHARACTER*8 DATA_STR(2)
C     INTEGER  IERR                ! Error return flag
C     INTEGER NUMIMAGES		   ! Maximum number of images/packs
C     INTEGER NPLATES              ! Maximum number of plates
C     INTEGER I_DEFLT(10)          ! Default integer value
C     REAL IMAGE_SIZE_DEFLT(2)	   ! Default image size in cm
C     REAL F_DEFLT(10)             ! Default real value(s)
C     REAL LATT_CONS_DFLT(6)       ! Lattice constants defaults
C     REAL SIGREJ_DFLT		   ! Exclude refl. with I<SIGREJ*SIGMA
C     CHARACTER*80 STR             ! Temporary string
C     CHARACTER*1 DUMMY_STR        ! Dummy title string
C     CHARACTER*3 FILE_STR(2)      ! Input file typ
C     CHARACTER*8 DET_STR(2)       ! Detector shape
C     CHARACTER*7 OUTFILE_NAME     ! Default name for output file 

C
C======Data
C      

      DATA LATT_CONS_DFLT/0.0,0.0,0.0,90.0,90.0,90.0/
      DATA DUMMY_STR/' '/
      DATA TITL_STR/'** NO TITLE GIVEN **'/
      DATA FILE_STR/'mtz','ge'/
      DATA DET_STR/'cylinder','flat'/
      DATA DATA_STR/'MERGED','UNMERGED'/
      DATA SIGREJ_DFLT/0.0/
      DATA OUTFILE_NAME/'lsm_out'/
      DATA IMAGE_SIZE_DEFLT/0.0,0.0/	
      DATA REFMTZ_STR/'standard','lambda_sep','sign_sep',
     +                           'lambda&sign_sep'/
C
C-------------------------------------------------------------------------------

C
C====== Initialise KDM keyword dataset
C

      CALL KDMF_INIT (MAXPACK, MAXPLATES, KDMSTR('NUMIMAGES'), 
     +                LENSTR('NUMIMAGES'),
     +                KDMSTR('NPLATES'), LENSTR('NPLATES'), 
     +                KDMSTR('PACK'), LENSTR('PACK'),
     +                KDMSTR('PLATE'), LENSTR('PLATE'), KDX, IERR)

C
C====== Define data set parameters
C      

      STR = 'TITLE'
      CALL KDMF_DEFINE_STR (KDX, KDMSTR(STR), LENSTR(STR), 5, 4, 1, 70,
     +                      KDMSTR(TITL_STR), 20, KDMSTR(DUMMY_STR),
     +                      1, 1, 0, 0, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'A'	
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 1, 1, 1, 1,
     +                       LATT_CONS_DFLT(1), 0.0, 0.0, 1, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'B'	
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 1, 1, 1, 1,
     +                       LATT_CONS_DFLT(2), 0.0, 0.0, 1, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'C'	
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 1, 1, 1, 1,
     +                       LATT_CONS_DFLT(3), 0.0, 0.0, 1, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810      

      STR = 'ALPHA'	
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 5, 1, 1, 1,
     +                       LATT_CONS_DFLT(4), 0.0, 180.0, 5, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'BETA'	
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 4, 1, 1, 1,
     +                       LATT_CONS_DFLT(5), 0.0, 180.0, 5, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'GAMMA'	
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 5, 1, 1, 1,
     +                       LATT_CONS_DFLT(6), 0.0, 180.0, 5, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810
 
      STR = 'SPINDLES'
      F_DEFLT(1) = 0.0
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 8, 1, 1, 1,
     +                       F_DEFLT, -360.0, 360.0, 5, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'SPINDLE_ANGLE'	
      F_DEFLT(1) = 0.0
      F_DEFLT(2) = 0.0
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 9, 1, 1, 2,
     +                       F_DEFLT, -360.0, 360.0, 5, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'CTOF'	
      F_DEFLT(1) = 0.0
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 4, 3, 1, 1,
     +                       F_DEFLT(1), 0.0, 0.0, 1, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'IMAGE_SIZE'	
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 7, 1, 1, 2,
     +                       IMAGE_SIZE_DEFLT, 0.0, 0.0, 1, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'DETECTOR'
      CALL KDMF_DEFINE_STR (KDX, KDMSTR(STR), LENSTR(STR), 8, 1, 1, 8,
     +                      KDMSTR(DET_STR(2)), 8, KDMSTR(DET_STR),
     +                      2, 8, 1, 4, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'NUMIMAGES'
      I_DEFLT(1) = 0
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 7, 1, 1, 1,
     +                      I_DEFLT(1), 0, MAXPACK, 
     +                      5, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'NPLATES'
      I_DEFLT(1) = 1
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 7, 2, 1, 1,
     +                      I_DEFLT(1), 0, MAXPLATES, 
     +                      5, 0, IERR)
      IF (IERR.NE.0) GOTO 810

C
C====== Define control parameters 
C

      STR = 'FILENAME_INPUT'
      CALL KDMF_DEFINE_STR (KDX, KDMSTR(STR), LENSTR(STR), 10, 2, 1,100,
     +                      KDMSTR(DUMMY_STR), 5, KDMSTR(DUMMY_STR),
     +                      1, 1, 0, 0, 0, IERR)
      IF (IERR.NE.0) GOTO 810
     
      STR = 'FILETYP_INPUT'
      CALL KDMF_DEFINE_STR (KDX, KDMSTR(STR), LENSTR(STR), 10, 1, 1, 3,
     +                      KDMSTR(FILE_STR(2)), 3, KDMSTR(FILE_STR),
     +                      2, 3, 1, 1, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'FILENAME_OUTPUT'
      CALL KDMF_DEFINE_STR (KDX, KDMSTR(STR), LENSTR(STR), 12, 1, 1, 50,
     +                      KDMSTR(' '), 1, KDMSTR(DUMMY_STR),
     +                      1, 1, 0, 0, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'OUTPUT_DATAOPT'
      CALL KDMF_DEFINE_STR (KDX, KDMSTR(STR), LENSTR(STR), 11, 1, 1, 8,
     +                      KDMSTR('UNMERGED'), 8, KDMSTR(DATA_STR),
     +                      2, 8, 1, 6, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'OUTPUT_OVLD'
      I_DEFLT(1) = -1
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 11, 1, 1, 1,
     +                      I_DEFLT(1), 0, 0, 
     +                      0, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'OUTPUT_SPAT'
      I_DEFLT(1) = 1
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 11, 1, 1, 1,
     +                      I_DEFLT(1), 0, 0, 
     +                      1, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'OUTPUT_NEGINT'
      I_DEFLT(1) = 1
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 13, 1, 1, 1,
     +                      I_DEFLT(1), 0, 0, 
     +                      0, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'OUTPUT_SIGCUT'
      F_DEFLT(1) = 0.0
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 13, 1, 1,
     +                        1,F_DEFLT(1), 0, 0, 1, 0, 2, 2, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'REFFILENAME'
      CALL KDMF_DEFINE_STR (KDX, KDMSTR(STR), LENSTR(STR), 11, 1, 1,100, 
     +                      KDMSTR(' '), 1, KDMSTR(DUMMY_STR),
     +                      1, 1, 0, 0, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'REFMTZ_FILETYP'
      CALL KDMF_DEFINE_STR (KDX, KDMSTR(STR), LENSTR(STR),11, 1, 1, 15,
     +                     KDMSTR(REFMTZ_STR(1)), 8, KDMSTR(REFMTZ_STR),
     +                      4, 15, 1, 0, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'REFMTZ_DLAM'	
      F_DEFLT(1) = 0.1
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 11, 1, 1,1,
     +                       F_DEFLT(1), 0.0, 0.0, 1, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'REFSET_RESCALE'	
      F_DEFLT(1) = 10.0E05
      CALL KDMF_DEFINE_FLOAT (KDX,KDMSTR(STR),LENSTR(STR), 14, 1, 1, 1,
     +                       F_DEFLT(1), 0.0, 0.0, 2, 0, 4, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'REFMTZ_FILEASSIGN'
      CALL KDMF_DEFINE_STR (KDX, KDMSTR(STR), LENSTR(STR), 17, 4, 1,200,
     +                      KDMSTR(' '), 1, KDMSTR(DUMMY_STR),
     +                      1, 1, 0, 0, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'RFAC_OUTPUT'
      I_DEFLT(1) = 1
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 9, 1, 1, 1,
     +                      I_DEFLT(1), 0, 0, 
     +                      1, 0, IERR)
      IF (IERR.NE.0) GOTO 810
C
C====== Flags for selection of reflections
C
      STR = 'MULTIPLES'
      I_DEFLT(1) = 0
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 4, 1, 1, 1,
     +                      I_DEFLT(1), 0, 1, 
     +                      5, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'SIGN_SEP'
      I_DEFLT(1) = 0
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 8, 1, 1, 1,
     +                      I_DEFLT(1), 0, 1, 
     +                      5, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'SPATOV'
      I_DEFLT(1) = 0
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 6, 1, 1, 1,
     +                      I_DEFLT(1), 0, 1, 
     +                      5, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'OVERLD'
      I_DEFLT(1) = 0
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 6, 1, 1, 1,
     +                      I_DEFLT(1), 0, 1, 
     +                      5, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'SIGREJ_EX'
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 9, 1, 1, 1,
     +                       SIGREJ_DFLT, 0.0, 0.0, 1, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'CUTOFF'
      F_DEFLT(1) = 0.0
      CALL KDMF_DEFINE_FLOAT (KDX, KDMSTR(STR), LENSTR(STR), 6, 1, 1, 1,
     +                       F_DEFLT(1), 0.0, 0.0, 1, 0, 2, 2,
     +                       IERR)
      IF (IERR.NE.0) GOTO 810
C
C====== Define refinement flags
C      
      STR = 'ABSOPT'
      I_DEFLT(1) = 1
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 6, 1, 1, 1,
     +                      I_DEFLT(1), 1 , 2, 
     +                      5, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      STR = 'OMIT'
      CALL KDMF_DEFINE_STR (KDX, KDMSTR(STR), LENSTR(STR), 4, 1, 1, 200,
     +                      KDMSTR(' '), 1, KDMSTR(' '),
     +                      1, 1, 0, 0, 0, IERR)
      IF (IERR.NE.0) GOTO 810

      MAXCYCLE = 10
      STR = 'NCYCLE'
      I_DEFLT(1) = 3
      CALL KDMF_DEFINE_INT (KDX, KDMSTR(STR), LENSTR(STR), 6, 1, 1, 1,
     +                      I_DEFLT(1), 1, MAXCYCLE, 
     +                      5, 0, IERR)
      IF (IERR.NE.0) GOTO 810

810   CONTINUE
      RETURN
      END
