00001 /* 00002 * cartography.c ~rick/src/util 00003 * 00004 * Functions for mapping between plate, heliographic, and various map 00005 * coordinate systems, including scaling. 00006 * 00007 * Contents: 00008 * img2sphere Map from plate location to heliographic 00009 * coordinates 00010 * plane2sphere Map from map location to heliographic or 00011 * geographical coordinates 00012 * sphere2img Map from heliographic coordinates to plate 00013 * location 00014 * sphere2plane Map from heliographic/geographic coordinates 00015 * to map location 00016 * name2proj Convert name to key value of projection 00017 * proj2name Convert projection key value to name 00018 * 00019 * Responsible: Rick Bogart RBogart@solar.Stanford.EDU 00020 * 00021 * Usage: 00022 * int img2sphere (double x, double y, double ang_r, double latc, 00023 * double lonc, double pa, double *rho, double *lat, double *lon, 00024 * double *sinlat, double *coslat, double *sig, double *mu, double *chi); 00025 * int plane2sphere (double x, double y, double latc, double lonc, 00026 * double *lat, double *lon, int projection); 00027 * int sphere2img (double lat, double lon, double latc, double lonc, 00028 * double *x, double *y, double xcenter, double ycenter, 00029 * double rsun, double peff, double ecc, double chi, 00030 * int xinvrt, int yinvrt); 00031 * int sphere2plane (double lat, double lon, double latc, double lonc, 00032 * double *x, double *y, int projection); 00033 * int name2proj (char *proj_name); 00034 * char *proj2name (int projection); 00035 * 00036 * Bugs: 00037 * It is assumed that the function atan2() returns the correct value 00038 * for the quadrant; not all libraries may support this feature. 00039 * sphere2img uses a constant for the correction due to the finite 00040 * distance to the sun. 00041 * sphere2plane and plane2sphere are not true inverses for the following 00042 * projections: (Lambert) cylindrical equal area, sinusoidal equal area 00043 * (Sanson-Flamsteed), and Mercator; for these projections, sphere2plane is 00044 * implemented as the normal projection, while plane2sphere is implemented 00045 * as the oblique projection tangent at the normal to the central meridian 00046 * plane2sphere doesn't return 1 if the x coordinate would map to a point 00047 * off the surface. 00048 * 00049 * Planned updates: 00050 * Provide appropriate oblique versions for cylindrical and 00051 * pseudo-cylindrical projections in sphere2plane 00052 * 00053 * Revision history is at end of file. 00054 */ 00055 #include <math.h> 00056 00057 #define RECTANGULAR (0) 00058 #define CASSINI (1) 00059 #define MERCATOR (2) 00060 #define CYLEQA (3) 00061 #define SINEQA (4) 00062 #define GNOMONIC (5) 00063 #define POSTEL (6) 00064 #define STEREOGRAPHIC (7) 00065 #define ORTHOGRAPHIC (8) 00066 #define LAMBERT (9) 00067 00068 static double arc_distance (double lat, double lon, double latc, double lonc) { 00069 double cosa = sin (lat) * sin (latc) + 00070 cos (lat) * cos (latc) * cos (lon - lonc); 00071 return acos (cosa); 00072 } 00073 00074 int img2sphere (double x, double y, double ang_r, double latc, double lonc, 00075 double pa, double *rho, double *lat, double *lon, double *sinlat, 00076 double *coslat, double *sig, double *mu, double *chi) { 00077 /* 00078 * Map projected coordinates (x, y) to (lon, lat) and (rho | sig, chi) 00079 * 00080 * Arguments: 00081 * x } Plate locations, in units of the image radius, relative 00082 * y } to the image center 00083 * ang_r Apparent semi-diameter of sun (angular radius of sun at 00084 * the observer's tangent line) 00085 * latc Latitude of disc center, uncorrected for light travel time 00086 * lonc Longitude of disc center 00087 * pa Position angle of solar north on image, measured eastward 00088 * from north (sky coordinates) 00089 * Return values: 00090 * rho Angle point:sun_center:observer 00091 * lon Heliographic longitude 00092 * lat Heliographic latitude 00093 * sinlat sine of heliographic latitude 00094 * coslat cosine of heliographic latitude 00095 * sig Angle point:observer:sun_center 00096 * mu cosine of angle between the point:observer line and the 00097 * local normal 00098 * chi Position angle on image measured westward from solar 00099 * north 00100 * 00101 * All angles are in radians. 00102 * Return value is 1 if point is outside solar radius (in which case the 00103 * heliographic coordinates and mu are meaningless), 0 otherwise. 00104 * It is assumed that the image is direct; the x or y coordinates require a 00105 * sign change if the image is inverted. 00106 * 00107 */ 00108 static double ang_r0 = 0.0, sinang_r = 0.0, tanang_r = 0.0; 00109 static double latc0 = 0.0, coslatc = 1.0, sinlatc = 0.0; 00110 double cosr, sinr, sinlon, sinsig; 00111 00112 if (ang_r != ang_r0) { 00113 sinang_r = sin (ang_r); 00114 tanang_r = tan (ang_r); 00115 ang_r0 = ang_r; 00116 } 00117 if (latc != latc0) { 00118 sinlatc = sin (latc); 00119 coslatc = cos (latc); 00120 latc0 = latc; 00121 } 00122 *chi = atan2 (x, y) + pa; 00123 while (*chi > 2 * M_PI) *chi -= 2 * M_PI; 00124 while (*chi < 0.0) *chi += 2 * M_PI; 00125 /* Camera curvature correction, no small angle approximations */ 00126 *sig = atan (hypot (x, y) * tanang_r); 00127 sinsig = sin (*sig); 00128 *rho = asin (sinsig / sinang_r) - *sig; 00129 if (*sig > ang_r) return (-1); 00130 *mu = cos (*rho + *sig); 00131 sinr = sin (*rho); 00132 cosr = cos (*rho); 00133 00134 *sinlat = sinlatc * cos (*rho) + coslatc * sinr * cos (*chi); 00135 *coslat = sqrt (1.0 - *sinlat * *sinlat); 00136 *lat = asin (*sinlat); 00137 sinlon = sinr * sin (*chi) / *coslat; 00138 *lon = asin (sinlon); 00139 if (cosr < (*sinlat * sinlatc)) *lon = M_PI - *lon; 00140 *lon += lonc; 00141 while (*lon < 0.0) *lon += 2 * M_PI; 00142 while (*lon >= 2 * M_PI) *lon -= 2 * M_PI; 00143 return (0); 00144 } 00145 00146 int plane2sphere (double x, double y, double latc, double lonc, 00147 double *lat, double *lon, int projection) { 00148 /* 00149 * Perform the inverse mapping from rectangular coordinates x, y on a map 00150 * in a particular projection to heliographic (or geographic) coordinates 00151 * latitude and longitude (in radians). 00152 * The map coordinates are first transformed into arc and azimuth coordinates 00153 * relative to the center of the map according to the appropriate inverse 00154 * transformation for the projection, and thence to latitude and longitude 00155 * from the known heliographic coordinates of the map center (in radians). 00156 * The scale of the map coordinates is assumed to be in units of radians at 00157 * the map center (or other appropriate location of minimum distortion). 00158 * 00159 * Arguments: 00160 * x } Map coordinates, in units of radians at the scale 00161 * y } appropriate to the map center 00162 * latc Latitude of the map center (in radians) 00163 * lonc Longitude of the map center (in radians) 00164 * *lat Returned latitude (in radians) 00165 * *lon Returned longitude (in radians) 00166 * projection A code specifying the map projection to be used: see below 00167 * 00168 * The following projections are supported: 00169 * RECTANGULAR A "rectangular" mapping of x and y directly to 00170 * longitude and latitude, respectively; it is the 00171 * normal cylindrical equidistant projection (plate 00172 * carrée) tangent at the equator and equidistant 00173 * along meridians. Central latitudes off the equator 00174 * merely result in displacement of the map in y 00175 * Also known as CYLEQD 00176 * CASSINI The transverse cylindrical equidistant projection 00177 * (Cassini-Soldner) equidistant along great circles 00178 * perpendicular to the central meridian 00179 * MERCATOR Mercator's conformal projection, in which paths of 00180 * constant bearing are straight lines 00181 * CYLEQA Lambert's normal equal cylindrical (equal-area) 00182 * projection, in which evenly-spaced meridians are 00183 * evenly spaced in x and evenly-spaced parallels are 00184 * separated by the cosine of the latitude 00185 * SINEQA The Sanson-Flamsteed sinusoidal equal-area projection, 00186 * in which evenly-spaced parallels are evenly spaced in 00187 * y and meridians are sinusoidal curves 00188 * GNOMONIC The gnomonic, or central, projection, in which all 00189 * straight lines correspond to geodesics; projection 00190 * from the center of the sphere onto a tangent plane 00191 * POSTEL Postel's azimuthal equidistant projection, in which 00192 * straight lines through the center of the map are 00193 * geodesics with a uniform scale 00194 * STEREOGRAPHIC The stereographic projection, mapping from the 00195 * antipode of the map center onto a tangent plane 00196 * ORTHOGRAPHIC The orthographic projection, mapping from infinity 00197 * onto a tangent plane 00198 * LAMBERT Lambert's azimuthal equivalent projection 00199 * 00200 * The function returns -1 if the requested point on the map does not project 00201 * back to the sphere or is not a principal value, 1 if it projects to a 00202 * point on a hidden hemisphere (if that makes sense), 0 otherwise 00203 */ 00204 static double latc0 = 0.0, sinlatc = 0.0, coslatc = 1.0 ; 00205 double r, rm, test; 00206 double cosr, sinr, cosp, sinp, coslat, sinlat, sinlon; 00207 double sinphi, cosphi, phicom; 00208 int status = 0; 00209 00210 if (latc != latc0) { 00211 coslatc = cos (latc); 00212 sinlatc = sin (latc); 00213 } 00214 latc0 = latc; 00215 00216 switch (projection) { 00217 case (RECTANGULAR): 00218 *lon = lonc + x; 00219 *lat = latc + y; 00220 if (arc_distance (*lat, *lon, latc, lonc) > M_PI_2) status = 1; 00221 if (fabs (x) > M_PI || fabs (y) > M_PI_2) status = -1; 00222 return status; 00223 case (CASSINI): { 00224 double sinx = sin (x); 00225 double cosy = cos (y + latc); 00226 double siny = sin (y + latc); 00227 *lat = acos (sqrt (cosy * cosy + siny * siny * sinx * sinx)); 00228 if (y < -latc) *lat *= -1; 00229 *lon = (fabs (*lat) < M_PI_2) ? lonc + asin (sinx / cos (*lat)) : lonc; 00230 if (y > (M_PI_2 - latc) || y < (-M_PI_2 - latc)) 00231 *lon = 2 * lonc + M_PI - *lon; 00232 if (*lon < -M_PI) *lon += 2* M_PI; 00233 if (*lon > M_PI) *lon -= 2 * M_PI; 00234 if (arc_distance (*lat, *lon, latc, lonc) > M_PI_2) status = 1; 00235 if (fabs (x) > M_PI || fabs (y) > M_PI_2) status = -1; 00236 return status; 00237 } 00238 case (CYLEQA): 00239 if (fabs (y) > 1.0) { 00240 y = copysign (1.0, y); 00241 status = -1; 00242 } 00243 cosphi = sqrt (1.0 - y*y); 00244 *lat = asin ((y * coslatc) + (cosphi * cos (x) * sinlatc)); 00245 test = (cos (*lat) == 0.0) ? 0.0 : cosphi * sin (x) / cos (*lat); 00246 *lon = asin (test) + lonc; 00247 if (fabs (x) > M_PI_2) { 00248 status = 1; 00249 while (x > M_PI_2) { 00250 *lon = M_PI - *lon; 00251 x -= M_PI; 00252 } 00253 while (x < -M_PI_2) { 00254 *lon = -M_PI - *lon; 00255 x += M_PI; 00256 } 00257 } 00258 if (arc_distance (*lat, *lon, latc, lonc) > M_PI_2) status = 1; 00259 return status; 00260 case (SINEQA): 00261 cosphi = cos (y); 00262 if (cosphi <= 0.0) { 00263 *lat = y; 00264 *lon = lonc; 00265 if (cosphi < 0.0) status = -1; 00266 return status; 00267 } 00268 *lat = asin ((sin (y) * coslatc) + (cosphi * cos (x/cosphi) * sinlatc)); 00269 coslat = cos (*lat); 00270 if (coslat <= 0.0) { 00271 *lon = lonc; 00272 if (coslat < 0.0) status = 1; 00273 return status; 00274 } 00275 test = cosphi * sin (x/cosphi) / coslat; 00276 *lon = asin (test) + lonc; 00277 if (fabs (x) > M_PI * cosphi) return (-1); 00278 /* 00279 if (fabs (x) > M_PI_2) { 00280 status = 1; 00281 while (x > M_PI_2) { 00282 *lon = M_PI - *lon; 00283 x -= M_PI; 00284 } 00285 while (x < -M_PI_2) { 00286 *lon = -M_PI - *lon; 00287 x += M_PI; 00288 } 00289 */ 00290 if (fabs (x) > M_PI_2 * cosphi) { 00291 status = 1; 00292 while (x > M_PI_2 * cosphi) { 00293 *lon = M_PI - *lon; 00294 x -= M_PI * cosphi; 00295 } 00296 while (x < -M_PI_2 * cosphi) { 00297 *lon = -M_PI - *lon; 00298 x += M_PI * cosphi; 00299 } 00300 } 00301 /* 00302 if (arc_distance (*lat, *lon, latc, lonc) > M_PI_2) status = 1; 00303 */ 00304 return status; 00305 case (MERCATOR): 00306 phicom = 2.0 * atan (exp (y)); 00307 sinphi = -cos (phicom); 00308 cosphi = sin (phicom); 00309 *lat = asin ((sinphi * coslatc) + (cosphi * cos (x) * sinlatc)); 00310 *lon = asin (cosphi * sin (x) / cos (*lat)) + lonc; 00311 if (arc_distance (*lat, *lon, latc, lonc) > M_PI_2) status = 1; 00312 if (fabs (x) > M_PI_2) status = -1; 00313 return status; 00314 } 00315 /* Convert to polar coordinates */ 00316 r = hypot (x, y); 00317 cosp = (r == 0.0) ? 1.0 : x / r; 00318 sinp = (r == 0.0) ? 0.0 : y / r; 00319 /* Convert to arc */ 00320 switch (projection) { 00321 case (POSTEL): 00322 rm = r; 00323 if (rm > M_PI_2) status = 1; 00324 break; 00325 case (GNOMONIC): 00326 rm = atan (r); 00327 break; 00328 case (STEREOGRAPHIC): 00329 rm = 2 * atan (0.5 * r); 00330 if (rm > M_PI_2) status = 1; 00331 break; 00332 case (ORTHOGRAPHIC): 00333 if ( r > 1.0 ) { 00334 r = 1.0; 00335 status = -1; 00336 } 00337 rm = asin (r); 00338 break; 00339 case (LAMBERT): 00340 if ( r > 2.0 ) { 00341 r = 2.0; 00342 status = -1; 00343 } 00344 rm = 2 * asin (0.5 * r); 00345 if (rm > M_PI_2 && status == 0) status = 1; 00346 break; 00347 } 00348 cosr = cos (rm); 00349 sinr = sin (rm); 00350 /* Convert to latitude-longitude */ 00351 sinlat = sinlatc * cosr + coslatc * sinr * sinp; 00352 *lat = asin (sinlat); 00353 coslat = cos (*lat); 00354 sinlon = (coslat == 0.0) ? 0.0 : sinr * cosp / coslat; 00355 /* This should never happen except for roundoff errors, but just in case: */ 00356 /* 00357 if (sinlon + 1.0 <= 0.0) *lon = -M_PI_2; 00358 else if (sinlon - 1.0 >= 0.0) *lon = M_PI_2; 00359 else 00360 */ 00361 *lon = asin (sinlon); 00362 /* Correction suggested by Dick Shine */ 00363 if (cosr < (sinlat * sinlatc)) *lon = M_PI - *lon; 00364 *lon += lonc; 00365 return status; 00366 } 00367 00368 int sphere2img (double lat, double lon, double latc, double lonc, 00369 double *x, double *y, double xcenter, double ycenter, 00370 double rsun, double peff, double ecc, double chi, 00371 int xinvrt, int yinvrt) { 00372 /* 00373 * Perform a mapping from heliographic coordinates latitude and longitude 00374 * (in radians) to plate location on an image of the sun. The plate 00375 * location is in units of the image radius and is given relative to 00376 * the image center. The function returns 1 if the requested point is 00377 * on the far side (>90 deg from disc center), 0 otherwise. 00378 * 00379 * Arguments: 00380 * lat Latitude (in radians) 00381 * lon Longitude (in radians) 00382 * latc Heliographic latitude of the disc center (in radians) 00383 * lonc Heliographic longitude of the disc center (in radians) 00384 * *x } Plate locations, in units of the image radius, relative 00385 * *y } to the image center 00386 * xcenter } Plate locations of the image center, in units of the 00387 * ycenter } image radius, and measured from an arbitrary origin 00388 * (presumably the plate center or a corner) 00389 * rsun Apparent semi-diameter of the solar disc, in plate 00390 * coordinates 00391 * peff Position angle of the heliographic pole, measured 00392 * eastward from north, relative to the north direction 00393 * on the plate, in radians 00394 * ecc Eccentricity of the fit ellipse presumed due to image 00395 * distortion (no distortion in direction of major axis) 00396 * chi Position angle of the major axis of the fit ellipse, 00397 * measure eastward from north, relative to the north 00398 * direction on the plate, in radians (ignored if ecc = 0) 00399 * xinvrt} Flag parameters: if not equal to 0, the respective 00400 * yinvrt} coordinates on the image x and y are inverted 00401 * 00402 * The heliographic coordinates are first mapped into the polar coordinates 00403 * in an orthographic projection centered at the appropriate location and 00404 * oriented with north in direction of increasing y and west in direction 00405 * of increasing x. The radial coordinate is corrected for foreshortening 00406 * due to the finite distance to the Sun. If the eccentricity of the fit 00407 * ellipse is non-zero the coordinate of the mapped point is proportionately 00408 * reduced in the direction parallel to the minor axis. 00409 * 00410 * Bugs: 00411 * The finite distance correction uses a fixed apparent semi-diameter 00412 * of 16'01'' appropriate to 1.0 AU. In principle the plate radius could 00413 * be used, but this would require the plate scale to be supplied and the 00414 * correction would probably be erroneous and in any case negligible. 00415 * 00416 * The ellipsoidal correction has not been tested very thoroughly. 00417 * 00418 * The return value is based on a test which does not take foreshortening 00419 * into account. 00420 */ 00421 static double sin_asd = 0.004660, cos_asd = 0.99998914; 00422 /* appropriate to 1 AU */ 00423 static double last_latc = 0.0, cos_latc = 1.0, sin_latc = 0.0; 00424 double r, cos_cang, xr, yr; 00425 double sin_lat, cos_lat, cos_lat_lon, cospa, sinpa; 00426 double squash, cchi, schi, c2chi, s2chi, xp, yp; 00427 int hemisphere; 00428 00429 if (latc != last_latc) { 00430 sin_latc = sin (latc); 00431 cos_latc = cos (latc); 00432 last_latc = latc; 00433 } 00434 sin_lat = sin (lat); 00435 cos_lat = cos (lat); 00436 cos_lat_lon = cos_lat * cos (lon - lonc); 00437 00438 cos_cang = sin_lat * sin_latc + cos_latc * cos_lat_lon; 00439 hemisphere = (cos_cang < 0.0) ? 1 : 0; 00440 r = rsun * cos_asd / (1.0 - cos_cang * sin_asd); 00441 xr = r * cos_lat * sin (lon - lonc); 00442 yr = r * (sin_lat * cos_latc - sin_latc * cos_lat_lon); 00443 /* Change sign for inverted images */ 00444 if (xinvrt) xr *= -1.0; 00445 if (yinvrt) yr *= -1.0; 00446 /* Correction for ellipsoidal squashing of image */ 00447 if (ecc > 0.0 && ecc < 1.0) { 00448 squash = sqrt (1.0 - ecc * ecc); 00449 cchi = cos (chi); 00450 schi = sin (chi); 00451 s2chi = schi * schi; 00452 c2chi = 1.0 - s2chi; 00453 xp = xr * (s2chi + squash * c2chi) - yr * (1.0 - squash) * schi * cchi; 00454 yp = yr * (c2chi + squash * s2chi) - xr * (1.0 - squash) * schi * cchi; 00455 xr = xp; 00456 yr = yp; 00457 } 00458 00459 cospa = cos (peff); 00460 sinpa = sin (peff); 00461 *x = xr * cospa - yr * sinpa; 00462 *y = xr * sinpa + yr * cospa; 00463 00464 *y += ycenter; 00465 *x += xcenter; 00466 00467 return (hemisphere); 00468 } 00469 00470 int sphere2plane (double lat, double lon, double latc, double lonc, 00471 double *x, double *y, int projection) { 00472 /* 00473 * Perform a mapping from heliographic (or geographic or celestial) 00474 * coordinates latitude and longitude (in radians) to map location in 00475 * the given projection. The function returns 1 if the requested point is 00476 * on the far side (>90 deg from disc center), 0 otherwise. 00477 * 00478 * Arguments: 00479 * lat Latitude (in radians) 00480 * lon Longitude (in radians) 00481 * latc Heliographic latitude of the disc center (in radians) 00482 * lonc Heliographic longitude of the disc center (in radians) 00483 * *x } Plate locations, in units of the image radius, relative 00484 * *y } to the image center 00485 * projection code specifying the map projection to be used: 00486 * see plane2sphere 00487 */ 00488 static double last_latc = 0.0, cos_latc = 1.0, sin_latc = 0.0, yc_merc; 00489 double r, rm, cos_cang; 00490 double sin_lat, cos_lat, cos_lat_lon; 00491 int hemisphere; 00492 00493 if (latc != last_latc) { 00494 sin_latc = sin (latc); 00495 cos_latc = cos (latc); 00496 last_latc = latc; 00497 yc_merc = log (tan (M_PI_4 + 0.5 * latc)); 00498 } 00499 sin_lat = sin (lat); 00500 cos_lat = cos (lat); 00501 cos_lat_lon = cos_lat * cos (lon - lonc); 00502 cos_cang = sin_lat * sin_latc + cos_latc * cos_lat_lon; 00503 hemisphere = (cos_cang < 0.0) ? 1 : 0; 00504 /* Cylindrical projections */ 00505 switch (projection) { 00506 /* Normal cylindrical equidistant */ 00507 case (RECTANGULAR): 00508 *x = lon - lonc; 00509 *y = lat - latc; 00510 return hemisphere; 00511 /* Transverse cylindrical equidistant */ 00512 case (CASSINI): 00513 *x = asin (cos_lat * sin (lon - lonc)); 00514 *y = atan2 (tan (lat), cos (lon - lonc)) - latc; 00515 return hemisphere; 00516 /* Normal cylindrical equivalent - differs from sphere2plane */ 00517 case (CYLEQA): 00518 *x = lon - lonc; 00519 *y = sin_lat - sin_latc; 00520 return hemisphere; 00521 /* Normal sinusoidal equivalent - differs from sphere2plane */ 00522 case (SINEQA): 00523 *x = cos_lat * (lon - lonc); 00524 *y = lat - latc; 00525 return hemisphere; 00526 /* Normal Mercator - differs from sphere2plane */ 00527 case (MERCATOR): 00528 *x = lon - lonc; 00529 *y = log (tan (M_PI_4 + 0.5 * lat)) - yc_merc; 00530 return hemisphere; 00531 } 00532 /* Azimuthal projections */ 00533 rm = acos (cos_cang); 00534 00535 switch (projection) { 00536 case (POSTEL): 00537 r = rm; 00538 break; 00539 case (GNOMONIC): 00540 r = tan (rm); 00541 break; 00542 case (STEREOGRAPHIC): 00543 r = 2.0 * tan (0.5 * rm); 00544 break; 00545 case (ORTHOGRAPHIC): 00546 r = sin (rm); 00547 break; 00548 case (LAMBERT): 00549 r = 2.0 * sin (0.5 * rm); 00550 break; 00551 default: 00552 return -1; 00553 } 00554 if (rm != 0.) { 00555 *x = r * cos_lat * sin (lon - lonc) / sin (rm); 00556 *y = r * (sin_lat * cos_latc - sin_latc * cos_lat_lon) / sin(rm); 00557 } else { 00558 *x = 0.; 00559 *y = 0.; 00560 } 00561 return hemisphere; 00562 } 00563 00564 /********************************************************************** 00565 * Projection names package -- contains a structure 00566 * with the conversion between names and numeric constants 00567 * for the different projections. Also two subroutines to walk back and 00568 * forth. The projection names are case inseNSiTIVe. 00569 * 00570 * The first table entry is the default value for the projection 00571 * if an unknown string is entered. 00572 */ 00573 static struct projnames { 00574 int projection; 00575 char *name; 00576 char *lowname; 00577 int uniq; 00578 } projnames[]= { 00579 {ORTHOGRAPHIC, "orthographic", "orthographic"}, 00580 {STEREOGRAPHIC, "stereographic", "stereographic"}, 00581 {POSTEL, "Postel\'s", "postels"}, 00582 {GNOMONIC, "Gnomonic", "gnomonic"}, 00583 {LAMBERT, "Lambert", "lambert"}, 00584 {CYLEQA, "cyleqa", "cyleqa"}, 00585 {SINEQA, "sineqa", "sineqa"}, 00586 {MERCATOR, "Mercator", "mercator"}, 00587 {RECTANGULAR, "plate carree", "plate carree"}, 00588 {CASSINI, "Cassini\'s", "cassinis"}, 00589 {-1, "", ""} 00590 }; 00591 00592 int name2proj (char *map_name) { 00593 char *s0, *s, *t; 00594 struct projnames *proj; 00595 00596 if (!map_name) return -1; 00597 00598 s0 = s = (char *)(malloc (strlen (map_name) + 1)); /* sic */ 00599 strcpy (s, map_name); 00600 for (t = s; *t; t++) *t = tolower (*t); 00601 /* trim leading and trailing whitespace */ 00602 for(; isspace (*s); s++); 00603 for (t = s; *t && !isspace (*t); t++); 00604 *t = '\0'; 00605 /* check for name */ 00606 for (proj=projnames; *(proj->name); proj++) { 00607 if (!strcmp (proj->lowname, s)) { 00608 free (s0); 00609 return proj->projection; 00610 } 00611 } 00612 00613 free (s0); 00614 return projnames->projection; 00615 } 00616 00617 00618 char *proj2name(int proj_in) { 00619 struct projnames *proj; 00620 for (proj=projnames; *(proj->name); proj++) { 00621 if (proj->projection == proj_in) return proj->name; 00622 } 00623 return "UNKNOWN"; 00624 } 00625 00626 00627 /* 00628 * Revision History 00629 * v 0.9 94.08.03 Rick Bogart created this file 00630 * 94.10.27 R Bogart reorganized for inclusion in libM 00631 * 94.11.24 R Bogart fixed bug in sinusoidal equal-area 00632 * mapping and minor bug in cylindrical equal-area mapoing 00633 * (latc != 0); added Mercator projection; more comments 00634 * 94.12.12 R Bogart & Luiz Sa fixed non-azimuthal projections 00635 * in plane2sphere to support center of map at other than L0L0; 00636 * removed unnecessary (and incorrect) scaling in azimuthal 00637 * mappings 00638 * v 1.0 95.08.18 R Bogart & L Sa implemented optimum_scale(); 00639 * added arguments and code to sphere2img() to deal with elliptic 00640 * images and image inversion; additional comments; 00641 * minor fix in SINEQA option of plane2sphere(); changed sign on 00642 * on position angle used in sphere2img() to conform with standard 00643 * usage (positive eastward from north in sky) 00644 * 96.05.17 R Bogart fixed bug in longitude calculation of 00645 * points "over the pole" for azimuthal projections in plane2sphere() 00646 * and corrected bug in sphere2img(). 00647 * 96.06.07 R Bogart return status of sphere2img indicates 00648 * whether mapped point is on far side of globe. 00649 * 96.12.18 R Bogart removed debugging prints from function 00650 * optimum_scale() 00651 * 97.01.21 R Bogart plane2sphere now returns status 00652 * 98.09.02 R Bogart added img2sphere 00653 * 99.02.25 R Bogart fixed calculated chi in img2sphere to 00654 * conform to man page description; plane2sphere now returns 1 if 00655 * requested point is not principal value in rectangular, cylindrical 00656 * equal-area, sinusoidal equal-area, and Mercator projections 00657 * 99.12.13 R Bogart added sphere2plane 00658 * 00.04.24 R Bogart modifications to plane2sphere to avoid 00659 * occasional roundoff errors leading to undefined results at the 00660 * limb 00661 * 05.01.07 R Bogart fixed bug in longitude calculation in 00662 * plane2sphere() for points more than 90deg from target longitude 00663 * of map center 00664 * 06.11.10 R Bogart fixed return value of sphere2plane for 00665 * cylindrical projection(s); added support for Cassini's projection 00666 * (transverse cylindrical equidistant); added support for normal 00667 * cylindrical and pseudocylindrical projections to sphere2plane 00668 * 09.07.02 R Bogart copied to private location for inclusion in 00669 * DRMS modules and standalone code; removed optimum_scale(), pow2scale(), 00670 * name2proj(), proj2name() 00671 * 09.12.02 R Bogart fixed two icc11 compiler warnings 00672 * 14.02.06 " fixed over-limb sinusoidal equal-area mapping 00673 * bug for plane2sphere (not thoroughly tested) 00674 * 14.08.01 " restored name2proj(), proj2name() from original 00675 * source (but removing "Aerial") 00676 */