/Proj4/geod_set.c

http://github.com/route-me/route-me · C · 79 lines · 71 code · 3 blank · 5 comment · 23 complexity · c575464901c6918f962bba20d37f8286 MD5 · raw file

  1. #ifndef lint
  2. static const char SCCSID[]="@(#)geod_set.c 4.8 95/09/23 GIE REL";
  3. #endif
  4. #define _IN_GEOD_SET
  5. #include <string.h>
  6. #include "projects.h"
  7. #include "geodesic.h"
  8. #include "emess.h"
  9. void
  10. geod_set(int argc, char **argv) {
  11. paralist *start = 0, *curr = 0;
  12. double es;
  13. char *name;
  14. int i;
  15. /* put arguments into internal linked list */
  16. if (argc <= 0)
  17. emess(1, "no arguments in initialization list");
  18. for (i = 0; i < argc; ++i)
  19. if (i)
  20. curr = curr->next = pj_mkparam(argv[i]);
  21. else
  22. start = curr = pj_mkparam(argv[i]);
  23. /* set elliptical parameters */
  24. if (pj_ell_set(start, &geod_a, &es)) emess(1,"ellipse setup failure");
  25. /* set units */
  26. name = pj_param(start, "sunits").s;
  27. if (name) {
  28. char *s;
  29. struct PJ_UNITS *unit_list = pj_get_units_ref();
  30. for (i = 0; (s = unit_list[i].id) && strcmp(name, s) ; ++i) ;
  31. if (!s)
  32. emess(1,"%s unknown unit conversion id", name);
  33. fr_meter = 1. / (to_meter = atof(unit_list[i].to_meter));
  34. } else
  35. to_meter = fr_meter = 1.;
  36. ellipse = es != 0.;
  37. if (ellipse) {
  38. onef = sqrt(1. - es);
  39. geod_f = 1 - onef;
  40. f2 = geod_f/2;
  41. f4 = geod_f/4;
  42. f64 = geod_f*geod_f/64;
  43. } else {
  44. onef = 1.;
  45. geod_f = f2 = f4 = f64 = 0.;
  46. }
  47. /* check if line or arc mode */
  48. if (pj_param(start, "tlat_1").i) {
  49. double del_S;
  50. #undef f
  51. phi1 = pj_param(start, "rlat_1").f;
  52. lam1 = pj_param(start, "rlon_1").f;
  53. if (pj_param(start, "tlat_2").i) {
  54. phi2 = pj_param(start, "rlat_2").f;
  55. lam2 = pj_param(start, "rlon_2").f;
  56. geod_inv();
  57. geod_pre();
  58. } else if ((geod_S = pj_param(start, "dS").f)) {
  59. al12 = pj_param(start, "rA").f;
  60. geod_pre();
  61. geod_for();
  62. } else emess(1,"incomplete geodesic/arc info");
  63. if ((n_alpha = pj_param(start, "in_A").i) > 0) {
  64. if (!(del_alpha = pj_param(start, "rdel_A").f))
  65. emess(1,"del azimuth == 0");
  66. } else if ((del_S = fabs(pj_param(start, "ddel_S").f))) {
  67. n_S = geod_S / del_S + .5;
  68. } else if ((n_S = pj_param(start, "in_S").i) <= 0)
  69. emess(1,"no interval divisor selected");
  70. }
  71. /* free up linked list */
  72. for ( ; start; start = curr) {
  73. curr = start->next;
  74. pj_dalloc(start);
  75. }
  76. }