Skip to content

Commit

Permalink
Return EXIT_FAILURE if ANY files fail to convert
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Aug 18, 2017
1 parent 43c70f0 commit efeddd8
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions console/nii_dicom_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2359,16 +2359,15 @@ int convert_parRec(struct TDCMopts opts) {
dcmList[0] = nii_readParRec(nameList.str[0], opts.isVerbose, &dti4D);
struct TDCMsort dcmSort[1];
dcmSort[0].indx = 0;
saveDcm2Nii(1, dcmSort, dcmList, &nameList, opts, &dti4D);
int ret = saveDcm2Nii(1, dcmSort, dcmList, &nameList, opts, &dti4D);
free(dcmList);//if (nConvertTotal == 0)
if (nameList.numItems < 1)
printMessage("No valid PAR/REC files were found\n");
if (nameList.numItems > 0)
for (int i = 0; i < nameList.numItems; i++)
free(nameList.str[i]);
free(nameList.str);

return EXIT_SUCCESS;
return ret;
}// convert_parRec()

void freeNameList(struct TSearchList nameList) {
Expand Down Expand Up @@ -2459,15 +2458,19 @@ int nii_loadDir(struct TDCMopts* opts) {
struct TDTI4D dti4D;
int nConvertTotal = 0;
bool compressionWarning = false;
bool convertError = false;
for (int i = 0; i < nDcm; i++ ) {
dcmList[i] = readDICOMv(nameList.str[i], opts->isVerbose, opts->compressFlag, &dti4D); //ignore compile warning - memory only freed on first of 2 passes
if ((dcmList[i].isValid) &&((dcmList[i].patientPositionNumPhilips > 1) || (dcmList[i].CSA.numDti > 1))) { //4D dataset: dti4D arrays require huge amounts of RAM - write this immediately
struct TDCMsort dcmSort[1];
dcmSort[0].indx = i;
dcmSort[0].img = ((uint64_t)dcmList[i].seriesNum << 32) + dcmList[i].imageNum;
dcmList[i].converted2NII = 1;
saveDcm2Nii(1, dcmSort, dcmList, &nameList, *opts, &dti4D);
nConvertTotal++;
int ret = saveDcm2Nii(1, dcmSort, dcmList, &nameList, *opts, &dti4D);
if (ret == EXIT_SUCCESS)
nConvertTotal++;
else
convertError = true;
}
if ((dcmList[i].compressionScheme != kCompressNone) && (!compressionWarning) && (opts->compressFlag != kCompressNone)) {
compressionWarning = true; //generate once per conversion rather than once per image
Expand Down Expand Up @@ -2502,7 +2505,6 @@ int nii_loadDir(struct TDCMopts* opts) {
opts->series.push_back(nextSeries);
}
}

// To avoid a spurious warning below
nConvertTotal = nDcm;
} else {
Expand Down Expand Up @@ -2534,8 +2536,11 @@ int nii_loadDir(struct TDCMopts* opts) {
nConvert = removeDuplicatesVerbose(nConvert, dcmSort, &nameList);
else
nConvert = removeDuplicates(nConvert, dcmSort);
nConvertTotal += nConvert;
saveDcm2Nii(nConvert, dcmSort, dcmList, &nameList, *opts, &dti4D);
int ret = saveDcm2Nii(nConvert, dcmSort, dcmList, &nameList, *opts, &dti4D);
if (ret == EXIT_SUCCESS)
nConvertTotal += nConvert;
else
convertError = true;
free(dcmSort);
}//convert all images of this series
}
Expand All @@ -2544,6 +2549,8 @@ int nii_loadDir(struct TDCMopts* opts) {
#endif
free(dcmList);
freeNameList(nameList);
if (convertError)
return EXIT_FAILURE; //at least one image failed to convert
if (nConvertTotal == 0) {
printMessage("No valid DICOM files were found\n");
return kEXIT_NO_VALID_FILES_FOUND;
Expand Down

0 comments on commit efeddd8

Please sign in to comment.