source: branches/FACT++_lidctrl_usb/erfa/src/tf2d.c@ 19185

Last change on this file since 19185 was 18711, checked in by tbretz, 8 years ago
Updated to ERFA 1.3.0 (no relevant code change except the leap second at the beginning of 2017)
File size: 4.5 KB
Line 
1#include "erfa.h"
2#include <stdlib.h>
3
4int eraTf2d(char s, int ihour, int imin, double sec, double *days)
5/*
6** - - - - - - - -
7** e r a T f 2 d
8** - - - - - - - -
9**
10** Convert hours, minutes, seconds to days.
11**
12** Given:
13** s char sign: '-' = negative, otherwise positive
14** ihour int hours
15** imin int minutes
16** sec double seconds
17**
18** Returned:
19** days double interval in days
20**
21** Returned (function value):
22** int status: 0 = OK
23** 1 = ihour outside range 0-23
24** 2 = imin outside range 0-59
25** 3 = sec outside range 0-59.999...
26**
27** Notes:
28**
29** 1) The result is computed even if any of the range checks fail.
30**
31** 2) Negative ihour, imin and/or sec produce a warning status, but
32** the absolute value is used in the conversion.
33**
34** 3) If there are multiple errors, the status value reflects only the
35** first, the smallest taking precedence.
36**
37** Copyright (C) 2013-2016, NumFOCUS Foundation.
38** Derived, with permission, from the SOFA library. See notes at end of file.
39*/
40{
41
42/* Compute the interval. */
43 *days = ( s == '-' ? -1.0 : 1.0 ) *
44 ( 60.0 * ( 60.0 * ( (double) abs(ihour) ) +
45 ( (double) abs(imin) ) ) +
46 fabs(sec) ) / ERFA_DAYSEC;
47
48/* Validate arguments and return status. */
49 if ( ihour < 0 || ihour > 23 ) return 1;
50 if ( imin < 0 || imin > 59 ) return 2;
51 if ( sec < 0.0 || sec >= 60.0 ) return 3;
52 return 0;
53
54}
55/*----------------------------------------------------------------------
56**
57**
58** Copyright (C) 2013-2016, NumFOCUS Foundation.
59** All rights reserved.
60**
61** This library is derived, with permission, from the International
62** Astronomical Union's "Standards of Fundamental Astronomy" library,
63** available from http://www.iausofa.org.
64**
65** The ERFA version is intended to retain identical functionality to
66** the SOFA library, but made distinct through different function and
67** file names, as set out in the SOFA license conditions. The SOFA
68** original has a role as a reference standard for the IAU and IERS,
69** and consequently redistribution is permitted only in its unaltered
70** state. The ERFA version is not subject to this restriction and
71** therefore can be included in distributions which do not support the
72** concept of "read only" software.
73**
74** Although the intent is to replicate the SOFA API (other than
75** replacement of prefix names) and results (with the exception of
76** bugs; any that are discovered will be fixed), SOFA is not
77** responsible for any errors found in this version of the library.
78**
79** If you wish to acknowledge the SOFA heritage, please acknowledge
80** that you are using a library derived from SOFA, rather than SOFA
81** itself.
82**
83**
84** TERMS AND CONDITIONS
85**
86** Redistribution and use in source and binary forms, with or without
87** modification, are permitted provided that the following conditions
88** are met:
89**
90** 1 Redistributions of source code must retain the above copyright
91** notice, this list of conditions and the following disclaimer.
92**
93** 2 Redistributions in binary form must reproduce the above copyright
94** notice, this list of conditions and the following disclaimer in
95** the documentation and/or other materials provided with the
96** distribution.
97**
98** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
99** the International Astronomical Union nor the names of its
100** contributors may be used to endorse or promote products derived
101** from this software without specific prior written permission.
102**
103** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
104** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
105** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
106** FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
107** COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
108** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
109** BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
110** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
111** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
112** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
113** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
114** POSSIBILITY OF SUCH DAMAGE.
115**
116*/
Note: See TracBrowser for help on using the repository browser.