Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

hdyn_pp3.C

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00015 
00016 // Externally visible functions:
00017 //
00018 //      void pp3_maximal
00019 //      void pp3
00020 //      void pp3_minimal
00021 //      void pp3_tree
00022 
00023 #include "hdyn.h"
00024 
00025 #ifndef TOOLBOX
00026 
00027 //========================================================================
00028 //
00029 // Helper functions:
00030 
00031 #define MAX_INDENT      10
00032 #define PP3_PRECISION   16
00033 
00034 local bool pp3_check(hdyn* b)
00035 {
00036     if (!b) return false;
00037     if (!b->is_valid()) return false;
00038 
00039     return true;
00040 }
00041 
00042 local void skip(int n, ostream & s)
00043 {
00044     for (int i = 0; i < n; i++) s << " ";
00045 }
00046 
00047 local void print_node(char* label, hdyn * b, ostream & s)
00048 {
00049     skip(MAX_INDENT, s); s << " \t" << label;
00050 
00051     if (b) {
00052 
00053         s << "(" << b << ")";
00054         if (b->is_valid())
00055             s << "  " << b->format_label();
00056         else
00057             s << "  invalid.";
00058 
00059     } else
00060 
00061         s << "(NULL)";
00062 
00063     s << endl;
00064 }
00065 
00066 local void print_id_and_time(hdyn * b, ostream & s, int level)
00067 {
00068     char *string = b->format_label();
00069     int len = strlen(string);
00070 
00071     skip(2*level, s); s << string;
00072 
00073     skip(MAX_INDENT - len - 2*level, s);
00074     s << " \taddr: " << b << "  system_time: " << b->get_system_time() << endl;
00075 
00076 #ifdef USE_XREAL
00077     skip(MAX_INDENT, s);
00078     s << " \txreal system_time = "; xprint(b->get_system_time(), s);
00079 #endif
00080 
00081     skip(MAX_INDENT, s); s << " \tt: " << b->get_time()
00082                                        << "  dt: " << b->get_timestep();
00083     if (b->get_kepler() || b->get_unperturbed_timestep() > 0)
00084         s << "  dt_u: " << b->get_unperturbed_timestep();
00085     s << endl;
00086 
00087 #ifdef USE_XREAL
00088     skip(MAX_INDENT, s);
00089     s << " \txreal time = "; xprint(b->get_time(), s);
00090 #endif
00091 
00092 }
00093 
00094 local void print_pos_and_vel(hdyn * b, ostream & s, bool print_abs = false)
00095 {
00096     skip(MAX_INDENT, s); s << " \tm: " << b->get_mass()
00097                            << "  |x|: " << abs(b->get_pos())
00098                            << endl;
00099 
00100     skip(MAX_INDENT, s); s << " \tx: " << b->get_pos()  << endl;
00101     if (print_abs && b->is_low_level_node()) {
00102         skip(MAX_INDENT, s);
00103         s << " \tX: "
00104           << hdyn_something_relative_to_root(b, &hdyn::get_pos)
00105           << endl;
00106     }
00107 
00108     skip(MAX_INDENT, s); s << " \tv: " << b->get_vel()  << endl;
00109     if (print_abs && b->is_low_level_node()) {
00110         skip(MAX_INDENT, s);
00111         s << " \tV: "
00112           << hdyn_something_relative_to_root(b, &hdyn::get_vel)
00113           << endl;
00114     }
00115 }
00116 
00117 //========================================================================
00118 //
00119 // Functions to print out information on a single node:
00120 
00121 local void print_tree(hdyn * b, ostream & s, int level)
00122 {
00123     if (!pp3_check(b)) return;
00124 
00125     print_node("parent:          ", b->get_parent(), s);
00126     print_node("elder_sister:    ", b->get_elder_sister(), s);
00127     print_node("younger_sister:  ", b->get_younger_sister(), s);
00128     print_node("oldest_daughter: ", b->get_oldest_daughter(), s);
00129 }
00130 
00131 local void print_minimal(hdyn * b, ostream & s, int level)
00132 {
00133     if (!pp3_check(b)) return;
00134 
00135     // ID, address, times:
00136 
00137     print_id_and_time(b, s, level);
00138 
00139     // mass, pos, vel:
00140 
00141     print_pos_and_vel(b, s);
00142 
00143     // neighbor information:
00144 
00145     skip(MAX_INDENT, s); s << " \tnn: "; print_nn(b, 0, s);
00146     if (b->get_nn()) s << "  (" << sqrt(abs(b->get_d_nn_sq())) << ")";
00147     s << endl;
00148 }
00149 
00150 local void print_maximal(hdyn * b, ostream & s, int level)
00151 {
00152     // Print out vital information in compact but readable form.
00153 
00154     if (!pp3_check(b)) return;
00155 
00156     //------------------------------------------------------------
00157     //
00158     // ID, address, times:
00159 
00160     print_id_and_time(b, s, level);
00161 
00162     //------------------------------------------------------------
00163     //
00164     // mass, pos, vel, acc, jerk:
00165 
00166     print_pos_and_vel(b, s, true);
00167 
00168     skip(MAX_INDENT, s); s << " \ta: " << b->get_acc()  << endl;
00169     skip(MAX_INDENT, s); s << " \tj: " << b->get_jerk() << endl;
00170     skip(MAX_INDENT, s); s << " \tk: " << 18*b->get_k_over_18() << endl;
00171 
00172     if (b->is_root()) {
00173         s << endl;
00174         return;
00175     }
00176 
00177     //------------------------------------------------------------
00178     //
00179     // nn, kepler, binary properties:
00180 
00181     skip(MAX_INDENT, s); s << " \tnn: "; print_nn(b, 0, s);
00182     if (b->get_nn()) s << "  (" << sqrt(abs(b->get_d_nn_sq())) << ")";
00183     if (b->is_low_level_node()) s << "  kep: " << b->get_kepler();
00184     s << endl;
00185 
00186     // Print binary properties only for elder binary component.
00187 
00188     if (b->is_low_level_node() && b->get_elder_sister() == NULL) {
00189 
00190         // Don't touch b's kepler structure, even if one exists.
00191 
00192         kepler k;
00193         initialize_kepler_from_dyn_pair(k, b, b->get_younger_sister(),
00194                                         true);          // minimal kepler
00195 
00196         int prec = s.precision(INT_PRECISION);
00197         skip(MAX_INDENT, s); s << " \tsma: " << k.get_semi_major_axis()
00198                                << "  ecc: "  << k.get_eccentricity()
00199                                << "  P: "    << k.get_period()
00200                                << endl;
00201 
00202         s.precision(prec);
00203     }
00204 
00205     //------------------------------------------------------------
00206     //
00207     // Perturbation:
00208 
00209     // Print perturber info only for elder binary component.
00210 
00211     if (!b->is_top_level_leaf()) {
00212         if (b->is_low_level_node() && b->get_elder_sister() == NULL) {
00213             skip(MAX_INDENT, s);
00214             if (b->get_perturbation_squared() >= 0
00215                 && b->get_perturbation_squared() < VERY_LARGE_NUMBER)
00216                 s << " \tpert_sq: " << b->get_perturbation_squared() << endl;
00217             else
00218                 s << " \tpert_sq: unknown" << endl;
00219         }
00220 
00221         char pre[MAX_INDENT+3];
00222         for (int i = 0; i <= MAX_INDENT; i++) pre[i] = ' ';
00223         pre[MAX_INDENT+1] = '\t';
00224         pre[MAX_INDENT+2] = '\0';
00225 
00226         if (!b->is_leaf())
00227             b->print_perturber_list(s, pre);
00228         if (b->is_low_level_node() && b->get_elder_sister() == NULL)
00229             b->find_print_perturber_list(s, pre);
00230     }
00231 
00232     //------------------------------------------------------------
00233 
00234     s << endl;
00235 }
00236 
00237 //========================================================================
00238 //
00239 // Externally visible functions:
00240 
00241 void pp3_maximal(hdyn * b,                              // maximal, recursive
00242                  ostream & s,   // default = cerr
00243                  int level)     // default = 0          // -1 ==> no recursion
00244 {
00245     if (!pp3_check(b)) return;
00246 
00247     if (b->is_root() && level >= 0) {
00248         s << endl << "Static data:" << endl << endl;
00249         b->print_static(s);
00250     }
00251 
00252     int p = s.precision(PP3_PRECISION);
00253     print_maximal(b, s, level);
00254     s.precision(p);
00255     print_tree(b, s, level);
00256 
00257     if (level >= 0) {
00258         for_all_daughters(hdyn, b, daughter)
00259             pp3_maximal(daughter, s, level + 1);
00260     }
00261 }
00262 
00263 void pp3(hdyn * b,                                      // standard, recursive
00264          ostream & s,   // default = cerr
00265          int level)     // default = 0                  // -1 ==> no recursion
00266 {
00267     if (!pp3_check(b)) return;
00268 
00269     if (b->is_root() && level >= 0) {
00270         s << endl << "Static data:" << endl << endl;
00271         b->print_static(s);
00272     }
00273 
00274     int p = s.precision(PP3_PRECISION);
00275     print_maximal(b, s, level);
00276     s.precision(p);
00277 
00278     if (level >= 0) {
00279         for_all_daughters(hdyn, b, daughter)
00280             pp3(daughter, s, level + 1);
00281     }
00282 }
00283 
00284 void pp3_minimal(hdyn * b,                              // minimal, recursive
00285                  ostream & s,   // default = cerr
00286                  int level)     // default = 0          // -1 ==> no recursion
00287 {
00288     if (!pp3_check(b)) return;
00289 
00290     int p = s.precision(PP3_PRECISION);
00291     print_minimal(b, s, level);
00292     s.precision(p);
00293 
00294     if (level >= 0) {
00295         for_all_daughters(hdyn, b, daughter)
00296             pp3_minimal(daughter, s, level + 1);
00297     }
00298 }
00299 
00300 void pp3_tree(hdyn * b,                                 // data+links, recursive
00301               ostream & s,      // default = cerr
00302               int level)        // default = 0          // -1 ==> no recursion
00303 {
00304     if (!pp3_check(b)) return;
00305 
00306     int p = s.precision(PP3_PRECISION);
00307     print_minimal(b, s, level);
00308     print_tree(b, s, level);
00309     s.precision(p);
00310 
00311     if (level >= 0) {
00312         for_all_daughters(hdyn, b, daughter)
00313             pp3_tree(daughter, s, level + 1);
00314     }
00315 }
00316 
00317 #else
00318 
00319 main(int argc, char ** argv)
00320 {
00321     check_help();
00322 
00323     extern char *poptarg;
00324     int c;
00325     char* param_string = "c:";
00326 
00327     while ((c = pgetopt(argc, argv, param_string)) != -1)
00328         switch(c) {
00329 
00330             case '?': params_to_usage(cerr, argv[0], param_string);
00331                       get_help();
00332                       exit(1);
00333         }
00334 
00335     hdyn *b;
00336 
00337     while (b = get_hdyn(cin)) {
00338         pp3_tree(b);
00339         delete b;
00340     }
00341 }
00342 
00343 #endif

Generated at Sun Feb 24 09:57:03 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001