//+------------------------------------------------------------------+
//|                                                  generateCsv.mq4 |
//|         Copyright © 2006, Antonio Banderass. All rights reserved |
//|                                               banderassa@ukr.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Antonio Banderass. All rights reserved"
#property link      "banderassa@ukr.net"
#property library
//+------------------------------------------------------------------+
//| PrepareString                                                    |
//+------------------------------------------------------------------+
string PrepareString(string s)
  {
   bool exit = false;
   int index = 0;
   string str = s;
//----
   while(!exit)
     {
       index = StringFind(str, ".", index);
       if(index > -1)
           str = StringSetChar(str, index, ',');
       else
           exit = true;
     }
   return(str);
  }
//+------------------------------------------------------------------+
//| GenerateCsv                                                      |
//+------------------------------------------------------------------+
int GenerateCsv(string fileName, int arraySizeX, int arraySizeY,
                double arrayIndexX[], double arrayIndexY[], double arrayZ[][])
  {
   int handle = FileOpen(fileName, FILE_CSV|FILE_WRITE, ' '), x, y;
   string str;
   if(handle < 1)
     {
       Print("Error:", GetLastError());
       return(handle);
     }
   else
     {
       str = ";";
       for(x = 0; x < arraySizeX; x++)
         {
           str = str + arrayIndexX[x];
           str = str + ";";         
         }
       FileWrite(handle, PrepareString(str));
       for(y = 0; y < arraySizeY; y++)
         {
           str = "";   
           str = str + arrayIndexY[y] + ";";
           for(x = 0; x < arraySizeX; x++)
             {
               str = str + arrayZ[x,y];
               str = str + ";";         
             }
           FileWrite(handle, PrepareString(str));
         }
     }
   FileClose(handle);   
   return(handle);
  }
//+------------------------------------------------------------------+


