Take data from a file and make a graph

Hi everyone
This is my first topic on this forum so I hope it will be all fine.

I’m going to show you my problem:
I have a file filled with some data.
Those data are arranged in five columns.
The first column is filled with time data and the other four columns are voltages of a certain thing.
What I have to do is plot on the same graph time vs voltage… so I must have four plots on the same graph (preferably, each plot of a different color).
Could you please tell me which are the commands I have to type on root to do this?
My problem is that I don’t know how to take data from a file and plot them and where the file is supposed to be on my computer.
Thank you very much for your help.

The code:

{
   FILE *f = fopen("graphsfromfile.dat","r");
   Int_t i=0;
   Double_t x[10],y1[10],y2[10],y3[10],y4[10];
   while (!feof(f)){ 
      fscanf(f,"%lf %lf %lf %lf %lf\n",&x[i],&y1[i],&y2[i],&y3[i],&y4[i]);
      i++;
   }
   TGraph g1(10,x,y1); g1->SetLineColor(2);
   TGraph g2(10,x,y2); g2->SetLineColor(3);
   TGraph g3(10,x,y3); g3->SetLineColor(4);
   TGraph g4(10,x,y4); g4->SetLineColor(5);
   g1.Draw("AL*");
   g2.Draw("L*");
   g3.Draw("L*");
   g4.Draw("L*");
}

The data:

$ cat graphsfromfile.dat
0. 0. 0. 5. 1.
1. 1. 1. 4. 2.
2. 2. 2. 3. 6.
3. 3. 3. 2. 5.
4. 4. 4. 1. 7.
5. 5. 5. 2. 8.
6. 6. 4. 3. 9.
7. 7. 3. 4. 0.
8. 8. 2. 5. 6.
9. 9. 1. 0. 5.

This is very simple. just to show the idea. Later you may need a TMultiGraph in order to have a common scale.


Hi
thanks for answering
Your help has been really useful.
Unfortunately I had this problem after I copied your code:

I have had the same problem in the past but I did not understand what does it means param[0]=0 must not be 0.

If you can still help me I will be very thankful to you

Can you send a small running macro reproducing this problem ?

Ops, sorry…I’ve solved my problem…
I just typed wrong the name of the tile