GPS2CSV.C

/* Turbo C 2.00 */

#include <stdio.h>
#include <stdlib.h>
#include <Dos.h>
#include <Bios.h>
#include <conio.h>
#include <math.h>
#include <time.h>
#include <string.h>

#define TAB 9

typedef enum {FALSE,TRUE} bool;
typedef unsigned char byte;
typedef unsigned int word;

long Taille;
long PtrFile;

FILE *f1;
int ind;
int PAcquis;

word i,j,k,l,m,n;
float Longitude,Latitude,Altitude;
/*float v,w,x,y;*/

char c;
char NomFich[14];
char Convert[32];
char *Buff;
char *BuffPtr;
char *Tampon;

void Delay(int jjj)
{
int i;
while (jjj>0) { for (i=0;i<800;i++); jjj--; }
}

void Couine()
{
int i;
for (i=100;i<1000;i=i+10){sound(i);Delay(5);nosound();}
nosound();
}

void Pause(char ccc)
{
char c1;
if (ccc>32)
{ printf("Appuyer sur <%c> ",ccc); }
else
{
switch (ccc)
{
case 27:
printf("Appuyer sur <ESC> ");
break;
case 13:
printf("Appuyer sur <RETURN>");
break;
default:
printf("Appuyer sur une Touche");
break;
}
}
c1=0;
while((c1!=ccc)&&(c1!=27))
{
if (kbhit()) c1=getch();
if (c1>96) c1=c1-32;
}
}

void main (int argc,char *argv[])
{
clrscr();
textcolor(30);cprintf(" ");
printf("\nGpx2Csv.c 2008 rev 080923 P.F.");
printf("\nMoulinette d'adaptation de fichiers ");
printf("\n Permet d'extraire d'un fichier *.gpx les datas ");
printf("\n Sortie dans un fichier *.txt format‚: Long Alt Lat");
printf("\n ex usage : Gpx2Csv.exe Buet_2j.gpx ==> Buet_2j.txt");
Tampon=(char *)malloc(32767);
Buff=(char *)malloc(32767);
BuffPtr=(char *)malloc(32767);
if ((Tampon==NULL) | (Buff==NULL))
{ printf("\npb d'allocation memoire...");
sleep(2);
exit(2);
}
if(argc>1)
{
strcpy(Tampon,argv[1]);
strupr(Tampon);
printf("\nFichier pass‚ en parametre=");
cprintf(" %s",Tampon);
f1=fopen(Tampon,"rt");
Taille=fseek(f1,-1,SEEK_END);
Taille=ftell(f1);
PtrFile=fseek(f1,0,SEEK_SET);

if (Taille==-1L)
{
printf("\ninexistant");
sleep(2);
exit(1);
}
printf("\ntaille fichier binaire = %6lu octets\n",Taille);
Taille=fread(Buff,sizeof(char),Taille-1,f1);
if (Taille>0)
printf("\nlecture de %6ld octets ",Taille);
else
{
printf("\nPB de lecture fichier d'entree ..");
sleep(2);
exit(0);
}
i=fclose(f1);
sleep(1);
/* Pause('S');*/
}
else
{
Couine();
printf("\npas de parametres pass‚..\n");
sleep(1);
exit(3);
}
/* elimine extension fichier .gpx */
k=strlen(Tampon);
*(Tampon+k-4)=0;
strcat(Tampon,".txt");
printf("\nFichier de sortie = %s ",Tampon);
printf("\navancement:");
f1=fopen(Tampon,"wt");
if (f1==NULL)
{
printf("\nPB creation fichier de sortie ..");
sleep(2);
exit(1);
}
else
printf("\nCreation fichier de sortie .OK\n");
/* fprintf(f1,"N Longitude Altidude Latitude\n");*/
printf("N Longitude Altidude Latitude\n");
i=0;
while (Buff!=NULL)
{

*(Tampon)=0 ;

strcpy(Tampon,"<trkpt lat=");
Buff=strstr(Buff,Tampon);
if (Buff==NULL) break;
*(Tampon)=0;
Buff=Buff+12;
Tampon=Buff;
*(Tampon+9)=0;
Buff=Buff+10;
Longitude=atof(Tampon);

strcpy(Tampon,"lon=");
Buff=strstr(Buff,Tampon);
if (Buff==NULL) break;
*(Tampon)=0;
Buff=Buff+5;
Tampon=Buff;
*(Tampon+8)=0;
Buff=Buff+10;
Latitude=atof(Tampon);

strcpy(Tampon,"<ele>");
Buff=strstr(Buff,Tampon);
if (Buff==NULL) break;
*(Tampon)=0;
Buff=Buff+5;
Tampon=Buff;
*(Tampon+4)=0;
Buff=Buff+10;
Altitude=atof(Tampon);
i++;
printf("%3d%c%2.5f%c%2.5f%c%5.0f\n",i,TAB,Longitude,TAB,Latitude,9,Altitude);
fprintf(f1,"%2.5f%c%2.5f%c%5.0f\n",Longitude,TAB,Latitude,TAB,Altitude);
/* printf("%3d%c%2.5f%c%5.0f%c%2.5f\n",i,TAB,Longitude,TAB,Altitude,TAB,Latitude);*/


Buff=Buff+5;
}
i=fclose(f1);
printf("\nfermeture fichier de sortie : ");
if (i==0) printf(".. OK .."); else printf(" PROBLEME!");
sleep(1);
printf("\nLiberation memoires");
free(Tampon);
free(BuffPtr);
free(Buff);
sleep(1);
printf("\nFin normale de programme..\n\n");
sleep(2);
/* exit code 93 */
}