forked from omega13a/stargen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
554 lines (528 loc) · 22.7 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include "Planetary_Habitability_Laboratory.h"
#include "andromeda.h"
#include "dole.h"
#include "elements.h"
#include "ic3094.h"
#include "jimb.h"
#include "omega_galaxy.h"
#include "PerformanceMonitor.h"
#include "planets.h"
#include "radius_tables.h"
#include "ring_universe.h"
#include "solstation.h"
#include "star_trek.h"
#include "stargen.h"
#include "structs.h"
#include "utils.h"
using namespace std;
void initData();
void usage(string);
void printAknowledgement() {
cout << "Web systems (-W) taken from\n"
<< "\thttp://www.solstation.com/stars.htm, Wikipedia, and various research papers\n"
<< "AU systems (-F) taken from stories by C.J. Cherry\n"
<< "Manticore systems (-B) taken from stories by David Weber\n"
<< "StarGen: " << stargen_revision << endl;
}
void printExamples() {
cout << "Examples:\n"
"10000 systems with 1 as the seed for the first system around a\n"
"custom star with moons and migrated planets and only save ones with "
"an earthlike planet:\n\n"
"stargen -m1.09 -y1.12609 -BG0V -b6215 -M -r -s1 -n10000 -E\n\n"
"10000 systems with 1 as the seed for the first system around a\n"
"custom star in a circumbinary system with moons and migrated "
"planets and only save ones with an earthlike planet:\n\n"
"stargen -m1.09 -y1.12609 -BG0V -b6215 -CB -w0.75 -j0.178473 -X4493 -NK3V "
"-d0.11146 -f0.011 -M -r -s1 -n10000 -E\n\n"
"10000 systems with 1 as the seed for the first system around a predefined star:\n\n"
"stargen -W73 -M -r -s1 -n10000 -E\n\n"
"10000 systems with 1 as the seed for the first system around a\n"
"custom star with a distant companion star with moons and migrated "
"planets and only save ones with an earthlike planet:\n\n"
"stargen -m1.09 -y1.12609 -BG0V -b6215 -w0.75 -d1114.6 -f0.011 -M -r -s1 -n10000 -E\n\n";
}
int main(int argc, char **argv) {
actions action = aGenerate;
string flag_char = "?";
string path = SUBDIR;
string url_path_arg = "";
string filename_arg = "";
string arg_name = "";
char arg_name_temp[80] = "";
bool use_stdout = false;
string prognam;
long double mass_arg = 0.0;
long double luminosity_arg = 0.0;
long seed_arg = 0;
int count_arg = 1;
int increment_arg = 1;
catalog star_catalog;
int sys_no_arg = 0;
long double ratio_arg = 0.0;
long double ecc_coef_arg = 0.077; // seb: dole value
long double inner_planet_factor_arg = 0.3; // seb: dole value
int flags_arg = 0;
int out_format = ffHTML;
int graphic_format = gfGIF;
const char *c;
bool skip = false;
int index = 0;
string temp_string;
#ifdef macintosh
_ftype = 'TEXT';
_fcreator = 'R*ch';
argc = ccommand(&argv);
#endif
initData();
prognam = argv[0];
if ((c = strrchr(prognam.c_str(), DIRSEP[0])) != nullptr) {
prognam = c + 1;
}
if (argc <= 1) {
usage(prognam);
return EXIT_FAILURE;
}
// need to somehow parse arguments
bool first_part_of_name = true;
for (int i = 0; i < argc; i++) {
skip = false;
temp_string = argv[i];
if (compare_string_char(temp_string, 0, "-")) {
if (compare_string_char(temp_string, 1, "-")) {
use_stdout = true;
} else if (compare_string_char(temp_string, 1, "PHL", 3)) {
star_catalog = phl;
if (temp_string.length() > 2) {
sys_no_arg = atoi(temp_string.substr(4, temp_string.length() - 4).c_str());
} else {
sys_no_arg = 0;
}
flag_char = star_catalog.getArg();
} else if (compare_string_char(temp_string, 1, "sn", 2)) {
decimals_arg = atoi(temp_string.substr(3, temp_string.length() - 3).c_str());
} else if (compare_string_char(temp_string, 1, "CB", 2)) {
flags_arg |= fIsCircubinaryStar;
} else if (compare_string_char(temp_string, 1, "MY", 2)) {
max_age_backup = max_age = atof(temp_string.substr(3, temp_string.length() - 3).c_str());
} else if (compare_string_char(temp_string, 1, "md", 2)) {
max_distance_arg = atof(temp_string.substr(3, temp_string.length() - 3).c_str());
} else if (compare_string_char(temp_string, 1, "s")) {
seed_arg = atol(temp_string.substr(2, temp_string.length() - 2).c_str());
// skip = true;
} else if (compare_string_char(temp_string, 1, "m")) {
mass_arg = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
// skip = true;
} else if (compare_string_char(temp_string, 1, "y")) {
luminosity_arg = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
// skip = true;
} else if (compare_string_char(temp_string, 1, "Y")) {
min_age = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
// skip = true;
} else if (compare_string_char(temp_string, 1, "n")) {
count_arg = atoi(temp_string.substr(2, temp_string.length() - 2).c_str());
// skip = true;
} else if (compare_string_char(temp_string, 1, "i")) {
increment_arg = atoi(temp_string.substr(2, temp_string.length() - 2).c_str());
// skip = true;
} else if (compare_string_char(temp_string, 1, "x")) {
flag_char = temp_string.substr(1, 1).c_str();
flags_arg |= fUseSolarsystem;
if (mass_arg == 0.0) mass_arg = 1.0;
} else if (compare_string_char(temp_string, 1, "a") &&
!compare_string_char(temp_string, 2, "k")) {
flag_char = temp_string.substr(1, 1).c_str();
flags_arg |= fReuseSolarsystem;
break;
} else if (compare_string_char(temp_string, 1, "D") ||
compare_string_char(temp_string, 1, "W") ||
compare_string_char(temp_string, 1, "F") ||
compare_string_char(temp_string, 1, "O") ||
compare_string_char(temp_string, 1, "R") ||
compare_string_char(temp_string, 1, "I") ||
compare_string_char(temp_string, 1, "U") ||
compare_string_char(temp_string, 1, "G")) {
if (compare_string_char(temp_string, 1, "D")) {
star_catalog = dole;
} else if (compare_string_char(temp_string, 1, "W")) {
star_catalog = solstation;
} else if (compare_string_char(temp_string, 1, "F")) {
star_catalog = jimb;
} else if (compare_string_char(temp_string, 1, "O")) {
star_catalog = omega_galaxy;
} else if (compare_string_char(temp_string, 1, "R")) {
star_catalog = ring_universe;
} else if (compare_string_char(temp_string, 1, "I")) {
star_catalog = ic3094;
} else if (compare_string_char(temp_string, 1, "U")) {
star_catalog = andromeda;
} else if (compare_string_char(temp_string, 1, "G")) {
star_catalog = star_trek;
}
if (temp_string.length() > 2) {
sys_no_arg = atoi(temp_string.substr(2, temp_string.length() - 2).c_str());
} else {
sys_no_arg = 0;
}
flag_char = star_catalog.getArg();
// skip = true;
} else if (compare_string_char(temp_string, 1, "o")) {
filename_arg = argv[i + 1];
skip = true;
} else if (compare_string_char(temp_string, 1, "t")) {
out_format = ffTEXT;
} else if (compare_string_char(temp_string, 1, "ex", 2)) {
printExamples();
return 0;
} else if (compare_string_char(temp_string, 1, "e") &&
!compare_string_char(temp_string, 2, "x")) {
out_format = ffCSV;
} else if (compare_string_char(temp_string, 1, "C")) {
out_format = ffCSVdl;
} else if (compare_string_char(temp_string, 1, "c")) {
out_format = ffCELESTIA;
} else if (compare_string_char(temp_string, 1, "J") &&
compare_string_char(temp_string, 2, "S")) {
out_format = ffJSON;
}
/*else if (compare_string_char(temp_string, 1, "P"))
{
out_format = ffMOONGEN;
}*/
else if (compare_string_char(temp_string, 1, "V")) {
graphic_format = gfSVG;
} else if (compare_string_char(temp_string, 1, "S")) {
graphic_format = gfSVG;
out_format = ffSVG;
} else if (compare_string_char(temp_string, 1, "k")) {
flags_arg |= fUseKnownPlanets;
} else if (compare_string_char(temp_string, 1, "K")) {
flags_arg |= fUseKnownPlanets | fNoGenerate;
} else if (compare_string_char(temp_string, 1, "path")) {
path = argv[i + 1];
skip = true;
} else if (compare_string_char(temp_string, 1, "u")) {
url_path_arg = argv[i + 1];
skip = true;
} else if (compare_string_char(temp_string, 1, "g")) {
flags_arg |= fDoGases;
} else if (compare_string_char(temp_string, 1, "v")) {
if (temp_string.length() > 2) {
sscanf(temp_string.substr(2, temp_string.length() - 2).c_str(), "%x", &flag_verbose);
if (flag_verbose & 0x0001) {
flags_arg |= fDoGases;
}
// skip = true;
} else {
action = aListVerbosity;
}
} else if (compare_string_char(temp_string, 1, "l")) {
action = aListCatalog;
} else if (compare_string_char(temp_string, 1, "L")) {
action = aListCatalogAsHTML;
} else if (compare_string_char(temp_string, 1, "z")) {
action = aSizeCheck;
} else if (compare_string_char(temp_string, 1, "Z")) {
action = aListGases;
} else if (compare_string_char(temp_string, 1, "M")) {
flags_arg |= fDoMoons;
} else if (compare_string_char(temp_string, 1, "r")) {
flags_arg |= fDoMigration;
} else if (compare_string_char(temp_string, 1, "ak", 2)) {
printAknowledgement();
return 0;
} else if (compare_string_char(temp_string, 1, "H")) {
flags_arg |= fDoGases | fOnlyHabitable;
} else if (compare_string_char(temp_string, 1, "2")) {
flags_arg |= fDoGases | fOnlyMultiHabitable;
} else if (compare_string_char(temp_string, 1, "3")) {
flags_arg |= fDoGases | fOnlyThreeHabitable;
} else if (compare_string_char(temp_string, 1, "J")) {
flags_arg |= fDoGases | fOnlyJovianHabitable;
} else if (compare_string_char(temp_string, 1, "E")) {
flags_arg |= fDoGases | fOnlyEarthlike;
} else if (compare_string_char(temp_string, 1, "P")) {
flags_arg |= fDoGases | fOnlyPotentialHabitable;
} else if (compare_string_char(temp_string, 1, "A")) {
ratio_arg = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
if (ratio_arg <= 0.0) {
cout << "Accrete dust density coefficient -A (" << ratio_arg << ") must be > 0.0\n";
return EXIT_FAILURE;
}
// skip = true;
} else if (compare_string_char(temp_string, 1, "Q")) {
ecc_coef_arg = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
if (ecc_coef_arg <= 0.0) {
cout << "Accrete eccentricity coeffecient -Q (" << ecc_coef_arg << ") must be > 0.0\n";
return EXIT_FAILURE;
}
// skip = true;
} else if (compare_string_char(temp_string, 1, "q")) {
inner_planet_factor_arg = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
if (inner_planet_factor_arg <= 0.0) {
cout << "Accrete inner dust boundary -q (" << inner_planet_factor_arg
<< ") must be > 0.0\n";
return EXIT_FAILURE;
}
// skip = true;
} else if (compare_string_char(temp_string, 1, "w")) {
compainion_mass_arg = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
if (compainion_mass_arg <= 0.0) {
cout << "Mass of compainion object -w (" << compainion_mass_arg << ") must be > 0.0\n";
return EXIT_FAILURE;
}
// skip = true;
} else if (compare_string_char(temp_string, 1, "f")) {
compainion_eccentricity_arg = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
if (compainion_eccentricity_arg <= 0.0) {
cout << "Eccentritiy of compainion object's orbit (" << compainion_eccentricity_arg
<< ") must be > 0.0\n";
return EXIT_FAILURE;
}
// skip = true;
} else if (compare_string_char(temp_string, 1, "d")) {
compainion_distant_arg = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
if (compainion_distant_arg <= 0.0) {
cout << "Distance of compainion object -d (" << compainion_distant_arg
<< ") must be > 0.0\n";
return EXIT_FAILURE;
}
// skip = true;
} else if (compare_string_char(temp_string, 1, "b")) {
temp_arg = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
if (temp_arg <= 0.0) {
cout << "Temperature of star -b (" << temp_arg << ") must be > 0.0" << endl;
return EXIT_FAILURE;
}
// skip = true;
} else if (compare_string_char(temp_string, 1, "B")) {
type_arg = temp_string.substr(2, temp_string.length() - 2).c_str();
// skip = true;
} else if (compare_string_char(temp_string, 1, "j")) {
compainion_lum_arg = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
if (compainion_lum_arg <= 0.0) {
cout << "Luminosity of companion star j (" << compainion_lum_arg << ") must be > 0.0\n";
return EXIT_FAILURE;
}
// skip = true;
} else if (compare_string_char(temp_string, 1, "X")) {
compainion_eff_arg = atof(temp_string.substr(2, temp_string.length() - 2).c_str());
if (compainion_eff_arg <= 0.0) {
cout << "Temperature of companion star X (" << compainion_lum_arg << ") must be > 0.0\n";
return EXIT_FAILURE;
}
// skip = true;
} else if (compare_string_char(temp_string, 1, "N")) {
companion_spec_arg = temp_string.substr(2, temp_string.length() - 2).c_str();
// skip = true;
} else if (compare_string_char(temp_string, 1, "h")) {
usage(prognam);
return EXIT_FAILURE;
} else if (compare_string_char(temp_string, 1, "p") &&
!compare_string_char(temp_string, 2, "ath")) {
performanceMonitor.setEnabled(true);
} else {
usage(prognam);
return EXIT_FAILURE;
}
} else if (temp_string != prognam) {
if (first_part_of_name) {
first_part_of_name = false;
arg_name = temp_string;
} else {
arg_name.append(" ");
arg_name.append(temp_string);
}
}
if (skip) {
i++;
}
}
// cout << arg_name << " blada\n";
/*for (index = 0; index < argc; index++)
{
if ((strlen(argv[index]) + arg_name.length()) < arg_name.size())
{
if (arg_name.length())
arg_name = " ";
arg_name = argv[index];
}
if ((strlen(argv[index]) + strlen(arg_name_temp)) < sizeof(arg_name_temp))
{
if (strlen(arg_name_temp))
{
strcpy(arg_name_temp + strlen(arg_name_temp), " ");
}
strcpy(arg_name_temp + strlen(arg_name_temp), argv[index]);
}
}
arg_name = arg_name_temp;*/
if (use_stdout) {
if (flags_arg &
(fOnlyHabitable | fOnlyMultiHabitable | fOnlyJovianHabitable | fOnlyEarthlike)) {
if (count_arg > 50000) {
cout << "Sorry, you cannot set the Repeat count > 50,000 even if you "
"use a filter, due to system resource issues."
<< endl;
return EXIT_FAILURE;
}
} else {
if (count_arg > 1000) {
cout << "Sorry, you cannot set the Repeat count > 1,000 unless you use "
"a filter, due to system resource issues."
<< endl;
return EXIT_FAILURE;
}
}
}
flags_arg_clone = flags_arg;
ZoneScoped;
return stargen(action, flag_char, path, url_path_arg, filename_arg, arg_name, prognam, mass_arg,
luminosity_arg, seed_arg, count_arg, increment_arg, star_catalog, sys_no_arg,
ratio_arg, ecc_coef_arg, inner_planet_factor_arg, flags_arg, out_format,
graphic_format);
}
/**
* @brief Initialize Data
*
*/
void initData() {
initRadii();
initGases();
initPlanets();
initDole();
initSolStation();
initJimb();
initOmegaGalaxy();
initRingUniverse();
initIC3094();
initAndromeda();
initStarTrek();
initPlanetaryHabitabilityLaboratory();
}
void usage(string program) {
cout << "Usage: " << program
<< " [options] [system name]\n"
" Options:\n"
"Seed values:\n"
" -s# Set random number seed [default: from time]\n"
" -i# Number to increment each random seed [default: 1]\n"
" -n# Specify number of systems [default: 1]\n"
" -A# set accretion dust density ratio_arg to # [default: 0.0]\n"
" -q# set accretion inner dust border to # [default: 0.3]\n"
" -Q# set accretion planetesimal seed eccentricity coefficient "
"to # [default: 0.077]\n"
"Preset seeds:\n"
" -k Use known planets as planitesimal seeds [from internal "
"tables]\n"
" -K Generate only known planets [from internal tables]\n"
" -x Use the Solar System's masses/orbits\n"
" -a Use the Solar System's masses/orbits varying Earth\n"
"Stars:\n"
"\tPlease note that for a custom star, you need to specify a mass "
"and/or a luminosity\n\tas well as a spectral type and/or a temperature. Other wise the "
"program will not work.\n"
" -m# Specify stellar mass # [fraction of Sun's mass] (optional "
"if -y is used)\n"
" -y# Specify stellar luminosity # [fraction of Sun's "
"luminosity] (optional if -m is used)\n"
" -Y# Specify minimum age for star (years) (optional)\n"
" -MY# Specify maximum age for star (years) (optional)\n"
" -b# The temperature of the star (optional if -B is used)\n"
" -B Spectral type of the star (optional if -b is used)\n"
" -CB Make this a circumbinary system like Tatoonine in Star "
"Wars (optional)\n"
" -w# The mass of a companion star (optional and required if the "
"-CB option is used)\n"
" -j# The luminosity of a companion star (optional and required "
"if the -CB option is used)\n"
" -X# The temperature of a companion star (optional and required "
"if the -CB option is used)\n"
" -N Spectral type of the companion star (optional and required "
"if the -CB option is used)\n"
" -d# The distance to a companion star (optional and required if "
"the -CB option is used)\n"
" -f# The eccentricity of the orbit of the companion star "
"(optional and required if the -CB option is used)\n"
" For a predefined star:\n"
" -D Use all of Dole's "
<< dole.count()
<< " nearby stars\n"
" -D# Use Dole's system #\n"
" -F Use all "
<< jimb.count()
<< " AU systems\n"
" -F# Use AU system #\n"
" -W Use all "
<< solstation.count()
<< " nearby stars taken from the Web\n"
" -W# Use Web system #\n"
" -O Use all "
<< omega_galaxy.count()
<< " fictious stars in the fictious Omega Galaxy\n"
" -O# Use Omega Galaxy system #\n"
" -R Use all "
<< ring_universe.count()
<< " fictious stars in the fictious Ring Universe galaxy\n"
" -R# Use Ring Universe system #\n"
" -I Use all "
<< ic3094.count()
<< " fictious stars in IC 3094 that cham generated\n"
" -I# Use IC 3094 system #\n"
" -U Use all "
<< andromeda.count()
<< " fictious stars in the Andromeda Galaxy that cham generated\n"
" -U# Use Andromeda Galaxy system #\n"
" -G Use the "
<< star_trek.count()
<< " predefined stars from Star Trek\n"
" -G# Use Star Trek system #\n"
" -PHL Use the "
<< phl.count()
<< " predefined stars listed at the Planetary Habitability Library\n"
" -PHL#Use potentially habitable system #\n"
" -l List stars of selected table and exit\n"
" -L List stars of selected table as HTML and exit\n"
"Filters:\n"
" Please note that these options are only usefull if you are making\n"
"\ta large batch of systems and only want to save certain ones.\n"
" -E Only systems with earthlike planets\n"
" -H Only systems with habitable planets\n"
" -2 Only systems with 2 or more habitable planets\n"
" -3 Only systems with 3 or more habitable planets\n"
" -T Only systems with habitable planets more than 2 Earth "
"Masses in size\n"
" -P Only systems with planets habitable by the Planetary "
"Habitability Laboratory's criteria\n"
" -J Only systems with Jovian planets in habitable region\n"
" -g Include atmospheric gases\n"
" -v List verbosities [hex values] and exit\n"
" -v# Set output verbosity [hex value]\n"
" -V Use vector graphics [SVG] images [default: GIF]\n"
" -z Do numeric size check and exit\n"
" -Z Dump tables used for gases and exit\n"
"File specs:\n"
" -- use stdout\n"
" -o Name for the output file(s) [default: taken from star name]\n"
" -p Path for where the output file(s) are saved [default: ./html]\n"
" -u Internet URL path for/in the output file(s) [default: none]\n"
"Output formats: (only one is generated) default HTML to file\n"
" -c Celestia .ssc to stdout\n"
" -C Excel .csv [dl: no thumbnail html] to file\n"
" -JS JSON .json [dl: no thumbnail html] to file\n"
" -e Excel .csv to file\n"
" -S Vector graphics (SVG) to file\n"
" -t Text to stdout\n"
" -sn# Number of decimal places for numbers\n"
"Other:\n"
" -M Generate moons (highly experimental and incomplete)\n"
" -r Allow planet migration after forming. (highly experimental)\n"
" -p Enable performance monitoring\n"
" -ak Acknowledgement\n"
" -ex Examples\n";
}