Rev 40 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 39 | mjames | 1 | #include <iostream> |
| 2 | #include <stdio.h> |
||
| 3 | #include <map> |
||
| 4 | #include <vector> |
||
| 5 | |||
| 6 | #include "../plx_lib/plx.h" |
||
| 7 | |||
| 8 | |||
| 9 | |||
| 10 | |||
| 11 | |||
| 12 | |||
| 13 | /* run this program using the console pauser or add your own getch, system("pause") or input loop */ |
||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | int main(int argc, char** argv) { |
||
| 18 | |||
| 19 | int nextcol = 1; |
||
| 20 | int row = 0; |
||
| 21 | std::map<int,int> mapping; |
||
| 22 | std::vector<std::vector<double> *> store; |
||
| 42 | mjames | 23 | std::vector<std::string> headings; |
| 24 | size_t constexpr size_step = 10000; |
||
| 39 | mjames | 25 | |
| 26 | FILE * f; |
||
| 27 | if(argc > 1) { |
||
| 28 | |||
| 29 | f=fopen(argv[1],"r"); |
||
| 30 | if(f){ |
||
| 31 | while (!feof(f)) |
||
| 32 | { |
||
| 33 | int key; |
||
| 34 | int index; |
||
| 35 | int value; |
||
| 36 | |||
| 37 | |||
| 38 | int c = fscanf(f,"%d,%d,%d\n",&key,&index,&value); |
||
| 42 | mjames | 39 | if(c) |
| 40 | { |
||
| 39 | mjames | 41 | int search = key * 10 + index; |
| 42 | |||
| 43 | int & col = mapping[search]; |
||
| 44 | |||
| 45 | if(col == 0) |
||
| 46 | { |
||
| 47 | col = nextcol++; |
||
| 48 | mapping[search] = col; |
||
| 49 | } |
||
| 50 | |||
| 51 | if (col > store.size()) |
||
| 52 | { |
||
| 42 | mjames | 53 | if(key <= PLX_X_CHT ) |
| 54 | { |
||
| 55 | |||
| 56 | std::string st = PLX_Obs_Names[key]; |
||
| 57 | char c_code = '1'+ index; |
||
| 58 | st += c_code; |
||
| 59 | headings.push_back( st ); // save column heading |
||
| 60 | std::vector<double> * new_vec = new std::vector<double>; |
||
| 61 | // new_vec->reserve(size_step); // reserve a big chunk of store |
||
| 62 | store.push_back(new_vec); // save value |
||
| 63 | } |
||
| 39 | mjames | 64 | } |
| 42 | mjames | 65 | |
| 39 | mjames | 66 | std::vector<double> * vec = store[col-1]; |
| 42 | mjames | 67 | if(vec) |
| 68 | { |
||
| 39 | mjames | 69 | |
| 42 | mjames | 70 | if(vec->capacity() <= row ) |
| 71 | { |
||
| 72 | vec->reserve(vec->capacity() + size_step); |
||
| 73 | } |
||
| 74 | |||
| 39 | mjames | 75 | // decode scaling |
| 76 | double res = 0; |
||
| 77 | switch (key) |
||
| 78 | { |
||
| 42 | mjames | 79 | case PLX_Volts: |
| 80 | vec->push_back(ConveriMFDRaw2Data(key ,0, value)) ; |
||
| 81 | break; |
||
| 39 | mjames | 82 | case PLX_AFR: |
| 83 | vec->push_back(ConveriMFDRaw2Data(key , AFR_Gasoline, value)) ; |
||
| 84 | break; |
||
| 85 | case PLX_RPM: |
||
| 86 | vec->push_back( ConveriMFDRaw2Data(key ,0, value)) ; |
||
| 87 | break; |
||
| 42 | mjames | 88 | case PLX_MAP: |
| 89 | vec->push_back(ConveriMFDRaw2Data(key ,PRESSURE_kPa, value)) ; |
||
| 90 | break; |
||
| 39 | mjames | 91 | case PLX_X_CHT: |
| 92 | vec->push_back(ConveriMFDRaw2Data(key ,TEMP_Celsius, value)); |
||
| 42 | mjames | 93 | break; |
| 40 | mjames | 94 | case PLX_FluidPressure: |
| 95 | vec->push_back(ConveriMFDRaw2Data(key ,PRESSURE_PSI_Oil, value)); |
||
| 96 | break; |
||
| 39 | mjames | 97 | default: |
| 98 | break; |
||
| 99 | } |
||
| 100 | |||
| 101 | if(col == 1) |
||
| 102 | { |
||
| 103 | row++; |
||
| 104 | } |
||
| 42 | mjames | 105 | |
| 106 | } |
||
| 39 | mjames | 107 | // printf("%3d %3d %10d\n", key,index,value); |
| 108 | |||
| 42 | mjames | 109 | }} |
| 110 | |||
| 39 | mjames | 111 | } |
| 112 | |||
| 113 | } |
||
| 114 | |||
| 115 | // having gathered all the data print it |
||
| 116 | |||
| 117 | for(auto it = headings.begin(); it != headings.end() ;it++) |
||
| 118 | { |
||
| 42 | mjames | 119 | printf("%s,",(*it).c_str()); |
| 39 | mjames | 120 | } |
| 121 | printf("\n"); |
||
| 122 | |||
| 123 | for(size_t print = 0; print < row ; print++) |
||
| 124 | { |
||
| 125 | |||
| 126 | |||
| 127 | for(auto it = store.begin(); it != store.end() ;it++) |
||
| 128 | |||
| 129 | |||
| 130 | { |
||
| 131 | |||
| 132 | double val = 0.0; |
||
| 133 | if(*it != nullptr) |
||
| 134 | { |
||
| 42 | mjames | 135 | std::vector<double> * vec = *it; |
| 136 | if(vec && (print < vec->size())) |
||
| 137 | val = vec->at(print); |
||
| 39 | mjames | 138 | } |
| 139 | printf("%0.2f," ,val); |
||
| 140 | } |
||
| 141 | |||
| 142 | printf("\n"); |
||
| 143 | |||
| 144 | } |
||
| 145 | |||
| 146 | |||
| 147 | return 0; |
||
| 148 | } |
||
| 149 |