1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3     Gpredict: Real-time satellite tracking and orbit prediction program
4 
5     Copyright (C)  2001-2009  Alexandru Csete, OZ9AEC.
6 
7     Authors: Alexandru Csete <oz9aec@gmail.com>
8 
9     Comments, questions and bugreports should be submitted via
10     http://sourceforge.net/projects/gpredict/
11     More details can be found at the project home page:
12 
13             http://gpredict.oz9aec.net/
14 
15     This program is free software; you can redistribute it and/or modify
16     it under the terms of the GNU General Public License as published by
17     the Free Software Foundation; either version 2 of the License, or
18     (at your option) any later version.
19 
20     This program is distributed in the hope that it will be useful,
21     but WITHOUT ANY WARRANTY; without even the implied warranty of
22     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     GNU General Public License for more details.
24 
25     You should have received a copy of the GNU General Public License
26     along with this program; if not, visit http://www.fsf.org/
27 */
28 
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 //#include <sys/time.h>
32 #ifdef HAVE_CONFIG_H
33 #  include <build-config.h>
34 #endif
35 #include "sgpsdp/sgp4sdp4.h"
36 #include "time-tools.h"
37 #include "sat-cfg.h"
38 //#ifdef G_OS_WIN32
39 //#  include "libc_internal.h"
40 //#  include "libc_interface.h"
41 //#endif
42 
43 
44 
45 /** \brief Get the current time.
46  *
47  * Read the system clock and return the current Julian day.
48  */
49 gdouble
get_current_daynum()50 get_current_daynum ()
51 {
52     struct tm utc;
53     //struct timeval tmval;
54     GTimeVal tmval;
55     double daynum;
56 
57     UTC_Calendar_Now (&utc);
58     //gettimeofday (&tmval, NULL);
59     g_get_current_time (&tmval);
60     daynum = Julian_Date (&utc);
61     daynum = daynum + (double)tmval.tv_usec/8.64e+10;
62 
63     return daynum;
64 }
65 
66 int
daynum_to_str(char * s,size_t max,const char * format,gdouble jultime)67 daynum_to_str(char *s, size_t max, const char *format, gdouble jultime){
68     //    printf("Someone called me\n");
69     time_t tim;
70     size_t size=0;
71     tim = (jultime - 2440587.5)*86400.0;
72     if (sat_cfg_get_bool (SAT_CFG_BOOL_USE_LOCAL_TIME))
73         size = strftime (s, max, format, localtime (&tim));
74     else
75         size = strftime (s, max, format, gmtime (&tim));
76 
77     if (size<max)
78         s[size] = '\0';
79     else
80         s[max-1] = '\0';
81     return size;
82 }
83 
84 /* This function calculates the day number from m/d/y. */
85 /* Legacy code no longer in use
86 long
87 get_daynum_from_dmy (int d, int m, int y)
88 {
89 
90     long dn;
91     double mm, yy;
92 
93     if (m<3)
94     {
95         y--;
96         m+=12;
97     }
98 
99     if (y<57)
100         y+=100;
101 
102     yy=(double)y;
103     mm=(double)m;
104     dn=(long)(floor(365.25*(yy-80.0))-floor(19.0+yy/100.0)+floor(4.75+yy/400.0)-16.0);
105     dn+=d+30*m+(long)floor(0.6*mm-0.3);
106 
107     return dn;
108 }
109 */
110