/* splitgpx -- split GPX on waypoints Copyright (C) 2011 Frans Faase This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. GNU General Public License: http://www.iwriteiam.nl/GNU.txt Description: This program when run as pipe command, processes a GPX file saved with @Trip PC such that the single track is split with the enclosed waypoints in tracks where the name of the track is determined by the times mentiones in the waypoints. This is a rather low-level implementation, which does not really parse the GPX as XML, as it should, but it works for my purpose. This program is mentioned on http://www.iwriteiam.nl/D1109.html#10b */ #include #include char buffer[2001]; void getLine(FILE* f) { if (!fgets(buffer, 2000, f)) buffer[0] = '\n'; else { int len = strlen(buffer); while (len > 0 && (buffer[len-1] < ' ')) buffer[--len] = '\0'; } } class Waypoint { public: Waypoint() : next(0) {} char coord[200]; char ele[200]; char time[200]; Waypoint *next; }; Waypoint* all_waypoints = 0; Waypoint* newWaypoint() { static Waypoint** ref_last = &all_waypoints; Waypoint* n = new Waypoint(); (*ref_last) = n; ref_last = &n->next; return n; } int main(int argc, char* argv) { FILE *f = stdin; getLine(f); printf("%s\n", buffer); getLine(f); printf("%s\n", buffer); getLine(f); while (strncmp(buffer, "coord, buffer+5); getLine(f); strcpy(n->ele, buffer); getLine(f); strcpy(n->time, buffer); getLine(f); getLine(f); getLine(f); getLine(f); getLine(f); } if (strcmp(buffer, "") != 0) return 0; getLine(f); getLine(f); getLine(f); getLine(f); Waypoint* next_waypoint = all_waypoints; bool in_trk = false; while (strncmp(buffer, "time) > 0) { if (in_trk) printf("0.00\n\n\n\n", next_waypoint->coord, next_waypoint->ele, next_waypoint->time); in_trk = false; } if (!in_trk) { printf("\n%8.8s-%8.8s\nColor:004000ff\n\n", next_waypoint->time+17, next_waypoint->next == 0 ? "" : next_waypoint->next->time+17); printf("0.00\n\n", next_waypoint->coord, next_waypoint->ele, next_waypoint->time); in_trk = true; next_waypoint = next_waypoint->next; } printf("%s\n%s\%s\n0.00\n\n", coord, ele, time); getLine(f); } if (in_trk) { if (next_waypoint) printf("0.00\n\n", next_waypoint->coord, next_waypoint->ele, next_waypoint->time); printf("\n\n"); } printf("\n"); return 0; }