5 typedef struct Contour {int Class,XMin,YMin,XMax,YMax,Count;} CONTOUR;
6 /* ÏÐÉÓÁÎÉÅ ÏÄÎÏÇÏ ËÏÎÔÕÒÁ */
10 int first_class; /* ÄÌÑ ÐÅÒÅÓÞÅÔÁ */
12 int sort_area(const void *p1, const void *p2)
13 /* óÒÁ×ÎÅÎÉÅ ÐÏ ÐÌÏÝÁÄÉ */
16 t1=(((CONTOUR *)p1))->Count;
17 t2=(((CONTOUR *)p2))->Count;
23 int sort_y_top(const void *p1, const void *p2)
24 /* óÒÁ×ÎÅÎÉÅ ÐÏ ×ÅÒÈÎÅÊ ÇÒÁÎÉÃÅ */
27 t1=((CONTOUR *)p1)->YMin;
28 t2=((CONTOUR *)p2)->YMin;
34 int sort_y_bottom(const void *p1, const void *p2)
37 t1=((CONTOUR *)p1)->YMax;
38 t2=((CONTOUR *)p2)->YMax;
43 int sort_x_right(const void *p1, const void *p2)
46 t1=((CONTOUR *)p1)->XMax;
47 t2=((CONTOUR *)p2)->XMax;
52 int sort_x_left(const void *p1, const void *p2)
55 t1=((CONTOUR *)p1)->XMin;
56 t2=((CONTOUR *)p2)->XMin;
62 int sort_x(const void *p1, const void *p2)
63 /* óÒÁ×ÎÅÎÉÅ ÐÏ ÓÒÅÄÎÅÍÕ X */
66 t1=((CONTOUR *)p1)->XMin+((CONTOUR *)p1)->XMax;
67 t2=((CONTOUR *)p2)->XMin+((CONTOUR *)p2)->XMax;
73 int sort_y(const void *p1, const void *p2)
74 /* óÒÁ×ÎÅÎÉÅ ÐÏ ÓÒÅÄÎÅÍÕ Y */
77 t1=((CONTOUR *)p1)->YMin+((CONTOUR *)p1)->YMax;
78 t2=((CONTOUR *)p2)->YMin+((CONTOUR *)p2)->YMax;
84 /*int sort_s(const void *p1, const void *p2)*/
85 /* óÒÁ×ÎÅÎÉÅ ÐÏ ÏÔÎÏÛÅÎÉÀ count/(W*H) */
91 int process_cell(int col,int row, int value)
94 if (b->XMin>col) b->XMin=col;
95 if (b->XMax<col) b->XMax=col;
96 if (b->YMin>row) b->YMin=row;
97 if (b->YMax<row) b->YMax=row;
102 int main(int argc,char **argv)
104 int (*sort_function)(const void *,const void *)=NULL;
105 /*òÁÚÂÏÒ ÐÁÒÁÍÅÔÒÏ× ËÏÍÁÎÄÎÏÊ ÓÔÒÏËÉ*/
106 struct option longoptions[]={
110 {"alt-coords",0,0,'a'},
111 {"sort-left",0,0,'l'},
112 {"sort-right",0,0,'r'},
113 {"sort-top",0,0,'t'},
114 {"sort-bottom",0,0,'b'},
115 {"sort-area",0,0,'A'},
116 {"sort-x-center",0,0,'x'},
117 {"sort-y-center",0,0,'y'},
118 {"output-file",1,0,'o'},
128 while((c=getopt_long(argc,argv,"alrtbxyA%ho:",longoptions,&index))!=-1)
130 { case 2:show_version("extents","$Revision: 1.1 $");
131 case '%': verbose=1; break;
132 case 'a': use_alt=1;break;
133 case 'o': if (!(f=fopen(optarg,"w")))
134 {fprintf(stderr,"Cannot open file %s\n",optarg); return 2;}
136 case 'l':sort_function=sort_x_left; break;
137 case 'r':sort_function=sort_x_right; break;
138 case 't':sort_function=sort_y_top; break;
139 case 'b':sort_function=sort_y_bottom; break;
140 case 'x':sort_function=sort_x; break;
141 case 'y':sort_function=sort_y; break;
142 case 'A':sort_function=sort_area; break;
143 case 'h':print_header=1;break;
146 default: printf("Usage: extents [-%%alrtbxtA] [-o file] file.epp\n");
151 /*ïÔËÒÙÔØ epp-ÛÎÉË, ÐÒÏÞÉÔÁÔØ ÚÁÇÏÌÏ×ÏË, ÓÏÚÄÁÔØ ÍÁÓÓÉ× CONTOUR ÄÌÉÎÙ
153 epp=open_epp(default_ext(argv[optind],".epp"));
154 if(epp==NULL) {fprintf(stderr,"Can not open file %s\n",
155 default_ext(argv[optind],".epp"));
157 a=calloc(sizeof(CONTOUR),epp->max+1);
158 for(i=0,b=a;i<=epp->max;i++,b++)
165 install_progress_indicator(verbose?show_percent:check_int);
166 if (clear_progress(for_each_cell(epp,process_cell))) return 3;
167 if (sort_function) qsort(a,epp->max+1,sizeof(CONTOUR),sort_function);
170 " Class X Left X Right Y Top Y Bottom Area\n":
171 " Class Min Col Max Col Min Row Max Row Count\n");
172 for(i=0;i<=epp->max;i++)
175 fprintf(f,"%6d %13g %13g %13g %13g %14g\n",
176 a[i].Class,alt_x(epp,a[i].XMin),alt_x(epp,a[i].XMax+1),
177 alt_y(epp,a[i].YMin),alt_y(epp,a[i].YMax+1),
178 a[i].Count*epp->cell_area);
180 fprintf(f,"%6d %7d %7d %7d %7d %9d\n",
181 a[i].Class,a[i].XMin,a[i].XMax,a[i].YMin,a[i].YMax,a[i].Count);
185 if (f!=stdout) fclose(f);