Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-proj4 / src / nad2bin.c @ 7098

History | View | Annotate | Download (1.68 KB)

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

    
21
        if (argc != 2) {
22
                fprintf(stderr,"usage: %s %s\n", argv[0], usage);
23
                exit(1);
24
        }
25
        fgets(ct.id, MAX_TAB_ID, stdin);
26
        scanf("%d %d %*d %lf %lf %lf %lf", &ct.lim.lam, &ct.lim.phi,
27
                &ct.ll.lam, &ct.del.lam, &ct.ll.phi, &ct.del.phi);
28
        if (!(ct.cvs = (FLP *)malloc(tsize = ct.lim.lam * ct.lim.phi *
29
                sizeof(FLP)))) {
30
                perror("mem. alloc");
31
                exit(1);
32
        }
33
        ct.ll.lam *= DEG_TO_RAD;
34
        ct.ll.phi *= DEG_TO_RAD;
35
        ct.del.lam *= DEG_TO_RAD;
36
        ct.del.phi *= DEG_TO_RAD;
37
        /* load table */
38
        for (p = ct.cvs, i = 0; i < ct.lim.phi; ++i) {
39
                scanf("%d:%ld %ld", &ichk, &laml, &phil);
40
                if (ichk != i) {
41
                        fprintf(stderr,"format check on row\n");
42
                        exit(1);
43
                }
44
                t.lam = laml * U_SEC_TO_RAD;
45
                t.phi = phil * U_SEC_TO_RAD;
46
                *p++ = t;
47
                for (j = 1; j < ct.lim.lam; ++j) {
48
                        scanf("%ld %ld", &lam, &phi);
49
                        t.lam = (laml += lam) * U_SEC_TO_RAD;
50
                        t.phi = (phil += phi) * U_SEC_TO_RAD;
51
                        *p++ = t;
52
                }
53
        }
54
        if (feof(stdin)) {
55
                fprintf(stderr, "premature EOF\n");
56
                exit(1);
57
        }
58
        if (!(bin = freopen(argv[1], "wb", stdout))) {
59
                perror(argv[1]);
60
                exit(2);
61
        }
62
        if (fwrite(&ct, sizeof(ct), 1, stdout) != 1 ||
63
                fwrite(ct.cvs, tsize, 1, stdout) != 1) {
64
                fprintf(stderr, "output failure\n");
65
                exit(2);
66
        }
67
        exit(0); /* normal completion */
68
}