GRASS Programmer's Manual  6.5.svn(2012)-r51648
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
atovm.c
Go to the documentation of this file.
00001 /*  atovm.c    CCMATH mathematics library source code.
00002  *
00003  *  Copyright (C)  2000   Daniel A. Atkinson    All rights reserved.
00004  *  This code may be redistributed under the terms of the GNU library
00005  *  public license (LGPL). ( See the lgpl.license file for details.)
00006  * ------------------------------------------------------------------------
00007  */
00008 void atovm(double *v, int n)
00009 {
00010     double *p0, *q0, *p, *q, *qq;
00011 
00012     double h, s;
00013 
00014     int i, j, k, mm;
00015 
00016     q0 = v + n * n - 1;
00017     *q0 = 1.;
00018     q0 -= n + 1;
00019     p0 = v + n * n - n - n - 1;
00020     for (i = n - 2, mm = 1; i >= 0; --i, p0 -= n + 1, q0 -= n + 1, ++mm) {
00021         if (i && *(p0 - 1) != 0.) {
00022             for (j = 0, p = p0, h = 1.; j < mm; ++j, ++p)
00023                 h += *p * *p;
00024             h = *(p0 - 1);
00025             *q0 = 1. - h;
00026             for (j = 0, q = q0 + n, p = p0; j < mm; ++j, q += n)
00027                 *q = -h * *p++;
00028             for (k = i + 1, q = q0 + 1; k < n; ++k) {
00029                 for (j = 0, qq = q + n, p = p0, s = 0.; j < mm; ++j, qq += n)
00030                     s += *qq * *p++;
00031                 s *= h;
00032                 for (j = 0, qq = q + n, p = p0; j < mm; ++j, qq += n)
00033                     *qq -= s * *p++;
00034                 *q++ = -s;
00035             }
00036         }
00037         else {
00038             *q0 = 1.;
00039             for (j = 0, p = q0 + 1, q = q0 + n; j < mm; ++j, q += n)
00040                 *q = *p++ = 0.;
00041         }
00042     }
00043 }