Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "SparseMatrix.h"
#include "Options.h"
int main(int argc, char **argv) {
FILE *fp;
char filename[MAX_WORD_LENGTH];
struct sparsematrix A;
long m, n, i, j, weight;
printf("Test MMSparseMatrixReadWeights: ");
strcpy(filename,"test_MMSparseMatrixReadWeights.inp");
fp = fopen(filename, "r");
if (!fp) {
printf("Error\n");
exit(1);
}
m = 5; /* number of row weights */
n = 4; /* number of column weights */
A.MMTypeCode[0] = 'W'; /* weighted matrix */
A.NrRowWeights = m;
A.NrColWeights = n;
/* Allocate matrix arrays */
A.RowWeights = (long *) malloc(A.NrRowWeights* sizeof(long));
A.ColWeights = (long *) malloc(A.NrColWeights* sizeof(long));
if (A.RowWeights == NULL || A.ColWeights == NULL) {
printf("Error\n");
exit(1);
}
MMSparseMatrixReadWeights(&A, fp);
fclose(fp);
/* Check that matrix dimensions and type are the same */
if (A.MMTypeCode[0] != 'W' ||
A.NrRowWeights != m ||
A.NrColWeights != n) {
printf("Error\n");
exit(1);
}
/* Check that row entries have been read correctly */
weight = 1;
for (i = 0; i < A.NrRowWeights; i++) {
if (A.RowWeights[i] != weight) {
printf("Error\n");
exit(1);
}
weight *= 2;
}
/* Check that column entries have been read correctly */
weight = 1;
for (j = 0; j < A.NrColWeights; j++) {
if (A.ColWeights[j] != weight) {
printf("Error\n");
exit(1);
}
weight *= 2;
}
printf("OK\n");
exit(0);
} /* end main */