00001
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "dyn.h"
00018
00019 #ifdef TOOLBOX
00020
00021
00022
00023
00024
00025 local void print_sqrt_n_tiles(real * squares, int n_intervals, int n_squares)
00026 {
00027 int i;
00028 real factor = (n_squares - 1) / (real) n_intervals;
00029
00030 for (i = 0; i <= n_intervals; i++)
00031 printf(" %.3g", sqrt(squares[(int) (factor*i + 0.5)]));
00032 printf("\n");
00033 }
00034
00035
00036
00037
00038
00039 local int realcompare(const void * a, const void * b)
00040 {
00041 if (*((real *) a) > *((real *) b))
00042 return (1);
00043 else if (*((real *) a) < *((real *) b))
00044 return (-1);
00045 else
00046 return (0);
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 void dist_stats(dyn * b1, dyn * b2, int n_intervals)
00058 {
00059 real rootrdist, rootvdist;
00060 vector dr, dv;
00061 real * posdists;
00062 real * veldists;
00063 real * posdists_i;
00064 real * veldists_i;
00065
00066
00067
00068
00069
00070
00071 int n1, n2;
00072 dyn * bi1;
00073 dyn * bi2;
00074 for (n1 = 0, bi1 = b1->get_oldest_daughter(); bi1 != NULL;
00075 bi1 = bi1->get_younger_sister())
00076 n1++;
00077 for (n2 = 0, bi2 = b2->get_oldest_daughter(); bi2 != NULL;
00078 bi2 = bi2->get_younger_sister())
00079 n2++;
00080 if (n1 != n2)
00081 {
00082 cerr << "dyndiff: N1 = " << n1 << " != N2 = " << n2 << endl;
00083 exit(1);
00084 }
00085
00086
00087
00088 if ((posdists = (real *) malloc(n1 * sizeof(real))) == NULL)
00089 err_exit("dist_stats: not enough memory left for posdists[]");
00090
00091 if ((veldists = (real *) malloc(n1 * sizeof(real))) == NULL)
00092 err_exit("dist_stats: not enough memory left for veldists[]");
00093
00094
00095
00096 if ((rootrdist = abs(b1->get_pos() - b2->get_pos())) > 0)
00097 cerr << "dist_stats: the root nodes have a spatial separation of "
00098 << rootrdist << endl;
00099
00100 if ((rootvdist = abs(b1->get_vel() - b2->get_vel())) > 0)
00101 cerr << "dist_stats: the root nodes have a velocity separation of "
00102 << rootvdist << endl;
00103
00104
00105
00106 for (bi1 = b1->get_oldest_daughter(), bi2 = b2->get_oldest_daughter(),
00107 posdists_i = posdists, veldists_i = veldists;
00108 bi1 != NULL;
00109 bi1 = bi1->get_younger_sister(), bi2 = bi2->get_younger_sister(),
00110 posdists_i++, veldists_i++)
00111 {
00112 dr = bi1->get_pos() - bi2->get_pos();
00113 *posdists_i = dr*dr;
00114 dv = bi1->get_vel() - bi2->get_vel();
00115 *veldists_i = dv*dv;
00116 }
00117
00118 qsort((void *)posdists, (size_t)n1, sizeof(real), realcompare);
00119 qsort((void *)veldists, (size_t)n1, sizeof(real), realcompare);
00120
00121 print_sqrt_n_tiles(posdists, n_intervals, n1);
00122 print_sqrt_n_tiles(veldists, n_intervals, n1);
00123 }
00124
00125 main(int argc, char ** argv)
00126 {
00127 int n_intervals;
00128 bool n_flag = FALSE;
00129
00130 check_help();
00131
00132 extern char *poptarg;
00133 int c;
00134 char* param_string = "n:";
00135
00136 while ((c = pgetopt(argc, argv, param_string)) != -1)
00137 switch(c)
00138 {
00139 case 'n': n_flag = TRUE;
00140 n_intervals = atoi(poptarg);
00141 break;
00142 case '?': params_to_usage(cerr, argv[0], param_string);
00143 get_help();
00144 exit(1);
00145 }
00146
00147 dyn * b1;
00148 dyn * b2;
00149 b1 = get_dyn(cin);
00150 b2 = get_dyn(cin);
00151
00152 if (n_flag == FALSE)
00153 n_intervals = 4;
00154
00155 dist_stats(b1, b2, n_intervals);
00156 }
00157
00158 #endif
00159
00160