I simply typed the recipe in the source code.
I am importing excel data (two columns) so added the code that appears in the third line.
I don't know anything about C++.
When I attempted to ran the program it got stuck in the first line. Please help: How do I use the recipe?
#include "nr.h"
void NR::correl(vec_I_DP &data2, Vec_0_DP &ans)
File *F=fopen("nois15pgandpng.txt","r");
int i;
for (i=0; i<=1024; i++){
fscanf("%d\t%d", &i1, &i2);
data1[i]=i1;
data2[i]=i2;
}
{
int no2,i;
DP tmp;
int n=data1.size();
Vec_DP temp(n);
for ((i=0; i <= 1024; i++) {
ans[i]=data1[i];
temp[i]=data2[i];
}
realft(ans,1);
realft(temp,1);
no2=n>>1;
for ((i=2; i <= 1024; i+=2) {
tmp=ans[i];
ans[i]=(ans[i]*temp[i]+ans[i+1]*temp[i+1])/no2;
ans[i+1]=(ans[i+1]*temp[i]-tmp*temp[i+1])/no2;
}
ans[0]=ans[0]*temp[0]/no2;
ans[1]=ans[1]*temp[1]/no2;
realft(ans,-1);
}
davekw7x
03-20-2008, 12:16 PM
I don't know anything about C++.
Then I respectfully suggest that if you are going to use C++ as a tool to solve your correlation assignment, that you consider one of the following approaches:
1. You learn how to write a program in C++. If you are going to use code from the Numerical Recipes text, then you will have to learn how to use the functions and how to interpret their results. There a are books, and on-line tutorials to get you started. There are a number of C++ help forums that can, maybe, answer specific questions and/or help you with code that you wrote and are having problems with.
or
2. You get someone else to write a program that performs the required calculations and prints the results. (Or saves them in a file or feeds the results to another program, or whatever...)
See Footnote.
I simply typed the recipe in the source code.
Actually, you could put all of the code in a single main() function, but I wouldn't recommend it. I would write a main() function that calls corr(), and use that function as originally written.
In order to use that function as originally written, you need at least the following:
1. A main() function that declares vectors of the appropriate type to use with the numerical recipes functions. The main() function will open the file and read the values into the vectors and then call the function correl() with the appropriate arguments.
2. If you read the text (or the source code for correl()), you will find that you also need the Numerical Recipes function realft(), from section 13.1 of the text.
3. If you read section 13.1 (or the source code for realft()) you will see that you also need the Numerical Recipes function four1() from section 12.2 of the text.
Maybe more, but that's all I see from a (cursory) perusal.
Anyhow...
After you have determined what functions you need and how to call them with what parameter values, and what to do with the values calculated by the functions, then you need to be able, somehow, to compile them.
So, the next requirement is:
4. If you are using the Integrated Development Environment of Borland Builder, you create a project (a C++ command-line project might be my choice). You add the cpp source files to the project. You also will need to add header files nr.h, nr_types.h, and nrutil.h to the project and set some project options that tell the IDE tool about the location of the files (what directory).
If you are using the command-line tool from Borland Builder, you create a makefile that tells the Borland make program about all of the cpp files and header files and how to put them together to create an executable. (You could enter all of this stuff with command-line switches, but a makefile is the way to go, in my opinion.)
Summary: It seems to me that there are three tools for you to learn in order to solve your problem:
1. The C++ language: How to write a program that reads numbers from a file and then calls functions to operate on those numbers and then print out the results.
2. The particular Numerical Recipes function(s): How to set up data to use as arguments in calling the function(s) and how to handle the results of the calculations.
3. The compiler tool set: How to create a project or a makefile that puts all of the stuff together to make a program that you can execute.
Bottom line: These will require some effort. It's not something that you are likely to get in response to a simple, "I don't know anything about C++...How do I ..." request on a forum. Sorry.
Regards,
Dave
Footnote:
"No one was born knowing this stuff, you know."