#include #include #include #include #include "JDetector/JHydrophone.hh" #include "JSupport/JMeta.hh" #include "Jeep/JContainer.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using namespace JPP; static const std::string set_t = "set"; //!< Set position static const std::string add_t = "add"; //!< Add position static const std::string sub_t = "sub"; //!< Subtract position static const std::string rot_t = "rot"; //!< Rotate around z-axis by given value [rad] /** * Auxiliary class to apply hydrophone modifications. */ struct JModifier { /** * Apply modification to given hydrophone. * * \param hydrophone hydrophone * \return true if valid action; else false */ bool apply(JHydrophone& hydrophone) const { switch (data.size()) { case 1: return apply(hydrophone, action, data[0]); // orientation calibration case 3: return apply(hydrophone, action, JVector3D(data[0], data[1], data[2])); // 3D position calibration default: return false; } } /** * Read modifier from input. * * \param in input stream * \param modifier modifier * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JModifier& modifier) { using namespace std; if (in >> modifier.id >> modifier.action) { modifier.data.clear(); for (double x; in >> x; ) { modifier.data.push_back(x); } in.clear(ios_base::eofbit); } return in; } /** * Write modifier to output. * * \param out output stream * \param modifier modifier * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JModifier& modifier) { out << modifier.id; out << ' '; out << modifier.action; for (std::vector::const_iterator i = modifier.data.begin(); i != modifier.data.end(); ++i) { out << ' ' << *i; } return out; } int id; std::string action; std::vector data; private: /** * Apply orientation calibration to given hydrophone. * * \param hydrophone hydrophone * \param action action * \param value value * \return true if valid action; else false */ static bool apply(JHydrophone& hydrophone, const std::string& action, const double value) { if (action == rot_t) hydrophone.rotate(JRotation3Z(value)); else return false; return true; } /** * Apply position calibration to given hydrophone. * * \param hydrophone hydrophone * \param action action * \param pos pos * \return true if valid action; else false */ static bool apply(JHydrophone& hydrophone, const std::string& action, const JVector3D& pos) { if (action == set_t) hydrophone.setPosition(pos); else if (action == add_t) hydrophone.add(pos); else if (action == sub_t) hydrophone.sub(pos); else return false; return true; } }; } /** * \file * * Auxiliary program to modify hydrophone configuration. * * Syntax: *
 *     -S "         (set|add|sub) x y z"
 *     -S "         (rot) phi"
 * 
* * For option rot, * the angle phi refers to an anti-clockwise rotation around the z-axis.\n * The rotation angle is defined in radians. * * The options *
 *     -A "  x y z"
 *     -r ""
 * 
* can be used to add and remove a hydrophone, respectively. * * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; typedef JContainer< vector > container_type; string inputFile; string outputFile; vector mod; vector add; set rm; bool squash; int debug; try { JParser<> zap("Auxiliary program to modify hydrophone configuration."); zap['f'] = make_field(inputFile, "hydrophone input file"); zap['o'] = make_field(outputFile, "hydrophone output file"); zap['S'] = make_field(mod, "hydrophone modifier") = JPARSER::initialised(); zap['A'] = make_field(add, "add hydrophone") = JPARSER::initialised(); zap['r'] = make_field(rm, "remove hydrophone[s]") = JPARSER::initialised(); zap['q'] = make_field(squash, "squash meta data"); zap['d'] = make_field(debug, "debug level") = 2; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } container_type data; try { data.load(inputFile.c_str()); } catch(const exception&) {} if (squash) { data.comment.clear(); } data.comment.add(JMeta(argc, argv)); for (vector::const_iterator i = add.begin(); i != add.end(); ++i) { data.push_back(*i); } for (vector::const_iterator i = mod.begin(); i != mod.end(); ++i) { for (container_type::iterator target = data.begin(); target != data.end(); ++target) { if (target->getString() == i->id) { DEBUG("Modifier" << ' ' << "(" << FILL(4,'0') << target->getString() << "," << FILL(2,'0') << target->getFloor() << FILL() << ")" << ' ' << "action" << ' ' << i->action << JEEPZ() << i->data << endl); if (!i->apply(*target)) { ERROR("No valid action: " << *i << endl); } } } } for (set::const_iterator i = rm.begin(); i != rm.end(); ++i) { for (container_type::iterator target = data.begin(); target != data.end(); ) { if (target->getString() == *i) target = data.erase(target); else ++target; } } data.store(outputFile.c_str()); }