Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

renumber.C

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00018 
00020 
00021 //   version 1:  Jan 1993   Piet Hut
00022 //               Feb 2001   Simon Portegies Zwart
00023 
00024 #include "node.h"
00025 
00026 #ifndef TOOLBOX
00027 
00028 typedef  struct {
00029     node* str;
00030     real  mass;
00031 } nm_pair, *nm_pair_ptr;
00032 
00033 //-----------------------------------------------------------------------------
00034 //  compare_mass  --  compare the masses of two particles
00035 //-----------------------------------------------------------------------------
00036 
00037 local int compare_mass(const void * pi, const void * pj)
00038 {
00039     if (((nm_pair_ptr) pi)->mass < ((nm_pair_ptr) pj)->mass)
00040         return(1);
00041     else if (((nm_pair_ptr)pi)->mass > ((nm_pair_ptr)pj)->mass)
00042         return(-1);
00043     else
00044         return(0);
00045 }
00046 
00047 void renumber(node* b, int istart, bool mass_order) {
00048 
00049     int i;
00050     if(!mass_order) {
00051 
00052       i = istart;
00053       for_all_leaves(node, b, bj)
00054         bj->set_label(i++);
00055 
00056       return;
00057     }
00058 
00059     // Renumber the stars in order of mass.
00060     // Highest mass gets smallest number (strange choise, but).
00061 
00062     int n = b->n_leaves();
00063     nm_pair_ptr nm_table = new nm_pair[n];
00064     if (nm_table == NULL) {
00065       cerr << "renumber: "
00066            << "not enough memory left for nm_table\n";
00067       return;
00068     }
00069 
00070     i=0;
00071     for_all_daughters(node, b, bi) {
00072       nm_table[i].str = bi;
00073       nm_table[i].mass = bi->get_mass();
00074       i++;
00075     }
00076 
00077     qsort((void *)nm_table, (size_t)n, sizeof(nm_pair), compare_mass);
00078 
00079     for (i=0; i<n; i++) {
00080       nm_table[i].str->set_index(istart+i);
00081     }
00082     delete []nm_table;
00083 
00084 }
00085 
00086 #else
00087 
00088 void main(int argc, char ** argv)
00089 {
00090     bool  c_flag = FALSE;
00091     char  *comment;
00092 
00093     bool M_flag = false;
00094     int istart = 1;
00095 
00096     check_help();
00097 
00098     extern char *poptarg;
00099     int c;
00100     char* param_string = "MmI:i:c:";
00101 
00102     while ((c = pgetopt(argc, argv, param_string)) != -1)
00103         switch(c) {
00104 
00105             case 'c': c_flag = TRUE;
00106                       comment = poptarg;
00107                       break;
00108             case 'i':
00109             case 'I': istart = atoi(poptarg);
00110                       break;
00111             case 'm':
00112             case 'M': M_flag = true;
00113                       break;
00114             case '?': params_to_usage(cerr, argv[0], param_string);
00115                       get_help();
00116                       exit(1);
00117         }
00118 
00119 
00120     node* b;
00121     b = get_node(cin);
00122     b->log_history(argc, argv);
00123 
00124     renumber(b, istart, M_flag);
00125 
00126     put_node(cout, *b);
00127     rmtree(b);
00128 
00129 }
00130 #endif
00131 

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