+void a_gpx_write_file( VikTrwLayer *vtl, FILE *f )
+{
+ a_gpx_write_file_options(NULL, vtl, f);
+}
+
+void a_gpx_write_file_options ( GpxWritingOptions *options, VikTrwLayer *vtl, FILE *f )
+{
+ GpxWritingContext context = { options, f };
+ int i;
+
+ gpx_write_header ( f );
+
+
+ gpx_gather_waypoints_passalong_t passalong;
+ passalong.n_wps = g_hash_table_size ( vik_trw_layer_get_waypoints ( vtl ) );
+ passalong.i = 0;
+ passalong.wps = g_new(gpx_waypoint_and_name,passalong.n_wps);
+ g_hash_table_foreach ( vik_trw_layer_get_waypoints ( vtl ), (GHFunc) gpx_collect_waypoint, &passalong );
+ /* gather waypoints in a list, then sort */
+ qsort(passalong.wps, passalong.n_wps, sizeof(gpx_waypoint_and_name), gpx_waypoint_and_name_compar);
+ for ( i = 0; i < passalong.n_wps; i++ )
+ gpx_write_waypoint ( passalong.wps[i].name, passalong.wps[i].wp, &context);
+ g_free ( passalong.wps );
+
+ g_hash_table_foreach ( vik_trw_layer_get_tracks ( vtl ), (GHFunc) gpx_write_track, &context );
+
+ gpx_write_footer ( f );
+}
+
+void a_gpx_write_track_file ( const gchar *name, VikTrack *t, FILE *f )
+{
+ a_gpx_write_track_file_options ( NULL, name, t, f );
+}
+
+void a_gpx_write_track_file_options ( GpxWritingOptions *options, const gchar *name, VikTrack *t, FILE *f )
+{
+ GpxWritingContext context = {options, f};
+ gpx_write_header ( f );
+ gpx_write_track ( name, t, &context );
+ gpx_write_footer ( f );