Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

dyn_io.C

Go to the documentation of this file.
00001 
00002        //=======================================================//    _\|/_
00003       //  __  _____           ___                    ___       //      /|\ ~
00004      //  /      |      ^     |   \  |         ^     |   \     //          _\|/_
00005     //   \__    |     / \    |___/  |        / \    |___/    //            /|\ ~
00006    //       \   |    /___\   |  \   |       /___\   |   \   // _\|/_
00007   //     ___/   |   /     \  |   \  |____  /     \  |___/  //   /|\ ~
00008  //                                                       //            _\|/_
00009 //=======================================================//              /|\ ~
00010 
00017 
00018 #include "dyn.h"
00019 #include "util_io.h"
00020 
00021 #ifndef TOOLBOX
00022 
00023 // Initialize all static dyn data here...
00024 
00025 xreal dyn::system_time          = 0.0;
00026 real dyn::real_system_time      = 0.0;
00027 bool dyn::use_sstar             = false;
00028 
00029 bool dyn::ignore_internal       = false;
00030 
00031 unsigned int  dyn::external_field       = 0;
00032 
00033 int  dyn::tidal_type    = 0;
00034 real dyn::omega = 0;
00035 real dyn::omega_sq      = 0;
00036 real dyn::alpha1        = 0;
00037 real dyn::alpha3        = 0;
00038 vector dyn::tidal_center = vector(0,0,0);
00039 
00040 real dyn::p_mass = 0;
00041 real dyn::p_scale_sq = 0;
00042 vector dyn::p_center = vector(0,0,0);
00043 
00044 real dyn::pl_coeff = 0;
00045 real dyn::pl_scale_sq = 0;
00046 real dyn::pl_exponent = 0;
00047 vector dyn::pl_center = vector(0,0,0);
00048 real dyn::pl_cutoff = 0;
00049 real dyn::pl_cutoff_sq = 0;
00050 real dyn::pl_mass = 0;
00051 real dyn::pl_softening_sq = 0;
00052 
00053 void dyn::print_static(ostream& s)              // default = cerr
00054 {
00055     node::print_static(s);
00056 
00057     s << "system_time = " << system_time << endl;
00058     s << "real_system_time = " << real_system_time << endl;
00059 
00060     s << "use_sstar = " << use_sstar << endl;
00061     s << "ignore_internal = " << ignore_internal << endl;
00062 
00063     s << "external_field = " << external_field << endl;
00064     s << "tidal_type = " << tidal_type << endl;
00065 
00066     s << "omega = " << omega << endl;
00067     s << "omega_sq = " << omega_sq << endl;
00068     s << "alpha1 = " << alpha1 << endl;
00069     s << "alpha3 = " << alpha3 << endl;
00070     s << "tidal_center = " << tidal_center << endl;
00071 
00072     s << "p_mass = " << p_mass << endl;
00073     s << "p_scale_sq = " << p_scale_sq << endl;
00074     s << "p_center = " << p_center << endl;
00075 
00076     s << "pl_coeff = " << pl_coeff << endl;
00077     s << "pl_scale_sq = " << pl_scale_sq << endl;
00078     s << "pl_exponent = " << pl_exponent << endl;
00079     s << "pl_center = " << pl_center << endl;
00080 
00081     s << "pl_cutoff = " << pl_cutoff << endl;
00082     s << "pl_cutoff_sq = " << pl_cutoff_sq << endl;
00083     s << "pl_mass = " << pl_mass << endl;
00084     s << "pl_softening_sq = " << pl_softening_sq << endl;
00085 }
00086 
00087 static bool read_xreal = false;
00088 
00089 istream & dyn::scan_dyn_story(istream& s)
00090 {
00091     char input_line[MAX_INPUT_LINE_LENGTH];
00092     real last_real = false;
00093 
00094     while (get_line(s,input_line), !matchbracket(END_DYNAMICS, input_line)) {
00095 
00096         char keyword[MAX_INPUT_LINE_LENGTH];
00097         const char *val = getequals(input_line, keyword);
00098 
00099         if (!strcmp("real_system_time", keyword)) {
00100 
00101             read_xreal = true;
00102             last_real = true;
00103 
00104             // We don't know anything about parent nodes yet, so it is
00105             // not easy to know if we are the root node.  Rule: if we
00106             // find real_system_time, assume that we should read an
00107             // xreal as system_time.  Otherwise, read it as real.
00108             // The tortuous logic is to keep the determination of
00109             // which choice we should make completely local.
00110             //
00111             // Unfortunately, this logic must be duplicated in all
00112             // other *dyn::scan_dyn_story functions (see _dyn_io.C,
00113             // hdyn_io.C, sdyn3_io.C)...
00114 
00115         } else if (!strcmp("system_time", keyword)) {
00116 
00117             // Check input format before reading.
00118 
00119             if (!last_real) read_xreal = false;
00120 
00121             if (read_xreal) {
00122 
00123                 //cerr << "dyn::scan_dyn_story: input "
00124                 //     << "time data type is xreal"
00125                 //     << endl;
00126 
00127                 // The following should set real_system_time too...
00128 
00129                 set_system_time(get_xreal_from_input_line(input_line));
00130 
00131             } else {
00132 
00133                 //cerr << "dyn::scan_dyn_story: input "
00134                 //     << "time data type is real"
00135                 //     << endl;
00136 
00137                 real_system_time = system_time = strtod(val, NULL);
00138             }
00139         } else {
00140 
00141             last_real = false;
00142 
00143             if (!strcmp("m", keyword))
00144                 mass = strtod(val, NULL);
00145             else if (!strcmp("r", keyword))
00146                 set_vector_from_input_line(pos, input_line);
00147             else if (!strcmp("v", keyword))
00148                 set_vector_from_input_line(vel, input_line);
00149             else
00150                 add_story_line(dyn_story, input_line);
00151         }
00152     }
00153 
00154     return s;
00155 }
00156 
00157 ostream& dyn::print_dyn_story(ostream& s,
00158                               bool print_xreal,         // default = true
00159                               int short_output) // default = 0
00160 {
00161     // Modifications by Steve (5/01) to streamline output.
00162 
00163     // Print system time first (root node only).
00164 
00165     if (!parent) {
00166 
00167 #ifdef USE_XREAL
00168         if (print_xreal) {
00169 
00170             // Note (Steve 5/00): system_time is now xreal and hard to read.
00171             // For convenience, also print out a real version of the time.
00172             // By printing out real_system_time first, we set a flag that
00173             // allows scan_dyn_story to read xreal, rather than real, input.
00174 
00175             put_real_number(s, "  real_system_time  =  ", (real)system_time);
00176             put_real_number(s, "  system_time  =  ", system_time);
00177 
00178         } else
00179 
00180             put_real_number(s, "  system_time  =  ", (real)system_time);
00181 #else
00182 
00183         put_real_number(s, "  system_time  =  ", system_time);
00184 
00185 #endif
00186     }
00187 
00188     // Mass is now printed by node::print_dyn_story().
00189 
00190     node::print_dyn_story(s, print_xreal, short_output);
00191 
00192     put_real_vector(s, "  r  =  ", pos);
00193     put_real_vector(s, "  v  =  ", vel);
00194 
00195     return s;
00196 }
00197 
00198 #else
00199 main(int argc, char** argv)
00200 {
00201     dyn  * b;
00202     check_help();
00203 
00204     while (b = (dyn *) get_node(cin, new_dyn)) {
00205         cout << "TESTING put_dyn:" << endl;
00206         put_node(cout,*b);
00207         cout << "TESTING pp2()   :" << endl;
00208         pp2(b);
00209         delete b;
00210     }
00211     cerr << "Normal exit\n";
00212 }
00213 #endif

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