NRvector<T> redefinition


petmal
03-02-2011, 12:37 PM
Hello.
I am using NR3 Fitab (linear regression). Because I would also like to have my application compatible with other fitters that accept STL vector<double> rather than NRvectors I would like to somehow redefine VecDoub_I to vector<double> is this possible without makinkg changes to the Fitab code.
Thank you.

davekw7x
03-02-2011, 01:21 PM
...I would like to somehow redefine VecDoub_I to vector<double>...


The header file <nr3.h> contains the following lines:

#ifdef _USESTDVECTOR_
#define NRvector vector
#else
//
// All of the stuff that's needed for "normal" NRvector definitions
//
#endif //ifdef _USESTDVECTOR_


So, the first non-comment lines in your code might look like

#define _USESTDVECTOR_
#include <nr3.h>
//
// Your NR3 program goes here
//



Example:

// "Regular" NRvectors don't have things like push_back, but
// you can use std::vectors by defining _USESTDVECTOR_
//
// With this defined, all of the std::vector operations are available,
// and you can use any and all NR functions that expect any kind
// of NRvector as an argument.
//
// davekw7x
//
#define _USESTDVECTOR_
#include <nr3.h>

int main()
{
VecDoub(x);
x.push_back(1.23);
//
// Do other stuff if you want to
//
for (unsigned i = 0; i < x.size(); i++) {
cout << "x[" << i << "] = " << x[i] << endl;
}
return 0;
}


Output:

x[0] = 1.23


If you comment out the #define directive, it won't compile.



Regards,

Dave