Indexing the database

/*

  for( cdbxx::iterator it1 = open_database.begin();it1 != open_database.end();it1++)

  {

      cdbxx::vector<int> key(it1->first);

      TIME1=key.get()[0];

      if(it1 == open_database.begin())

      {

        i_time=TIME1/periodseconds;

        i_time*=periodseconds;

       }

       time0=TIME1;

      //a new bar

      if(time0>=i_time+periodseconds || it1 == open_database.end())

      {

            key1[0] = i_time;

         //new_database.insert(key1, value1);

         cnt++;

         if(time0>=i_time+periodseconds)

         {

            i_time=time0/periodseconds;

            i_time*=periodseconds;

        }

      }

  }

            key1[0] = i_time;

         //new_database.insert(key1, value1);

         cnt++;

*/

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void idx_create(    string symbol,

                    int Period,

                    int Period1,

                    int Period2,

                    int Period3

                    )

{

   static int i_time1;

   static int i_time2;

   static int i_time3;

   int ps1,ps2,ps3;

   int cnt1 = 0;

   int cnt2 = 0;

   int cnt3 = 0;

   int LastBarTime;

   int PeriodMultiplier1=(int)(Period1/Period);

   int PeriodMultiplier2=(int)(Period2/Period);

   int PeriodMultiplier3=(int)(Period3/Period);

   if (PeriodMultiplier1 <= 1)

   {

      PeriodMultiplier1 = 1;

   }

   if (PeriodMultiplier2 <= 1)

   {

      PeriodMultiplier2 = 1;

   }

   if (PeriodMultiplier3 <= 1)

   {

      PeriodMultiplier3 = 1;

   }

   std::stringstream ss1;

   ss1 << Period;

   std::string min1 = ss1.str();

   //std::string db_name1="/home/barnix/mt4db/cdb/"+symbol+min1+".cdb";

   //std::string _db_idx="/home/barnix/mt4db/cdb/_"+symbol+min1+".cdb";

   std::string db_name1=symbol_filename(symbol, Period);//"/home/barnix/mt4db/cdb/"+symbol+min1+".cdb";

   std::string _db_idx=symbol_idxfile(symbol, Period1);//"/home/barnix/mt4db/cdb/"+symbol+min2+".cdb";

   cdbxx::in_db open_database(db_name1);

   cdbxx::out_db new_idx(_db_idx);

   ps1 = Period * PeriodMultiplier1 * 60;

   ps2 = Period * PeriodMultiplier2 * 60;

   ps3 = Period * PeriodMultiplier3 * 60;

  for( cdbxx::iterator it1 = open_database.begin();it1 != open_database.end();it1++)

  {

         cdbxx::vector<int> key(it1->first);

      int key1,key2,key3;

      if(it1 == open_database.begin())

      {

        i_time1=key.get()[0]/ps1;

        i_time1*=ps1;

        key1=i_time1;

        i_time2=key.get()[0]/ps2;

        i_time2*=ps2;

        key2=i_time2;

        i_time3=key.get()[0]/ps3;

        i_time3*=ps3;

        key3=i_time3;

      }

      LastBarTime = key.get()[0];

      //a new bar

      if (LastBarTime >=  i_time1+ps1)

      {

            key1 = i_time1;

         cnt1++;

         i_time1=LastBarTime/ps1;

         i_time1*=ps1;

      }

      //a new bar

      if (LastBarTime >=  i_time2+ps2)

      {

            key2 = i_time2;

         cnt2++;

         i_time2=LastBarTime/ps2;

         i_time2*=ps2;

      }

      //a new bar

      if (LastBarTime >=  i_time3+ps3)

      {

            key3 = i_time3;

         cnt3++;

         i_time3=LastBarTime/ps3;

         i_time3*=ps3;

      }

      std::vector<int> kidx(1);

      std::vector<int> idx(3);

      kidx[0]=LastBarTime;

      idx[0]=key1;

      idx[1]=key2;

      idx[2]=key3;

      new_idx.insert(kidx,idx);

        //std::cout << kidx[0]<<","<<idx[0]<<"," <<idx[1]<<","<<idx[2] <<std::endl;

        //std::cout << LastBarTime<<","<<i_time1<<"," <<i_time2<<","<<i_time3<<std::endl;

  }

 std::cout << symbol    << " "<< cnt1

                        << " "<< cnt2

                        << " "<< cnt3

                        << " - indexed" << std::endl;

}