int main() { int retcode = 0; cout << "XMAP buffer parser!" << endl; // prints !!!Hello World!!! unsigned short *testfilebuf = NULL; unsigned int testfilelen = 1024*1024; testfilebuf = (unsigned short*)calloc(testfilelen, sizeof(unsigned short)); retcode = load_dataset_txt("/home/up45/sandbox/data1.txt", testfilebuf, testfilelen); printf("retcode: %d\n", retcode); for (int i=0; i<10; i++) printf("%6d 0x%04X\n", testfilebuf[i], testfilebuf[i]); XmapBuffer buf; printf("Parsing data1.txt....\n"); buf.parse(testfilebuf, testfilelen); free(testfilebuf); //buf.report(4); //return 0; printf("Parsing testbuf1....\n"); buf.parse(testbuf1, sizeof(testbuf1)/2); printf("Parsing testbuf2...\n"); buf.parse(testbuf2, sizeof(testbuf2)/2); buf.report(2); printf("Getting pixelmap reference\n"); XmapBuffer::PixelMap_t& pm = buf.pixels(); printf("pixel0 report:\n"); pm[0].report(2); printf("Testing copy\n"); unsigned short dest[3] = {0,0,0}; XmapChannelData *xcd = pm[0].channels()[0]; Spectrum* sp; sp = dynamic_cast<Spectrum*> (xcd); sp->report(2); sp->copy_data(dest, 3); printf("dest: %d %d %d\n", dest[0], dest[1], dest[2]); printf("Testing copy to NDArray\n"); NDArray ndarr; ndarr.dataSize = 500; ndarr.dataType = NDUInt16; ndarr.ndims = 2; ndarr.initDimension(ndarr.dims+0, (int)pm[0].num_channels()); ndarr.initDimension(ndarr.dims+1, pm[0].data_size()); ndarr.pData = calloc(ndarr.dataSize, sizeof(char)); pm[0].copy_data( &ndarr ); ndarr.report(stdout, 11); return 0; }
void util_fill_ndarr_dims(NDArray &ndarr, unsigned long int *sizes, int ndims) { log4cxx::LoggerPtr log( log4cxx::Logger::getLogger("main") ); static short counter = 3; int i=0; ndarr.ndims = ndims; int num_elements = 1; for (i=0; i<ndims; i++) { // Note: the NDArray dimensions are reverse order in relation to // the HDF5 dataset dimensionality. sigh.... ndarr.initDimension(&(ndarr.dims[ndims-i-1]), sizes[i]); num_elements *= sizes[i]; } ndarr.pData = calloc(num_elements, sizeof(short)); LOG4CXX_TRACE(log, "Filling array with dummy data..."); for (i=0; i<num_elements; i++) { *((short*)ndarr.pData + i) = i; } short *ptrdata = (short*)ndarr.pData; ptrdata[0] = counter++; ptrdata[1] = counter++; LOG4CXX_TRACE(log, "Done filling array!"); }