This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
195 lines (179 loc) · 6.69 KB
/
main.c
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
#include <stdio.h>
#include <math.h>
#include <sys/types.h>
#include <sys/timeb.h>
#ifdef MSDOS
#include <stddef.h>
#include <malloc.h>
#include <stdlib.h>
#include <float.h>
#endif
#include "const.h"
#include "structs.h"
/* These are all of the global variables used during accretion: */
planet_pointer first_planet;
#ifdef MOON
planet_pointer first_moon;
#endif /* MOON */
double stellar_mass_ratio, stellar_luminosity_ratio, main_seq_life,
age, ecosphere_radius, greenhouse_radius;
int flag_verbose=FALSE;
long flag_seed=FALSE;
int flag_lisp = FALSE;
int flag_graphics = FALSE;
int resonance;
/* externals from C library not elsewhere declared: */
extern void srand();
extern double random_number();
extern double luminosity();
extern double stellar_dust_limit();
extern planet_pointer distribute_planetary_masses();
extern int orbital_zone();
extern double empirical_density();
extern double volume_density();
extern double volume_radius();
extern double kothari_radius();
extern double period();
extern double day_length();
extern int inclination();
extern double escape_vel();
extern double acceleration();
extern double rms_vel();
extern double molecule_limit();
extern double about();
extern int greenhouse();
extern double gravity();
extern double vol_inventory();
extern double pressure();
extern double boiling_point();
#ifdef MOON
extern planet_pointer distribute_moon_masses();
extern double planet_dust_limit();
#endif /* MOON */
void init()
{
struct timeb grap;
int seed;
if (flag_seed) {
(void)srand(flag_seed);
if (flag_lisp)
printf("(Accrete %s) ; seed: 0x%.8lx\n", "3.0", flag_seed);
else
printf("Accrete - V%s; seed=0x%.8lx\n", "3.0", flag_seed);
} else {
/* the random number seed from starform didn't work */
/* ftime(&grap); */
/* seed = (int)((grap.time%100000)+grap.millitm); */
seed = time(NULL);
(void)srand(seed);
if (flag_lisp)
printf("(Accrete %s) ; seed: 0x%.8lx\n", "3.0", seed);
else
printf("Accrete - V%s; seed=0x%.8lx\n", "3.0", seed);
}
}
void generate_stellar_system()
{
planet_pointer planet;
double outer_dust_limit;
stellar_mass_ratio = random_number(0.6,1.3);
stellar_luminosity_ratio = luminosity(stellar_mass_ratio);
ecosphere_radius = sqrt(stellar_luminosity_ratio);
greenhouse_radius = ecosphere_radius * GREENHOUSE_EFFECT_CONST;
main_seq_life = 1.0E10 * (stellar_mass_ratio / stellar_luminosity_ratio);
if ((main_seq_life >= 6.0E9))
age = random_number(1.0E9,6.0E9);
else
age = random_number(1.0E9,main_seq_life);
outer_dust_limit = stellar_dust_limit(stellar_mass_ratio);
first_planet = distribute_planetary_masses(stellar_mass_ratio,stellar_luminosity_ratio,0.0,outer_dust_limit);
for (planet=first_planet; planet != NULL; planet = planet->next_planet)
{
#ifdef MOON
planet->first_moon = distribute_moon_masses (planet->mass, stellar_luminosity_ratio,
planet->e, 0.0, planet_dust_limit(planet->mass));
#endif /* MOON */
planet->orbit_zone = orbital_zone(planet->a);
if (planet->gas_giant)
{
planet->density = empirical_density(planet->mass,planet->a,planet->gas_giant);
planet->radius = volume_radius(planet->mass,planet->density);
} else {
planet->radius = kothari_radius(planet->mass,planet->gas_giant,planet->orbit_zone);
planet->density = volume_density(planet->mass,planet->radius);
}
planet->orbital_period = period(planet->a,planet->mass,stellar_mass_ratio);
planet->day = day_length(planet->mass,planet->radius,planet->e,
planet->density, planet->a, planet->orbital_period,planet->gas_giant);
planet->resonant_period = resonance;
planet->axial_tilt = inclination(planet->a);
planet->escape_velocity = escape_vel(planet->mass,planet->radius);
planet->surface_accel = acceleration(planet->mass,planet->radius);
planet->rms_velocity = rms_vel(MOLECULAR_NITROGEN,planet->a);
planet->molecule_weight = molecule_limit(planet->mass,planet->radius);
if ((planet->gas_giant))
{
planet->surface_grav = INCREDIBLY_LARGE_NUMBER;
planet->greenhouse_effect = FALSE;
planet->volatile_gas_inventory = INCREDIBLY_LARGE_NUMBER;
planet->surface_pressure = INCREDIBLY_LARGE_NUMBER;
planet->boil_point = INCREDIBLY_LARGE_NUMBER;
planet->hydrosphere = INCREDIBLY_LARGE_NUMBER;
planet->albedo = about(GAS_GIANT_ALBEDO,0.1);
planet->surf_temp = INCREDIBLY_LARGE_NUMBER;
} else {
planet->surface_grav = gravity(planet->surface_accel);
planet->greenhouse_effect = greenhouse(planet->orbit_zone,planet->a,greenhouse_radius);
planet->volatile_gas_inventory = vol_inventory(planet->mass,
planet->escape_velocity,planet->rms_velocity,stellar_mass_ratio,
planet->orbit_zone,planet->greenhouse_effect);
planet->surface_pressure = pressure(planet->volatile_gas_inventory,planet->radius,planet->surface_grav);
if ((planet->surface_pressure == 0.0))
planet->boil_point = 0.0;
else
planet->boil_point = boiling_point(planet->surface_pressure);
iterate_surface_temp(&(planet));
}
}
display_system(first_planet);
}
main (argc, argv)
int argc;
char *argv[];
{
char *c, *prognam;
int skip;
prognam = argv[0];
while (--argc > 0 && (*++argv)[0] == '-') {
for (c = argv[0]+1, skip=FALSE; (*c != '\0') && (!(skip)); c++)
switch (*c)
{
case 'l': /* set lisp output */
++flag_lisp;
break;
case 'g': /* display graphically */
++flag_graphics;
break;
case 's': /* set random seed */
flag_seed = atoi(&(*++c));
skip = TRUE;
break;
case 'v': /* increment verbosity */
++flag_verbose;
break;
default:
case '?':
fprintf(stderr, "%s: Usage: %s [-l] [-g] [-s#] [-v]\n",
prognam, prognam);
fprintf(stderr, "\t-l Lisp-style output\n");
fprintf(stderr, "\t-g Display graphically\n");
fprintf(stderr, "\t-s# Set seed for random number generator\n");
fprintf(stderr, "\t-v Increment verbosity\n");
fprintf(stderr, "\t-h Echo usage information\n");
return (1);
} /* end switch */
} /* end while */
init();
generate_stellar_system();
return(0);
}