aboutsummaryrefslogtreecommitdiff
path: root/src/nad_init.c
blob: ad6a48d487cc0370c0607c2f6a56cd76ea57bc17 (plain)
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
/* open structure for NAD27<->NAD83 conversion */
#ifndef lint
static const char SCCSID[]="@(#)nad_init.c	4.5   94/10/30 GIE REL";
#endif
#define PJ_LIB__
#include <projects.h>
#include <stdio.h>
#include <errno.h>
extern FILE *pj_open_lib(char *, char *);
	struct CTABLE *
nad_init(char *name) {
	char fname[MAX_PATH_FILENAME+1];
	struct CTABLE *ct;
	FILE *fid;
	size_t i;

	errno = pj_errno = 0;
	strcpy(fname, name);
	if (!(fid = pj_open_lib(fname, "rb"))) {
		pj_errno = errno;
		return 0;
	}
	if (!(ct = pj_malloc(sizeof(struct CTABLE))) ||
		fread(ct, sizeof(struct CTABLE), 1, fid) != 1 ||
		!(ct->cvs = (FLP *)pj_malloc(i=sizeof(FLP)*ct->lim.lam*ct->lim.phi)) ||
		fread(ct->cvs, i, 1, fid) != 1) {
		nad_free(ct);
		pj_errno = -38;
		ct = 0;
		return 0;
	}
	fclose(fid);
	pj_errno = 0;
	return ct;
}
	void
nad_free(struct CTABLE *ct) {
	if (ct) {
		pj_dalloc(ct->cvs);
		pj_dalloc(ct);
	}
}