void generate_stellar_system() { planet_pointer planet; radians_per_rotation = 2.0 * PI; stellar_mass_ratio = random_number(0.6,1.3); stellar_luminosity_ratio = luminosity(stellar_mass_ratio); planet = distribute_planetary_masses(stellar_mass_ratio,stellar_luminosity_ratio,0.0,stellar_dust_limit(stellar_mass_ratio)); 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); r_ecosphere = sqrt(stellar_luminosity_ratio); r_greenhouse = r_ecosphere * GREENHOUSE_EFFECT_CONST; while (planet != NULL) { 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->a,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->orbital_period,planet->e,planet->gas_giant); planet->resonant_period = spin_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->a,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->surface_temp = INCREDIBLY_LARGE_NUMBER; } else { planet->surface_grav = gravity(planet->surface_accel); planet->greenhouse_effect = greenhouse(planet->orbit_zone,planet->a,r_greenhouse); 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)); } planet = planet->next_planet; } display_system( ); }
stellar_system* generate_stellar_system(unsigned long random_seed) { planet* planet; double outer_dust_limit; stellar_system *system = malloc(sizeof(stellar_system)); system->first_planet = NULL; setup_seed(system, random_seed); system->star_mass_r = random_number(0.6, 1.3); /* was 0.6, 1.3 */ system->star_radius_r = about(pow(system->star_mass_r, 1.0 / 3.0), 0.05); /* for some unknown reason, only 3 digits wanted... */ system->star_radius_r = floor(system->star_radius_r * 1000.0) / 1000.0; system->star_lum_r = luminosity(system->star_mass_r); /* luminosity is proportional to T^4 and to area of star */ /* so temp is Tsol * 4th-root ( Lum / r^2 ) */ system->star_temp = 5650 * sqrt(sqrt(system->star_lum_r) / system->star_radius_r); /* ignore fractional degrees */ system->star_temp = floor(system->star_temp); sprintf(system->star_class, "%.16s", find_star_class(system->star_temp)); outer_dust_limit = stellar_dust_limit(system->star_mass_r); system->first_planet = distribute_planetary_masses(system, 0.0, outer_dust_limit); system->main_seq_life = 1.0E10 * (system->star_mass_r / system->star_lum_r); if (system->main_seq_life > 6.0E9) system->star_age = random_number(1.0E9, 6.0E9); else if (system->main_seq_life > 1.0E9) system->star_age = random_number(1.0E9, system->main_seq_life); else system->star_age = random_number(system->main_seq_life/10, system->main_seq_life); system->r_ecosphere = sqrt(system->star_lum_r); system->r_greenhouse = system->r_ecosphere * GREENHOUSE_EFFECT_CONST; for (planet = system->first_planet; planet != NULL; planet = planet->next_planet) { planet->orbit_zone = orbital_zone(system, planet->a); if (planet->gas_giant) { planet->density = empirical_density(system, 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->orb_period = period(planet->a, planet->mass, system->star_mass_r); planet->day = day_length(system, planet->mass, planet->radius, planet->e, planet->density, planet->a, planet->orb_period, planet->gas_giant, system->star_mass_r); planet->resonant_period = system->resonance; planet->axial_tilt = inclination(planet->a); planet->esc_velocity = escape_velocity(planet->mass, planet->radius); planet->surf_accel = acceleration(planet->mass, planet->radius); planet->rms_velocity = rms_velocity(system, MOL_NITROGEN, planet->a); planet->molec_weight = molecule_limit(planet->mass, planet->radius); if ((planet->gas_giant)) { planet->surf_grav = INCREDIBLY_LARGE_NUMBER; planet->greenhouse_effect = false; planet->volatile_gas_inventory = INCREDIBLY_LARGE_NUMBER; planet->surf_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->surf_grav = gravity(planet->surf_accel); planet->greenhouse_effect = greenhouse(planet->orbit_zone, planet->a, system->r_greenhouse); planet->volatile_gas_inventory = vol_inventory(planet->mass, planet->esc_velocity, planet->rms_velocity, system->star_mass_r, planet->orbit_zone, planet->greenhouse_effect); planet->surf_pressure = pressure(planet->volatile_gas_inventory, planet->radius, planet->surf_grav); if (planet->surf_pressure == 0.0) planet->boil_point = 0.0; else planet->boil_point = boiling_point(planet->surf_pressure); iterate_surface_temp(system, &(planet)); } #ifdef MOON if (args.make_moon) { #ifdef PROPER_MOON planet->first_moon = dist_moon_masses(planet->mass, star_lum_r, planet->e, 0.0, planet_dust_limit(planet->mass)); #else planet->first_moon = do_dist_moon_masses(planet->mass, planet->radius); { planet* moon = planet->first_moon; while (moon) { moon->radius = kothari_radius(moon->mass, 0, planet->orbit_zone); moon->density = volume_density(moon->mass, moon->radius); moon->density = random_number(1.5, moon->density * 1.1); if (moon->density < 1.5) moon->density = 1.5; moon->radius = volume_radius(moon->mass, moon->density); moon->orb_period = period(moon->a, moon->mass, planet->mass); moon->day = day_length(system, moon->mass, moon->radius, moon->e, moon->density, moon->a, moon->orb_period, moon->gas_giant, planet->mass); moon->resonant_period = system->resonance; moon->axial_tilt = inclination(moon->a); moon->esc_velocity = escape_vel(moon->mass, moon->radius); moon->surf_accel = acceleration(moon->mass, moon->radius); moon->rms_velocity = rms_vel(system, MOL_NITROGEN, planet->a); moon->molec_weight = molecule_limit(moon->mass, moon->radius); moon->surf_grav = gravity(moon->surf_accel); moon->greenhouse_effect = grnhouse(planet->orbit_zone, planet->a, system->r_greenhouse); moon->volatile_gas_inventory = vol_inventory(moon->mass, moon->esc_velocity, moon->rms_velocity, system->star_mass_r, planet->orbit_zone, moon->greenhouse_effect); moon->surf_pressure = pressure(moon->volatile_gas_inventory, moon->radius, moon->surf_grav); if ((moon->surf_pressure == 0.0)) moon->boil_point = 0.0; else moon->boil_point = boiling_point(moon->surf_pressure); iterate_surface_temp_moon(system, &planet, &moon); moon = moon->next_planet; } } #endif /* CC_MOON */ } #endif /* MOON */ } return system; }
main() { int year,month,day; double lon, lat; double daylen, civlen, nautlen, astrlen; double rise, set, civ_start, civ_end, naut_start, naut_end, astr_start, astr_end; int rs, civ, naut, astr; char buf[80]; printf( "Longitude (+ is east) and latitude (+ is north) : " ); fgets(buf, 80, stdin); sscanf(buf, "%lf %lf", &lon, &lat ); for(;;) { printf( "Input date ( yyyy mm dd ) (ctrl-C exits): " ); fgets(buf, 80, stdin); sscanf(buf, "%d %d %d", &year, &month, &day ); daylen = day_length(year,month,day,lon,lat); civlen = day_civil_twilight_length(year,month,day,lon,lat); nautlen = day_nautical_twilight_length(year,month,day,lon,lat); astrlen = day_astronomical_twilight_length(year,month,day, lon,lat); printf( "Day length: %5.2f hours\n", daylen ); printf( "With civil twilight %5.2f hours\n", civlen ); printf( "With nautical twilight %5.2f hours\n", nautlen ); printf( "With astronomical twilight %5.2f hours\n", astrlen ); printf( "Length of twilight: civil %5.2f hours\n", (civlen-daylen)/2.0); printf( " nautical %5.2f hours\n", (nautlen-daylen)/2.0); printf( " astronomical %5.2f hours\n", (astrlen-daylen)/2.0); rs = sun_rise_set ( year, month, day, lon, lat, &rise, &set ); civ = civil_twilight ( year, month, day, lon, lat, &civ_start, &civ_end ); naut = nautical_twilight ( year, month, day, lon, lat, &naut_start, &naut_end ); astr = astronomical_twilight( year, month, day, lon, lat, &astr_start, &astr_end ); printf( "Sun at south %5.2fh UT\n", (rise+set)/2.0 ); switch( rs ) { case 0: printf( "Sun rises %5.2fh UT, sets %5.2fh UT\n", rise, set ); break; case +1: printf( "Sun above horizon\n" ); break; case -1: printf( "Sun below horizon\n" ); break; } switch( civ ) { case 0: printf( "Civil twilight starts %5.2fh, " "ends %5.2fh UT\n", civ_start, civ_end ); break; case +1: printf( "Never darker than civil twilight\n" ); break; case -1: printf( "Never as bright as civil twilight\n" ); break; } switch( naut ) { case 0: printf( "Nautical twilight starts %5.2fh, " "ends %5.2fh UT\n", naut_start, naut_end ); break; case +1: printf( "Never darker than nautical twilight\n" ); break; case -1: printf( "Never as bright as nautical twilight\n" ); break; } switch( astr ) { case 0: printf( "Astronomical twilight starts %5.2fh, " "ends %5.2fh UT\n", astr_start, astr_end ); break; case +1: printf( "Never darker than astronomical twilight\n" ); break; case -1: printf( "Never as bright as astronomical twilight\n" ); break; } return 0; } }
main() { int year,month,day; double lon, lat; double daylen, civlen, nautlen, astrlen; double rise, set, civ_start, civ_end, naut_start, naut_end, astr_start, astr_end; double daylen_int,daylen_frac; /* CWR */ int rs, civ, naut, astr; int daylen_hours,daylen_min, gmtoff_hr; /* cwr */ double rise_int,rise_frac,set_int,set_frac; int rise_hours,rise_min,set_hours,set_min; time_t the_time; /* only need so can get time zone of local machine... */ struct tm *mylocal_time; char buf[80]; /* get time and offset from GMT */ time(&the_time); mylocal_time = localtime(&the_time); gmtoff_hr = mylocal_time->tm_gmtoff/3600; printf("Enter longitude and latitude in decimal degrees, i.e. -97.75 30.23\n"); printf("Hint: divide minutes by 60 to get decimal portion\n"); printf( "Longitude (+ is east) and latitude (+ is north) : " ); fgets(buf, 80, stdin); sscanf(buf, "%lf %lf", &lon, &lat ); for(;;) { printf( "Input date ( yyyy mm dd ) (ctrl-C exits): " ); fgets(buf, 80, stdin); sscanf(buf, "%d %d %d", &year, &month, &day ); daylen = day_length(year,month,day,lon,lat); civlen = day_civil_twilight_length(year,month,day,lon,lat); nautlen = day_nautical_twilight_length(year,month,day,lon,lat); astrlen = day_astronomical_twilight_length(year,month,day, lon,lat); daylen_frac = modf(daylen,&daylen_int); /* daylen into int and fraction */ daylen_hours = (int)daylen_int; daylen_min = (int)(daylen_frac * 60); printf( "Day length: %5.2f hours", daylen ); printf( "(%2d hours %2d min)\n", daylen_hours,daylen_min ); daylen_frac = modf(civlen,&daylen_int); daylen_hours = (int)daylen_int; daylen_min = (int)(daylen_frac * 60); printf( "With civil twilight %5.2f hours", civlen ); printf( "(%2d hours %2d min)\n", daylen_hours,daylen_min ); daylen_frac = modf(nautlen,&daylen_int); daylen_hours = (int)daylen_int; daylen_min = (int)(daylen_frac * 60); printf( "With nautical twilight %5.2f hours", nautlen ); printf( "(%2d hours %2d min)\n", daylen_hours,daylen_min ); daylen_frac = modf(astrlen,&daylen_int); daylen_hours = (int)daylen_int; daylen_min = (int)(daylen_frac * 60); printf( "With astronomical twilight %5.2f hours", astrlen ); printf( "(%2d hours %2d min)\n", daylen_hours,daylen_min ); daylen_frac = modf((civlen-daylen)/2.0,&daylen_int); daylen_hours = (int)daylen_int; daylen_min = (int)(daylen_frac * 60); printf( "Length of twilight: civil %5.2f hours", (civlen-daylen)/2.0); printf( "(%2d hours %2d min)\n", daylen_hours,daylen_min ); daylen_frac = modf((nautlen-daylen)/2.0,&daylen_int); daylen_hours = (int)daylen_int; daylen_min = (int)(daylen_frac * 60); printf( " nautical %5.2f hours", (nautlen-daylen)/2.0); printf( "(%2d hours %2d min)\n", daylen_hours,daylen_min ); daylen_frac = modf((astrlen-daylen)/2.0,&daylen_int); daylen_hours = (int)daylen_int; daylen_min = (int)(daylen_frac * 60); printf( " astronomical %5.2f hours", (astrlen-daylen)/2.0); printf( "(%2d hours %2d min)\n", daylen_hours,daylen_min ); rs = sun_rise_set ( year, month, day, lon, lat, &rise, &set ); civ = civil_twilight ( year, month, day, lon, lat, &civ_start, &civ_end ); naut = nautical_twilight ( year, month, day, lon, lat, &naut_start, &naut_end ); astr = astronomical_twilight( year, month, day, lon, lat, &astr_start, &astr_end ); daylen_frac = modf(((rise+set)/2.0)+gmtoff_hr ,&daylen_int); daylen_hours = (int)daylen_int; daylen_min = (int)(daylen_frac * 60); printf( "Sun at south %5.2fh UT,%20d:%02d local\n", (rise+set)/2.0,daylen_hours,daylen_min); switch( rs ) { case 0: /* add minutes and local. CWR*/ rise_frac = modf(rise+gmtoff_hr ,&rise_int); rise_hours = (int)rise_int; rise_min = (int)(rise_frac * 60); set_frac = modf(set+gmtoff_hr ,&set_int); set_hours = (int)set_int; set_min = (int)(set_frac * 60); printf( "Sun rises %5.2fh UT, sets %5.2fh UT;\n rises %02d:%02d, sets %02d:%02d local\n", rise, set, rise_hours,rise_min,set_hours,set_min); break; case +1: printf( "Sun above horizon\n" ); break; case -1: printf( "Sun below horizon\n" ); break; } switch( civ ) { case 0: rise_frac = modf(civ_start+gmtoff_hr ,&rise_int); rise_hours = (int)rise_int; rise_min = (int)(rise_frac * 60); set_frac = modf(civ_end+gmtoff_hr ,&set_int); set_hours = (int)set_int; set_min = (int)(set_frac * 60); printf( "Civil twilight starts %5.2fh, " "ends %5.2fh UT;\n starts %02d:%02d, ends %02d:%02d local\n", civ_start, civ_end, rise_hours, rise_min, set_hours, set_min); break; case +1: printf( "Never darker than civil twilight\n" ); break; case -1: printf( "Never as bright as civil twilight\n" ); break; } switch( naut ) { case 0: rise_frac = modf(naut_start+gmtoff_hr ,&rise_int); rise_hours = (int)rise_int; rise_min = (int)(rise_frac * 60); set_frac = modf(naut_end+gmtoff_hr ,&set_int); set_hours = (int)set_int; set_min = (int)(set_frac * 60); printf( "Nautical twilight starts %5.2fh, " "ends %5.2fh UT;\n starts %02d:%02d, ends %02d:%02d local\n", naut_start, naut_end, rise_hours, rise_min, set_hours, set_min ); break; case +1: printf( "Never darker than nautical twilight\n" ); break; case -1: printf( "Never as bright as nautical twilight\n" ); break; } switch( astr ) { case 0: rise_frac = modf(astr_start+gmtoff_hr ,&rise_int); rise_hours = (int)rise_int; rise_min = (int)(rise_frac * 60); set_frac = modf(astr_end+gmtoff_hr ,&set_int); set_hours = (int)set_int; set_min = (int)(set_frac * 60); printf( "Astronomical twilight starts %5.2fh, " "ends %5.2fh UT;\n starts %02d:%02d, ends %02d:%02d local\n", astr_start, astr_end, rise_hours, rise_min, set_hours, set_min ); break; case +1: printf( "Never darker than astronomical twilight\n" ); break; case -1: printf( "Never as bright as astronomical twilight\n" ); break; } return 0; } }
int main (void) { int year, month, day; double lon, lat; double len, rise, set, cur_time; int rc; char ch; time_t t; struct tm *tm; t = time (NULL); tm = gmtime (&t); lon = 0; sun_rise_set (tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, lon, 0.0, &rise, &set); cur_time = tm->tm_hour + tm->tm_min / 60.0; lon += (rise - cur_time) * 15.0; if (lon > 180.0) lon -= 360.0; if (lon < -180.0) lon += 360.0; printf ("==> Sun is rising at longitude %5.2fE, latitude 0.00N\n", lon); printf ("Longitude (+ is east) and latitude (+ is north), or * for Lugano: "); ch = getchar (); if (ch == '*') lon = 8.0 + 57.0/60.0, lat = 46.0; else { ungetc (ch, stdin); while (scanf ("%lf %lf", &lon, &lat) < 2) ; } tm = localtime (&t); year = tm->tm_year + 1900; month = tm->tm_mon + 1; day = tm->tm_mday; do { len = day_length (year, month, day, lon, lat); printf ("==> Day length: %5.2f hours\n", len); rc = sun_rise_set (year, month, day, lon, lat, &rise, &set); if (rc == 1) printf ("==> Sun never sets!\n"); else if (rc == -1) printf ("==> Sun never rises!\n"); else { printf ("==> Midday: %5.2f GMT\n", (rise + set) / 2); printf ("==> Sunrise: %5.2f, Sunset: %5.2f GMT\n", rise, set); } rc = civil_rise_set (year, month, day, lon, lat, &rise, &set); if (rc == 1) printf ("==> Sun never reaches civil dusk!\n"); else if (rc == -1) printf ("==> Sun never reaches civil dawn!\n"); else printf ("==> Civil sunrise: %5.2f, Sunset: %5.2f GMT\n", rise, set); printf ("Date (yyyy mm dd) (ctrl-C exits): "); while (scanf ("%d %d %d", &year, &month, &day) < 3 && !feof (stdin)) ; } while (!feof (stdin)); return 0; }