00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #define spINSIDE_SPARSE
00005 #include "spConfig.h"
00006 #include "spmatrix.h"
00007 char ProgramName[] = "Program";
00008
00009 MatrixPtr Matrix = NULL;
00010 int cteniMatice(int *ind, int *jnd, double* nenul, double *prava, char *nazev, int *pocet)
00011 {
00012 int n, i, j, *iind = ind;
00013 double d;
00014 char radek[80];
00015 FILE *soubor = fopen(nazev, "r");
00016 fgets(radek, 80, soubor);
00017 fgets(radek, 80, soubor);
00018 sscanf(radek, "%d%", &n);
00019 while(1)
00020 {
00021 fscanf(soubor, "%d%d%lf", &i, &j, &d);
00022 if (i == 0 && j == 0)
00023 break;
00024 else
00025 {
00026 *iind++ = i; *jnd++ = j; *nenul++ = d;
00027 }
00028 }
00029 for (i = 0; i < n; i++)
00030 fscanf(soubor, "%lf", prava++);
00031 fclose(soubor);
00032 *pocet = (int)(iind - ind);
00033 return n;
00034 }
00035
00036
00037 int novaMatice(int n, int *ind, int *jnd, double* nenul, int rozm)
00038 {
00039 int Error, *lastInd = ind + n;
00040 ElementPtr pElement;
00041 do
00042 {
00043 if(*ind > rozm || *jnd > rozm)
00044 {
00045 fprintf( stderr, "Špatné indexy %d %d \n", *ind, *jnd);
00046 exit(1);
00047 }
00048 pElement = spGetElement(Matrix, *ind, *jnd);
00049 if (pElement == NULL)
00050 {
00051 fprintf(stderr, "Insufficient memory available.\n");
00052 exit(1);
00053 }
00054 pElement->Real = *nenul++;
00055
00056 jnd++;
00057 } while (++ind <lastInd);
00058
00059
00060 if ((Error = spError(Matrix)) != spOKAY)
00061 {
00062
00063 if(Error >= spFATAL) return 1;
00064 }
00065 return 0;
00066 }
00067 static int Init(ElementPtr pElement, double *pInitInfo)
00068 {
00069 pElement->Real = *pInitInfo;
00070 return 0;
00071 }
00072 void main()
00073 {
00074 int pocet, Error, ret, m, n;
00075 int *indi = (int*)malloc(60 * sizeof(int));
00076 int *indj = (int*)malloc(60 * sizeof(int));
00077 double *hodn = (double*)malloc(60 * sizeof(double));
00078 double *prava = (double*)malloc(25 * sizeof(double));
00079 double *Solution = (double*)malloc(25 * sizeof(double));
00080 int rozm = cteniMatice(indi, indj, hodn, prava, "mat2.txt", &pocet);
00081 Matrix = spCreate(rozm, &Error);
00082 ret = novaMatice(pocet, indi, indj, hodn, rozm);
00083 if ((m = spGetSize(Matrix, 1)) != (n = spGetSize(Matrix, 0)))
00084 return;
00085
00086 Error = spFactor(Matrix);
00087 spSolve( Matrix, prava, Solution);
00088 }