/********************************************************************************* * * File: getcat-2001.c * * Remaps the NLCD 2001 urban land use categories to the indices expected by * the WRF UCM; all non-urban categories are discarded. * *********************************************************************************/ #include #include #include #include #include #include #include int main(int argc, char ** argv) { size_t datlen, i; struct stat st; int fdin, fdout; unsigned char * dat; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } printf("Opening input file %s\n", argv[1]); if ((fdin = open(argv[1], O_RDONLY)) == -1) { fprintf(stderr, "Error opening input file %s\n", argv[1]); return 1; } /* Get size of the input file */ i = fstat(fdin, &st); datlen = (size_t)st.st_size; fprintf(stderr, "Reading %ld bytes from %s\n", (long)datlen, argv[1]); /* Allocate working array */ dat = (unsigned char *)malloc(datlen); read(fdin,dat,datlen); close(fdin); /* * Remap urban categories */ for(i=0; i