Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "../include/root_app.h"
  2. #include "../include/workstation.h"
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7.  
  8. // Main window constructor (+layout) ---------------------------------
  9.  
  10. TGAppMainFrame::TGAppMainFrame(const TGWindow *p, int w, int h)
  11. {
  12.    // Define main window and menubar
  13.    fMain = new TGMainFrame(p, w, h, kVerticalFrame);
  14.  
  15.    AppLayout();
  16.    fMain->SetWindowName(WINDOW_NAME);
  17.    fMain->MapSubwindows();
  18.    fMain->MapWindow();
  19.    fMain->Layout();
  20. }
  21.  
  22. TGAppMainFrame::~TGAppMainFrame()
  23. {
  24.    fMain->Cleanup();
  25.    delete fMain;
  26. }
  27.  
  28. // Closing main window and checking about information ----------------
  29.  
  30. void TGAppMainFrame::CloseWindow()
  31. {
  32.    fMain->Cleanup();
  33.    delete fMain;
  34.    gApplication->Terminate(0);
  35. }
  36.  
  37. // -------------------------------------------------------------------
  38.  
  39. // -------------------------------------------------------------------
  40.  
  41. // Separate functions -----------------------------------------
  42. void GetTime(int intime, char *outtime)
  43. {
  44.    time_t rawtime;
  45.    struct tm * timeinfo;
  46.    if(intime < 0)
  47.       time(&rawtime);
  48.    else
  49.       rawtime = (time_t)intime;
  50.    timeinfo = localtime(&rawtime);
  51.    sprintf(outtime, "%s", asctime(timeinfo));
  52.    int len = strlen(outtime);
  53.    if(len) outtime[len-1] = 0;
  54. }
  55.  
  56. // ----------------------------------------------------------
  57.  
  58. // Temperature sensor functions -----------------------------
  59. const char* dbname = "mysql://f9lab08.ijs.si/f9phdet";
  60. const char* tblname = "fprtd122";
  61. const char* username = "f9daq";
  62. const char* userpass = "f9lab";
  63.  
  64. // Get the temperature from MYSQL database
  65. double GetTemperature(int ch, const char *s)
  66. {
  67.    int bin=5+7*4-ch*4;
  68.    char hex[16];
  69.    strncpy(hex, (const char *) &s[bin], 4);
  70.    hex[4]=0;
  71.    int ix;
  72.    sscanf (hex,"%x",&ix);
  73.    //printf("0x%s\t",hex);
  74.    return (ix/65535.)*1050.-200.;
  75. }
  76.  
  77. // Transform local time to timestamp
  78. int GetTimeStamp(int *intime)
  79. {
  80.    time_t rawtime;
  81.    struct tm * timeinfo;
  82.    time(&rawtime);
  83.    timeinfo = localtime(&rawtime);
  84.  
  85.    if(DBGSIG)
  86.       printf("%d.%d.%d, %d:%d:%d\n", intime[0], intime[1], intime[2], intime[3], intime[4], intime[5]);
  87.  
  88.    timeinfo->tm_mday = intime[0];
  89.    timeinfo->tm_mon = intime[1] - 1;
  90.    timeinfo->tm_year = intime[2] - 1900;
  91.    timeinfo->tm_hour = intime[3];
  92.    timeinfo->tm_min = intime[4];
  93.    timeinfo->tm_sec = intime[5];
  94.    
  95.    return (int)mktime(timeinfo);
  96. }
  97.  
  98. // Get data from MYSQL database
  99. void TGAppMainFrame::fieldpoint(int *timerange, int selch)
  100. {
  101.    char humantime[256];
  102.  
  103.    // Display selected timestamps
  104.    GetTime(timerange[0], humantime);
  105.    printf("Minimum time set to: %s (%d)\n", humantime, timerange[0]);
  106.    if(timerange[1] != -1)
  107.    {
  108.       GetTime(timerange[1], humantime);
  109.       printf("Maximum time set to: %s (%d)\n", humantime, timerange[1]);
  110.    }
  111.    printf("Selected fieldpoint channel: %d\n", selch);
  112.    printf("\n");
  113.  
  114.    // Database settings
  115.    TSQLServer *db = TSQLServer::Connect(dbname, username, userpass);
  116.    printf("Server info: %s\n", db->ServerInfo());
  117.    TSQLRow *row;
  118.    TSQLResult *res;
  119.  
  120.    if(DBGSIG)
  121.    {
  122.       // list databases available on server
  123.       printf("\nList all databases on server %s\n", db->GetHost());
  124.       res = db->GetDataBases();
  125.       while ((row = res->Next())) {
  126.          printf("%s\n", row->GetField(0));
  127.          delete row;
  128.       }
  129.       delete res;
  130.  
  131.       // list tables in database "test" (the permission tables)
  132.       printf("\nList all tables in database \"f9phdet\" on server %s\n", db->GetHost());
  133.       res = db->GetTables("f9phdet");
  134.       while ((row = res->Next())) {
  135.          printf("%s\n", row->GetField(0));
  136.          delete row;
  137.       }
  138.       delete res;
  139.    
  140.       // list columns in table "runcatalog" in database "mysql"
  141.       printf("\nList all columns in table \"f9phdet\" in database \"f9rtd122\" on server %s\n", db->GetHost());
  142.       res = db->GetColumns("f9phdet", "fprtd122");
  143.       while ((row = res->Next())) {
  144.          printf("%s\n", row->GetField(0));
  145.          delete row;
  146.       }
  147.       delete res;
  148.    }
  149.  
  150.    // query database and print results
  151.    char sql[1000] = "SELECT status,data,timestamp FROM fprtd122 WHERE status='A272727272727272748' AND substring(data,1,4)='A00C' ";
  152.    if(timerange[1] == -1)
  153.       sprintf(sql,"%s AND timestamp>='%d'", sql, timerange[0]);
  154.    else
  155.       sprintf(sql,"%s AND timestamp>='%d' AND timestamp<='%d'", sql, timerange[0], timerange[1]);
  156.    if(DBGSIG)
  157.       printf("%s\n",sql);
  158.    
  159.    res = db->Query(sql);
  160.  
  161.    int nrows = res->GetRowCount();
  162.    printf("\nGot %d rows in result\n", nrows);
  163.    
  164.    // Printing and plotting
  165.    char timeval[256];
  166.    TGraph *gr;
  167.    double *x, *y;
  168.    double firsttime, lasttime;
  169.  
  170.    gr = new TGraph(nrows);
  171.    gr->SetLineColor(kRed);
  172.    gr->SetLineWidth(1);
  173.    gr->SetMarkerColor(kBlack);
  174.    gr->SetMarkerSize(0.8);
  175.    gr->SetMarkerStyle(20);
  176.    gr->SetTitle("Temperature sensor;Time;Temperature (deg.)");
  177.  
  178.    FILE *fp;
  179.    fp = fopen("./fieldpoint/dataout_fieldpoint.txt", "w");
  180.  
  181.    if(DBGSIG)
  182.       printf("Time\tTemperature\n");
  183.    for (int i = 0; i < nrows; i++) {
  184.       row = res->Next();
  185.  
  186.       GetTime((int)atof(row->GetField(2))-TIMEOFF, timeval);
  187.       x = new double;
  188.       y = new double;
  189.  
  190.       *x = atof(row->GetField(2))-TIMEOFF;
  191.       *y = GetTemperature(selch,row->GetField(1));
  192.       gr->SetPoint(i,*x,*y);
  193.  
  194.       if(i == 0) firsttime = *x;
  195.       else if(i == nrows-1) lasttime = *x;
  196.  
  197.       if(datSettings->GetSelected() == 0)
  198.       {
  199.          fprintf(fp, "%s\t%d\t%f\n",timeval,(int)*x,*y);
  200.          if(DBGSIG)
  201.             printf("%s\t%d\t%f\n",timeval,(int)*x,*y);
  202.       }
  203.       else if(datSettings->GetSelected() == 1)
  204.       {
  205.          fprintf(fp, "%s\t%f\n",timeval,*y);
  206.          if(DBGSIG)
  207.             printf("%s\t%f\n",timeval,*y);
  208.       }
  209.       else if(datSettings->GetSelected() == 2)
  210.       {
  211.          fprintf(fp, "%d\t%f\n",(int)*x,*y);
  212.          if(DBGSIG)
  213.             printf("%d\t%f\n",(int)*x,*y);
  214.       }
  215.      
  216.       delete x;
  217.       delete y;
  218.  
  219.       delete row;
  220.    }
  221.  
  222.    fclose(fp);
  223.  
  224.    delete res;
  225.    delete db;
  226.  
  227.    TCanvas *gCanvas = displayCanvas->GetCanvas();
  228.    gCanvas->SetGrid();
  229.    gr->GetXaxis()->SetTimeDisplay(1);
  230.    gr->GetXaxis()->SetTimeFormat("%H:%M, %d.%m.");
  231.    gr->GetXaxis()->SetTimeOffset(0);
  232.    gr->GetXaxis()->SetLabelSize(0.027);
  233.    gr->GetXaxis()->SetLabelOffset(0.015);
  234.    gr->GetXaxis()->SetTitleSize(0.038);
  235.    gr->GetXaxis()->SetTitleOffset(1.2);
  236.    gr->GetYaxis()->SetLabelSize(0.027);
  237.    gr->GetYaxis()->SetTitleSize(0.038);
  238.    gr->GetXaxis()->SetNdivisions(-507);
  239.    gr->GetXaxis()->SetRange(firsttime,lasttime);
  240.    gr->GetXaxis()->SetRangeUser(firsttime,lasttime);
  241.    gr->Draw("APL");
  242.  
  243.    gCanvas->Modified();
  244.    gCanvas->Update();
  245. }
  246.  
  247. // Update the temperature plot
  248. void TGAppMainFrame::UpdateTempPlot()
  249. {
  250.    int stime[6];
  251.    int etime[6];
  252.  
  253.    int timestamp[2];
  254.  
  255.    time_t rtime;
  256.    int curyear;
  257.    time(&rtime);
  258.    curyear = (int)(localtime(&rtime))->tm_year+1900;
  259.  
  260.    int leapy = 0;
  261.  
  262.    // Getting the start time
  263.    stime[0] = (int)(tempDay[0]->GetSelected())+1;
  264.    stime[2] = curyear - (int)(tempYear[0]->GetSelected());
  265.    if(DBGSIG)
  266.       printf("%d, %d, %d\n", stime[2], curyear, (int)(tempYear[0]->GetSelected()));
  267.    stime[3] = (int)(tempHour[0]->GetSelected());
  268.    stime[4] = (int)(tempMinute[0]->GetSelected());
  269.    stime[5] = (int)(tempSecond[0]->GetSelected());
  270.  
  271.    switch( tempMonth[0]->GetSelected() )
  272.    {
  273.       case 0:
  274.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  275.          break;
  276.       case 1:
  277.          if( stime[2]%4 == 0)
  278.             leapy = 1;
  279.  
  280.          if( (leapy == 1) && (stime[0] > 29) )
  281.          {
  282.             stime[0] = 29;
  283.             tempDay[0]->Select(28);
  284.          }
  285.          else if( (leapy == 0) && (stime[0] > 28) )
  286.          {
  287.             stime[0] = 28;
  288.             tempDay[0]->Select(27);
  289.          }
  290.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  291.          break;
  292.       case 2:
  293.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  294.          break;
  295.       case 3:
  296.          if(stime[0] > 30)
  297.          {
  298.             stime[0] = 30;
  299.             tempDay[0]->Select(29);
  300.          }
  301.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  302.          break;
  303.       case 4:
  304.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  305.          break;
  306.       case 5:
  307.          if(stime[0] > 30)
  308.          {
  309.             stime[0] = 30;
  310.             tempDay[0]->Select(29);
  311.          }
  312.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  313.          break;
  314.       case 6:
  315.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  316.          break;
  317.       case 7:
  318.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  319.          break;
  320.       case 8:
  321.          if(stime[0] > 30)
  322.          {
  323.             stime[0] = 30;
  324.             tempDay[0]->Select(29);
  325.          }
  326.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  327.          break;
  328.       case 9:
  329.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  330.          break;
  331.       case 10:
  332.          if(stime[0] > 30)
  333.          {
  334.             stime[0] = 30;
  335.             tempDay[0]->Select(29);
  336.          }
  337.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  338.          break;
  339.       case 11:
  340.          stime[1] = (int)(tempMonth[0]->GetSelected())+1;
  341.          break;
  342.       default:
  343.          break;
  344.    }
  345.  
  346.    timestamp[0] = GetTimeStamp(stime);
  347.    if(DBGSIG)
  348.       printf("Start time: %d\n", timestamp[0]);
  349.  
  350.    // Getting the end time
  351.    etime[0] = (int)(tempDay[1]->GetSelected())+1;
  352.    etime[2] = curyear - (int)(tempYear[1]->GetSelected());
  353.    etime[3] = (int)(tempHour[1]->GetSelected());
  354.    etime[4] = (int)(tempMinute[1]->GetSelected());
  355.    etime[5] = (int)(tempSecond[1]->GetSelected());
  356.  
  357.    switch( tempMonth[1]->GetSelected() )
  358.    {
  359.       case 0:
  360.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  361.          break;
  362.       case 1:
  363.          if( etime[2]%4 == 0)
  364.             leapy = 1;
  365.  
  366.          if( (leapy == 1) && (etime[0] > 29) )
  367.          {
  368.             etime[0] = 29;
  369.             tempDay[1]->Select(28);
  370.          }
  371.          else if( (leapy == 0) && (etime[0] > 28) )
  372.          {
  373.             etime[0] = 28;
  374.             tempDay[1]->Select(27);
  375.          }
  376.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  377.          break;
  378.       case 2:
  379.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  380.          break;
  381.       case 3:
  382.          if(etime[0] > 30)
  383.          {
  384.             etime[0] = 30;
  385.             tempDay[1]->Select(29);
  386.          }
  387.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  388.          break;
  389.       case 4:
  390.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  391.          break;
  392.       case 5:
  393.          if(etime[0] > 30)
  394.          {
  395.             etime[0] = 30;
  396.             tempDay[1]->Select(29);
  397.          }
  398.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  399.          break;
  400.       case 6:
  401.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  402.          break;
  403.       case 7:
  404.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  405.          break;
  406.       case 8:
  407.          if(etime[0] > 30)
  408.          {
  409.             etime[0] = 30;
  410.             tempDay[1]->Select(29);
  411.          }
  412.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  413.          break;
  414.       case 9:
  415.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  416.          break;
  417.       case 10:
  418.          if(etime[0] > 30)
  419.          {
  420.             etime[0] = 30;
  421.             tempDay[1]->Select(29);
  422.          }
  423.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  424.          break;
  425.       case 11:
  426.          etime[1] = (int)(tempMonth[1]->GetSelected())+1;
  427.          break;
  428.       default:
  429.          break;
  430.    }
  431.  
  432.    if( tempEndOn->IsDown() )
  433.       timestamp[1] = -1;
  434.    else
  435.       timestamp[1] = GetTimeStamp(etime);
  436.    if(DBGSIG)
  437.       printf("End time: %d\n", timestamp[1]);
  438.  
  439.    fieldpoint(timestamp, tempCh->GetSelected());
  440. }
  441.  
  442. // Export the temperature plot to pdf
  443. void TGAppMainFrame::ExportTempPlot()
  444. {
  445.    TCanvas *gCanvas = displayCanvas->GetCanvas();
  446.    gCanvas->Modified();
  447.    gCanvas->Update();
  448.    gCanvas->SaveAs("./fieldpoint/plotout_fieldpoint.pdf");
  449. }
  450.  
  451. // Toggle the endtime settings for temperature sensor
  452. void TGAppMainFrame::TempEndToggle()
  453. {
  454.    if( tempEndOn->IsDown() )
  455.    {
  456.       tempDay[1]->SetEnabled(kFALSE);
  457.       tempMonth[1]->SetEnabled(kFALSE);
  458.       tempYear[1]->SetEnabled(kFALSE);
  459.       tempHour[1]->SetEnabled(kFALSE);
  460.       tempMinute[1]->SetEnabled(kFALSE);
  461.       tempSecond[1]->SetEnabled(kFALSE);
  462.    }
  463.    else
  464.    {
  465.       tempDay[1]->SetEnabled(kTRUE);
  466.       tempMonth[1]->SetEnabled(kTRUE);
  467.       tempYear[1]->SetEnabled(kTRUE);
  468.       tempHour[1]->SetEnabled(kTRUE);
  469.       tempMinute[1]->SetEnabled(kTRUE);
  470.       tempSecond[1]->SetEnabled(kTRUE);
  471.    }
  472. }
  473.  
  474. // --------------------------------------------------------------
  475.  
  476. // Setting the application layout ------------------------------------
  477.  
  478. void TGAppMainFrame::AppLayout()
  479. {
  480. // Fieldpoint window ------------------------
  481.  
  482.    TGLayoutHints *f0 = new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2);
  483.    TGLayoutHints *f0centerx = new TGLayoutHints(kLHintsCenterX,2,2,2,2);
  484.    TGLayoutHints *f0centery = new TGLayoutHints(kLHintsLeft | kLHintsCenterY,2,2,2,2);
  485.    TGLayoutHints *f1 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2);
  486.    TGLayoutHints *f2 = new TGLayoutHints(kLHintsExpandX,2,2,2,2);
  487.  
  488.    TGHorizontalFrame *fH1, *fH2;
  489.    TGGroupFrame *fG1;
  490.    TGLabel *lab;
  491.  
  492.    time_t rtime;
  493.    int yearrange[2];
  494.    int subwin[2];
  495.    char ctemp[256];
  496.  
  497.    subwin[0] = winWidth-10;
  498.    subwin[1] = 6.6*winHeight/12;
  499.  
  500.    // Display canvas for temperature sensor
  501.    displayCanvas = new TRootEmbeddedCanvas("displayCanvas",fMain,subwin[0],subwin[1]);
  502.    fMain->AddFrame(displayCanvas, f0centerx);
  503.    TCanvas *gCanvas = displayCanvas->GetCanvas();
  504.    gCanvas->SetGridx();
  505.    gCanvas->SetGridy();
  506.  
  507.    fG1 = new TGGroupFrame(fMain, "Temperature sensor settings");
  508.    // Channel selector
  509.    fH1 = new TGHorizontalFrame(fG1, subwin[0], 30);
  510.    lab = new TGLabel(fH1, "Fieldpoint channel:");
  511.    fH1->AddFrame(lab, f0centery);
  512.    tempCh = new TGComboBox(fH1, 200);
  513.    tempCh->AddEntry("0", 0);
  514.    tempCh->AddEntry("1", 1);
  515.    tempCh->AddEntry("2", 2);
  516.    tempCh->AddEntry("3", 3);
  517.    tempCh->AddEntry("4", 4);
  518.    tempCh->AddEntry("5", 5);
  519.    tempCh->AddEntry("6", 6);
  520.    tempCh->AddEntry("7", 7);
  521.    tempCh->Resize(50,22);
  522.    tempCh->Select(1);
  523.    fH1->AddFrame(tempCh, f0centery);
  524.    fG1->AddFrame(fH1, f2);
  525.  
  526.    // Start and stop time ------------------------
  527.    time(&rtime);
  528.  
  529.    lab = new TGLabel(fG1, "Start time:");
  530.    fG1->AddFrame(lab, f0);
  531.    fH1 = new TGHorizontalFrame(fG1, subwin[0], 30);
  532.    // Start day
  533.    lab = new TGLabel(fH1, "\tDay: ");
  534.    fH1->AddFrame(lab, f0centery);
  535.    tempDay[0] = new TGComboBox(fH1, 200);
  536.    for(int i = 0; i < 31; i++)
  537.    {
  538.       sprintf(ctemp, "%d", i+1);
  539.       tempDay[0]->AddEntry(ctemp, i);
  540.    }
  541.    tempDay[0]->Resize(50,22);
  542.    tempDay[0]->Select((int)(localtime(&rtime))->tm_mday-1);
  543.    fH1->AddFrame(tempDay[0], f0centery);
  544.  
  545.    // Start month
  546.    lab = new TGLabel(fH1, " Month: ");
  547.    fH1->AddFrame(lab, f0centery);
  548.    tempMonth[0] = new TGComboBox(fH1, 200);
  549.    tempMonth[0]->AddEntry("January", 0);
  550.    tempMonth[0]->AddEntry("February", 1);
  551.    tempMonth[0]->AddEntry("March", 2);
  552.    tempMonth[0]->AddEntry("April", 3);
  553.    tempMonth[0]->AddEntry("May", 4);
  554.    tempMonth[0]->AddEntry("June", 5);
  555.    tempMonth[0]->AddEntry("July", 6);
  556.    tempMonth[0]->AddEntry("August", 7);
  557.    tempMonth[0]->AddEntry("September", 8);
  558.    tempMonth[0]->AddEntry("October", 9);
  559.    tempMonth[0]->AddEntry("November", 10);
  560.    tempMonth[0]->AddEntry("December", 11);
  561.    tempMonth[0]->Resize(80,22);
  562.    tempMonth[0]->Select((int)(localtime(&rtime))->tm_mon);
  563.    fH1->AddFrame(tempMonth[0], f0centery);
  564.  
  565.    // Start year
  566.    yearrange[0] = 2010;
  567.    yearrange[1] = (int)(localtime(&rtime))->tm_year+1900;
  568.  
  569.    lab = new TGLabel(fH1, " Year: ");
  570.    fH1->AddFrame(lab, f0centery);
  571.    tempYear[0] = new TGComboBox(fH1, 200);
  572.    for(int i = 0; i < (yearrange[1]-yearrange[0])+1; i++)
  573.    {
  574.       sprintf(ctemp, "%d", yearrange[1]-i);
  575.       tempYear[0]->AddEntry(ctemp, i);
  576.    }
  577.    tempYear[0]->Resize(60,22);
  578.    tempYear[0]->Select(0);
  579.    fH1->AddFrame(tempYear[0], f0centery);
  580.  
  581.    // Start hour
  582.    lab = new TGLabel(fH1, " Hour: ");
  583.    fH1->AddFrame(lab, f0centery);
  584.    tempHour[0] = new TGComboBox(fH1, 200);
  585.    for(int i = 0; i < 24; i++)
  586.    {
  587.       if(i < 10)
  588.          sprintf(ctemp, "0%d", i);
  589.       else
  590.          sprintf(ctemp, "%d", i);
  591.       tempHour[0]->AddEntry(ctemp, i);
  592.    }
  593.    tempHour[0]->Resize(50,22);
  594.    tempHour[0]->Select(7);
  595.    fH1->AddFrame(tempHour[0], f0centery);
  596.  
  597.    // Start minute
  598.    lab = new TGLabel(fH1, " Minute: ");
  599.    fH1->AddFrame(lab, f0centery);
  600.    tempMinute[0] = new TGComboBox(fH1, 200);
  601.    for(int i = 0; i < 60; i++)
  602.    {
  603.       if(i < 10)
  604.          sprintf(ctemp, "0%d", i);
  605.       else
  606.          sprintf(ctemp, "%d", i);
  607.       tempMinute[0]->AddEntry(ctemp, i);
  608.    }
  609.    tempMinute[0]->Resize(50,22);
  610.    tempMinute[0]->Select(0);
  611.    fH1->AddFrame(tempMinute[0], f0centery);
  612.  
  613.    // Start second
  614.    lab = new TGLabel(fH1, " Second: ");
  615.    fH1->AddFrame(lab, f0centery);
  616.    tempSecond[0] = new TGComboBox(fH1, 200);
  617.    for(int i = 0; i < 60; i++)
  618.    {
  619.       if(i < 10)
  620.          sprintf(ctemp, "0%d", i);
  621.       else
  622.          sprintf(ctemp, "%d", i);
  623.       tempSecond[0]->AddEntry(ctemp, i);
  624.    }
  625.    tempSecond[0]->Resize(50,22);
  626.    tempSecond[0]->Select(0);
  627.    fH1->AddFrame(tempSecond[0], f0centery);
  628.  
  629.    fG1->AddFrame(fH1, f2);
  630.  
  631.    // Use the end time or not
  632.    tempEndOn = new TGCheckButton(fG1, "Draw to last time point (ON/OFF)");
  633.    tempEndOn->Resize(100,22);
  634.    tempEndOn->SetState(kButtonUp);
  635.    fG1->AddFrame(tempEndOn, f0);
  636.  
  637.    lab = new TGLabel(fG1, "End time:");
  638.    fG1->AddFrame(lab, f0);
  639.    fH1 = new TGHorizontalFrame(fG1, subwin[0], 30);
  640.    // End day
  641.    lab = new TGLabel(fH1, "\tDay: ");
  642.    fH1->AddFrame(lab, f0centery);
  643.    tempDay[1] = new TGComboBox(fH1, 200);
  644.    for(int i = 0; i < 31; i++)
  645.    {
  646.       sprintf(ctemp, "%d", i+1);
  647.       tempDay[1]->AddEntry(ctemp, i);
  648.    }
  649.    tempDay[1]->Resize(50,22);
  650.    tempDay[1]->Select((int)(localtime(&rtime))->tm_mday-1);
  651.    fH1->AddFrame(tempDay[1], f0centery);
  652.  
  653.    // End month
  654.    lab = new TGLabel(fH1, " Month: ");
  655.    fH1->AddFrame(lab, f0centery);
  656.    tempMonth[1] = new TGComboBox(fH1, 200);
  657.    tempMonth[1]->AddEntry("January", 0);
  658.    tempMonth[1]->AddEntry("February", 1);
  659.    tempMonth[1]->AddEntry("March", 2);
  660.    tempMonth[1]->AddEntry("April", 3);
  661.    tempMonth[1]->AddEntry("May", 4);
  662.    tempMonth[1]->AddEntry("June", 5);
  663.    tempMonth[1]->AddEntry("July", 6);
  664.    tempMonth[1]->AddEntry("August", 7);
  665.    tempMonth[1]->AddEntry("September", 8);
  666.    tempMonth[1]->AddEntry("October", 9);
  667.    tempMonth[1]->AddEntry("November", 10);
  668.    tempMonth[1]->AddEntry("December", 11);
  669.    tempMonth[1]->Resize(80,22);
  670.    tempMonth[1]->Select((int)(localtime(&rtime))->tm_mon);
  671.    fH1->AddFrame(tempMonth[1], f0centery);
  672.  
  673.    // End year
  674.    time(&rtime);
  675.    yearrange[0] = 2010;
  676.    yearrange[1] = (int)(localtime(&rtime))->tm_year+1900;
  677.  
  678.    lab = new TGLabel(fH1, " Year: ");
  679.    fH1->AddFrame(lab, f0centery);
  680.    tempYear[1] = new TGComboBox(fH1, 200);
  681.    for(int i = 0; i < (yearrange[1]-yearrange[0])+1; i++)
  682.    {
  683.       sprintf(ctemp, "%d", yearrange[1]-i);
  684.       tempYear[1]->AddEntry(ctemp, i);
  685.    }
  686.    tempYear[1]->Resize(60,22);
  687.    tempYear[1]->Select(0);
  688.    fH1->AddFrame(tempYear[1], f0centery);
  689.  
  690.    // End hour
  691.    lab = new TGLabel(fH1, " Hour: ");
  692.    fH1->AddFrame(lab, f0centery);
  693.    tempHour[1] = new TGComboBox(fH1, 200);
  694.    for(int i = 0; i < 24; i++)
  695.    {
  696.       if(i < 10)
  697.          sprintf(ctemp, "0%d", i);
  698.       else
  699.          sprintf(ctemp, "%d", i);
  700.       tempHour[1]->AddEntry(ctemp, i);
  701.    }
  702.    tempHour[1]->Resize(50,22);
  703.    tempHour[1]->Select(18);
  704.    fH1->AddFrame(tempHour[1], f0centery);
  705.  
  706.    // End minute
  707.    lab = new TGLabel(fH1, " Minute: ");
  708.    fH1->AddFrame(lab, f0centery);
  709.    tempMinute[1] = new TGComboBox(fH1, 200);
  710.    for(int i = 0; i < 60; i++)
  711.    {
  712.       if(i < 10)
  713.          sprintf(ctemp, "0%d", i);
  714.       else
  715.          sprintf(ctemp, "%d", i);
  716.       tempMinute[1]->AddEntry(ctemp, i);
  717.    }
  718.    tempMinute[1]->Resize(50,22);
  719.    tempMinute[1]->Select(0);
  720.    fH1->AddFrame(tempMinute[1], f0centery);
  721.  
  722.    // End second
  723.    lab = new TGLabel(fH1, " Second: ");
  724.    fH1->AddFrame(lab, f0centery);
  725.    tempSecond[1] = new TGComboBox(fH1, 200);
  726.    for(int i = 0; i < 60; i++)
  727.    {
  728.       if(i < 10)
  729.          sprintf(ctemp, "0%d", i);
  730.       else
  731.          sprintf(ctemp, "%d", i);
  732.       tempSecond[1]->AddEntry(ctemp, i);
  733.    }
  734.    tempSecond[1]->Resize(50,22);
  735.    tempSecond[1]->Select(0);
  736.    fH1->AddFrame(tempSecond[1], f0centery);
  737.  
  738.    fG1->AddFrame(fH1, f2);
  739.    // Start and stop time ------------------------
  740.  
  741.    // Dataout settings
  742.    fH1 = new TGHorizontalFrame(fG1, subwin[0], 30);
  743.    lab = new TGLabel(fH1, "Output data settings: ");
  744.    fH1->AddFrame(lab, f0centery);
  745.    datSettings = new TGComboBox(fH1, 200);
  746.    datSettings->AddEntry("Export local time and UNIX timestamp", 0);
  747.    datSettings->AddEntry("Export only local time", 1);
  748.    datSettings->AddEntry("Export only UNIX timestamp", 2);
  749.    datSettings->Resize(300,22);
  750.    datSettings->Select(0);
  751.    fH1->AddFrame(datSettings, f0centery);
  752.  
  753.    fG1->AddFrame(fH1, f2);
  754.    
  755.    // Control buttons
  756.    fH2 = new TGHorizontalFrame(fG1, subwin[0], 30);
  757.    fH1 = new TGHorizontalFrame(fH2, subwin[0], 30);
  758.    updateTemp = new TGTextButton(fH1, "Update");
  759.    updateTemp->SetTextJustify(36);
  760.    updateTemp->SetWrapLength(-1);
  761.    updateTemp->Resize(80,22);
  762.    fH1->AddFrame(updateTemp, f0);
  763.  
  764.    exportTemp = new TGTextButton(fH1, "Export");
  765.    exportTemp->SetTextJustify(36);
  766.    exportTemp->SetWrapLength(-1);
  767.    exportTemp->Resize(80,22);
  768.    fH1->AddFrame(exportTemp, f0);
  769.  
  770.    closeTemp = new TGTextButton(fH1, "Close");
  771.    closeTemp->SetTextJustify(36);
  772.    closeTemp->SetWrapLength(-1);
  773.    closeTemp->Resize(80,22);
  774.    fH1->AddFrame(closeTemp, f0);
  775.    fH2->AddFrame(fH1, f0centerx);
  776.  
  777.    fG1->AddFrame(fH2, f2);
  778.    
  779.    fMain->AddFrame(fG1, f1);
  780.  
  781.    // Action connections
  782.    updateTemp->Connect("Clicked()", "TGAppMainFrame", this, "UpdateTempPlot()");
  783.    tempEndOn->Connect("Clicked()", "TGAppMainFrame", this, "TempEndToggle()");
  784.    exportTemp->Connect("Clicked()", "TGAppMainFrame", this, "ExportTempPlot()");
  785.    closeTemp->Connect("Clicked()", "TGAppMainFrame", this, "CloseWindow()");
  786.  
  787. // Fieldpoint window ------------------------
  788.  
  789. }
  790.  
  791. // -------------------------------------------------------------------
  792.  
  793. // Main function -----------------------------------------------------
  794.  
  795. void root_app()
  796. {
  797.    new TGAppMainFrame(gClient->GetRoot(), winWidth, winHeight);
  798. }
  799.  
  800. int main(int argc, char **argv)
  801. {
  802.    TApplication theApp("TGAppMainFrame", &argc, argv);
  803.    root_app();
  804.    theApp.Run();
  805.  
  806.    return 0;
  807. }
  808.  
  809. // -------------------------------------------------------------------
  810.