Debian Codegraph @

gctp/src/somfor.c

raw
1 /*******************************************************************************
2 NAME SPACE OBLIQUE MERCATOR (SOM)
3
4 PURPOSE: The first method of Transforming input longitude and
5 latitude to Easting and Northing for the SOM projection.
6 The longitude and latitude must be in radians. The
7 Easting and Northing values will be returned in meters.
8
9 PROGRAM HISTORY
10 PROGRAMMER DATE REASON
11 ---------- ---- ------
12 D. Steinwand July, 1992
13 T. Mittan Mar, 1993
14 S. Nelson Nov, 1993 Changed error message
15 Raj Gejjagaraguppe(ARC) Aug, 1996 Landsat Ratio is removed as hard
16 coded value. Now this ratio can be
17 an input from the user through the
18 projection parameter array element
19 number 9.
20
21 ALGORITHM REFERENCES
22
23 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
24 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
25 State Government Printing Office, Washington D.C., 1987.
26
27 2. "Software Documentation for GCTP General Cartographic Transformation
28 Package", U.S. Geological Survey National Mapping Division, May 1982.
29 *******************************************************************************/
30 #include <stdio.h>
31 #include "cproj.h"
32
33 static double lon_center,a,b,a2,a4,c1,c3,q,t,w,xj,p21,sa,ca,es,s,start;
34 static double false_easting;
35 static double false_northing;
36 static void som_series(double *fb, double *fa2, double *fa4,
37 double *fc1, double *fc3, double *dlam);
38
39 double gsat_ratio;
40
41 int somforint(
42 double r_major, /* major axis */
43 double r_minor, /* minor axis */
44 long satnum, /* Landsat satellite number (1,2,3,4,5) */
45 long path, /* Landsat path number */
46 double alf_in,
47 double lon,
48 double false_east, /* x offset in meters */
49 double false_north, /* y offset in meters */
50 double time,
51 long start1,
52 long flag,
53 double sat_ratio) /* satellite ratio which specify the
54 start point of x,y reading within an
55 orbit */
56 {
57 long i;
58 double alf,e2c,e2s,one_es;
59 double dlam,fb,fa2,fa4,fc1,fc3,suma2,suma4,sumc1,sumc3,sumb;
60 double adjust_lon();
61
62 /* Assign satellite ratio to a global variable
63 ------------------------------------------- */
64 gsat_ratio = sat_ratio;
65
66 /* Place parameters in static storage for common use
67 -------------------------------------------------*/
68 false_easting = false_east;
69 false_northing = false_north;
70 a = r_major;
71 b = r_minor;
72 es = 1.0 - SQUARE(r_minor/r_major);
73 if (flag != 0)
74 {
75 alf = alf_in;
76 p21 = time / 1440.0;
77 lon_center = lon;
78 start = start1;
79 }
80 else
81 {
82 if (satnum < 4)
83 {
84 alf = 99.092 * D2R;
85 p21=103.2669323/1440.0;
86 lon_center = (128.87 - (360.0/251.0 * path)) * D2R;
87 gsat_ratio = 0.5201613;
88 }
89 else
90 {
91 alf = 98.2 * D2R;
92 p21=98.8841202/1440.0;
93 lon_center = (129.30 - (360.0/233.0 * path)) * D2R;
94 gsat_ratio = 0.5201613;
95 /*
96 lon_center = (-129.30557714 - (360.0/233.0 * path)) * D2R;
97 */
98 }
99 start=0.0;
100 }
101
102 /* Report parameters to the user (to device set up prior to this call)
103 -------------------------------------------------------------------*/
104 ptitle("SPACE OBLIQUE MERCATOR");
105 radius2(a,b);
106 if (flag == 0)
107 {
108 genrpt_long(path, "Path Number: ");
109 genrpt_long(satnum, "Satellite Number: ");
110 }
111 genrpt(alf*R2D, "Inclination of Orbit: ");
112 genrpt(lon_center*R2D,"Longitude of Ascending Orbit: ");
113 offsetp(false_easting,false_northing);
114 genrpt(gsat_ratio, "Landsat Ratio: ");
115
116 ca=cos(alf);
117 if (fabs(ca)<1.e-9) ca=1.e-9;
118 sa=sin(alf);
119 e2c=es*ca*ca;
120 e2s=es*sa*sa;
121 w=(1.0-e2c)/(1.0-es);
122 w=w*w-1.0;
123 one_es=1.0-es;
124 q = e2s / one_es;
125 t = (e2s*(2.0-es)) / (one_es*one_es);
126 xj = one_es*one_es*one_es;
127 dlam=0.0;
128 som_series(&fb,&fa2,&fa4,&fc1,&fc3,&dlam);
129 suma2=fa2;
130 suma4=fa4;
131 sumb=fb;
132 sumc1=fc1;
133 sumc3=fc3;
134 for(i=9;i<=81;i+=18)
135 {
136 dlam=i;
137 som_series(&fb,&fa2,&fa4,&fc1,&fc3,&dlam);
138 suma2=suma2+4.0*fa2;
139 suma4=suma4+4.0*fa4;
140 sumb=sumb+4.0*fb;
141 sumc1=sumc1+4.0*fc1;
142 sumc3=sumc3+4.0*fc3;
143 }
144 for(i=18; i<=72; i+=18)
145 {
146 dlam=i;
147 som_series(&fb,&fa2,&fa4,&fc1,&fc3,&dlam);
148 suma2=suma2+2.0*fa2;
149 suma4=suma4+2.0*fa4;
150 sumb=sumb+2.0*fb;
151 sumc1=sumc1+2.0*fc1;
152 sumc3=sumc3+2.0*fc3;
153 }
154
155 dlam=90.0;
156 som_series(&fb,&fa2,&fa4,&fc1,&fc3,&dlam);
157 suma2=suma2+fa2;
158 suma4=suma4+fa4;
159 sumb=sumb+fb;
160 sumc1=sumc1+fc1;
161 sumc3=sumc3+fc3;
162 a2=suma2/30.0;
163 a4=suma4/60.0;
164 b=sumb/30.0;
165 c1=sumc1/15.0;
166 c3=sumc3/45.0;
167 return(OK);
168 }
169
170 int somfor(
171 double lon, /* (I) Longitude */
172 double lat, /* (I) Latitude */
173 double *y, /* (O) X projection coordinate */
174 double *x) /* (O) Y projection coordinate */
175 {
176 long n,l;
177 double delta_lon;
178 double rlm,tabs,tlam,xlam,c,xlamt,ab2,ab1,xlamp,sav;
179 double d,sdsq,sd,tanlg,xtan,tphi,dp,rlm2;
180 double scl,tlamp,conv,delta_lat,radlt,radln;
181 double temp;
182 char errorbuf[80];
183
184 /* Forward equations
185 -----------------*/
186 conv=1.e-7;
187 delta_lat=lat;
188 delta_lon= lon-lon_center;
189
190 /* Test for latitude and longitude approaching 90 degrees
191 ----------------------------------------------------*/
192 if (delta_lat>1.570796) delta_lat=1.570796;
193 if (delta_lat<-1.570796) delta_lat= -1.570796;
194 radlt=delta_lat;
195 radln=delta_lon;
196 if(delta_lat>=0.0)tlamp=PI/2.0;
197 if(start!= 0.0)tlamp=2.5*PI;
198 if(delta_lat<0.0) tlamp=1.5*PI;
199 n=0;
200
201 L230: sav=tlamp;
202 l=0;
203 xlamp=radln+p21*tlamp;
204 ab1=cos(xlamp);
205 if(fabs(ab1)<conv) xlamp=xlamp-1.e-7;
206 if(ab1>=0.0) scl=1.0;
207 if(ab1<0.0) scl= -1.0;
208 ab2=tlamp-(scl)*sin(tlamp)*HALF_PI;
209 L240: xlamt=radln+p21*sav;
210 c=cos(xlamt);
211 if (fabs(c)<1.e-7) xlamt=xlamt-1.e-7;
212 xlam=(((1.0-es)*tan(radlt)*sa)+sin(xlamt)*ca)/c;
213 tlam=atan(xlam);
214 tlam=tlam+ab2;
215 tabs=fabs(sav)-fabs(tlam);
216 if(fabs(tabs)<conv) goto L250;
217 l=l+1;
218 if (l > 50) goto L260;
219 sav=tlam;
220 goto L240;
221
222 /* Adjust for confusion at beginning and end of landsat orbits
223 -----------------------------------------------------------*/
224 L250: rlm=PI * gsat_ratio;
225 rlm2=rlm+2.0*PI;
226 n++;
227 if(n>=3) goto L300;
228 if(tlam>rlm&&tlam<rlm2) goto L300;
229 if(tlam<rlm)tlamp=2.50*PI;
230 if(tlam>=rlm2) tlamp=HALF_PI;
231 goto L230;
232 L260: sprintf(errorbuf,"50 iterations without conv\n");
233 p_error(errorbuf,"som-forward");
234 return(214);
235
236 /* tlam computed - now compute tphi
237 --------------------------------*/
238 L300: dp=sin(radlt);
239 tphi=asin(((1.0-es)*ca*dp-sa*cos(radlt)*sin(xlamt))/sqrt(1.0-es*dp*dp));
240
241 /* compute x and y
242 ---------------*/
243 xtan = (PI/4.0) + (tphi/2.0);
244 tanlg = log(tan(xtan));
245 sd=sin(tlam);
246 sdsq=sd*sd;
247 s=p21*sa*cos(tlam)*sqrt((1.0+t*sdsq)/((1.0+w*sdsq)*(1.0+q*sdsq)));
248 d=sqrt(xj*xj+s*s);
249 *x=b*tlam+a2*sin(2.0*tlam)+a4*sin(4.0*tlam)-tanlg*s/d;
250 *x = a* *x;
251 *y=c1*sd+c3*sin(3.0*tlam)+tanlg*xj/d;
252 *y = a* *y;
253
254 /* Negate x & swap x,y
255 -------------------*/
256 temp= *x;
257 *x= *y + false_easting;
258 *y=temp + false_northing;;
259 return(OK);
260 }
261 /* Series to calculate a,b,c coefficients to convert from transform
262 latitude,longitude to Space Oblique Mercator (SOM) rectangular coordinates
263
264 Mathematical analysis by John Snyder 6/82
265 --------------------------------------------------------------------------*/
266 static void som_series(
267 double *fb,
268 double *fa2,
269 double *fa4,
270 double *fc1,
271 double *fc3,
272 double *dlam)
273 {
274 double sd,sdsq,h,sq,fc;
275
276 *dlam= *dlam*0.0174532925; /* Convert dlam to radians */
277 sd=sin(*dlam);
278 sdsq=sd*sd;
279 s=p21*sa*cos(*dlam)*sqrt((1.0+t*sdsq)/((1.0+w*sdsq)*(1.0+q*sdsq)));
280 h=sqrt((1.0+q*sdsq)/(1.0+w*sdsq))*(((1.0+w*sdsq)/((1.0+q*sdsq)*(1.0+
281 q*sdsq)))-p21*ca);
282 sq=sqrt(xj*xj+s*s);
283 *fb=(h*xj-s*s)/sq;
284 *fa2= *fb*cos(2.0* *dlam);
285 *fa4= *fb*cos(4.0* *dlam);
286 fc=s*(h+xj)/sq;
287 *fc1=fc*cos(*dlam);
288 *fc3=fc*cos(3.0* *dlam);
289 }