int plotGridImg(signed int * grids, unsigned int t, int X, int Y, signed burnPropAge) { // gnuplot has a "with image" option... int myX, myY; Gnuplot g1=Gnuplot(); // g1.cmd("set xrange[0 : %d]", X+1); g1.cmd("set yrange[0 : %d]", Y+1); g1.cmd("plot '-' with image"); // int imax = (X+2)*(Y+2); int treeAge; int i = 0; while (i < imax) { //printf("starting i: %d\n", i); //if (int(i/20)==float(i)/20) yodapause(); myY = i/(X+2); myX = i-myY*(X+2); //myVal = *(grids + i); treeAge=getGridStatus(*(grids+i), t); if (treeAge==0) treeAge=0; if (treeAge>=burnPropAge) treeAge=8; if (treeAge>0 and treeAge < burnPropAge) treeAge=4; if (treeAge<0 and treeAge>-burnPropAge) treeAge=12; if (treeAge<= -burnPropAge) treeAge=16; if (i<(int(xmax)+2)) treeAge=int(i/16); // this to get some pallet normalization... g1.cmd("%d,\t%d,\t%d", myX, myY, treeAge); i++; }; g1.cmd("e"); yodapause(); return 0; };
int plotGrid(signed int * grids, int X, int Y) { printf("we'll plot the grid here..."); // yodapause(); //std::string strArray(""); //std::string strNewRow(""); int myX, myY, myVal; Gnuplot g1=Gnuplot(); // // note: grids[x][y] (maybe we should just make our own 1d array) is like: grids->[x=0][{y}],[x=1][{y}],etc. // so we have to transpose this. get the 1st of every row, the second of every row, etc. //g1.cmd("plot '-' using 1:2 with points 8 "); // g1.cmd("set multiplot"); g1.cmd("set xrange[0 : %d]", X+1); g1.cmd("set yrange[0 : %d]", Y+1); g1.cmd("plot '-' with points 4, '-' with points 7"); //g1.cmd("3 4"); //g1.cmd("e"); //g1.cmd("plot '-' with points 4"); int imax = (X+2)*(Y+2); int i = 0; while (i < imax) { //printf("starting i: %d\n", i); //if (int(i/20)==float(i)/20) yodapause(); myY = i/(X+2); myX = i-myY*(X+2); myVal = *(grids + i); // printf("thisX, thisY, thisVal: (%d, %d, %d)\n", thisX, thisY, thisVal); // yodacode::yodapause(); if (myVal >= 1) { //printf("(%i) thisX, thisY, thisVal: (%d, %d, %d)\n", i, myX, myY, myVal); //if (int(i/20)==float(i)/20) yodapause(); g1.cmd("%d %d", myX, myY); //g1.cmd("%s %s", yodacode::intToStr(thisX).c_str(), yodacode::intToStr(thisY).c_str()); }; i++; }; g1.cmd("e"); // yodapause(); // //printf("now plot fires?\n"); i = 0; //g1.cmd("plot '-' using 1:2 with linespoints 0 "); while (i < imax) { myY = i/(X+2); myX = i-myY*(X+2); myVal = *(grids + i); if (myVal==-1) { g1.cmd("%d %d", myX, myY); }; i++; }; g1.cmd("e"); yodacode::yodapause(); return 0; };
int plotGridSimple(signed int * grids, unsigned int t, int X, int Y) { //printf("we'll plot the grid here..."); // yodapause(); //std::string strArray(""); //std::string strNewRow(""); int myX, myY, treeAge; Gnuplot g1=Gnuplot(); // g1.cmd("set xrange[0 : %d]", X+1); g1.cmd("set yrange[0 : %d]", Y+1); //g1.cmd("plot '-' title 'young' with points 3, '-' title 'older' with points, '-' title 'young-burn' with points 7, '-' title 'old-burn' with points 9"); g1.cmd("plot '-' title 'trees' with points 3, '-' title 'burn' with points 9"); //g1.cmd("3 4"); //g1.cmd("e"); //g1.cmd("plot '-' with points 4"); int imax = (X+2)*(Y+2); int i = 0; while (i < imax) { myY = i/(X+2); myX = i-myY*(X+2); treeAge=0; //treeAge = getGridStatus(*(grids+i), t); g1.cmd("0,\t0"); treeAge = *(grids+i); if (treeAge > 0) { //if (treeAge > burnAge and treeAge < burnPropAge) { g1.cmd("%d,\t%d", myX, myY); }; i++; }; g1.cmd("e"); // i = 0; while (i < imax) { myY = i/(X+2); myX = i-myY*(X+2); treeAge=0; g1.cmd("0,\t0"); treeAge = *(grids+i); if (treeAge < 0) { //if (treeAge > burnAge and treeAge < burnPropAge) { g1.cmd("%d,\t%d", myX, myY); }; i++; }; g1.cmd("e"); // yodapause(); return 0; };
int plotGrid(signed int * grids, unsigned int t, int X, int Y, signed burnPropAge) { //printf("we'll plot the grid here..."); // yodapause(); //std::string strArray(""); //std::string strNewRow(""); int myX, myY, treeAge; Gnuplot g1=Gnuplot(); // // note: grids[x][y] (maybe we should just make our own 1d array) is like: grids->[x=0][{y}],[x=1][{y}],etc. // so we have to transpose this. get the 1st of every row, the second of every row, etc. //g1.cmd("plot '-' using 1:2 with points 8 "); // g1.cmd("set multiplot"); g1.cmd("set xrange[0 : %d]", X+1); g1.cmd("set yrange[0 : %d]", Y+1); //g1.cmd("plot '-' title 'young' with points 3, '-' title 'older' with points, '-' title 'young-burn' with points 7, '-' title 'old-burn' with points 9"); g1.cmd("plot '-' title 'young' with points 3, '-' title 'older' with points, '-' title 'young-burn' with points 7, '-' title 'old-burn' with points 9, '-' title 'rocks' with points"); //g1.cmd("3 4"); //g1.cmd("e"); //g1.cmd("plot '-' with points 4"); int imax = (X+2)*(Y+2); int i = 0; while (i < imax) { myY = i/(X+2); myX = i-myY*(X+2); treeAge=0; //treeAge = getGridStatus(*(grids+i), t); g1.cmd("0,\t0"); treeAge = *(grids+i); if (treeAge > 0 and treeAge < burnPropAge) { //if (treeAge > burnAge and treeAge < burnPropAge) { g1.cmd("%d,\t%d", myX, myY); }; i++; }; g1.cmd("e"); // i = 0; while (i < imax) { myY = i/(X+2); myX = i-myY*(X+2); treeAge=0; //treeAge = getGridStatus(*(grids+i), t); g1.cmd("0,\t0"); treeAge = *(grids+i); if (treeAge >= burnPropAge and treeAge<rockAge) { g1.cmd("%d,\t%d", myX, myY); }; i++; }; g1.cmd("e"); // //// Burning Fires: i = 0; while (i < imax) { myY = i/(X+2); myX = i-myY*(X+2); treeAge=0; g1.cmd("0,\t0"); //treeAge = getGridStatus(*(grids+i), t); treeAge = *(grids+i); if (treeAge<=-1 and treeAge>-burnPropAge) { g1.cmd("%d,\t%d", myX, myY); }; i++; }; g1.cmd("e"); i = 0; // while (i < imax) { myY = i/(X+2); myX = i-myY*(X+2); treeAge=0; g1.cmd("0,\t0"); //treeAge = getGridStatus(*(grids+i), t); treeAge = *(grids+i); if (treeAge <= -burnPropAge) { g1.cmd("%d,\t%d", myX, myY); }; i++; }; g1.cmd("e"); // // Rocks: i = 0; while (i < imax) { myY = i/(X+2); myX = i-myY*(X+2); treeAge=0; g1.cmd("0,\t0"); //treeAge = getGridStatus(*(grids+i), t); treeAge = *(grids+i); if (treeAge >= rockAge) { g1.cmd("%d,\t%d", myX, myY); }; i++; }; g1.cmd("e"); // yodapause(); return 0; };
int TestMHD(int argc, char *argv[]) { real cfl = 0.2; real tmax = 0.1; bool writemsh = false; real vmax = 6.0; bool usegpu = false; real dt = 0.0; for (;;) { int cc = getopt(argc, argv, "c:t:w:D:P:g:s:"); if (cc == -1) break; switch (cc) { case 0: break; case 'c': cfl = atof(optarg); break; case 'g': usegpu = atoi(optarg); break; case 't': tmax = atof(optarg); break; case 'w': writemsh = true; break; case 'D': ndevice_cl= atoi(optarg); break; case 'P': nplatform_cl = atoi(optarg); break; default: printf("Error: invalid option.\n"); printf("Usage:\n"); printf("./testmanyv -c <cfl> -d <deg> -n <nraf> -t <tmax> -C\n -P <cl platform number> -D <cl device number> FIXME"); exit(1); } } bool test = true; field f; init_empty_field(&f); f.varindex = GenericVarindex; f.model.m = 9; f.model.cfl = cfl; strcpy(f.model.name,"MHD"); f.model.NumFlux=MHDNumFluxP2; f.model.BoundaryFlux=MHDBoundaryFlux; f.model.InitData=MHDInitData; f.model.ImposedData=MHDImposedData; char buf[1000]; sprintf(buf, "-D _M=%d", f.model.m); strcat(cl_buildoptions, buf); sprintf(numflux_cl_name, "%s", "MHDNumFluxP2"); sprintf(buf," -D NUMFLUX="); strcat(buf, numflux_cl_name); strcat(cl_buildoptions, buf); sprintf(buf, " -D BOUNDARYFLUX=%s", "MHDBoundaryFlux"); strcat(cl_buildoptions, buf); // Set the global parameters for the Vlasov equation f.interp.interp_param[0] = f.model.m; // _M f.interp.interp_param[1] = 1; // x direction degree f.interp.interp_param[2] = 1; // y direction degree f.interp.interp_param[3] = 0; // z direction degree f.interp.interp_param[4] = 10; // x direction refinement f.interp.interp_param[5] = 10; // y direction refinement f.interp.interp_param[6] = 1; // z direction refinement //set_vlasov_params(&(f.model)); // Read the gmsh file //ReadMacroMesh(&(f.macromesh), "test/testcartesiangrid2d2.msh"); ReadMacroMesh(&(f.macromesh), "test/testOTgrid.msh"); //ReadMacroMesh(&(f.macromesh), "test/testcube.msh"); // Try to detect a 2d mesh Detect2DMacroMesh(&(f.macromesh)); bool is2d=f.macromesh.is2d; assert(is2d); f.macromesh.period[0]=6.2831853; f.macromesh.period[1]=6.2831853; // Mesh preparation BuildConnectivity(&(f.macromesh)); // Prepare the initial fields Initfield(&f); // Prudence... CheckMacroMesh(&(f.macromesh), f.interp.interp_param + 1); Plotfield(0, (1==0), &f, "Rho", "dginit.msh"); f.vmax=vmax; real executiontime; if(usegpu) { printf("Using OpenCL:\n"); //executiontime = seconds(); //assert(1==2); RK2(&f, tmax, dt); //executiontime = seconds() - executiontime; } else { printf("Using C:\n"); //executiontime = seconds(); RK2(&f, tmax, dt); //executiontime = seconds() - executiontime; } Plotfield(0,false,&f, "Rho", "dgvisu.msh"); Gnuplot(&f,0,0.0,"data1D.dat"); printf("tmax: %f, cfl: %f\n", tmax, f.model.cfl); printf("deltax:\n"); printf("%f\n", f.hmin); printf("deltat:\n"); printf("%f\n", dt); printf("DOF:\n"); printf("%d\n", f.wsize); printf("executiontime (s):\n"); printf("%f\n", executiontime); printf("time per RK2 (s):\n"); printf("%f\n", executiontime / (real)f.itermax); return test; }
static int main(int argc, char *argv[]) { const string DEFAULT_TITLE = "Sequence Coverage Plot"; const string DEFAULT_X_LABEL = "X"; const string DEFAULT_Y_LABEL = "Y"; const int32_t DEFAULT_X_MAX = 1000; const int32_t DEFAULT_Y_MAX = 1000; const uint32_t DEFAULT_FASTA_INDEX = 0; path sect_file; string output_type; path output; string title; string x_label; string y_label; uint16_t width; uint16_t height; uint32_t x_max; uint32_t y_max; bool y_logscale; uint32_t fasta_index; string fasta_header; bool verbose; bool help; // Declare the supported options. po::options_description generic_options(PlotProfile::helpMessage(), 100); generic_options.add_options() ("output_type,p", po::value<string>(&output_type)->default_value("png"), "The plot file type to create: png, ps, pdf. Warning... if pdf is selected please ensure your gnuplot installation can export pdf files.") ("output,o", po::value<path>(&output), "The path to the output file") ("title,t", po::value<string>(&title)->default_value(DEFAULT_TITLE), "Title for plot") ("x_label,a", po::value<string>(&x_label)->default_value(DEFAULT_X_LABEL), "Label for the x-axis (value taken from matrix metadata if present)") ("y_label,b", po::value<string>(&y_label)->default_value(DEFAULT_Y_LABEL), "Label for the y-axis (value taken from matrix metadata if present)") ("x_max,x", po::value<uint32_t>(&x_max)->default_value(DEFAULT_X_MAX), "Maximum value for the x-axis (value taken from matrix metadata if present)") ("y_max,y", po::value<uint32_t>(&y_max)->default_value(DEFAULT_Y_MAX), "Maximum value for the y-axis (value taken from matrix metadata if present)") ("width,w", po::value<uint16_t>(&width)->default_value(1024), "Width of canvas") ("height,h", po::value<uint16_t>(&height)->default_value(1024), "Height of canvas") ("index,n", po::value<uint32_t>(&fasta_index)->default_value(DEFAULT_FASTA_INDEX), "Index of fasta entry to plot. First entry is 1.") ("header,d", po::value<string>(&fasta_header), "Fasta header of fasta entry to plot. NOTE: \'--header\' has priority over index") ("y_logscale,m", po::bool_switch(&y_logscale)->default_value(false), "Y-axis is logscale. This overrides the y_min and y_max limits.") ("verbose,v", po::bool_switch(&verbose)->default_value(false), "Print extra information.") ("help", po::bool_switch(&help)->default_value(false), "Produce help message.") ; // Hidden options, will be allowed both on command line and // in config file, but will not be shown to the user. po::options_description hidden_options("Hidden options"); hidden_options.add_options() ("sect_file,s", po::value<path>(§_file), "Path to the sect profile file to plot.") ; // Positional option for the input bam file po::positional_options_description p; p.add("sect_file", 1); // Combine non-positional options po::options_description cmdline_options; cmdline_options.add(generic_options).add(hidden_options); // Parse command line po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm); po::notify(vm); // Output help information the exit if requested if (help || argc <= 1) { cout << generic_options << endl; return 1; } // Check input file exists if (!bfs::exists(sect_file) && !bfs::symbolic_link_exists(sect_file)) { cerr << endl << "Could not find matrix file at: " << sect_file << "; please check the path and try again." << endl << endl; return 1; } string header; string coverages; if (!fasta_header.empty()) { header.assign(fasta_header); getEntryFromFasta(sect_file, header, coverages); } else if (fasta_index > 0) { getEntryFromFasta(sect_file, fasta_index, header, coverages); } if (coverages.length() == 0) { cerr << "Could not find requested fasta header in sect coverages fasta file" << endl; } else { if (verbose) cerr << "Found requested sequence : " << header << endl << coverages << endl << endl; // Split coverages vector<uint32_t> cvs = kat::splitUInt32(coverages, ' '); uint32_t maxCvgVal = y_max != DEFAULT_Y_MAX ? y_max : (*(std::max_element(cvs.begin(), cvs.end())) + 1); string t = autoTitle(title, header); if (verbose) cerr << "Acquired K-mer counts" << endl; // Initialise gnuplot Gnuplot profile_plot = Gnuplot("lines"); profile_plot.configurePlot(output_type, output.string(), width, height); profile_plot.set_title(t); profile_plot.set_xlabel(x_label); profile_plot.set_ylabel(y_label); profile_plot.set_xrange(0, cvs.size()); profile_plot.set_yrange(0, maxCvgVal); profile_plot.cmd("set style data linespoints"); std::ostringstream data_str; for(uint32_t i = 0; i < cvs.size(); i++) { uint32_t index = i+1; double val = y_logscale ? (double)std::log(cvs[i]) : (double)cvs[i]; data_str << index << " " << val << "\n"; } std::ostringstream plot_str; plot_str << "plot '-'\n" << data_str.str() << "e\n"; profile_plot.cmd(plot_str.str()); if (verbose) cerr << "Plotted data: " << plot_str.str() << endl; } return 0; }