src/main.cpp: filename rule
This commit is contained in:
parent
4d9dff517e
commit
156d8ce62f
12
README.md
12
README.md
@ -1,4 +1,13 @@
|
||||
# tdm_ripper
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/RecordEvolution/tdm_ripper.git">
|
||||
<img
|
||||
alt="tdmripper.svg"
|
||||
src="tdmripper.svg"
|
||||
width="400"
|
||||
/>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
The _tdm_ripper_ is a C++ based library that decodes the _technical data management_
|
||||
file format _TDM/TDX_ and is mainly employed for measurement data by
|
||||
@ -154,4 +163,5 @@ wrapper.
|
||||
|
||||
## References
|
||||
|
||||
- https://www.ni.com/de-de/support/documentation/supplemental/10/ni-tdm-data-model.html
|
||||
- https://zone.ni.com/reference/en-XX/help/371361R-01/lvhowto/ni_test_data_exchange/
|
||||
|
@ -203,7 +203,8 @@ public:
|
||||
{
|
||||
numsum += num_channels_group_[i];
|
||||
}
|
||||
assert( (numsum + channelid) > 0 && (numsum + channelid) <= num_channels_ );
|
||||
assert( (numsum + channelid) >= 0 );
|
||||
assert( (numsum + channelid) <= num_channels_ );
|
||||
|
||||
return numsum+channelid;
|
||||
}
|
||||
|
51
src/main.cpp
51
src/main.cpp
@ -13,7 +13,7 @@ const std::string githash("HASHSTRING");
|
||||
void show_usage()
|
||||
{
|
||||
std::cout<<"\n"
|
||||
<<"tdmripper ["<<gittag<<"-g"<<githash<<"] (Copyright © 2021 Record Evolution GmbH)"
|
||||
<<"tdmripper ["<<gittag<<"-g"<<githash<<"] (github.com/RecordEvolution/tdm_ripper.git)"
|
||||
<<"\n\n"
|
||||
<<"Decode TDM/TDX files and dump data as *.csv"
|
||||
<<"\n\n"
|
||||
@ -23,8 +23,10 @@ void show_usage()
|
||||
<<"Options:"
|
||||
<<"\n\n"
|
||||
<<" -d, --output (existing!) output directory (default: current working directory)\n"
|
||||
<<" -f, --filenames filenaming rule using %C (channel index), %c (channel name),\n"
|
||||
<<" %G (group index), %g (group name) \n"
|
||||
<<" (default: --filenames=channel_%G_%C.csv )\n"
|
||||
<<" -s, --csvsep separator character used in .csv files (default is comma ',')\n"
|
||||
<<" -p, --prefix name prefix for .csv files (default is none)\n"
|
||||
<<" -g, --listgroups list groups in data\n"
|
||||
<<" -c, --listchannels list channels in data\n"
|
||||
<<" -h, --help show this help message \n"
|
||||
@ -119,10 +121,10 @@ optkeys parse_args(int argc, char* argv[], bool showargs = false)
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("csvsep",argv[i+1]));
|
||||
i += 1;
|
||||
}
|
||||
else if ( std::string(argv[i]) == std::string("--prefix")
|
||||
|| std::string(argv[i]) == std::string("-p") )
|
||||
else if ( std::string(argv[i]) == std::string("--filenames")
|
||||
|| std::string(argv[i]) == std::string("-f") )
|
||||
{
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("prefix",argv[i+1]));
|
||||
prsdkeys.insert(std::pair<std::string,std::string>("filenames",argv[i+1]));
|
||||
i += 1;
|
||||
}
|
||||
else if ( std::string(argv[i]) == std::string("--listgroups")
|
||||
@ -167,8 +169,8 @@ int main(int argc, char* argv[])
|
||||
: std::string("./");
|
||||
std::string csvsep = cfgopts.count("csvsep") == 1 ? cfgopts.at("csvsep")
|
||||
: std::string(",");
|
||||
std::string prefix = cfgopts.count("prefix") == 1 ? cfgopts.at("prefix")
|
||||
: std::string("");
|
||||
std::string files = cfgopts.count("filenames") == 1 ? cfgopts.at("filenames")
|
||||
: std::string("channel_%C_%G.csv");
|
||||
bool listgroups = cfgopts.count("listgroups") == 1 ? true : false;
|
||||
bool listchannels = cfgopts.count("listchannels") == 1 ? true : false;
|
||||
|
||||
@ -185,19 +187,36 @@ int main(int argc, char* argv[])
|
||||
std::filesystem::path pd = output;
|
||||
if ( std::filesystem::is_directory(pd) )
|
||||
{
|
||||
for ( int i = 0; i < jack.num_channels(); i++ )
|
||||
for ( int g = 0; g < jack.num_groups(); g++ )
|
||||
{
|
||||
// sanitize channel name
|
||||
std::regex reg("([^A-Za-z0-9])");
|
||||
std::string chname = std::regex_replace(jack.channel_name(i),reg,"");
|
||||
// get and sanitize group name
|
||||
std::string grpnm = jack.group_name(g);
|
||||
std::regex regg("([^A-Za-z0-9])");
|
||||
std::string grpname = std::regex_replace(grpnm,regg,"");
|
||||
|
||||
// concat path and construct file name
|
||||
std::filesystem::path outfile = pd / ( std::string("channel_")
|
||||
+ std::to_string(i+1) + std::string("_")
|
||||
+ chname + std::string(".csv") );
|
||||
for ( int c = 0; c < jack.no_channels(g); c++ )
|
||||
{
|
||||
// get overall channel index/id
|
||||
int chidx = jack.obtain_channel_id(g,c);
|
||||
|
||||
// get and sanitize channel name
|
||||
std::string chnm = jack.channel_name(g,c);
|
||||
std::regex regc("([^A-Za-z0-9])");
|
||||
std::string chname = std::regex_replace(chnm,regc,"");
|
||||
|
||||
// construct file name according to filenaming rule
|
||||
std::string filenm = files;
|
||||
filenm = std::regex_replace(files,std::regex("\\%C"),std::to_string(c+1));
|
||||
filenm = std::regex_replace(filenm,std::regex("\\%c"),chname);
|
||||
filenm = std::regex_replace(filenm,std::regex("\\%G"),std::to_string(g+1));
|
||||
filenm = std::regex_replace(filenm,std::regex("\\%g"),grpname);
|
||||
|
||||
// concat paths
|
||||
std::filesystem::path outfile = pd / filenm;
|
||||
|
||||
// write channel to filesystem
|
||||
jack.print_channel(i,outfile.c_str());
|
||||
jack.print_channel(chidx,outfile.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
78
tdmripper.svg
Normal file
78
tdmripper.svg
Normal file
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 328.72 77.08"
|
||||
version="1.1"
|
||||
id="svg3945"
|
||||
width="328.72"
|
||||
height="77.080002">
|
||||
<metadata
|
||||
id="metadata3951">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title>flasher</dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<defs
|
||||
id="defs3949" />
|
||||
<title
|
||||
id="title3916">flasher</title>
|
||||
<g
|
||||
id="logog">
|
||||
<path
|
||||
id="path138"
|
||||
d="m 32.86,2 -13,7.5 v 0 h -0.05 v 0 l -0.48,0.28 c -4.27,2.46 -5.68,11.38 -6.06,14.75 L 36.2,11.33 c 0.39,-0.19 7.6,-3.69 13.57,-3.69 h 0.14 L 40.13,2 a 8.15,8.15 0 0 0 -7.27,0"
|
||||
transform="translate(-2.04,-1.15)"
|
||||
style="fill:#364d5c" />
|
||||
<path
|
||||
id="path142"
|
||||
d="M 5.68,17.69 A 8.2,8.2 0 0 0 2,24 v 15.78 c 0,4.9 7,10.48 9.75,12.46 V 25.77 c 0,-0.44 0.6,-8.55 3.65,-13.72 z"
|
||||
transform="translate(-2.04,-1.15)"
|
||||
style="fill:#364d5c" />
|
||||
<path
|
||||
id="path146"
|
||||
d="m 12.1,54.12 v 0 C 11.74,53.88 5,49.41 2,44.24 v 11.14 a 8.2,8.2 0 0 0 3.64,6.3 l 13.5,7.79 c 4.28,2.46 12.7,-0.77 15.81,-2.12 z"
|
||||
transform="translate(-2.04,-1.15)"
|
||||
style="fill:#364d5c" />
|
||||
<path
|
||||
id="path150"
|
||||
d="m 36.79,68 c -0.4,0.19 -7.71,3.75 -13.71,3.69 l 9.78,5.64 a 8.15,8.15 0 0 0 7.27,0 l 13.51,-7.8 c 4.27,-2.46 5.68,-11.39 6.06,-14.75 z"
|
||||
transform="translate(-2.04,-1.15)"
|
||||
style="fill:#364d5c" />
|
||||
<path
|
||||
id="path154"
|
||||
d="M 61.2,27.13 V 53.6 c 0,0.44 -0.6,8.55 -3.65,13.72 l 9.77,-5.64 A 8.2,8.2 0 0 0 71,55.38 V 39.59 c 0,-4.94 -7,-10.5 -9.75,-12.46"
|
||||
transform="translate(-2.04,-1.15)"
|
||||
style="fill:#364d5c" />
|
||||
<path
|
||||
id="path158"
|
||||
d="M 67.31,17.69 53.81,9.9 C 49.53,7.44 41.11,10.67 38,12 l 22.85,13.23 v 0 a 43.43,43.43 0 0 1 5.7,4.51 24,24 0 0 1 4.45,5.35 V 24 a 8.2,8.2 0 0 0 -3.64,-6.3"
|
||||
transform="translate(-2.04,-1.15)"
|
||||
style="fill:#364d5c" />
|
||||
</g>
|
||||
<g
|
||||
id="re" />
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#364d5c;fill-opacity:1;stroke:none"
|
||||
x="74.101189"
|
||||
y="54.47554"
|
||||
id="text3955"><tspan
|
||||
id="tspan3953"
|
||||
x="74.101189"
|
||||
y="54.47554"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:44px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#364d5c;fill-opacity:1"><tspan
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold'"
|
||||
id="tspan86">TDM</tspan><tspan
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:sans-serif;-inkscape-font-specification:sans-serif"
|
||||
id="tspan3845">Ripper</tspan> </tspan></text>
|
||||
</svg>
|
After Width: | Height: | Size: 3.4 KiB |
Loading…
x
Reference in New Issue
Block a user