home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / WORLD10.ZIP / WORLD.C next >
Encoding:
C/C++ Source or Header  |  1988-04-11  |  1.3 KB  |  52 lines

  1. /*    world - reformat world.dat data for GRAPH   */
  2.  
  3. #include <stdio.h>
  4.  
  5. typedef struct
  6.     {char    code[2];    /* "LS" for first point in each curve, "S " otherwise */
  7.     int        longi;
  8.     int        lati;
  9.     }    LLREC;
  10.  
  11. LLREC ll, saved;
  12.  
  13. FILE *ifile;
  14. int n=1, count=0;
  15.  
  16. main(argc, argv) int argc; char **argv;
  17. {    int prev;
  18.     if(argc>1 && *argv[1]=='?')
  19.         {puts("world - read WORLD.DAT and generate GRAPH input file\n");
  20.         puts("usage:  world [n] >outfile\n");
  21.         puts("approximately every nth point will be included \
  22. (default: all 7574 points)\n");
  23.         exit();
  24.         }
  25.     if(argc>1 && isdigit(*argv[1])) n=atoi(argv[1]);
  26.     ifile=fopen("world.dat", "r");
  27.     if(!ifile) {fprintf(stderr, "cannot open world.dat"); exit(1);}
  28.     if(n>1)
  29.         printf("; world map, including approximately 1/%d of WORLD.DAT  ", n);
  30.     else
  31.         printf("; world map, including all of WORLD.DAT  ", n);
  32.     while(fread(&ll, sizeof(ll), 1, ifile))
  33.         {count++;
  34.         if(ll.code[0]=='L' || abs(ll.longi-prev)>15000) 
  35.             {if(count!=1)    /* display last point in previous segment */
  36.                 printf("\n%7.2f %7.2f", saved.longi*.01, saved.lati*.01);
  37.             puts(" \"\"\n");
  38.             }
  39.         else if(count<n) 
  40.             {saved=ll;
  41.             continue;    /* display every nth point */
  42.             }
  43.         else puts("\n");
  44.         count=0;
  45.         prev=ll.longi;
  46.         printf("%7.2f %7.2f", ll.longi*.01, ll.lati*.01);
  47.         }
  48.     puts(" \"\"\n");
  49. }
  50.  
  51.     
  52.