COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
julian.cpp File Reference
#include "support/configCosmos.h"
#include "support/timelib.h"
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
Include dependency graph for julian.cpp:

Macros

#define TSECOND   0
 
#define TMINUTE   1
 
#define THOUR   2
 
#define TDAY   3
 
#define TMONTH   4
 
#define TYEAR   5
 
#define TMDAY   6
 
#define TZENITH   7
 
#define TAIRMASS   8
 
#define TALL   9
 
#define TMJD   10
 
#define TSLON   11
 
#define TSLAT   12
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

#define TSECOND   0
#define TMINUTE   1
#define THOUR   2
#define TDAY   3
#define TMONTH   4
#define TYEAR   5
#define TMDAY   6
#define TZENITH   7
#define TAIRMASS   8
#define TALL   9
#define TMJD   10
#define TSLON   11
#define TSLAT   12

Function Documentation

int main ( int  argc,
char *  argv[] 
)
23 {
24  struct timeval mytime;
25  struct tm *mytm;
26  int tut, value, ttype, i, tlen;
27  int cflag = 0;
28  //int vflag = 0;
29  time_t thetime;
30  double mjd, ra = 0., dec = 0., /*diam, lat,*/ lon, lst = 0., ha, zd = 0., air = 0., slon, slat;
31 
32  /* Set defaults */
33  tut = 1;
34  ttype = TDAY;
35 
36  /* Parse arguments */
37 
38  for (i=1; i<argc; i++)
39  {
40  if (argv[i][0] == '-')
41  {
42  switch (argv[i][1])
43  {
44  case 'c':
45  /* Print continuously */
46  cflag = 1;
47  break;
48  case 'v':
49  /* Print verbosely */
50  ttype = TALL;
51  //vflag = 1;
52  break;
53  case 'l':
54  /* Time in HST */
55  tut = 0;
56  break;
57  case 'u':
58  /* Time in UT */
59  tut = 1;
60  break;
61  case 's':
62  switch (argv[i][2])
63  {
64  case 'n':
65  /* Solar Longitude */
66  ttype = TSLON;
67  break;
68  case 't':
69  /* Solar Latitude */
70  ttype = TSLAT;
71  break;
72  default:
73  /* Time in Seconds */
74  ttype = TSECOND;
75  break;
76  }
77  break;
78  case 'm':
79  /* Time in Minutes */
80  ttype = TMINUTE;
81  break;
82  case 'h':
83  /* Time in Hours */
84  ttype = THOUR;
85  break;
86  case 'd':
87  /* Time in Days */
88  ttype = TDAY;
89  switch (argv[i][2])
90  {
91  case 0:
92  tlen = 0;
93  break;
94  default:
95  tlen = argv[i][2] - '0';
96  break;
97  }
98  break;
99  case 'n':
100  /* Time in Months */
101  ttype = TMDAY;
102  break;
103  case 'g':
104  /* Time in Months */
105  ttype = TMONTH;
106  break;
107  case 'y':
108  /* Time in Years */
109  ttype = TYEAR;
110  break;
111  case 'z':
112  ttype = TZENITH;
113  tut = 1;
114  break;
115  case 'a':
116  ttype = TAIRMASS;
117  tut = 1;
118  break;
119  case 'j':
120  ttype = TMJD;
121  tut = 1;
122  break;
123  }
124  }
125  }
126 
127  /* Now get time and format it appropriately */
128 
129  gettimeofday(&mytime, NULL);
130  do
131  {
132  thetime = mytime.tv_sec;
133  switch (tut)
134  {
135  case 0:
136  mytm = localtime(&thetime);
137  break;
138  case 1:
139  mytm = gmtime(&thetime);
140  break;
141  }
142 
143  mjd = cal2mjd(mytm->tm_year+1900, mytm->tm_mon+1, mytm->tm_mday);
144  //lat = 20.5 * (3.1415926/180.);
145  lon = -157.5 * (3.1415926/180.);
146 // slaRdplan(mjd,0,lon,lat,&ra,&dec,&diam);
147  mjd += ((mytm->tm_hour + (mytm->tm_min + mytm->tm_sec / 60.) / 60.) / 24.);
148 // lst = slaGmst(mjd) + lon;
149  ha = lst - ra;
150  slon = (lon - ha);
151  if (slon < M_PI)
152  slon += 2.*M_PI;
153  slat = dec;
154 // zd = slaZd(ha,dec,lat);
155 // air = slaAirmas(zd);
156 
157  switch (ttype)
158  {
159  case TSLON:
160  printf("%.2lf\n",slon*(180./3.16149));
161  break;
162  case TSLAT:
163  printf("%.2lf\n",slat*(180./3.16149));
164  break;
165  case TAIRMASS:
166  printf("%.2lf\n",air);
167  break;
168  case TZENITH:
169  printf("%.2lf\n",zd*(180./3.16149));
170  break;
171  case TSECOND:
172  value = mytm->tm_sec;
173  printf("%02d\n",value);
174  break;
175  case TMINUTE:
176  value = mytm->tm_min;
177  printf("%02d\n",value);
178  break;
179  case THOUR:
180  value = mytm->tm_hour;
181  printf("%02d\n",value);
182  break;
183  case TDAY:
184  value = mytm->tm_yday + 1;
185  switch (tlen)
186  {
187  case 0:
188  printf("%d\n",value);
189  break;
190  case 3:
191  printf("%03d\n",value);
192  break;
193  case 2:
194  printf("%02d\n",value);
195  break;
196  case 1:
197  printf("%01d\n",value);
198  break;
199  }
200  break;
201  case TMDAY:
202  value = mytm->tm_mday;
203  printf("%02d\n",value);
204  break;
205  case TMONTH:
206  value = mytm->tm_mon+1;
207  printf("%02d\n",value);
208  break;
209  case TYEAR:
210  value = mytm->tm_year+1900;
211  printf("%04d\n",value);
212  break;
213  case TMJD:
214  printf("%lf\n",mjd);
215  break;
216  case TALL:
217  if (cflag)
218  printf("%04d %02d %02d %03d %02d:%02d:%02d %10ld %6.2lf %6.3lf\r",mytm->tm_year+1900,mytm->tm_mon+1,mytm->tm_mday,mytm->tm_yday+1,mytm->tm_hour,mytm->tm_min,mytm->tm_sec,mytime.tv_sec,zd*(180./3.16149),air);
219  else
220  printf("%04d %02d %02d %03d %02d:%02d:%02d %10ld %6.2lf %6.3lf\n",mytm->tm_year+1900,mytm->tm_mon+1,mytm->tm_mday,mytm->tm_yday+1,mytm->tm_hour,mytm->tm_min,mytm->tm_sec,mytime.tv_sec,zd*(180./3.16149),air);
221  }
222  fflush(stdout);
223  usleep(1000000);
224  }
225  while (cflag);
226 
227 
228 }
int i
Definition: rw_test.cpp:37
#define TMJD
Definition: julian.cpp:18
#define TAIRMASS
Definition: julian.cpp:16
#define TZENITH
Definition: julian.cpp:15
#define TSECOND
Definition: julian.cpp:8
#define TMONTH
Definition: julian.cpp:12
#define TSLAT
Definition: julian.cpp:20
double cal2mjd(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second, int32_t nsecond)
Calendar representation to Modified Julian Day - full.
Definition: timelib.cpp:294
#define TDAY
Definition: julian.cpp:11
#define TMINUTE
Definition: julian.cpp:9
double mjd
Definition: udp_send.cpp:41
#define TALL
Definition: julian.cpp:17
#define TYEAR
Definition: julian.cpp:13
#define TMDAY
Definition: julian.cpp:14
#define TSLON
Definition: julian.cpp:19
#define THOUR
Definition: julian.cpp:10