123 uint64_t vectorSize, byteSize;
124 uint64_t amountToReadIn;
125 vlsv::datatype::type dataType;
126 const string variableName =
"CellID";
127 std::list< pair<std::string, std::string> > xmlAttributes;
128 xmlAttributes.push_back( make_pair(
"name", variableName ) );
129 xmlAttributes.push_back( make_pair(
"mesh", meshName ) );
131 if( getArrayInfo(
"VARIABLE", xmlAttributes, amountToReadIn, vectorSize, dataType, byteSize ) ==
false ) {
132 cerr <<
"ERROR, failed to read array info for variable '" << variableName <<
"' ";
133 cerr <<
"in mesh '" << meshName <<
"' at " << __FILE__ <<
":" << __LINE__ << endl;
136 if( dataType != vlsv::datatype::type::UINT ) {
137 cerr <<
"ERROR, BAD DATATYPE AT " << __FILE__ <<
" " << __LINE__ << endl;
140 if( byteSize !=
sizeof(uint64_t) ) {
141 cerr <<
"ERROR, BAD DATASIZE AT " << __FILE__ <<
" " << __LINE__ << endl;
144 if( vectorSize != 1 ) {
145 cerr <<
"ERROR, BAD VECTORSIZE AT " << __FILE__ <<
" " << __LINE__ << endl;
148 uint64_t * cellIds_buffer =
new uint64_t[amountToReadIn * vectorSize];
150 const uint16_t begin = 0;
151 const bool allocateMemory =
false;
152 if( read(
"VARIABLE", xmlAttributes, begin, amountToReadIn, cellIds_buffer, allocateMemory ) ==
false ) {
153 cerr <<
"ERROR, Failed to read variable data at " << __FILE__ <<
":" << __LINE__ << endl;
157 cellIds.reserve( amountToReadIn * vectorSize );
158 for( uint64_t
i = 0;
i < amountToReadIn * vectorSize; ++
i ) {
159 cellIds.push_back( cellIds_buffer[
i] );
161 delete[] cellIds_buffer;
170 uint64_t vectorSize, byteSize;
171 uint64_t amountToReadIn;
172 vlsv::datatype::type dataType;
173 const string variableName =
"CellID";
174 std::list< pair<std::string, std::string> > xmlAttributes;
175 xmlAttributes.push_back( make_pair(
"name", variableName ) );
176 xmlAttributes.push_back( make_pair(
"mesh",
"SpatialGrid" ) );
177 if( getArrayInfo(
"VARIABLE", xmlAttributes, amountToReadIn, vectorSize, dataType, byteSize ) ==
false )
return false;
178 if( dataType != vlsv::datatype::type::UINT ) {
179 cerr <<
"ERROR, BAD DATATYPE AT " << __FILE__ <<
" " << __LINE__ << endl;
182 if( byteSize !=
sizeof(uint64_t) ) {
183 cerr <<
"ERROR, BAD DATASIZE AT " << __FILE__ <<
" " << __LINE__ << endl;
186 if( vectorSize != 1 ) {
187 cerr <<
"ERROR, BAD VECTORSIZE AT " << __FILE__ <<
" " << __LINE__ << endl;
190 uint64_t * cellIds_buffer =
new uint64_t[amountToReadIn * vectorSize];
192 const uint16_t begin = 0;
193 const bool allocateMemory =
false;
194 if( read(
"VARIABLE", xmlAttributes, begin, amountToReadIn, cellIds_buffer, allocateMemory ) ==
false )
return false;
196 cellIdLocations.rehash( (uint64_t)(amountToReadIn * vectorSize * 1.25) );
197 for( uint64_t
i = 0;
i < amountToReadIn * vectorSize; ++
i ) {
198 const uint64_t cellid = cellIds_buffer[
i];
201 delete[] cellIds_buffer;
210 vlsv::datatype::type cwb_dataType;
211 uint64_t cwb_arraySize, cwb_vectorSize, cwb_dataSize;
212 list<pair<string, string> > attribs;
217 attribs.push_back(make_pair(
"mesh", meshName));
218 if (popName.size() > 0) attribs.push_back(make_pair(
"name", popName));
221 if (getArrayInfo(
"CELLSWITHBLOCKS", attribs, cwb_arraySize, cwb_vectorSize, cwb_dataType, cwb_dataSize) ==
false) {
222 cerr <<
"ERROR, COULD NOT FIND ARRAY CELLSWITHBLOCKS FOR POPULATION '" << popName <<
"' AT " << __FILE__ <<
":" << __LINE__ << endl;
227 if( cwb_vectorSize != 1 ) {
228 cerr <<
"ERROR, BAD VECTORSIZE AT " << __FILE__ <<
" " << __LINE__ << endl;
231 if( cwb_dataType != vlsv::datatype::type::UINT ) {
232 cerr <<
"ERROR, BAD DATATYPE AT " << __FILE__ <<
" " << __LINE__ << endl;
235 if( cwb_dataSize !=
sizeof(uint64_t) ) {
236 cerr <<
"ERROR, BAD DATASIZE AT " << __FILE__ <<
" " << __LINE__ << endl;
241 const uint64_t cwb_amountToReadIn = cwb_arraySize * cwb_vectorSize * cwb_dataSize;
242 const uint16_t cwb_startingPoint = 0;
243 char * cwb_buffer =
new char[cwb_amountToReadIn];
244 if (readArray(
"CELLSWITHBLOCKS", attribs, cwb_startingPoint, cwb_arraySize, cwb_buffer) ==
false) {
245 cerr <<
"Failed to read block metadata for mesh '" << meshName <<
"'" << endl;
250 vlsv::datatype::type nb_dataType;
251 uint64_t nb_arraySize, nb_vectorSize, nb_dataSize;
255 if (getArrayInfo(
"BLOCKSPERCELL", attribs, nb_arraySize, nb_vectorSize, nb_dataType, nb_dataSize) ==
false) {
256 cerr <<
"ERROR, COULD NOT FIND ARRAY BLOCKSPERCELL AT " << __FILE__ <<
" " << __LINE__ << endl;
261 const short int startingPoint = 0;
262 char* nb_buffer =
new char[nb_arraySize * nb_vectorSize * nb_dataSize];
263 if (readArray(
"BLOCKSPERCELL", attribs, startingPoint, nb_arraySize, nb_buffer) ==
false) {
264 cerr <<
"Failed to read number of blocks for mesh '" << meshName <<
"'" << endl;
271 uint64_t blockOffset = 0;
273 for (uint64_t cell = 0; cell < cwb_arraySize; ++cell) {
274 const uint64_t readCellID =
convUInt(cwb_buffer + cell*cwb_dataSize, cwb_dataType, cwb_dataSize);
275 N_blocks =
convUInt(nb_buffer + cell*nb_dataSize, nb_dataType, nb_dataSize);
276 const pair<uint64_t, uint32_t> input = make_pair( blockOffset, N_blocks );
279 blockOffset += N_blocks;
288 bool Reader::getBlockIds(
const uint64_t& cellId,std::vector<uint64_t>& blockIds,
const std::string& popName) {
290 cerr <<
"ERROR, setCellsWithBlocks() NOT CALLED AT (CALL setCellsWithBlocks()) BEFORE CALLING getBlockIds " << __FILE__ <<
" " << __LINE__ << endl;
296 cerr <<
"COULDNT FIND CELL ID " << cellId <<
" AT " << __FILE__ <<
" " << __LINE__ << endl;
300 pair<uint64_t, uint32_t> offsetAndBlocks = it->second;
301 const uint64_t blockOffset = get<0>(offsetAndBlocks);
302 const uint32_t N_blocks = get<1>(offsetAndBlocks);
305 list<pair<string, string> > attribs;
306 if (popName.size() > 0) attribs.push_back(make_pair(
"name",popName));
309 uint64_t blockIds_arraySize, blockIds_vectorSize, blockIds_dataSize;
310 vlsv::datatype::type blockIds_dataType;
312 if (getArrayInfo(
"BLOCKIDS", attribs, blockIds_arraySize, blockIds_vectorSize, blockIds_dataType, blockIds_dataSize) ==
false) {
313 cerr <<
"ERROR, COULD NOT FIND BLOCKIDS FOR '" << popName <<
"' AT " << __FILE__ <<
" " << __LINE__ << endl;
317 if( blockIds_dataType != vlsv::datatype::type::UINT ) {
318 cerr <<
"ERROR, bad datatype at " << __FILE__ <<
" " << __LINE__ << endl;
322 char * blockIds_buffer =
new char[N_blocks*blockIds_vectorSize*blockIds_dataSize];
324 if( readArray(
"BLOCKIDS", attribs, blockOffset, N_blocks, blockIds_buffer ) ==
false ) {
325 cerr <<
"ERROR, FAILED TO READ BLOCKIDS AT " << __FILE__ <<
" " << __LINE__ << endl;
326 delete[] blockIds_buffer;
330 blockIds.reserve(N_blocks);
331 for (uint64_t
i = 0;
i < N_blocks; ++
i) {
332 const uint64_t blockId =
convUInt(blockIds_buffer +
i*blockIds_dataSize, blockIds_dataType, blockIds_dataSize);
333 blockIds.push_back( blockId );
335 delete[] blockIds_buffer;
341 cerr <<
"ERROR, CELLS WITH BLOCKS NOT SET AT " << __FILE__ <<
" " << __LINE__ << endl;
348 cerr <<
"COULDNT FIND CELL ID " << cellId <<
" AT " << __FILE__ <<
" " << __LINE__ << endl;
353 list<pair<string, string> > attribs;
354 attribs.push_back(make_pair(
"name", variableName));
355 attribs.push_back(make_pair(
"mesh",
"SpatialGrid"));
357 vlsv::datatype::type dataType;
358 uint64_t arraySize, vectorSize, dataSize;
359 if (getArrayInfo(
"BLOCKVARIABLE", attribs, arraySize, vectorSize, dataType, dataSize) ==
false) {
360 cerr <<
"Could not read BLOCKVARIABLE array info" << endl;
365 const uint64_t offset = get<0>(it->second);
366 const uint32_t amountToReadIn = get<1>(it->second);
368 if( allocateMemory ==
true ) {
369 buffer =
new char[amountToReadIn * vectorSize * dataSize];
373 if (readArray(
"BLOCKVARIABLE", attribs, offset, amountToReadIn, buffer) ==
false) {
374 cerr <<
"ERROR could not read block variable" << endl;
375 if( allocateMemory ==
true ) {
376 delete[] buffer; buffer = NULL;