FACT++  1.0
int eraD2dtf ( const char *  scale,
int  ndp,
double  d1,
double  d2,
int *  iy,
int *  im,
int *  id,
int  ihmsf[4] 
)

Definition at line 4 of file d2dtf.c.

References eraD2tf(), eraDat(), eraJd2cal(), ERFA_DAYSEC, and i.

Referenced by t_d2dtf().

77 {
78  int leap;
79  char s;
80  int iy1, im1, id1, js, iy2, im2, id2, ihmsf1[4], i;
81  double a1, b1, fd, dat0, dat12, w, dat24, dleap;
82 
83 /* The two-part JD. */
84  a1 = d1;
85  b1 = d2;
86 
87 /* Provisional calendar date. */
88  js = eraJd2cal(a1, b1, &iy1, &im1, &id1, &fd);
89  if ( js ) return -1;
90 
91 /* Is this a leap second day? */
92  leap = 0;
93  if ( ! strcmp(scale,"UTC") ) {
94 
95  /* TAI-UTC at 0h today. */
96  js = eraDat(iy1, im1, id1, 0.0, &dat0);
97  if ( js < 0 ) return -1;
98 
99  /* TAI-UTC at 12h today (to detect drift). */
100  js = eraDat(iy1, im1, id1, 0.5, &dat12);
101  if ( js < 0 ) return -1;
102 
103  /* TAI-UTC at 0h tomorrow (to detect jumps). */
104  js = eraJd2cal(a1+1.5, b1-fd, &iy2, &im2, &id2, &w);
105  if ( js ) return -1;
106  js = eraDat(iy2, im2, id2, 0.0, &dat24);
107  if ( js < 0 ) return -1;
108 
109  /* Any sudden change in TAI-UTC (seconds). */
110  dleap = dat24 - (2.0*dat12 - dat0);
111 
112  /* If leap second day, scale the fraction of a day into SI. */
113  leap = (dleap != 0.0);
114  if (leap) fd += fd * dleap/ERFA_DAYSEC;
115  }
116 
117 /* Provisional time of day. */
118  eraD2tf ( ndp, fd, &s, ihmsf1 );
119 
120 /* Has the (rounded) time gone past 24h? */
121  if ( ihmsf1[0] > 23 ) {
122 
123  /* Yes. We probably need tomorrow's calendar date. */
124  js = eraJd2cal(a1+1.5, b1-fd, &iy2, &im2, &id2, &w);
125  if ( js ) return -1;
126 
127  /* Is today a leap second day? */
128  if ( ! leap ) {
129 
130  /* No. Use 0h tomorrow. */
131  iy1 = iy2;
132  im1 = im2;
133  id1 = id2;
134  ihmsf1[0] = 0;
135  ihmsf1[1] = 0;
136  ihmsf1[2] = 0;
137 
138  } else {
139 
140  /* Yes. Are we past the leap second itself? */
141  if ( ihmsf1[2] > 0 ) {
142 
143  /* Yes. Use tomorrow but allow for the leap second. */
144  iy1 = iy2;
145  im1 = im2;
146  id1 = id2;
147  ihmsf1[0] = 0;
148  ihmsf1[1] = 0;
149  ihmsf1[2] = 0;
150 
151  } else {
152 
153  /* No. Use 23 59 60... today. */
154  ihmsf1[0] = 23;
155  ihmsf1[1] = 59;
156  ihmsf1[2] = 60;
157  }
158 
159  /* If rounding to 10s or coarser always go up to new day. */
160  if ( ndp < 0 && ihmsf1[2] == 60 ) {
161  iy1 = iy2;
162  im1 = im2;
163  id1 = id2;
164  ihmsf1[0] = 0;
165  ihmsf1[1] = 0;
166  ihmsf1[2] = 0;
167  }
168  }
169  }
170 
171 /* Results. */
172  *iy = iy1;
173  *im = im1;
174  *id = id1;
175  for ( i = 0; i < 4; i++ ) {
176  ihmsf[i] = ihmsf1[i];
177  }
178 
179 /* Status. */
180  return js;
181 
182 }
int i
Definition: db_dim_client.c:21
#define ERFA_DAYSEC
Definition: erfam.h:75
int eraJd2cal(double dj1, double dj2, int *iy, int *im, int *id, double *fd)
Definition: jd2cal.c:3
int eraDat(int iy, int im, int id, double fd, double *deltat)
Definition: dat.c:3
void eraD2tf(int ndp, double days, char *sign, int ihmsf[4])
Definition: d2tf.c:3

+ Here is the call graph for this function:

+ Here is the caller graph for this function: