source: trunk/FACT++/sofa/src/tf2d.c@ 18346

Last change on this file since 18346 was 18346, checked in by tbretz, 9 years ago
File size: 5.9 KB
Line 
1#include "sofa.h"
2#include <stdlib.h>
3
4int iauTf2d(char s, int ihour, int imin, double sec, double *days)
5/*
6** - - - - - - - -
7** i a u T f 2 d
8** - - - - - - - -
9**
10** Convert hours, minutes, seconds to days.
11**
12** This function is part of the International Astronomical Union's
13** SOFA (Standards of Fundamental Astronomy) software collection.
14**
15** Status: support function.
16**
17** Given:
18** s char sign: '-' = negative, otherwise positive
19** ihour int hours
20** imin int minutes
21** sec double seconds
22**
23** Returned:
24** days double interval in days
25**
26** Returned (function value):
27** int status: 0 = OK
28** 1 = ihour outside range 0-23
29** 2 = imin outside range 0-59
30** 3 = sec outside range 0-59.999...
31**
32** Notes:
33**
34** 1) The result is computed even if any of the range checks fail.
35**
36** 2) Negative ihour, imin and/or sec produce a warning status, but
37** the absolute value is used in the conversion.
38**
39** 3) If there are multiple errors, the status value reflects only the
40** first, the smallest taking precedence.
41**
42** This revision: 2013 June 18
43**
44** SOFA release 2015-02-09
45**
46** Copyright (C) 2015 IAU SOFA Board. See notes at end.
47*/
48{
49
50/* Compute the interval. */
51 *days = ( s == '-' ? -1.0 : 1.0 ) *
52 ( 60.0 * ( 60.0 * ( (double) abs(ihour) ) +
53 ( (double) abs(imin) ) ) +
54 fabs(sec) ) / DAYSEC;
55
56/* Validate arguments and return status. */
57 if ( ihour < 0 || ihour > 23 ) return 1;
58 if ( imin < 0 || imin > 59 ) return 2;
59 if ( sec < 0.0 || sec >= 60.0 ) return 3;
60 return 0;
61
62/*----------------------------------------------------------------------
63**
64** Copyright (C) 2015
65** Standards Of Fundamental Astronomy Board
66** of the International Astronomical Union.
67**
68** =====================
69** SOFA Software License
70** =====================
71**
72** NOTICE TO USER:
73**
74** BY USING THIS SOFTWARE YOU ACCEPT THE FOLLOWING SIX TERMS AND
75** CONDITIONS WHICH APPLY TO ITS USE.
76**
77** 1. The Software is owned by the IAU SOFA Board ("SOFA").
78**
79** 2. Permission is granted to anyone to use the SOFA software for any
80** purpose, including commercial applications, free of charge and
81** without payment of royalties, subject to the conditions and
82** restrictions listed below.
83**
84** 3. You (the user) may copy and distribute SOFA source code to others,
85** and use and adapt its code and algorithms in your own software,
86** on a world-wide, royalty-free basis. That portion of your
87** distribution that does not consist of intact and unchanged copies
88** of SOFA source code files is a "derived work" that must comply
89** with the following requirements:
90**
91** a) Your work shall be marked or carry a statement that it
92** (i) uses routines and computations derived by you from
93** software provided by SOFA under license to you; and
94** (ii) does not itself constitute software provided by and/or
95** endorsed by SOFA.
96**
97** b) The source code of your derived work must contain descriptions
98** of how the derived work is based upon, contains and/or differs
99** from the original SOFA software.
100**
101** c) The names of all routines in your derived work shall not
102** include the prefix "iau" or "sofa" or trivial modifications
103** thereof such as changes of case.
104**
105** d) The origin of the SOFA components of your derived work must
106** not be misrepresented; you must not claim that you wrote the
107** original software, nor file a patent application for SOFA
108** software or algorithms embedded in the SOFA software.
109**
110** e) These requirements must be reproduced intact in any source
111** distribution and shall apply to anyone to whom you have
112** granted a further right to modify the source code of your
113** derived work.
114**
115** Note that, as originally distributed, the SOFA software is
116** intended to be a definitive implementation of the IAU standards,
117** and consequently third-party modifications are discouraged. All
118** variations, no matter how minor, must be explicitly marked as
119** such, as explained above.
120**
121** 4. You shall not cause the SOFA software to be brought into
122** disrepute, either by misuse, or use for inappropriate tasks, or
123** by inappropriate modification.
124**
125** 5. The SOFA software is provided "as is" and SOFA makes no warranty
126** as to its use or performance. SOFA does not and cannot warrant
127** the performance or results which the user may obtain by using the
128** SOFA software. SOFA makes no warranties, express or implied, as
129** to non-infringement of third party rights, merchantability, or
130** fitness for any particular purpose. In no event will SOFA be
131** liable to the user for any consequential, incidental, or special
132** damages, including any lost profits or lost savings, even if a
133** SOFA representative has been advised of such damages, or for any
134** claim by any third party.
135**
136** 6. The provision of any version of the SOFA software under the terms
137** and conditions specified herein does not imply that future
138** versions will also be made available under the same terms and
139** conditions.
140*
141** In any published work or commercial product which uses the SOFA
142** software directly, acknowledgement (see www.iausofa.org) is
143** appreciated.
144**
145** Correspondence concerning SOFA software should be addressed as
146** follows:
147**
148** By email: sofa@ukho.gov.uk
149** By post: IAU SOFA Center
150** HM Nautical Almanac Office
151** UK Hydrographic Office
152** Admiralty Way, Taunton
153** Somerset, TA1 2DN
154** United Kingdom
155**
156**--------------------------------------------------------------------*/
157}
Note: See TracBrowser for help on using the repository browser.