Re: Newbie Question- strtok type mismatch

From: Hermann Fuchs <hermann.fuchs_at_meduniwien.ac.at>
Date: Mon, 2 May 2011 09:06:33 +0200


Hello

I am using the current stable version, version 5.28

It causes a type missmatch, wheter I start it with .x myfile.cxx or .x myfile.cxx+

I have attached my script below, perhaps it is something trivial, which I'm just not seeing.
The reason why I'm using this complicated read process instead of using the built-in ReadFile is, because I've to preprocess the values first. The current source file consists of a single column of data which can be surrounded by leading and trailing spaces and blank lines. In the next step I want to read in a 8000*8000 matrix therefore the complicated design.

any help would be greatly appreciated,
Cheers,
Hermann
{
gROOT->Reset();
Int_t i,numValRead;
//the variables for the data

Double_t depth=0;
Double_t EDep=0;

Double_t x,y,z;
Double_t incrementX,incrementY,incrementZ;
Double_t startX,startY,startZ;
Double_t value;

Int_t nBytes=10000;
Int_t len=0;
Char_t line[nBytes];
Char_t* splitedString;

value=x=y=z=0;
incrementX=incrementY=incrementZ=0.05;
startX=startY=startZ=0;

x=startX;
y=startY;
z=startZ;

// open the ASCII file

FILE *fp = fopen("sourceFileOneColumn.txt","r");

// create a new ROOT file

 TFile *f = new TFile("testv1.root","RECREATE");

// create a TTree

TTree *tree = new TTree("EDep","OneDimZ-Edep");

//create two branches with one variable each
tree.Branch("depth",&depth,"depth/D");
tree.Branch("EDep",&depth,"EDep/D");

// fill the tree from the values in ASCII file
while (fgets(line,(nBytes),fp))
 {

                // remove newline
   len = strlen(line);

	if( line[len-1] == '\n' ) line[len-1] = 0;
		//if stringlenght was zero, line is empty, skip it
		if (strlen(line) == 0) continue;

		//if starting with # skip line and go to next line
		if (line[0] == '#')
		  {
		 //printf( "# detected \n");
		    continue;
		}

		//cut string by seperators
		printf("here\n");

		splitedString = strtok(line," ");

		while (splitedString != NULL)
		{
			//Fill tree
			EDep=atof (splitedString);
			depth=z;
			tree->Fill();

			splitedString = strtok (NULL, " ");			
			//increment z
			z=z+incrementZ;
		}		

 }

// check what the tree looks like

tree->Print();

//close the source file

fclose(fp);

//write data to root file

f->Write();

//Close the root file

f->Close();
}

On Fri, 2011-04-29 at 10:25 -0500, Philippe Canal wrote:

> Hi Hermann,
> 
> I can not reproduce the problem with the trunk.   Which version of ROOT are you using?
> 
> Cheers,
> Philippe.
> 
> On 4/29/11 9:05 AM, Hermann Fuchs wrote:
> > Hello
> >
> > I apologize if this is a stupid question, as I am pretty new to Root
> > development.
> >
> > I am trying to split a string using strtok. The same code fragment works
> > outside of root, so i am unsure why this would cause an error.
> >
> > The troubling lines are:
> >
> > Char_t line[nBytes];
> > Char_t* splitedString;
> > ...
> > fgets(line,(nBytes+1),fp)
> > ...
> >
> > splitedString = strtok(line," ");
> >
> > The following error occurs:
> >
> > Error: strtok param[0] type mismatch readFilesv1.cxx:57:
> > *** Interpreter error recovered ***
> >
> >
> > Does anybody have an idea how to solve that problem?
> > Any idea would help.
> > Background info: I am trying to read an Asci file delimited by spaces.
> >
> >
> > Cheers,
> > Hermann
> >
> 
> 
Received on Mon May 02 2011 - 09:06:38 CEST

This archive was generated by hypermail 2.2.0 : Mon May 02 2011 - 11:50:01 CEST