SUBROUTINE FKINV
*-- Author : S.Burke / J.V. Morris
      SUBROUTINE FKINV(MES,CMES,GMES,IERR)
**********************************************************************                                        
*                                                                    *                                        
* Invert the measurement covariance matrix                           *                                        
*                                                                    *                                        
* ERROR CONDITIONS;                                                  *                                        
*       IERR =   0 ; normal termination                              *                                        
*   ->  IERR = 107 ; measurement covariance not positive definite    *                                        
*                                                                    *                                        
*   ->  Fatal error                                                  *                                        
*                                                                    *                                        
**********************************************************************                                        
                                                                        
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)                               
                                                                        
      PARAMETER (IUTIL=1,IROUT=3)                                       
*KEEP,FKECODE.                                                                                                
      PARAMETER (IWARN=0,IFATAL=1,IFPRO=2,IFFLT=3,IFSMO=4,IFPRS=5,      
     &           IFPAS=6,IFPAF=7)                                       
      PARAMETER (IINF1=1,IINF2=2,IINF3=3,IINV=4,IDONE=5)                
      PARAMETER (IICV=6,IMCV=7,IOCV=11,IRCV=12,IOVCV=13,                
     &           ITHGP2=16,ITHG1=17)                                    
      PARAMETER (IFREE=20,IFREE1=30,IFREE2=40,IFREE3=50)                
*KEND.                                                                                                        
                                                                        
      DIMENSION CMES(2,2),GMES(2,2)                                     
                                                                        
**********************************************************************                                        
                                                                        
      IERR = 0                                                          
                                                                        
      IF (MES.EQ.2) THEN                                                
         DET = (CMES(1,1)*CMES(2,2) - CMES(2,1)*CMES(2,1))              
         IF (DET.LE.0.D0) THEN                                          
            CALL FKERR(IUTIL,IROUT,IFATAL,IMCV,IERR)
            RETURN                                                      
         ENDIF                                                          
         DET = 1.D0/DET                                                 
         GMES(1,1) =  CMES(2,2)*DET                                     
         GMES(2,1) = -CMES(2,1)*DET                                     
         GMES(2,2) =  CMES(1,1)*DET                                     
      ELSE                                                              
         IF (CMES(1,1).LE.0.D0) THEN                                    
            CALL FKERR(IUTIL,IROUT,IFATAL,IMCV,IERR)
            RETURN                                                      
         ENDIF                                                          
         GMES(1,1) = 1.D0/CMES(1,1)                                     
      ENDIF                                                             
                                                                        
      RETURN                                                            
      END                                                               
*