Re: [ROOT] Reading the Time from an ASCII File

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Mar 19 2002 - 10:52:42 MET


Hi Steffen,

a running example. See below files stime.C and stime.dat

Rene Brun

//file stime.C
void stime() {
   ifstream in;
   in.open("stime.dat", ios::in);
   int h,m,s;
   const int nmax=1000;
   double seconds[nmax], bincount[nmax];
   int ntimes = 0;
   char ctime[10];
   while (1) {
      in >> ctime >> bincount[ntimes];
      if (!in.good()) break;
      sscanf(ctime,"%d:%d:%d",&h,&m,&s);
      seconds[ntimes] = s +60*m +3600*h;
      ntimes++;
   }
   in.close();
   TCanvas *c1 = new TCanvas("c1");
   c1->SetGrid();
   TGraph *gr = new TGraph(ntimes,seconds,bincount);
   gr->SetMarkerStyle(21);
   gr->Draw("alp");
   c1->Update(); //force creation of frame histogram
   gr->GetHistogram()->GetXaxis()->SetTimeDisplay(1);
   c1->Modified();   
}

//file stime.dat
 0:00:00     771
 0:00:05     759
 0:00:10     751
 0:00:15     756
 0:00:20     752
 0:00:25     763
 0:00:30     745
 0:00:35     742
 0:00:40     745
 0:00:45     742
 0:00:50     750
 0:00:55     751
 0:01:00     739


Steffen Grohmann wrote:
> 
> Dear Rene,
> 
> I would like to know the code for reading the file, especially the time
> column, and allocate the values of the time string ("hh:mm:ss") to a
> time variable, which then can be used for scaling the x-axis
> (SetTimeDisplay etc...).
> 
> Of course, I could generate the time scale with a certain time interval
> directly in ROOT, but this only works for a constant interval between
> all the data.
> 
> In my case data might have been recorded in arbitrary time intervals,
> which need to be read from the data file.
> 
> Regards, Steffen
> 
> Rene Brun wrote:
> >
> > Hi Steffen,
> >
> > Could you clarify your request?
> > Do you want the code to read this file or simply label
> > your x axis with a time format?
> > eg;
> >
> > TH1F h("h","test",13,0,65);
> > h.GetXaxis()->SetTimeDisplay();
> > h.SetBinContent(1,771);
> > etc..
> > h.Draw();
> >
> > Rene Brun
> >
> > On Mon, 18 Mar 2002, Steffen Grohmann wrote:
> >
> > > Hello,
> > >
> > > I am looking for an option to read recoreded time values from an ascii
> > > file to be used in a histogram or graph (see example).
> > >
> > > Example file:
> > >  0:00:00     771
> > >  0:00:05     759
> > >  0:00:10     751
> > >  0:00:15     756
> > >  0:00:20     752
> > >  0:00:25     763
> > >  0:00:30     745
> > >  0:00:35     742
> > >  0:00:40     745
> > >  0:00:45     742
> > >  0:00:50     750
> > >  0:00:55     751
> > >  0:01:00     739
> > >
> > > Regards, Steffen
> > > --
> > >
> > > +------------------------------------------------------+
> > > |Steffen Grohmann             steffen.grohmann@cern.ch |
> > > +------------------------------------------------------|
> > > |CERN                                                  |
> > > |European Organization for Nuclear Research            |
> > > |ST Division                                           |
> > > |CH-1211 Geneve 23             phone:   +41 22 767-7079|
> > > |Switzerland                   fax:     +41 22 767-8767|
> > > +------------------------------------------------------+
> > >
> 
> --
> 
> +------------------------------------------------------+
> |Steffen Grohmann             steffen.grohmann@cern.ch |
> +------------------------------------------------------|
> |CERN                                                  |
> |European Organization for Nuclear Research            |
> |ST Division                                           |
> |CH-1211 Geneve 23             phone:   +41 22 767-7079|
> |Switzerland                   fax:     +41 22 767-8767|
> +------------------------------------------------------+



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