Skip to content

Commit

Permalink
ENH: Add -q option to only search directory for DICOMs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ningfei committed Dec 18, 2022
1 parent 4762234 commit a82cf42
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
18 changes: 15 additions & 3 deletions console/main_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void showHelp(const char *argv[], struct TDCMopts opts) {
printf(" -n : only convert this series CRC number - can be used up to %i times (default convert all)\n", MAX_NUM_SERIES);
printf(" -o : output directory (omit to save to input folder)\n");
printf(" -p : Philips precise float (not display) scaling (y/n, default y)\n");
printf(" -q : only search directory for DICOMs (y/l/n, default y) [y=show number of DICOMs found, l=additionally list DICOMs found, n=no]\n");
printf(" -r : rename instead of convert DICOMs (y/n, default n)\n");
printf(" -s : single file mode, do not convert other images in folder (y/n, default n)\n");
//text notes replaced with BIDS: this function is deprecated
Expand Down Expand Up @@ -178,7 +179,7 @@ void showHelp(const char *argv[], struct TDCMopts opts) {
} //showHelp()

int invalidParam(int i, const char *argv[]) {
if (strchr("yYnNoOhHiIjJBb01234",argv[i][0]))
if (strchr("yYnNoOhHiIjlLJBb01234",argv[i][0]))
return 0;

//if (argv[i][0] != '-') return 0;
Expand Down Expand Up @@ -471,6 +472,14 @@ int main(int argc, const char *argv[]) {
return 0;
if ((argv[i][0] == 'y') || (argv[i][0] == 'Y'))
opts.isRenameNotConvert = true;
} else if ((argv[i][1] == 'q') && ((i + 1) < argc)) {
i++;
if (invalidParam(i, argv))
return 0;
if ((argv[i][0] == 'y') || (argv[i][0] == 'Y'))
opts.onlySearchDirForDICOM = 1;
else if ((argv[i][0] == 'l') || (argv[i][0] == 'L'))
opts.onlySearchDirForDICOM = 2;
} else if ((argv[i][1] == 's') && ((i + 1) < argc)) {
i++;
if (invalidParam(i, argv))
Expand Down Expand Up @@ -624,11 +633,14 @@ int main(int argc, const char *argv[]) {
if (ret != EXIT_SUCCESS)
return ret;
}

if (opts.onlySearchDirForDICOM == 0) {
#if !defined(_WIN64) && !defined(_WIN32)
printf("Conversion required %f seconds (%f for core code).\n", get_wall_time() - startWall, ((float)(clock() - start)) / CLOCKS_PER_SEC);
printf("Conversion required %f seconds (%f for core code).\n", get_wall_time() - startWall, ((float)(clock() - start)) / CLOCKS_PER_SEC);
#else
printf("Conversion required %f seconds.\n", ((float)(clock() - start)) / CLOCKS_PER_SEC);
printf("Conversion required %f seconds.\n", ((float)(clock() - start)) / CLOCKS_PER_SEC);
#endif
}
//if (isSaveIni) //we now save defaults earlier, in case of early termination.
// saveIniFile(opts);
return EXIT_SUCCESS;
Expand Down
9 changes: 8 additions & 1 deletion console/nii_dicom_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8238,6 +8238,12 @@ int nii_loadDirCore(char *indir, struct TDCMopts *opts) {
}
size_t nDcm = nameList.numItems;
printMessage("Found %lu DICOM file(s)\n", nameList.numItems); //includes images and other non-image DICOMs
if (opts->onlySearchDirForDICOM == 2) {
printMessage("List of DICOM file(s):\n");
for (int i = 0; i < nameList.numItems; i++)
printMessage("%s\n", nameList.str[i]);
printMessage("End of list (%lu in total)\n", nameList.numItems);
}
#ifdef myTimer
if (opts->isProgress > 1)
printMessage("Stage 1 (Count number of DICOMs) required %f seconds.\n", ((float)(clock() - start)) / CLOCKS_PER_SEC);
Expand Down Expand Up @@ -8294,7 +8300,7 @@ int nii_loadDirCore(char *indir, struct TDCMopts *opts) {
printMessage("Stage 2 (Read DICOM headers, Convert 4D) required %f seconds.\n", ((float)(clock() - start)) / CLOCKS_PER_SEC);
start = clock();
#endif
if (opts->isRenameNotConvert) {
if ((opts->isRenameNotConvert) || (opts->onlySearchDirForDICOM != 0)) {
free(dcmList);
free(dti4D);
return EXIT_SUCCESS;
Expand Down Expand Up @@ -8852,6 +8858,7 @@ void setDefaultOpts(struct TDCMopts *opts, const char *argv[]) { //either "setDe
opts->isPipedGz = false; //e.g. pipe data directly to pigz instead of saving uncompressed to disk
opts->isSave3D = false;
opts->dirSearchDepth = 5;
opts->onlySearchDirForDICOM = 0;
opts->isProgress = 0;
opts->nameConflictBehavior = kNAME_CONFLICT_ADD_SUFFIX;
#ifdef myDisableZLib
Expand Down
2 changes: 1 addition & 1 deletion console/nii_dicom_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void nii_clrMrifsStruct();

struct TDCMopts {
bool isIgnoreTriggerTimes, isTestx0021x105E, isAddNamePostFixes, isSaveNativeEndian, isOneDirAtATime, isRenameNotConvert, isSave3D, isGz, isPipedGz, isFlipY, isCreateBIDS, isSortDTIbyBVal, isAnonymizeBIDS, isOnlyBIDS, isCreateText, isForceOnsetTimes,isIgnoreDerivedAnd2D, isPhilipsFloatNotDisplayScaling, isTiltCorrect, isRGBplanar, isOnlySingleFile, isForceStackDCE, isIgnoreSeriesInstanceUID, isRotate3DAcq, isCrop;
int saveFormat, isMaximize16BitRange, isForceStackSameSeries, nameConflictBehavior, isVerbose, isProgress, compressFlag, dirSearchDepth, gzLevel, diffCyclingModeGE; //support for compressed data 0=none,
int saveFormat, isMaximize16BitRange, isForceStackSameSeries, nameConflictBehavior, isVerbose, isProgress, compressFlag, dirSearchDepth, onlySearchDirForDICOM, gzLevel, diffCyclingModeGE; //support for compressed data 0=none,
char filename[512], outdir[512], indir[512], pigzname[512], optsname[512], indirParent[512], imageComments[24];
double seriesNumber[MAX_NUM_SERIES]; //requires double must store -1 (report but do not convert) as well as seriesUidCrc (uint32)
long numSeries;
Expand Down

0 comments on commit a82cf42

Please sign in to comment.