\( \def\bold#1{\bf #1} \newcommand{\d}{\mathrm{d}} \) BTP: Manual and Source Code Documentation

Power Uphill

bike mass [kg]
body mass [kg]
altitude gain [m]
climb length [km]
gradient [%]
time [s]
speed [km/h]
power [W]
power/mass [W/kg]
climbrate [m/min]

average power on climb stage

BTP  3.0
Routing/ClimbAnalysis/PowerCalculation
gpx.cpp
1 #include "gpx.h"
2 
3 
4 gpx::gpx(char* filename){
5  file = filename;
6  l = NULL;
7  if(file != NULL){
8  read_in();
9  calc_distance();
10  }
11 }
12 gpx::~gpx(){
13 }
14 void gpx::add_point(double lon, double lat, double h, long int time){
15  gpxlist* g;
16  if(l != NULL){
17  (*l)->prev->next = new gpxlist;
18  g = (*l)->prev->next;
19  }
20  else{
21  l = new gpxlist*;
22  *l = new gpxlist;
23  g = *l;
24  (*l)->prev = g;
25  }
26  g->prev = (*l)->prev;
27  (*l)->prev = g;
28  g->next = NULL;
29  g->d = 0;
30  g->lat = lat;
31  g->lon = lon;
32  g->h = h;
33  g->time = time;
34 }
35 void gpx::read_in(){
36  FILE* f = fopen(file,"r");
37  if(f != NULL){
38  /*Datei existiert*/
39  char line[10000],*readstart,*newstart;
40  double lon = 0, lat = 0, h = 0;
41  long int time;
42  int read_out;
43  while(!feof(f)){
44  /*Zeilenweise einlesen*/
45  fgets(line,10000,f);
46  replace_quotation(line);
47  read_out = 0;
48  readstart = line;
49  while(!read_out){
50  newstart = strstr(readstart,"</trkpt>");
51  if (newstart != NULL){
52  newstart[0] = '\0';
53  newstart = &newstart[1];
54  }
55  else{
56  read_out = 1;
57  }
58  extract_attribute("lat",readstart,&lat);
59  extract_attribute("lon",readstart,&lon);
60  extract_element("ele",readstart,&h);
61  extract_time(readstart,&time);
62 
63  if(!read_out){
64  add_point(lon,lat,h,time);
65  readstart = newstart;
66  }
67  }
68  }
69  }
70 }
71 void gpx::replace_quotation(char* a){
72  int i = 0;
73  while(a[i] != '\0'){
74  if(a[i] == '\"')
75  a[i] = '\'';
76  i++;
77  }
78 }
79 void gpx::extract_attribute(const char* attr, char* src, double* result){
80  char *x1;
81  char *x2;
82  x1 = strstr(src, attr);
83  if(x1 != NULL){
84  x1 = &x1[strlen(attr)+2*sizeof(char)];
85  x2 = strchr(x1,'\'');
86  x2[0] = '\0';
87  *result = atof(x1);
88  x2[0] = '\'';
89  }
90 }
91 void gpx::extract_element(const char* elem, char* src, double* result){
92  char *x1;
93  char *x2;
94  char pattern[100];
95  strcpy(&pattern[2],elem);
96  pattern[1]='<';
97  pattern[2+strlen(elem)] = '>';
98  pattern[3+strlen(elem)] = '\0';
99  x1 = strstr(src,&pattern[1]);
100  if(x1 != NULL){
101  x1 = &x1[strlen(pattern)-1];
102  pattern[1] = '/';
103  pattern[0] = '<';
104  x2 = strstr(src,pattern);
105  x2[0] = '\0';
106  *result = atof(x1);
107  x2[0] = '<';
108  }
109 }
110 void gpx::extract_time(char* src, long int* unix_time){
111  char *x1,*x2;
112  char pattern[] = "</time>";
113  pattern[1]='<';
114  x1 = strstr(src,&pattern[1]);
115  if(x1 != NULL){
116  x1 = &x1[strlen(pattern)-1];
117  pattern[1] = '/';
118  x2 = strstr(src,pattern);
119  x2[0] = '\0';
120  int totaldays,year,month,day,hour,minute,second;
121  char *x3 = strstr(x1,"T");
122  if(x3 != NULL){
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';
129 
130  int is_leap_year = 0;
131  if( year % 4 == 0
132  && (((year-1901) % 100 != 0) || ((year-1901) % 400 == 0)))
133  is_leap_year = 1;
134 
135  /*Tage seit 1970 inkl. Schalt- und Saekularisierungsjahr*/
136  totaldays = (year-1970)*365; //normale Tagesanzahl
137  totaldays = totaldays + (year-1969) / 4; //Schaltjahr normal
138  totaldays = totaldays - (year-1901) / 100; //Seakularisierung 1
139  totaldays = totaldays + (year-1601) / 400; //Seakularisierung 2
140 
141  /*Aufschlüsselung der Monatstage*/
142  switch(month){
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;
154  }
155 
156  *unix_time = 24*60*60 * (totaldays + (day -1))
157  + 60*60 * hour
158  + 60 * minute
159  + second;
160  }
161  x2[0] = '<';
162  }
163 }
164 void* gpx::get_complete_List(){
165  return l;
166 }
167 void gpx::calc_distance(){
168  if(l != NULL){
169  (*l)->d = 0;
170  gpxlist *g = (*l)->next;
171  while(g != NULL){
172  g->d = g->prev->d
173  + distance(g->lat,g->lon,g->prev->lat,g->prev->lon);
174  g = g->next;
175  }
176  }
177 }
178 double gpx::distance(double lat1, double lon1, double lat2, double lon2){
179  if (lat1 == lat2 && lon1 == lon2) return 0;
180  else{
181  return
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;
185  }
186 }
187 double** gpx::get_complete(long int* n){
188  *n = 0;
189  double** result;
190  if(l != NULL){
191  gpxlist *g = *l;
192  while(g != NULL){
193  (*n)++;
194  g = g->next;
195  }
196 
197  g = *l;
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++){
202  result[0][i] = g->d;
203  result[1][i] = g->h;
204  result[2][i] = g->lat;
205  result[3][i] = g->lon;
206  result[4][i] = g->time;
207  g = g->next;
208  }
209  }
210  else
211  result = NULL;
212 
213  return result;
214 }
215 
216 
Definition: gpx.h:6