I am new to .NET programming.....I am trying to write a program that copies a large matrix into a certain format called HDF5 format. The program just has to do this. There are a large number of text files (140). The program just reads the files and converts the text data into integers and stores these in a matrix. So the matrix has 140*1091 rows as each file has 1091 integers. But in the beginning when I give the memory allocation as "const int FSPACE_DIM1 = 1091*100;" the program stops here itself and gives the error:
"An unhandled exception of type 'System.StackOverflowException' occurred in copytohdf5.exe".
I saw the earlier discussion where daniel had the same problem. Swandog46 had given a reply asking him to rewrite the program iteratively so that he could allocate his own memory. I am not able to figure out how to do this. This is my code (It builds and compiles):
// This is the main project file for VC++ application project
// generated using an Application Wizard.
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include <string>
#include "stdafx.h"
#ifdef OLD_HEADER_FILENAME
#include <iostream.h>
#else
#include <iostream>
#endif
#include "H5Cpp.h"
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif
const string FILE_NAME = "RamanHDF.h5";
const string DATASET_NAME( " RAMAN data" );
const int FSPACE_RANK = 2; // Dataset rank as it is stored in the file
const int FSPACE_DIM1 = 1091*100; // Dimension sizes of the dataset as it is...
const int FSPACE_DIM2 = 4; // ...stored in the file
//const int FSPACE_DIM3 = 2;
#include <iomanip>
#include <fstream>
using namespace std;
#using <mscorlib.dll>
using namespace System;
int _tmain()
{
//float matrix[FSPACE_DIM1][FSPACE_DIM2][FSPACE_DIM3];
float matrix[FSPACE_DIM1][FSPACE_DIM2];
float x=0;
int m=0;
int e=0;
string y;
char filename1[100] = "C:\\Documents and Settings\\ganesht-a\\Desktop\\moving to CPP\\directRAMANTOHDFALLXY\\raman-files\\wy2-136";
char filename3[15]=".txt";
char filename2[15];
char filename[100];
for(int j=1;j<=100;j++)
{
y.clear();
for(int k=0;k<=250;k++)
filename[k]='\0';
for(int k=0;k<=strlen(filename2);k++)
filename2[k]='\0';
sprintf(filename2, "%d", j);
for(int i=0;i<(strlen(filename1));i++)
filename[i]=filename1[i];
m=strlen(filename);
for(int i=0;filename2[i]!='\0';i++)
filename[m+i]=filename2[i];
m=strlen(filename);
for(int i=0;filename3[i]!='\0';i++)
filename[m+i]=filename3[i];
ifstream inFile;
inFile.open(filename);
if (!inFile)
{
cout << "Unable to open file";
exit(1); // terminate with error
}
while(getline(inFile,y))
if(y =="XYDATA")
{
for(int i=0;i<1091;i++)
for(int l=0;l<2;l++)
{
inFile >> x;
matrix[i+(1091*(j-1))][l] = x;
}
}
for(int i=0;i<j*1091;i++)
{
if(((i+1)%1091)==0)
e=(i+1)/1091;
else
e = (i+1)/1091 + 1;
if(e%20==0)
matrix[i][2]=20;
else
matrix[i][2]=e%20;
if(e%20==0)
matrix[i][3]=e/20;
else
matrix[i][3]=(e)/20+1;
}
for(int i=0;i<j*1091;i++)
{
cout<<matrix[i][0]<<"\t"<<matrix[i][1]<<endl;
}
inFile.close();
}
//This part is only after reading the file data into the matrix and must work fine once the matrix size problem is cleared..
H5File* file = new H5File( FILE_NAME, H5F_ACC_TRUNC );
hsize_t fdim[] = {FSPACE_DIM1, FSPACE_DIM2}; // dim sizes of ds (on disk)
DataSpace fspace( FSPACE_RANK, fdim );
DataSet* dataset = new DataSet( file->createDataSet( DATASET_NAME, PredType::NATIVE_FLOAT , fspace ));
dataset->write( matrix, PredType::NATIVE_FLOAT );
delete dataset;
delete file;
file = new H5File( FILE_NAME, H5F_ACC_RDONLY );
dataset = new DataSet( file->openDataSet( DATASET_NAME ));
dataset->read( matrix, PredType::NATIVE_FLOAT);
delete dataset;
delete file;
return 0;
}
I am not from a programming background and have been trying this. If Swandog46 could tell me how to allocate memory on my own I would greatly appreciate it.