sscanf with wrong parameters

Hi

I'm trying to write a script to be used with ROOT from CERN. But I'm having a error which I don't know what's causing it.

The objective is to the script read some data files, grab the numbers, and fill a histogram with them.

This is the script:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
  char name[20], title[20], file_name[30];
  ifstream read;
  string line;
  Float_t x, y, rms, file=8.0;
  Int_t i, n;
  TProfile *h;
  TObjArray Hlist(0);
  
  //open data files
  for(i=0; i<=6; i++, file+=0.5){
    sprintf(file_name,"%.1fmev/energy-ph-trans.dat",file);
    read.open(file_name);
    
    //put stream pointer in the 6th line
    for(n=1; n<=8; n++){
      getline(read,line);
    }
    
    //get and write data lines
    while(!read.eof()){
      
      //read data from file
      line.clear();
      getline(read,line);
      sscanf(line," %.1f %.1f %.1f ", &x, &y, &rms);
      
      //write name and title of histogram
      sprintf(name,"%.1f", file);
      sprintf(title,"%.1f MeV", file);

      //create histogram
      h = new TProfile(name,title,60,5000000,11000000);
      Hlist.Add(h);
      h->Fill(x,y,rms);
    }
    
    //close the data files
    read.close();
  }

  TFile f("histograms.root","Bremsstrahlung","RECREATE");
  Hlist->Write();
}


The stuff that begins with a capital "T" are constructors from the ROOT, so don't pay attention to them. The error is with sscanf because when I try to execute the script I get this error:

Error: sscanf parameter mismatch param[0] C u create_histograms.cpp:27:
*** Interpreter error recovered ***
*** Interpreter error recovered ***


The data format of the files is this:

# Results from PENCYL.
# Energy distribution of transmitted photons.
# 1st column: E (eV).
# 2nd and 3rd columns: probability density and STU (1/(eV*particle)).

5.050000E+06 5.799000E-10 2.284469E-11
5.150000E+06 5.535000E-10 2.231866E-11
5.250000E+06 5.353000E-10 2.194867E-11
5.350000E+06 5.155000E-10 2.153894E-11
5.450000E+06 4.977000E-10 2.116383E-11
5.550000E+06 4.868000E-10 2.093081E-11
5.650000E+06 4.766000E-10 2.071037E-11
5.750000E+06 4.595000E-10 2.033546E-11
5.850000E+06 4.336000E-10 1.975406E-11
5.950000E+06 4.270000E-10 1.960315E-11
6.050000E+06 4.061000E-10 1.911740E-11
6.150000E+06 4.024000E-10 1.903012E-11
6.250000E+06 4.073000E-10 1.914563E-11
6.350000E+06 3.833000E-10 1.857301E-11
6.450000E+06 3.790000E-10 1.846854E-11
6.550000E+06 3.510000E-10 1.777326E-11
6.650000E+06 3.360000E-10 1.738936E-11
6.750000E+06 3.437000E-10 1.758748E-11
6.850000E+06 3.205000E-10 1.698354E-11
6.950000E+06 3.181000E-10 1.691984E-11
7.050000E+06 2.960000E-10 1.632152E-11
7.150000E+06 2.897000E-10 1.614690E-11
7.250000E+06 2.899000E-10 1.615247E-11
7.350000E+06 2.818000E-10 1.592523E-11
7.450000E+06 2.703000E-10 1.559690E-11
7.550000E+06 2.730000E-10 1.567461E-11
7.650000E+06 2.512000E-10 1.503577E-11
7.750000E+06 2.388000E-10 1.465998E-11
7.850000E+06 2.341000E-10 1.451499E-11
7.950000E+06 2.403000E-10 1.470594E-11
8.050000E+06 2.308000E-10 1.441233E-11
8.150000E+06 2.307000E-10 1.440921E-11
8.250000E+06 2.156000E-10 1.392967E-11
8.350000E+06 2.002000E-10 1.342298E-11
8.450000E+06 1.940000E-10 1.321350E-11
8.550000E+06 1.910000E-10 1.311094E-11
8.650000E+06 1.794000E-10 1.270658E-11
8.750000E+06 1.728000E-10 1.247066E-11
8.850000E+06 1.714000E-10 1.242004E-11
8.950000E+06 1.608000E-10 1.202987E-11
9.050000E+06 1.593000E-10 1.197363E-11
9.150000E+06 1.491000E-10 1.158395E-11
9.250000E+06 1.425000E-10 1.132467E-11
9.350000E+06 1.356000E-10 1.104710E-11
9.450000E+06 1.320000E-10 1.089947E-11
9.550000E+06 1.317000E-10 1.088708E-11
9.650000E+06 1.223000E-10 1.049136E-11
9.750000E+06 1.153000E-10 1.018670E-11
9.850000E+06 1.080000E-10 9.858953E-12
9.950000E+06 9.980000E-11 9.477294E-12
1.005000E+07 9.580000E-11 9.285428E-12
1.015000E+07 8.130000E-11 8.553912E-12
1.025000E+07 7.660000E-11 8.302980E-12
1.035000E+07 6.690000E-11 7.759484E-12
1.045000E+07 5.980000E-11 7.336190E-12
1.055000E+07 5.370000E-11 6.951959E-12
1.065000E+07 4.380000E-11 6.278521E-12
1.075000E+07 3.960000E-11 5.969913E-12
1.085000E+07 2.770000E-11 4.992988E-12
1.095000E+07 1.370000E-11 3.511408E-12


Thanks in advance. :)
Topic archived. No new replies allowed.