-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhb_io.cpp
4362 lines (4051 loc) · 104 KB
/
hb_io.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# include <cmath>
# include <cstdlib>
# include <cstring>
# include <ctime>
# include <sstream>
# include <iomanip>
# include <iostream>
# include <stdexcept>
# include "hb_io.hpp"
namespace hb_io
{
using namespace std;
double atof_fortran(char* s)
{
for (char* p = s; *p != '\0'; ++p)
{
switch (*p)
{
case 'd':
case 'D':
*p = 'E';
break;
}
}
return atof(s);
}
//****************************************************************************80
bool ch_eqi ( char c1, char c2 )
//****************************************************************************80
//
// Purpose:
//
// CH_EQI is true if two characters are equal, disregarding case.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 13 June 2003
//
// Author:
//
// John Burkardt,
// Modifications by Reinhard Resch.
//
// Parameters:
//
// Input, char C1, C2, the characters to compare.
//
// Output, bool CH_EQI, is true if the two characters are equal,
// disregarding case.
//
{
if ( 97 <= c1 && c1 <= 122 )
{
c1 = c1 - 32;
}
if ( 97 <= c2 && c2 <= 122 )
{
c2 = c2 - 32;
}
return ( c1 == c2 );
}
//****************************************************************************80
bool ch_is_digit ( char c )
//****************************************************************************80
//
// Purpose:
//
// CH_IS_DIGIT returns TRUE if a character is a decimal digit.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 05 December 2003
//
// Author:
//
// John Burkardt,
// Modifications by Reinhard Resch.
//
// Parameters:
//
// Input, char C, the character to be analyzed.
//
// Output, bool CH_IS_DIGIT, is TRUE if C is a digit.
//
{
if ( '0' <= c && c <= '9' )
{
return true;
}
else
{
return false;
}
}
//****************************************************************************80
bool ch_is_format_code ( char c )
//****************************************************************************80
//
// Purpose:
//
// CH_IS_FORMAT_CODE returns TRUE if a character is a FORTRAN format code.
//
// Discussion:
//
// The format codes accepted here are not the only legal format
// codes in FORTRAN90. However, they are more than sufficient
// for my needs!
//
// Table:
//
// A Character
// B Binary digits
// D Real number, exponential representation
// E Real number, exponential representation
// F Real number, fixed point
// G General format
// I Integer
// L Logical variable
// O Octal digits
// Z Hexadecimal digits
// * Free format
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 November 2003
//
// Author:
//
// John Burkardt,
// Modifications by Reinhard Resch.
//
// Parameters:
//
// Input, char C, the character to be analyzed.
//
// Output, bool CH_IS_FORMAT_CODE, is TRUE if C is a FORTRAN format code.
//
{
if ( ch_eqi ( c, 'A' ) )
{
return true;
}
else if ( ch_eqi ( c, 'B' ) )
{
return true;
}
else if ( ch_eqi ( c, 'D' ) )
{
return true;
}
else if ( ch_eqi ( c, 'E' ) )
{
return true;
}
else if ( ch_eqi ( c, 'F' ) )
{
return true;
}
else if ( ch_eqi ( c, 'G' ) )
{
return true;
}
else if ( ch_eqi ( c, 'I' ) )
{
return true;
}
else if ( ch_eqi ( c, 'L' ) )
{
return true;
}
else if ( ch_eqi ( c, 'O' ) )
{
return true;
}
else if ( ch_eqi ( c, 'Z' ) )
{
return true;
}
else if ( c == '*' )
{
return true;
}
else
{
return false;
}
}
//****************************************************************************80
int ch_to_digit ( char c )
//****************************************************************************80
//
// Purpose:
//
// CH_TO_DIGIT returns the integer value of a base 10 digit.
//
// Example:
//
// C DIGIT
// --- -----
// '0' 0
// '1' 1
// ... ...
// '9' 9
// ' ' 0
// 'X' -1
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 13 June 2003
//
// Author:
//
// John Burkardt,
// Modifications by Reinhard Resch.
//
// Parameters:
//
// Input, char C, the decimal digit, '0' through '9' or blank are legal.
//
// Output, int CH_TO_DIGIT, the corresponding integer value. If C was
// 'illegal', then DIGIT is -1.
//
{
int digit;
if ( '0' <= c && c <= '9' )
{
digit = c - '0';
}
else if ( c == ' ' )
{
digit = 0;
}
else
{
digit = -1;
}
return digit;
}
//****************************************************************************80
void hb_exact_read ( ifstream &input, int nrow, int nrhs, int rhscrd,
char *rhsfmt, char *rhstyp, double exact[] )
//****************************************************************************80
//
// Purpose:
//
// HB_EXACT_READ reads the exact solution vectors in an HB file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 January 2014
//
// Author:
//
// John Burkardt,
// Modifications by Reinhard Resch.
//
// Reference:
//
// Iain Duff, Roger Grimes, John Lewis,
// User's Guide for the Harwell-Boeing Sparse Matrix Collection,
// October 1992.
//
// Parameters:
//
// Input, ifstream &INPUT, the unit from which data is read.
//
// Input, int NROW, the number of rows or variables.
//
// Input, int NRHS, the number of right hand sides.
//
// Input, int RHSCRD, the number of lines in the file for
// right hand sides.
//
// Input, char *RHSFMT, the 20 character format for reading values
// of the right hand side.
//
// Input, char *RHSTYP, the 3 character right hand side type.
// First character is F for full storage or M for same as matrix.
// Second character is G if starting "guess" vectors are supplied.
// Third character is X if exact solution vectors are supplied.
// Ignored if NRHS = 0.
//
// Output, double EXACT[NROW*NRHS], the exact solution vectors.
//
{
char code;
int i;
int j;
int jhi;
int jlo;
int khi;
int klo;
char line[255];
int line_num;
int m;
int r;
char *s;
int w;
if ( 0 < rhscrd )
{
if ( rhstyp[2] == 'X' )
{
s_to_format ( rhsfmt, &r, &code, &w, &m );
line_num = 1 + ( nrow * nrhs - 1 ) / r;
jhi = 0;
for ( i = 1; i <= line_num; i++ )
{
input.getline ( line, sizeof ( line ) );
jlo = jhi + 1;
jhi = i4_min ( jlo + r - 1, nrow * nrhs );
khi = 0;
for ( j = jlo; j <= jhi; j++ )
{
klo = khi + 1;
khi = i4_min ( klo + w - 1, strlen ( line ) );
s = s_substring ( line, klo, khi );
exact[j-1] = atof_fortran ( s );
}
}
}
}
return;
}
//****************************************************************************80
void hb_exact_write ( ofstream &output, int nrow, int nrhs, int rhscrd,
char *rhsfmt, char *rhstyp, double exact[] )
//****************************************************************************80
//
// Purpose:
//
// HB_EXACT_WRITE writes the exact solution vectors to an HB file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 January 2014
//
// Author:
//
// John Burkardt,
// Modifications by Reinhard Resch.
//
// Reference:
//
// Iain Duff, Roger Grimes, John Lewis,
// User's Guide for the Harwell-Boeing Sparse Matrix Collection,
// October 1992.
//
// Parameters:
//
// Input, ofstream &OUTPUT, the unit to which data is written.
//
// Input, int NROW, the number of rows or variables.
//
// Input, int NRHS, the number of right hand sides.
//
// Input, int RHSCRD, the number of lines in the file for
// right hand sides.
//
// Input, char *RHSFMT, the 20 character format for reading values
// of the right hand side.
//
// Input, char *RHSTYP, the 3 character right hand side type.
// First character is F for full storage or M for same as matrix.
// Second character is G if starting "guess" vectors are supplied.
// Third character is X if exact solution vectors are supplied.
// Ignored if NRHS = 0.
//
// Input, double EXACT[NROW*NRHS], the exact solution vectors.
//
{
char code;
int i;
int j;
int jhi;
int jlo;
int line_num;
int m;
int r;
int w;
if ( 0 < rhscrd )
{
if ( rhstyp[2] == 'X' )
{
s_to_format ( rhsfmt, &r, &code, &w, &m );
line_num = 1 + ( nrow * nrhs - 1 ) / r;
jhi = 0;
for ( i = 1; i <= line_num; i++ )
{
jlo = jhi + 1;
jhi = i4_min ( jlo + r - 1, nrow * nrhs );
for ( j = jlo; j <= jhi; j++ )
{
output << setw(w) << exact[j-1];
}
output << "\n";
}
}
}
return;
}
//****************************************************************************80
void hb_file_read ( ifstream &input, char **title, char **key, int *totcrd,
int *ptrcrd, int *indcrd, int *valcrd, int *rhscrd, char **mxtype, int *nrow,
int *ncol, int *nnzero, int *neltvl, char **ptrfmt, char **indfmt, char **valfmt,
char **rhsfmt, char **rhstyp, int *nrhs, int *nrhsix, int **colptr,
int **rowind, double **values, double **rhsval, int **rhsptr, int **rhsind,
double **rhsvec, double **guess, double **exact )
//****************************************************************************80
//
// Purpose:
//
// HB_FILE_READ reads an HB file.
//
// Discussion:
//
// This routine reads all the information from an HB file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 15 August 2016
//
// Author:
//
// John Burkardt,
// Modifications by Reinhard Resch.
//
// Reference:
//
// Iain Duff, Roger Grimes, John Lewis,
// User's Guide for the Harwell-Boeing Sparse Matrix Collection,
// October 1992.
//
// Parameters:
//
// Input, ifstream &INPUT, the unit from which the data is read.
//
// Output, char *TITLE, a 72 character title for the matrix.
//
// Output, char *KEY, an 8 character identifier for the matrix.
//
// Output, int *TOTCRD, the total number of lines of data.
//
// Output, int *PTRCRD, the number of input lines for pointers.
//
// Output, int *INDCRD, the number of input lines for row indices.
//
// Output, int *VALCRD, the number of input lines for numerical values.
//
// Output, int *RHSCRD, the number of input lines for right hand sides.
//
// Output, char *MXTYPE, the 3 character matrix type.
// First character is R for Real, C for complex, P for pattern only.
// Second character is S for symmetric, U for unsymmetric, H for
// Hermitian, Z for skew symmetric, R for rectangular.
// Third character is A for assembled and E for unassembled
// finite element matrices.
//
// Output, int *NROW, the number of rows or variables.
//
// Output, int *NCOL, the number of columns or elements.
//
// Output, int *NNZERO. In the case of assembled sparse matrices,
// this is the number of nonzeroes. In the case of unassembled finite
// element matrices, in which the right hand side vectors are also
// stored as unassembled finite element vectors, this is the total
// number of entries in a single unassembled right hand side vector.
//
// Output, int *NELTVL, the number of finite element matrix entries,
// set to 0 in the case of assembled matrices.
//
// Output, char *PTRFMT, the 16 character format for reading pointers.
//
// Output, char *INDFMT, the 16 character format for reading indices.
//
// Output, char *VALFMT, the 20 character format for reading values.
//
// Output, char *RHSFMT, the 20 character format for reading values
// of the right hand side.
//
// Output, char *RHSTYP, the 3 character right hand side type.
// First character is F for full storage or M for same as matrix.
// Second character is G if starting "guess" vectors are supplied.
// Third character is X if exact solution vectors are supplied.
//
// Output, int *NRHS, the number of right hand sides.
//
// Output, int *NRHSIX, the number of entries of storage for right
// hand side values, in the case where RHSTYP[0] = 'M' and
// MXTYPE[2] = 'A'.
//
// Output, int COLPTR[NCOL+1], COLPTR[I-1] points to the location of
// the first entry of column I in the sparse matrix structure.
//
// If MXTYPE[2] == 'A':
//
// Output, int ROWIND[NNZERO], the row index of each item.
//
// If MXTYPE[2] == 'F':
//
// Output, int ROWIND[NELTVL], the row index of each item.
//
// If RHSTYP[0] == 'F':
//
// Output, double RHSVAL[NROW*NRHS], contains NRHS dense right hand
// side vectors.
//
// Output, int RHSPTR[], is not used.
//
// Output, int RHSIND[], is not used.
//
// Output, int RHSVEC[], is not used.
//
// If RHSTYP[0] = 'M' and MXTYPE[2] = 'A':
//
// Output, double RHSVAL[], is not used.
//
// Output, int RHSPTR[NRHS+1], RHSPTR[I-1] points to the location of
// the first entry of right hand side I in the sparse right hand
// side vector.
//
// Output, int RHSIND[NRHSIX], indicates, for each entry of
// RHSVEC, the corresponding row index.
//
// Output, double RHSVEC[NRHSIX], contains the value of the right hand
// side entries.
//
// If RHSTYP[0] = 'M' and MXTYPE[2] = 'E':
//
// Output, double RHSVAL[NNZERO*NRHS], contains NRHS unassembled
// finite element vector right hand sides.
//
// Output, int RHSPTR[], is not used.
//
// Output, int RHSIND[], is not used.
//
// Output, double RHSVEC[], is not used.
//
// Output, double GUESS[NROW*NRHS], the starting guess vectors.
//
// Output, double EXACT[NROW*NRHS], the exact solution vectors.
//
{
//
// Read the header block.
//
hb_header_read ( input, title, key, totcrd, ptrcrd, indcrd,
valcrd, rhscrd, mxtype, nrow, ncol, nnzero, neltvl, ptrfmt, indfmt,
valfmt, rhsfmt, rhstyp, nrhs, nrhsix );
//
// Read the matrix structure.
//
if ( 0 < ptrcrd )
{
if ( (*colptr) )
{
delete [] (*colptr);
}
(*colptr) = new int[*(ncol)+1];
}
if ( 0 < indcrd )
{
if ( (*rowind) )
{
delete [] (*rowind);
}
if ( (*mxtype)[2] == 'A' )
{
(*rowind) = new int[*nnzero];
}
else if ( (*mxtype)[2] == 'E' )
{
(*rowind) = new int[*neltvl];
}
else
{
ostringstream os;
os << "HB_FILE_READ - Fatal error!\n";
os << " Illegal value of MXTYPE character 3!\n";
throw runtime_error(os.str());
}
}
hb_structure_read ( input, *ncol, *mxtype, *nnzero, *neltvl,
*ptrcrd, *ptrfmt, *indcrd, *indfmt, *colptr, *rowind );
//
// Read the matrix values.
//
if ( 0 < valcrd )
{
if ( *values )
{
delete [] (*values);
}
if ( (*mxtype)[2] == 'A' )
{
*values = new double[*nnzero];
}
else if ( (*mxtype)[2] == 'E' )
{
*values = new double[*neltvl];
}
else
{
ostringstream os;
os << "HB_FILE_READ - Fatal error!\n";
os << " Illegal value of MXTYPE character 3!\n";
throw runtime_error(os.str());
}
hb_values_read ( input, *valcrd, *mxtype, *nnzero, *neltvl,
*valfmt, *values );
}
//
// Read the right hand sides.
//
if ( 0 < *rhscrd )
{
if ( (*rhstyp)[0] == 'F' )
{
if ( *rhsval )
{
delete [] *rhsval;
}
*rhsval = new double[(*nrow)*(*nrhs)];
}
else if ( (*rhstyp)[0] == 'M' && (*mxtype)[2] == 'A' )
{
if ( *rhsptr )
{
delete [] *rhsptr;
}
*rhsptr = new int[*nrhs+1];
if ( *rhsind )
{
delete [] *rhsind;
}
*rhsind = new int[*nrhsix];
if ( *rhsvec )
{
delete [] *rhsvec;
}
*rhsvec = new double[(*nrhsix)];
}
else if ( (*rhstyp)[0] == 'M' && (*mxtype)[2] == 'E' )
{
if ( *rhsval )
{
delete [] *rhsval;
}
*rhsval = new double[(*nnzero)*(*nrhs)];
}
else
{
ostringstream os;
os << "HB_FILE_READ - Fatal error!\n";
os << " Illegal combination of RHSTYP character 1\n";
os << " and MXTYPE character 3!\n";
throw runtime_error(os.str());
}
hb_rhs_read ( input, *nrow, *nnzero, *nrhs, *nrhsix,
*rhscrd, *ptrfmt, *indfmt, *rhsfmt, *mxtype, *rhstyp, *rhsval,
*rhsind, *rhsptr, *rhsvec );
//
// Read the starting guesses.
//
if ( (*rhstyp)[1] == 'G' )
{
if ( *guess )
{
delete [] *guess;
}
*guess = new double[(*nrow)*(*nrhs)];
hb_guess_read ( input, *nrow, *nrhs, *rhscrd, *rhsfmt, *rhstyp, *guess );
}
//
// Read the exact solutions.
//
if ( (*rhstyp)[2] == 'X' )
{
if ( *exact )
{
delete [] *exact;
}
*exact = new double[(*nrow)*(*nrhs)];
hb_exact_read ( input, *nrow, *nrhs, *rhscrd, *rhsfmt, *rhstyp, *exact );
}
}
return;
}
//****************************************************************************80
void hb_file_write ( ofstream &output, char *title, char *key, int totcrd,
int ptrcrd, int indcrd, int valcrd, int rhscrd, char *mxtype, int nrow,
int ncol, int nnzero, int neltvl, char *ptrfmt, char *indfmt, char *valfmt,
char *rhsfmt, char *rhstyp, int nrhs, int nrhsix, int colptr[],
int rowind[], double values[], double rhsval[], int rhsptr[], int rhsind[],
double rhsvec[], double guess[], double exact[] )
//****************************************************************************80
//
// Purpose:
//
// HB_FILE_WRITE writes an HB file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 January 2014
//
// Author:
//
// John Burkardt,
// Modifications by Reinhard Resch.
//
// Reference:
//
// Iain Duff, Roger Grimes, John Lewis,
// User's Guide for the Harwell-Boeing Sparse Matrix Collection,
// October 1992.
//
// Parameters:
//
// Input, ofsteam &OUTPUT, the unit to which data is written.
//
// Input, char *TITLE, a 72 character title for the matrix.
//
// Input, char *KEY, an 8 character identifier for the matrix.
//
// Input, int TOTCRD, the total number of lines of data.
//
// Input, int PTRCRD, the number of input lines for pointers.
//
// Input, int INDCRD, the number of input lines for row indices.
//
// Input, int VALCRD, the number of input lines for numerical values.
//
// Input, int RHSCRD, the number of input lines for right hand sides.
//
// Input, char *MXTYPE, the 3 character matrix type.
// First character is R for Real, C for complex, P for pattern only.
// Second character is S for symmetric, U for unsymmetric, H for
// Hermitian, Z for skew symmetric, R for rectangular.
// Third character is A for assembled and E for unassembled
// finite element matrices.
//
// Input, int NROW, the number of rows or variables.
//
// Input, int NCOL, the number of columns or elements.
//
// Input, int NNZERO. In the case of assembled sparse matrices,
// this is the number of nonzeroes. In the case of unassembled finite
// element matrices, in which the right hand side vectors are also
// stored as unassembled finite element vectors, this is the total
// number of entries in a single unassembled right hand side vector.
//
// Input, int NELTVL, the number of finite element matrix entries,
// set to 0 in the case of assembled matrices.
//
// Input, char *PTRFMT, the 16 character format for reading pointers.
//
// Input, char *INDFMT, the 16 character format for reading indices.
//
// Input, char *VALFMT, the 20 character format for reading values.
//
// Input, char *RHSFMT, the 20 character format for reading values
// of the right hand side.
//
// Input, char *RHSTYP, the 3 character right hand side type.
// First character is F for full storage or M for same as matrix.
// Second character is G if starting "guess" vectors are supplied.
// Third character is X if exact solution vectors are supplied.
// Ignored if NRHS = 0.
//
// Input, int NRHS, the number of right hand sides.
//
// Input, int NRHSIX, the number of row indices (set to 0
// in the case of unassembled matrices.) Ignored if NRHS = 0.
//
// Input, int COLPTR[NCOL+1], COLPTR(I) points to the location of
// the first entry of column I in the sparse matrix structure.
//
// If MXTYPE[2] == 'A':
//
// Input, int ROWIND[NNZERO], the row index of each item.
//
// Input, double VALUES[NNZERO], the nonzero values of the matrix.
//
// If MXTYPE[2] == 'E':
//
// Input, int ROWIND[NELTVL], the row index of each item.
//
// Input, double VALUES[NELTVL], the nonzero values of the matrix.
//
// If RHSTYP[0] == 'F':
//
// Input, double RHSVAL[NROW*NRHS], contains NRHS dense right hand
// side vectors.
//
// Input, int RHSPTR[], is not used.
//
// Input, int RHSIND[], is not used.
//
// Input, double RHSVEC[], is not used.
//
// If RHSTYP[0] = 'M' and MXTYPE[2] = 'A':
//
// Input, double RHSVAL[], is not used.
//
// Input, int RHSPTR[NRHS+1], RHSPTR(I) points to the location of
// the first entry of right hand side I in the sparse right hand
// side vector.
//
// Input, int RHSIND[NRHSIX], indicates, for each entry of
// RHSVEC, the corresponding row index.
//
// Input, double RHSVEC[NRHSIX], contains the value of the right hand
// side entries.
//
// If RHSTYP[0] = 'M' and MXTYPE[2] = 'E':
//
// Input, double RHSVAL[NNZERO*NRHS], contains NRHS unassembled
// finite element vector right hand sides.
//
// Input, int RHSPTR[], is not used.
//
// Input, int RHSIND[], is not used.
//
// Input, double RHSVEC[], is not used.
//
// Input, double GUESS[NROW*NRHS], the starting guess vectors.
//
// Input, double EXACT[NROW*NRHS], the exact solution vectors.
//
{
//
// Write the header block.
//
hb_header_write ( output, title, key, totcrd, ptrcrd, indcrd,
valcrd, rhscrd, mxtype, nrow, ncol, nnzero, neltvl, ptrfmt, indfmt,
valfmt, rhsfmt, rhstyp, nrhs, nrhsix );
//
// Write the matrix structure.
//
hb_structure_write ( output, ncol, mxtype, nnzero, neltvl,
ptrfmt, indfmt, colptr, rowind );
//
// Write the matrix values.
//
hb_values_write ( output, valcrd, mxtype, nnzero, neltvl,
valfmt, values );
//
// Write the right hand sides.
//
hb_rhs_write ( output, nrow, nnzero, nrhs, nrhsix,
rhscrd, ptrfmt, indfmt, rhsfmt, mxtype, rhstyp, rhsval,
rhsind, rhsptr, rhsvec );
//
// Write the starting guesses.
//
hb_guess_write ( output, nrow, nrhs, rhscrd, rhsfmt, rhstyp, guess );
//
// Write the exact solutions.
//
hb_exact_write ( output, nrow, nrhs, rhscrd, rhsfmt, rhstyp, exact );
return;
}
//****************************************************************************80
void hb_guess_read ( ifstream &input, int nrow, int nrhs, int rhscrd,
char *rhsfmt, char *rhstyp, double guess[] )
//****************************************************************************80
//
// Purpose:
//
// HB_GUESS_READ reads the starting guess vectors in an HB file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 21 January 2014
//
// Author:
//
// John Burkardt,
// Modifications by Reinhard Resch.
//
// Reference:
//
// Iain Duff, Roger Grimes, John Lewis,
// User's Guide for the Harwell-Boeing Sparse Matrix Collection,
// October 1992.
//
// Parameters:
//
// Input, ifstream &INPUT, the unit from which data is read.
//
// Input, int NROW, the number of rows or variables.
//
// Input, int NRHS, the number of right hand sides.
//
// Input, int RHSCRD, the number of lines in the file for
// right hand sides.
//
// Input, char *RHSFMT, the 20 character format for reading values
// of the right hand side.
//
// Input, char *RHSTYP, the 3 character right hand side type.
// First character is F for full storage or M for same as matrix.
// Second character is G if starting "guess" vectors are supplied.
// Third character is X if exact solution vectors are supplied.