00001
00010
00011 #include "dyn.h"
00012
00013 #ifndef TOOLBOX
00014
00015 void compute_com(dyn *b, vector& pos, vector& vel)
00016 {
00017 real total_mass = 0;
00018
00019 pos = 0;
00020 vel = 0;
00021
00022
00023 for_all_daughters(dyn, b, d) {
00024 total_mass += d->get_mass();
00025 pos += d->get_mass() * d->get_pos();
00026 vel += d->get_mass() * d->get_vel();
00027 }
00028
00029 pos /= total_mass;
00030 vel /= total_mass;
00031
00032 putrq(b->get_dyn_story(), "com_time", b->get_system_time());
00033 putvq(b->get_dyn_story(), "com_pos", pos);
00034 putvq(b->get_dyn_story(), "com_vel", vel);
00035 }
00036
00037 void compute_com(dyn *b)
00038 {
00039 vector pos, vel;
00040 compute_com(b, pos, vel);
00041 }
00042
00043 #else
00044
00045
00046
00047
00048
00049 main(int argc, char ** argv)
00050 {
00051 char *comment;
00052 dyn * b;
00053 bool c_flag = FALSE;
00054
00055 check_help();
00056
00057 extern char *poptarg;
00058 int c;
00059 char* param_string = "c:";
00060
00061 while ((c = pgetopt(argc, argv, param_string)) != -1)
00062 switch(c) {
00063
00064 case 'c': c_flag = TRUE;
00065 comment = poptarg;
00066 break;
00067 case '?': params_to_usage(cerr, argv[0], param_string);
00068 get_help();
00069 exit(1);
00070 }
00071
00072 if ((b = get_dyn(cin)) == NULL)
00073 err_exit("compute_com: No N-body system on standard input");
00074
00075 while (b) {
00076
00077 if (c_flag == TRUE)
00078 b->log_comment(comment);
00079 b->log_history(argc, argv);
00080
00081 compute_com(b);
00082
00083
00084
00085 put_dyn(cout, *b);
00086 rmtree(b);
00087 b = get_dyn(cin);
00088 }
00089 }
00090
00091 #endif
00092
00093