 MODULE FM_QUAD_INT

!  FM_quadint 1.4                   David M. Smith                  Quadruple Length Integer Support

!  This module extends the definition of basic FM types (FM), (IM), and (ZM) so they can interact
!  with quad length integer variables.

!  Warning:  This module is needed only when the user's program explicitly declares quad length
!            integer variables.  If quad length integers are obtained by using a compiler switch
!            to change the default integer size for the entire program (such as with gfortran's
!            -fdefault-integer-8 option), then compiling the basic FM package with the same option
!            means this module is not needed.

!  Not all compilers might support quad length integers, but for those that do, variables can be
!  declared via the SELECTED_REAL_KIND function.

!  For example, when this module was first written, typical computer hardware supported 32-bit
!  integers as default precision and 64-bits as double precision.  Some compilers offered 128-bit
!  quad integers implemented in software, giving values up to 2**127 - 1, with 39 decimal digits.

!  So SELECTED_INT_KIND(30) could be used to select this 128-bit format.

!  The routines in this interface extend basic functions like TO_FM, TO_IM, TO_ZM so they can be
!  used with quad integer arguments.  New conversion function TO_QUAD_INT will take FM, IM, or ZM
!  inputs and convert to quad integers.

!  Other mixed-mode operations, such as assignment ( a = b ), logical comparisons, and arithmetic
!  are also provided.  As with the basic FMZM module, assignments and arithmetic may also involve
!  1 or 2-dimensional arrays.

    USE FMZM

    INTEGER, PARAMETER :: QUAD_INT = SELECTED_INT_KIND(30)

    INTERFACE TO_FM
       MODULE PROCEDURE FM_QI
       MODULE PROCEDURE FM_QI1
       MODULE PROCEDURE FM_QI2
    END INTERFACE

    INTERFACE TO_IM
       MODULE PROCEDURE IM_QI
       MODULE PROCEDURE IM_QI1
       MODULE PROCEDURE IM_QI2
    END INTERFACE

    INTERFACE TO_ZM
       MODULE PROCEDURE ZM_QI
       MODULE PROCEDURE ZM2_QI
       MODULE PROCEDURE ZM_QI1
       MODULE PROCEDURE ZM_QI2
    END INTERFACE

    INTERFACE TO_QUAD_INT
       MODULE PROCEDURE FM_2QI
       MODULE PROCEDURE IM_2QI
       MODULE PROCEDURE ZM_2QI
       MODULE PROCEDURE FM_2QI1
       MODULE PROCEDURE IM_2QI1
       MODULE PROCEDURE ZM_2QI1
       MODULE PROCEDURE FM_2QI2
       MODULE PROCEDURE IM_2QI2
       MODULE PROCEDURE ZM_2QI2
    END INTERFACE

    INTERFACE ASSIGNMENT (=)
       MODULE PROCEDURE FMEQ_QIFM
       MODULE PROCEDURE FMEQ_QIIM
       MODULE PROCEDURE FMEQ_QIZM
       MODULE PROCEDURE FMEQ_FMQI
       MODULE PROCEDURE FMEQ_IMQI
       MODULE PROCEDURE FMEQ_ZMQI
       MODULE PROCEDURE FMEQ_FM1QI
       MODULE PROCEDURE FMEQ_QI1FM
       MODULE PROCEDURE FMEQ_FM1QI1
       MODULE PROCEDURE FMEQ_QI1FM1
       MODULE PROCEDURE FMEQ_IM1QI
       MODULE PROCEDURE FMEQ_QI1IM
       MODULE PROCEDURE FMEQ_IM1QI1
       MODULE PROCEDURE FMEQ_QI1IM1
       MODULE PROCEDURE FMEQ_ZM1QI
       MODULE PROCEDURE FMEQ_QI1ZM
       MODULE PROCEDURE FMEQ_ZM1QI1
       MODULE PROCEDURE FMEQ_QI1ZM1
       MODULE PROCEDURE FMEQ_FM2QI
       MODULE PROCEDURE FMEQ_QI2FM
       MODULE PROCEDURE FMEQ_FM2QI2
       MODULE PROCEDURE FMEQ_QI2FM2
       MODULE PROCEDURE FMEQ_IM2QI
       MODULE PROCEDURE FMEQ_QI2IM
       MODULE PROCEDURE FMEQ_IM2QI2
       MODULE PROCEDURE FMEQ_QI2IM2
       MODULE PROCEDURE FMEQ_ZM2QI
       MODULE PROCEDURE FMEQ_QI2ZM
       MODULE PROCEDURE FMEQ_ZM2QI2
       MODULE PROCEDURE FMEQ_QI2ZM2
    END INTERFACE

    INTERFACE OPERATOR (==)
       MODULE PROCEDURE FMLEQ_QIFM
       MODULE PROCEDURE FMLEQ_QIIM
       MODULE PROCEDURE FMLEQ_QIZM
       MODULE PROCEDURE FMLEQ_FMQI
       MODULE PROCEDURE FMLEQ_IMQI
       MODULE PROCEDURE FMLEQ_ZMQI
    END INTERFACE

    INTERFACE OPERATOR (/=)
       MODULE PROCEDURE FMLNE_QIFM
       MODULE PROCEDURE FMLNE_QIIM
       MODULE PROCEDURE FMLNE_QIZM
       MODULE PROCEDURE FMLNE_FMQI
       MODULE PROCEDURE FMLNE_IMQI
       MODULE PROCEDURE FMLNE_ZMQI
    END INTERFACE

    INTERFACE OPERATOR (>)
       MODULE PROCEDURE FMLGT_QIFM
       MODULE PROCEDURE FMLGT_QIIM
       MODULE PROCEDURE FMLGT_FMQI
       MODULE PROCEDURE FMLGT_IMQI
    END INTERFACE

    INTERFACE OPERATOR (>=)
       MODULE PROCEDURE FMLGE_QIFM
       MODULE PROCEDURE FMLGE_QIIM
       MODULE PROCEDURE FMLGE_FMQI
       MODULE PROCEDURE FMLGE_IMQI
    END INTERFACE

    INTERFACE OPERATOR (<)
       MODULE PROCEDURE FMLLT_QIFM
       MODULE PROCEDURE FMLLT_QIIM
       MODULE PROCEDURE FMLLT_FMQI
       MODULE PROCEDURE FMLLT_IMQI
    END INTERFACE

    INTERFACE OPERATOR (<=)
       MODULE PROCEDURE FMLLE_QIFM
       MODULE PROCEDURE FMLLE_QIIM
       MODULE PROCEDURE FMLLE_FMQI
       MODULE PROCEDURE FMLLE_IMQI
    END INTERFACE

    INTERFACE OPERATOR (+)
       MODULE PROCEDURE FMADD_QIFM
       MODULE PROCEDURE FMADD_QIIM
       MODULE PROCEDURE FMADD_QIZM
       MODULE PROCEDURE FMADD_FMQI
       MODULE PROCEDURE FMADD_IMQI
       MODULE PROCEDURE FMADD_ZMQI
       MODULE PROCEDURE FMADD_QIFM1
       MODULE PROCEDURE FMADD_QIIM1
       MODULE PROCEDURE FMADD_FMQI1
       MODULE PROCEDURE FMADD_FM1QI
       MODULE PROCEDURE FMADD_QI1FM
       MODULE PROCEDURE FMADD_QI1FM1
       MODULE PROCEDURE FMADD_FM1QI1
       MODULE PROCEDURE FMADD_IMQI1
       MODULE PROCEDURE FMADD_IM1QI
       MODULE PROCEDURE FMADD_QI1IM
       MODULE PROCEDURE FMADD_QI1IM1
       MODULE PROCEDURE FMADD_IM1QI1
       MODULE PROCEDURE FMADD_QIZM1
       MODULE PROCEDURE FMADD_ZMQI1
       MODULE PROCEDURE FMADD_ZM1QI
       MODULE PROCEDURE FMADD_QI1ZM
       MODULE PROCEDURE FMADD_QI1ZM1
       MODULE PROCEDURE FMADD_ZM1QI1
       MODULE PROCEDURE FMADD_QIFM2
       MODULE PROCEDURE FMADD_QIIM2
       MODULE PROCEDURE FMADD_FMQI2
       MODULE PROCEDURE FMADD_FM2QI
       MODULE PROCEDURE FMADD_QI2FM
       MODULE PROCEDURE FMADD_QI2FM2
       MODULE PROCEDURE FMADD_FM2QI2
       MODULE PROCEDURE FMADD_IMQI2
       MODULE PROCEDURE FMADD_IM2QI
       MODULE PROCEDURE FMADD_QI2IM
       MODULE PROCEDURE FMADD_QI2IM2
       MODULE PROCEDURE FMADD_IM2QI2
       MODULE PROCEDURE FMADD_QIZM2
       MODULE PROCEDURE FMADD_ZMQI2
       MODULE PROCEDURE FMADD_ZM2QI
       MODULE PROCEDURE FMADD_QI2ZM
       MODULE PROCEDURE FMADD_QI2ZM2
       MODULE PROCEDURE FMADD_ZM2QI2
    END INTERFACE

    INTERFACE OPERATOR (-)
       MODULE PROCEDURE FMSUB_QIFM
       MODULE PROCEDURE FMSUB_QIIM
       MODULE PROCEDURE FMSUB_QIZM
       MODULE PROCEDURE FMSUB_FMQI
       MODULE PROCEDURE FMSUB_IMQI
       MODULE PROCEDURE FMSUB_ZMQI
       MODULE PROCEDURE FMSUB_QIFM1
       MODULE PROCEDURE FMSUB_QIIM1
       MODULE PROCEDURE FMSUB_FMQI1
       MODULE PROCEDURE FMSUB_FM1QI
       MODULE PROCEDURE FMSUB_QI1FM
       MODULE PROCEDURE FMSUB_QI1FM1
       MODULE PROCEDURE FMSUB_FM1QI1
       MODULE PROCEDURE FMSUB_IMQI1
       MODULE PROCEDURE FMSUB_IM1QI
       MODULE PROCEDURE FMSUB_QI1IM
       MODULE PROCEDURE FMSUB_QI1IM1
       MODULE PROCEDURE FMSUB_IM1QI1
       MODULE PROCEDURE FMSUB_QIZM1
       MODULE PROCEDURE FMSUB_ZMQI1
       MODULE PROCEDURE FMSUB_ZM1QI
       MODULE PROCEDURE FMSUB_QI1ZM
       MODULE PROCEDURE FMSUB_QI1ZM1
       MODULE PROCEDURE FMSUB_ZM1QI1
       MODULE PROCEDURE FMSUB_QIFM2
       MODULE PROCEDURE FMSUB_QIIM2
       MODULE PROCEDURE FMSUB_FMQI2
       MODULE PROCEDURE FMSUB_FM2QI
       MODULE PROCEDURE FMSUB_QI2FM
       MODULE PROCEDURE FMSUB_QI2FM2
       MODULE PROCEDURE FMSUB_FM2QI2
       MODULE PROCEDURE FMSUB_IMQI2
       MODULE PROCEDURE FMSUB_IM2QI
       MODULE PROCEDURE FMSUB_QI2IM
       MODULE PROCEDURE FMSUB_QI2IM2
       MODULE PROCEDURE FMSUB_IM2QI2
       MODULE PROCEDURE FMSUB_QIZM2
       MODULE PROCEDURE FMSUB_ZMQI2
       MODULE PROCEDURE FMSUB_ZM2QI
       MODULE PROCEDURE FMSUB_QI2ZM
       MODULE PROCEDURE FMSUB_QI2ZM2
       MODULE PROCEDURE FMSUB_ZM2QI2
    END INTERFACE

    INTERFACE OPERATOR (*)
       MODULE PROCEDURE FMMPY_QIFM
       MODULE PROCEDURE FMMPY_QIIM
       MODULE PROCEDURE FMMPY_QIZM
       MODULE PROCEDURE FMMPY_FMQI
       MODULE PROCEDURE FMMPY_IMQI
       MODULE PROCEDURE FMMPY_ZMQI
       MODULE PROCEDURE FMMPY_QIFM1
       MODULE PROCEDURE FMMPY_QIIM1
       MODULE PROCEDURE FMMPY_FMQI1
       MODULE PROCEDURE FMMPY_FM1QI
       MODULE PROCEDURE FMMPY_QI1FM
       MODULE PROCEDURE FMMPY_QI1FM1
       MODULE PROCEDURE FMMPY_FM1QI1
       MODULE PROCEDURE FMMPY_IMQI1
       MODULE PROCEDURE FMMPY_IM1QI
       MODULE PROCEDURE FMMPY_QI1IM
       MODULE PROCEDURE FMMPY_QI1IM1
       MODULE PROCEDURE FMMPY_IM1QI1
       MODULE PROCEDURE FMMPY_QIZM1
       MODULE PROCEDURE FMMPY_ZMQI1
       MODULE PROCEDURE FMMPY_ZM1QI
       MODULE PROCEDURE FMMPY_QI1ZM
       MODULE PROCEDURE FMMPY_QI1ZM1
       MODULE PROCEDURE FMMPY_ZM1QI1
       MODULE PROCEDURE FMMPY_QIFM2
       MODULE PROCEDURE FMMPY_QIIM2
       MODULE PROCEDURE FMMPY_FMQI2
       MODULE PROCEDURE FMMPY_FM2QI
       MODULE PROCEDURE FMMPY_QI2FM
       MODULE PROCEDURE FMMPY_QI2FM2
       MODULE PROCEDURE FMMPY_FM2QI2
       MODULE PROCEDURE FMMPY_IMQI2
       MODULE PROCEDURE FMMPY_IM2QI
       MODULE PROCEDURE FMMPY_QI2IM
       MODULE PROCEDURE FMMPY_QI2IM2
       MODULE PROCEDURE FMMPY_IM2QI2
       MODULE PROCEDURE FMMPY_QIZM2
       MODULE PROCEDURE FMMPY_ZMQI2
       MODULE PROCEDURE FMMPY_ZM2QI
       MODULE PROCEDURE FMMPY_QI2ZM
       MODULE PROCEDURE FMMPY_QI2ZM2
       MODULE PROCEDURE FMMPY_ZM2QI2
    END INTERFACE

    INTERFACE OPERATOR (/)
       MODULE PROCEDURE FMDIV_QIFM
       MODULE PROCEDURE FMDIV_QIIM
       MODULE PROCEDURE FMDIV_QIZM
       MODULE PROCEDURE FMDIV_FMQI
       MODULE PROCEDURE FMDIV_IMQI
       MODULE PROCEDURE FMDIV_ZMQI
       MODULE PROCEDURE FMDIV_QIFM1
       MODULE PROCEDURE FMDIV_QIIM1
       MODULE PROCEDURE FMDIV_FMQI1
       MODULE PROCEDURE FMDIV_FM1QI
       MODULE PROCEDURE FMDIV_QI1FM
       MODULE PROCEDURE FMDIV_QI1FM1
       MODULE PROCEDURE FMDIV_FM1QI1
       MODULE PROCEDURE FMDIV_IMQI1
       MODULE PROCEDURE FMDIV_IM1QI
       MODULE PROCEDURE FMDIV_QI1IM
       MODULE PROCEDURE FMDIV_QI1IM1
       MODULE PROCEDURE FMDIV_IM1QI1
       MODULE PROCEDURE FMDIV_QIZM1
       MODULE PROCEDURE FMDIV_ZMQI1
       MODULE PROCEDURE FMDIV_ZM1QI
       MODULE PROCEDURE FMDIV_QI1ZM
       MODULE PROCEDURE FMDIV_QI1ZM1
       MODULE PROCEDURE FMDIV_ZM1QI1
       MODULE PROCEDURE FMDIV_QIFM2
       MODULE PROCEDURE FMDIV_QIIM2
       MODULE PROCEDURE FMDIV_FMQI2
       MODULE PROCEDURE FMDIV_FM2QI
       MODULE PROCEDURE FMDIV_QI2FM
       MODULE PROCEDURE FMDIV_QI2FM2
       MODULE PROCEDURE FMDIV_FM2QI2
       MODULE PROCEDURE FMDIV_IMQI2
       MODULE PROCEDURE FMDIV_IM2QI
       MODULE PROCEDURE FMDIV_QI2IM
       MODULE PROCEDURE FMDIV_QI2IM2
       MODULE PROCEDURE FMDIV_IM2QI2
       MODULE PROCEDURE FMDIV_QIZM2
       MODULE PROCEDURE FMDIV_ZMQI2
       MODULE PROCEDURE FMDIV_ZM2QI
       MODULE PROCEDURE FMDIV_QI2ZM
       MODULE PROCEDURE FMDIV_QI2ZM2
       MODULE PROCEDURE FMDIV_ZM2QI2
    END INTERFACE

    INTERFACE OPERATOR (**)
       MODULE PROCEDURE FMPWR_QIFM
       MODULE PROCEDURE FMPWR_QIIM
       MODULE PROCEDURE FMPWR_QIZM
       MODULE PROCEDURE FMPWR_FMQI
       MODULE PROCEDURE FMPWR_IMQI
       MODULE PROCEDURE FMPWR_ZMQI
    END INTERFACE

 CONTAINS

      SUBROUTINE FMQI2M(IVAL,MA)

!  Convert quad length integer IVAL to multiple precision MA.

      USE FMVALS
      IMPLICIT NONE

      TYPE(MULTI) :: MA
      INTEGER (QUAD_INT) :: IVAL

      REAL (KIND(1.0D0)) :: MK,ML,MVAL
      INTEGER (QUAD_INT) :: J,JM2,KB,KB1,N1,NMVAL,NV2
      CHARACTER(50) :: STR
      INTENT (IN) :: IVAL
      INTENT (INOUT) :: MA

      IF (.NOT. ALLOCATED(MA%MP)) THEN
          ALLOCATE(MA%MP(NDIG+2),STAT=K_STAT)
          IF (K_STAT /= 0) CALL FMDEFINE_ERROR
      ELSE IF (SIZE(MA%MP) < NDIG+2) THEN
          DEALLOCATE(MA%MP)
          ALLOCATE(MA%MP(NDIG+2),STAT=K_STAT)
          IF (K_STAT /= 0) CALL FMDEFINE_ERROR
      ENDIF

      IF (MBLOGS /= MBASE) CALL FMCONS
      KFLAG = 0
      N1 = NDIG + 1

      IF (ABS(IVAL) > MXBASE) THEN
          WRITE (STR,"(I50)") IVAL
          CALL FMST2M(STR,MA)
          GO TO 150
      ELSE
          MVAL = ABS(IVAL)
          NMVAL = MVAL
          NV2 = NMVAL - 1
          IF (NMVAL /= ABS(IVAL) .OR. NV2 /= ABS(IVAL)-1) THEN
              WRITE (STR,"(I50)") IVAL
              CALL FMST2M(STR,MA)
              GO TO 150
          ENDIF
      ENDIF

!             Check for small IVAL.

      IF (MVAL < MBASE) THEN
          DO J = 3, N1
             MA%MP(J+1) = 0
          ENDDO
          IF (IVAL >= 0) THEN
              MA%MP(3) = IVAL
              MA%MP(1) = 1
          ELSE
              MA%MP(3) = -IVAL
              MA%MP(1) = -1
          ENDIF
          IF (IVAL == 0) THEN
              MA%MP(2) = 0
          ELSE
              MA%MP(2) = 1
          ENDIF
          GO TO 150
      ENDIF

!             Compute and store the digits, right to left.

      MA%MP(2) = 0
      J = NDIG + 1

  120 MK = AINT (MVAL/MBASE)
      ML = MVAL - MK*MBASE
      MA%MP(2) = MA%MP(2) + 1
      MA%MP(J+1) = ML
      IF (MK > 0) THEN
          MVAL = MK
          J = J - 1
          IF (J >= 2) GO TO 120

!             Here IVAL cannot be expressed exactly.

          WRITE (STR,"(I50)") IVAL
          CALL FMST2M(STR,MA)
          RETURN
      ENDIF

!             Normalize MA.

      KB = N1 - J + 2
      JM2 = J - 2
      DO J = 2, KB
         MA%MP(J+1) = MA%MP(J+JM2+1)
      ENDDO
      KB1 = KB + 1
      IF (KB1 <= N1) THEN
          DO J = KB1, N1
             MA%MP(J+1) = 0
          ENDDO
      ENDIF

      MA%MP(1) = 1
      IF (IVAL < 0 .AND. MA%MP(2) /= MUNKNO .AND. MA%MP(3) /= 0) MA%MP(1) = -1

  150 RETURN
      END SUBROUTINE FMQI2M

      SUBROUTINE FMM2QI(MA,IVAL)

!  Convert multiple precision MA to quad length integer IVAL.

      USE FMVALS
      IMPLICIT NONE

      TYPE(MULTI) :: MA
      INTEGER (QUAD_INT) :: IVAL

      INTEGER (QUAD_INT) :: IBASE,J,KA,KB,LARGE,N1
      INTENT (IN) :: MA
      INTENT (INOUT) :: IVAL

      KFLAG = 0
      N1 = NDIG + 1
      LARGE = HUGE(IVAL)/MBASE
      IBASE = MBASE
      IVAL = 0
      IF (MA%MP(2) <= 0) THEN
          IF (MA%MP(3) /= 0) KFLAG = 2
          RETURN
      ENDIF

      KB = MA%MP(2) + 1
      IVAL = ABS(MA%MP(3))
      IF (KB >= 3) THEN
          DO J = 3, KB
             IF (IVAL > LARGE) THEN
                 KFLAG = -4
                 IF (MA%MP(2) /= MUNKNO) CALL FMWARN
                 IVAL = IUNKNO
                 RETURN
             ENDIF
             IF (J <= N1) THEN
                 IVAL = IVAL*IBASE
                 IF (IVAL > HUGE(IVAL)-MA%MP(J+1)) THEN
                     KFLAG = -4
                     IF (MA%MP(2) /= MUNKNO) CALL FMWARN
                     IVAL = IUNKNO
                     RETURN
                 ELSE
                     IVAL = IVAL + INT(MA%MP(J+1))
                 ENDIF
             ELSE
                 IVAL = IVAL*IBASE
             ENDIF
          ENDDO
      ENDIF

      IF (MA%MP(1) < 0) IVAL = -IVAL

!             Check to see if MA is an integer.

      KA = KB + 1
      IF (KA <= N1) THEN
          DO J = KA, N1
             IF (MA%MP(J+1) /= 0) THEN
                 KFLAG = 2
                 RETURN
             ENDIF
          ENDDO
      ENDIF

      RETURN
      END SUBROUTINE FMM2QI

      SUBROUTINE IMQI2M(IVAL,MA)

!  MA = IVAL

!  Convert a quad length integer to an IM number.

      USE FMVALS
      IMPLICIT NONE

      TYPE(MULTI) :: MA
      INTEGER (QUAD_INT) :: IVAL

      INTEGER :: NDSAVE
      INTENT (IN) :: IVAL
      INTENT (INOUT) :: MA
      TYPE(MULTI), SAVE :: MVLVFM

      CALL FMQI2M(IVAL,MVLVFM)

      IF (INT(MVLVFM%MP(2)) > NDIG) THEN
          NDSAVE = NDIG
          NDIG = MAX(2,INT(MVLVFM%MP(2)))
          CALL FMQI2M(IVAL,MVLVFM)
          CALL IMFM2I(MVLVFM,MA)
          NDIG = NDSAVE
      ELSE
          CALL IMFM2I(MVLVFM,MA)
      ENDIF

      RETURN
      END SUBROUTINE IMQI2M

      SUBROUTINE IMM2QI(MA,IVAL)

!  IVAL = MA

!  Convert an IM number to quad length integer.

      USE FMVALS
      IMPLICIT NONE

      TYPE(MULTI) :: MA
      INTEGER (QUAD_INT) :: IVAL

      INTEGER :: NDSAVE
      INTENT (IN) :: MA
      INTENT (INOUT) :: IVAL
      TYPE(MULTI), SAVE :: MTLVFM

      NDSAVE = NDIG
      NDIG = MAX(2,INT(MA%MP(2)))

      CALL IMI2FM(MA,MTLVFM)
      CALL FMM2QI(MTLVFM,IVAL)

      NDIG = NDSAVE
      RETURN
      END SUBROUTINE IMM2QI

   FUNCTION FM_QI(D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D
      CALL FMQI2M(D,RETURN_VALUE%MFM)
   END FUNCTION FM_QI

   FUNCTION FM_QI1(D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: D
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FM_QI1

   FUNCTION FM_QI2(D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: D
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FM_QI2

   FUNCTION IM_QI(D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D
      CALL IMQI2M(D,RETURN_VALUE%MIM)
   END FUNCTION IM_QI

   FUNCTION IM_QI1(D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: D
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION IM_QI1

   FUNCTION IM_QI2(D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: D
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL IMQI2M(D(J,K),RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION IM_QI2

   FUNCTION ZM_QI(D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,RETURN_VALUE%MZM)
   END FUNCTION ZM_QI

   FUNCTION ZM2_QI(D1,D2)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: RETURN_VALUE
      INTEGER (QUAD_INT) :: D1,D2
      INTENT (IN) :: D1,D2
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FMQI2M(D1,MTLVFM)
      CALL FMQI2M(D2,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,RETURN_VALUE%MZM)
   END FUNCTION ZM2_QI

   FUNCTION ZM_QI1(D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION ZM_QI1

   FUNCTION ZM_QI2(D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION ZM_QI2

   FUNCTION FM_2QI(MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: RETURN_VALUE
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      CALL FMM2QI(MA%MFM,RETURN_VALUE)
   END FUNCTION FM_2QI

   FUNCTION IM_2QI(MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: RETURN_VALUE
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      CALL IMM2QI(MA%MIM,RETURN_VALUE)
   END FUNCTION IM_2QI

   FUNCTION ZM_2QI(MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT) :: RETURN_VALUE
      INTENT (IN) :: MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL ZMREAL(MA%MZM,MTLVFM)
      CALL FMM2QI(MTLVFM,RETURN_VALUE)
   END FUNCTION ZM_2QI

   FUNCTION FM_2QI1(MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      DO J = 1, N
         CALL FMM2QI(MA(J)%MFM,RETURN_VALUE(J))
      ENDDO
   END FUNCTION FM_2QI1

   FUNCTION IM_2QI1(MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      DO J = 1, N
         CALL IMM2QI(MA(J)%MIM,RETURN_VALUE(J))
      ENDDO
   END FUNCTION IM_2QI1

   FUNCTION ZM_2QI1(MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      DO J = 1, N
         CALL FMM2QI(MA(J)%MZM(1),RETURN_VALUE(J))
      ENDDO
   END FUNCTION ZM_2QI1

   FUNCTION FM_2QI2(MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMM2QI(MA(J,K)%MFM,RETURN_VALUE(J,K))
         ENDDO
      ENDDO
   END FUNCTION FM_2QI2

   FUNCTION IM_2QI2(MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMM2QI(MA(J,K)%MIM,RETURN_VALUE(J,K))
         ENDDO
      ENDDO
   END FUNCTION IM_2QI2

   FUNCTION ZM_2QI2(MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMM2QI(MA(J,K)%MZM(1),RETURN_VALUE(J,K))
         ENDDO
      ENDDO
   END FUNCTION ZM_2QI2

   SUBROUTINE FMEQ_QIFM(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      CALL FMM2QI(MA%MFM,D)
   END SUBROUTINE FMEQ_QIFM

   SUBROUTINE FMEQ_QIIM(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      CALL IMM2QI(MA%MIM,D)
   END SUBROUTINE FMEQ_QIIM

   SUBROUTINE FMEQ_QIZM(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL ZMREAL(MA%MZM,MTLVFM)
      CALL FMM2QI(MTLVFM,D)
   END SUBROUTINE FMEQ_QIZM

   SUBROUTINE FMEQ_FMQI(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      CALL FMQI2M(D,MA%MFM)
   END SUBROUTINE FMEQ_FMQI

   SUBROUTINE FMEQ_IMQI(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER :: IVAL
      INTEGER (QUAD_INT) :: D
      CHARACTER(50) :: ST
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      IF (ABS(D) < HUGE(1)) THEN
          IVAL = INT(D)
          CALL IMI2M(IVAL,MA%MIM)
      ELSE
          WRITE (ST,'(I50)') D
          CALL IMST2M(ST,MA%MIM)
      ENDIF
   END SUBROUTINE FMEQ_IMQI

   SUBROUTINE FMEQ_ZMQI(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MA%MZM)
   END SUBROUTINE FMEQ_ZMQI

   SUBROUTINE FMEQ_FM1QI(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL FMEQ(MTLVFM,MA(J)%MFM)
      ENDDO
   END SUBROUTINE FMEQ_FM1QI

   SUBROUTINE FMEQ_QI1FM(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTEGER (QUAD_INT) :: D2
      INTEGER :: J,N
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      CALL FMM2QI(MA%MFM,D2)
      DO J = 1, N
         D(J) = D2
      ENDDO
   END SUBROUTINE FMEQ_QI1FM

   SUBROUTINE FMEQ_FM1QI1(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM
      IF (SIZE(MA) /= SIZE(D)) THEN
          CALL FMST2M(' UNKNOWN ',MTLVFM)
          DO J = 1, SIZE(MA)
             CALL FMEQ(MTLVFM,MA(J)%MFM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      DO J = 1, N
         CALL FMQI2M(D(J),MA(J)%MFM)
      ENDDO
   END SUBROUTINE FMEQ_FM1QI1

   SUBROUTINE FMEQ_QI1FM1(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTEGER :: J,N
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(D)
             D(J) = RUNKNO
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      DO J = 1, N
         CALL FMM2QI(MA(J)%MFM,D(J))
      ENDDO
   END SUBROUTINE FMEQ_QI1FM1

   SUBROUTINE FMEQ_FM2QI(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMEQ(MTLVFM,MA(J,K)%MFM)
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_FM2QI

   SUBROUTINE FMEQ_QI2FM(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTEGER (QUAD_INT) :: D2
      INTEGER :: J,K
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      CALL FMM2QI(MA%MFM,D2)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            D(J,K) = D2
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_QI2FM

   SUBROUTINE FMEQ_FM2QI2(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          CALL FMST2M(' UNKNOWN ',MTLVFM)
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL FMEQ(MTLVFM,MA(J,K)%MFM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MA(J,K)%MFM)
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_FM2QI2

   SUBROUTINE FMEQ_QI2FM2(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTEGER :: J,K
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(D,DIM=1)
             DO K = 1, SIZE(D,DIM=2)
                D(J,K) = RUNKNO
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMM2QI(MA(J,K)%MFM,D(J,K))
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_QI2FM2

   SUBROUTINE FMEQ_IM1QI(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVIM
      N = SIZE(MA)
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, N
         CALL IMEQ(MTLVIM,MA(J)%MIM)
      ENDDO
   END SUBROUTINE FMEQ_IM1QI

   SUBROUTINE FMEQ_QI1IM(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTEGER (QUAD_INT) :: D2
      INTEGER :: J,N
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      CALL IMM2QI(MA%MIM,D2)
      DO J = 1, N
         D(J) = D2
      ENDDO
   END SUBROUTINE FMEQ_QI1IM

   SUBROUTINE FMEQ_IM1QI1(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVIM
      IF (SIZE(MA) /= SIZE(D)) THEN
          CALL IMST2M(' UNKNOWN ',MTLVIM)
          DO J = 1, SIZE(MA)
             CALL IMEQ(MTLVIM,MA(J)%MIM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      DO J = 1, N
         CALL IMQI2M(D(J),MA(J)%MIM)
      ENDDO
   END SUBROUTINE FMEQ_IM1QI1

   SUBROUTINE FMEQ_QI1IM1(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTEGER :: J,N
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             D(J) = RUNKNO
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      DO J = 1, N
         CALL IMM2QI(MA(J)%MIM,D(J))
      ENDDO
   END SUBROUTINE FMEQ_QI1IM1

   SUBROUTINE FMEQ_IM2QI(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMEQ(MTLVIM,MA(J,K)%MIM)
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_IM2QI

   SUBROUTINE FMEQ_QI2IM(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTEGER (QUAD_INT) :: D2
      INTEGER :: J,K
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      CALL IMM2QI(MA%MIM,D2)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            D(J,K) = D2
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_QI2IM

   SUBROUTINE FMEQ_IM2QI2(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVIM
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          CALL IMST2M(' UNKNOWN ',MTLVIM)
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL IMEQ(MTLVIM,MA(J,K)%MIM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMQI2M(D(J,K),MA(J,K)%MIM)
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_IM2QI2

   SUBROUTINE FMEQ_QI2IM2(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTEGER :: J,K
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                D(J,K) = RUNKNO
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMM2QI(MA(J,K)%MIM,D(J,K))
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_QI2IM2

   SUBROUTINE FMEQ_ZM1QI(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, N
         CALL ZMEQ(MTLVZM,MA(J)%MZM)
      ENDDO
   END SUBROUTINE FMEQ_ZM1QI

   SUBROUTINE FMEQ_QI1ZM(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTEGER (QUAD_INT) :: D2
      INTEGER :: J,N
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      CALL ZMREAL(MA%MZM,MTLVFM)
      CALL FMM2QI(MTLVFM,D2)
      DO J = 1, N
         D(J) = D2
      ENDDO
   END SUBROUTINE FMEQ_QI1ZM

   SUBROUTINE FMEQ_ZM1QI1(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      IF (SIZE(MA) /= SIZE(D)) THEN
          CALL ZMST2M(' UNKNOWN + UNKNOWN i ',MTLVZM)
          DO J = 1, SIZE(MA)
             CALL ZMEQ(MTLVZM,MA(J)%MZM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MA(J)%MZM)
      ENDDO
   END SUBROUTINE FMEQ_ZM1QI1

   SUBROUTINE FMEQ_QI1ZM1(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTEGER :: J,N
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             D(J) = RUNKNO
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      DO J = 1, N
         CALL ZMREAL(MA(J)%MZM,MTLVFM)
         CALL FMM2QI(MTLVFM,D(J))
      ENDDO
   END SUBROUTINE FMEQ_QI1ZM1

   SUBROUTINE FMEQ_ZM2QI(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL ZMEQ(MTLVZM,MA(J,K)%MZM)
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_ZM2QI

   SUBROUTINE FMEQ_QI2ZM(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTEGER (QUAD_INT) :: D2
      INTEGER :: J,K
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL ZMREAL(MA%MZM,MTLVFM)
      CALL FMM2QI(MTLVFM,D2)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            D(J,K) = D2
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_QI2ZM

   SUBROUTINE FMEQ_ZM2QI2(MA,D)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (INOUT) :: MA
      INTENT (IN) :: D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          CALL ZMST2M(' UNKNOWN + UNKNOWN i ',MTLVZM)
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL ZMEQ(MTLVZM,MA(J,K)%MZM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MA(J,K)%MZM)
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_ZM2QI2

   SUBROUTINE FMEQ_QI2ZM2(D,MA)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTEGER :: J,K
      INTENT (INOUT) :: D
      INTENT (IN) :: MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                D(J,K) = RUNKNO
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL ZMREAL(MA(J,K)%MZM,MTLVFM)
            CALL FMM2QI(MTLVFM,D(J,K))
         ENDDO
      ENDDO
   END SUBROUTINE FMEQ_QI2ZM2

   FUNCTION FMLEQ_QIFM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MTLVFM,'EQ',MA%MFM)
   END FUNCTION FMLEQ_QIFM

   FUNCTION FMLEQ_QIIM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: IMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      RETURN_VALUE = IMCOMP(MTLVIM,'EQ',MA%MIM)
   END FUNCTION FMLEQ_QIIM

   FUNCTION FMLEQ_QIZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE,L1,L2
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL ZMREAL(MA%MZM,MULVFM)
      L1 = FMCOMP(MTLVFM,'EQ',MULVFM)
      CALL FMI2M(0,MTLVFM)
      CALL ZMIMAG(MA%MZM,MULVFM)
      L2 = FMCOMP(MTLVFM,'EQ',MULVFM)
      RETURN_VALUE = L1.AND.L2
   END FUNCTION FMLEQ_QIZM

   FUNCTION FMLEQ_FMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MA%MFM,'EQ',MTLVFM)
   END FUNCTION FMLEQ_FMQI

   FUNCTION FMLEQ_IMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTEGER :: KA,NDSAVE
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FM_UNDEF_INP(MA)
      NDSAVE = NDIG
      KA = MA%MIM%MP(2)
      NDIG = MAX(KA+NGRD52,NDIG)
      CALL FMQI2M(D,MTLVFM)
      CALL IMI2FM(MA%MIM,MULVFM)
      RETURN_VALUE = FMCOMP(MULVFM,'EQ',MTLVFM)
      NDIG = NDSAVE
   END FUNCTION FMLEQ_IMQI

   FUNCTION FMLEQ_ZMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE,L1,L2
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL ZMREAL(MA%MZM,MULVFM)
      L1 = FMCOMP(MTLVFM,'EQ',MULVFM)
      CALL FMI2M(0,MTLVFM)
      CALL ZMIMAG(MA%MZM,MULVFM)
      L2 = FMCOMP(MTLVFM,'EQ',MULVFM)
      RETURN_VALUE = L1.AND.L2
   END FUNCTION FMLEQ_ZMQI

   FUNCTION FMLNE_QIFM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MTLVFM,'NE',MA%MFM)
   END FUNCTION FMLNE_QIFM

   FUNCTION FMLNE_QIIM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: IMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      RETURN_VALUE = IMCOMP(MTLVIM,'NE',MA%MIM)
   END FUNCTION FMLNE_QIIM

   FUNCTION FMLNE_QIZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE,L1,L2
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL ZMREAL(MA%MZM,MULVFM)
      L1 = FMCOMP(MTLVFM,'NE',MULVFM)
      CALL FMI2M(0,MTLVFM)
      CALL ZMIMAG(MA%MZM,MULVFM)
      L2 = FMCOMP(MTLVFM,'NE',MULVFM)
      RETURN_VALUE = L1.OR.L2
   END FUNCTION FMLNE_QIZM

   FUNCTION FMLNE_FMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MA%MFM,'NE',MTLVFM)
   END FUNCTION FMLNE_FMQI

   FUNCTION FMLNE_IMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTEGER :: KA,NDSAVE
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FM_UNDEF_INP(MA)
      NDSAVE = NDIG
      KA = MA%MIM%MP(2)
      NDIG = MAX(KA+NGRD52,NDIG)
      CALL FMQI2M(D,MTLVFM)
      CALL IMI2FM(MA%MIM,MULVFM)
      RETURN_VALUE = FMCOMP(MULVFM,'NE',MTLVFM)
      NDIG = NDSAVE
   END FUNCTION FMLNE_IMQI

   FUNCTION FMLNE_ZMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE,L1,L2
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL ZMREAL(MA%MZM,MULVFM)
      L1 = FMCOMP(MTLVFM,'NE',MULVFM)
      CALL FMI2M(0,MTLVFM)
      CALL ZMIMAG(MA%MZM,MULVFM)
      L2 = FMCOMP(MTLVFM,'NE',MULVFM)
      RETURN_VALUE = L1.OR.L2
   END FUNCTION FMLNE_ZMQI

   FUNCTION FMLGT_QIFM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MTLVFM,'GT',MA%MFM)
   END FUNCTION FMLGT_QIFM

   FUNCTION FMLGT_QIIM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: IMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      RETURN_VALUE = IMCOMP(MTLVIM,'GT',MA%MIM)
   END FUNCTION FMLGT_QIIM

   FUNCTION FMLGT_FMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MA%MFM,'GT',MTLVFM)
   END FUNCTION FMLGT_FMQI

   FUNCTION FMLGT_IMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTEGER :: KA,NDSAVE
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FM_UNDEF_INP(MA)
      NDSAVE = NDIG
      KA = MA%MIM%MP(2)
      NDIG = MAX(KA+NGRD52,NDIG)
      CALL FMQI2M(D,MTLVFM)
      CALL IMI2FM(MA%MIM,MULVFM)
      RETURN_VALUE = FMCOMP(MULVFM,'GT',MTLVFM)
      NDIG = NDSAVE
   END FUNCTION FMLGT_IMQI

   FUNCTION FMLGE_QIFM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MTLVFM,'GE',MA%MFM)
   END FUNCTION FMLGE_QIFM

   FUNCTION FMLGE_QIIM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: IMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      RETURN_VALUE = IMCOMP(MTLVIM,'GE',MA%MIM)
   END FUNCTION FMLGE_QIIM

   FUNCTION FMLGE_FMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MA%MFM,'GE',MTLVFM)
   END FUNCTION FMLGE_FMQI

   FUNCTION FMLGE_IMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTEGER :: KA,NDSAVE
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FM_UNDEF_INP(MA)
      NDSAVE = NDIG
      KA = MA%MIM%MP(2)
      NDIG = MAX(KA+NGRD52,NDIG)
      CALL FMQI2M(D,MTLVFM)
      CALL IMI2FM(MA%MIM,MULVFM)
      RETURN_VALUE = FMCOMP(MULVFM,'GE',MTLVFM)
      NDIG = NDSAVE
   END FUNCTION FMLGE_IMQI

   FUNCTION FMLLT_QIFM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MTLVFM,'LT',MA%MFM)
   END FUNCTION FMLLT_QIFM

   FUNCTION FMLLT_QIIM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: IMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      RETURN_VALUE = IMCOMP(MTLVIM,'LT',MA%MIM)
   END FUNCTION FMLLT_QIIM

   FUNCTION FMLLT_FMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MA%MFM,'LT',MTLVFM)
   END FUNCTION FMLLT_FMQI

   FUNCTION FMLLT_IMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTEGER :: KA,NDSAVE
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FM_UNDEF_INP(MA)
      NDSAVE = NDIG
      KA = MA%MIM%MP(2)
      NDIG = MAX(KA+NGRD52,NDIG)
      CALL FMQI2M(D,MTLVFM)
      CALL IMI2FM(MA%MIM,MULVFM)
      RETURN_VALUE = FMCOMP(MULVFM,'LT',MTLVFM)
      NDIG = NDSAVE
   END FUNCTION FMLLT_IMQI

   FUNCTION FMLLE_QIFM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MTLVFM,'LE',MA%MFM)
   END FUNCTION FMLLE_QIFM

   FUNCTION FMLLE_QIIM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: IMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      RETURN_VALUE = IMCOMP(MTLVIM,'LE',MA%MIM)
   END FUNCTION FMLLE_QIIM

   FUNCTION FMLLE_FMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (FM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      RETURN_VALUE = FMCOMP(MA%MFM,'LE',MTLVFM)
   END FUNCTION FMLLE_FMQI

   FUNCTION FMLLE_IMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      LOGICAL :: RETURN_VALUE
      LOGICAL, EXTERNAL :: FMCOMP
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTEGER :: KA,NDSAVE
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM
      CALL FM_UNDEF_INP(MA)
      NDSAVE = NDIG
      KA = MA%MIM%MP(2)
      NDIG = MAX(KA+NGRD52,NDIG)
      CALL FMQI2M(D,MTLVFM)
      CALL IMI2FM(MA%MIM,MULVFM)
      RETURN_VALUE = FMCOMP(MULVFM,'LE',MTLVFM)
      NDIG = NDSAVE
   END FUNCTION FMLLE_IMQI

   FUNCTION FMADD_QIFM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMADD(MTLVFM,MA%MFM,RETURN_VALUE%MFM)
   END FUNCTION FMADD_QIFM

   FUNCTION FMADD_QIIM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      CALL IMADD(MTLVIM,MA%MIM,RETURN_VALUE%MIM)
   END FUNCTION FMADD_QIIM

   FUNCTION FMADD_QIZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      CALL ZMADD(MTLVZM,MA%MZM,RETURN_VALUE%MZM)
   END FUNCTION FMADD_QIZM

   FUNCTION FMADD_FMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMADD(MA%MFM,MTLVFM,RETURN_VALUE%MFM)
   END FUNCTION FMADD_FMQI

   FUNCTION FMADD_IMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: RETURN_VALUE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      CALL IMADD(MA%MIM,MTLVIM,RETURN_VALUE%MIM)
   END FUNCTION FMADD_IMQI

   FUNCTION FMADD_ZMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      CALL ZMADD(MA%MZM,MTLVZM,RETURN_VALUE%MZM)
   END FUNCTION FMADD_ZMQI

   FUNCTION FMADD_QIFM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL FMADD(MTLVFM,MA(J)%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMADD_QIFM1

   FUNCTION FMADD_QIIM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, N
         CALL IMADD(MTLVIM,MA(J)%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMADD_QIIM1

   FUNCTION FMADD_FMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMADD(MA%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMADD_FMQI1

   FUNCTION FMADD_FM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL FMADD(MA(J)%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMADD_FM1QI

   FUNCTION FMADD_QI1FM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMADD(MTLVFM,MA%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMADD_QI1FM

   FUNCTION FMADD_FM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J)%MFM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMADD(MA(J)%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMADD_FM1QI1

   FUNCTION FMADD_QI1FM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J)%MFM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMADD(MTLVFM,MA(J)%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMADD_QI1FM1

   FUNCTION FMADD_QIFM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMADD(MTLVFM,MA(J,K)%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_QIFM2

   FUNCTION FMADD_QIIM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMADD(MTLVIM,MA(J,K)%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_QIIM2

   FUNCTION FMADD_FMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMADD(MA%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_FMQI2

   FUNCTION FMADD_FM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMADD(MA(J,K)%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_FM2QI

   FUNCTION FMADD_QI2FM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMADD(MTLVFM,MA%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_QI2FM

   FUNCTION FMADD_FM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MFM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMADD(MA(J,K)%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_FM2QI2

   FUNCTION FMADD_QI2FM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MFM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMADD(MTLVFM,MA(J,K)%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_QI2FM2

   FUNCTION FMADD_IMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMADD(MA%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMADD_IMQI1

   FUNCTION FMADD_IM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, N
         CALL IMADD(MA(J)%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMADD_IM1QI

   FUNCTION FMADD_QI1IM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMADD(MTLVIM,MA%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMADD_QI1IM

   FUNCTION FMADD_IM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J)%MIM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMADD(MA(J)%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMADD_IM1QI1

   FUNCTION FMADD_QI1IM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J)%MIM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMADD(MTLVIM,MA(J)%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMADD_QI1IM1

   FUNCTION FMADD_IMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMADD(MA%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_IMQI2

   FUNCTION FMADD_IM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMADD(MA(J,K)%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_IM2QI

   FUNCTION FMADD_QI2IM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMADD(MTLVIM,MA%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_QI2IM

   FUNCTION FMADD_IM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MIM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMADD(MA(J,K)%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_IM2QI2

   FUNCTION FMADD_QI2IM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MIM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMADD(MTLVIM,MA(J,K)%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_QI2IM2

   FUNCTION FMADD_QIZM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, N
         CALL ZMADD(MTLVZM,MA(J)%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMADD_QIZM1

   FUNCTION FMADD_ZMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMADD(MA%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMADD_ZMQI1

   FUNCTION FMADD_ZM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, N
         CALL ZMADD(MA(J)%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMADD_ZM1QI

   FUNCTION FMADD_QI1ZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMADD(MTLVZM,MA%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMADD_QI1ZM

   FUNCTION FMADD_ZM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J)%MZM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMADD(MA(J)%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMADD_ZM1QI1

   FUNCTION FMADD_QI1ZM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J)%MZM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMADD(MTLVZM,MA(J)%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMADD_QI1ZM1

   FUNCTION FMADD_QIZM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL ZMADD(MTLVZM,MA(J,K)%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_QIZM2

   FUNCTION FMADD_ZMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMADD(MA%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_ZMQI2

   FUNCTION FMADD_ZM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL ZMADD(MA(J,K)%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_ZM2QI

   FUNCTION FMADD_QI2ZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMADD(MTLVZM,MA%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_QI2ZM

   FUNCTION FMADD_ZM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J,K)%MZM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMADD(MA(J,K)%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_ZM2QI2

   FUNCTION FMADD_QI2ZM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J,K)%MZM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMADD(MTLVZM,MA(J,K)%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMADD_QI2ZM2

   FUNCTION FMSUB_QIFM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMSUB(MTLVFM,MA%MFM,RETURN_VALUE%MFM)
   END FUNCTION FMSUB_QIFM

   FUNCTION FMSUB_QIIM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVFM)
      CALL IMSUB(MTLVFM,MA%MIM,RETURN_VALUE%MIM)
   END FUNCTION FMSUB_QIIM

   FUNCTION FMSUB_QIZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      CALL ZMSUB(MTLVZM,MA%MZM,RETURN_VALUE%MZM)
   END FUNCTION FMSUB_QIZM

   FUNCTION FMSUB_FMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMSUB(MA%MFM,MTLVFM,RETURN_VALUE%MFM)
   END FUNCTION FMSUB_FMQI

   FUNCTION FMSUB_IMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: RETURN_VALUE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      CALL IMSUB(MA%MIM,MTLVIM,RETURN_VALUE%MIM)
   END FUNCTION FMSUB_IMQI

   FUNCTION FMSUB_ZMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      CALL ZMSUB(MA%MZM,MTLVZM,RETURN_VALUE%MZM)
   END FUNCTION FMSUB_ZMQI

   FUNCTION FMSUB_QIFM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL FMSUB(MTLVFM,MA(J)%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMSUB_QIFM1

   FUNCTION FMSUB_QIIM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL IMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL IMSUB(MTLVFM,MA(J)%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMSUB_QIIM1

   FUNCTION FMSUB_FMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMSUB(MA%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMSUB_FMQI1

   FUNCTION FMSUB_FM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL FMSUB(MA(J)%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMSUB_FM1QI

   FUNCTION FMSUB_QI1FM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMSUB(MTLVFM,MA%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMSUB_QI1FM

   FUNCTION FMSUB_FM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J)%MFM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMSUB(MA(J)%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMSUB_FM1QI1

   FUNCTION FMSUB_QI1FM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J)%MFM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMSUB(MTLVFM,MA(J)%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMSUB_QI1FM1

   FUNCTION FMSUB_QIFM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMSUB(MTLVFM,MA(J,K)%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_QIFM2

   FUNCTION FMSUB_QIIM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMSUB(MTLVFM,MA(J,K)%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_QIIM2

   FUNCTION FMSUB_FMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMSUB(MA%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_FMQI2

   FUNCTION FMSUB_FM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMSUB(MA(J,K)%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_FM2QI

   FUNCTION FMSUB_QI2FM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMSUB(MTLVFM,MA%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_QI2FM

   FUNCTION FMSUB_FM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MFM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMSUB(MA(J,K)%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_FM2QI2

   FUNCTION FMSUB_QI2FM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MFM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMSUB(MTLVFM,MA(J,K)%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_QI2FM2

   FUNCTION FMSUB_IMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMSUB(MA%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMSUB_IMQI1

   FUNCTION FMSUB_IM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, N
         CALL IMSUB(MA(J)%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMSUB_IM1QI

   FUNCTION FMSUB_QI1IM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMSUB(MTLVIM,MA%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMSUB_QI1IM

   FUNCTION FMSUB_IM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J)%MIM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMSUB(MA(J)%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMSUB_IM1QI1

   FUNCTION FMSUB_QI1IM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J)%MIM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMSUB(MTLVIM,MA(J)%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMSUB_QI1IM1

   FUNCTION FMSUB_IMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMSUB(MA%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_IMQI2

   FUNCTION FMSUB_IM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMSUB(MA(J,K)%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_IM2QI

   FUNCTION FMSUB_QI2IM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMSUB(MTLVIM,MA%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_QI2IM

   FUNCTION FMSUB_IM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MIM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMSUB(MA(J,K)%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_IM2QI2

   FUNCTION FMSUB_QI2IM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MIM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMSUB(MTLVIM,MA(J,K)%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_QI2IM2

   FUNCTION FMSUB_QIZM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, N
         CALL ZMSUB(MTLVZM,MA(J)%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMSUB_QIZM1

   FUNCTION FMSUB_ZMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMSUB(MA%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMSUB_ZMQI1

   FUNCTION FMSUB_ZM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, N
         CALL ZMSUB(MA(J)%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMSUB_ZM1QI

   FUNCTION FMSUB_QI1ZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMSUB(MTLVZM,MA%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMSUB_QI1ZM

   FUNCTION FMSUB_ZM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J)%MZM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMSUB(MA(J)%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMSUB_ZM1QI1

   FUNCTION FMSUB_QI1ZM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J)%MZM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMSUB(MTLVZM,MA(J)%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMSUB_QI1ZM1

   FUNCTION FMSUB_QIZM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL ZMSUB(MTLVZM,MA(J,K)%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_QIZM2

   FUNCTION FMSUB_ZMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMSUB(MA%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_ZMQI2

   FUNCTION FMSUB_ZM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL ZMSUB(MA(J,K)%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_ZM2QI

   FUNCTION FMSUB_QI2ZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMSUB(MTLVZM,MA%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_QI2ZM

   FUNCTION FMSUB_ZM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J,K)%MZM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMSUB(MA(J,K)%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_ZM2QI2

   FUNCTION FMSUB_QI2ZM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J,K)%MZM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMSUB(MTLVZM,MA(J,K)%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMSUB_QI2ZM2

   FUNCTION FMMPY_QIFM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMMPY(MTLVFM,MA%MFM,RETURN_VALUE%MFM)
   END FUNCTION FMMPY_QIFM

   FUNCTION FMMPY_QIIM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVFM)
      CALL IMMPY(MTLVFM,MA%MIM,RETURN_VALUE%MIM)
   END FUNCTION FMMPY_QIIM

   FUNCTION FMMPY_QIZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      CALL ZMMPY(MTLVZM,MA%MZM,RETURN_VALUE%MZM)
   END FUNCTION FMMPY_QIZM

   FUNCTION FMMPY_FMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMMPY(MA%MFM,MTLVFM,RETURN_VALUE%MFM)
   END FUNCTION FMMPY_FMQI

   FUNCTION FMMPY_IMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: RETURN_VALUE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      CALL IMMPY(MA%MIM,MTLVIM,RETURN_VALUE%MIM)
   END FUNCTION FMMPY_IMQI

   FUNCTION FMMPY_ZMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      CALL ZMMPY(MA%MZM,MTLVZM,RETURN_VALUE%MZM)
   END FUNCTION FMMPY_ZMQI

   FUNCTION FMMPY_QIFM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL FMMPY(MTLVFM,MA(J)%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMMPY_QIFM1

   FUNCTION FMMPY_QIIM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL IMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL IMMPY(MTLVFM,MA(J)%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMMPY_QIIM1

   FUNCTION FMMPY_FMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMMPY(MA%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMMPY_FMQI1

   FUNCTION FMMPY_FM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL FMMPY(MA(J)%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMMPY_FM1QI

   FUNCTION FMMPY_QI1FM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMMPY(MTLVFM,MA%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMMPY_QI1FM

   FUNCTION FMMPY_FM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J)%MFM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMMPY(MA(J)%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMMPY_FM1QI1

   FUNCTION FMMPY_QI1FM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J)%MFM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMMPY(MTLVFM,MA(J)%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMMPY_QI1FM1

   FUNCTION FMMPY_QIFM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMMPY(MTLVFM,MA(J,K)%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_QIFM2

   FUNCTION FMMPY_QIIM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMMPY(MTLVFM,MA(J,K)%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_QIIM2

   FUNCTION FMMPY_FMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMMPY(MA%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_FMQI2

   FUNCTION FMMPY_FM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMMPY(MA(J,K)%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_FM2QI

   FUNCTION FMMPY_QI2FM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMMPY(MTLVFM,MA%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_QI2FM

   FUNCTION FMMPY_FM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MFM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMMPY(MA(J,K)%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_FM2QI2

   FUNCTION FMMPY_QI2FM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MFM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMMPY(MTLVFM,MA(J,K)%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_QI2FM2

   FUNCTION FMMPY_IMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMMPY(MA%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMMPY_IMQI1

   FUNCTION FMMPY_IM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, N
         CALL IMMPY(MA(J)%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMMPY_IM1QI

   FUNCTION FMMPY_QI1IM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMMPY(MTLVIM,MA%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMMPY_QI1IM

   FUNCTION FMMPY_IM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J)%MIM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMMPY(MA(J)%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMMPY_IM1QI1

   FUNCTION FMMPY_QI1IM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J)%MIM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMMPY(MTLVIM,MA(J)%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMMPY_QI1IM1

   FUNCTION FMMPY_IMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMMPY(MA%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_IMQI2

   FUNCTION FMMPY_IM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMMPY(MA(J,K)%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_IM2QI

   FUNCTION FMMPY_QI2IM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMMPY(MTLVIM,MA%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_QI2IM

   FUNCTION FMMPY_IM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MIM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMMPY(MA(J,K)%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_IM2QI2

   FUNCTION FMMPY_QI2IM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MIM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMMPY(MTLVIM,MA(J,K)%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_QI2IM2

   FUNCTION FMMPY_QIZM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, N
         CALL ZMMPY(MTLVZM,MA(J)%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMMPY_QIZM1

   FUNCTION FMMPY_ZMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMMPY(MA%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMMPY_ZMQI1

   FUNCTION FMMPY_ZM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, N
         CALL ZMMPY(MA(J)%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMMPY_ZM1QI

   FUNCTION FMMPY_QI1ZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMMPY(MTLVZM,MA%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMMPY_QI1ZM

   FUNCTION FMMPY_ZM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J)%MZM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMMPY(MA(J)%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMMPY_ZM1QI1

   FUNCTION FMMPY_QI1ZM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J)%MZM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMMPY(MTLVZM,MA(J)%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMMPY_QI1ZM1

   FUNCTION FMMPY_QIZM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL ZMMPY(MTLVZM,MA(J,K)%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_QIZM2

   FUNCTION FMMPY_ZMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMMPY(MA%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_ZMQI2

   FUNCTION FMMPY_ZM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL ZMMPY(MA(J,K)%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_ZM2QI

   FUNCTION FMMPY_QI2ZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMMPY(MTLVZM,MA%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_QI2ZM

   FUNCTION FMMPY_ZM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J,K)%MZM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMMPY(MA(J,K)%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_ZM2QI2

   FUNCTION FMMPY_QI2ZM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J,K)%MZM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMMPY(MTLVZM,MA(J,K)%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMMPY_QI2ZM2

   FUNCTION FMDIV_QIFM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMDIV(MTLVFM,MA%MFM,RETURN_VALUE%MFM)
   END FUNCTION FMDIV_QIFM

   FUNCTION FMDIV_QIIM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVFM)
      CALL IMDIV(MTLVFM,MA%MIM,RETURN_VALUE%MIM)
   END FUNCTION FMDIV_QIIM

   FUNCTION FMDIV_QIZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      CALL ZMDIV(MTLVZM,MA%MZM,RETURN_VALUE%MZM)
   END FUNCTION FMDIV_QIZM

   FUNCTION FMDIV_FMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMDIV(MA%MFM,MTLVFM,RETURN_VALUE%MFM)
   END FUNCTION FMDIV_FMQI

   FUNCTION FMDIV_IMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: RETURN_VALUE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      CALL IMDIV(MA%MIM,MTLVIM,RETURN_VALUE%MIM)
   END FUNCTION FMDIV_IMQI

   FUNCTION FMDIV_ZMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      CALL ZMDIV(MA%MZM,MTLVZM,RETURN_VALUE%MZM)
   END FUNCTION FMDIV_ZMQI

   FUNCTION FMDIV_QIFM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL FMDIV(MTLVFM,MA(J)%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMDIV_QIFM1

   FUNCTION FMDIV_QIIM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL IMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL IMDIV(MTLVFM,MA(J)%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMDIV_QIIM1

   FUNCTION FMDIV_FMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMDIV(MA%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMDIV_FMQI1

   FUNCTION FMDIV_FM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, N
         CALL FMDIV(MA(J)%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMDIV_FM1QI

   FUNCTION FMDIV_QI1FM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMDIV(MTLVFM,MA%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMDIV_QI1FM

   FUNCTION FMDIV_FM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J)%MFM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMDIV(MA(J)%MFM,MTLVFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMDIV_FM1QI1

   FUNCTION FMDIV_QI1FM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (FM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J)%MFM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL FMDIV(MTLVFM,MA(J)%MFM,RETURN_VALUE(J)%MFM)
      ENDDO
   END FUNCTION FMDIV_QI1FM1

   FUNCTION FMDIV_QIFM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMDIV(MTLVFM,MA(J,K)%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_QIFM2

   FUNCTION FMDIV_QIIM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMDIV(MTLVFM,MA(J,K)%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_QIIM2

   FUNCTION FMDIV_FMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMDIV(MA%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_FMQI2

   FUNCTION FMDIV_FM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMDIV(MA(J,K)%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_FM2QI

   FUNCTION FMDIV_QI2FM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMDIV(MTLVFM,MA%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_QI2FM

   FUNCTION FMDIV_FM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      TYPE (FM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MFM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMDIV(MA(J,K)%MFM,MTLVFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_FM2QI2

   FUNCTION FMDIV_QI2FM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (FM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL FMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MFM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL FMDIV(MTLVFM,MA(J,K)%MFM,RETURN_VALUE(J,K)%MFM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_QI2FM2

   FUNCTION FMDIV_IMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMDIV(MA%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMDIV_IMQI1

   FUNCTION FMDIV_IM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, N
         CALL IMDIV(MA(J)%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMDIV_IM1QI

   FUNCTION FMDIV_QI1IM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMDIV(MTLVIM,MA%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMDIV_QI1IM

   FUNCTION FMDIV_IM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J)%MIM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMDIV(MA(J)%MIM,MTLVIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMDIV_IM1QI1

   FUNCTION FMDIV_QI1IM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (IM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J)%MIM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      DO J = 1, N
         CALL IMQI2M(D(J),MTLVIM)
         CALL IMDIV(MTLVIM,MA(J)%MIM,RETURN_VALUE(J)%MIM)
      ENDDO
   END FUNCTION FMDIV_QI1IM1

   FUNCTION FMDIV_IMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMDIV(MA%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_IMQI2

   FUNCTION FMDIV_IM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMDIV(MA(J,K)%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_IM2QI

   FUNCTION FMDIV_QI2IM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMDIV(MTLVIM,MA%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_QI2IM

   FUNCTION FMDIV_IM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      TYPE (IM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MIM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMDIV(MA(J,K)%MIM,MTLVIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_IM2QI2

   FUNCTION FMDIV_QI2IM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (IM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL IMST2M(' UNKNOWN ',RETURN_VALUE(J,K)%MIM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL IMQI2M(D(J,K),MTLVIM)
            CALL IMDIV(MTLVIM,MA(J,K)%MIM,RETURN_VALUE(J,K)%MIM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_QI2IM2

   FUNCTION FMDIV_QIZM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, N
         CALL ZMDIV(MTLVZM,MA(J)%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMDIV_QIZM1

   FUNCTION FMDIV_ZMQI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMDIV(MA%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMDIV_ZMQI1

   FUNCTION FMDIV_ZM1QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, N
         CALL ZMDIV(MA(J)%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMDIV_ZM1QI

   FUNCTION FMDIV_QI1ZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMDIV(MTLVZM,MA%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMDIV_QI1ZM

   FUNCTION FMDIV_ZM1QI1(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA)) :: RETURN_VALUE
      INTEGER :: J,N
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J)%MZM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMDIV(MA(J)%MZM,MTLVZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMDIV_ZM1QI1

   FUNCTION FMDIV_QI1ZM1(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:) :: D
      TYPE (ZM), DIMENSION(SIZE(D)) :: RETURN_VALUE
      INTEGER :: J,N
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA) /= SIZE(D)) THEN
          DO J = 1, SIZE(MA)
             CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J)%MZM)
          ENDDO
          RETURN
      ENDIF
      N = SIZE(D)
      CALL FMI2M(0,MULVFM)
      DO J = 1, N
         CALL FMQI2M(D(J),MTLVFM)
         CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
         CALL ZMDIV(MTLVZM,MA(J)%MZM,RETURN_VALUE(J)%MZM)
      ENDDO
   END FUNCTION FMDIV_QI1ZM1

   FUNCTION FMDIV_QIZM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL ZMDIV(MTLVZM,MA(J,K)%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_QIZM2

   FUNCTION FMDIV_ZMQI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMDIV(MA%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_ZMQI2

   FUNCTION FMDIV_ZM2QI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL ZMDIV(MA(J,K)%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_ZM2QI

   FUNCTION FMDIV_QI2ZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(D,DIM=1)
         DO K = 1, SIZE(D,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMDIV(MTLVZM,MA%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_QI2ZM

   FUNCTION FMDIV_ZM2QI2(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      TYPE (ZM), DIMENSION(SIZE(MA,DIM=1),SIZE(MA,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J,K)%MZM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMDIV(MA(J,K)%MZM,MTLVZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_ZM2QI2

   FUNCTION FMDIV_QI2ZM2(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM), DIMENSION(:,:) :: MA
      INTEGER (QUAD_INT), DIMENSION(:,:) :: D
      TYPE (ZM), DIMENSION(SIZE(D,DIM=1),SIZE(D,DIM=2)) :: RETURN_VALUE
      INTEGER :: J,K
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      IF (SIZE(MA,DIM=1) /= SIZE(D,DIM=1) .OR. SIZE(MA,DIM=2) /= SIZE(D,DIM=2)) THEN
          DO J = 1, SIZE(MA,DIM=1)
             DO K = 1, SIZE(MA,DIM=2)
                CALL ZMST2M(' UNKNOWN + UNKNOWN i ',RETURN_VALUE(J,K)%MZM)
             ENDDO
          ENDDO
          RETURN
      ENDIF
      CALL FMI2M(0,MULVFM)
      DO J = 1, SIZE(MA,DIM=1)
         DO K = 1, SIZE(MA,DIM=2)
            CALL FMQI2M(D(J,K),MTLVFM)
            CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
            CALL ZMDIV(MTLVZM,MA(J,K)%MZM,RETURN_VALUE(J,K)%MZM)
         ENDDO
      ENDDO
   END FUNCTION FMDIV_QI2ZM2

   FUNCTION FMPWR_QIFM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMPWR(MTLVFM,MA%MFM,RETURN_VALUE%MFM)
   END FUNCTION FMPWR_QIFM

   FUNCTION FMPWR_QIIM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVFM)
      CALL IMPWR(MTLVFM,MA%MIM,RETURN_VALUE%MIM)
   END FUNCTION FMPWR_QIIM

   FUNCTION FMPWR_QIZM(D,MA)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: D,MA
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      CALL ZMPWR(MTLVZM,MA%MZM,RETURN_VALUE%MZM)
   END FUNCTION FMPWR_QIZM

   FUNCTION FMPWR_FMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (FM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMPWR(MA%MFM,MTLVFM,RETURN_VALUE%MFM)
   END FUNCTION FMPWR_FMQI

   FUNCTION FMPWR_IMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (IM) :: RETURN_VALUE
      TYPE (IM) :: MA
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVIM
      CALL FM_UNDEF_INP(MA)
      CALL IMQI2M(D,MTLVIM)
      CALL IMPWR(MA%MIM,MTLVIM,RETURN_VALUE%MIM)
   END FUNCTION FMPWR_IMQI

   FUNCTION FMPWR_ZMQI(MA,D)     RESULT (RETURN_VALUE)
      USE FMVALS
      IMPLICIT NONE
      TYPE (ZM) :: MA,RETURN_VALUE
      INTEGER (QUAD_INT) :: D
      INTENT (IN) :: MA,D
      TYPE(MULTI), SAVE :: MTLVFM,MULVFM,MTLVZM(2)
      CALL FM_UNDEF_INP(MA)
      CALL FMQI2M(D,MTLVFM)
      CALL FMI2M(0,MULVFM)
      CALL ZMCMPX(MTLVFM,MULVFM,MTLVZM)
      CALL ZMPWR(MA%MZM,MTLVZM,RETURN_VALUE%MZM)
   END FUNCTION FMPWR_ZMQI

 END MODULE FM_QUAD_INT