FACT++  1.0
int eraUt1utc ( double  ut11,
double  ut12,
double  dut1,
double *  utc1,
double *  utc2 
)

Definition at line 3 of file ut1utc.c.

References eraCal2jd(), eraDat(), eraJd2cal(), ERFA_DAYSEC, i, and id.

Referenced by t_ut1utc().

68 {
69  int big1;
70  int i, iy, im, id, js;
71  double duts, u1, u2, d1, dats1, d2, fd, dats2, ddats, us1, us2, du;
72 
73 /* UT1-UTC in seconds. */
74  duts = dut1;
75 
76 /* Put the two parts of the UT1 into big-first order. */
77  big1 = ( ut11 >= ut12 );
78  if ( big1 ) {
79  u1 = ut11;
80  u2 = ut12;
81  } else {
82  u1 = ut12;
83  u2 = ut11;
84  }
85 
86 /* See if the UT1 can possibly be in a leap-second day. */
87  d1 = u1;
88  dats1 = 0;
89  for ( i = -1; i <= 3; i++ ) {
90  d2 = u2 + (double) i;
91  if ( eraJd2cal(d1, d2, &iy, &im, &id, &fd) ) return -1;
92  js = eraDat(iy, im, id, 0.0, &dats2);
93  if ( js < 0 ) return -1;
94  if ( i == - 1 ) dats1 = dats2;
95  ddats = dats2 - dats1;
96  if ( fabs(ddats) >= 0.5 ) {
97 
98  /* Yes, leap second nearby: ensure UT1-UTC is "before" value. */
99  if ( ddats * duts >= 0 ) duts -= ddats;
100 
101  /* UT1 for the start of the UTC day that ends in a leap. */
102  if ( eraCal2jd(iy, im, id, &d1, &d2) ) return -1;
103  us1 = d1;
104  us2 = d2 - 1.0 + duts/ERFA_DAYSEC;
105 
106  /* Is the UT1 after this point? */
107  du = u1 - us1;
108  du += u2 - us2;
109  if ( du > 0 ) {
110 
111  /* Yes: fraction of the current UTC day that has elapsed. */
112  fd = du * ERFA_DAYSEC / ( ERFA_DAYSEC + ddats );
113 
114  /* Ramp UT1-UTC to bring about ERFA's JD(UTC) convention. */
115  duts += ddats * ( fd <= 1.0 ? fd : 1.0 );
116  }
117 
118  /* Done. */
119  break;
120  }
121  dats1 = dats2;
122  }
123 
124 /* Subtract the (possibly adjusted) UT1-UTC from UT1 to give UTC. */
125  u2 -= duts / ERFA_DAYSEC;
126 
127 /* Result, safeguarding precision. */
128  if ( big1 ) {
129  *utc1 = u1;
130  *utc2 = u2;
131  } else {
132  *utc1 = u2;
133  *utc2 = u1;
134  }
135 
136 /* Status. */
137  return js;
138 
139 }
int i
Definition: db_dim_client.c:21
char id[4]
Definition: FITS.h:71
#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
int eraCal2jd(int iy, int im, int id, double *djm0, double *djm)
Definition: cal2jd.c:3

+ Here is the call graph for this function:

+ Here is the caller graph for this function: