Hi.
I am trying to read a file that basically contains the following:
RXbytes = 98 b TXbytes = 98 b
RXbytes = 98 b TXbytes = 98 b
RXbytes = 6 Kb TXbytes = 3 Kb
RXbytes = 749 Kb TXbytes = 21 Kb
RXbytes = 955 Kb TXbytes = 25 Kb
RXbytes = 945 Kb TXbytes = 24 Kb
RXbytes = 945 Kb TXbytes = 24 Kb
RXbytes = 945 Kb TXbytes = 23 Kb
RXbytes = 964 Kb TXbytes = 23 Kb
RXbytes = 945 Kb TXbytes = 25 Kb
RXbytes = 945 Kb TXbytes = 23 Kb
RXbytes = 945 Kb TXbytes = 23 Kb
RXbytes = 945 Kb TXbytes = 23 Kb
RXbytes = 945 Kb TXbytes = 23 Kb
RXbytes = 958 Kb TXbytes = 24 Kb
RXbytes = 950 Kb TXbytes = 24 Kb
RXbytes = 945 Kb TXbytes = 24 Kb
RXbytes = 945 Kb TXbytes = 23 Kb
RXbytes = 945 Kb TXbytes = 23 Kb
RXbytes = 945 Kb TXbytes = 23 Kb
RXbytes = 945 Kb TXbytes = 24 Kb
RXbytes = 945 Kb TXbytes = 24 Kb
RXbytes = 945 Kb TXbytes = 23 Kb
RXbytes = 152 Kb TXbytes = 4 Kb
RXbytes = 98 b TXbytes = 98 b
RXbytes = 98 b TXbytes = 98
but however the following error
*** Break *** segmentation violation
Generating stack trace…
0x00323b6c in memcpy + 0x1c from /lib/libc.so.6
0x00e0747e in G__interpret_func at ifunc.cxx:0 from /users/root_v5.20/lib/libCint.so
0x00df3966 in G__getfunction at func.cxx:0 from /users/root_v5.20/lib/libCint.so
0x00dd7e70 in G__getitem at expr.cxx:0 from /users/root_v5.20/lib/libCint.so
0x00ddaabb in G__getexpr at expr.cxx:0 from /users/root_v5.20/lib/libCint.so
0x00dca2e4 in G__define_var + 0x1ac8 from /users/root_v5.20/lib/libCint.so
0x00e4e880 in G__exec_statement at parse.cxx:0 from /users/root_v5.20/lib/libCint.so
0x00dc5c68 in from /users/root_v5.20/lib/libCint.so
0x00dc6fa3 in G__exec_tempfile_fp + 0x13 from /users/root_v5.20/lib/libCint.so
0x00e5eb2c in G__process_cmd + 0x14c8 from /users/root_v5.20/lib/libCint.so
0x0073b8db in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0x343 from /users/root_v5.20/lib/libCore.so
0x00680a16 in TApplication::ProcessLine(char const*, bool, int*) + 0x62a from /users/root_v5.20/lib/libCore.so
0x0011ce9a in TRint::HandleTermInput() + 0x1a6 from /users/root_v5.20/lib/libRint.so
0x0011b4f0 in TTermInputHandler::Notify() + 0x24 from /users/root_v5.20/lib/libRint.so
0x0011d78e in TTermInputHandler::ReadNotify() + 0x12 from /users/root_v5.20/lib/libRint.so
0x0074ae02 in TUnixSystem::CheckDescriptors() + 0x1d2 from /users/root_v5.20/lib/libCore.so
0x0074f024 in TUnixSystem::DispatchOneEvent(bool) + 0x448 from /users/root_v5.20/lib/libCore.so
0x006d88bc in TSystem::InnerLoop() + 0x18 from /users/root_v5.20/lib/libCore.so
0x006d8683 in TSystem::Run() + 0x77 from /users/root_v5.20/lib/libCore.so
0x00680b02 in TApplication::Run(bool) + 0x32 from /users/root_v5.20/lib/libCore.so
0x0011bc6e in TRint::Run(bool) + 0x37e from /users/root_v5.20/lib/libRint.so
0x08048d46 in main + 0x52 from /users/root_v5.20/bin/root.exe
0x002c7e9c in __libc_start_main + 0xdc from /lib/libc.so.6
0x08048c6d in TApplicationImp::ShowMembers(TMemberInspector&, char*) + 0x31 from /users/root_v5.20/bin/root.exe
Root > Function readThroughput() busy flag cleared
networkMacros.C
// sets nice plotting settings
int rootlogon ()
{
gStyle->SetDrawBorder(0);
gStyle->SetCanvasColor(kWhite);
gStyle->SetCanvasDefH(800);
gStyle->SetCanvasDefW(800);
gStyle->SetCanvasBorderMode(0);
gStyle->SetPadBorderMode(0);
gStyle->SetPaintTextFormat("5.2f");
gStyle->SetLineWidth(2);
gStyle->SetTextSize(1.1);
gStyle->SetLabelSize(0.04,"xy");
gStyle->SetTitleSize(0.05,"xy");
gStyle->SetTitleOffset(1.0,"x");
gStyle->SetTitleOffset(1.6,"y");
gStyle->SetPadTopMargin(0.05);
gStyle->SetPadRightMargin(0.05);
gStyle->SetPadBottomMargin(0.15);
gStyle->SetPadLeftMargin(0.15);
gStyle->SetLegendBorderSize(1);
gStyle->SetFrameBorderMode(0);
gStyle->SetFrameFillColor(kWhite);
gStyle->SetTitleFillColor(kWhite);
gStyle->SetStatFontSize(0.03);
gStyle->SetStatBorderSize(1);
gStyle->SetStatFormat("6.4g");
gStyle->SetStatX(0.95);
gStyle->SetStatY(0.95);
gStyle->SetStatW(0.2);
gStyle->SetStatH(0.2);
gStyle->SetStatColor(kWhite);
gStyle->SetTitleX(0.3);
gStyle->SetTitleY(0.98);
gStyle->SetTitleBorderSize(1);
gStyle->SetTitleFontSize(0.06);
gStyle->SetLegendBorderSize(1);
gROOT->SetStyle("Default");
gROOT->ForceStyle();
return 0;
}
//read data file fname with nread readings and return a 1D histogram
TH1F readThroughput(char *fname, int nread) {
char rec, trans, equal00, equal01;
int rxThoughput, txThroughput;
int i,j;
string RXunit, TXunit;
TH1F *h = new TH1F("h1","Network Throughput", nread, 0.5, nread-0.5);
FILE *fp = fopen(fname, "r");
if (fp == NULL) {
printf("Cound not open file %s\n",fname);
return h;
}
for (i=0; i<nread; i++) {
fscanf(fp,"%c %c %d %c %c %c %d %c", &rec, &equal00, &rxThoughput, &RXunit, &trans, &equal01, &txThroughput, &TXunit);
h->SetBinContent(i+1, rxThoughput);
}
fclose(fp);
h->Sumw2();
return h;
}
and
networkMacros.h
#ifndef NETWORKMACROS_H
#define NETWORKMACROS_H
#include <stdio.h>
#include <TMath.h>
#include <TStyle.h>
#include <TH1F.h>
#include <TH2F.h>
#include <TF1.h>
#include <TGraph.h>
#include <TGraphErrors.h>
#include <TROOT.h>
#include <THStack.h>
#include <TColor.h>
#include <TCanvas.h>
#include <TAxis.h>
#include <iostream>
#include <TMultiGraph.h>
#include <TLegend.h>
int rootlogon();
TH1F readThroughput(char *fname, int nread);
#endif
what is wrong with my fscanf?
.L networkMacros.C
.x networkMacros.h