SHARE
TWEET

Untitled

a guest Mar 26th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pch.h"
  2. #include "Sample.h"
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include <Windows.h>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  11.  
  12. Sample *latitude, *longitude, *altitude;
  13.  
  14. int main()
  15. {
  16.  
  17.     FILE *fp;
  18.     const int size = 1000;
  19.     const int hist_columns = 250;
  20.  
  21.     double utc_time[size], latitude_l[size], longitude_l[size], hor_dilution[size], altitude_l[size], geoidal_separation[size];
  22.     char latitude_hemisphere[size], longitude_hemisphere[size];
  23.     int quality_indicator[size], num_of_satellites[size];
  24.  
  25.     char buff[100];
  26.  
  27.     fp = fopen("C:\\Users\\Administrator\\source\\repos\\NMEATesting\\Debug\\log.tps", "r");
  28.  
  29.     for (int i = 0; i < size; i++) {
  30.         fscanf(fp, "$GPGGA,%lf,%lf,%c,%lf,%c,%d,%d,%lf,%lf,M,%lf,M,%s\n",
  31.             utc_time + i, latitude_l + i, latitude_hemisphere + i,
  32.             longitude_l + i, longitude_hemisphere + i, quality_indicator + i,
  33.             num_of_satellites + i, hor_dilution + i, altitude_l + i,
  34.             geoidal_separation + i, buff);
  35.     }
  36.  
  37.     fclose(fp);
  38.  
  39.     latitude = new Sample(latitude_l, size);
  40.     longitude = new Sample(longitude_l, size);
  41.     altitude = new Sample(altitude_l, size);
  42.  
  43.     printf("Parameter\tMean\t\tMin\t\tMax\t\tDeviation\n");
  44.     printf("Latitude\t%f\t%f\t%f\t%f\n",
  45.         latitude->get_mean(), latitude->get_minimum(), latitude->get_maximum(), latitude->get_deviation());
  46.     printf("Longitude\t%f\t%f\t%f\t%f\n",
  47.         longitude->get_mean(), longitude->get_minimum(), longitude->get_maximum(), longitude->get_deviation());
  48.     printf("Altitude\t%f\t%f\t%f\t%f\n",
  49.         altitude->get_mean(), altitude->get_minimum(), altitude->get_maximum(), altitude->get_deviation());
  50.  
  51.     printf("\nParameter\tQ-0.9\t\tQ-0.95\t\tQ-0.99\t\tQ-0.999\n");
  52.     printf("Latitude\t%f\t%f\t%f\t%f\n",
  53.         latitude->get_quantile(0.9, hist_columns), latitude->get_quantile(0.95, hist_columns), latitude->get_quantile(0.99, hist_columns), latitude->get_quantile(0.999, hist_columns));
  54.     printf("Longitude\t%f\t%f\t%f\t%f\n",
  55.         longitude->get_quantile(0.9, hist_columns), longitude->get_quantile(0.95, hist_columns), longitude->get_quantile(0.99, hist_columns), longitude->get_quantile(0.999, hist_columns));
  56.     printf("Altitude\t%f\t%f\t%f\t%f\n",
  57.         altitude->get_quantile(0.9, hist_columns), altitude->get_quantile(0.95, hist_columns), altitude->get_quantile(0.99, hist_columns), altitude->get_quantile(0.999, hist_columns));
  58.  
  59.     MSG msg;
  60.     int use = CW_USEDEFAULT;
  61.     HWND  wnd = CreateWindowA("BUTTON", "Graphic", WS_OVERLAPPEDWINDOW, use, use, use, use, GetDesktopWindow(), NULL, (HINSTANCE)GetModuleHandle(NULL), NULL);
  62.     if (!wnd)
  63.         ExitProcess(1u);
  64.     SetClassLong(wnd, GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_ARROW));
  65.     SetClassLong(wnd, GCL_HBRBACKGROUND, (LONG)GetStockObject(BLACK_BRUSH));
  66.     SetWindowLong(wnd, GWL_WNDPROC, (LONG)WndProc);
  67.  
  68.     ShowWindow(wnd, SW_SHOWDEFAULT);
  69.     UpdateWindow(wnd);
  70.     InvalidateRect(wnd, NULL, TRUE);
  71.     ZeroMemory(&msg, sizeof(MSG));
  72.     while (GetMessageA(&msg, NULL, 0U, 0U)) {
  73.         DispatchMessageA(&msg);
  74.         TranslateMessage(&msg);
  75.     }
  76.     DestroyWindow(wnd);
  77.  
  78.     return 0;
  79.  
  80. }
  81.  
  82. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
  83.     PAINTSTRUCT ps;
  84.  
  85.     const wchar_t* font_name = L"Consolas";
  86.     const wchar_t* str = L"Wew";
  87.     wstring label;
  88.  
  89.     static HPEN  border_pen = CreatePen(PS_SOLID, 1, RGB(100, 100, 255));
  90.     static HPEN  fore_pen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
  91.     static HPEN  sec_pen = CreatePen(PS_SOLID, 1, RGB(255, 100, 255));
  92.     static HFONT regular_font = CreateFont(18, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, font_name);
  93.     static HFONT h_font = CreateFont(64, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, font_name);
  94.     double per_v_pix = 0, per_h_pix = 0, field_v_size = 0, field_h_size = 0, field_h_margin = 150, field_v_margin = 50, cutter = 10;
  95.     switch (msg) {
  96.     case WM_PAINT:  
  97.  
  98.         BeginPaint(hwnd, &ps);
  99.  
  100.  
  101.         SelectObject(ps.hdc, regular_font);
  102.         SetTextColor(ps.hdc, RGB(255, 255, 255));
  103.         SetBkColor(ps.hdc, RGB(0, 0, 0));
  104.  
  105.         SelectObject(ps.hdc, fore_pen);
  106.  
  107.         field_v_size = ps.rcPaint.bottom - 2 * field_v_margin;
  108.         field_h_size = ps.rcPaint.right - 2 * field_h_margin;
  109.  
  110.         per_v_pix = (altitude->get_maximum() - altitude->get_minimum()) / field_v_size;
  111.         per_h_pix = (double)altitude->get_size() / field_h_size;
  112.  
  113.         //Graphic
  114.         SelectObject(ps.hdc, fore_pen);
  115.         MoveToEx(ps.hdc, field_h_margin, field_v_margin + (int)((altitude->get_maximum() - altitude->get_list()[0]) / per_v_pix), NULL);
  116.         for (int i = 0; i < latitude->get_size(); i++) {
  117.             LineTo(ps.hdc, field_h_margin + (int)(i / per_h_pix), field_v_margin + (int)((altitude->get_maximum() - altitude->get_list()[i]) / per_v_pix));
  118.         }
  119.        
  120.         //Mean
  121.         SelectObject(ps.hdc, sec_pen);
  122.         MoveToEx(ps.hdc, field_h_margin - cutter, field_v_margin + (int)((altitude->get_maximum() - altitude->get_mean()) / per_v_pix), NULL);
  123.         LineTo(ps.hdc, field_h_margin + cutter + field_h_size, field_v_margin + (int)((altitude->get_maximum() - altitude->get_mean()) / per_v_pix));
  124.  
  125.         SetTextAlign(ps.hdc, TA_RIGHT);
  126.         label = L"Mean = " + to_wstring(altitude->get_mean()) + L" M";
  127.         TextOut(ps.hdc, field_h_margin + cutter + field_h_size, field_v_margin + (int)((altitude->get_maximum() - altitude->get_mean()) / per_v_pix) - 20, label.c_str(), label.size());
  128.  
  129.  
  130.         SelectObject(ps.hdc, border_pen);
  131.  
  132.  
  133.         //Maximum label
  134.         MoveToEx(ps.hdc, field_h_margin - cutter, field_v_margin + (int)((altitude->get_maximum() - altitude->get_maximum()) / per_v_pix), NULL);
  135.         LineTo(ps.hdc, field_h_margin + cutter, field_v_margin + (int)((altitude->get_maximum() - altitude->get_maximum()) / per_v_pix));
  136.  
  137.         label = to_wstring(altitude->get_maximum()) + L" M";
  138.         TextOut(ps.hdc, field_h_margin - cutter - 5, field_v_margin + (int)((altitude->get_maximum() - altitude->get_maximum()) / per_v_pix) - 18 / 2, label.c_str(), label.size());
  139.  
  140.         //Minimum label
  141.         label = to_wstring(altitude->get_minimum()) + L" M";
  142.         TextOut(ps.hdc, field_h_margin - cutter - 5, field_v_margin + (int)((altitude->get_maximum() - altitude->get_minimum()) / per_v_pix) - 18 / 2, label.c_str(), label.size());
  143.  
  144.         //Axes
  145.         MoveToEx(ps.hdc, field_h_margin, field_v_margin - cutter, NULL);
  146.         LineTo(ps.hdc, field_h_margin, field_v_margin + cutter + field_v_size);
  147.         MoveToEx(ps.hdc, field_h_margin - cutter, field_v_margin + field_v_size, NULL);
  148.         LineTo(ps.hdc, field_h_margin + cutter + field_h_size, field_v_margin + field_v_size);
  149.  
  150.  
  151.         EndPaint(hwnd, &ps);
  152.         break;
  153.     case WM_DESTROY:
  154.         DeleteObject(fore_pen);
  155.         PostQuitMessage(0);
  156.         break;
  157.     default: return DefWindowProcA(hwnd, msg, wParam, lParam);
  158.     }
  159.     return 0;
  160. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top