/* nag_kalman_sqrt_filt_info_invar (g13edc) Example Program. * * Copyright 1993 Numerical Algorithms Group * * Mark 3, 1993 * Mark 7 revised, 2001. * Mark 8 revised, 2004. * */ #include #include #include #include #include #include typedef enum {read, print} ioflag; static int ex1(void); static int ex2(void); int main(void) { Integer exit_status_ex1=0; Integer exit_status_ex2=0; exit_status_ex1 = ex1(); exit_status_ex2 = ex2(); return exit_status_ex1 == 0 && exit_status_ex2 == 0 ? 0 : 1; } #define AINV(I,J) ainv[(I)*tdainv + J] #define QINV(I,J) qinv[(I)*tdqinv + J] #define RINV(I,J) rinv[(I)*tdrinv + J] #define T(I,J) t[(I)*tdt + J] #define AINVB(I,J) ainvb[(I)*tdainvb + J] #define C(I,J) c[(I)*tdc + J] static int ex1(void) { Integer exit_status=0, i, istep, j, m, n, p, tdainv, tdainvb, tdc, tdqinv; Integer tdrinv, tdt; NagError fail; double *ainv=0, *ainvb=0, *c=0, *qinv=0, *rinv=0, *rinvy=0, *t=0, tol, *x=0; double *z=0; INIT_FAIL(fail); Vprintf("nag_kalman_sqrt_filt_info_invar (g13edc) Example 1 Program " "Results\n"); /* Skip the heading in the data file */ Vscanf("%*[^\n]"); Vscanf("%ld%ld%ld%lf",&n,&m,&p,&tol); if (n>=1 || m>=1 || p>=1) { if ( !( ainv = NAG_ALLOC(n*n, double)) || !( qinv = NAG_ALLOC(m*m, double)) || !( rinv = NAG_ALLOC(p*p, double)) || !( t = NAG_ALLOC(n*n, double)) || !( ainvb = NAG_ALLOC(n*m, double)) || !( c = NAG_ALLOC(p*n, double)) || !( x = NAG_ALLOC(n, double)) || !( z = NAG_ALLOC(m, double)) || !( rinvy = NAG_ALLOC(p, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdainv = n; tdqinv = m; tdrinv = p; tdt = n; tdainvb = m; tdc = n; } else { Vprintf("Invalid n or m or p.\n"); exit_status = 1; return exit_status; } /* Read data */ for (i=0; i=1 || m>=1 || p>=1) { if ( !( ainv = NAG_ALLOC(n*n, double)) || !( ainvb = NAG_ALLOC(n*m, double)) || !( c = NAG_ALLOC(p*n, double)) || !( ainvu = NAG_ALLOC(n*n, double)) || !( ainvbu = NAG_ALLOC(n*m, double))|| !( qinv = NAG_ALLOC(m*m, double)) || !( rinv = NAG_ALLOC(p*p, double)) || !( t = NAG_ALLOC(n*n, double)) || !( x = NAG_ALLOC(n, double)) || !( z = NAG_ALLOC(n, double)) || !( rwork = NAG_ALLOC(n*n, double)) || !( tu = NAG_ALLOC(n*n, double)) || !( rinvy = NAG_ALLOC(p, double)) || !( ig = NAG_ALLOC(n*n, double)) || !( ih = NAG_ALLOC(n*n, double)) || !( cu = NAG_ALLOC(p*n, double)) || !( u = NAG_ALLOC(n*n, double)) || !( ux = NAG_ALLOC(n, double)) || !( diag = NAG_ALLOC(n, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdainv = n; tdainvb = m; tdc = n; tdainvu = n; tdainvbu = m; tdqinv = m; tdrinv = p; tdt = n; tdrwork = n; tdtu = n; tdig = n; tdih = n; tdcu = n; tdu = n; } else { Vprintf("Invalid n or m or p.\n"); exit_status = 1; return exit_status; } /* Read data */ mat_io(n, n, ainv, tdainv, read, ""); mat_io(p, n, c, tdc, read, ""); if (rinv) mat_io(p, p, rinv, tdrinv, read,""); mat_io(n, m, ainvb, tdainvb, read, ""); mat_io(m, m, qinv, tdqinv, read, ""); mat_io(n, n, t, tdt, read, ""); for (j=0; j