-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbinMatrix.cpp
37 lines (36 loc) · 1.09 KB
/
binMatrix.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
//read matrix binary data in gnuplot format
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
int main(int argc, char *argv[])
{
if(argc<2) {
cout<<"usage:: <matrix_file>\n";
return(0);
}
ifstream in1(argv[1],ifstream::binary);
if(! in1.is_open()){
cout<<"usage:: <matrix_file>\n";
return(0);
}
float n1;
in1.read((char*)(&n1),sizeof(float));
vector<float> x,y;
x.resize( (unsigned int) ( n1 -0.5));
y.resize( (unsigned int) ( n1 +0.5));
cerr<<x.size()<<endl;
if(in1.fail()){
cerr<<"incomplete data file\n";
return 0;
}
in1.read((char *) (& x[0]),x.size()*sizeof(float));
do{
in1.read((char*) (&y[0]),sizeof(float)*y.size());
if(in1.fail()) break;
for(unsigned int i=0;i<x.size();i++){
cout<<x.at(i)<<' '<<y.at(0)<<' '<<y.at(i+1)<<endl;
}
}while(! in1.eof());
return 0;
}