get_deg.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* get_deg.c 1.0 6/182/91
  2. * Created by : R.L.Glenn , Soil Conservation Service, USDA
  3. * Purpose: function
  4. * Provide a means of collecting user lat/long
  5. * data, in different formats; convert to
  6. * decimal degrees
  7. * Input arguments : lat or long string and
  8. * a 1 for latitude or 0 for longitude
  9. * Output arguments: decimal degrees in string
  10. *
  11. * Note: All functions are callable directly see
  12. * g.get_stp g.get_fips g.stp_proj geo
  13. *
  14. */
  15. #include <stdio.h>
  16. #include <unistd.h>
  17. #include <ctype.h>
  18. #include <string.h>
  19. #include <sys/types.h>
  20. #include <grass/gis.h>
  21. int get_deg(char *strng, int ll_swt)
  22. {
  23. double degrees;
  24. switch (ll_swt) {
  25. case 0:
  26. {
  27. if (!G_scan_easting(strng, &degrees, PROJECTION_LL)) {
  28. fprintf(stderr,
  29. "\n\t** %s is invalid for longitude **\n", strng);
  30. G_sleep(2);
  31. return (0);
  32. }
  33. break;
  34. }
  35. case 1:
  36. {
  37. if (G_scan_northing(strng, &degrees, PROJECTION_LL) == 0) {
  38. fprintf(stderr,
  39. "\n\t** %s is invalid for latitude **\n", strng);
  40. G_sleep(2);
  41. return (0);
  42. }
  43. break;
  44. }
  45. } /* end of switch */
  46. sprintf(strng, "%.10f", degrees);
  47. return (1);
  48. }