add filepath check, minimal.py, tdm_reaper.pyx: write_all
This commit is contained in:
parent
a3b78f5ae2
commit
0db972c2f5
11
README.md
11
README.md
@ -267,7 +267,16 @@ for grp in grpids :
|
||||
print("failed to print channelgroup: " + str(grp) + " : " + str(e))
|
||||
```
|
||||
|
||||
For a full example including more details see `python/usage.py`.
|
||||
For a full example including more details see [python/usage.py](python/usage.py)
|
||||
and the absolute minimal example [minimal usage](python/minimal.py). In order
|
||||
to simply extract all data of the TDM datatset and dump it to files in a given
|
||||
(existing!) directory, do
|
||||
|
||||
```Python
|
||||
import tdm_reaper
|
||||
jack = tdm_reaper.tdmreaper(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
||||
jack.write_all(b"./my_tdm_data/")
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
|
@ -42,3 +42,10 @@ cdef class tdmreaper:
|
||||
def print_channel(self, string id, const char* filename,
|
||||
bool include_meta):
|
||||
self.cpp_tdm.print_channel(id,filename,include_meta)
|
||||
|
||||
# print all data grouped by channelgroups
|
||||
def write_all(self, string outputdir) :
|
||||
grpids = self.cpp_tdm.get_channelgroup_ids()
|
||||
for id in grpids :
|
||||
grpfile = outputdir.decode() + "/channelgroup_" + id.decode() + ".csv"
|
||||
self.cpp_tdm.print_group(id,grpfile.encode(),True,ord(','))
|
||||
|
@ -24,5 +24,5 @@ cdef extern from "tdm_reaper.hpp":
|
||||
string get_channelgroup_info(string id) except+
|
||||
string get_channel_info(string id) except+
|
||||
# print a channel(-group)
|
||||
void print_group(string id, const char* filename, bool include_meta, char delimiter)
|
||||
void print_channel(string id, const char* filename, bool include_meta)
|
||||
void print_group(string id, const char* filename, bool include_meta, char delimiter) except+
|
||||
void print_channel(string id, const char* filename, bool include_meta) except+
|
||||
|
@ -610,6 +610,9 @@ std::vector<tdmdatatype> tdm_reaper::get_channel(std::string& id)
|
||||
|
||||
void tdm_reaper::print_channel(std::string &id, const char* filename, bool include_meta)
|
||||
{
|
||||
// check required path
|
||||
this->check_filename_path(filename);
|
||||
|
||||
// check for channel id
|
||||
if ( this->tdmchannels_.count(id) != 1 )
|
||||
{
|
||||
@ -652,6 +655,9 @@ void tdm_reaper::print_channel(std::string &id, const char* filename, bool inclu
|
||||
|
||||
void tdm_reaper::print_group(std::string &id, const char* filename, bool include_meta, char sep)
|
||||
{
|
||||
// check required path
|
||||
this->check_filename_path(filename);
|
||||
|
||||
// check for group id
|
||||
if ( this->tdmchannelgroups_.count(id) != 1 )
|
||||
{
|
||||
@ -761,6 +767,20 @@ void tdm_reaper::print_group(std::string &id, const char* filename, bool include
|
||||
}
|
||||
}
|
||||
|
||||
void tdm_reaper::check_filename_path(const char* filename)
|
||||
{
|
||||
// declare filesystem path instance from filename
|
||||
std::filesystem::path pt(filename);
|
||||
|
||||
// get pure directory path
|
||||
pt.remove_filename();
|
||||
|
||||
if ( !std::filesystem::is_directory(pt) )
|
||||
{
|
||||
throw std::runtime_error(std::string("directory does not exist: ") + pt.c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
void tdm_reaper::check_local_datatypes()
|
||||
|
@ -208,6 +208,7 @@ public:
|
||||
// dump a single channel/entire group (identified by id) to file
|
||||
void print_channel(std::string &id, const char* filename, bool include_meta = true);
|
||||
void print_group(std::string &id, const char* filename, bool include_meta = true, char sep = ' ');
|
||||
void check_filename_path(const char* filename);
|
||||
|
||||
// check machine's datatypes
|
||||
// https://en.cppreference.com/w/cpp/language/types
|
||||
|
15
python/minimal.py
Normal file
15
python/minimal.py
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
import tdm_reaper
|
||||
|
||||
# create 'tdm_reaper' instance object
|
||||
try :
|
||||
jack = tdm_reaper.tdmreaper(b'samples/SineData.tdm',b'samples/SineData.tdx')
|
||||
# list ids of channelgroups
|
||||
grpids = jack.get_channelgroup_ids()
|
||||
# iterate through groups
|
||||
for grp in grpids :
|
||||
# write channelgroup to file (prepend './' for local directory!!)
|
||||
grpfile = "./channelgroup_" + str(grp.decode()) + ".csv"
|
||||
jack.print_channelgroup(grp,grpfile.encode(),True,ord(' '))
|
||||
except RuntimeError as e :
|
||||
print("failed to load/decode/write TDM files: " + str(e))
|
@ -391,7 +391,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user