0

Below is the code I've modified from Numerical Recipes. My x will represent voltage in and my y will represent the digital code out. I am still pretty new to programming and this is also my first time working in a Linux environment so I'm just wondering about the best way to read my dataset into the fit function. Thanks!

#include <vxWorks.h>
#include <vxLib.h>
#include <sysLib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <taskLib.h>

static float sqrarg;
#define SQR(a) (sqrarg=(a),sqrarg*sqrarg)


void fit(x,y,ndata,sig,mwt,a, b, siga, sigb, chi2, q)
float x[], y[], sig[], *a, *b, *siga, *sigb, *chi2, *q;
int ndata, mwt;


{
int i;
float t,sxoss,sx=0.0,sy=0.0,st2=0.0,ss,sigdat;

*b=0.0;

    for (i=1;i<=ndata; i++) {
    sx += x[i];
    sy += y[i];
    }
    ss=ndata;

sxoss=sx/ss;

        for (i=1;i<=ndata;i++) {
    t=(x[i]-sxoss);
    st2 += t*t;
    *b += t*y[i];
     }

*b /= st2;
*a=(sy-sx*(*b))/ss;
*siga=sqrt ((1.0+sx*sx/(ss+st2))/ss);
*sigb=sqrt (1.0/st2);
*chi2=0.0;

(mwt==0) 

   for (i=1;i<=ndata;i++) {
       *chi2 += SQR(y[i]-(*a)-(*b)*x[i]);
   *q=1.0;
   sigdat = sqrt((*chi2)/(ndata-2));
   *siga *= sigdat;
   *sigb *= sigdat;
  } 
}
  • What kind of data set do you have? Is it from a flat file, or a database connection? Is it a binary file, or a text file. If it's a text file, is it fixed width, or space/comma/etc delimited? – Cloud Jul 15 '14 at 16:22
  • At the moment I'm just using test data from a flat file in .cvs format. Here is the info... 1,7 2,6 3,5 4,3 5,4 6,2 7,1 8,0 9,18 10,17 11,16 12,15 13,14 14,10 15,9 16,8 17,12 18,13 19,35 20,34 21,33 22,32 23,31 24,30 25,29 26,11 27,28 28,25 29,27 30,19 31,20 32,21 33,22 34,23 35,24 – jonas85 Jul 15 '14 at 19:43
  • Then this should help you read a delimited CSV file in C: http://stackoverflow.com/questions/12911299/read-csv-file-in-c – Cloud Jul 15 '14 at 20:24

0 Answers0