home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / misc / sci / accrete / src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-02  |  4.6 KB  |  141 lines

  1. #ifndef AMIGA
  2. #pragma keep "Accrete"
  3. #pragma debug 0     /* Don't generate debug code */
  4. #pragma memorymodel 0   /* Use small memorymodel */
  5. #pragma optimize -1 /* If you do not optimize you will run out of memory */
  6. #endif /* AMIGA */
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <math.h>
  11. #include <stddef.h>
  12. #include <stdlib.h>
  13. #ifdef AMIGA
  14. #ifdef HUGE_VAL
  15. #undef HUGE_VAL
  16. #endif /* HUGE_VAL */
  17. #endif /* AMIGA */
  18. #include <float.h>
  19. #include <time.h>
  20.  
  21. #include "const.h"
  22. #include "structs.h"
  23. #include "accrete.h"
  24.  
  25.  
  26. /*  These are all of the global variables used during accretion:  */
  27. float anum;
  28. planet_pointer planet_head;
  29. double stellar_mass_ratio, stellar_luminosity_ratio, main_seq_life;
  30. double age, r_ecosphere, r_greenhouse, radians_per_rotation;
  31. int spin_resonance;
  32.  
  33.  
  34. #ifndef APPLE
  35. /*
  36.  * init() - initialize random number generator
  37.  *
  38.  * As compared to the original code which follows, this generates much
  39.  * better random numbers, due to the greater integer precision of machines
  40.  * with an architecture larger than the 6502
  41.  *
  42.  */
  43. void init()
  44. {
  45.     time_t t;
  46.     struct tm trec;
  47.  
  48.     t = time(NULL);
  49.     trec = *localtime(&t);
  50.     t = t / trec.tm_min;
  51.     t = t * trec.tm_sec;
  52.  
  53.     srand(t);
  54. }
  55. #else 
  56. void init()
  57. {                       /* This code gets the random number seed */
  58. time_t t;               /* from the seconds on the clock. It is  */
  59. struct tm trec;         /* from page 316 of the Orca/C manual.   */
  60.                         /* The origional code gave srand as 25,  */
  61. t = time(NULL);         /* this is much more random.             */
  62. trec = *localtime(&t);
  63. srand (trec.tm_sec);
  64. }
  65. #endif /* APPLE */
  66.  
  67. void generate_stellar_system()
  68. {
  69.      planet_pointer planet;
  70.      radians_per_rotation = 2.0 * PI;
  71.      stellar_mass_ratio = random_number(0.6,1.3);
  72.      stellar_luminosity_ratio = luminosity(stellar_mass_ratio);
  73.      planet = distribute_planetary_masses(stellar_mass_ratio, stellar_luminosity_ratio, 0.0, stellar_dust_limit(stellar_mass_ratio));
  74.      main_seq_life = 1.0E10 * (stellar_mass_ratio / stellar_luminosity_ratio);
  75.      if ((main_seq_life >= 6.0E9))
  76.       age = random_number(1.0E9,6.0E9);
  77.      else 
  78.       age = random_number(1.0E9,main_seq_life);
  79.      r_ecosphere = sqrt(stellar_luminosity_ratio);
  80.      r_greenhouse = r_ecosphere * GREENHOUSE_EFFECT_CONST;
  81.      while (planet != NULL)
  82.      {
  83.       planet->orbit_zone = orbital_zone(planet->a);
  84.       if (planet->gas_giant)
  85.       {
  86.            planet->density = empirical_density(planet->mass,planet->a,planet->gas_giant);
  87.            planet->radius = volume_radius(planet->mass,planet->density);
  88.       }
  89.       else 
  90.       {
  91.            planet->radius = kothari_radius(planet->mass,planet->a,planet->gas_giant,planet->orbit_zone);
  92.            planet->density = volume_density(planet->mass,planet->radius);
  93.       }
  94.       planet->orbital_period = period(planet->a,planet->mass,stellar_mass_ratio);
  95.       planet->day = day_length(planet->mass,planet->radius,planet->orbital_period,planet->e,planet->gas_giant);
  96.       planet->resonant_period = spin_resonance;
  97.       planet->axial_tilt = inclination(planet->a);
  98.       planet->escape_velocity = escape_vel(planet->mass,planet->radius);
  99.       planet->surface_accel = acceleration(planet->mass,planet->radius);
  100.       planet->rms_velocity = rms_vel(MOLECULAR_NITROGEN,planet->a);
  101.       planet->molecule_weight = molecule_limit(planet->a,planet->mass,planet->radius);
  102.       if ((planet->gas_giant))
  103.       {
  104.            planet->surface_grav = INCREDIBLY_LARGE_NUMBER;
  105.            planet->greenhouse_effect = FALSE;
  106.            planet->volatile_gas_inventory = INCREDIBLY_LARGE_NUMBER;
  107.            planet->surface_pressure = INCREDIBLY_LARGE_NUMBER;
  108.            planet->boil_point = INCREDIBLY_LARGE_NUMBER;
  109.            planet->hydrosphere = INCREDIBLY_LARGE_NUMBER;
  110.            planet->albedo = about(GAS_GIANT_ALBEDO,0.1);
  111.            planet->surface_temp = INCREDIBLY_LARGE_NUMBER;
  112.       }
  113.       else 
  114.       {
  115.            planet->surface_grav = gravity(planet->surface_accel);
  116.            planet->greenhouse_effect = greenhouse(planet->orbit_zone,planet->a,r_greenhouse);
  117.            planet->volatile_gas_inventory = vol_inventory(planet->mass,planet->escape_velocity,planet->rms_velocity,stellar_mass_ratio,planet->orbit_zone,planet->greenhouse_effect);
  118.            planet->surface_pressure = pressure(planet->volatile_gas_inventory,planet->radius,planet->surface_grav);
  119.            if ((planet->surface_pressure == 0.0))
  120.             planet->boil_point = 0.0;
  121.            else 
  122.             planet->boil_point = boiling_point(planet->surface_pressure);
  123.            iterate_surface_temp(&(planet));
  124.       }
  125.       planet = planet->next_planet;
  126.      }
  127.      display_system( );
  128. }
  129.  
  130.  
  131. void main ()
  132. {
  133.      init();
  134.      generate_stellar_system();
  135. #ifndef VERBOSE
  136. # ifndef SILENT
  137.      printf("\nDone.\n");
  138. # endif /* SILENT */
  139. #endif /* VERBOSE */
  140. }
  141.