Run a program that read text file

I have a program that reads a txt file and create a histogram.

void Example(const char* NameofDataText, const char* histName)

with this function

How can I call it from cmd?

.x namefile("NameOfTxtFile.txt","NameOfHistogram.root")

Is this correct? Because cmd gives me that namefile doesn’t exist in macro. But there is in macro.

Imagine your macro file is named namefile.C, the function in your file should be also named name file… or the opposite if your function is named Example the macro file should be named Example.C … then to execute it you should do:

.x Example.C("NameOfTxtFile.txt","NameOfHistogram.root")
1 Like

Ok but now he say that NameOfTxtFile (in my case Dati) doesn’t exist. the txt file should go in the macro folder? I have a simple txt like this:

Dati.txt (59 Bytes)

It depends how you open it … but yes, I guess so.
Hard to tell without seeing your macro…

Ciao.C (987 Bytes)

It seems ok for me:

$ root
  | Welcome to ROOT 6.19/01               |
  | (c) 1995-2019, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosx64 on Sep 26 2019, 14:45:29                      |
  | From heads/master@v6-19-01-1381-gc7c1340fbe                      |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |

root [0] .x Ciao.C("Dati.txt","Dati.root")
Dati letti: 14
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [1] 

where have you put the txt file? I have put it in macros folder but it continues to tell me that file Dati.txt doesn’t exist. I use Visual Studio 2019 and Windows 10

It has some probles in the reading part. The program is fine. But it enters in if and gives that message.

Your macro opens the txt file in the current working directory.
I put the macro and the txt file in the same folder: the folder from where you should run root.

I put them in the same folder. The folder (called macros ) in which i put programs in order to run them but it seems it doesnt see the txt, if we delete the if root tells me that it has read 0 data instead of 14.
I dont know probably this problem is linked with

Your macro is written in a such way that:

  1. The two files (txt and .C) must be in the same folder
  2. You should start root from that folder

What does it mean starting root from that folder?

Thank you for your help

At the shell prompt you cd to that folder and start root from there.

$ cd the-folder-where-your-files-are
$ root

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.