-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathst_io_prb.cpp
272 lines (235 loc) · 5.24 KB
/
st_io_prb.cpp
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <cmath>
# include <ctime>
# include <cstring>
using namespace std;
# include "st_io.hpp"
int main ( );
void test01 ( );
void test02 ( );
void test03 ( );
//****************************************************************************80
int main ( )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for ST_IO_PRB.
//
// Discussion:
//
// ST_IO_PRB tests the ST_IO library.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 28 January 2014
//
// Author:
//
// John Burkardt
//
{
timestamp ( );
cout << "\n";
cout << "ST_IO_PRB:\n";
cout << " C++ version\n";
cout << " Test the ST_IO library.\n";
test01 ( );
test02 ( );
test03 ( );
//
// Terminate.
//
cout << "\n";
cout << "ST_IO_PRB:\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );
return 0;
}
//****************************************************************************80
void test01 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST01 tests ST_WRITE.
//
// Discussion:
//
// The matrix is:
//
// 11 12 0 0 15
// 21 22 0 0 0
// 0 0 33 0 35
// 0 0 0 44 0
// 51 0 53 0 55
//
// The index vectors are 1 based, and so have to be converted to
// 0-base before being written.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 23 July 2014
//
// Author:
//
// John Burkardt
//
{
double ast[11] = {
51.0, 12.0, 11.0, 33.0, 15.0,
53.0, 55.0, 22.0, 35.0, 44.0,
21.0 };
int i_max;
int i_min;
int ist[11] = {
5, 1, 1, 3, 1, 5, 5, 2, 3, 4, 2 };
int j_max;
int j_min;
int jst[11] = {
1, 2, 1, 3, 5, 3, 5, 2, 5, 4, 1 };
int m = 5;
int n = 5;
int nst = 11;
string output_filename = "a5by5.st";
cout << "\n";
cout << "TEST01\n";
cout << " ST_WRITE writes an ST file.\n";
i4vec_dec ( nst, ist );
i4vec_dec ( nst, jst );
i_min = i4vec_min ( nst, ist );
i_max = i4vec_max ( nst, ist );
j_min = i4vec_min ( nst, jst );
j_max = i4vec_max ( nst, jst );
st_header_print ( i_min, i_max, j_min, j_max, m, n, nst );
st_print ( m, n, nst, ist, jst, ast,
" Sparse Triple (ST) data:" );
st_write ( output_filename, m, n, nst, ist, jst, ast );
cout << "\n";
cout << " Wrote the matrix data to '" << output_filename << "'\n";
return;
}
//****************************************************************************80
void test02 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST02 tests ST_HEADER_READ, ST_DATA_READ.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 23 July 2014
//
// Author:
//
// John Burkardt
//
{
double *ast;
int i_max;
int i_min;
string input_filename = "kershaw.st";
int *ist;
int j_max;
int j_min;
int *jst;
int m;
int n;
int nst;
cout << "\n";
cout << "TEST02\n";
cout << " ST_HEADER_READ reads the header from an ST file.\n";
cout << " ST_DATA_READ reads the data from an ST file.\n";
cout << "\n";
cout << " Read the data from '" << input_filename << "'\n";
st_header_read ( input_filename, i_min, i_max, j_min, j_max, m, n, nst );
st_header_print ( i_min, i_max, j_min, j_max, m, n, nst );
ast = new double[nst];
ist = new int[nst];
jst = new int[nst];
st_data_read ( input_filename, m, n, nst, ist, jst, ast );
st_print ( m, n, nst, ist, jst, ast,
" Sparse Triplet (ST) data read from file:" );
delete [] ast;
delete [] ist;
delete [] jst;
return;
}
//****************************************************************************80
void test03 ( )
//****************************************************************************80
//
// Purpose:
//
// TEST03 tests ST_SORT_A.
//
// Discussion:
//
// The matrix is:
//
// 11 12 0 0 15
// 21 22 0 0 0
// 0 0 33 0 35
// 0 0 0 44 0
// 51 0 53 0 55
//
// The index vectors are 1 based, and so have to be converted to
// 0-base before being written.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 23 July 2014
//
// Author:
//
// John Burkardt
//
{
double ast[11] = {
51.0, 12.0, 11.0, 33.0, 15.0,
53.0, 55.0, 22.0, 35.0, 44.0,
21.0 };
int i_max;
int i_min;
int ist[11] = {
5, 1, 1, 3, 1, 5, 5, 2, 3, 4, 2 };
int j_max;
int j_min;
int jst[11] = {
1, 2, 1, 3, 5, 3, 5, 2, 5, 4, 1 };
int m = 5;
int n = 5;
int nst = 11;
cout << "\n";
cout << "TEST03\n";
cout << " ST_SORT_A sorts an ST matrix by columns.\n";
i_min = i4vec_min ( nst, ist );
i_max = i4vec_max ( nst, ist );
j_min = i4vec_min ( nst, jst );
j_max = i4vec_max ( nst, jst );
st_header_print ( i_min, i_max, j_min, j_max, m, n, nst );
st_print ( m, n, nst, ist, jst, ast, " Matrix data before sorting:" );
st_sort_a ( m, n, nst, ist, jst, ast );
st_print ( m, n, nst, ist, jst, ast, " Matrix data sorted by column:" );
return;
}