fscanf input

Hi, i'm working on a project and i'm trying to dissect someone else's code.
They used fscanf and i can't replicate their results. I've tried figuring this out for two weeks but i've been busy and i can't find (but i'm sure there is) a good answer out there.

Here are the important parts


wfm = vector(1,npts);
time1 = vector(1,npts);

for(k=1;k<=npts1;k++)
{
fscanf(fp1,"%f,%f\n",time1+k, wfm+k);
}


I would like to take in a simple two dimensional data file either to an array, or using vectors, but i haven't used vectors before.

Any suggestions on how to do this, either using arrays or vectors?
Thanks





Here's some of the data file:
Time,Ampl
-5.00025e-06,0.000212647
-4.99975e-06,0.000187012
-4.99925e-06,0.000125977
-4.99875e-06,5.51758e-05
-4.99825e-06,8.56934e-05














#include <math.h>
#include <stdio.h>
#include <values.h>
#include <stdlib.h>

#define PI M_PI
#define eps 1.e-20

typedef struct {float re, im; } complex;

main(argc,argv)
int argc; char **argv;
{
int i, i0, j, k, l, c,N,eof,npts,npts0,npts1,npts2,Npts, eof1,eof2;
int n1, n2, trignum, K1, K2, nchan1, nchan2,n1L,n1R;
double mean, pow(), exp(), gamma(), ck, dtausum, toffs0,toffs1;
double kpoi(),Nf2,S2,K, tmpsum, wfmsum, ntsum,nwsum;
double Ibar,tau,dtau,nu,nubar,dnu,lambar,dlam,rate,drate,sweep,S;
double tmp2sum, tmpsig, wfm2sum, wfmsig, testamp, testoff;
double ttime, A1, A2, Tamp, tfreq, twidth, t1, t2;
float *wfm, *templt, *tmp, *corr,*time0,*time1,a,b;
float *tmp1,*tmp2,tmpin;
float dat1Asum, dat1Bsum,dat2sum,dat1Amean,dat1Bmean,dat2mean;
char file1[80], file2[80], Header1L[80], Header1R[80], Header2[80],test[80];

FILE *fopen(), *fp1, *fp0;

void correl();

if(argc<4){
fprintf(stderr,
"usage: spolexcor [Templ freq][width][data file] \
[npts1][toffs0][toffs1][testoffs][testamp] >corrfile\n");
exit(0);
}

tfreq = atof(argv[1]);
twidth = atof(argv[2]);
npts1 = atoi(argv[4]);
toffs0 = atof(argv[5]); //time offset from beginning of file to start of pulse
toffs1 = atof(argv[6]);//time offset to trigger point
testoff = atof(argv[7]); // times offset for test signal
testamp = atof(argv[8]); // test signal amplitude in V

Npts = npts1;

i=0;
k=Npts;
/* get next higher power of 2, then factor of 2 bigger for cross cor,
we need the extra length for the tail of the CCF */
while((k=k>>1) > 0){
i++;
}
npts = 1 << (i+2);

fprintf(stderr,"npts1= %d, npts= %d\n", npts1, npts);


wfm = vector(1,npts);
time1 = vector(1,npts);
templt = vector(1,npts);
tmp = vector(1,npts0);
fp1 = fopen(argv[3],"r");

/* first jump over the header info */

for(i=0;i<5;i++){
n1L += fscanf(fp1,"%[^\n]\n", Header1L);
}
/* then read the data */

tmpsum = ntsum = tmp2sum= 0.0;

wfmsum = nwsum = wfm2sum= 0.0;
for(k=1;k<=npts1;k++){
fscanf(fp1,"%f,%f\n",time1+k, wfm+k);
if(k>npts1/2){
wfmsum += wfm[k];
wfm2sum += wfm[k]*wfm[k];
nwsum += 1.0;
}
}







Topic archived. No new replies allowed.