// Read the data (first line comes from header analysis)
nLines=*nParam+1;
while(!feof(bayes)&&!ferror(bayes))
{
// Test for line too long
if(strlen(line)+1==LINESIZE)
{
fprintf(stderr,"ERROR: while reading bayes.dat line %ld. Increase LINESIZE(current value is=%d) to match the line size in bayes.dat.\n",nLines,LINESIZE);
exit(1);
}
// Skip the fist column and read the 2nd one
pch=strtok(line," ");
// Fill array[][*nVal]
j=0;
while(j<*nParam&&pch!=NULL)
{
pch=strtok(NULL," ");
if(pch!=NULL)
{
intlnval;
doubleval;
if(sscanf(pch,"%dx%lf",&lnval,&val)==2)
{
longinti;
for(i=0;i<lnval;i++)
array[j++][*nVal]=val;
}
elseif(sscanf(pch,"%lf",&array[j++][*nVal])!=1)
{
fprintf(stderr,"ERROR: while reading bayes.dat line %ld, column %d. pch = %s\n",*nVal,j+1,pch);
pch=NULL;
*nVal-=1;
}
}
}
// normal exit: (j == *nParam && pch != NULL) || pch == NULL (it points on the last element)
if(j<*nParam)// if true pch != NULL
{
fprintf(stderr,"ERROR: while reading bayes.dat line %ld, not enough parameters (%d/%d).\n",nLines,j+1,*nParam+1);
*nVal-=1;
}
fgets(line,LINESIZE,bayes);
line[strlen(line)-1]='\0';
nLines++;
(*nVal)++;
}
fprintf(stderr,"INFO: %ld good lines found in bayes.dat\n",*nVal);