37int main(
int argc,
char *argv[] )
41 cout <<
"Usage: " << argv[0] <<
" <filename> <bin/text>" << endl;
46 outs << argv[1] <<
".converted";
47 FILE * bFile = fopen (outs.str().c_str(),
"wb+");
50 char start[5] =
"HKDT";
59 if(
string(argv[2]) == string(
"text"))
61 FILE * rFile = fopen (argv[1],
"r");
64 cout <<
"Reading text file" << endl;
67 char * comment = (
char*) malloc(n);
68 int bytes_read = getline(&comment, &n, rFile);
69 while(comment[0] ==
'%')
71 bytes_read = getline(&comment, &n, rFile);
74 ss << string(comment);
75 ss >> hdr.
m >> hdr.
n >> hdr.
nnz;
77 cout <<
"Size of Header: " <<
sizeof(hdr) << 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;
93 if(fscanf (rFile,
"%d %d %d %d",&(twi.
from),&(twi.
to),&(twi.
follow),&(twi.
retweets)) == 0)
break;
96 if(fscanf (rFile,
"%d-%d-%d %d:%d:%d\n", &year, &month, &day, &hour, &min, &sec) == 0)
98 cout <<
"Expected retweet data non-existent\n";
101 memset(&timeinfo, 0,
sizeof(
struct tm));
102 timeinfo.tm_year = year - 1900;
103 timeinfo.tm_mon = month - 1 ;
104 timeinfo.tm_mday = day;
105 timeinfo.tm_hour = hour;
106 timeinfo.tm_min = min;
107 timeinfo.tm_sec = sec;
109 twi.
twtime = mktime(&timeinfo);
110 if(twi.
twtime == -1) { cout <<
"Can not parse time date" << endl;
break;}
115 fscanf (rFile,
"\n");
121 else if(
string(argv[2]) ==
string(
"bin"))
123 FILE * rFile = fopen (argv[1],
"rb");
125 fread(&vid,
sizeof(
int32_t),1,rFile);
126 fread(&edges,
sizeof(
int64_t),1,rFile);
132 cout <<
"Size of Header: " <<
sizeof(hdr) << endl;
133 fwrite(start, 4, 1, bFile);
137 fwrite(&hdr.
m,
sizeof(
uint64_t), 1,bFile);
138 fwrite(&hdr.
n,
sizeof(
uint64_t), 1,bFile);
143 cout <<
"Reading binary" << endl;
144 vector<TwitterInteraction> twis;
151 random_shuffle ( twis.begin(), twis.end());
153 for(vector<TwitterInteraction>::iterator it = twis.begin(); it != twis.end(); it++)
162 cout <<
"What's your file format, dude?" << endl;
168 cout <<
"Reading first line of binary file..." << endl;
169 bFile = fopen (outs.str().c_str(),
"r");
171 fread(begin, 4, 1, bFile);
173 printf (
"Header of : %s\n", begin);