/Proj4/nad2bin.c

http://github.com/route-me/route-me · C · 68 lines · 65 code · 1 blank · 2 comment · 12 complexity · 5ccc77c1c521574082bbd35329ef35e2 MD5 · raw file

  1. /* Convert bivariate ASCII NAD27 to NAD83 tables to binary structure */
  2. #ifndef lint
  3. static const char SCCSID[]="@(#)nad2bin.c 4.2 93/08/25 GIE REL";
  4. #endif
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #define PJ_LIB__
  8. #include "projects.h"
  9. #define U_SEC_TO_RAD 4.848136811095359935899141023e-12
  10. static char
  11. *usage = "<ASCII_dist_table local_bin_table";
  12. void
  13. main(int argc, char **argv) {
  14. struct CTABLE ct;
  15. FLP *p, t;
  16. size_t tsize;
  17. int i, j, ichk;
  18. long lam, laml, phi, phil;
  19. FILE *bin;
  20. if (argc != 2) {
  21. fprintf(stderr,"usage: %s %s\n", argv[0], usage);
  22. exit(1);
  23. }
  24. fgets(ct.id, MAX_TAB_ID, stdin);
  25. scanf("%d %d %*d %lf %lf %lf %lf", &ct.lim.lam, &ct.lim.phi,
  26. &ct.ll.lam, &ct.del.lam, &ct.ll.phi, &ct.del.phi);
  27. if (!(ct.cvs = (FLP *)malloc(tsize = ct.lim.lam * ct.lim.phi *
  28. sizeof(FLP)))) {
  29. perror("mem. alloc");
  30. exit(1);
  31. }
  32. ct.ll.lam *= DEG_TO_RAD;
  33. ct.ll.phi *= DEG_TO_RAD;
  34. ct.del.lam *= DEG_TO_RAD;
  35. ct.del.phi *= DEG_TO_RAD;
  36. /* load table */
  37. for (p = ct.cvs, i = 0; i < ct.lim.phi; ++i) {
  38. scanf("%d:%ld %ld", &ichk, &laml, &phil);
  39. if (ichk != i) {
  40. fprintf(stderr,"format check on row\n");
  41. exit(1);
  42. }
  43. t.lam = laml * U_SEC_TO_RAD;
  44. t.phi = phil * U_SEC_TO_RAD;
  45. *p++ = t;
  46. for (j = 1; j < ct.lim.lam; ++j) {
  47. scanf("%ld %ld", &lam, &phi);
  48. t.lam = (laml += lam) * U_SEC_TO_RAD;
  49. t.phi = (phil += phi) * U_SEC_TO_RAD;
  50. *p++ = t;
  51. }
  52. }
  53. if (feof(stdin)) {
  54. fprintf(stderr, "premature EOF\n");
  55. exit(1);
  56. }
  57. if (!(bin = freopen(argv[1], "wb", stdout))) {
  58. perror(argv[1]);
  59. exit(2);
  60. }
  61. if (fwrite(&ct, sizeof(ct), 1, stdout) != 1 ||
  62. fwrite(ct.cvs, tsize, 1, stdout) != 1) {
  63. fprintf(stderr, "output failure\n");
  64. exit(2);
  65. }
  66. exit(0); /* normal completion */
  67. }