OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
gctp_dms2degrees.c
Go to the documentation of this file.
1 /*******************************************************************************
2 Name: gctp_dms2degrees
3 
4 Purpose: Converts a packed DMS angle to degrees. The standard packed DMS
5 format is:
6 
7  degrees * 1000000 + minutes * 1000 + seconds
8 
9  Example: angle = 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 = angle/1000000 (fractional portion truncated)
20 
21  3. The minutes are separated out:
22  min = (angle - deg * 1000000) / 1000 (fractional
23  portion truncated)
24 
25  4. The seconds are then computed:
26  sec = angle - 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  7. The total degrees are computed:
34  degrees = sec / 3600.0
35 
36 ALGORITHM REFERENCES
37 
38 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
39  Survey Proffesional Paper 1395 (Supersedes USGS Bulletin 1532), United
40  State Government Printing Office, Washington D.C., 1987.
41 
42 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
43  U.S. Geological Survey Professional Paper 1453 , United State Government
44  Printing Office, Washington D.C., 1989.
45 *******************************************************************************/
46 #include "oli_local.h"
47 #include "oli_cproj.h"
48 
50 (
51  double angle, /* I: angle in DMS */
52  double *degrees /* O: angle in degrees */
53 )
54 {
55  double fac; /* sign flag */
56  double deg; /* degree variable */
57  double min; /* minute variable */
58  double sec; /* seconds variable */
59  double tmp; /* temporary variable */
60 
61  if (angle < 0.0)
62  fac = -1;
63  else
64  fac = 1;
65 
66  /* find degrees */
67  sec = fabs(angle);
68  tmp = 1000000.0;
69  deg = (int) (sec/tmp);
70  if (deg > 360)
71  {
72  GCTP_PRINT_ERROR("Illegal DMS degrees field: %f", deg);
73  return GCTP_ERROR;
74  }
75 
76  /* find minutes */
77  sec = sec - deg * tmp;
78  tmp = 1000;
79  min = (int) (sec / tmp);
80  if (min > 60)
81  {
82  GCTP_PRINT_ERROR("Illegal DMS minutes field: %f", min);
83  return GCTP_ERROR;
84  }
85 
86  /* find seconds */
87  sec = sec - min * tmp;
88  if (sec > 60)
89  {
90  GCTP_PRINT_ERROR("Illegal DMS seconds field: %f", sec);
91  return GCTP_ERROR;
92  }
93  else
94  sec = fac * (deg * 3600.0 + min * 60.0 + sec);
95  deg = sec / 3600.0;
96 
97  *degrees = deg;
98 
99  return GCTP_SUCCESS;
100 }
These are used to scale the SD before writing it to the HDF4 file The default is and which means the product is not scaled at all Since the product is usually stored as a float inside of this is a way to write the float out as a integer l2prod min
#define GCTP_ERROR
Definition: gctp.h:81
#define GCTP_PRINT_ERROR(format,...)
Definition: oli_local.h:81
#define fac
data_t tmp
Definition: decode_rs.h:74
#define GCTP_SUCCESS
Definition: gctp.h:82
int gctp_dms2degrees(double angle, double *degrees)
#define fabs(a)
Definition: misc.h:93
#define degrees(radians)
Definition: niwa_iop.c:30