Re: [ROOT] errot in reading array of files

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Oct 11 2002 - 23:32:38 MEST


Hi  Subhendu,

Your code contains too many basic C++ errors. I fixed most of them below

Rene Brun

{
gROOT->Reset();
c1 = new TCanvas("c1","yscan ",1100,50,800,600);
c1->SetGridx();
c1->SetGridy();


const Int_t m=113;
Float_t x[m],y[m],w[m],z[m],v[m],ny[m],d[m];

FILE *fp[2];
fp[0] = fopen("pt1.dat","r");
fp[1] = fopen("pt2.dat","r");
TGraph *gr[2];


for(Int_t j=0;j<2;j++){
   for(Int_t i=0;i<m;i++) {
      fscanf(fp[j],"%f",&x[i]);
      fscanf(fp[j],"%f",&y[i]);
      fscanf(fp[j],"%f",&w[i]);
      fscanf(fp[j],"%f",&z[i]);
      fscanf(fp[j],"%f",&v[i]);
      if(y[i]<0) ny[i]=-y[i];
      else       ny[i]=y[i];
   }

   gr[j] = new TGraph(m,ny,z);
 

   gr[j]->SetLineColor(j+1);
   gr[j]->Draw("AC");

   fclose(fp[j]);
}
}


On Sat, 12 Oct 2002, Subhendu Chakrabarti wrote:

> 
> 
> I have corrected my code .Still the problem persists.
> Thanks for helping.
> 
> {
> gROOT->Reset();
> c1 = new TCanvas("c1","yscan ",1100,50,800,600);
> c1->SetGridx();
> c1->SetGridy();
> 
> 
> Int_t m=113;
> Float_t x[m],y[m],w[m],z[m],v[m],ny[m],d[m],
> 
> FILE *fp[2];
> fp[0] = fopen("pt1.dat","r");
> fp[1] = fopen("pt2.dat","r");
> 
> 
> for(Int_t j=0;j<2;j++){
> for(Int_t i=0;i<m;i++)
>   {
> fscanf(fp[j],"%f",&x[i]);
> fscanf(fp[j],"%f",&y[i]);
> fscanf(fp[j],"%f",&w[i]);
> fscanf(fp[j],"%f",&z[i]);
> fscanf(fp[j],"%f",&v[i]);
> if(y[i]<0)
>   {
> ny[i]=-y[i];
>   }
> else ny[i]=y[i];
> 
> 
> }
> 
> TGraph *gr[j] = new TGraph(m,ny,z);
>  
> 
>  gr[j]->SetLineColor(j+1);
>   gr[j]->Draw("AC");
> 
>   fclose(fp[j]);
>     }
>   }
> ***********************************************
> Warning: Automatic variable fp[0] allocated in global scope FILE:ycomp.C
> LINE:12
> Error: Array index out of range fp[1] -> [1]  valid upto fp FILE:ycomp.C
> LINE:13
> *** Interpreter error recovered ***
> *************************************************************
> 
>                
>         Subhendu Chakrabarti   
> 
>                 
> 
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:14 MET