C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C****************************
C**     LDM_SET_AXORD      **
C****************************
C
C
CD-Doc:
C AXORd            SUBROUTINE LDM_SET_AXORD (VALSTR, IERR, ERRSTR)
CD-end
      SUBROUTINE LDM_SET_AXORD (VALSTR, IERR, ERRSTR)
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Set value of string parameter AXORD
C
C Author:  John W. Campbell, June 1993
C
C Arguments:
C
      CHARACTER*(*) VALSTR
      INTEGER IERR
      CHARACTER*(*) ERRSTR
C
C  VALSTR    (R)   Axis order string (see LDM_AXORD for details)
C
C                 The string defines the axis order in terms of x and y 
C                 (the detector xd, yd axes). The slower moving axis is
C                 given first followed by the faster moving axis. Minus 
C                 signs are used when the order of an axis is reversed. 
C                 The code 's' if present indicates that byte swapping is 
C                 to be done and the code 'n' indicates that no byte swapping 
C                 is to be done (byte swapping only relevant for image plate
C                 data). Characters, other than 'x', 'y', '-', '+', 's' and 
C                 'n', or their upper case equivalents, are ignored. 
C                 Some examples follow and the returned flags are indicated:
C
C                 xy                     IORD = 1, ISWAP = 0
C                 +x+y                   IORD = 1, ISWAP = 0
C                 -xy                    IORD = 3, ISWAP = 0
C                 x-y s                  IORD = 2, ISWAP = 2
C                 -Y, +X, n              IORD = 7, ISWAP = 1
C                 S                      IORD = 0, ISWAP = 2
C                 +yd, +xd               IORD = 4, ISWAP = 0
C
C                 Invalid strings: +x-x      (Same axis defined twice)
C                                  +x+y-x    (More than two axes defined)
C                                  xysn      (Byte swapping and no byte 
C                                             swapping both defined)
C
C  IERR      (W)   Error flag =0 OK
C                             =1 Invalid code or syntax error in string
C  ERRSTR    (W)   Error description string if error found
C
C====== GLOBALS:
C
      INCLUDE 'ldm_data.finc'
      EXTERNAL LDM_BDAT
C
C====== FUNCTION TYPES:
C
      INTEGER LENSTR
C
C====== LOCALS:
C
      INTEGER I
      INTEGER L
      INTEGER LL
      INTEGER KERR
      INTEGER IORD
      INTEGER ISWAP
      CHARACTER*20 STR

C     INTEGER I          !Character count for compressed string
C     INTEGER L          !Loop counter through string
C     INTEGER LL         !Significant length of string
C     INTEGER KERR       !Error flag from LDM_AXORD
C     INTEGER IORD       !Axis order flag 1-8
C     INTEGER ISWAP      !Byte swap flag 1-2
C     CHARACTER*20 STR   !String to hold compressed order string
C
C-------------------------------------------------------------------------------
C
      IERR = 0
      CALL LDM_AXORD (VALSTR, IORD, ISWAP, KERR, ERRSTR)
      IF (KERR.GT.0) THEN
         IERR = 1
         RETURN
      END IF
      IF (VALSTR.EQ.' ') THEN
         AXORD = '+xd+yd'
      ELSE
         STR = ' '
         I = 0
         LL = LENSTR (VALSTR)
         DO 100 L = 1, LL
            IF (VALSTR(L:L).EQ.' ') GO TO 100
            IF (VALSTR(L:L).EQ.',') GO TO 100
            IF (VALSTR(L:L).EQ.'#') GO TO 100
            IF (VALSTR(L:L).EQ.'!') GO TO 100
            IF (VALSTR(L:L).EQ.'&') GO TO 100
            I = I + 1
            STR(I:I) = VALSTR(L:L)
100      CONTINUE
         IF (STR.EQ.' ') THEN
            AXORD = '+xd+yd'
         ELSE
            AXORD = STR
         END IF
      END IF
      IS_AXORD = 1
      CH_AXORD = CH_MASK
      RETURN
      END
