|
GRASS Programmer's Manual
6.5.svn(2012)-r51648
|
00001 /* atou1.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 #include <stdlib.h> 00009 void atou1(double *a, int m, int n) 00010 { 00011 double *p0, *p, *q, *w; 00012 00013 int i, j, k, mm; 00014 00015 double s, h; 00016 00017 w = (double *)calloc(m, sizeof(double)); 00018 p0 = a + n * n - 1; 00019 i = n - 1; 00020 mm = m - n; 00021 if (mm == 0) { 00022 *p0 = 1.; 00023 p0 -= n + 1; 00024 --i; 00025 ++mm; 00026 } 00027 for (; i >= 0; --i, ++mm, p0 -= n + 1) { 00028 if (*p0 != 0.) { 00029 for (j = 0, p = p0 + n; j < mm; p += n) 00030 w[j++] = *p; 00031 h = *p0; 00032 *p0 = 1. - h; 00033 for (j = 0, p = p0 + n; j < mm; p += n) 00034 *p = -h * w[j++]; 00035 for (k = i + 1, q = p0 + 1; k < n; ++k) { 00036 for (j = 0, p = q + n, s = 0.; j < mm; p += n) 00037 s += w[j++] * *p; 00038 s *= h; 00039 for (j = 0, p = q + n; j < mm; p += n) 00040 *p -= s * w[j++]; 00041 *q++ = -s; 00042 } 00043 } 00044 else { 00045 *p0 = 1.; 00046 for (j = 0, p = p0 + n, q = p0 + 1; j < mm; ++j, p += n) 00047 *p = *q++ = 0.; 00048 } 00049 } 00050 free(w); 00051 }