
C LAST UPDATE:
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C******************************
C**     LSM_PARSETUP_LDM     **
C******************************
C
CD-Routine: Set up other LSM parameters - LSM_PARSETUP_LDM
C This routine may be used instead of LSM_PARSETUP if the program using the
C LSM is based on an LDM file from which the required parameter
C values are to be taken. Remember to call this routine again if any
C of the relevant LDM parameter values may have changed.
CD-end
CD-Fortran:
      SUBROUTINE LSM_PARSETUP_LDM (IERR)
CD-end
C
      INCLUDE 'implicit_none.finc'
C
      INTEGER IERR
C
CD-Parameters:
C  IERR      i (W)   Error flag =0 OK,
C                               =1 Number of packs is zero
C                               =2 A zero CTOF value found 
CD-end
C
C Implementation note: Sets 'markup required' flag
C Implementation note: Sets 'more than one plate defined' flag
C Implementation note: Sets 'minimum crystal-film/plate distance' variable
C
C====== PARAMETERS:
C
      INCLUDE 'limits.finc'
C
C====== GLOBALS:
C
      INCLUDE 'lsm_flags.finc'
      INCLUDE 'other_scale.finc'
C
C====== LOCALS:
C
      INTEGER NPLATES
      INTEGER IFLAG
      INTEGER KERR
      INTEGER I
      INTEGER J
      INTEGER ND
      CHARACTER*2 ERRSTR 

C     INTEGER NPLATES        !No. of plates
C     INTEGER IFLAG          !Parameter status flag
C     INTEGER KERR           !Error flag
C     INTEGER I              !Temp/loop variable
C     INTEGER J              !Temp/loop variable
C     INTEGER ND             !No. of decimal places flag
C     CHARACTER*2 ERRSTR     !Error string (dummy)
C
C-------------------------------------------------------------------------------
      IERR = 0
      MARKUP_REQUIRED = .TRUE.
      CALL LDM_GET_NUMP (NPK, IFLAG)
      IF (NPK.LT.1) THEN
         IERR = 1
         RETURN
      END IF
      CALL LDM_GET_NPLAT (NPLATES, IFLAG)
      PLFLAG = .FALSE.
      IF (NPLATES.GT.1) PLFLAG = .TRUE.
      DO 10 I = 1, NPK
         NPL(I) = NPLATES
         CALL LDM_GET_SPIN (I, SPINDLE(I), IFLAG, ND, KERR, ERRSTR)
 10   CONTINUE
      CALL LDM_GET_A (A, IFLAG, ND)
      CALL LDM_GET_B (B, IFLAG, ND)
      CALL LDM_GET_C (C, IFLAG, ND)
      CALL LDM_GET_ALPHA (ALPHA, IFLAG, ND)
      CALL LDM_GET_BETA (BETA, IFLAG, ND)
      CALL LDM_GET_GAMMA (GAMMA, IFLAG, ND)
      CALL LDM_GET_CTOF (1, 1, AMINCTOF, IFLAG, ND, KERR, ERRSTR)
      DO 50 I = 1, NPK
         DO 40 J = 1, NPLATES
            CALL LDM_GET_CTOF (I, J, CTOF(I,J), IFLAG, ND, 
     +                         KERR, ERRSTR)
            IF (CTOF(I,J).LT.AMINCTOF) AMINCTOF = CTOF(I,J)
 40      CONTINUE
 50   CONTINUE
      IF (AMINCTOF.LE.0.0) THEN
         IERR = 2
         RETURN
      END IF
      RETURN
      END
