1041 {
1042 options opts;
1043
1044 if (!parse_arguments(argc, argv, opts)) {
1045
1046 std::cout << R"(
1047 ____ ____ __ __ ____ _ _ __ __ ____
1048 | _ \ / ___| \/ | | _ \| | | | \/ | _ \
1049 | | | | | | |\/| | | | | | | | | |\/| | |_) |
1050 | |_| | |___| | | | | |_| | |_| | | | | __/
1051 |____/ \____|_| |_| |____/ \___/|_| |_|_|
1052
1053 DICOM File Inspection Utility
1054)" << "\n";
1055 print_usage(argv[0]);
1056 return 1;
1057 }
1058
1059
1060 if (!std::filesystem::exists(opts.path)) {
1061 std::cerr << "Error: Path does not exist: " << opts.path.string()
1062 << "\n";
1063 return 2;
1064 }
1065
1066
1067 if (!opts.quiet && opts.format == output_format::human_readable) {
1068 std::cout << R"(
1069 ____ ____ __ __ ____ _ _ __ __ ____
1070 | _ \ / ___| \/ | | _ \| | | | \/ | _ \
1071 | | | | | | |\/| | | | | | | | | |\/| | |_) |
1072 | |_| | |___| | | | | |_| | |_| | | | | __/
1073 |____/ \____|_| |_| |____/ \___/|_| |_|_|
1074
1075 DICOM File Inspection Utility
1076)" << "\n";
1077 }
1078
1079
1080 if (std::filesystem::is_directory(opts.path)) {
1081 if (opts.summary) {
1082 if (!opts.quiet) {
1083 std::cout << "Scanning directory: " << opts.path.string() << "\n";
1084 if (opts.recursive) {
1085 std::cout << "Mode: Recursive\n";
1086 }
1087 std::cout << "\n";
1088 }
1089
1091 scan_directory(opts.path, opts, summary);
1092 if (!opts.quiet) {
1093 print_summary(summary, opts);
1094 }
1095 return summary.invalid_files > 0 ? 1 : 0;
1096 } else {
1097
1098 int exit_code = 0;
1099 auto process = [&](const std::filesystem::path& file_path) {
1100 auto ext = file_path.extension().string();
1101 std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
1102 if (ext == ".dcm" || ext == ".dicom" || ext.empty()) {
1103 if (dump_file(file_path, opts) != 0) {
1104 exit_code = 1;
1105 }
1106 std::cout << "\n";
1107 }
1108 };
1109
1110 if (opts.recursive) {
1111 for (const auto& entry :
1112 std::filesystem::recursive_directory_iterator(opts.path)) {
1113 if (entry.is_regular_file()) {
1114 process(entry.path());
1115 }
1116 }
@ summary
Statistical summary (min, max, mean, percentiles)