#include "TreeRefineC.h" #include "CipresHelper.h" #include "CipresRegistry.h" #include "orbsvcs/CosNamingC.h" #include #include using namespace std; /* If first arg is "-ns" uses naming service. Next arg is the name of the object we want (eg. "TreeRefine") Subsequent args identify the Naming Service: eg. -ORBInitRef NameService=corbaloc:iiop:10.0.1.5:1050/NameService Otherwise first arg is an ior file name. */ int main(int argc, char *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "orb1"); if (argc < 2) { cerr << "usage: " << argv[0] << " iorFileName" << endl; return 1; } CORBA::Object_var object; if (strcmp(argv[1], "-ns") == 0) { // todo: check for right number of arguments before accessing argv CipresRegistry registry(orb.in()); object = registry.nsFind(argv[2]); } else { fstream f(argv[1], ios::in); CORBA::String_var iorstring; f >> iorstring; cout << "ior is: " << iorstring << endl; object = orb->string_to_object(iorstring); } if (CORBA::is_nil(object.in())) { cerr << "Nil object ref" << endl; throw 0; } CipresIDL_api1::TreeRefine_var tr_var = CipresIDL_api1::TreeRefine::_narrow(object.in()); if (CORBA::is_nil(tr_var.in())) { cerr << "Object ref is not of type TreeImprove" << endl; throw 0; } CipresIDL_api1::DataMatrix chars; chars.m_symbols= "ACGT"; chars.m_numStates = 4; chars.m_stride = 1; chars.m_numCharacters = 4; chars.m_matrix.length(4); chars.m_matrix[0].length(3); chars.m_matrix[0][0] = 1; chars.m_matrix[0][1] = 2; chars.m_matrix[0][2] = 3; chars.m_matrix[1].length(3); chars.m_matrix[1][0] = 3; chars.m_matrix[1][1] = 2; chars.m_matrix[1][2] = 1; chars.m_matrix[2].length(3); chars.m_matrix[2][0] = 3; chars.m_matrix[2][1] = 3; chars.m_matrix[2][2] = 3; chars.m_matrix[3].length(3); chars.m_matrix[3][0] = 3; chars.m_matrix[3][1] = 3; chars.m_matrix[3][2] = 1; cout << "setting matrix:" << endl; cout << chars << endl; cout << "calling setMatrix" << endl; tr_var->setMatrix(chars); CipresIDL_api1::Tree tree; tree.m_score = 0; // paup requires a semicolon at the end of the newick string tree.m_newick = CORBA::string_dup("((1,2,3),4);"); tree.m_leafSet.length(4); for (int i = 0; i < 4; i++) { tree.m_leafSet[i] = i + 1; } cout << "calling setTree: " << tree.m_newick << endl; tr_var->setTree(tree); cout << "calling refineTree" << endl; CipresIDL_api1::Tree_var resultTree = tr_var->refineTree(); cout << "got tree: " << resultTree->m_newick << endl; orb->destroy(); } catch(CORBA::Exception &ex) { cerr << "CORBA Exception raised: " << ex << endl; return 1; } return 0; }