dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mgrs.c File Reference
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "ups.h"
#include "utm.h"
#include "mgrs.h"

Go to the source code of this file.

Data Structures

struct  Latitude_Band_Value
 
struct  UPS_Constant_Value
 

Macros

#define DEG_TO_RAD   0.017453292519943295 /* PI/180 */
 
#define RAD_TO_DEG   57.29577951308232087 /* 180/PI */
 
#define LETTER_A   0 /* ARRAY INDEX FOR LETTER A */
 
#define LETTER_B   1 /* ARRAY INDEX FOR LETTER B */
 
#define LETTER_C   2 /* ARRAY INDEX FOR LETTER C */
 
#define LETTER_D   3 /* ARRAY INDEX FOR LETTER D */
 
#define LETTER_E   4 /* ARRAY INDEX FOR LETTER E */
 
#define LETTER_F   5 /* ARRAY INDEX FOR LETTER F */
 
#define LETTER_G   6 /* ARRAY INDEX FOR LETTER G */
 
#define LETTER_H   7 /* ARRAY INDEX FOR LETTER H */
 
#define LETTER_I   8 /* ARRAY INDEX FOR LETTER I */
 
#define LETTER_J   9 /* ARRAY INDEX FOR LETTER J */
 
#define LETTER_K   10 /* ARRAY INDEX FOR LETTER K */
 
#define LETTER_L   11 /* ARRAY INDEX FOR LETTER L */
 
#define LETTER_M   12 /* ARRAY INDEX FOR LETTER M */
 
#define LETTER_N   13 /* ARRAY INDEX FOR LETTER N */
 
#define LETTER_O   14 /* ARRAY INDEX FOR LETTER O */
 
#define LETTER_P   15 /* ARRAY INDEX FOR LETTER P */
 
#define LETTER_Q   16 /* ARRAY INDEX FOR LETTER Q */
 
#define LETTER_R   17 /* ARRAY INDEX FOR LETTER R */
 
#define LETTER_S   18 /* ARRAY INDEX FOR LETTER S */
 
#define LETTER_T   19 /* ARRAY INDEX FOR LETTER T */
 
#define LETTER_U   20 /* ARRAY INDEX FOR LETTER U */
 
#define LETTER_V   21 /* ARRAY INDEX FOR LETTER V */
 
#define LETTER_W   22 /* ARRAY INDEX FOR LETTER W */
 
#define LETTER_X   23 /* ARRAY INDEX FOR LETTER X */
 
#define LETTER_Y   24 /* ARRAY INDEX FOR LETTER Y */
 
#define LETTER_Z   25 /* ARRAY INDEX FOR LETTER Z */
 
#define MGRS_LETTERS   3 /* NUMBER OF LETTERS IN MGRS */
 
#define ONEHT   100000.e0 /* ONE HUNDRED THOUSAND */
 
#define TWOMIL   2000000.e0 /* TWO MILLION */
 
#define TRUE   1 /* CONSTANT VALUE FOR TRUE VALUE */
 
#define FALSE   0 /* CONSTANT VALUE FOR FALSE VALUE */
 
#define PI   3.14159265358979323e0 /* PI */
 
#define PI_OVER_2   (PI / 2.0e0)
 
#define MIN_EASTING   100000
 
#define MAX_EASTING   900000
 
#define MIN_NORTHING   0
 
#define MAX_NORTHING   10000000
 
#define MAX_PRECISION   5 /* Maximum precision of easting & northing */
 
#define MIN_UTM_LAT   ( (-80 * PI) / 180.0 ) /* -80 degrees in radians */
 
#define MAX_UTM_LAT   ( (84 * PI) / 180.0 ) /* 84 degrees in radians */
 
#define MIN_EAST_NORTH   0
 
#define MAX_EAST_NORTH   4000000
 

Typedefs

typedef struct Latitude_Band_Value Latitude_Band
 
typedef struct UPS_Constant_Value UPS_Constant
 

Functions

int Get_Latitude_Band_Min_Northing (int letter, double *min_northing, double *northing_offset)
 
int Get_Latitude_Range (int letter, double *north, double *south)
 
int Get_Latitude_Letter (double latitude, int *letter)
 
int Check_Zone (char *MGRS, int *zone_exists)
 
int Round_MGRS (double value)
 
int Make_MGRS_String (char *MGRS, int Zone, int Letters[MGRS_LETTERS], double Easting, double Northing, int Precision)
 
int Break_MGRS_String (char *MGRS, int *Zone, int Letters[MGRS_LETTERS], double *Easting, double *Northing, int *Precision)
 
void Get_Grid_Values (int zone, int *ltr2_low_value, int *ltr2_high_value, double *pattern_offset)
 
int UTM_To_MGRS (int Zone, char Hemisphere, double Longitude, double Latitude, double Easting, double Northing, int Precision, char *MGRS)
 
int Set_MGRS_Parameters (double a, double f, char *Ellipsoid_Code)
 
void Get_MGRS_Parameters (double *a, double *f, char *Ellipsoid_Code)
 
int Convert_Geodetic_To_MGRS (double Latitude, double Longitude, int Precision, char *MGRS)
 
int Convert_MGRS_To_Geodetic (char *MGRS, double *Latitude, double *Longitude)
 
int Convert_UTM_To_MGRS (int Zone, char Hemisphere, double Easting, double Northing, int Precision, char *MGRS)
 
int Convert_MGRS_To_UTM (char *MGRS, int *Zone, char *Hemisphere, double *Easting, double *Northing)
 
int Convert_UPS_To_MGRS (char Hemisphere, double Easting, double Northing, int Precision, char *MGRS)
 
int Convert_MGRS_To_UPS (char *MGRS, char *Hemisphere, double *Easting, double *Northing)
 

Variables

double MGRS_a = 6378137.0
 
double MGRS_f = 1 / 298.257223563
 
char MGRS_Ellipsoid_Code [3] = {'W','E',0}
 
const char * CLARKE_1866 = "CC"
 
const char * CLARKE_1880 = "CD"
 
const char * BESSEL_1841 = "BR"
 
const char * BESSEL_1841_NAMIBIA = "BN"
 
static const Latitude_Band Latitude_Band_Table [20]
 
static const UPS_Constant UPS_Constant_Table [4]
 

Macro Definition Documentation

#define DEG_TO_RAD   0.017453292519943295 /* PI/180 */

Definition at line 103 of file mgrs.c.

#define FALSE   0 /* CONSTANT VALUE FOR FALSE VALUE */

Definition at line 135 of file mgrs.c.

#define LETTER_A   0 /* ARRAY INDEX FOR LETTER A */

Definition at line 105 of file mgrs.c.

#define LETTER_B   1 /* ARRAY INDEX FOR LETTER B */

Definition at line 106 of file mgrs.c.

#define LETTER_C   2 /* ARRAY INDEX FOR LETTER C */

Definition at line 107 of file mgrs.c.

#define LETTER_D   3 /* ARRAY INDEX FOR LETTER D */

Definition at line 108 of file mgrs.c.

#define LETTER_E   4 /* ARRAY INDEX FOR LETTER E */

Definition at line 109 of file mgrs.c.

#define LETTER_F   5 /* ARRAY INDEX FOR LETTER F */

Definition at line 110 of file mgrs.c.

#define LETTER_G   6 /* ARRAY INDEX FOR LETTER G */

Definition at line 111 of file mgrs.c.

#define LETTER_H   7 /* ARRAY INDEX FOR LETTER H */

Definition at line 112 of file mgrs.c.

#define LETTER_I   8 /* ARRAY INDEX FOR LETTER I */

Definition at line 113 of file mgrs.c.

#define LETTER_J   9 /* ARRAY INDEX FOR LETTER J */

Definition at line 114 of file mgrs.c.

#define LETTER_K   10 /* ARRAY INDEX FOR LETTER K */

Definition at line 115 of file mgrs.c.

#define LETTER_L   11 /* ARRAY INDEX FOR LETTER L */

Definition at line 116 of file mgrs.c.

#define LETTER_M   12 /* ARRAY INDEX FOR LETTER M */

Definition at line 117 of file mgrs.c.

#define LETTER_N   13 /* ARRAY INDEX FOR LETTER N */

Definition at line 118 of file mgrs.c.

#define LETTER_O   14 /* ARRAY INDEX FOR LETTER O */

Definition at line 119 of file mgrs.c.

#define LETTER_P   15 /* ARRAY INDEX FOR LETTER P */

Definition at line 120 of file mgrs.c.

#define LETTER_Q   16 /* ARRAY INDEX FOR LETTER Q */

Definition at line 121 of file mgrs.c.

#define LETTER_R   17 /* ARRAY INDEX FOR LETTER R */

Definition at line 122 of file mgrs.c.

#define LETTER_S   18 /* ARRAY INDEX FOR LETTER S */

Definition at line 123 of file mgrs.c.

#define LETTER_T   19 /* ARRAY INDEX FOR LETTER T */

Definition at line 124 of file mgrs.c.

#define LETTER_U   20 /* ARRAY INDEX FOR LETTER U */

Definition at line 125 of file mgrs.c.

#define LETTER_V   21 /* ARRAY INDEX FOR LETTER V */

Definition at line 126 of file mgrs.c.

#define LETTER_W   22 /* ARRAY INDEX FOR LETTER W */

Definition at line 127 of file mgrs.c.

#define LETTER_X   23 /* ARRAY INDEX FOR LETTER X */

Definition at line 128 of file mgrs.c.

#define LETTER_Y   24 /* ARRAY INDEX FOR LETTER Y */

Definition at line 129 of file mgrs.c.

#define LETTER_Z   25 /* ARRAY INDEX FOR LETTER Z */

Definition at line 130 of file mgrs.c.

#define MAX_EAST_NORTH   4000000

Definition at line 148 of file mgrs.c.

#define MAX_EASTING   900000

Definition at line 140 of file mgrs.c.

#define MAX_NORTHING   10000000

Definition at line 142 of file mgrs.c.

#define MAX_PRECISION   5 /* Maximum precision of easting & northing */

Definition at line 143 of file mgrs.c.

#define MAX_UTM_LAT   ( (84 * PI) / 180.0 ) /* 84 degrees in radians */

Definition at line 145 of file mgrs.c.

#define MGRS_LETTERS   3 /* NUMBER OF LETTERS IN MGRS */

Definition at line 131 of file mgrs.c.

#define MIN_EAST_NORTH   0

Definition at line 147 of file mgrs.c.

#define MIN_EASTING   100000

Definition at line 139 of file mgrs.c.

#define MIN_NORTHING   0

Definition at line 141 of file mgrs.c.

#define MIN_UTM_LAT   ( (-80 * PI) / 180.0 ) /* -80 degrees in radians */

Definition at line 144 of file mgrs.c.

#define ONEHT   100000.e0 /* ONE HUNDRED THOUSAND */

Definition at line 132 of file mgrs.c.

#define PI   3.14159265358979323e0 /* PI */

Definition at line 136 of file mgrs.c.

#define PI_OVER_2   (PI / 2.0e0)

Definition at line 137 of file mgrs.c.

#define RAD_TO_DEG   57.29577951308232087 /* 180/PI */

Definition at line 104 of file mgrs.c.

#define TRUE   1 /* CONSTANT VALUE FOR TRUE VALUE */

Definition at line 134 of file mgrs.c.

#define TWOMIL   2000000.e0 /* TWO MILLION */

Definition at line 133 of file mgrs.c.

Typedef Documentation

Function Documentation

int Break_MGRS_String ( char *  MGRS,
int *  Zone,
int  Letters[MGRS_LETTERS],
double *  Easting,
double *  Northing,
int *  Precision 
)

Definition at line 442 of file mgrs.c.

int Check_Zone ( char *  MGRS,
int *  zone_exists 
)

Definition at line 319 of file mgrs.c.

int Convert_Geodetic_To_MGRS ( double  Latitude,
double  Longitude,
int  Precision,
char *  MGRS 
)

Definition at line 775 of file mgrs.c.

int Convert_MGRS_To_Geodetic ( char *  MGRS,
double *  Latitude,
double *  Longitude 
)

Definition at line 874 of file mgrs.c.

int Convert_MGRS_To_UPS ( char *  MGRS,
char *  Hemisphere,
double *  Easting,
double *  Northing 
)

Definition at line 1259 of file mgrs.c.

int Convert_MGRS_To_UTM ( char *  MGRS,
int *  Zone,
char *  Hemisphere,
double *  Easting,
double *  Northing 
)

Definition at line 1018 of file mgrs.c.

int Convert_UPS_To_MGRS ( char  Hemisphere,
double  Easting,
double  Northing,
int  Precision,
char *  MGRS 
)

Definition at line 1152 of file mgrs.c.

int Convert_UTM_To_MGRS ( int  Zone,
char  Hemisphere,
double  Easting,
double  Northing,
int  Precision,
char *  MGRS 
)

Definition at line 963 of file mgrs.c.

void Get_Grid_Values ( int  zone,
int *  ltr2_low_value,
int *  ltr2_high_value,
double *  pattern_offset 
)

Definition at line 547 of file mgrs.c.

int Get_Latitude_Band_Min_Northing ( int  letter,
double *  min_northing,
double *  northing_offset 
)

Definition at line 222 of file mgrs.c.

int Get_Latitude_Letter ( double  latitude,
int *  letter 
)

Definition at line 291 of file mgrs.c.

int Get_Latitude_Range ( int  letter,
double *  north,
double *  south 
)

Definition at line 256 of file mgrs.c.

void Get_MGRS_Parameters ( double *  a,
double *  f,
char *  Ellipsoid_Code 
)

Definition at line 756 of file mgrs.c.

int Make_MGRS_String ( char *  MGRS,
int  Zone,
int  Letters[MGRS_LETTERS],
double  Easting,
double  Northing,
int  Precision 
)

Definition at line 373 of file mgrs.c.

int Round_MGRS ( double  value)

Definition at line 354 of file mgrs.c.

int Set_MGRS_Parameters ( double  a,
double  f,
char *  Ellipsoid_Code 
)

Definition at line 721 of file mgrs.c.

int UTM_To_MGRS ( int  Zone,
char  Hemisphere,
double  Longitude,
double  Latitude,
double  Easting,
double  Northing,
int  Precision,
char *  MGRS 
)

Definition at line 612 of file mgrs.c.

Variable Documentation

const char* BESSEL_1841 = "BR"

Definition at line 165 of file mgrs.c.

const char* BESSEL_1841_NAMIBIA = "BN"

Definition at line 166 of file mgrs.c.

const char* CLARKE_1866 = "CC"

Definition at line 163 of file mgrs.c.

const char* CLARKE_1880 = "CD"

Definition at line 164 of file mgrs.c.

const Latitude_Band Latitude_Band_Table[20]
static
Initial value:
=
{{LETTER_C, 1100000.0, -72.0, -80.5, 0.0},
{LETTER_D, 2000000.0, -64.0, -72.0, 2000000.0},
{LETTER_E, 2800000.0, -56.0, -64.0, 2000000.0},
{LETTER_F, 3700000.0, -48.0, -56.0, 2000000.0},
{LETTER_G, 4600000.0, -40.0, -48.0, 4000000.0},
{LETTER_H, 5500000.0, -32.0, -40.0, 4000000.0},
{LETTER_J, 6400000.0, -24.0, -32.0, 6000000.0},
{LETTER_K, 7300000.0, -16.0, -24.0, 6000000.0},
{LETTER_L, 8200000.0, -8.0, -16.0, 8000000.0},
{LETTER_M, 9100000.0, 0.0, -8.0, 8000000.0},
{LETTER_N, 0.0, 8.0, 0.0, 0.0},
{LETTER_P, 800000.0, 16.0, 8.0, 0.0},
{LETTER_Q, 1700000.0, 24.0, 16.0, 0.0},
{LETTER_R, 2600000.0, 32.0, 24.0, 2000000.0},
{LETTER_S, 3500000.0, 40.0, 32.0, 2000000.0},
{LETTER_T, 4400000.0, 48.0, 40.0, 4000000.0},
{LETTER_U, 5300000.0, 56.0, 48.0, 4000000.0},
{LETTER_V, 6200000.0, 64.0, 56.0, 6000000.0},
{LETTER_W, 7000000.0, 72.0, 64.0, 6000000.0},
{LETTER_X, 7900000.0, 84.5, 72.0, 6000000.0}}
#define LETTER_R
Definition: mgrs.c:122
#define LETTER_X
Definition: mgrs.c:128
#define LETTER_P
Definition: mgrs.c:120
#define LETTER_V
Definition: mgrs.c:126
#define LETTER_K
Definition: mgrs.c:115
#define LETTER_E
Definition: mgrs.c:109
#define LETTER_M
Definition: mgrs.c:117
#define LETTER_W
Definition: mgrs.c:127
#define LETTER_S
Definition: mgrs.c:123
#define LETTER_Q
Definition: mgrs.c:121
#define LETTER_G
Definition: mgrs.c:111
#define LETTER_H
Definition: mgrs.c:112
#define LETTER_D
Definition: mgrs.c:108
#define LETTER_C
Definition: mgrs.c:107
#define LETTER_T
Definition: mgrs.c:124
#define LETTER_U
Definition: mgrs.c:125
#define LETTER_N
Definition: mgrs.c:118
#define LETTER_L
Definition: mgrs.c:116
#define LETTER_F
Definition: mgrs.c:110
#define LETTER_J
Definition: mgrs.c:114

Definition at line 178 of file mgrs.c.

double MGRS_a = 6378137.0

Definition at line 152 of file mgrs.c.

char MGRS_Ellipsoid_Code[3] = {'W','E',0}

Definition at line 154 of file mgrs.c.

double MGRS_f = 1 / 298.257223563

Definition at line 153 of file mgrs.c.

const UPS_Constant UPS_Constant_Table[4]
static
Initial value:
=
{{LETTER_A, LETTER_J, LETTER_Z, LETTER_Z, 800000.0, 800000.0},
{LETTER_B, LETTER_A, LETTER_R, LETTER_Z, 2000000.0, 800000.0},
{LETTER_Y, LETTER_J, LETTER_Z, LETTER_P, 800000.0, 1300000.0},
{LETTER_Z, LETTER_A, LETTER_J, LETTER_P, 2000000.0, 1300000.0}}
#define LETTER_Z
Definition: mgrs.c:130
#define LETTER_R
Definition: mgrs.c:122
#define LETTER_Y
Definition: mgrs.c:129
#define LETTER_B
Definition: mgrs.c:106
#define LETTER_P
Definition: mgrs.c:120
#define LETTER_A
Definition: mgrs.c:105
#define LETTER_J
Definition: mgrs.c:114

Definition at line 211 of file mgrs.c.