COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
convert.cpp
Go to the documentation of this file.
1/*
2Written by Ariful Azad, Lawrence Berkeley National Laboratory
3*/
4
5#include <stdlib.h>
6#include <stdio.h>
7#include <string.h>
8#include <math.h>
9#include <assert.h>
10#include <alloca.h>
11#include <iostream>
12#include <vector>
13#include <fstream>
14#include <algorithm>
15#include <iterator>
16
17
18using namespace std;
19
20
21
22int main(int argc, char** argv)
23{
24
25
26 if(argc<3)
27 {
28 cout << "Input and/or output filenames are missing!\n";
29 cout << "Usage: convert inputFileName outputFileName \n";
30 exit(1);
31 }
32 char * ifname = argv[1];
33 char * ofname = argv[2];
34
35 long count=0,i,j;
36 long inp, m, sym;
37 long numRow;
38 double f;
39 string s;
40 ifstream inf;
41 inf.open(ifname, ios::in);
42 FILE* outf = fopen(ofname, "wb");
43 char space[]= " ";
44
45 if(inf.is_open())
46 {
47 size_t found1, found2, found3;
48 getline(inf,s);
49 found1 = s.find("pattern");
50 if (found1 != string::npos)
51 m = 2;
52 else
53 m = 3;
54 found1 = s.find("symmetric");
55 found2 = s.find("hermitian");
56 found3 = s.find("skew-symmetric");
57 if (found1 != string::npos || found2 != string::npos || found3 != string::npos)
58 sym = 1;
59 else
60 sym = 0;
61 while(inf.peek()=='%')
62 getline(inf,s);
63
64 inf>>inp;
65 numRow=inp;
66 inf>>inp;
67 //numCol=inp;
68 inf>>inp;
69
70 count=inp;
71 cout << count << endl;
72
73 while(count>0)
74 {
75 inf>>i;
76 inf>>j;
77 i--;
78 j--;
79 fwrite(&i, sizeof(long), 1, outf);
80 fwrite(space, sizeof(space), 1, outf);
81 fwrite(&j, sizeof(long), 1, outf);
82 fwrite(space, sizeof(space), 1, outf);
83
84 if(m==3)
85 {
86 inf>>f;
87 }
88
89 if (sym && i != j)
90 {
91 fprintf(outf, "%ld %ld ", j-1 , numRow+i-1);
92 long i1 = j;
93 long j1 = numRow+i;
94 fwrite(&i1, sizeof(long), 1, outf);
95 fwrite(space, sizeof(space), 1, outf);
96 fwrite(&j1, sizeof(long), 1, outf);
97 fwrite(space, sizeof(space), 1, outf);
98 }
99 count--;
100 }
101 inf.close();
102 fclose(outf);
103
104 }
105 else
106 {
107 printf("file can not be opened \n");
108 exit(-1);
109 }
110
111}
112
113
string ofname
int main()
Definition Driver.cpp:12