4 gpx::gpx(
char* filename){
14 void gpx::add_point(
double lon,
double lat,
double h,
long int time){
36 FILE* f = fopen(file,
"r");
39 char line[10000],*readstart,*newstart;
40 double lon = 0, lat = 0, h = 0;
46 replace_quotation(line);
50 newstart = strstr(readstart,
"</trkpt>");
51 if (newstart != NULL){
53 newstart = &newstart[1];
58 extract_attribute(
"lat",readstart,&lat);
59 extract_attribute(
"lon",readstart,&lon);
60 extract_element(
"ele",readstart,&h);
61 extract_time(readstart,&time);
64 add_point(lon,lat,h,time);
71 void gpx::replace_quotation(
char* a){
79 void gpx::extract_attribute(
const char* attr,
char* src,
double* result){
82 x1 = strstr(src, attr);
84 x1 = &x1[strlen(attr)+2*
sizeof(char)];
91 void gpx::extract_element(
const char* elem,
char* src,
double* result){
95 strcpy(&pattern[2],elem);
97 pattern[2+strlen(elem)] =
'>';
98 pattern[3+strlen(elem)] =
'\0';
99 x1 = strstr(src,&pattern[1]);
101 x1 = &x1[strlen(pattern)-1];
104 x2 = strstr(src,pattern);
110 void gpx::extract_time(
char* src,
long int* unix_time){
112 char pattern[] =
"</time>";
114 x1 = strstr(src,&pattern[1]);
116 x1 = &x1[strlen(pattern)-1];
118 x2 = strstr(src,pattern);
120 int totaldays,year,month,day,hour,minute,second;
121 char *x3 = strstr(x1,
"T");
123 x1 = x1; x1[4]=
'\0'; year = atoi(x1); x1[4]=
'-';
124 x1 = &x1[5]; x1[2]=
'\0'; month = atoi(x1); x1[2]=
'-';
125 x1 = &x1[3]; x1[2]=
'\0'; day = atoi(x1); x1[2]=
'T';
126 x1 = &x3[1]; x1[2]=
'\0'; hour = atoi(x1); x1[2]=
':';
127 x1 = &x1[3]; x1[2]=
'\0'; minute = atoi(x1); x1[2]=
':';
128 x1 = &x1[3]; x1[2]=
'\0'; second = atoi(x1); x1[2]=
'Z';
130 int is_leap_year = 0;
132 && (((year-1901) % 100 != 0) || ((year-1901) % 400 == 0)))
136 totaldays = (year-1970)*365;
137 totaldays = totaldays + (year-1969) / 4;
138 totaldays = totaldays - (year-1901) / 100;
139 totaldays = totaldays + (year-1601) / 400;
143 case 12: totaldays = totaldays + 30;
144 case 11: totaldays = totaldays + 31;
145 case 10: totaldays = totaldays + 30;
146 case 9: totaldays = totaldays + 31;
147 case 8: totaldays = totaldays + 31;
148 case 7: totaldays = totaldays + 30;
149 case 6: totaldays = totaldays + 31;
150 case 5: totaldays = totaldays + 30;
151 case 4: totaldays = totaldays + 31;
152 case 3: totaldays = totaldays + 28 + is_leap_year;
153 case 2: totaldays = totaldays + 31;
156 *unix_time = 24*60*60 * (totaldays + (day -1))
164 void* gpx::get_complete_List(){
167 void gpx::calc_distance(){
173 + distance(g->lat,g->lon,g->prev->lat,g->prev->lon);
178 double gpx::distance(
double lat1,
double lon1,
double lat2,
double lon2){
179 if (lat1 == lat2 && lon1 == lon2)
return 0;
182 acos(cos(lat2/180*M_PI)*cos(lat1/180*M_PI)*
183 (cos(lon2/180*M_PI-(lon1)/180*M_PI))+sin(lat2/180*M_PI)
184 *sin((lat1)/180*M_PI))*R0;
187 double** gpx::get_complete(
long int* n){
198 result =
new double*[5];
199 for(
int i = 0; i < 5; i++)
200 result[i] =
new double[*n];
201 for(
int i = 0; i < *n; i++){
204 result[2][i] = g->lat;
205 result[3][i] = g->lon;
206 result[4][i] = g->time;