/* cl /AL filter.c filter track 1 /c 100 filters 'track.raw' and makes 'tracka.raw' with no vector longer than 100 points. */ #include #include #include #define NUM_TYPE 5 #define DEG_RAD 0.01745329251 /* converts degrees to radians */ #define MAX_VAL 10000 #define MAX_DIST 10000.00 FILE *Fpin,*Fpout,*FpPrn; double huge Lat[MAX_VAL],huge Lon[MAX_VAL]; struct filetype { char *id; double scale; }F[NUM_TYPE]= { {"0",100.0}, {"A",10.0}, {"B",1.0}, {"C",0.1}, {"D",0.01} }; int Type=0; int CutLong=0; main(argc,argv) int argc; char *argv[]; { int i,j,k,n,il,m; char string1[100],string2[100],filename[40],file[40],string0[100]; int num,segs=0,len,numread,print=0,end_of_file=0; double dist,mindist,coslat,sum=0.0,used=0.0; for(i=1;i=NUM_TYPE) exit(0); strcpy(filename,file); filename[7]='\0'; strcat(filename,F[num].id); strcat(filename,".raw"); Fpout=fopen(filename,"wt"); if(!Fpout) { printf("Could not open '%s'/n",filename); if(print==1) fprintf(FpPrn,"Could not open '%s'/n",filename); } else { printf("Opened '%s'\n",filename); if(print==1) fprintf(FpPrn,"Opened '%s'\n",filename); } mindist=F[num].scale/111.0; mindist*=mindist; while(fscanf(Fpin,"%s",string0)==1) { sscanf(string0,"%d",&n); segs+=1; i=0; if(string0[strlen(string0)-1]!='/') { do { numread=fscanf(Fpin,"%s%s",string1,string2); if(numread<2) { end_of_file=1; printf("Hit unexpected end of file!\n"); if(print==1) fprintf(FpPrn,"Hit unexpected end of file!\n"); } len=strlen(string2); if(len>100) { printf("String too long.\n"); if(print==1) fprintf(FpPrn,"String too long.\n"); exit(0); } if(i>=MAX_VAL) { printf("Too many entries in segment %d\n",segs); printf("1st Lat = %lf Lon = %lf\n",Lat[0],Lon[0]); if(print==1) { printf("Too many entries in segment %d\n",segs); printf("1st Lat = %lf Lon = %lf\n",Lat[0],Lon[0]); } exit(0); } sscanf(string1,"%lf",Lat+i); sscanf(string2,"%lf",Lon+i); i+=1; }while(string2[strlen(string2)-1]!='/'&&end_of_file==0); num=i; sum+=num; printf("Segment %3d (attrib %3d) contains %3d elements. ",segs,n,num); fprintf(Fpout,"%5d\n%10.6lf %11.6lf",n,Lat[0],Lon[0]); j=1; il=0; coslat=cos(Lat[0]*DEG_RAD); coslat*=coslat; m=1; for(i=1;imindist&&dist0&&(num-i)>25&&m%CutLong==0) { printf("cutting at %d entries\n",j); fprintf(Fpout,"//\n%5d\n%10.6lf %11.6lf",n,Lat[i],Lon[i]); m=1; } } } if(m%3==0) fprintf(Fpout,"\n"); else fprintf(Fpout," "); fprintf(Fpout,"%10.6lf %11.6lf//\n",Lat[num-1],Lon[num-1]); printf("%3d after filter.\n",j+1); used+=j+1; } } if(string2[strlen(string2)-1]!='/') fprintf(Fpout,"//\n\n"); else fprintf(Fpout,"\n\n"); printf("%d segments: ",segs); printf("Filtered file is %0.2lf percent of original.\n",used/sum*100.0); if(print==1) { fprintf(FpPrn,"%s",filename); fprintf(FpPrn,"%d segments: ",segs); fprintf(FpPrn,"Filtered file is %0.2lf percent of original.\n", used/sum*100.0); } fclose(FpPrn); fclose(Fpout); fclose(Fpin); }