void print_trace(std::ostream & out_stream) { // First try a GDB backtrace. They are better than what you get // from calling backtrace() because you don't have to do any // demangling, and they include line numbers! If the GDB backtrace // fails, for example if your system does not have GDB, fall back to // calling backtrace(). bool gdb_worked = false; // Let the user disable GDB backtraces by configuring with // --without-gdb-command or with a command line option. if (std::string(LIBMESH_GDB_COMMAND) != std::string("no") && !libMesh::on_command_line("--no-gdb-backtrace")) gdb_worked = gdb_backtrace(out_stream); // This part requires that your compiler at least supports // backtraces. Demangling is also nice, but it will still run // without it. #if defined(LIBMESH_HAVE_GLIBC_BACKTRACE) if (!gdb_worked) { void * addresses[40]; char ** strings; int size = backtrace(addresses, 40); strings = backtrace_symbols(addresses, size); out_stream << "Stack frames: " << size << std::endl; for(int i = 0; i < size; i++) out_stream << i << ": " << process_trace(strings[i]) << std::endl; std::free(strings); } #endif }
void print_trace(std::ostream &out) { void *addresses[40]; char **strings; int size = backtrace(addresses, 40); strings = backtrace_symbols(addresses, size); out << "Stack frames: " << size << std::endl; for(int i = 0; i < size; i++) out << i << ": " << process_trace(strings[i]) << std::endl; std::free(strings); }
int main(int argc, char *argv[]) { void* itr_buf; void* otr_buf; Trace* itrace; Trace* otrace; rtf99 itr_rtf99, otr_rtf99; Shade5 itr_shade5, otr_shade5; Shade6x32 itr_shade6x32, otr_shade6x32; Shade6x64 itr_shade6x64, otr_shade6x64; Master itr_master, otr_master; RSTF_Union itr_rstf_union, otr_rstf_union; init_globals(argv); parse_args(argc, argv); // make input trace buffer itr_buf = calloc(BUFFER_SIZE, gbl.fromsize); if (itr_buf == NULL) { fprintf(stderr, "Could not allocate memory for itr_buf[] in main().\n"); exit(2); } // make output trace buffer, if conversion specified if (gbl.totype != NONE) { otr_buf = calloc(BUFFER_SIZE, gbl.tosize); if (otr_buf == NULL) { fprintf(stderr, "Could not allocate memory for otr_buf[] in main().\n"); exit(2); } } switch (gbl.fromtype) { case RTF99: itrace = &itr_rtf99; break; case SHADE5: itrace = &itr_shade5; break; case SHADE6x32: itrace = &itr_shade6x32; break; case SHADE6x64: itrace = &itr_shade6x64; break; case MASTER64: itrace = &itr_master; break; case RST: itrace = &itr_rstf_union; break; case NONE: usage(argv[0]); exit(1); default: fprintf(stderr, switch_error_string, "fromtype", "main()", gbl.fromtype); exit(2); } switch (gbl.totype) { case RTF99: otrace = &otr_rtf99; break; case SHADE5: otrace = &otr_shade5; break; case SHADE6x32: otrace = &otr_shade6x32; break; case SHADE6x64: otrace = &otr_shade6x64; break; case MASTER64: otrace = &otr_master; break; case RST: otrace = &otr_rstf_union; break; case NONE: otrace = NULL; break; default: fprintf(stderr, switch_error_string, "totype", "main()", gbl.totype); exit(2); } process_trace(itrace, otrace, itr_buf, otr_buf); return 0; } // main()
ref<data::Plot> RayFan::get_plot(enum rayfan_plot_type_e x, enum rayfan_plot_type_e y) { ref<data::Plot> plot = GOPTICAL_REFNEW(data::Plot); plot->get_axes().set_position(math::vector3_0); // select X axis evaluation function get_value_t get_x_value; bool single_x_reference = true; switch (x) { case EntranceHeight: get_x_value = &RayFan::get_entrance_height; plot->get_axes().set_range(math::range_t(-1.0, 1.0), io::RendererAxes::X); plot->get_axes().set_tics_step(1.0, io::RendererAxes::X); break; case EntranceAngle: get_x_value = &RayFan::get_entrance_angle; break; case ImageAngle: get_x_value = &RayFan::get_image_angle; break; case ExitAngle: get_x_value = &RayFan::get_exit_angle; break; default: throw Error("bad value type for X plot axis"); } // select Y axis evaluation function get_value_t get_y_value; bool single_y_reference = true; switch (y) { case EntranceHeight: get_y_value = &RayFan::get_entrance_height; break; case EntranceAngle: get_y_value = &RayFan::get_entrance_angle; break; case TransverseDistance: get_y_value = &RayFan::get_transverse_distance; break; case LongitudinalDistance: get_y_value = &RayFan::get_longitudinal_distance; break; case OpticalPathDiff: get_y_value = &RayFan::get_optical_path_len; single_y_reference = false; break; case ImageAngle: get_y_value = &RayFan::get_image_angle; break; case ExitAngle: get_y_value = &RayFan::get_exit_angle; break; default: throw Error("bad value type for Y plot axis"); } // process ray tracing process_trace(); trace::Result &result = _tracer.get_trace_result(); const trace::rays_queue_t &intercepts = result.get_intercepted(*_exit); if (intercepts.empty() || result.get_ray_wavelen_set().empty()) throw Error("no raytracing data available for analysis"); bool first = true; double x_ref = 0.0, y_ref = 0.0; // extract data for each wavelen for(auto& w : result.get_ray_wavelen_set()) { const trace::Ray & chief_ray = find_chief_ray(intercepts, w); // get chief ray reference values if (!single_x_reference || first) try { x_ref = (this->*get_x_value)(chief_ray, chief_ray); } catch (...) { x_ref = 0.0; // no valid data for chief ray } if (!single_y_reference || first) try { y_ref = (this->*get_y_value)(chief_ray, chief_ray); } catch (...) { y_ref = 0.0; // no valid data for chief ray } first = false; // extract data for each ray ref<data::DiscreteSet> s = GOPTICAL_REFNEW(data::DiscreteSet); s->set_interpolation(data::Cubic); for(auto& i : intercepts) { trace::Ray & ray = *i; if (ray.get_wavelen() != w) continue; double x_val, y_val; try { x_val = (this->*get_x_value)(ray, chief_ray) - x_ref; y_val = (this->*get_y_value)(ray, chief_ray) - y_ref; } catch (...) { // no valid data for this ray continue; } // add data to plot s->add_data(x_val, y_val); } if (!s->get_count()) continue; data::Plotdata p(*s); p.set_color(light::SpectralLine::get_wavelen_color(w)); plot->add_plot_data(p); } static const struct { const char *label; const char *unit; bool prefix; int pow10; } axis[] = { { "Entrance ray height (normalized)", "", false }, { "Entrance ray angle", "degree", false }, { "Transverse ray aberration", "m", true, -3 }, { "Longitudinal ray aberration", "m", true, -3 }, { "Image ray angle", "degree", false }, { "Exit ray angle", "degree", false }, { "Optical path difference", "waves", false } }; plot->set_title(axis[y].label + std::string(" fan (") + (_dist_plane == SagittalAberration ? "sagittal)" : "tangential)")); plot->get_axes().set_label(axis[x].label, io::RendererAxes::X); plot->get_axes().set_label(axis[y].label, io::RendererAxes::Y); plot->get_axes().set_unit(axis[x].unit, true, axis[x].prefix, axis[x].pow10, io::RendererAxes::X); plot->get_axes().set_unit(axis[y].unit, true, axis[y].prefix, axis[y].pow10, io::RendererAxes::Y); plot->set_style(data::InterpolatePlot); return plot; }