csv2cdb
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdexcept>
#include <cstdio>
#include <ctime>
#include "cdbxx/db.hh"
#include "cdbxx/map.hh"
#include "mt4.hh"
using namespace std;
string _Symbol_;
int _Period_;
string _db_;
string _history_;
string _hstfiles_;
string _csvfiles_;
string _marketinfo_;
string Sym[NR_OF_SYMBOLS];
int Per[NR_OF_PERIODS];
int main()
{
typedef std::vector < std::string > VS;
std::string line;
VS tokens;
init_mt4();
for(int i=0;i<20;i++)
{
string csv_name1=csv_filename(Sym[i], Per[0]);//"/home/barnix/mt4db/db/EURUSD1.csv";
string db_name1=symbol_filename(Sym[i], Per[0]);//"/home/barnix/mt4db/cdb/eurusd1.cdb";
ifstream csvfile(csv_name1.c_str());
if (!csvfile)
{
cerr << "No "<<csv_name1 << std::endl;
return -1;
}
cdbxx::out_db new_database(db_name1.c_str());
vector<int> key(1);
vector<float> value(5);
getline (csvfile,line);//header
cout << Sym[i] << " ... " << endl;
while (!csvfile.eof())
{
getline (csvfile,line);
if(!line.empty())
{
tokens.clear();
Tokenize(line, tokens, ",");
//cout << line << " ... ";
//cout << tokens[0] << " "<< tokens[1]<< " " << tokens[2] << " ... " << endl;
//1105315200,1.3047,1.3047,1.3075,1.307,453
key[0] = atoi(tokens[0].c_str());
value[0] = atof(tokens[1].c_str());
value[1] = atof(tokens[2].c_str());
value[2] = atof(tokens[3].c_str());
value[3] = atof(tokens[4].c_str());
value[4] = atof(tokens[5].c_str());
new_database.insert(key, value);
}
}
csvfile.close();
}
return 0;
}