[Proj] NADCON, et al.

Gerald I. Evenden geraldi.evenden at gmail.com
Sat Jun 13 13:07:46 EST 2009

The following is something that should work on Linux and probably BSD, Unix 
but I have *no idea* if it will work on any of the Microsoft compilers.  If 
anyone is so inclined could you compile and test the following.


Before execution set the environment variable to a directory that contains any 
of the grid correction types like nadcon, hpgn, ... .

An example of execution on may machine is

gie at charon:~/tmp$ ./a.out nadcon
NADCON: prvi.las
NADCON: hawaii.las
NADCON: stgeorge.las
NADCON: alaska.las
NADCON: conus.las
NADCON: stlrnc.las
NADCON: stpaul.las
gie at charon:~/tmp$

Many thanks.

Source code---*very* straight forward other than the fact I did not translate 
to lower case the file names:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <sys/types.h>
#include <dirent.h>
int main(int argc, char *argv[]) {
	struct dirent *D;
	DIR *dir;
	const char *dirname;
	enum {NADCON, HPGN, NTv1, NTv2} grid_type = NADCON;

	assert((dirname = getenv("PROJ_GRIDS")) != NULL);
	assert((dir = opendir(dirname)) != NULL);
	if (argc == 2)
		if ( strcasecmp(argv[1], "nadcon") == 0)
			grid_type = NADCON;
		else if ( strcasecmp(argv[1], "hpgn") == 0)
			grid_type = HPGN;
		else if ( strcmp(argv[1], "NTv1") == 0)
			grid_type = NTv1;
		else if ( strcmp(argv[1], "NTv2") == 0)
			grid_type = NTv2;
		else {
			fprintf(stderr, "execute %s file_type\n", argv[0]);
	while ((D = readdir(dir)) != NULL) {
		if (D->d_type == DT_REG) {
			switch (grid_type) {
			case NADCON:
				if ((strstr(D->d_name, ".las") != 0) &&
					(strstr(D->d_name, "hpgn.") == 0))
					printf("NADCON: %s\n", D->d_name);
			case HPGN:
				if (strstr(D->d_name, "hpgn.las") != 0)
					printf("HPGN: %s\n", D->d_name);
			case NTv1:
			case NTv2:
				if (strstr(D->d_name, ".gas") != 0)
					printf("MTv[1|2]: %s\n", D->d_name);
				fprintf(stderr, "program logic error\n");

The whole religious complexion of the modern world is due
to the absence from Jerusalem of a lunatic asylum.
-- Havelock Ellis (1859-1939) British psychologist

More information about the Proj mailing list