| 1 |
/******************************************************************************* |
| 2 |
NAME PAKSZ |
| 3 |
|
| 4 |
PURPOSE: This function converts a packed DMS angle to seconds. The |
| 5 |
standard packed DMS format is: |
| 6 |
|
| 7 |
degrees * 1000000 + minutes * 1000 + seconds |
| 8 |
|
| 9 |
Example: ang = 120025045.25 yields |
| 10 |
deg = 120 |
| 11 |
min = 25 |
| 12 |
sec = 45.25 |
| 13 |
|
| 14 |
The algorithm used for the conversion is as follows: |
| 15 |
|
| 16 |
1. The absolute value of the angle is used. |
| 17 |
|
| 18 |
2. The degrees are separated out: |
| 19 |
deg = ang/1000000 (fractional portion truncated) |
| 20 |
|
| 21 |
3. The minutes are separated out: |
| 22 |
min = (ang - deg * 1000000) / 1000 (fractional |
| 23 |
portion truncated) |
| 24 |
|
| 25 |
4. The seconds are then computed: |
| 26 |
sec = ang - deg * 1000000 - min * 1000 |
| 27 |
|
| 28 |
5. The total angle in seconds is computed: |
| 29 |
sec = deg * 3600.0 + min * 60.0 + sec |
| 30 |
|
| 31 |
6. The sign of sec is set to that of the input angle. |
| 32 |
|
| 33 |
|
| 34 |
PROGRAMMER DATE |
| 35 |
---------- ---- |
| 36 |
T. Mittan MARCH, 1993 |
| 37 |
|
| 38 |
ALGORITHM REFERENCES |
| 39 |
|
| 40 |
1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological |
| 41 |
Survey Proffesional Paper 1395 (Supersedes USGS Bulletin 1532), United |
| 42 |
State Government Printing Office, Washington D.C., 1987. |
| 43 |
|
| 44 |
2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections", |
| 45 |
U.S. Geological Survey Professional Paper 1453 , United State Government |
| 46 |
Printing Office, Washington D.C., 1989. |
| 47 |
*******************************************************************************/ |
| 48 |
#include <stdio.h> |
| 49 |
#include <stdio.h> |
| 50 |
#include "cproj.h" |
| 51 |
|
| 52 |
/* Convert DMS packed angle into deg |
| 53 |
----------------------------------*/ |
| 54 |
double paksz( |
| 55 |
double ang, /* angle which in DMS */ |
| 56 |
long *iflg) /* error flag number */ |
| 57 |
{ |
| 58 |
double fac; /* sign flag */ |
| 59 |
double deg; /* degree variable */ |
| 60 |
double min; /* minute variable */ |
| 61 |
double sec; /* seconds variable */ |
| 62 |
double tmp; /* temporary variable */ |
| 63 |
long i; /* temporary variable */ |
| 64 |
|
| 65 |
*iflg = (long)0; |
| 66 |
|
| 67 |
if (ang < 0.0) |
| 68 |
fac = -1; |
| 69 |
else |
| 70 |
fac = 1; |
| 71 |
|
| 72 |
/* find degrees |
| 73 |
-------------*/ |
| 74 |
sec = fabs(ang); |
| 75 |
tmp = 1000000.0; |
| 76 |
i = (long) (sec/tmp); |
| 77 |
|
| 78 |
if ((int)i > 360) |
| 79 |
{ |
| 80 |
p_error("Illegal DMS field","paksz-deg"); |
| 81 |
*iflg = (long)1116; |
| 82 |
return(ERROR); |
| 83 |
} |
| 84 |
else |
| 85 |
deg = i; |
| 86 |
|
| 87 |
/* find minutes |
| 88 |
-------------*/ |
| 89 |
sec = sec - deg * tmp; |
| 90 |
tmp = 1000; |
| 91 |
i = (long) (sec / tmp); |
| 92 |
|
| 93 |
if ((int)i > 60) |
| 94 |
{ |
| 95 |
p_error("Illegal DMS field","paksz-min"); |
| 96 |
*iflg = (long)1116; |
| 97 |
return(ERROR); |
| 98 |
} |
| 99 |
else |
| 100 |
min = i; |
| 101 |
|
| 102 |
/* find seconds |
| 103 |
-------------*/ |
| 104 |
sec = sec - min * tmp; |
| 105 |
if (sec > 60) |
| 106 |
{ |
| 107 |
p_error("Illegal DMS field","paksz-sec"); |
| 108 |
*iflg = (long)1116; |
| 109 |
return(ERROR); |
| 110 |
} |
| 111 |
else |
| 112 |
sec = fac * (deg * 3600.0 + min * 60.0 + sec); |
| 113 |
deg = sec / 3600.0; |
| 114 |
return(deg); |
| 115 |
} |