Assigning values to an int array from another file
Jun 21, 2017 at 8:11am UTC
Hello everybody,
I have the code below that performs a time calibration on some data. The data is first acquired and stored in another file called dv_values.txt. dv_values.txt contains 1024 lines, each with one voltage value. I need to read each of these values and assign them to the array wf[i]. Can anybody help me please? Thank you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
int AnalyzeSlope(/*Averager *ave, */ int iIter, int nIter, int channel, float wf[1024], int tCell, double cellDV[1024], double cellDT[1024])
// 1024 = number of cells
{
int i;
float dv, llim, ulim;
double sum, dtCell;
llim = -300;
ulim = 300; // For now leave these values until nominal frequency is determined
/* rising edges */
// skip first cells after rigger cell
for (i = tCell+5 ; i<tCell+1024-5 ; i++) {
// test slope between previous and next cell to allow for negative cell width
if (wf[(i+1024-1) % 1024] < wf[(i+2) % 1024] && wf[i % 1024] > llim && wf[(i+1) % 1024] < ulim) {
// calculate delta_v
dv = wf[(i+1) % 1024] - wf[i % 1024];
// average delta_v; instert here averager value
}
}
/* falling edges */
// skip first cells after rigger cell
for (i = tCell+5 ; i<tCell+1024-5 ; i++) {
// test slope between previous and next cell to allow for negative cell width
if (wf[(i+1024-1) % 1024] > wf[(i+2) % 1024] && wf[i % 1024] < ulim && wf[(i+1) % 1024] > llim) {
// calculate delta_v
dv = wf[(i+1) % 1024] - wf[i % 1024];
// average delta_v; instert here averager value
}
}
// calculate calibration every 100 events
if ((iIter + 1) % 100 == 0) {
// average over all 1024 dU
sum = 0;
for (i=0 ; i<1024 ; i++) {
// averager value for: cellDV[i] = ave->Median(0, channel, i);
sum += cellDV[i];
}
sum /= 1024; // sum = sum/1024
dtCell = (float )1/fNominalFrequency; // fNominalFrequency needs to be determined separately
// dT =dV/average * dt_cell
for (i=0 ; i<1024 ; i++)
cellDT[i] = cellDV[i] / sum * dtCell;
}
return 1;
}
Jun 21, 2017 at 9:42am UTC
1 2 3
ifstream in( "dv_values.txt" );
for ( int r = 0; r <1024; r++ ) in >> wf[r];
in.close();
Last edited on Jun 21, 2017 at 9:43am UTC
Jun 21, 2017 at 10:33am UTC
Great! Thanks.
Topic archived. No new replies allowed.