]> www.wagner.pp.ru Git - oss/fgis.git/blob - epu/centers.c
First checked in version
[oss/fgis.git] / epu / centers.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include "epp.h"
5 #include "eppl_ut.h"
6 #include <getopt.h>
7 void help(int exitcode) {
8    printf("Usage centers [-%%] cluster_file radius_file\n");
9    printf("Table of coordinates and cluster values is written to stdout\n");
10    exit (exitcode);
11 }   
12 struct center {
13           int row,col;
14           int radius;
15        };
16 struct center *table;
17    EPP *cluster_file,*radius_file;
18 int check_max_r (int col,int row, int value) {
19   int r=epp_get(radius_file,col,row);
20   struct center *rec = table+value;
21   if (rec->radius<r) {
22     rec->radius=r;
23     rec->row=row;
24     rec->col=col;
25   }  
26   return 0;
27 }
28 int main(int argc,char **argv) {
29     struct option long_options[]={
30     {"help",0,0,1},
31     {"version",0,0,2},
32     {"verbose",0,0,'%'},
33    }; 
34    int c,index,result,i;
35    int verbose=0;
36    while ((c=getopt_long(argc,argv,"%",long_options,&index))!=-1) {
37       switch(c) {
38          case 2:show_version("centers","$Revision: 1.1 $");
39          case '%':verbose=1;break;
40          case 1:
41          default: help(c==1?0:1);
42       }
43    }   
44    cluster_file = open_epp(default_ext(argv[optind],".epp"));
45    if (!cluster_file) {
46       fprintf(stderr,"Cannot open file %s\n",
47        default_ext(argv[optind],".epp"));
48       exit (2);
49     }
50     optind++;
51     radius_file = open_epp(default_ext(argv[optind],".epp"));
52     if (!radius_file) {
53       fprintf(stderr,"Cannot open file %s\n",
54        default_ext(argv[optind],".epp"));
55       exit (2);
56     }
57     if (!is_aligned(cluster_file,radius_file)) {
58        fprintf(stderr,"Files don't have same coordinate system and cell size\n");
59        exit(2);
60     }   
61     table=calloc((cluster_file->max+1),sizeof(struct center));
62     if (!table) {
63       perror("allocating table");
64       exit(2);
65     }
66     install_progress_indicator(verbose?show_percent:check_int);
67     result=clear_progress(for_each_cell(cluster_file,check_max_r));
68    if (result) {
69       return abs(result);
70    }   
71    for (i=0;i<=cluster_file->max;i++) {
72      if (table[i].radius) {
73        printf ("%5d,%12g,%12g\n",i,alt_x(cluster_file,table[i].col),
74          alt_yc(cluster_file,table[i].row));
75      }
76    }
77    return 0;
78 }