Skip to content

Commit

Permalink
add support for negative indexing of measurement numbers (#83)
Browse files Browse the repository at this point in the history
* add support for negative indexing of measurement numbers

For example, the argument '-z -1' is now a shortcut for the last
element of the multiMeasFile.

* increment minor version number
  • Loading branch information
pehses authored Feb 21, 2022
1 parent d7e46c3 commit b34196b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ message(STATUS "Looking for packages in : ${CMAKE_PREFIX_PATH}")

#VERSIONING
set(SIEMENS_TO_ISMRMRD_VERSION_MAJOR 1)
set(SIEMENS_TO_ISMRMRD_VERSION_MINOR 1)
set(SIEMENS_TO_ISMRMRD_VERSION_MINOR 2)
set(SIEMENS_TO_ISMRMRD_VERSION_PATCH 0)
set(SIEMENS_TO_ISMRMRD_VERSION_STRING ${SIEMENS_TO_ISMRMRD_VERSION_MAJOR}.${SIEMENS_TO_ISMRMRD_VERSION_MINOR}.${SIEMENS_TO_ISMRMRD_VERSION_PATCH})

Expand Down
26 changes: 20 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ std::string ws2s(const std::wstring &wstr) {

int main(int argc, char* argv[]) {
std::string siemens_dat_filename;
unsigned int measurement_number;
int measurement_number;

std::string parammap_file;
std::string parammap_xsl;
Expand Down Expand Up @@ -464,7 +464,7 @@ int main(int argc, char* argv[]) {
("help,h", "Produce HELP message")
("version,v", "Prints converter version and ISMRMRD version")
("file,f", po::value<std::string>(&siemens_dat_filename), "<SIEMENS dat file>")
("measNum,z", po::value<unsigned int>(&measurement_number)->default_value(1), "<Measurement number>")
("measNum,z", po::value<int>(&measurement_number)->default_value(1), "<Measurement number (with negative indexing)>")
("allMeas,Z", po::value<bool>(&all_measurements)->implicit_value(true), "<All measurements flag>")
("multiMeasFile,M", po::value<bool>(&multi_meas_file)->implicit_value(true), "<Multiple measurements in single output file flag>")
("skipSyncData", po::value<bool>(&skip_syncdata)->implicit_value(true), "<Skip syncdata (PMU) conversion>")
Expand Down Expand Up @@ -571,8 +571,8 @@ int main(int argc, char* argv[]) {
return 0;
}

if (measurement_number < 1) {
std::cerr << "The measurement number must be a positive integer" << std::endl;
if (measurement_number == 0) {
std::cerr << "The measurement number must not be zero (count starts at 1)" << std::endl;
std::cerr << display_options << "\n";
return -1;
}
Expand Down Expand Up @@ -629,6 +629,20 @@ int main(int argc, char* argv[]) {
return -1;
}

if (measurement_number < 0) {
// negative indexing support ('-1' returns the last measurement)
if (-measurement_number > ParcRaidHead.count_)
{
std::cout << "The file you are trying to convert has only " << ParcRaidHead.count_ << " measurements."
<< std::endl;
std::cout << "Using negative indexing, you are trying to convert measurement number: " << measurement_number
<< std::endl;
return -1;
}

measurement_number = ParcRaidHead.count_ + measurement_number + 1;
}

// Loop through all measurements in multi-raid
std::string ismrmrd_file_orig = ismrmrd_file;
std::string ismrmrd_group_orig = ismrmrd_group;
Expand All @@ -638,8 +652,8 @@ int main(int argc, char* argv[]) {
{
firstMeas = 1;
lastMeas = ParcRaidHead.count_;
}
else
}
else
{
firstMeas = measurement_number;
lastMeas = measurement_number;
Expand Down

0 comments on commit b34196b

Please sign in to comment.