Drawing graph from a text file by skipping 1st 47 rows

Dear
I am new in root. So sorry if anything very easy.
I cannot call my text file (“Image.txt”) in root V 5.34. This text file contains 9 column and 250 rows. I want to read 2nd, 3rd, 4th, 5th and 7th (those are separated by “,” and have the value from row 47) column as x,y, a, b, z. Then I want to draw graph as y Vs x, b vs a and histogram as count/bin Vs z. Before that I need to grab the value of these column from rows 47. How can I solve this problem? Thanks in advance for your kind help. File (Image.txt) as an attachment:
http://www.filedropper.com/image_9

I am not sure to understand what you want to plot but here is an example reading your file and producing a graph out of it. You can then elaborate from that and customise it as you wish.

void Image()
{
   FILE *f = fopen("Image.txt","r");
   if (!f) {
      printf("Could not open Image.txt\n");
      return;
   }
   char line[200];
   float v1,v2,v3,v4,v5,v6,v7;
   Int_t i = 0;
   TGraph *g = new TGraph();
   while (fgets(line,160,f)) {
      if (i>51) {
         sscanf(&line[0]  ,"%g,%g,%g,%g,%g,%g,%g",&v1,&v2,&v3,&v4,&v5,&v6,&v7);
         g->SetPoint(i,v1,v2);
      }
      i++;
   }
   fclose(f);
   g->Draw();
}

Thanks for your kind help. It shows a blank canvas and message like:
Info in TCanvas::MakeDefCanvas: created default TCanvas with name c1
Error in TGraphPainter::PaintGraph: illegal number of points (0)

What does it mean? Would you please let me know how I can I proceed.

For me it is ok. I do:

$ root
   ----------------------------------------------------------------
  | Welcome to ROOT 6.09/01                    http://root.cern.ch |
  |                                   (c) 1995-2016, The ROOT Team |
  | Built for macosx64                                             |
  | From heads/master@v6-09-01-224-g5bf0afe, Oct 26 2016, 09:48:25 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'     |
   ----------------------------------------------------------------

root [0] .x Image.C
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [1] 

I get the attached picture.


Ohh! So what can I do now? I cannot understand why this illegal number!
Sorry for disturbing. But I need help to solve this problem.
Thanks again.

Post all the error messages you get … you should have more …
Note I also tried with version 5.34/37 and it works too.

http://www.filedropper.com/errormsg

Here it is. Thats all I have. Thanks.


copy/paste the code I sent you into a file named Image.C and do .x Image.C in root (see the dump I sent you … )

Sorry, the same problem.
http://www.filedropper.com/err-2


Well … I see… You should debug and understand what is wrong … The macro is super simple… a few print out should help…

If the number of points in the graph is 0 it might be i is never > 51 (see the code) ? … check that … may be your file Image.txt is not the one you send me … As I told you the macro I sent you works for me with 5.34/37 and ROOT 6.

I attach it again.

Also, the way you send the info via screen dump is a bit annoying … you can just copy/paste the output text here.
Image.C (436 Bytes)

According to your file, result is same as before. So I want to change the I value.

Int_t i = 48;
 if (i>48) 

when I change here (bold portion) it becomes like this (attached file). Now what to do?
sorry for annoying.


You should try yourself to understand what is wrong … as I said it works for me … May be you are not using the same Image.txt file you send me ? …
Do some printout (cout or printf) in the file to understand what is wrong … the logic is super simple … that’s just C code …

Sorry for time consumption and bothering.
Thank you very much for your nice and helpful suggestion.

Attached is the macro with some debugging statements which might help you to understand what is going wrong.
Image.C (628 Bytes)

Dear, its work nicely. Thanks for your kind co-operation.
Now when I am trying to execute the file by “.x Image.C”, it shows me the following message.

“Error in TApplication::ExecuteFile: macro Image.C not found in path .;C:\root_v5.34.36/macros;”

What does it mean? how can I solve it?

Thanks and regards.

http://www.filedropper.com/image_23

One more thing, can I draw histogram from this by adding the following lines:

[code]TH1F *h1=new TH1F (“h1”,“Histo for Elps Area”,20,-10,10);
while (fgets(line,160,f)) {
if (i>51) {
sscanf(&line[0] ,"%g,%g,%g,%g,%g,%g,%g,%g",&v1,&v2,&v3,&v4,&v5,&v6,&v7,&v8);
h1->Fill(i,v8);
}
i++;
}

TCanvas *c2 = new TCanvas(“c2”,“Histo for Elps area”,400,600);
h1.Draw();[/code]

I tried but it just show me the blank canvas. I wan to draw “Count/bin Vs v8” histogram.
Thanks.

can you attach here the current version of image.C ? thanks.

http://www.filedropper.com/image_24
here it is. Thanks.
Image .C (1.64 KB)

your file name is corrupted:

$ ls Image*
Image%20.C	Image.txt

If I create the file with the good name it is ok.