Subversion Repositories f9daq

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <TString.h>
  4. #include <TGraph.h>
  5. #include <TCanvas.h>
  6. #include <TMultiGraph.h>
  7.  
  8. int IUdraw(const char *datoteka =  "C:/home/data/meritev-iv.dat"){
  9. auto c1 = new TCanvas("c1","A Simple Graph Example",200,10,1400,1000);
  10. c1->SetLogy();
  11. auto mg = new TMultiGraph();
  12. char setNames[40][20] = {"gr1", "gr2", "gr3", "gr4", "gr5", "gr6","gr7","gr8"};
  13. char barve[40][20] = {"kBlue", "kRed", "kGreen", "kOrange", "kYellow", "kPurple","kBlack","kMagenta"};
  14. char naslovi[40][35] = {"testna"};
  15.  
  16.  printf("#%s#\n", datoteka);
  17.  /*
  18. string s = datoteka;
  19. s.erase(s.find_last_of("."), string::npos);
  20. fprintf(stderr,"%s\n", s.c_str());
  21. std::string key ("/");
  22. string ime;
  23. std::size_t found = s.rfind(key);
  24. if (found!=std::string::npos) {
  25.   ime = s.substr(found+1,s.length());
  26. }
  27. */
  28. TString ime = gSystem->BaseName(datoteka);
  29. TString path = gSystem->DirName(datoteka);
  30. ime.Remove(ime.Index(".dat"));
  31. fprintf(stderr,"Ime=%s\n", ime.Data());
  32. TString formatted = path + TString("/") + ime + TString(".png");
  33. //formatted.Form("%s.png", );
  34. fprintf(stderr,"png=%s\n", formatted.Data());
  35. TString formattedGraph;
  36. formattedGraph.Form("I ( V ) -> %s ; Voltage [V]; Current [A]", ime.Data());
  37.  
  38. for (Int_t d = 0; d<1; d++) {
  39.   FILE * fp=fopen(datoteka,"r");
  40.   if (!fp) continue;
  41.   float f[4];
  42.   Int_t j=0;  
  43.   Int_t ndim=400;
  44.   char line[400];  
  45.   double fpXX[250];
  46.   double fpYY[250];
  47. //  Int_t k = 0;
  48.   while (fgets(line,ndim,fp)!=NULL) {
  49.         if (line[0] == '#') continue;
  50.     sscanf(line,"%f%f%f%f",&f[0],&f[1],&f[2],&f[3]);
  51.         printf("%f %f %f %f \n",f[0],f[1],f[2],f[3]);
  52.         fpXX[j]=f[2];
  53.         fpYY[j]=f[3];
  54.         j++;
  55.   }
  56.   // float *fpx =    new float[j+1];
  57.   // float *fpy =    new float[j+1];
  58.   // for (Int_t i=0; i<j-3; i++) {
  59.     // if (fpXX[i]!= 0) {
  60.                 // k++;
  61.                 // fpx[i]=fpXX[i+2];
  62.                 // fpy[i]=fpYY[i+2];
  63.                 // printf("%2.6f\t",fpx[i]);
  64.                 // printf("\n");
  65.                 // printf("%2.6f\t",fpy[i]);
  66.                 // printf("\n");
  67.         // }
  68.   // }
  69.   fclose(fp);
  70.  
  71.   auto graf = new TGraph();
  72.   graf->SetMarkerStyle(20);
  73. //  graf->SetName(setNames[d]);
  74. //  graf->SetTitle(naslovi[d]);
  75.   graf->SetDrawOption("AP");
  76. //  graf->SetLineColor(d+1);
  77.   graf->SetLineWidth(3);
  78.   graf->SetFillStyle(0);
  79.  
  80.   for (int i=0; i<j; i++) {
  81.         if (fpYY[i]<=0) fpYY[i] = 1e-12;  
  82.         graf->SetPoint(i,fpXX[i],fpYY[i]);
  83.   }
  84.   mg->Add(graf,"PL"); //graf->SetTitle(naslovi[d]); //graf->SetLineWidth(3);
  85.   //delete fpXX;
  86.   //delete fpYY;
  87. }
  88. mg->SetTitle(formattedGraph);
  89. mg->Draw("A pmc plc");
  90. //c1->BuildLegend();
  91. c1->SaveAs(formatted);
  92. return 0;
  93. }
  94.