

#ifndef MATRICE_H
        #define MATRICE_H

        typedef struct {
                int nlig;
                int ncol;
                double *valeur;
        } matrice;

        #define Fabs(a)   ( ((a)<0.0) ? (-(a)) : (a) )
        #define Max(a,b)  ( ((a)>(b)) ? (a) : (b) )
        #define PRECISION 1.0e-64
        #define e(A,i,j)  (*(A.valeur + (i)*(A.ncol) + (j) ))

        /*--- dimensions for filter */
        #define NB_STATE           7 /* x,y,z,vcn,vce,du,dpsi */
        #define NB_INPUT           3 /* yaw,pitch,speed */
        #define NB_OBS             1 /* tof to beacon i */
        #define NB_DATA_EST       60

        /*--- matrix P0/0 (except x and y) */
        #ifdef REAL_DATA_POST_PROCESSING
                #define INIT_DEPTH_VAR           0.1
                #define INIT_VC_VAR        2.5e-3
                #define INIT_DU_VAR        1e-4
                #define INIT_DPSI_VAR      1e-4
        #else
                #define INIT_DEPTH_VAR     0.1
                #define INIT_VC_VAR        9e-2
                #define INIT_DU_VAR        9e-2
                #define INIT_DPSI_VAR      1e-3
        #endif

        /*--- matrix Q */
        #ifdef REAL_DATA_POST_PROCESSING
                #define Qxy                5e-2
                #define Qz                 0.1
                #define Qvc                1e-5
                #define Qdu                5e-5
                #define Qdpsi              5e-6
        #else
                #define Qxy                5e-2
                #define Qz                 0.1
                #define Qvc                1e-6
                #define Qdu                1e-6
                #define Qdpsi              1e-6
        #endif

        /*--- sensor noise variance */
        #define YAW_VAR            6.85e-4 /* (1.5*pi/180)^2 */
        #define PITCH_VAR          3.05e-4 /* (1.0*pi/180)^2 */
        #define SPEED_VAR          2.50e-3 /* 0.05^2         */
        #define DEPTH_VAR          1.00e-4 /* 0.01^2         */
        #define TOF_VAR            2.50e-5 /* 0.005*0.005    */

        void init_matrices(void);
        double inv22(double *);
        void solve_syst(double *,double *);
        double Norme(double*,int);
        int mat_show(char *,matrice);
        int mat_prod(double *,double *,double *,int,int,int);
        int mat_transpose(double *,double *,int,int);
        int mat_copy(double *,double *,int,int);
        int mat_plus(double *,double *,double *,int,int);
        int mat_moins(double *,double *,double *,int,int);
        int mat_scal_prod(double *,int,int,double);
        int mat_unit(double *,int);

        int mat_new_S(matrice *,int,int);
        int mat_prod_S(matrice,matrice,matrice);
        int mat_transpose_S(matrice,matrice);
        int mat_copy_S(matrice,matrice);
        int mat_plus_S(matrice,matrice,matrice);
        int mat_moins_S(matrice,matrice,matrice);
        int mat_scal_prod_S(matrice,double);
        int mat_unit_S(matrice);

#endif
