Export data in columns in a dat format
Jul 26, 2013 at 3:08am UTC
Hello guys,
I want to export data (X,U) in a .dat format to open it by Tecplot.
I need something like this.
VARIABLES = "X", "U"
ZONE I=2, F=POINT
1,77
2,41
3,69
4,51
.,.
.,.
.,.
.,.
the problem is that code does not write the value of X,U in two columns.
Help plz!!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("MY case" );
myfile << "VARIABLES = X , U \n" ;
myfile << "ZONE I=2 , F=POINTS \n" ;
for ( i = 1; i <= n; i++ )
{
{cout << X[i] << ' ' ;}
}
for ( j = 1; j <= n; j++ )
{
{cout << X[j] << ' ' ;}
}
myfile.close();
return 0;
}
Jul 26, 2013 at 6:08am UTC
this will only work if
X is an array of objects of some class you defined, and overloaded the insertion operator so that it prints data in the form:
<
X >
, <
U >
new-line-character
otherwise, you'd want to try declaring 2 arrays, one contains the number before the comma, another contains the number after it:
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
#include <iostream>
#include <fstream>
using namespace std;
const ARRAY_SIZE = somesize;
int main () {
int X[ARRAY_SIZE];
int U[ARRAY_SIZE];
// . . .
//some initialization of X and U
// . . .
ofstream myfile;
myfile.open ("MY case" );
myfile << "VARIABLES = X , U \n" ;
myfile << "ZONE I=2 , F=POINTS \n" ;
for ( i = 1; i <= ARRAY_SIZE; i++ )
{
{cout << X[i] << ',' << U[i] << std::endl;}
}
myfile.close();
return 0;
}
i hope this is what you want.
Topic archived. No new replies allowed.