// Exercise 4
//
// Read an F and phase from an MTZ file

#include <iostream>
#include <vector>
#include <clipper/clipper.h>
#include <clipper/clipper-ccp4.h>

int main(int argc, char** argv)
{
  // Check the input arguments to acquire a filename
  if ( argc != 2 ) {
    std::cout << "Error no filename specified\n";
    exit(1);
  }

  // Acquire filename from first argument
  clipper::String hklin(argv[1]);
  std::cout << "Filename: " << hklin << "\n";

  // Read in the MTZ file
  clipper::CCP4MTZfile mtz;
  mtz.open_read(hklin);
  clipper::HKL_info hkls;
  clipper::HKL_data<clipper::data32::F_phi> fphidata(hkls);
  // Read only spacegroup. resolution, hkls
  mtz.import_hkl_info(hkls);
  // Acquire the column labels in the file
  std::vector<clipper::String> flabels = mtz.column_paths();
  // Read in the FCAL and PHICAL columns
  mtz.import_hkl_data(fphidata, "/*/*/[FCAL,PHICAL]");
  // Finish the read
  mtz.close_read();
  // Write out the labels from the file
  std::cout << "List of column labels in " << hklin << ":\n";
  for (int i = 0; i < flabels.size(); i++) {
    std::cout << "\t" << flabels[i] << "\n";
  }
}
