static void mg3P(double **u, double *v, double **r, double a[4], double c[4], int n1, int n2, int n3, int k) { /*-------------------------------------------------------------------- c-------------------------------------------------------------------*/ /*-------------------------------------------------------------------- c multigrid V-cycle routine c-------------------------------------------------------------------*/ int j; /*-------------------------------------------------------------------- c down cycle. c restrict the residual from the find grid to the coarse c-------------------------------------------------------------------*/ for (k = lt; k >= lb+1; k--) { j = k-1; rprj3(r[k], m1[k], m2[k], m3[k], r[j], m1[j], m2[j], m3[j], k); } k = lb; /*-------------------------------------------------------------------- c compute an approximate solution on the coarsest grid c-------------------------------------------------------------------*/ zero3(u[k], m1[k], m2[k], m3[k]); psinv(r[k], u[k], m1[k], m2[k], m3[k], c, k); for (k = lb+1; k <= lt-1; k++) { j = k-1; /*-------------------------------------------------------------------- c prolongate from level k-1 to k c-------------------------------------------------------------------*/ zero3(u[k], m1[k], m2[k], m3[k]); interp(u[j], m1[j], m2[j], m3[j], u[k], m1[k], m2[k], m3[k], k); /*-------------------------------------------------------------------- c compute residual for level k c-------------------------------------------------------------------*/ resid(u[k], r[k], r[k], m1[k], m2[k], m3[k], a, k); /*-------------------------------------------------------------------- c apply smoother c-------------------------------------------------------------------*/ psinv(r[k], u[k], m1[k], m2[k], m3[k], c, k); } j = lt - 1; k = lt; interp(u[j], m1[j], m2[j], m3[j], u[lt], n1, n2, n3, k); resid(u[lt], v, r[lt], n1, n2, n3, a, k); psinv(r[lt], u[lt], n1, n2, n3, c, k); }
/* Polar Stereographic inverse equations--mapping line,sample to x,y to lat/long ---------------------------------------------------------------------*/ int LSpsinv ( double s, /* I: sample */ double l, /* I: line */ double *lon, /* O: longitude (degrees) */ double *lat /* O: latitude (degrees) */ ) { int ret = 0; /* return value */ double x, y; /* x,y projection coords */ double dl, dp, dy, dx; /* delta line, sample and x,y values */ /* Calculate the x,y from the line,sample */ dl = (l + 0.5) * pixel_size; dp = (s + 0.5) * pixel_size; dy = (dp * sin_orien) - (dl * cos_orien); dx = (dp * cos_orien) + (dl * sin_orien); y = ul_corner[1] + dy; x = ul_corner[0] + dx; /* Do the inverse mapping */ ret = psinv (x, y, lon, lat); if (ret != 0) { printf ("Error in the inverse PS mapping"); return (ret); } /* Convert lat/long to degrees */ *lat *= R2D; *lon *= R2D; return(0); }
/** \brief Invert (in place) a symmetric real matrix, V -> Inv(V). The input matrix V is symmetric (V[i,j] = V[j,i]). \param a = array containing a symmetric input matrix. This is converted to the inverse matrix. \param n = dimension of the system (dim(v)=n*n) \return: 0 -> normal exit 1 -> input matrix not positive definite */ int G_math_psinv(double **a,int n) { return psinv( a[0], n); }