static void SkipComments(ifstream &input){ // Look ahead in the input stream int c; bool cont = true; bool comment = false; while(cont && !input.eof()){ c = input.peek(); // Skip spaces if(c == ' ' || c == '\t') input.get(); // Skip end-of-lines else if(c == '\n'){ input.get(); // If we were inside a comment, we just finished it. comment = false; } // Skip comments else if(c == '#' || comment){ input.get(); // We are entering a comment (starting with '#' and finishing // with the end of the line). comment = true; } // If the last character found cannot be skipped else cont = false; } } int PbF2Abslen(char *fname){ double *xx=new double[200]; double *yy=new double[200]; int nc; ifstream fin(fname); if (fin.is_open()){ while (! fin.eof() ) { SkipComments(fin); fin >> xx[nc] >> yy[nc]; if (fin.eof())break; // cout << "x:" << xx[nc] <<" y:" << yy[nc]<< endl; nc++; } fin.close(); } else { cerr << fname <<" cannot be opened! "<< endl; } TGraph *g=new TGraph(nc,xx,yy); nc=0; for (double i=340;i<840;i+=10){ // cout << i << " " << -10/log(g->Eval(i)/100.)<< endl; cout << i << " " << g->Eval(i)<< endl; xx[nc] = i; yy[nc] = g->Eval(i); nc++; } TGraph *g1=new TGraph(nc,xx,yy); TCanvas *c= new TCanvas("c","c",600,600); g->Draw("AC*"); g1->Draw("L"); c->Modified(); c->Update(); return 0; }