Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

nn_distribution.C

Go to the documentation of this file.
00001 
00007 
00008 //-----------------------------------------------------------------------------
00009 //   version 1:  Aug 2001   Simon Portegies Zwart, MIT
00010 //.............................................................................
00011 //   non-local functions: 
00012 //-----------------------------------------------------------------------------
00013 
00014 #include "dyn.h"
00015 #include "assert.h"
00016 
00017 #ifndef TOOLBOX
00018 
00019 #else
00020 
00021 void nn_distribution(dyn * b) {
00022 
00023     b->flatten_node();
00024     int n = b->n_leaves();
00025     if(n<=0) {
00026         for_all_leaves(dyn, b, bb)
00027           n++;
00028     }
00029 
00030     real *nn = new real[n];
00031     int *indexA = new int[n];
00032     int *indexB = new int[n];
00033     for(int j=0; j<n; j++) {
00034       nn[j] = VERY_LARGE_NUMBER;
00035     }
00036 
00037     int i=-1;
00038     real r;
00039     for_all_daughters(dyn, b, bi) {
00040       i++;
00041       indexA[i] = bi->get_index();
00042       for_all_daughters(dyn, b, bj) {
00043         if(bi!=bj) {
00044             r = abs(bi->get_pos()-bj->get_pos());
00045           if(r<=nn[i]) {
00046             nn[i] = r;
00047             indexB[i] = bj->get_index();
00048           }
00049         }
00050       }
00051     }
00052 
00053     if(indexA[0]==-1)
00054       for(int j=0; j<n; j++) 
00055         cout << nn[j] << endl;
00056     else
00057       for(int j=0; j<n; j++)
00058         cout << indexA[j] << "\t" 
00059              << indexB[j] << "\t" << nn[j] << endl;
00060 
00061     delete [] nn;
00062     delete [] indexA;
00063     delete [] indexB;
00064 }
00065 
00066 //-----------------------------------------------------------------------------
00067 //  main  --  driver to use  compute_luminosity_radii() as a tool
00068 //-----------------------------------------------------------------------------
00069 
00070 main(int argc, char ** argv)
00071 {
00072     char  *comment;
00073     bool  c_flag = false;
00074 
00075     check_help();
00076 
00077     extern char *poptarg;
00078     int c;
00079     char* param_string = "c:";
00080 
00081     while ((c = pgetopt(argc, argv, param_string)) != -1)
00082         switch(c)
00083             {
00084             case 'c': c_flag = true;
00085                       comment = poptarg;
00086                       break;
00087             case '?': params_to_usage(cerr, argv[0], param_string);
00088                       get_help();
00089                       exit(1);
00090             }    
00091 
00092     dyn* b;
00093     while (b = get_dyn(cin)) {
00094 
00095       if (c_flag == TRUE)
00096         b->log_comment(comment);
00097 
00098       b->log_history(argc, argv);
00099 
00100       nn_distribution(b);
00101       rmtree(b);
00102     }
00103 }
00104 
00105 #endif
00106 
00107 

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