00001
00002 //=======================================================// _\|/_
00003 // __ _____ ___ ___ // /|\ ~
00004 // / | ^ | \ | ^ | \ // _\|/_
00005 // \__ | / \ |___/ | / \ |___/ // /|\ ~
00006 // \ | /___\ | \ | /___\ | \ // _\|/_
00007 // ___/ | / \ | \ |____ / \ |___/ // /|\ ~
00008 // // _\|/_
00009 //=======================================================// /|\ ~
00010
00017
00018 #include "tdyn.h"
00019 #include "util_io.h"
00020
00021 #ifndef TOOLBOX
00022
00023 // Initialize any static p/tdyn data here...
00024 //
00025 // ...
00026
00027 static bool read_xreal = false;
00028
00029 istream & pdyn::scan_star_story(istream & s, int level)
00030 {
00031 // (Same function is inherited by tdyn.)
00032
00033 char input_line[MAX_INPUT_LINE_LENGTH];
00034
00035 // In this case, simply read the Star info into the dyn variables.
00036 // This code replicates part of scan_dyn_story() below, and allows
00037 // us to read a snapshot with the stellar information encoded in
00038 // a (Star...)Star clause instead of in Dyn.
00039
00040 while (get_line(s, input_line), !matchbracket(END_STAR, input_line)) {
00041
00042 char keyword[MAX_INPUT_LINE_LENGTH];
00043 const char *val = getequals(input_line, keyword);
00044
00045 if (!strcmp("S", keyword)) {
00046
00047 // char cptr[MAX_INPUT_LINE_LENGTH];
00048 // sscanf(val,"%s",cptr);
00049 // set_stellar_type(cptr);
00050
00051 stellar_type = strtol(val, NULL, 10);
00052
00053 } else if (!strcmp("T", keyword))
00054 temperature = strtod(val, NULL);
00055 else if (!strcmp("L", keyword))
00056 luminosity = strtod(val, NULL);
00057
00058 // Ignore everything else -- no stories!
00059 }
00060 return s;
00061 }
00062
00063 istream & pdyn::scan_dyn_story(istream & s)
00064 {
00065 char input_line[MAX_INPUT_LINE_LENGTH];
00066 bool last_real = false;
00067 bool reading_root = false;
00068 vector tmp;
00069
00070 while (get_line(s, input_line), !matchbracket(END_DYNAMICS, input_line)) {
00071
00072 char keyword[MAX_INPUT_LINE_LENGTH];
00073 const char *val = getequals(input_line, keyword);
00074
00075 // See xreal notes in dyn_io.C...
00076
00077 // PRL(keyword);
00078
00079 switch(keyword[0]) {
00080 case 'a':
00081
00082 // Acceleration:
00083
00084 if (!strcmp("a", keyword)) {
00085 set_vector_from_input_line(acc, input_line);
00086 break;
00087 }
00088 goto other;
00089
00090 case 'L':
00091
00092 // Luminosity:
00093
00094 if (!strcmp("L", keyword)) {
00095 luminosity = strtod(val, NULL);
00096 break;
00097 }
00098 goto other;
00099
00100 case 'm':
00101
00102 // Mass:
00103
00104 if (!strcmp("m", keyword)) {
00105 mass = strtod(val, NULL);
00106 break;
00107 }
00108 goto other;
00109
00110 case 'r':
00111
00112 // Position:
00113
00114 if (!strcmp("r", keyword)) {
00115 if (!reading_root)
00116 set_vector_from_input_line(pos, input_line);
00117 else
00118 set_vector_from_input_line(tmp, input_line);
00119 break;
00120 }
00121
00122 // Real system time:
00123
00124 if (!strcmp("real_system_time", keyword)) {
00125
00126 // "real_system_time" (a) gives the root-node time in
00127 // real format and (b) serves as a flag that all other
00128 // times are given in xreal form.
00129
00130 read_xreal = true;
00131 last_real = true;
00132 reading_root = true;
00133 break;
00134 }
00135 goto other;
00136
00137 case 's':
00138
00139 // System time:
00140
00141 if (!strcmp("system_time", keyword)) {
00142
00143 // Check input format before reading.
00144 // If we see "system_time" and haven't ever encountered
00145 // "real_system_time", then all our times are plain
00146 // "real"s.
00147
00148 if (!last_real) read_xreal = false;
00149 reading_root = true;
00150
00151 if (read_xreal) {
00152
00153 set_system_time(get_xreal_from_input_line(input_line));
00154
00155 } else {
00156
00157 real_system_time = system_time = strtod(val, NULL);
00158
00159 }
00160 break;
00161 }
00162 goto other;
00163
00164 case 'S':
00165
00166 // Stellar type:
00167
00168 if (!strcmp("S", keyword)) {
00169
00170 // char cptr[MAX_INPUT_LINE_LENGTH];
00171 // sscanf(val,"%s",cptr);
00172 // set_stellar_type(cptr);
00173
00174 stellar_type = strtol(val, NULL, 10);
00175 break;
00176 }
00177 goto other;
00178
00179 case 't':
00180
00181 if (!strcmp("tmpv", keyword)) {
00182
00183 // Read time, mass, pos, and vel as unformatted data.
00184 // Input time will be real, independent of USE_XREAL.
00185
00186 // *** Must coordinate with hdyn_io.C. ***
00187
00188 real time = read_unformatted_real( s );
00189 mass = read_unformatted_real( s );
00190
00191 if (!reading_root) {
00192
00193 read_unformatted_vector( s, pos );
00194 read_unformatted_vector( s, vel );
00195
00196 } else {
00197
00198 // Root pos and vel are used for center tracking.
00199
00200 read_unformatted_vector( s, tmp );
00201 read_unformatted_vector( s, tmp );
00202
00203 }
00204 break;
00205 }
00206
00207 if (!strcmp("t64mpv32", keyword)) {
00208 real time = read_unformatted_real( s );
00209 mass = read_unformatted32_real( s );
00210
00211 if (!reading_root) {
00212
00213 read_unformatted32_vector( s, pos );
00214 read_unformatted32_vector( s, vel );
00215
00216 } else {
00217
00218 // Root pos and vel are used for center tracking.
00219
00220 read_unformatted_vector( s, tmp );
00221 read_unformatted_vector( s, tmp );
00222
00223 }
00224 break;
00225 }
00226 goto other;
00227
00228 case 'T':
00229
00230 if (!strcmp("TL", keyword)) {
00231
00232 // Short output always uses floats for T and L.
00233
00234 temperature = read_unformatted32_real( s );
00235 luminosity = read_unformatted32_real( s );
00236 break;
00237 }
00238
00239 // Temperature:
00240
00241 if (!strcmp("T", keyword)) {
00242 temperature = strtod(val, NULL);
00243 break;
00244 }
00245 goto other;
00246
00247 case 'v':
00248
00249 // Velocity:
00250
00251 if (!strcmp("v", keyword)) {
00252 if (!reading_root)
00253 set_vector_from_input_line(vel, input_line);
00254 else
00255 set_vector_from_input_line(tmp, input_line);
00256 break;
00257 }
00258 goto other;
00259
00260 default:
00261 other:
00262 // else
00263 // add_story_line(dyn_story, input_line); // no stories!
00264 ;
00265 }
00266 }
00267 return s;
00268 }
00269
00270 istream & tdyn::scan_dyn_story(istream & s)
00271 {
00272 char input_line[MAX_INPUT_LINE_LENGTH];
00273 bool last_real = false;
00274 bool reading_root = false;
00275 vector tmp;
00276
00277 while (get_line(s, input_line), !matchbracket(END_DYNAMICS, input_line)) {
00278
00279 char keyword[MAX_INPUT_LINE_LENGTH];
00280 const char *val = getequals(input_line, keyword);
00281
00282 // See xreal notes in dyn_io.C...
00283
00284 // PRL(keyword);
00285
00286 switch(keyword[0]) {
00287 case 'a':
00288
00289 // Acceleration:
00290
00291 if (!strcmp("a", keyword)) {
00292 set_vector_from_input_line(acc, input_line);
00293 break;
00294 }
00295 goto other;
00296
00297 case 'b':
00298
00299 // Alternate center tracking (root node only). Save all
00300 // "center" quantities as stories for possible future use.
00301
00302 if (reading_root) {
00303
00304 vector tmp;
00305
00306 if (!strcmp("bound_center_pos", keyword)) {
00307 set_vector_from_input_line(tmp, input_line);
00308
00309 // Create a dyn story if none exists...
00310
00311 if (!dyn_story)
00312 dyn_story = mk_story_chapter(DYNAMICS_ID);
00313
00314 putvq(dyn_story, "bound_center_pos", tmp);
00315 break;
00316 }
00317
00318 if (!strcmp("bound_center_vel", keyword)) {
00319 set_vector_from_input_line(tmp, input_line);
00320
00321 if (!dyn_story)
00322 dyn_story = mk_story_chapter(DYNAMICS_ID);
00323
00324 putvq(dyn_story, "bound_center_vel", tmp);
00325 break;
00326 }
00327 }
00328 goto other;
00329
00330 case 'c':
00331
00332 // Center tracking (root node only). We will save any
00333 // "center" quantities to the root node pos and vel, and
00334 // save all such quantities as stories too.
00335
00336 if (reading_root) {
00337
00338 if (!strcmp("center_pos", keyword)) {
00339 set_vector_from_input_line(pos, input_line);
00340
00341 // Create a dyn story if none exists...
00342
00343 if (!dyn_story)
00344 dyn_story = mk_story_chapter(DYNAMICS_ID);
00345
00346 putvq(dyn_story, "center_pos", pos);
00347 break;
00348 }
00349
00350 if (!strcmp("center_vel", keyword)) {
00351 set_vector_from_input_line(vel, input_line);
00352
00353 if (!dyn_story)
00354 dyn_story = mk_story_chapter(DYNAMICS_ID);
00355
00356 putvq(dyn_story, "center_vel", vel);
00357 break;
00358 }
00359
00360 if (!strcmp("center_type", keyword)) {
00361 int type = strtol(val, NULL, 10);
00362
00363 if (!dyn_story)
00364 dyn_story = mk_story_chapter(DYNAMICS_ID);
00365
00366 putiq(dyn_story, "center_type", type);
00367 break;
00368 }
00369 }
00370 goto other;
00371
00372 case 'd':
00373
00374 // Bookkeeping:
00375
00376 if (!strcmp("defunct", keyword)) {
00377 defunct = true;
00378 break;
00379 }
00380 goto other;
00381
00382 case 'e':
00383
00384 // Cluster escaper flag:
00385
00386 if (!strcmp("esc", keyword)) {
00387
00388 // Use the prev pointer for temporary storage. Careful!!
00389 // Note: NULL means that esc is false.
00390
00391 // The esc flag is largely redundant, as all necessary
00392 // information is contained in t_esc (below).
00393
00394 int esc = strtol(val, NULL, 10);
00395 if (esc == 1) prev = (tdyn*) 42;
00396 break;
00397 }
00398 goto other;
00399
00400 case 'j':
00401
00402 // Jerk:
00403
00404 if (!strcmp("j", keyword)) {
00405 set_vector_from_input_line(jerk, input_line);
00406 break;
00407 }
00408 goto other;
00409
00410 case 'k':
00411
00412 // Kepler flag (1 = unperturbed, 2 = lightly perturbed):
00413
00414 if (!strcmp("kep", keyword)) {
00415 int i;
00416 i = strtol(val, NULL, 10);
00417 kep = (kepler*)i;
00418 break;
00419 }
00420 goto other;
00421
00422 case 'L':
00423
00424 // Luminosity:
00425
00426 if (!strcmp("L", keyword)) {
00427 luminosity = strtod(val, NULL);
00428 break;
00429 }
00430 goto other;
00431
00432 case 'm':
00433
00434 // Mass:
00435
00436 if (!strcmp("m", keyword)) {
00437 mass = strtod(val, NULL);
00438 break;
00439 }
00440 goto other;
00441
00442 case 'r':
00443
00444 // Position:
00445
00446 if (!strcmp("r", keyword)) {
00447 if (!reading_root)
00448 set_vector_from_input_line(pos, input_line);
00449 else
00450 set_vector_from_input_line(tmp, input_line);
00451 break;
00452 }
00453
00454 // Real system time:
00455
00456 if (!strcmp("real_system_time", keyword)) {
00457
00458 // "real_system_time" (a) gives the root-node time in
00459 // real format and (b) serves as a flag that all other
00460 // times are given in xreal form.
00461
00462 read_xreal = true;
00463 last_real = true;
00464 reading_root = true;
00465 break;
00466 }
00467 goto other;
00468
00469 case 's':
00470
00471 // System time:
00472
00473 if (!strcmp("system_time", keyword)) {
00474
00475 // Check input format before reading.
00476 // If we see "system_time" and haven't ever encountered
00477 // "real_system_time", then all our times are plain
00478 // "real"s.
00479
00480 if (!last_real) read_xreal = false;
00481 reading_root = true;
00482
00483 if (read_xreal) {
00484
00485 set_system_time(get_xreal_from_input_line(input_line));
00486
00487 } else {
00488
00489 real_system_time = system_time = strtod(val, NULL);
00490
00491 }
00492 break;
00493 }
00494 goto other;
00495
00496 case 'S':
00497
00498 // Stellar type:
00499
00500 if (!strcmp("S", keyword)) {
00501
00502 // char cptr[MAX_INPUT_LINE_LENGTH];
00503 // sscanf(val,"%s",cptr);
00504 // set_stellar_type(cptr);
00505
00506 stellar_type = strtol(val, NULL, 10);
00507 break;
00508 }
00509 goto other;
00510
00511 case 't':
00512
00513 // Time:
00514
00515 if (!strcmp("t", keyword)) {
00516 if (read_xreal)
00517 time = get_xreal_from_input_line(input_line);
00518 else {
00519 time = strtod(val, NULL);
00520 }
00521 break;
00522 }
00523
00524 if (!strcmp("tmpv", keyword)) {
00525
00526 // Read time, mass, pos, and vel as unformatted data.
00527 // Input time will be real, independent of USE_XREAL.
00528
00529 // *** Must coordinate with hdyn_io.C. ***
00530
00531 time = read_unformatted_real( s );
00532 mass = read_unformatted_real( s );
00533
00534 if (!reading_root) {
00535
00536 read_unformatted_vector( s, pos );
00537 read_unformatted_vector( s, vel );
00538
00539 } else {
00540
00541 // Root pos and vel are used for center tracking.
00542
00543 read_unformatted_vector( s, tmp );
00544 read_unformatted_vector( s, tmp );
00545
00546 }
00547 break;
00548 }
00549
00550 if (!strcmp("t64mpv32", keyword)) {
00551 time = read_unformatted_real( s );
00552 mass = read_unformatted32_real( s );
00553
00554 if (!reading_root) {
00555
00556 read_unformatted32_vector( s, pos );
00557 read_unformatted32_vector( s, vel );
00558
00559 } else {
00560
00561 // Root pos and vel are used for center tracking.
00562
00563 read_unformatted_vector( s, tmp );
00564 read_unformatted_vector( s, tmp );
00565
00566 }
00567 break;
00568 }
00569
00570 // Escape time.
00571
00572 if (!strcmp("t_esc", keyword)) {
00573
00574 // Another kludge... Careful again!!
00575 // Return t_esc pointed to by t_next.
00576 // MUST be sure to delete it on return.
00577
00578 real *t_esc = new real;
00579 *t_esc = strtod(val, NULL);
00580
00581 next = (tdyn *)t_esc;
00582 }
00583 goto other;
00584
00585 case 'T':
00586
00587 if (!strcmp("TL", keyword)) {
00588
00589 // Short output always uses floats for T and L.
00590
00591 temperature = read_unformatted32_real( s );
00592 luminosity = read_unformatted32_real( s );
00593 break;
00594 }
00595
00596 // Temperature:
00597
00598 if (!strcmp("T", keyword)) {
00599 temperature = strtod(val, NULL);
00600 break;
00601 }
00602 goto other;
00603
00604 case 'v':
00605
00606 // Velocity:
00607
00608 if (!strcmp("v", keyword)) {
00609 if (!reading_root)
00610 set_vector_from_input_line(vel, input_line);
00611 else
00612 set_vector_from_input_line(tmp, input_line);
00613 break;
00614 }
00615 goto other;
00616
00617 default:
00618 other:
00619 // else
00620 // add_story_line(dyn_story, input_line); // no stories
00621 ;
00622 }
00623 }
00624 return s;
00625 }
00626
00627 local void print_local_time(xreal time,
00628 ostream & s,
00629 bool print_xreal,
00630 int short_output)
00631 {
00632 adjust_starlab_precision(HIGH_PRECISION);
00633
00634 if (print_xreal)
00635 put_real_number(s, " t = ", time); // OK for real or xreal
00636 else
00637 put_real_number(s, " t = ", (real)time);
00638
00639 adjust_starlab_precision(-1);
00640 }
00641
00642 ostream & _pdyn_::print_dyn_story(ostream & s,
00643 bool print_xreal, // default = true
00644 int short_output) // default = 0, ignored
00645 {
00646 // Use dyn::print_dyn_story() to print the dyn stuff...
00647
00648 dyn::print_dyn_story(s, print_xreal, short_output);
00649
00650 // if (stellar_type) put_string(s, " S = ", stellar_type);
00651
00652 put_integer(s, " S = ", stellar_type);
00653 put_real_number(s, " T = ", temperature);
00654 put_real_number(s, " L = ", luminosity);
00655
00656 return s;
00657 }
00658
00659 // Not needed (should be inherited?):
00660
00661 // ostream & pdyn::print_dyn_story(ostream & s,
00662 // bool print_xreal, // default = true
00663 // int short_output) // default = 0, ignored
00664 // {
00665 // _pdyn_::print_dyn_story(s, print_xreal, short_output);
00666 // return s;
00667 // }
00668
00669 ostream & tdyn::print_dyn_story(ostream & s,
00670 bool print_xreal, // default = true
00671 int short_output) // default = 0, ignored
00672 {
00673 // Modifications by Steve (5/01) to streamline output.
00674
00675 // Ordinarily we want to print time before dyn stuff, but it is
00676 // necessary to print system time first for the root node...
00677
00678 if (parent) print_local_time(time, s, print_xreal, short_output);
00679
00680 // Use pdyn::print_dyn_story() to print the pdyn stuff...
00681
00682 _pdyn_::print_dyn_story(s, print_xreal, short_output);
00683
00684 if (!parent) print_local_time(time, s, print_xreal, short_output);
00685
00686 return s;
00687 }
00688
00689 #else
00690
00691 main(int argc, char** argv)
00692 {
00693 tdyn *b;
00694 check_help();
00695
00696 #if 1
00697
00698 while (b = get_tdyn(cin)) {
00699 cout << "TESTING put_tdyn:" << endl;
00700 put_node(cout, *b, true, 1);
00701 cout << "TESTING pp2() :" << endl;
00702 pp2(b);
00703 delete b;
00704 }
00705
00706 #else
00707
00708 ifstream s("xxx");
00709 if (s) {
00710 cerr << "pause..." << flush;
00711 char tmp;
00712 cin >> tmp;
00713
00714 b = get_tdyn(s, NULL, NULL, false);
00715
00716 cerr << "pause..." << flush;
00717 cin >> tmp;
00718 } else
00719 cerr << "no file xxx" << endl;
00720
00721 #endif
00722 }
00723
00724 #endif
1.2.6 written by Dimitri van Heesch,
© 1997-2001