void testHand() { Hand h1; Card c1(1); // Normal 1 Card c2(2);// Normal 2 Card c3(3);// Normal 3 Card c4(4);// Normal 4 Card c11(11);// Normal 11 Card c12(12);// Normal 12 Card sb(13, SKIP_BO); // Skipbo h1.add(c1); assert(h1.getTopNum() == c1.getNumber()); //Checks if card was added h1.add(c3); h1.add(c2); h1.order(); assert(h1.getTopNum() == c3.getNumber()); // C3 should be at the top after it gets ordered h1.add(sb); h1.add(c12); h1.add(c11); h1.order(); assert(h1.getTopNum() == sb.getNumber()); // Skipbos always at the top h1.add(c4); assert(h1.getTopNum() == c4.getNumber()); // Added new card, out of order h1.order(); assert(h1.getTopNum() == sb.getNumber()); // Skipbos always at the top // Testing the remove function: assert(h1.remove(c4) == c4); assert(h1.remove(sb) == sb); assert(h1.remove(c11) == c11); // Adding a new card out of order h1.add(c3); h1.order(); // Removing all cards and checking if hand is fully ordered: assert(h1.getTopNum() == c12.getNumber()); assert(h1.remove(c12) == c12); assert(h1.getTopNum() == c3.getNumber()); assert(h1.remove(c3) == c3); assert(h1.getTopNum() == c3.getNumber()); // C3 remains at end because two c3 cards were added assert(h1.remove(c3) == c3); assert(h1.getTopNum() == c2.getNumber()); assert(h1.remove(c2) == c2); assert(h1.getTopNum() == c1.getNumber()); }
int read_multiplet_data(int lineno, char filename[], opt* opts, vector<string> *listname, vector<metab_template> *Tems, vector<double> *x, char chemshift[], int s, char inputdir[]) // read in metabolite multiplet data, note at present this assumes the file // is ordered in groups corresponding to different metabolites { vector<string> names(lineno);// name characters the first line matrix c1(lineno); matrix c2(lineno); matrix c3(lineno); matrix c4(lineno); matrix c5(lineno); //matrix c6(lineno); matrix c7(lineno); matrixI c8(lineno); // for ph vector<string> names2(lineno); matrix c11(lineno); matrix c12(lineno); int count = 0; double pst, ped; int nl = read_datf(&names,&c1, &c2, &c3, &c4, &c5, &c7, &c8, filename); if (nl < 0) { return nl; } if ((*opts).usechemshift == 1) { int nl2 = read_dat_chemshift(&names2, &c11,&c12, chemshift, s); if (nl2 < 0) { return nl2; } if (nl != nl2) { printf("Different number of multiplets, exiting ...\n"); system("PAUSE"); exit(1); //return -999; } for (unsigned int j = 0; j < nl2; j++) { if (!((c12[j][0]+50)<0.0000001)) { // if(names[j].compare(names2[j]) == 0 && c11[j][0] == c1[j][0]) //{ c1[j][0] = c12[j][0]; //}else{ // printf("something wrong with multi chemshift, exiting ...\n"); // system("PAUSE"); // exit(1); //} } } } char prevname[80]=" "; char name[80] = {'\0'}; char lis[80] = {'\0'}; metab_template templa("",(*x).size()); for (unsigned int i = 0; i < (*listname).size(); i++) { strcpy(lis,(*listname)[i].c_str()); for (int it = 0; it < nl; it++) { strcpy(name,names[it].c_str()); if (!strcmp(lis,name) && c8[it][0]==1) // find a match in the list { if (!strcmp(prevname, " ")&& c8[it][0]==1)//first prevname do not match prevname { metab_template templa1(name,(*x).size()); templa = templa1; } if (strcmp(prevname,name) && strcmp(prevname, " ") && c8[it][0]==1) // make a new template { metab_template templa1(name,(*x).size()); templa = templa1; } strcpy(prevname,name); for (unsigned int n2 = 0; n2<(*opts).st.size(); n2++) { if ((*opts).st[n2]>(*opts).ed[n2]) { pst = (*opts).ed[n2]; ped = (*opts).st[n2]; } else { ped = (*opts).ed[n2]; pst = (*opts).st[n2]; } if ((c5[it][0]+50)<0.0000001) { if (!((c7[it][0]+50)<0.0000001)) { if (c1[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+c7[it][0] && c1[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-c7[it][0]) { count = 1; } } else { if (c1[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+(*opts).rdelta && c1[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-(*opts).rdelta) { count = 1; } } } else { if (!((c7[it][0]+50)<0.0000001)) { if (c5[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+c7[it][0] && c5[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-c7[it][0]) { count = 1; } } else { if (c5[it][0]<ped+(15.0*(*opts).log_fwhh_prop_var)+(*opts).rdelta && c5[it][0]>pst-(15.0*(*opts).log_fwhh_prop_var)-(*opts).rdelta) { count = 1; } } } } if (count == 1) { if((c2[it][0]+1 <0.0000001) && (c2[it][0]+1 > -0.0000001)) { if (c3[it].size()!=c4[it].size()) { cout<<"\nNo. of protons do not match no. of J constant for metabolite "<<names[it]<<", exiting ...\n"; //system("PAUSE"); exit(1); } double prot=0; for(unsigned int locit=0;locit<c4[it].size();locit++) prot+=c4[it][locit]; vector<double> weights(c4[it]); for(unsigned int locit=0;locit<c4[it].size();locit++) weights[locit]/=prot; //multiplet_site ms(prot, c1[it][0]); multiplet_site ms(&c2[it], c1[it][0], &c3[it], prot, x, c5[it][0],-50, c7[it][0], opts); // vector<unsigned int> c2int(c2[it].size(),0); //vecftoi(c2[it], c2int); ms.setup_param_extra(c3[it],weights); templa.add_multiplet(ms); } else if ((c2[it][0]+2 <0.0000001) && (c2[it][0]+2 > -0.0000001)) { //multiplet_site new_mult2(&pos_vec,&nprot_vec, &x); //cout << "c2 "<<c2[it][0] << endl; vector<double> raster(0.0); double vec_el; multiplet_site ms(&c2[it], c1[it][0], &c3[it], c4[it][0], x, c5[it][0], -50, c7[it][0], opts); if (c3[it].size() == 2) { // raster //printf("find input raster\n"); raster.clear(); char fdirR[3000]={'\0'}; strcpy(fdirR,inputdir); strcat(fdirR,name); strcat(fdirR,".txt"); ifstream inA3_str(fdirR); //cout<<"route "<< fdirR<<endl; //cout<<"file is "<< inA3_str<< endl; //if (!inA3_str) //cout<<"empty, no file "<< inA3_str<< endl; //int tst = 1; int tst2 = 0; while(inA3_str.good()) { tst2 = tst2 +1; inA3_str>>vec_el; //cout<<"vec_el ppm "<<vec_el<<",tst2 " <<tst2<<endl; inA3_str.ignore(1); inA3_str.peek(); if (tst2%2 != 0) { //cout<<"tst2 " <<tst2<<endl; if(vec_el<=max(c3[it][1],c3[it][0]) && vec_el>=min(c3[it][1],c3[it][0])) { inA3_str>>vec_el; raster.push_back(vec_el); tst2 = tst2 +1; } } } /*cout<<"tst = " <<tst<<endl; cout<<"raster1 = "<< raster[0]<<"rasterE = "<<raster[raster.size()-1]<<endl; //cout << "c3 "<<c3[it].size()<<endl; //for (int ii = 0; ii <raster.size(); ii++) //cout<<"raster "<< raster[ii] << " "; FILE *outM; outM = fopen("raster.txt","w"); // wirte to file the metabolites in range for anaylsis for (unsigned int cv = 0; cv <raster.size(); cv++) { fprintf(outM, "%f",raster[cv]); if (cv <=(raster.size()-1)) { fprintf(outM, "\n"); } } fclose(outM);*/ ms.raster_setup(abs(c3[it][1]-c3[it][0]), &raster); } else { printf("Wrong ppm ranges for raster (-2) in J_constant, exiting ...\n"); system("PAUSE"); exit(1); } templa.add_multiplet(ms); } else {
int main(int argc, char* argv[]) { Polycurve_conic_traits_2 traits; //polycurve constructors Polycurve_conic_traits_2::Construct_x_monotone_curve_2 construct_x_mono_polycurve = traits.construct_x_monotone_curve_2_object(); Polycurve_conic_traits_2::Construct_curve_2 construct_polycurve = traits.construct_curve_2_object(); //create a curve Conic_curve_2 c3(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(0), Algebraic(0)), Conic_point_2(Algebraic(3), Algebraic(9))); Conic_curve_2 c4(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(3), Algebraic(9)), Conic_point_2(Algebraic(5), Algebraic(25))); Conic_curve_2 c5(0,1,0,1,0,0, CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(-25), Algebraic(-5)), Conic_point_2(Algebraic(0), Algebraic(0))); Conic_curve_2 c6(1,1,0,6,-26,162,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(-7), Algebraic(13)), Conic_point_2(Algebraic(-3), Algebraic(9))); Conic_curve_2 c7(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(-3), Algebraic(9)), Conic_point_2(Algebraic(0), Algebraic(0))); Conic_curve_2 c8(0,1,0,-1,0,0, CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(0), Algebraic(0)), Conic_point_2(Algebraic(4), Algebraic(-2))); Conic_curve_2 c9(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(-5), Algebraic(25)), Conic_point_2(Algebraic(5), Algebraic(25))); Conic_curve_2 c10(58, 72, -48, 0, 0, -360); //This vector is used to store curves that will be used to create polycurve std::vector<Conic_curve_2> conic_curves; conic_curves.push_back(c9); //construct poly-curve Polycurve_conic_traits_2::Curve_2 conic_polycurve = construct_polycurve(conic_curves.begin(), conic_curves.end()); Conic_curve_2 c11(0,1,0,-1,0,0,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(25), Algebraic(-5)), Conic_point_2(Algebraic(0), Algebraic(0))); Conic_curve_2 c12(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(0), Algebraic(0)), Conic_point_2(Algebraic(5), Algebraic(25))); conic_curves.clear(); conic_curves.push_back(c11); conic_curves.push_back(c12); //construct poly-curve Polycurve_conic_traits_2::Curve_2 conic_polycurve_2 = construct_polycurve(conic_curves.begin(), conic_curves.end()); /* VERY IMPORTANT * For efficiency reasons, we recommend users not to construct * x-monotone conic arc directly, but rather use the Make_x_monotone_2 * functor supplied by the conic-arc traits class to convert conic curves * to x-monotone curves. */ Conic_x_monotone_curve_2 xc3(c3); Conic_x_monotone_curve_2 xc4(c4); Conic_x_monotone_curve_2 xc5(c5); Conic_x_monotone_curve_2 xc6(c6); Conic_x_monotone_curve_2 xc7(c7); Conic_x_monotone_curve_2 xc8(c8); //This vector is used to store curves that will be used to create //X-monotone-polycurve std::vector<Conic_x_monotone_curve_2> xmono_conic_curves_2; xmono_conic_curves_2.push_back(xc5); xmono_conic_curves_2.push_back(xc3); xmono_conic_curves_2.push_back(xc4); //construct x-monotone poly-curve Pc_x_monotone_curve_2 conic_x_mono_polycurve_1 = construct_x_mono_polycurve(xmono_conic_curves_2.begin(), xmono_conic_curves_2.end()); xmono_conic_curves_2.clear(); xmono_conic_curves_2.push_back(xc6); xmono_conic_curves_2.push_back(xc7); xmono_conic_curves_2.push_back(xc8); //construct x-monotone poly-curve Pc_x_monotone_curve_2 conic_x_mono_polycurve_2 = construct_x_mono_polycurve(xmono_conic_curves_2.begin(), xmono_conic_curves_2.end()); xmono_conic_curves_2.clear(); xmono_conic_curves_2.push_back(xc5); Pc_x_monotone_curve_2 x_polycurve_push = construct_x_mono_polycurve(xmono_conic_curves_2.begin(), xmono_conic_curves_2.end()); Polycurve_conic_traits_2::X_monotone_subcurve_2 xcurve_push = Polycurve_conic_traits_2::X_monotone_subcurve_2(c5); //traits.construct_x_monotone_curve_2_object()(c5); xmono_conic_curves_2.clear(); xmono_conic_curves_2.push_back(xc3); xmono_conic_curves_2.push_back(xc4); Pc_x_monotone_curve_2 base_curve = construct_x_mono_polycurve(xmono_conic_curves_2.begin(), xmono_conic_curves_2.end()); //curves for push_back Conic_curve_2 c13(1,1,0,-50,12,660,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(25), Algebraic(-7)), Conic_point_2(Algebraic(25), Algebraic(-5))); Conic_curve_2 c14(0,1,0,-1,0,0,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(25), Algebraic(-5)), Conic_point_2(Algebraic(0), Algebraic(0))); Conic_curve_2 c15(-1,0,0,0,1,0,CGAL::COUNTERCLOCKWISE, Conic_point_2(Algebraic(0), Algebraic(0)), Conic_point_2(Algebraic(5), Algebraic(25))); conic_curves.clear(); conic_curves.push_back(c13); conic_curves.push_back(c14); Polycurve_conic_traits_2::Curve_2 base_curve_push_back = construct_polycurve(conic_curves.begin(), conic_curves.end()); conic_curves.push_back(c15); Polycurve_conic_traits_2::Curve_2 Expected_push_back_result = construct_polycurve(conic_curves.begin(), conic_curves.end()); // //checking the orientattion consistency // Conic_curve_2 c21(0,1,0,1,0,0,CGAL::CLOCKWISE, // Conic_point_2(Algebraic(9), Algebraic(-3)), // Conic_point_2(Algebraic(0), Algebraic(0))); // Conic_curve_2 c20(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE, // Conic_point_2(Algebraic(0), Algebraic(0)), // Conic_point_2(Algebraic(3), Algebraic(9))); // Conic_x_monotone_curve_2 xc20(c20); // Conic_x_monotone_curve_2 xc21(c21); // xmono_conic_curves_2.clear(); // xmono_conic_curves_2.push_back(xc20); // xmono_conic_curves_2.push_back(xc21); // Pc_x_monotone_curve_2 eric_polycurve = // construct_x_mono_polycurve(xmono_conic_curves_2.begin(), // xmono_conic_curves_2.end()); // std::cout << "the polycurve is: " << eric_polycurve << std::endl; // std::cout<< std::endl; //check_compare_x_2(xc3, xc5); // check_equal(); // std::cout<< std::endl; //check_intersect(conic_x_mono_polycurve_1, conic_x_mono_polycurve_2); //std::cout<< std::endl; // check_compare_end_points_xy_2(); // std::cout<< std::endl; //check_split(conic_x_mono_polycurve_1, conic_x_mono_polycurve_2); // std::cout<< std::endl; //check_make_x_monotne_curve(conic_polycurve_2); //std::cout<< std::endl; // check_is_vertical(); // std::cout<< std::endl; //check_compare_y_at_x_2(); //std::cout<< std::endl; //adds the segment to the right. //check_push_back(base_curve_push_back, c15); //std::cout<< std::endl; //adds the segment to the left. //check_push_front(base_curve, xcurve_push); //std::cout<< std::endl; // check_are_mergable(); // std::cout<< std::endl; // check_merge_2(); // std::cout<< std::endl; // check_construct_opposite(); // std::cout<< std::endl; // check_compare_y_at_x_right(); // std::cout<< std::endl; // check_compare_y_at_x_left(); // std::cout<< std::endl; //check_compare_points(conic_x_mono_polycurve_1); //number of segments //std::cout << "Number of segments: " // << traits.number_of_points_2_object()(base_curve_push_back) // << std::endl; check_trim(conic_x_mono_polycurve_1, atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), atoi(argv[4])); std::cout << std::endl; //std::cout << (atoi(argv[1]) + atoi(argv[2])) << std::endl; // Conic_traits_2 con_traits; // Conic_curve_2 cc3(1,0,0,0,-1,0,CGAL::COUNTERCLOCKWISE, // Conic_point_2(Algebraic(0), Algebraic(0)), // Conic_point_2(Algebraic(3), Algebraic(9))); // Conic_x_monotone_curve_2 xcc3(cc3); // Conic_point_2 ps2(0, 0); // Conic_point_2 pt2(3, 9); // std::cout << "conic curve is : " << xcc3 << std::endl; // Conic_x_monotone_curve_2 trimmed_curve = // con_traits.trim_2_object()(xc3, ps2, pt2); // std::cout << "trimmed conic curve is : " << trimmed_curve << std::endl; return 0; }