source: trunk/FACT++/sofa/src/d2tf.c@ 18368

Last change on this file since 18368 was 18346, checked in by tbretz, 11 years ago
File size: 7.1 KB
Line 
1#include "sofa.h"
2
3void iauD2tf(int ndp, double days, char *sign, int ihmsf[4])
4/*
5** - - - - - - - -
6** i a u D 2 t f
7** - - - - - - - -
8**
9** Decompose days to hours, minutes, seconds, fraction.
10**
11** This function is part of the International Astronomical Union's
12** SOFA (Standards Of Fundamental Astronomy) software collection.
13**
14** Status: vector/matrix support function.
15**
16** Given:
17** ndp int resolution (Note 1)
18** days double interval in days
19**
20** Returned:
21** sign char '+' or '-'
22** ihmsf int[4] hours, minutes, seconds, fraction
23**
24** Notes:
25**
26** 1) The argument ndp is interpreted as follows:
27**
28** ndp resolution
29** : ...0000 00 00
30** -7 1000 00 00
31** -6 100 00 00
32** -5 10 00 00
33** -4 1 00 00
34** -3 0 10 00
35** -2 0 01 00
36** -1 0 00 10
37** 0 0 00 01
38** 1 0 00 00.1
39** 2 0 00 00.01
40** 3 0 00 00.001
41** : 0 00 00.000...
42**
43** 2) The largest positive useful value for ndp is determined by the
44** size of days, the format of double on the target platform, and
45** the risk of overflowing ihmsf[3]. On a typical platform, for
46** days up to 1.0, the available floating-point precision might
47** correspond to ndp=12. However, the practical limit is typically
48** ndp=9, set by the capacity of a 32-bit int, or ndp=4 if int is
49** only 16 bits.
50**
51** 3) The absolute value of days may exceed 1.0. In cases where it
52** does not, it is up to the caller to test for and handle the
53** case where days is very nearly 1.0 and rounds up to 24 hours,
54** by testing for ihmsf[0]=24 and setting ihmsf[0-3] to zero.
55**
56** This revision: 2013 June 18
57**
58** SOFA release 2015-02-09
59**
60** Copyright (C) 2015 IAU SOFA Board. See notes at end.
61*/
62{
63 int nrs, n;
64 double rs, rm, rh, a, w, ah, am, as, af;
65
66/* Handle sign. */
67 *sign = (char) ( ( days >= 0.0 ) ? '+' : '-' );
68
69/* Interval in seconds. */
70 a = DAYSEC * fabs(days);
71
72/* Pre-round if resolution coarser than 1s (then pretend ndp=1). */
73 if (ndp < 0) {
74 nrs = 1;
75 for (n = 1; n <= -ndp; n++) {
76 nrs *= (n == 2 || n == 4) ? 6 : 10;
77 }
78 rs = (double) nrs;
79 w = a / rs;
80 a = rs * dnint(w);
81 }
82
83/* Express the unit of each field in resolution units. */
84 nrs = 1;
85 for (n = 1; n <= ndp; n++) {
86 nrs *= 10;
87 }
88 rs = (double) nrs;
89 rm = rs * 60.0;
90 rh = rm * 60.0;
91
92/* Round the interval and express in resolution units. */
93 a = dnint(rs * a);
94
95/* Break into fields. */
96 ah = a / rh;
97 ah = dint(ah);
98 a -= ah * rh;
99 am = a / rm;
100 am = dint(am);
101 a -= am * rm;
102 as = a / rs;
103 as = dint(as);
104 af = a - as * rs;
105
106/* Return results. */
107 ihmsf[0] = (int) ah;
108 ihmsf[1] = (int) am;
109 ihmsf[2] = (int) as;
110 ihmsf[3] = (int) af;
111
112 return;
113
114/*----------------------------------------------------------------------
115**
116** Copyright (C) 2015
117** Standards Of Fundamental Astronomy Board
118** of the International Astronomical Union.
119**
120** =====================
121** SOFA Software License
122** =====================
123**
124** NOTICE TO USER:
125**
126** BY USING THIS SOFTWARE YOU ACCEPT THE FOLLOWING SIX TERMS AND
127** CONDITIONS WHICH APPLY TO ITS USE.
128**
129** 1. The Software is owned by the IAU SOFA Board ("SOFA").
130**
131** 2. Permission is granted to anyone to use the SOFA software for any
132** purpose, including commercial applications, free of charge and
133** without payment of royalties, subject to the conditions and
134** restrictions listed below.
135**
136** 3. You (the user) may copy and distribute SOFA source code to others,
137** and use and adapt its code and algorithms in your own software,
138** on a world-wide, royalty-free basis. That portion of your
139** distribution that does not consist of intact and unchanged copies
140** of SOFA source code files is a "derived work" that must comply
141** with the following requirements:
142**
143** a) Your work shall be marked or carry a statement that it
144** (i) uses routines and computations derived by you from
145** software provided by SOFA under license to you; and
146** (ii) does not itself constitute software provided by and/or
147** endorsed by SOFA.
148**
149** b) The source code of your derived work must contain descriptions
150** of how the derived work is based upon, contains and/or differs
151** from the original SOFA software.
152**
153** c) The names of all routines in your derived work shall not
154** include the prefix "iau" or "sofa" or trivial modifications
155** thereof such as changes of case.
156**
157** d) The origin of the SOFA components of your derived work must
158** not be misrepresented; you must not claim that you wrote the
159** original software, nor file a patent application for SOFA
160** software or algorithms embedded in the SOFA software.
161**
162** e) These requirements must be reproduced intact in any source
163** distribution and shall apply to anyone to whom you have
164** granted a further right to modify the source code of your
165** derived work.
166**
167** Note that, as originally distributed, the SOFA software is
168** intended to be a definitive implementation of the IAU standards,
169** and consequently third-party modifications are discouraged. All
170** variations, no matter how minor, must be explicitly marked as
171** such, as explained above.
172**
173** 4. You shall not cause the SOFA software to be brought into
174** disrepute, either by misuse, or use for inappropriate tasks, or
175** by inappropriate modification.
176**
177** 5. The SOFA software is provided "as is" and SOFA makes no warranty
178** as to its use or performance. SOFA does not and cannot warrant
179** the performance or results which the user may obtain by using the
180** SOFA software. SOFA makes no warranties, express or implied, as
181** to non-infringement of third party rights, merchantability, or
182** fitness for any particular purpose. In no event will SOFA be
183** liable to the user for any consequential, incidental, or special
184** damages, including any lost profits or lost savings, even if a
185** SOFA representative has been advised of such damages, or for any
186** claim by any third party.
187**
188** 6. The provision of any version of the SOFA software under the terms
189** and conditions specified herein does not imply that future
190** versions will also be made available under the same terms and
191** conditions.
192*
193** In any published work or commercial product which uses the SOFA
194** software directly, acknowledgement (see www.iausofa.org) is
195** appreciated.
196**
197** Correspondence concerning SOFA software should be addressed as
198** follows:
199**
200** By email: sofa@ukho.gov.uk
201** By post: IAU SOFA Center
202** HM Nautical Almanac Office
203** UK Hydrographic Office
204** Admiralty Way, Taunton
205** Somerset, TA1 2DN
206** United Kingdom
207**
208**--------------------------------------------------------------------*/
209}
Note: See TracBrowser for help on using the repository browser.