Регистрация | Вход
#include <vcl.h>#include "main.h"UCHAR *fileBuffer=NULL;static TDateTime dateTimeArr[1138809];int dataCount=0;void __fastcall TForm1::btnLoadDataClick(TObject *Sender){ UINT startTime,stopTime,timeDiff; TOpenDialog* openTestDataDialog=new TOpenDialog(this); openTestDataDialog->Title="Open test data"; openTestDataDialog->Filter="CSV file (*.csv)|*.csv"; if(openTestDataDialog->Execute()){ startTime=GetTickCount(); TFileStream *csvFile=new TFileStream(openTestDataDialog->FileName, fmOpenRead | fmShareDenyNone); UINT fileSize=(UINT)csvFile->Size; fileBuffer=new UCHAR[fileSize]; csvFile->Read(fileBuffer, fileSize); char lineBuf[100]; char ch; AnsiString line=""; int rowCount=0; int charCount=0; TDateTime dt; TFormatSettings FormatSettings; FormatSettings.DateSeparator = '.'; FormatSettings.TimeSeparator = ':'; FormatSettings.LongDateFormat = "DD.MM.YYYY"; FormatSettings.ShortDateFormat = "DD.MM.YYYY"; FormatSettings.ShortTimeFormat = "HH:MM:SS"; FormatSettings.LongTimeFormat = "HH:MM:SS"; AnsiString strDate; for(UINT i=0; i<fileSize; i++){ ch=fileBuffer[i]; lineBuf[charCount]=ch; charCount++; if(ch=='\r'){ rowCount++; charCount=0; if(rowCount==1) continue; lineBuf[20]='\0'; strDate=AnsiString(lineBuf); if (TryStrToDateTime(strDate, dt, FormatSettings)){ dateTimeArr[dataCount]=dt; dataCount++; } } } delete csvFile; delete [] fileBuffer; stopTime=GetTickCount(); } delete openTestDataDialog; timeDiff=stopTime-startTime; Memo1->Lines->Add("Данные загружены за "+IntToStr((int)timeDiff)+" мс"); Memo1->Lines->Add("First data = "+dateTimeArr[0].DateTimeString()); Memo1->Lines->Add("Last data = "+dateTimeArr[dataCount-1].DateTimeString());}
vector<vector<double>> parseCsv(string path, char token){ ifstream read(path); vector<string> lines; string line; while (getline(read, line)) lines.push_back(line); vector<vector<double>> result; for (int i = 0; i < lines.size(); ++i) { stringstream test(lines[i]); vector<double> seglist; string segment; while (getline(test, segment, token)) seglist.push_back(stod(segment)); result.push_back(seglist); } return result;}