Dear co-rooters,
I am facing this rather bizarre issue… I have the following code
#include <iostream>
#include <fstream>
#include <vector>
#include "TString.h"
using namespace std;
// Inputs : -name = name of the ascii file to be read - two column file with x and y values, rescpectively assumed
// -X_USER = array that contains the user defined energy binning
// -output = if output = TRUE exports the interpolation array
// if output = FALSE exports the index of the input values used in the interpolation
int linear_Interpolation(TString name, float* X_USER, float* Y_USER, int* index){
float x, y;
// (1) Open the file to count its lines
ifstream myfile;
myfile.open(name);
if(!myfile){
cout << "File not found" << endl;
}
int size_EVAL = 0;
while(1){
myfile >> x >> y;
if (!myfile.good()) break;
size_EVAL++;
}
myfile.close();
// (2) Re-open the file to store the information
myfile.open(name);
float X_EVAL[size_EVAL], Y_EVAL[size_EVAL];
x = 0; y = 0;
int i=0;
while(1){
myfile >> x >> y;
if (!myfile.good()) break;
X_EVAL[i] = x;
Y_EVAL[i] = y;
i++;
}
myfile.close();
// (3) Do the interpolation
int size_USER = (int) sizeof(X_USER)/sizeof(X_USER[0]);
cout << "The USER size is : " << sizeof(X_USER) << endl;
cout << "The USER size is : " << sizeof(X_USER[0]) << endl;
//cout << "The USER size is : " << size_USER << endl;
//float Y_USER[size_USER];
//int index[size_USER];
float x1, x2,y1, y2, a, b;
bool boo;
x2=0.;
y2=0.;
a=0.;
b=0.;
for(i=0; i<=size_USER; ++i){
boo = true;
for (int j=0; j<=size_EVAL; j++){
if (boo==true){
if(X_USER[i] == X_EVAL[j]){
Y_USER[i] = Y_EVAL[j];
index[i]= j;
boo = false;
}
else if(X_USER[i]>X_EVAL[j]){
x1 = X_EVAL[j];
y1 = Y_EVAL[j];
}
else if( X_USER[i]<X_EVAL[j] && boo == true ){
x2 = X_EVAL[j];
y2 = Y_EVAL[j];
a = (y2-y1)/(x2-x1);
b = y2-a*x2;
Y_USER[i] = a*X_USER[i]+b;
index[i] = j;
boo = false;
}
}
}//end of loop over EVAL
}//end of loop over USER
//for(i=0; i<=size_USER; ++i){
// cout << Y_USER[i] << "\t" << index[i] << endl;
//}
return 0;
}
I compile and load it using
root [38] .L linear_interpolation.cc++
While in CINT, I define the following arrays (in order to check that the code is working properly)
root [35] float a[10] = {0.5, 0.6, 0.7, 0.8, 0.9, 1., 2., 3., 4., 5}; float y[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int ind[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Then I do the following check about the array a[10]
root [36] sizeof(a)
(const int)40
root [37] sizeof(a[0])
(const int)4
However when parsing array a[10]
in the code by running
root [39] linear_Interpolation("ENDF_B-VII_1.dat", a, y, ind)
the output about the size of a[10]
seems to be different than the one from CINT
The USER size is : 8
The USER size is : 4
Any idea on why this is happening?
P.S.: A sample file can be found here