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
00024
00025
00026
00027 static bool read_xreal = false;
00028
00029 istream & pdyn::scan_star_story(istream & s, int level)
00030 {
00031
00032
00033 char input_line[MAX_INPUT_LINE_LENGTH];
00034
00035
00036
00037
00038
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
00048
00049
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
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
00076
00077
00078
00079 switch(keyword[0]) {
00080 case 'a':
00081
00082
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
00093
00094 if (!strcmp("L", keyword)) {
00095 luminosity = strtod(val, NULL);
00096 break;
00097 }
00098 goto other;
00099
00100 case 'm':
00101
00102
00103
00104 if (!strcmp("m", keyword)) {
00105 mass = strtod(val, NULL);
00106 break;
00107 }
00108 goto other;
00109
00110 case 'r':
00111
00112
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
00123
00124 if (!strcmp("real_system_time", keyword)) {
00125
00126
00127
00128
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
00140
00141 if (!strcmp("system_time", keyword)) {
00142
00143
00144
00145
00146
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
00167
00168 if (!strcmp("S", keyword)) {
00169
00170
00171
00172
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
00184
00185
00186
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
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
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
00233
00234 temperature = read_unformatted32_real( s );
00235 luminosity = read_unformatted32_real( s );
00236 break;
00237 }
00238
00239
00240
00241 if (!strcmp("T", keyword)) {
00242 temperature = strtod(val, NULL);
00243 break;
00244 }
00245 goto other;
00246
00247 case 'v':
00248
00249
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
00263
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
00283
00284
00285
00286 switch(keyword[0]) {
00287 case 'a':
00288
00289
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
00300
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
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
00333
00334
00335
00336 if (reading_root) {
00337
00338 if (!strcmp("center_pos", keyword)) {
00339 set_vector_from_input_line(pos, input_line);
00340
00341
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
00375
00376 if (!strcmp("defunct", keyword)) {
00377 defunct = true;
00378 break;
00379 }
00380 goto other;
00381
00382 case 'e':
00383
00384
00385
00386 if (!strcmp("esc", keyword)) {
00387
00388
00389
00390
00391
00392
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
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
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
00425
00426 if (!strcmp("L", keyword)) {
00427 luminosity = strtod(val, NULL);
00428 break;
00429 }
00430 goto other;
00431
00432 case 'm':
00433
00434
00435
00436 if (!strcmp("m", keyword)) {
00437 mass = strtod(val, NULL);
00438 break;
00439 }
00440 goto other;
00441
00442 case 'r':
00443
00444
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
00455
00456 if (!strcmp("real_system_time", keyword)) {
00457
00458
00459
00460
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
00472
00473 if (!strcmp("system_time", keyword)) {
00474
00475
00476
00477
00478
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
00499
00500 if (!strcmp("S", keyword)) {
00501
00502
00503
00504
00505
00506 stellar_type = strtol(val, NULL, 10);
00507 break;
00508 }
00509 goto other;
00510
00511 case 't':
00512
00513
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
00527
00528
00529
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
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
00562
00563 read_unformatted_vector( s, tmp );
00564 read_unformatted_vector( s, tmp );
00565
00566 }
00567 break;
00568 }
00569
00570
00571
00572 if (!strcmp("t_esc", keyword)) {
00573
00574
00575
00576
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
00590
00591 temperature = read_unformatted32_real( s );
00592 luminosity = read_unformatted32_real( s );
00593 break;
00594 }
00595
00596
00597
00598 if (!strcmp("T", keyword)) {
00599 temperature = strtod(val, NULL);
00600 break;
00601 }
00602 goto other;
00603
00604 case 'v':
00605
00606
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
00620
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);
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,
00644 int short_output)
00645 {
00646
00647
00648 dyn::print_dyn_story(s, print_xreal, short_output);
00649
00650
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
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669 ostream & tdyn::print_dyn_story(ostream & s,
00670 bool print_xreal,
00671 int short_output)
00672 {
00673
00674
00675
00676
00677
00678 if (parent) print_local_time(time, s, print_xreal, short_output);
00679
00680
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