-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff_model.cc
More file actions
executable file
·80 lines (73 loc) · 1.61 KB
/
diff_model.cc
File metadata and controls
executable file
·80 lines (73 loc) · 1.61 KB
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
74
75
76
77
78
79
#include "diff_model.h"
tmat::tmat()
{
dim = 0; // not initialized
}
tmat::tmat(const string & mat_file)
{
// do the readin'
read_mat(mat_file);
}
void tmat::read_mat(const string & mat_file)
{
// do the readin'
const int buflen=1024;
char buf[buflen];
double tmp;
char *rtn;
int minij,maxij;
FILE *inp = fopen(mat_file.c_str(),"r");
if (inp == NULL) {
fprintf(stderr,"Could not open file %s\n",mat_file.c_str());
exit(1);
}
// first line
rtn=fgets(buf,buflen,inp);
dim = atoi(strtok(buf," "));
fprintf(stdout,"dim = %i\n",dim);
qlo = atof(strtok(NULL," "));
fprintf(stdout,"qlo = %8.3f\n",qlo);
qhi = atof(strtok(NULL," "));
fprintf(stdout,"qhi = %8.3f\n",qhi);
dq = (qhi-qlo)/float(dim);
lag = atof(strtok(NULL," "));
fprintf(stdout,"lag = %8.3f\n",lag);
// second line
rtn=fgets(buf,buflen,inp);
k1 = atof(strtok(buf," "));
fprintf(stdout,"k1 = %8.3f\n",k1);
q1 = atof(strtok(NULL," "));
fprintf(stdout,"q1 = %8.3f\n",q1);
//mat = gsl_matrix_alloc(dim,dim);
mat.resize(dim);
bin_lo = dim; bin_hi = 0;
for (int i=0; i<dim; i++) {
mat[i].resize(dim);
rtn=fgets(buf,buflen,inp);
for (int j=0; j<dim; j++) {
if (j==0) {
tmp = atoi(strtok(buf," "));
} else {
tmp = atoi(strtok(NULL," "));
}
//fprintf(stdout,"%5i %8.3f\n",j,tmp);
//gsl_matrix_set(mat,i,j,tmp);
mat[i][j] = tmp;
if (tmp>0) {
minij = ( i<j ? i : j );
maxij = ( i<j ? j : i );
if (minij<bin_lo) {
bin_lo = minij;
}
if (maxij>bin_hi) {
bin_hi = maxij;
}
}
}
}
bin_hi+=1; // so we can use it like conventional C bound
}
tmat::~tmat()
{
// deallocate gsl data
}