Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

rs_reorder.C

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 //----------------------------------------------------------------------------
00010 //   version 1:  July 2001  Simon Portegies Zwart   spz@mit.edu
00011 //............................................................................
00012 //   non-local functions: 
00013 //----------------------------------------------------------------------------
00014 
00015 
00016 #include "SeBa_hist.h"
00017 
00018 #define MAX_NSCENARIOS 5000
00019 
00020 #ifdef TOOLBOX
00021 
00022 bool binary_contains(char a[], char b[]) {
00023   bool identical = false;
00024   if(!strcmp(a, b))
00025     identical = true;
00026 
00027   return identical;
00028 }
00029 
00030 bool SeBa_hist_contains(SeBa_hist *hi, SeBa_hist *ha) {
00031 
00032 //  cerr << "SeBa_hist_contains(SeBa_hist *hi, SeBa_hist *ha)" << endl;
00033 //  PRI(10);PRL(*hi);
00034 //  PRI(10);PRL(*ha);
00035 
00036   bool same_primary = false;
00037   bool same_secondary = false;
00038   for_all_SeBa_hist(SeBa_hist, hi->get_first(), ho) {
00039     for_all_SeBa_hist(SeBa_hist, ha->get_first(), he) {
00040 
00041 //      PRC(ho->get_label_prim());PRL(he->get_label_prim());
00042 
00043       if(binary_contains(ho->get_label_prim(), he->get_label_prim())) {
00044         same_primary = true;
00045       }
00046       if(binary_contains(ho->get_label_sec(), he->get_label_sec())) {
00047         same_secondary = true;
00048       }
00049     }
00050   }
00051 
00052 //  PRC(same_primary);
00053 //  PRL(same_secondary);
00054   return same_primary;
00055 }
00056 
00057 
00058 local int reorder_binaries(SeBa_hist *hi, const real end_time) {
00059 
00060   int N_lread = 0;
00061   int N_scenarios = 0;
00062 
00063   SeBa_hist *scenarios[MAX_NSCENARIOS];
00064   int scenario_frequency[MAX_NSCENARIOS];
00065 
00066   for(int i=0; i< MAX_NSCENARIOS; i++) {
00067     scenarios[i] = NULL;
00068     scenario_frequency[i] = 0;
00069   }
00070 
00071   scenarios[N_scenarios] = hi;
00072   scenario_frequency[N_scenarios]++;
00073   N_scenarios++;
00074 
00075 //  PRL(*hi);
00076 
00077   bool new_entry;
00078   do {
00079 //    for(int i = 0; i<N_scenarios; i++) {
00080 //      PRC(i);PRC(scenarios[i]);PRL(scenarios[i]->get_last());
00081 //    }
00082 
00083     hi = new SeBa_hist();
00084     hi->read_SeBa_hist(cin);
00085 
00086     N_lread++;
00087 
00088     new_entry = true;
00089     for(int i = 0; i<N_scenarios; i++) {
00090       
00091       if(SeBa_hist_contains(scenarios[i], hi)) {
00092 
00093         if(!new_entry) {
00094           cerr << "Same star is member of more thanone binary"<<endl;
00095         }
00096         new_entry = false;
00097         SeBa_hist *last = scenarios[i]->get_last();
00098         scenarios[i]->set_last(hi);
00099         hi->set_past(last);
00100         hi->set_number(scenarios[i]->get_number());
00101 
00102 //      put_state(scenarios[i], cerr);
00103         scenario_frequency[i]++;
00104 //      break;
00105       }
00106     }
00107 
00108     if(new_entry) {
00109       if(hi->get_number()==-1)
00110         hi->set_number(N_scenarios);
00111 
00112       scenarios[N_scenarios] = hi;
00113       scenario_frequency[N_scenarios]++;
00114       
00115       N_scenarios++;
00116       if(N_scenarios >= MAX_NSCENARIOS)
00117         break;
00118     }    
00119 
00120   }
00121   while (!cin.eof());
00122 
00123   int i=0;
00124 #if 0
00125   cerr << "print all scenarios"<<endl;
00126   do {
00127 
00128     for_all_SeBa_hist(SeBa_hist, scenarios[i], ha)
00129       cerr << *ha;
00130     i++;
00131   }
00132   while(scenarios[i]!=NULL);
00133 #endif
00134 
00135   cerr << "Scn. # \t freq." << endl;
00136   for(i=0; i<N_scenarios; i++) {
00137 //    cerr << i << "\t" << scenario_frequency[i] << ":  "; 
00138 //    put_state(scenarios[i], cerr);
00139     for_all_SeBa_hist(SeBa_hist, scenarios[i], ha) {
00140       cout << *ha;
00141     }
00142   }
00143 
00144   cerr << "Binaries read = " << N_lread-1 << endl;
00145   return N_scenarios;
00146 } 
00147 
00148 //----------------------------------------------------------------------------
00149 //  main  --  driver to reduce SeBa short dump data
00150 //----------------------------------------------------------------------------
00151 
00152 main(int argc, char ** argv) {
00153 
00154     real end_time = VERY_LARGE_NUMBER;
00155 
00156     char  *comment;
00157     check_help();
00158 
00159     extern char *poptarg;
00160     int c;
00161     char* param_string = "T:";
00162 
00163     while ((c = pgetopt(argc, argv, param_string)) != -1)
00164         switch(c)
00165             {
00166             case 'T': end_time = atof(poptarg);
00167                       break;
00168             case '?': params_to_usage(cerr, argv[0], param_string);
00169                       get_help();
00170                       exit(1);
00171             }            
00172 
00173 
00174     SeBa_hist* hi = new SeBa_hist;
00175     if (!hi->read_SeBa_hist(cin))
00176       exit(-1);
00177 
00178     if(end_time<VERY_LARGE_NUMBER)
00179       cerr << "End time = " << end_time << " [Myr]" << endl << endl;
00180 
00181     int N_binaries = reorder_binaries(hi, end_time); 
00182 
00183     cerr << "Total number of binaries found: " << N_binaries << endl;
00184 }
00185 
00186 #endif // endof: TOOLBOX
00187 
00188 
00189 

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