// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include #include "../reader/JFJochHDF5Reader.h" #include "../common/print_license.h" #include "../common/Logger.h" void print_usage(Logger &logger) { logger.Info("Usage ./jfjoch_extract_hkl {} "); logger.Info("Options:"); logger.Info(" -I Number of images"); logger.Info(" -o Output filename"); logger.Info(" -x Max dist from Ewald sphere"); } int main(int argc, char **argv) { int64_t image_number = 0; float max_dist_ewald_sphere = 1.0; std::string output_filename = "out.hkl"; print_license("jfjoch_extract_hkl"); Logger logger("jfjoch_extract_hkl"); logger.Verbose(true); int opt; while ((opt = getopt(argc, argv, "I:x:o:")) != -1) { switch (opt) { case 'I': image_number = atol(optarg); break; case 'x': max_dist_ewald_sphere = atof(optarg); break; case 'o': output_filename = optarg; break; default: /* '?' */ print_usage(logger); exit(EXIT_FAILURE); } } if (optind != argc - 1) { print_usage(logger); exit(EXIT_FAILURE); } JFJochHDF5Reader reader; reader.ReadFile(argv[optind]); auto dataset = reader.LoadImage(image_number); if (dataset) { auto geom = dataset->Dataset().experiment.GetDiffractionGeometry(); std::fstream f(output_filename, std::ios::out); if (dataset->ImageData().indexing_lattice) { auto latt = dataset->ImageData().indexing_lattice.value(); Coord astar = latt.Astar(); Coord bstar = latt.Bstar(); Coord cstar = latt.Cstar(); auto uc = latt.GetUnitCell(); logger.Info("Cell {} {} {} {} {} {}",uc.a, uc.b, uc.c, uc.alpha, uc.beta, uc.gamma); logger.Info("A {} {} {}", astar.x, astar.y, astar.z); logger.Info("B {} {} {}", bstar.x, bstar.y, bstar.z); logger.Info("C {} {} {}", cstar.x, cstar.y, cstar.z); logger.Info("{} reflections identified", dataset->ImageData().reflections.size()); for (const auto &r: dataset->ImageData().reflections) { auto recip = astar * r.h + bstar * r.k + cstar * r.l; auto dist = geom.DistFromEwaldSphere(recip); if (dist < max_dist_ewald_sphere) f << r.l << " " << r.k << " " << r.h << " " << r.I << " " << r.sigma << " " << dist << std::endl; } } } }