00001
00002
00003
00004
00005
00006
00007 #include <stdio.h>
00008 #include "lsutil.h"
00009
00010
00011 #ifndef __GNUC__
00012 #ifndef __attribute__
00013 #define __attribute__(x)
00014 #endif
00015 #endif
00016
00017 static char __attribute__((unused)) ident[] = "$Id: testlsutil.c,v 1.3 2000/10/27 20:34:42 terrylr Exp $";
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #define MAX_PAIRS 1024
00028
00029 int main(int argc, char *argv[])
00030 {
00031 double x[1024], y[1024];
00032 int n = 0;
00033 double a, b;
00034 double d;
00035 int dflag = 0;
00036 int t;
00037
00038 if (argc > 1)
00039 {
00040
00041 if (1 != sscanf (argv[1], "%lf", &d))
00042 {
00043 return -1;
00044 }
00045
00046 dflag = 1;
00047 }
00048
00049 while (!feof(stdin) &&
00050 n < MAX_PAIRS)
00051 {
00052 if (2 != scanf("%lf %lf", &x[n], &y[n]))
00053 {
00054 break;
00055 }
00056 else
00057 {
00058 n++;
00059 }
00060 }
00061
00062 if (dflag)
00063 {
00064 if (0 == lsCoeffOD(x, y, n, d, &a))
00065 {
00066 printf("TitleText: y = %f (x - %f)\n", a, d);
00067 for (t = 0; t < n; t++)
00068 {
00069 printf("%f\t%f\n", x[t], a*(x[t]-d));
00070 }
00071 }
00072 }
00073 else
00074 {
00075 if (0 == lsCoeff(x, y, n, &a, &b))
00076 {
00077 printf("TitleText: y = %f x + %f\n", a, b);
00078 for (t = 0; t < n; t++)
00079 {
00080 printf("%f\t%f\n", x[t], a*x[t]+b);
00081 }
00082 }
00083 }
00084
00085 return 0;
00086 }