File: nad2bin.c

package info (click to toggle)
python-pyproj 1.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 9,192 kB
  • sloc: ansic: 10,983; python: 510; makefile: 6
file content (65 lines) | stat: -rw-r--r-- 1,631 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Convert bivariate ASCII NAD27 to NAD83 tables to binary structure */
#include <stdio.h>
#include <stdlib.h>
#define PJ_LIB__
#include <projects.h>
#define U_SEC_TO_RAD 4.848136811095359935899141023e-12
	static char
*usage = "<ASCII_dist_table local_bin_table";

int main(int argc, char **argv) {
	struct CTABLE ct;
	FLP *p, t;
	size_t tsize;
	int i, j, ichk;
	long lam, laml, phi, phil;
	FILE *bin;

	if (argc != 2) {
		fprintf(stderr,"usage: %s %s\n", argv[0], usage);
		exit(1);
	}
	fgets(ct.id, MAX_TAB_ID, stdin);
	scanf("%d %d %*d %lf %lf %lf %lf", &ct.lim.lam, &ct.lim.phi,
		&ct.ll.lam, &ct.del.lam, &ct.ll.phi, &ct.del.phi);
	if (!(ct.cvs = (FLP *)malloc(tsize = ct.lim.lam * ct.lim.phi *
		sizeof(FLP)))) {
		perror("mem. alloc");
		exit(1);
	}
	ct.ll.lam *= DEG_TO_RAD;
	ct.ll.phi *= DEG_TO_RAD;
	ct.del.lam *= DEG_TO_RAD;
	ct.del.phi *= DEG_TO_RAD;
	/* load table */
	for (p = ct.cvs, i = 0; i < ct.lim.phi; ++i) {
		scanf("%d:%ld %ld", &ichk, &laml, &phil);
		if (ichk != i) {
			fprintf(stderr,"format check on row\n");
			exit(1);
		}
		t.lam = laml * U_SEC_TO_RAD;
		t.phi = phil * U_SEC_TO_RAD;
		*p++ = t;
		for (j = 1; j < ct.lim.lam; ++j) {
			scanf("%ld %ld", &lam, &phi);
			t.lam = (laml += lam) * U_SEC_TO_RAD;
			t.phi = (phil += phi) * U_SEC_TO_RAD;
			*p++ = t;
		}
	}
	if (feof(stdin)) {
		fprintf(stderr, "premature EOF\n");
		exit(1);
	}
	if (!(bin = freopen(argv[1], "wb", stdout))) {
		perror(argv[1]);
		exit(2);
	}
	if (fwrite(&ct, sizeof(ct), 1, stdout) != 1 ||
		fwrite(ct.cvs, tsize, 1, stdout) != 1) {
		fprintf(stderr, "output failure\n");
		exit(2);
	}
	exit(0); /* normal completion */
}