File: xplanet.cc

package info (click to toggle)
xplanet 0.43-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 904 kB
  • ctags: 321
  • sloc: cpp: 3,041; sh: 1,977; makefile: 141
file content (167 lines) | stat: -rw-r--r-- 4,833 bytes parent folder | download
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
/******************************************************************************
    Xplanet 0.43 - render an image of the earth into an X window
    Copyright (C) 1999 Hari Nair <hari@alumni.caltech.edu>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

******************************************************************************/

#include <iostream.h>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "auxfiles.h"
#include "image.h"
#include "options.h"
#include "planet.h"
#include "text.h"
#include "util.h"

double sunlon, sunlat, sundist; 

extern void sunpos (double &sunlon, double &sunlat, double &sundist, 
		    double T);
extern void moonpos (double &moonlon, double &moonlat, double &moondist,
		     double T);
extern void doAnimate (int argc, char **argv);

int 
main (int argc, char **argv)
{ 
  process_args (argc, argv);

  double T = jcentury (opts.time.tv_sec);
  sunpos (sunlon, sunlat, sundist, T);
  double eps = compute_obliquity (T);

  double alpha, delta;    // Solar right ascension & declination

  if (opts.body == 0)    // Earth
    {
      compute_ra_dec (sunlon, sunlat, alpha, delta, eps);
      //  set sunlon and sunlat to subsolar longitude/latitude
      sunlon = TWO_PI * (alpha - gmst (T, opts.time.tv_sec)) / 24;
      sunlat = delta;

      if (opts.localtime <= 24)
	{
	  double currgmt = (gmtime (&opts.time.tv_sec)->tm_hour 
			    + gmtime (&opts.time.tv_sec)->tm_min/60.
			    + gmtime (&opts.time.tv_sec)->tm_sec/3600.);
	  opts.obslon = (opts.localtime - currgmt) * M_PI / 12;
	  if (opts.obslon < 0 || opts.obslon > TWO_PI) {
	    opts.obslon = fmod (opts.obslon, TWO_PI);
	    if (opts.obslon < 0) opts.obslon += TWO_PI;
	  }
	}
    }
  else 
    {
      planet planet (T, opts.body);
      if (opts.body == 3)
	{
	  planet.helio.lon = sunlon + M_PI;
	  planet.helio.lat = sunlat;
	  planet.helio.dist = sundist;
	}
      else
	planet.calc_helio ();

      coordinates subsolar = planet.calc_coordinates (planet.helio, eps);
      sunlon = subsolar.lon;
      sunlat = subsolar.lat;

      if (flipped) opts.obslon *= -1;  

      if (opts.position == EARTHSIDE)
	{
	  if (opts.body == 3)
	    moonpos (planet.geo.lon, planet.geo.lat, planet.geo.dist, T);
	  else
	    planet.calc_geo ();

	  coordinates subearth = planet.calc_coordinates (planet.geo, eps);
	  opts.rotate += subearth.dist;       // position angle of north pole 
	  opts.obslon = subearth.lon;   
	  opts.obslon -= subearth.alpha;      // correction for light_time
	  opts.obslat = subearth.lat;
	}

      if (opts.localtime <= 24)
	{
	  opts.obslon = sunlon + opts.localtime * M_PI / 12 - M_PI;
	  if (fabs(opts.obslon) > TWO_PI)
	    opts.obslon = fmod (opts.obslon, TWO_PI);
	  if (opts.obslon < 0) opts.obslon += TWO_PI;
	}
    }

  if (opts.position == SUNREL) 
    {
      /* 
	 if either dellon or dellat is 999 user has explicitly set 
	 lon or lat
      */
      if (opts.dellon != 999) 
	{
	  opts.obslon = sunlon + opts.dellon;
	  if (fabs(opts.obslon) > TWO_PI) 
	    opts.obslon = fmod (opts.obslon, TWO_PI);
	  if (opts.obslon < 0) opts.obslon += TWO_PI;
	}
      if (opts.dellat != 999) 
	{
	  opts.obslat = sunlat + opts.dellat;
	  while(opts.obslat < -M_PI_2) opts.obslat =  -M_PI - opts.obslat;
	  while(opts.obslat > M_PI_2) opts.obslat = M_PI - opts.obslat;
	}
    }
  else if (opts.position == DAYSIDE) 
    {
      opts.obslon = sunlon;
      opts.obslat = sunlat;
    }
  else if (opts.position == NIGHTSIDE) 
    {
      opts.obslon = sunlon + M_PI;
      opts.obslat = -sunlat;
    }
  else if (opts.position == MOONSIDE)
    {
      double moonlon, moonlat, moondist;
      double moonalpha, moondelta;
      moonpos (moonlon, moonlat, moondist, T);
      compute_ra_dec (moonlon, moonlat, moonalpha, moondelta, eps);
      opts.obslon = TWO_PI * (moonalpha - gmst(T, opts.time.tv_sec)) / 24;
      opts.obslat = moondelta;
    }

  init_display ();
  read_image ();
  create_merc ();
  
  if (opts.display == ANIMATE) 
    doAnimate (argc, argv);
  else 
    {
      if (opts.mode == ORTHOGRAPHIC) create_ortho ();
      render_image ();
    }

  exit (EXIT_SUCCESS);
}