00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "dyn.h"
00028
00029 #ifndef TOOLBOX
00030
00031
00032
00033
00034
00035
00036 #define MAX_COUNT 5
00037
00038 void compute_max_cod(dyn *b, vector& pos, vector& vel)
00039 {
00040 real max_density = 0;
00041 bool print_message = true;
00042 int count = 0;
00043
00044 pos = 0;
00045 vel = 0;
00046
00047
00048 for_all_daughters(dyn, b, d) {
00049
00050 real dens_time = getrq(d->get_dyn_story(), "density_time");
00051
00052 if (dens_time != b->get_system_time() && print_message) {
00053 warning("compute_max_cod: using out-of-date densities.");
00054 PRC(d->format_label()), PRL(dens_time);
00055 if (++count > MAX_COUNT) print_message = false;
00056 }
00057
00058 real this_density = getrq(d->get_dyn_story(), "density");
00059
00060 if (this_density > 0) {
00061 if (max_density < this_density) {
00062 max_density = this_density;
00063 pos = d->get_pos();
00064 vel = d->get_vel();
00065 }
00066 } else if (this_density <= -VERY_LARGE_NUMBER) {
00067 warning("compute_max_cod: density not set.");
00068 PRL(d->format_label());
00069 if (++count > MAX_COUNT) print_message = false;
00070 }
00071 }
00072
00073 putsq(b->get_dyn_story(), "density_center_type", "max");
00074 putrq(b->get_dyn_story(), "density_center_time", b->get_system_time());
00075 putvq(b->get_dyn_story(), "density_center_pos", pos);
00076 putvq(b->get_dyn_story(), "density_center_vel", vel);
00077 }
00078
00079 void compute_max_cod(dyn *b)
00080 {
00081 vector pos, vel;
00082 compute_max_cod(b, pos, vel);
00083 }
00084
00085 #else
00086
00087
00088
00089
00090
00091 main(int argc, char ** argv)
00092 {
00093 char *comment;
00094 dyn * b;
00095 bool c_flag = FALSE;
00096
00097 check_help();
00098
00099 extern char *poptarg;
00100 int c;
00101 char* param_string = "c:";
00102
00103 while ((c = pgetopt(argc, argv, param_string)) != -1)
00104 switch(c) {
00105
00106 case 'c': c_flag = TRUE;
00107 comment = poptarg;
00108 break;
00109 case '?': params_to_usage(cerr, argv[0], param_string);
00110 get_help();
00111 exit(1);
00112 }
00113
00114 if ((b = get_dyn(cin)) == NULL)
00115 err_exit("compute_max_cod: No N-body system on standard input");
00116
00117 while (b) {
00118
00119 if (c_flag == TRUE)
00120 b->log_comment(comment);
00121 b->log_history(argc, argv);
00122
00123 compute_max_cod(b);
00124
00125 put_dyn(cout, *b);
00126 rmtree(b);
00127 b = get_dyn(cin);
00128 }
00129 }
00130
00131 #endif
00132
00133