Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

get_std_center.C

Go to the documentation of this file.
00001 
00017 
00018 #include "dyn.h"
00019 
00020 #ifndef TOOLBOX
00021 
00022 int get_std_center(dyn *b, vector& pos, vector& vel,
00023                    bool verbose)                        // default = false
00024 {
00025     int which = 0;
00026 
00027     // See if densities are available and up to date.
00028 
00029     if (find_qmatch(b->get_dyn_story(), "density_center_pos")) {
00030 
00031         if (getrq(b->get_dyn_story(), "density_center_time")
00032                 != b->get_system_time()) {
00033 
00034             if (verbose)
00035               warning("get_std_center: ignoring out-of-date density center");
00036 
00037         } else {
00038 
00039             // Assume that density_center_vel exists if density_center_pos
00040             // is OK.
00041 
00042             pos = getvq(b->get_dyn_story(), "density_center_pos");
00043             vel = getvq(b->get_dyn_story(), "density_center_vel");
00044 
00045             which = 1;
00046         }
00047     }
00048 
00049     if (which == 0) {
00050 
00051         if (find_qmatch(b->get_dyn_story(), "mcom_pos")) {
00052 
00053             // Try modified center of mass instead.
00054 
00055             if (getrq(b->get_dyn_story(), "mcom_time")
00056                     != b->get_system_time()) {
00057 
00058                 if (verbose)
00059                     warning("get_std_center: ignoring out-of-date mcom");
00060 
00061             } else {
00062 
00063                 pos = getvq(b->get_dyn_story(), "mcom_pos");
00064                 vel = getvq(b->get_dyn_story(), "mcom_vel");
00065 
00066                 which = 2;
00067             }
00068 
00069         }
00070 
00071         if (which == 0) {
00072 
00073             // Compute the modified center of mass.
00074 
00075             compute_mcom(b, pos, vel);
00076             which = 2;
00077         }
00078     }
00079 
00080     putrq(b->get_dyn_story(), "std_center_time", b->get_system_time());
00081     putvq(b->get_dyn_story(), "std_center_pos", pos);
00082     putvq(b->get_dyn_story(), "std_center_vel", vel);
00083 
00084     return which;
00085 }
00086 
00087 int get_std_center(dyn *b,
00088                    bool verbose)                // default = false
00089 {
00090     vector pos, vel;
00091     return get_std_center(b, pos, vel, verbose);
00092 }
00093 
00094 #else
00095 
00096 //-----------------------------------------------------------------------------
00097 //  main  --  driver to use get_std_center() as a tool
00098 //-----------------------------------------------------------------------------
00099 
00100 main(int argc, char ** argv)
00101 {
00102     char  *comment;
00103     dyn * b;
00104     bool  c_flag = FALSE;       // if TRUE: a comment given on command line
00105 
00106     check_help();
00107 
00108     extern char *poptarg;
00109     int c;
00110     char* param_string = "c:";
00111 
00112     while ((c = pgetopt(argc, argv, param_string)) != -1)
00113         switch(c) {
00114 
00115             case 'c': c_flag = TRUE;
00116                       comment = poptarg;
00117                       break;
00118             case '?': params_to_usage(cerr, argv[0], param_string);
00119                       get_help();
00120                       exit(1);
00121         }            
00122 
00123     if ((b = get_dyn(cin)) == NULL)
00124        err_exit("compute_com: No N-body system on standard input");
00125 
00126     while (b) {
00127 
00128         if (c_flag == TRUE)
00129             b->log_comment(comment);
00130         b->log_history(argc, argv);
00131 
00132         get_std_center(b, true);
00133 
00134         // Write system to stdout and get next system (if any).
00135 
00136         put_dyn(cout, *b);
00137         rmtree(b);
00138         b = get_dyn(cin);
00139     }
00140 }
00141 
00142 #endif
00143 
00144 // endof: get_std_center.C

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