EasyBMP Extensions: SimpleArray
SimpleArray is intended to simplify ASCII tabular data import and export. In particular, you can use it to import and export data into plotting programs that use the EasyBMP bitmap library.
Click here to download the extension. (Contained in the extensions package)
SimpleArray can read tab, space, comma, and semicolon-delimited ASCII data files. It does its best to automatically determine the number of rows and columns and read the data. Once there, you get the following data structure:
class SimpleArray
{
int Rows; // number of rows in the data set
int Cols; // number of columns in the data set
char Delimiter; // text delimiter that was autodetected
double** Data; // the actual data
SimpleArray(); // creates empty array
SimpleArray(int nR, int nC); // creates empty nR x nC array
void SetSize(int nR, int nC); // resizes to an empty nR x nC array
bool ReadFromFile( char* FileName ); // reads from file
void WriteToFile( char* FileName ); // writes to file
double* operator()(int i, int j); // returns pointer to (i,j) entry
double* operator()(int i ); // returns pointer to (i,0) or (0,i) entry
~SimpleArray(); // cleanup (don't use this)
};
Note that the operator()(int i) function should only be used for data arrays with 1 row or 1 column. (Think of it as a way to treat an array as a vector.)
Here's a sample usage:
#include "EasyBMP_SimpleArray.h"
...
SimpleArray InputData;
InputData.ReadFromFile( "PHI.dat" );
SimpleArray OutputData( InputData.Rows, InputData.Cols );
int i,j;
for( i=0 ; i < InputData.Rows ; i++)
{
for( j=0 ; j < InputData.Cols ; j++)
{ *OutputData(i,j) = pow( *InputData(i,j) , 2.0 ); }
}
OutputData.WriteToFile( "junk.dat" );