Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

addchydro.C

Go to the documentation of this file.
00001 /*
00002  *  addchydro.C: creates a chydro part for each body
00003  *.............................................................................
00004  *    version 1:  Jan 1993   Piet Hut
00005  *.............................................................................
00006  */
00007 #include "starlab_vector.h"
00008 #include "node.h"
00009 #include "chydro.h"
00010 
00011 #ifndef TOOLBOX
00012 
00013 /*-----------------------------------------------------------------------------
00014  *  addchydro  --
00015  *-----------------------------------------------------------------------------
00016  */
00017 void  addchydro(node * b, real R_eff, real r_core, real m_core)
00018     {
00019     node * bi;
00020 
00021     if (b->get_oldest_daughter() != NULL)
00022         for (bi=b->get_oldest_daughter(); bi != NULL;
00023                                           bi=bi->get_younger_sister())
00024             addchydro(bi, R_eff, r_core, m_core);
00025     else
00026         {
00027         real M_tot = b->get_mass();
00028 
00029         if (m_core > M_tot)
00030             {
00031             cerr << "addchydro: m_core = " << m_core << " > M_tot = "
00032                  << M_tot << endl;
00033             exit(1);
00034             }
00035 
00036         if (r_core > R_eff)
00037             {
00038             cerr << "addchydro: r_core = " << r_core << " > R_eff = "
00039                  << R_eff << endl;
00040             exit(1);
00041             }
00042 
00043         hydrobase * old_hydrobase = b->get_hydrobase();
00044         chydro * new_chydro = new chydro(R_eff, m_core, r_core);
00045 
00046         new_chydro->set_hydro_story(old_hydrobase->get_hydro_story());
00047         b->set_hydrobase((hydrobase *) new_chydro);
00048         old_hydrobase->set_hydro_story(NULL);     // if not, deleting the old 
00049         delete old_hydrobase;                     // hydrobase would delete its
00050         }                                          // story as well
00051     }
00052 
00053 #else
00054 
00055 /*-----------------------------------------------------------------------------
00056  *  main  --
00057  *-----------------------------------------------------------------------------
00058  */
00059 main(int argc, char ** argv)
00060     {
00061     int  c;
00062     bool  r_flag = FALSE;
00063     bool  R_flag = FALSE;
00064     bool  m_flag = FALSE;
00065     bool  c_flag = FALSE;
00066     real  R_eff = 0;           // default value;
00067     real  r_core = 0;           // default value;
00068     real  m_core = 0;           // default value;
00069     char  *comment;
00070     extern char *poptarg;
00071     int  pgetopt(int, char **, char *);
00072 
00073     while ((c = pgetopt(argc, argv, "R:r:m:c:")) != -1)
00074         switch(c)
00075             {
00076             case 'R': R_flag = TRUE;
00077                       R_eff = atof(poptarg);
00078                       break;
00079             case 'r': r_flag = TRUE;
00080                       r_core = atof(poptarg);
00081                       break;
00082             case 'm': m_flag = TRUE;
00083                       m_core = atof(poptarg);
00084                       break;
00085             case 'c': c_flag = TRUE;
00086                       comment = poptarg;
00087                       break;
00088             case '?': cerr <<
00089                       "usage: addchydro [-R #] [-r #] [-m #] "
00090                       << "[-c \"..\"]\n" <<
00091                       "  for effective radius, core radius, core mass\n";
00092                       exit(1);
00093             }
00094     
00095     node *b;
00096 
00097     while (b = get_node(cin))
00098         {
00099         if (c_flag == TRUE)
00100             b->log_comment(comment);
00101         b->log_history(argc, argv);
00102 
00103         addchydro(b, R_eff, r_core, m_core);
00104         put_node(cout, *b);     
00105         delete b;
00106         }
00107     }
00108 
00109 #endif
00110 
00111 /* endof: addchydro.c */

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