@@ -42,6 +42,7 @@ class APRFile {
4242 template <typename DataType>
4343 bool read_particles (APR& apr,ParticleData<DataType>& particles,bool apr_or_tree = true ,uint64_t t = 0 ,std::string channel_name = " t" );
4444
45+ std::string get_particle_type (std::string particles_name, bool apr_or_tree=true , uint64_t t=0 , std::string channel_name=" t" );
4546
4647 // set helpers
4748 bool get_read_write_tree (){
@@ -641,6 +642,55 @@ bool APRFile::read_particles(APR& apr,ParticleData<DataType>& particles,bool apr
641642}
642643
643644
645+ std::string APRFile::get_particle_type (std::string particles_name, bool apr_or_tree, uint64_t t, std::string channel_name) {
646+
647+ if (!fileStructure.isOpened ()){
648+ std::cerr << " File is not open!" << std::endl;
649+ return " " ;
650+ }
651+
652+ if (!fileStructure.open_time_point (t, with_tree_flag,channel_name)) {
653+ std::cerr << " Error reading APR file: could not open time point t=" << t << " in channel '" << channel_name << " '" << std::endl;
654+ return " " ;
655+ }
656+
657+ hid_t part_location;
658+
659+ if (apr_or_tree){
660+ part_location = fileStructure.objectId ;
661+ } else {
662+ part_location = fileStructure.objectIdTree ;
663+ }
664+
665+ // Check that the dataset exists
666+ std::string data_n = particles_name;
667+ if (!data_exists (part_location,data_n.c_str ())) {
668+ std::cerr << " Error reading APR file: particle dataset '" << particles_name << " ' doesn't exist" << std::endl;
669+ return " " ;
670+ }
671+
672+ // Check the datatype
673+ Hdf5DataSet dataset;
674+ dataset.init (part_location,particles_name.c_str ());
675+ dataset.open ();
676+ hid_t dtype = dataset.get_type ();
677+
678+ if ( H5Tequal (dtype, APRWriter::Hdf5Type<uint16_t >::type ()) ) { dataset.close (); return " uint16" ; }
679+ if ( H5Tequal (dtype, APRWriter::Hdf5Type<float >::type ()) ) { dataset.close (); return " float" ; }
680+ if ( H5Tequal (dtype, APRWriter::Hdf5Type<uint8_t >::type ()) ) { dataset.close (); return " uint8" ; }
681+ if ( H5Tequal (dtype, APRWriter::Hdf5Type<uint32_t >::type ()) ) { dataset.close (); return " uint32" ; }
682+ if ( H5Tequal (dtype, APRWriter::Hdf5Type<uint64_t >::type ()) ) { dataset.close (); return " uint64" ; }
683+ if ( H5Tequal (dtype, APRWriter::Hdf5Type<double >::type ()) ) { dataset.close (); return " double" ; }
684+ if ( H5Tequal (dtype, APRWriter::Hdf5Type<int8_t >::type ()) ) { dataset.close (); return " int8" ; }
685+ if ( H5Tequal (dtype, APRWriter::Hdf5Type<int16_t >::type ()) ) { dataset.close (); return " int16" ; }
686+ if ( H5Tequal (dtype, APRWriter::Hdf5Type<int32_t >::type ()) ) { dataset.close (); return " int32" ; }
687+ if ( H5Tequal (dtype, APRWriter::Hdf5Type<int64_t >::type ()) ) { dataset.close (); return " int64" ; }
688+
689+ std::cerr << " Error: get_particle_type could not detect the data type (unsupported type)" << std::endl;
690+ return " " ;
691+ }
692+
693+
644694// get helpers
645695
646696/* *
0 commit comments