-
read in problem
hay
I have a problem with the following read in procedure:
Code:
ifstream widthfile("data-files/output_file3.txt");
while((widthfile >> x[n] >> y[n] >> z[n] >> vx[n] >> vy[n] >> vz[n] >> mass >> type[n])){
if(xmax < x[n]) xmax = x[n];
if(ymax < y[n]) ymax = y[n];
if(zmax < z[n]) zmax = z[n];
n++;
}
widthfile.close();
this gives an error to me. If I use only 5 columns in the file output_file3.txt it is working, so the problem is connected to the number of colums... ???
I can avoid the problem if I read only one data set and distribute it afterwards like
Code:
ifstream widthfile("data-files/output_file3.txt");
while((widthfile >>dummy)){
if(n%0 == 0){
x[n1] == dummy;
n1++;
}
....
n++;
}
widthfile.close();
but this is very ugly... I would like to know what is my mistake withe the procedure above.
thanks for any help
florian
-
There's nothing wrong with this piece of code. Could you show us the rest, including variable declarations and initialization?
-
of course... here is the complete program (its a root program but I hope its not connected to root itself)
Code:
#include <math.h>
void pos_plot_2color(){
gROOT->SetStyle("Plain");
gStyle->SetOptStat(0);
gStyle->SetOptFit(1111);
const int num = 1000000;
double x[num], y[num], z[num], type[num], dummy;
double vx[num], vy[num], vz[num];
double xmax, ymax, zmax, mass[num];
int j, n;
xmax = 0;
ymax = 0;
zmax = 0;
n = 0;
ifstream widthfile("data-files/output_file3.txt");
while((widthfile >> x[n] >> y[n] >> z[n] >> vx[n] >> vy[n] >> vz[n] >> mass[n] >> type[n])){
if(xmax < x[n]) xmax = x[n];
if(ymax < y[n]) ymax = y[n];
if(zmax < z[n]) zmax = z[n];
n++;
}
widthfile.close();
cout<<"xmax: "<<xmax<< endl;
cout<<"ymax: "<<ymax<< endl;
cout<<"zmax: "<<zmax<< endl;
TH3F *frame3d = new TH3F("frame3d","frame3d",10,-xmax,xmax,10,-ymax,ymax,10,-zmax,zmax);
frame3d->Draw();
TPolyMarker3D *pm3d1 = new TPolyMarker3D(3);
j = 0;
for(int i = 0; i <= n; i++){
if(type[i] == 2){
pm3d1->SetPoint(j,x[i],y[i],z[i]);
cout<<"x: "<<x[i]<<" y: "<<y[i]<<" z: "<<z[i]<<" vx: "<<vx[i]<<" vy: "<<vy[i]<<" vz: "<<vz[i]<< endl;
j++;
}
}
cout<<"type1: "<<j<< endl;
pm3d1->SetMarkerSize(1);
pm3d1->SetMarkerColor(kRed);
pm3d1->SetMarkerStyle(20);
frame3d->SetTitle("");
pm3d1->Draw();
TPolyMarker3D *pm3d2 = new TPolyMarker3D(3);
j = 0;
for(int i = 0; i <= n; i++){
if(type[i] == 1){
pm3d2->SetPoint(j,x[i],y[i],z[i]);
if(x[i] == 10000. && y[i] == 0. && z[i] == 0.) cout<<"i = "<<i<< endl;
j++;
}
}
cout<<"type2: "<<j<< endl;
pm3d2->SetMarkerSize(0.1);
pm3d2->SetMarkerColor(1);
pm3d2->SetMarkerStyle(20);
pm3d2->Draw();
}
thanks fpr the help
florian
-
You allocate on the stack:
8 arrays
1000000 elements each
8 bytes per element
That makes up for 64 MB. WAY too big for the stack; on the heap it should be OK if there's really no better way to do it.