Advertisement
zorbon90

seznamPamatek.c

Dec 30th, 2012
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.24 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6.  
  7. #include "pamatka.h"
  8. //#define SOUBOR "DataImport_Zamky.txt"
  9. #define R 6372.795
  10. #define PI 3.14159265
  11.  
  12. tPamatka *prvni=NULL, *akt=NULL;
  13.  
  14. void vlozNaPosl(tPamatka *novaPamatka)
  15. {
  16.     if (prvni == NULL)
  17.     {
  18.         *prvni = *novaPamatka;
  19.     } else {
  20.         akt->dalsi = novaPamatka;
  21.     }
  22.     akt = novaPamatka;
  23. }
  24.  
  25. tGPS ulozGPS(double latit, double longit)
  26. {
  27.     char *mesto;
  28.     tGPS *souradnice;
  29.     souradnice = (tGPS *) malloc (2 *sizeof(tGPS));
  30.  
  31.     souradnice->latit = latit;
  32.     souradnice->longit = longit;
  33.  
  34.     //return souradnice->latit;
  35. }
  36.  
  37. void nactiData(char *nazev) // *nazev (jmeno / cesta k souboru) - - použije VytvorPamatku a VlozNaPosl
  38. {
  39.     int i = 0;
  40.     int zn = 0;
  41.     FILE *soubor;
  42.     char *nazevSouboru = nazev;
  43.     tGPS *souradnice = (tGPS *) malloc(sizeof(tGPS));
  44.  
  45.     char *radek = (char *) malloc(80 * sizeof(char));
  46.     char *mesto = (char *) malloc(20 * sizeof(char));
  47.  
  48.     char charStupneN[3];
  49.     char charMinutyN[8];
  50.     char charStupneE[3];
  51.     char charMinutyE[8];
  52.  
  53.     double stupneN;
  54.     double minutyN;
  55.     double stupneE;
  56.     double minutyE;
  57.  
  58.     double latitGPS;
  59.     double longitGPS;
  60.  
  61.     int poziceNazvu = 69;
  62.     int poziceLatS = 20;
  63.     int poziceLatM = 23;
  64.     int poziceLongS = 33;
  65.     int poziceLongM = 36;
  66.  
  67.    
  68.     char *pomMesto;
  69.     char hranice[] = "^";
  70.  
  71.     soubor = fopen(nazevSouboru, "r");
  72.    
  73.  
  74.     //while (fgets(radek, sizeof(radek), soubor) != NULL)
  75.     //{
  76.  
  77.     //  while(EOF)
  78.     //  {
  79.     //       printf("EOF");
  80.     //  }
  81.  
  82.     for (i = 0; i < strlen(radek); i++)
  83.     {
  84.         *(radek+i) = fgetc(soubor);
  85.         //printf("%c", *(radek+i));         //kontrola pro vypisování
  86.     }//printf("\n");
  87.  
  88.     for (i = poziceNazvu; i < strlen(mesto) + poziceNazvu; i++)
  89.     {
  90.         *(mesto+zn) = *(radek+i);
  91.         //printf("%c", *(mesto+zn));        //kontrola pro vypisování
  92.         zn++;
  93.     }//printf("\n");
  94.  
  95.     strncpy(charStupneN, radek + poziceLatS, 2);
  96.     strncpy(charMinutyN, radek + poziceLatM, 7);
  97.     strncpy(charStupneE, radek + poziceLongS, 2);
  98.     strncpy(charMinutyE, radek + poziceLongM, 7);
  99.     charStupneN[2] = '\0';
  100.     charMinutyN[7] = '\0';
  101.     charStupneE[2] = '\0';
  102.     charMinutyE[7] = '\0';
  103.     printf("%s\n", charStupneN);
  104.     printf("%s\n", charMinutyN);
  105.     printf("%s\n", charStupneE);
  106.     printf("%s\n", charMinutyE);
  107.  
  108.     stupneN = atof(charStupneN);
  109.     minutyN = ( (atof(charMinutyN)) / 60 );
  110.     stupneE = atof(charStupneE);
  111.     minutyE =  ( (atof(charMinutyE)) / 60 );
  112.     printf("%.4f \n", stupneN);
  113.     printf("%.4f \n", minutyN);
  114.     printf("%.4f \n", stupneE);
  115.     printf("%.4f \n", minutyE);
  116.  
  117.  
  118.     latitGPS = stupneN + minutyN;
  119.     longitGPS = stupneE + minutyE;
  120.  
  121.     printf("%.4f \n", latitGPS);
  122.     printf("%.4f \n", longitGPS);
  123.  
  124.    
  125.  
  126.     pomMesto = NULL;
  127.     pomMesto = strtok( mesto, hranice );
  128.     while( pomMesto != NULL ) {
  129.         //printf( "result is \"%s\"\n", pomMesto );         //kontrola pro vypisování
  130.         pomMesto = strtok( NULL, hranice );
  131.     }
  132.  
  133.     for (i = strlen(mesto)-1; i > 0; i--)
  134.     {
  135.         if (mesto[i] == ' ')
  136.         {
  137.             mesto[i] = '\0';
  138.             if (mesto[i-1] != ' ')
  139.             {
  140.                 break;
  141.             }
  142.         }
  143.     }
  144.  
  145.     *souradnice = ulozGPS(latitGPS, longitGPS);
  146.     printf("N %.4f   E %.4f", souradnice->latit, souradnice->longit);
  147.  
  148.     //VytvorPamatku(mesto, souradnice);
  149.     //vlozNaPosl(VytvorPamatku(mesto, ulozGPS(latitGPS, longitGPS)));
  150.  
  151.     //}
  152.  
  153.     //printf("Mesto: %s :   souradnice: N%d E%d", mesto, latitGPS, longitGPS);
  154.     //printf("%d", pocMezer);
  155.     //printf("\n");
  156.    
  157.     fclose(soubor);
  158. }
  159.  
  160. void vypis() //využije VypisPamatku()
  161. {
  162.     if(prvni==NULL){
  163.       printf("Seznam je prazdny!\n");
  164.     }
  165.     else{
  166.         akt=prvni;
  167.         while(akt)
  168.         {
  169.              // UPRAVIT     printf("%d. pamatka: %s\zemepisna sirka - %lf\nzemepisna delka - %lf\n\n", akt->pamatka, akt->gps.latit, akt->gps.longit);
  170.              VypisPamatku(akt);
  171.              akt=akt->dalsi;
  172.         }
  173.     }
  174. }
  175.  
  176. void najdiDleNazvu()
  177. {
  178.  
  179. }
  180.  
  181. int zjistiVzdalenost(tGPS gpsPamatka1, tGPS gpsPamatka2)
  182. {
  183.     int vzdalenost;
  184.     vzdalenost = acos(sin(gpsPamatka1.latit*PI/180)*sin(gpsPamatka2.latit*PI/180)
  185.                     + (cos(gpsPamatka1.latit*PI/180)*cos(gpsPamatka2.latit*PI/180)
  186.                     * cos((gpsPamatka2.longit-gpsPamatka1.longit)*PI/180))) * R;
  187.     return vzdalenost;
  188. }
  189.  
  190. tPamatka najdiNejblizsi(tGPS gpsPamatky)
  191. {
  192.  
  193.     return;
  194. }
  195.  
  196. tPamatka najdiTriNejblizsi(tGPS gpsPamatky)
  197. {
  198.     return;
  199. }
  200.  
  201. void zrusData()
  202. {
  203.  
  204. }
  205.  
  206. void main()
  207. {
  208.     nactiData("DataImport_Zamky.txt");
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement