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
|
int main(int argc, char *argv[])
{
string filename, line, type1, type2, header;
int x, y, entry, count=0;
double element;
char norm;
float frobenius_norm;
ifstream openfile;
filename = argv[1];
openfile.open(argv[1]);
if(!openfile.is_open())
{
cout << "Sorry, but the file don't exist!\n";
exit(1);
}
for(int i =0;i<2;i++)
{
getline(openfile,line,' ');
}
getline(openfile,header,' ');
getline(openfile,type1,' ');
getline(openfile,type2);
// here i want to check if there is a '%' sign as first charecter beside the first line, if it is then i want to ignore that line, and i also want to check if there is blank line, which i also want to ignore it. But i cant make it work...
if(getline(openfile,line).peek()=='%'){
cout << "lol"<<endl;
}
this is current matrix dimensions and entries:
openfile >> x >> y >> entry;
// here i want to how i seperates matrix values as arrays/vectors, so i can calculate frobenius norm...
cout <<"Filename: " << filename << endl;
cout <<"Dimensions: " << x << " x " << y << endl;
cout <<"Entries: " << entry <<endl;
if(header == "coordinate")
{
cout <<"Sparse: "<< "true" <<endl;
}
else if ((x*y/2)<entry||header == "array")
{
cout <<"Sparse: "<< "false" <<endl;
}
cout <<"Type: "<< type1 << ' ' << type2 <<endl;
if(type1 == "pattern"){
norm = '-';
cout <<"Frobenius norm: "<< norm <<endl;
} else {
frobenius_norm = 100;
cout <<"Frobenius norm: "<< frobenius_norm <<endl;
}
return 0;
}
|