dsmuch.c - a quick and dirty program to split out NGS survey control datasheets

havard

Havard
Staff member
Admin
Hoppy Gorilla
Note:
This is a repost from my old livejournal on Dec. 30th, 2006 06:22 pm

The National Geodetic Survey is responsible for the various survey markes, triangulation stations, benchmarks and all that mess. The data about all those points for all those various markers are available from their FTP server, but the datasheets for the individual survey markers are bundled into county or state-sized chunks. I needed a way to split these into individual datasheets for a project I'm working on. Here's a program I wrote to do just that. It's very dirty, and does things The Wrong Way, but it runs fairly fast and was written in under 15 minutes. It was able to spit out all 755,000 data sheets in just over an hour.

C:
#include <stdio.h>

int main(int argc, char **argv) {
        FILE *f, *ds;

        int dsopen = 0;
        char line[1024], pidname[7], lpidname[7], dsfnam[128];
        f = fopen(argv[1], "r");
       
        while (! feof(f)) {
                fgets(line, 1024, f);
                strlcpy(lpidname,line+1,7);
                if (line[0] == '1') {
                        if (dsopen == 1) {
                                fclose(ds);
                        }
                        fgets(line, 1024, f);
                        strlcpy(lpidname,line+1,7);
                        strcpy(pidname,lpidname);
                        sprintf(dsfnam, "/a/SurveyMarkers/ds/%s", pidname);
                        ds = fopen(dsfnam, "w");
                        dsopen = 1;
                        printf("Opened file %s\n", dsfnam);
                }
                if (strcmp(pidname,lpidname) != 0) {
                        dsopen = 0;
                }
                if (dsopen == 1) {
                        fputs(line+7, ds);
                }
        }
}
 
Top