Mapper
hrap.c
Go to the documentation of this file.
1 /*=========================================================================*/
2 /* FILE PATH/NAME: STAGE3_SOURCE/hrap.c */
3 /* */
4 /* FUNCTIONS CONTAINED IN THIS FILE: HrapToLatLong */
5 /* LatLongToHrap */
6 /*=========================================================================*/
7 
8 #include "prototypes.h"
9 
10 /***************************************************************************/
11 /* FILE PATH/NAME: STAGE3_SOURCE/hrap.c */
12 /* FUNCTION NAME: HrapToLatLong */
13 /* FUNCTION: convert from HRAP coordinates to latitude-longitude */
14 /****************************************************************************/
15 
16 /*
17 Function type:
18  HRAP structure
19 
20 Called by function:
21  (callback) locate
22 
23 Functions called:
24  none
25 
26 Global variables:
27  HrapToLatLong - function
28  LatLongToHrap - function
29 
30 Local variables:
31  tlat - float; standard latitude in radians
32  earthr - float; earth's radius (km)
33  xmesh - float; mesh length at 60 deg North
34  raddeg - float; conversion from radians to degrees
35  stlon - float; standard longitude
36  ll - HRAP structure; latitude/longitude */
37 
38 /******************************************** BEGIN HrapToLatLong ***********/
39 
40 struct HRAP HrapToLatLong(hrap)
41  struct HRAP hrap;
42 {
43  double x, y, rr, gi, ang;
44  double tlat, earthr, xmesh, raddeg, stlon;
45  struct HRAP ll;
46 
47  earthr=6371.2;
48  stlon=105.;
49  raddeg=57.29577951;
50  xmesh=4.7625;
51  tlat=60./raddeg;
52 
53  x = (double)hrap.x - 401.;
54  y = (double)hrap.y - 1601.;
55  rr = x*x + y*y;
56  gi = ((earthr * (1+sin(tlat)))/xmesh);
57  gi=gi*gi;
58  ll.y = asin((gi-rr)/(gi+rr))*raddeg;
59  ang = atan2(y,x)*raddeg;
60  if (ang < 0) ang=ang+360.;
61  ll.x = 270+stlon-ang;
62  if (ll.x < 0) ll.x=ll.x+360;
63  if (ll.x > 360) ll.x=ll.x-360;
64  return ll;
65 }
66 
67 /********************************************* END HrapToLatLong ***********/
68 
69 
70 
71 /***************************************************************************/
72 /* FILE PATH/NAME: STAGE3_SOURCE/hrap.c */
73 /* FUNCTION NAME: LatLongToHrap */
74 /* FUNCTION: convert latitude-longitude coordinates to DV point */
75 /* structure at appropriate screen position */
76 /***************************************************************************
77 
78 Function type:
79  HRAP structure
80 
81 Called by function:
82 
83 Functions called:
84  none
85 
86 Global variables:
87  HrapToLatLong - function
88  LatLongToHrap - function
89 
90 Local variables:
91  lat - float; latitude
92  lon - float; longitude
93  degrad - float; conversion degrees to radians
94  earthrad - float; radius of earth
95  stdlat - float; standard latitude
96  stdlon - float; standard longitude
97  mesh_len - float; grid mesh length at standard latitude
98  tlat - float; standard latitude in radians
99  latrad - float; point latitude in radians
100  lonrad - float; point longitude in radians
101  hrap - HRAP structure; hrap coordinate
102 
103 ******************************************** BEGIN LatLongToHrap ***********/
104 
105 struct HRAP LatLongToHrap(float lat, float lon)
106 
107 {
108  double degrad = 0.017453293;
109  double earthrad = 6371.2;
110  double stdlat = 60.;
111  double stdlon = 105.;
112  double mesh_len = 4.7625;
113  double tlat, re, latrad, lonrad, r, x, y;
114  struct HRAP hrap;
115 
116  tlat = stdlat*degrad;
117  re = (earthrad*(1. + sin(tlat)))/mesh_len;
118  latrad = lat * degrad;
119  lonrad = (lon + 180. - stdlon) * degrad;
120  r = re * cos(latrad) / (1. + sin(latrad));
121  x = r * sin(lonrad);
122  y = r * cos(lonrad);
123  hrap.x = x + 401;
124  hrap.y = y + 1601;
125  return hrap;
126 }
127 
128 /********************************************* END LatLongToHrap ***********/
129 
130 /********* BEGIN stageiii_structures.h ***************/
131 
132 /*
133 #include <X11/Intrinsic.h>
134 
135 typedef struct HRAP {
136  float x,y;} HRAP;
137 
138 typedef struct {
139  int x,y;
140  } point;
141 
142 
143 typedef struct {
144  char id[4];
145  float xlat;
146  float xlong;
147  int on;
148  HRAP ctr;
149  int ngrd;
150  } nex_struct;
151 
152 
153 typedef struct
154  {
155  short int **data_array;
156  int maximum_columns, maximum_rows;
157  int num_levels;
158  int *levels;
159  int states_on;
160  int county_on;
161  int rivers_on;
162  int basins_on;
163  int rings_on;
164  int cities_on;
165  int ssnum;
166  point origin;
167  GC *gc;
168  Pixmap pix;
169  Pixmap pixbase;
170  Widget w;
171  } draw_struct; */
172 /**************** END stageiii_structures.h *****/
173 
174 
struct HRAP LatLongToHrap(float lat, float lon)
Definition: hrap.c:105
struct HRAP HrapToLatLong(struct HRAP hrap)
Definition: hrap.c:40
#define earthr
Definition: mapp2h.h:34
double re
Definition: mapp2h.h:41
double stlon
Definition: mapp2h.h:43
double lat
Definition: mapp2h.h:41
#define degrad
Definition: mapp2h.h:37
double lon
Definition: mapp2h.h:41
#define stdlat
Definition: mapp2h.h:38
#define xmesh
Definition: mapp2h.h:35
#define stdlon
Definition: mapp2h.h:39
HRAP ll
Definition: mapp2h.h:53
HRAP hrap
Definition: mapp2h.h:53
#define raddeg
Definition: mapp2h.h:36
Definition: mapp2h.h:25
float y
Definition: mapp2h.h:26
float x
Definition: mapp2h.h:26