#include "readcon-core.hpp"
#include <iostream>
#include <vector>
void print_frame_details(int frame_number, const readcon::ConFrame &frame) {
std::cout << "\n==================== FRAME " << frame_number
<< " ====================\n";
auto pre_headers = frame.prebox_header();
std::cout << "Pre-box Header 1: \"" << pre_headers[0] << "\"\n";
std::cout << "Pre-box Header 2: \"" << pre_headers[1] << "\"\n";
auto cell = frame.cell();
auto angles = frame.angles();
std::cout << "Cell Dimensions: " << cell[0] << ", " << cell[1] << ", "
<< cell[2] << std::endl;
std::cout << "Cell Angles: " << angles[0] << ", " << angles[1] << ", "
<< angles[2] << std::endl;
auto post_headers = frame.postbox_header();
std::cout << "Post-box Header 1:\"" << post_headers[0] << "\"\n";
std::cout << "Post-box Header 2:\"" << post_headers[1] << "\"\n";
std::cout << "Has Velocities: " << std::boolalpha << frame.has_velocities()
<< std::endl;
auto atoms = frame.atoms(); std::cout << "--- Atoms (" << atoms.size() << ") ---\n";
int atoms_to_print = 0;
for (const auto &atom : atoms) {
if (atoms_to_print >= 5) {
std::cout << "... and " << atoms.size() - 5 << " more."
<< std::endl;
break;
}
const auto fixed = atom.fixed_mask();
std::cout << " ID: " << atom.atom_id << ", Z: " << atom.atomic_number
<< ", Pos: (" << atom.x << ", " << atom.y << ", " << atom.z
<< ")"
<< ", Fixed: (" << fixed[0] << ", " << fixed[1] << ", "
<< fixed[2] << ")";
if (auto v = atom.velocity()) {
std::cout << ", Vel: (" << (*v)[0] << ", " << (*v)[1] << ", "
<< (*v)[2] << ")";
}
std::cout << std::endl;
atoms_to_print++;
}
}
int main(int argc, char *argv[]) {
if (argc < 2 || argc > 3) {
std::cerr << "Usage: " << argv[0] << " <input.con> [output.con]"
<< std::endl;
return 1;
}
std::string input_filename = argv[1];
try {
if (argc == 2) {
std::cout << "Mode: Read-only. Iterating lazily through frames in: "
<< input_filename << std::endl;
readcon::ConFrameIterator frame_iterator(input_filename);
int frame_count = 0;
for (const auto &frame : frame_iterator) {
frame_count++;
print_frame_details(frame_count, frame);
}
std::cout
<< "\n==================================================\n";
std::cout << "Iteration complete. Total frames processed: "
<< frame_count << std::endl;
}
else { std::string output_filename = argv[2];
std::cout << "Mode: Read-Write. Reading from '" << input_filename
<< "' and writing to '" << output_filename << "'."
<< std::endl;
readcon::ConFrameIterator frame_iterator(input_filename);
std::vector<readcon::ConFrame> all_frames;
for (auto &&frame : frame_iterator) {
all_frames.push_back(std::move(frame));
}
if (all_frames.empty()) {
std::cout << "No valid frames found to write." << std::endl;
} else {
print_frame_details(all_frames.size(), all_frames.back());
std::cout << "\nWriting " << all_frames.size()
<< " frames...\n";
readcon::ConFrameWriter writer(output_filename);
writer.extend(all_frames);
std::cout << "Successfully wrote all frames." << std::endl;
}
}
} catch (const std::exception &e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}