Printing Large Arrays

 

I am trying to run a script that will collect data in an array and then analyze it in excel. The problem is I don't know how to get it to excel.

I have tried both http://www.fx1.net/excellink.php and http://fxdialogue.com/ and neither of them work for this solution.

My arrays are 100,000 by 20 and larger. Any ideas?

Jeremy

 
JeremyJ:

I am trying to run a script that will collect data in an array and then analyze it in excel. The problem is I don't know how to get it to excel.

I have tried both http://www.fx1.net/excellink.php and http://fxdialogue.com/ and neither of them work for this solution.

My arrays are 100,000 by 20 and larger. Any ideas?

Why not just write the data to a *.csv file via file functions? U can even launch excel afterwords with a call to ShellExecuteA() (with the csv file as a parameter).
 

I copied the sample code for the FileWriteArray function as you can see below with the only change being switching from .dat to .csv and FILE_BIN to FILE_CSV.

With that change I get the error code 4104 which is "incompatible access to a file".

What am I missing?

int start()
  {
  int handle;
  double BarOpenValues[10];
  // copy first ten bars to the array
  for(int i=0;i<10; i++)
    BarOpenValues[i]=Open[i];
  // writing array to the file
  handle=FileOpen("mydata.csv", FILE_CSV|FILE_WRITE);
  if(handle>0)
    {
     FileWriteArray(handle, BarOpenValues, 0, 10); // writing last 7 elements
     FileClose(handle);
    }


      
      int error=GetLastError();
      Alert("Error = ",ErrorDescription(error));

   return(0);
  }
 
JeremyJ:

With that change I get the error code 4104 which is "incompatible access to a file".

FileWriteArray() can be used with binary files only...
 
gordon wrote >>
FileWriteArray() can be used with binary files only...


So then how do I write an array to a csv file? Do I use a different FileFunction? If you wouldn't mind can you please post a sample code of what you are talking about.

That would be very helpful. I have been searching for hours all over the internet. Thanks.

 

Quick and dirty (with no error handling...):

int start()
{
   int arr[100000,20];   //your data
   int handle=FileOpen("mydata.csv", FILE_CSV|FILE_WRITE, ',');
  
   for(int i=0; i<100000; i++) {             
      FileWrite(handle,arr[i, 0],arr[i, 1],arr[i, 2],arr[i, 3],arr[i, 4],
                       arr[i, 5],arr[i, 6],arr[i, 7],arr[i, 8],arr[i, 9],
                       arr[i,10],arr[i,11],arr[i,12],arr[i,13],arr[i,14],
                       arr[i,15],arr[i,16],arr[i,17],arr[i,18],arr[i,19] );
   }
   
   FileClose(handle);
}

Notes:

  • This can be done with less clatter by using another inner loop on j in arr[i,j].
  • Usage of ArrayRange() or #define for i,j limit will make the code clearer and more flexible.
 
gordon wrote >>

Quick and dirty (with no error handling...):

Notes:

  • This can be done with less clatter by using another inner loop on j in arr[i,j].
  • Usage of ArrayRange() or #define for i,j limit will make the code clearer and more flexible.

Perfect! Thanks Gordon.