Révision 23
Ajouté par nipelloux il y a environ 4 ans
branch/pelloux/sp4a12/main.c | ||
---|---|---|
int decode_nbr(char *ch,int n){
|
||
int res=0;
|
||
int i;
|
||
for(i=0;i<n;i++){
|
||
for(i=n-1;i>=0;i++){
|
||
res += (decode_int(ch[i]))*pow(10,n-1-i);
|
||
}
|
||
return res;
|
||
}
|
||
|
||
//float conv_latitude(char * latitude){
|
||
// int i=0
|
||
// float v=0;
|
||
//while(latitude[i]!=''){
|
||
// v+=decode_int()
|
||
// }
|
||
float conv_latitude(char * ch){
|
||
float res=0;
|
||
int i;
|
||
float val_sexa=decode_nbr(ch,4);
|
||
|
||
//}
|
||
for(i=5;i<0;i++){
|
||
val_sexa+=(decode_int(ch[i]))*pow(10,-i+4);
|
||
|
||
}
|
||
res=(int)(val_sexa/100);
|
||
res=res+(val_sexa-res*100)/60;
|
||
|
||
}
|
||
|
||
float conv_longitude(char * ch){
|
||
float res=0;
|
||
int i;
|
||
float val_sexa=decode_nbr(ch,5);
|
||
|
||
for(i=6;i<10;i++){
|
||
val_sexa+=(decode_int(ch[i]))*pow(10,-i+5);
|
||
|
||
}
|
||
res=(int)(val_sexa/100);
|
||
res=res+(val_sexa-res*100)/60;
|
||
|
||
}
|
||
|
||
float conversion(char * ch){
|
||
int i=0;
|
||
float res=0;
|
||
while (ch[i] != '\0'){
|
||
i++;
|
||
}
|
||
if (i==9){
|
||
res=conv_latitude(ch);
|
||
}
|
||
else if (i==10){
|
||
res=conv_longitude(ch);
|
||
}
|
||
else{res=1000.0;}
|
||
return res;
|
||
}
|
||
|
||
//Fonction ? modifier !!!!!
|
||
void traitement(char * trame)
|
||
{
|
||
... | ... | |
}
|
||
if (decode_nbr("123",3)!=123){
|
||
printf ("Erreur Test unitaire decode_nbr.\n");
|
||
printf ("%d",decode_nbr("123",3));
|
||
exit(-1);
|
||
}
|
||
// if (conv_latitude("987654321",2)!=98){
|
||
// printf ("Erreur Test unitaire decode_nbr.\n");
|
||
// exit(-1);
|
||
// }
|
||
if (fabs(conv_latitude("3723.2475")-37.387458)>=pow(10,-6)){
|
||
printf ("Erreur Test unitaire conv_latitude.\n");
|
||
exit(-1);
|
||
}
|
||
if (fabs(conv_longitude("00306.6036")-3.11006)>=pow(10,-6)){
|
||
printf ("Erreur Test unitaire conv_longitude.\n");
|
||
exit(-1);
|
||
}
|
||
if (fabs(conversion("3723.2475")-37.387458)>=pow(10,-6)){
|
||
printf ("Erreur Test unitaire conversion.\n");
|
||
exit(-1);
|
||
}
|
||
if (fabs(conversion("00306.6036")-3.11006)>=pow(10,-6)){
|
||
printf ("Erreur Test unitaire conversion.\n");
|
||
exit(-1);
|
||
}
|
||
|
||
}
|
||
|
||
// Ne pas modifier cette fonction
|
||
int main(int argc,char ** argv)
|
||
{
|
||
|
||
//tests_unitaires();
|
||
tests_unitaires();
|
||
|
||
// Affichage des trames definies dans la table trames.
|
||
printf ("Trames de tests tableau trames:\n");
|
Formats disponibles : Unified diff
Fonction conversion latitude longitude et fonction conversion