#include <stdlib.h>
#include <stdio.h>
#include <TString.h>
#include <TGraph.h>
#include <TCanvas.h>
#include <TMultiGraph.h>
int IUdraw(const char *datoteka = "C:/home/data/meritev-iv.dat"){
auto c1 = new TCanvas("c1","A Simple Graph Example",200,10,1400,1000);
c1->SetLogy();
auto mg = new TMultiGraph();
char setNames[40][20] = {"gr1", "gr2", "gr3", "gr4", "gr5", "gr6","gr7","gr8"};
char barve[40][20] = {"kBlue", "kRed", "kGreen", "kOrange", "kYellow", "kPurple","kBlack","kMagenta"};
char naslovi[40][35] = {"testna"};
printf("#%s#\n", datoteka);
/*
string s = datoteka;
s.erase(s.find_last_of("."), string::npos);
fprintf(stderr,"%s\n", s.c_str());
std::string key ("/");
string ime;
std::size_t found = s.rfind(key);
if (found!=std::string::npos) {
ime = s.substr(found+1,s.length());
}
*/
TString ime = gSystem->BaseName(datoteka);
TString path = gSystem->DirName(datoteka);
ime.Remove(ime.Index(".dat"));
fprintf(stderr,"Ime=%s\n", ime.Data());
TString formatted = path + TString("/") + ime + TString(".png");
//formatted.Form("%s.png", );
fprintf(stderr,"png=%s\n", formatted.Data());
TString formattedGraph;
formattedGraph.Form("I ( V ) -> %s ; Voltage [V]; Current [A]", ime.Data());
for (Int_t d = 0; d<1; d++) {
FILE * fp=fopen(datoteka,"r");
if (!fp) continue;
float f[4];
Int_t j=0;
Int_t ndim=400;
char line[400];
double fpXX[250];
double fpYY[250];
// Int_t k = 0;
while (fgets(line,ndim,fp)!=NULL) {
if (line[0] == '#') continue;
sscanf(line,"%f%f%f%f",&f[0],&f[1],&f[2],&f[3]);
printf("%f %f %f %f \n",f[0],f[1],f[2],f[3]);
fpXX[j]=f[2];
fpYY[j]=f[3];
j++;
}
// float *fpx = new float[j+1];
// float *fpy = new float[j+1];
// for (Int_t i=0; i<j-3; i++) {
// if (fpXX[i]!= 0) {
// k++;
// fpx[i]=fpXX[i+2];
// fpy[i]=fpYY[i+2];
// printf("%2.6f\t",fpx[i]);
// printf("\n");
// printf("%2.6f\t",fpy[i]);
// printf("\n");
// }
// }
fclose(fp);
auto graf = new TGraph();
graf->SetMarkerStyle(20);
// graf->SetName(setNames[d]);
// graf->SetTitle(naslovi[d]);
graf->SetDrawOption("AP");
// graf->SetLineColor(d+1);
graf->SetLineWidth(3);
graf->SetFillStyle(0);
for (int i=0; i<j; i++) {
if (fpYY[i]<=0) fpYY[i] = 1e-12;
graf->SetPoint(i,fpXX[i],fpYY[i]);
}
mg->Add(graf,"PL"); //graf->SetTitle(naslovi[d]); //graf->SetLineWidth(3);
//delete fpXX;
//delete fpYY;
}
mg->SetTitle(formattedGraph);
mg->Draw("A pmc plc");
//c1->BuildLegend();
c1->SaveAs(formatted);
return 0;
}