S
someone
Hi all,
I got fantastic help in the recent thread about "reading binary file
into memory" and converting from char* etc... I however have a slight
problem, consider this (pseudo)-code:
//--------------------------------------------------------------------
int main(int argc,char **argv)
{
xresReader myBinReader; // my "reader-class" (actually a struct)
myBinReader.readNow(); // read from binary file, put data in memory
unsigned long long N = myBinReader.timesteps_loaded;
cout << "timesteps_loaded = " << N << endl;
cout << "Last time-step found at t= " << myBinReader.RTtime[N-1] <<
" seconds." << endl;
length?? = N; // I need to pass N or length?? to mysample( )
below...
for(int i=1;i<length??;i++)
{
HOWTOGETTHISFLOATARRAY_X??? = myBinReader.X;
HOWTOGETTHISFLOATARRAY_Y??? = myBinReader.Y;
}
// need to pass these 3 variables to mysample( .. )
// 1) length??
// 2) HOWTOGETTHISFLOATARRAY_X??? = myBinReader.X;
// 3) HOWTOGETTHISFLOATARRAY_Y??? = myBinReader.Y;
//====================== PLOT ======================
mglGraphFLTK gr;
gr.Window(argc,argv,mysample,"MathGL examples");
return mglFlRun();
}
int mysample(mglGraph *gr, void *) // pseudo-code
{
mglData xvals, yvals;
xvals.Set(HOWTOGETTHISFLOATARRAY_X???, length??);
yvals.Set(HOWTOGETTHISFLOATARRAY_Y???, length??);
gr->Plot(xvals,yvals);
return 0;
}
//--------------------------------------------------------------------
This is getting very ugly... I know this forum is only meant for
discussing standard C++ but I also think this question is a general C+
+ standard question about scoping and passing data arrays around... I
think that for plotting my data, I need this function to take 2 input
arguments: int mysample(mglGraph *gr, void *) so I need to figure out
another way of passing these 3 values (pseudo-variables):
1) length??
2) HOWTOGETTHISFLOATARRAY_X??? = myBinReader.X;
3) HOWTOGETTHISFLOATARRAY_Y??? = myBinReader.Y;
I can only think of copying my data into a global length-variable and
then from the beginning (not even at run time) allocate two huge
HOWTOGETTHISFLOATARRAY (x+y-coordinates). Then I was thinking about
copying everything into these global arrays... But ugh...
This is really really ugly and therefore I have to ask if there isn't
any better and more nice/clean way of passing my 3 variables to the
plot-function? I think the plotfunction can only have 2 input
arguments, due to the line from which it is called:
gr.Window(argc,argv,mysample,"MathGL examples");
Thanks a lot for any hints / suggestions!
I got fantastic help in the recent thread about "reading binary file
into memory" and converting from char* etc... I however have a slight
problem, consider this (pseudo)-code:
//--------------------------------------------------------------------
int main(int argc,char **argv)
{
xresReader myBinReader; // my "reader-class" (actually a struct)
myBinReader.readNow(); // read from binary file, put data in memory
unsigned long long N = myBinReader.timesteps_loaded;
cout << "timesteps_loaded = " << N << endl;
cout << "Last time-step found at t= " << myBinReader.RTtime[N-1] <<
" seconds." << endl;
length?? = N; // I need to pass N or length?? to mysample( )
below...
for(int i=1;i<length??;i++)
{
HOWTOGETTHISFLOATARRAY_X??? = myBinReader.X;
HOWTOGETTHISFLOATARRAY_Y??? = myBinReader.Y;
}
// need to pass these 3 variables to mysample( .. )
// 1) length??
// 2) HOWTOGETTHISFLOATARRAY_X??? = myBinReader.X;
// 3) HOWTOGETTHISFLOATARRAY_Y??? = myBinReader.Y;
//====================== PLOT ======================
mglGraphFLTK gr;
gr.Window(argc,argv,mysample,"MathGL examples");
return mglFlRun();
}
int mysample(mglGraph *gr, void *) // pseudo-code
{
mglData xvals, yvals;
xvals.Set(HOWTOGETTHISFLOATARRAY_X???, length??);
yvals.Set(HOWTOGETTHISFLOATARRAY_Y???, length??);
gr->Plot(xvals,yvals);
return 0;
}
//--------------------------------------------------------------------
This is getting very ugly... I know this forum is only meant for
discussing standard C++ but I also think this question is a general C+
+ standard question about scoping and passing data arrays around... I
think that for plotting my data, I need this function to take 2 input
arguments: int mysample(mglGraph *gr, void *) so I need to figure out
another way of passing these 3 values (pseudo-variables):
1) length??
2) HOWTOGETTHISFLOATARRAY_X??? = myBinReader.X;
3) HOWTOGETTHISFLOATARRAY_Y??? = myBinReader.Y;
I can only think of copying my data into a global length-variable and
then from the beginning (not even at run time) allocate two huge
HOWTOGETTHISFLOATARRAY (x+y-coordinates). Then I was thinking about
copying everything into these global arrays... But ugh...
This is really really ugly and therefore I have to ask if there isn't
any better and more nice/clean way of passing my 3 variables to the
plot-function? I think the plotfunction can only have 2 input
arguments, due to the line from which it is called:
gr.Window(argc,argv,mysample,"MathGL examples");
Thanks a lot for any hints / suggestions!