36int main(
int argc,
char *argv[] )
40 cout <<
"Usage: " << argv[0] <<
" <filename> <bin/text>" << endl;
45 outs << argv[1] <<
".converted";
46 FILE * bFile = fopen (outs.str().c_str(),
"wb");
49 char start[5] =
"HKDT";
58 if(
string(argv[2]) == string(
"text"))
60 FILE * rFile = fopen (argv[1],
"r");
63 cout <<
"Reading text file" << endl;
66 char * comment = (
char*) malloc(n);
67 int bytes_read = getline(&comment, &n, rFile);
68 while(comment[0] ==
'%')
70 bytes_read = getline(&comment, &n, rFile);
73 ss << string(comment);
74 ss >> hdr.
m >> hdr.
n >> hdr.
nnz;
76 cout <<
"Size of Header: " <<
sizeof(hdr) << endl;
77 cout << hdr.
m <<
" " << hdr.
n <<
" " << hdr.
nnz << endl;
78 fwrite(start, 4, 1, bFile);
82 fwrite(&hdr.
m,
sizeof(
uint64_t), 1,bFile);
83 fwrite(&hdr.
n,
sizeof(
uint64_t), 1,bFile);
87 int year, month, day, hour, min, sec;
91 int from, to, follow, retweets;
94 bytes_read = getline(&comment, &n, rFile);
97 bytes_read = getline(&comment, &n, rFile);
100 bytes_read = getline(&comment, &n, rFile);
104 if(fscanf (rFile,
"%d %d %d %d",&from,&to,&follow,&retweets) == 0)
106 cout <<
"breaking... from " << from <<
" to " << to <<
" follows? " << follow <<
", retweets? " << retweets << endl;
111 cout <<
"all good" << endl;
116 if(fscanf (rFile,
" %d-%d-%d %d:%d:%d\n", &year, &month, &day, &hour, &min, &sec) == 0)
118 cout <<
"Expected retweet data non-existent\n";
121 memset(&timeinfo, 0,
sizeof(
struct tm));
122 timeinfo.tm_year = year - 1900;
123 timeinfo.tm_mon = month - 1 ;
124 timeinfo.tm_mday = day;
125 timeinfo.tm_hour = hour;
126 timeinfo.tm_min = min;
127 timeinfo.tm_sec = sec;
129 twi.
twtime = mktime(&timeinfo);
130 if(twi.
twtime == -1) { cout <<
"Can not parse time date" << endl;
break;}
135 fscanf (rFile,
"\n");
141 else if(
string(argv[2]) ==
string(
"bin"))
143 FILE * rFile = fopen (argv[1],
"rb");
145 fread(&vid,
sizeof(
int32_t),1,rFile);
146 fread(&edges,
sizeof(
int64_t),1,rFile);
152 cout <<
"Size of Header: " <<
sizeof(hdr) << endl;
153 fwrite(start, 4, 1, bFile);
157 fwrite(&hdr.
m,
sizeof(
uint64_t), 1,bFile);
158 fwrite(&hdr.
n,
sizeof(
uint64_t), 1,bFile);
163 cout <<
"Reading binary" << endl;
174 cout <<
"What's your file format, dude?" << endl;
180 cout <<
"Reading first line of binary file..." << endl;
181 bFile = fopen (outs.str().c_str(),
"r");
183 fread(begin, 4, 1, bFile);
185 printf (
"Header of : %s\n", begin);