Skip to content

Commit c68625d

Browse files
committed
add some error handling and minor polish of read_apr
1 parent ff32edb commit c68625d

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/io/APRFile.hpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -364,43 +364,43 @@ bool APRFile::write_particles(const std::string particles_name,ParticleData<Data
364364
bool APRFile::read_apr(APR &apr,uint64_t t,std::string channel_name){
365365

366366

367-
if(fileStructure.isOpened()){
368-
} else {
367+
if(!fileStructure.isOpened()){
369368
std::cerr << "File is not open!" << std::endl; //#TODO: should check if it is readable, and other functions if writeable ect.
369+
return false;
370370
}
371371

372-
bool tree_exists = fileStructure.open_time_point(t,with_tree_flag,channel_name);
372+
if(!fileStructure.open_time_point(t, with_tree_flag,channel_name)) {
373+
std::cerr << "Error reading APR file: could not open time point t=" << t << " in channel '" << channel_name << "'" << std::endl;
374+
return false;
375+
}
373376

374377
hid_t meta_data = fileStructure.groupId;
375378

376379
//check if old or new file, for location of the properties. (The metadata moved to the time point.)
377-
bool old = attribute_exists(fileStructure.objectId,AprTypes::MaxLevelType.typeName);
378-
379-
if(old) {
380+
if(attribute_exists(fileStructure.objectId,AprTypes::MaxLevelType.typeName)) {
380381
meta_data = fileStructure.objectId;
381382
}
382383

383-
if (!fileStructure.isOpened()) return false;
384-
385384
std::string data_n = fileStructure.subGroup1 + "/map_level";
386385
bool stored_random = data_exists(fileStructure.fileId,data_n.c_str());
387386

388387
data_n = fileStructure.subGroup1 + "/y_vec";
389388
bool stored_linear = data_exists(fileStructure.fileId,data_n.c_str());
390389

391390
if(!stored_linear && !stored_random){
392-
std::cerr << "An APR does not exist for that channel and time" << std::endl;
391+
std::cerr << "Error reading APR file: data does not exist for channel '" <<
392+
channel_name << "' and time point t=" << t << std::endl;
393393
return false;
394394
}
395395

396396
// ------------- read metadata --------------------------
397397
char string_out[100] = {0};
398398
hid_t attr_id = H5Aopen(meta_data,"name",H5P_DEFAULT);
399399
hid_t atype = H5Aget_type(attr_id);
400-
hid_t atype_mem = H5Tget_native_type(atype, H5T_DIR_ASCEND);
400+
hid_t atype_mem = H5Tget_native_type(atype, H5T_DIR_DEFAULT);
401401
H5Aread(attr_id, atype_mem, string_out) ;
402402
H5Aclose(attr_id);
403-
apr.name= string_out;
403+
apr.name = string_out;
404404

405405
//read in access information
406406
APRWriter::read_access_info(meta_data,apr.aprInfo);
@@ -412,13 +412,11 @@ bool APRFile::read_apr(APR &apr,uint64_t t,std::string channel_name){
412412

413413
timer.start_timer("read_apr_access");
414414

415-
if(!stored_random) {
416-
417-
//make this an automatic check to see what the file is.
415+
if(stored_linear) {
416+
//TODO: make this an automatic check to see what the file is.
418417
APRWriter::read_linear_access( fileStructure.objectId, apr.linearAccess,max_level_delta);
419418
apr.apr_initialized = true;
420419
} else {
421-
422420
APRWriter::read_random_access(meta_data, fileStructure.objectId, apr.apr_access);
423421
apr.apr_initialized_random = true;
424422
}
@@ -435,13 +433,10 @@ bool APRFile::read_apr(APR &apr,uint64_t t,std::string channel_name){
435433
data_n = fileStructure.subGroupTree1 + "/y_vec";
436434
bool stored_linear_tree = data_exists(fileStructure.fileId,data_n.c_str());;
437435

438-
tree_exists = true;
439-
if(!stored_random_tree && !stored_linear_tree){
440-
tree_exists = false;
441-
}
436+
bool tree_exists = stored_linear_tree || stored_random_tree;
442437

443438
if(!tree_exists){
444-
//initializing it from the dataset.
439+
// if tree access does not exist in file, initialize it from the APR access
445440
apr.initialize_tree_linear();
446441
} else {
447442

0 commit comments

Comments
 (0)