| 1 | #include "slalib.h"
|
|---|
| 2 | #include "slamac.h"
|
|---|
| 3 | void slaDafin ( char *string, int *iptr, double *a, int *j )
|
|---|
| 4 | /*
|
|---|
| 5 | ** - - - - - - - - -
|
|---|
| 6 | ** s l a D a f i n
|
|---|
| 7 | ** - - - - - - - - -
|
|---|
| 8 | **
|
|---|
| 9 | ** Sexagesimal character string to angle.
|
|---|
| 10 | **
|
|---|
| 11 | ** (double precision)
|
|---|
| 12 | **
|
|---|
| 13 | ** Given:
|
|---|
| 14 | ** string char* string containing deg, arcmin, arcsec fields
|
|---|
| 15 | ** iptr int where to start decode at (1st = 1)
|
|---|
| 16 | **
|
|---|
| 17 | ** Returned:
|
|---|
| 18 | ** iptr int advanced past the decoded angle
|
|---|
| 19 | ** a double angle in radians
|
|---|
| 20 | ** j int status: 0 = OK
|
|---|
| 21 | ** +1 = default, A unchanged
|
|---|
| 22 | ** -1 = bad degrees )
|
|---|
| 23 | ** -2 = bad arcminutes ) (note 3)
|
|---|
| 24 | ** -3 = bad arcseconds )
|
|---|
| 25 | **
|
|---|
| 26 | ** Example:
|
|---|
| 27 | **
|
|---|
| 28 | ** argument before after
|
|---|
| 29 | **
|
|---|
| 30 | ** string '-57 17 44.806 12 34 56.7' unchanged
|
|---|
| 31 | ** iptr 1 16 (points to 12...)
|
|---|
| 32 | **
|
|---|
| 33 | ** a ? -1.00000
|
|---|
| 34 | ** j ? 0
|
|---|
| 35 | **
|
|---|
| 36 | ** A further call to slaDafin, without adjustment of iptr, will
|
|---|
| 37 | ** decode the second angle, 12deg 34min 56.7sec.
|
|---|
| 38 | **
|
|---|
| 39 | ** Notes:
|
|---|
| 40 | **
|
|---|
| 41 | ** 1) The first three "fields" in string are degrees, arcminutes,
|
|---|
| 42 | ** arcseconds, separated by spaces or commas. The degrees field
|
|---|
| 43 | ** may be signed, but not the others. The decoding is carried
|
|---|
| 44 | ** out by the dfltin routine and is free-format.
|
|---|
| 45 | **
|
|---|
| 46 | ** 2) Successive fields may be absent, defaulting to zero. For
|
|---|
| 47 | ** zero status, the only combinations allowed are degrees alone,
|
|---|
| 48 | ** degrees and arcminutes, and all three fields present. If all
|
|---|
| 49 | ** three fields are omitted, a status of +1 is returned and a is
|
|---|
| 50 | ** unchanged. In all other cases a is changed.
|
|---|
| 51 | **
|
|---|
| 52 | ** 3) Range checking:
|
|---|
| 53 | ** The degrees field is not range checked. However, it is
|
|---|
| 54 | ** expected to be integral unless the other two fields are absent.
|
|---|
| 55 | ** The arcminutes field is expected to be 0-59, and integral if
|
|---|
| 56 | ** the arcseconds field is present. If the arcseconds field
|
|---|
| 57 | ** is absent, the arcminutes is expected to be 0-59.9999...
|
|---|
| 58 | ** The arcseconds field is expected to be 0-59.9999...
|
|---|
| 59 | **
|
|---|
| 60 | ** 4) Decoding continues even when a check has failed. Under these
|
|---|
| 61 | ** circumstances the field takes the supplied value, defaulting
|
|---|
| 62 | ** to zero, and the result a is computed and returned.
|
|---|
| 63 | **
|
|---|
| 64 | ** 5) Further fields after the three expected ones are not treated
|
|---|
| 65 | ** as an error. The pointer iptr is left in the correct state
|
|---|
| 66 | ** for further decoding with the present routine or with slaDfltin
|
|---|
| 67 | ** etc. See the example, above.
|
|---|
| 68 | **
|
|---|
| 69 | ** 6) If string contains hours, minutes, seconds instead of degrees
|
|---|
| 70 | ** etc, or if the required units are turns (or days) instead of
|
|---|
| 71 | ** radians, the result a should be multiplied as follows:
|
|---|
| 72 | ** for to obtain multiply
|
|---|
| 73 | ** string a in a by
|
|---|
| 74 | ** d ' " radians 1 = 1.0
|
|---|
| 75 | ** d ' " turns 1/2pi = 0.1591549430918953358
|
|---|
| 76 | ** h m s radians 15 = 15.0
|
|---|
| 77 | ** h m s days 15/2pi = 2.3873241463784300365
|
|---|
| 78 | **
|
|---|
| 79 | ** Called: slaDfltin
|
|---|
| 80 | **
|
|---|
| 81 | ** Defined in slamac.h: DAS2R
|
|---|
| 82 | **
|
|---|
| 83 | ** Last revision: 1 August 1996
|
|---|
| 84 | **
|
|---|
| 85 | ** Copyright P.T.Wallace. All rights reserved.
|
|---|
| 86 | */
|
|---|
| 87 | {
|
|---|
| 88 | /* Local variables */
|
|---|
| 89 | int jd, jf, jm, js;
|
|---|
| 90 | double arcsec, arcmin, deg;
|
|---|
| 91 |
|
|---|
| 92 | /* Preset the status to OK */
|
|---|
| 93 | jf = 0;
|
|---|
| 94 |
|
|---|
| 95 | /* Defaults */
|
|---|
| 96 | deg = 0.0;
|
|---|
| 97 | arcmin = 0.0;
|
|---|
| 98 | arcsec = 0.0;
|
|---|
| 99 |
|
|---|
| 100 | /* Decode degrees, arcminutes, arcseconds */
|
|---|
| 101 | slaDfltin ( string, iptr, °, &jd );
|
|---|
| 102 | if ( jd > 1 ) {
|
|---|
| 103 | jf = -1;
|
|---|
| 104 | } else {
|
|---|
| 105 | slaDfltin ( string, iptr, &arcmin, &jm );
|
|---|
| 106 | if ( jm < 0 || jm > 1 ) {
|
|---|
| 107 | jf = -2;
|
|---|
| 108 | } else {
|
|---|
| 109 | slaDfltin ( string, iptr, &arcsec, &js );
|
|---|
| 110 | if ( js < 0 || js > 1 ) {
|
|---|
| 111 | jf = -3;
|
|---|
| 112 |
|
|---|
| 113 | /* See if the combination of fields is credible */
|
|---|
| 114 | } else if ( jd > 0 ) {
|
|---|
| 115 |
|
|---|
| 116 | /* No degrees: arcmin, arcsec ought also to be absent */
|
|---|
| 117 | if ( jm == 0 ) {
|
|---|
| 118 |
|
|---|
| 119 | /* Suspect arcmin */
|
|---|
| 120 | jf = -2;
|
|---|
| 121 | } else if ( js == 0 ) {
|
|---|
| 122 |
|
|---|
| 123 | /* Suspect arcsec */
|
|---|
| 124 | jf = -3;
|
|---|
| 125 | } else {
|
|---|
| 126 |
|
|---|
| 127 | /* All three fields absent */
|
|---|
| 128 | jf = 1;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | /* Degrees present: if arcsec present so ought arcmin to be */
|
|---|
| 132 | } else if ( jm != 0 && js == 0 ) {
|
|---|
| 133 | jf = -3;
|
|---|
| 134 |
|
|---|
| 135 | /* Tests for range and integrality */
|
|---|
| 136 |
|
|---|
| 137 | /* Degrees */
|
|---|
| 138 | } else if ( jm == 0 && dint ( deg ) != deg ) {
|
|---|
| 139 | jf = -1;
|
|---|
| 140 |
|
|---|
| 141 | /* Arcminutes */
|
|---|
| 142 | } else if ( ( js == 0 && dint ( arcmin ) != arcmin )
|
|---|
| 143 | || arcmin >= 60.0 ) {
|
|---|
| 144 | jf = -2;
|
|---|
| 145 |
|
|---|
| 146 | /* Arcseconds */
|
|---|
| 147 | } else if ( arcsec >= 60.0 ) {
|
|---|
| 148 | jf = -3;
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | /* Unless all three fields absent, compute angle value */
|
|---|
| 154 | if ( jf <= 0 ) {
|
|---|
| 155 | *a = ( ( fabs ( deg ) * 60.0 + arcmin ) * 60.0 + arcsec ) * DAS2R;
|
|---|
| 156 | if (jd < 0) {
|
|---|
| 157 | *a = -(*a);
|
|---|
| 158 | }
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | /* Return the status */
|
|---|
| 162 | *j = jf;
|
|---|
| 163 | }
|
|---|