]> www.wagner.pp.ru Git - oss/fgis.git/blob - epu/reclass1.c
First checked in version
[oss/fgis.git] / epu / reclass1.c
1 #include <stdio.h>
2 #include <getopt.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include "epp.h"
7 #include "eppl_ut.h"
8 #include "reclass.h"
9 #define required_argument 1
10   FILE *input_stream;
11   short int *table;
12   EPP *infile;
13 int reclass_getc()
14 { return fgetc(input_stream);
15 }
16 int get_cell(int col,int row,int value)
17 { return table[epp_get(infile,col,row)];
18 }
19 int main(int argc,char **argv)
20 { char outname[256]="reclass.out.epp"; 
21   char filename[256];      
22  
23   struct option long_options[]={
24   {"help",0,0,1},
25   {"version",0,0,2},
26   {"verbose",0,0,'%'},
27   {"file",required_argument,0,'f'},
28   {"output-file",required_argument,0,'o'},
29   {NULL,0,0,0} };
30   int c;
31   int index,verbose=0;
32   EPP *outfile;  
33   input_stream=stdin;
34    
35   while ((c=getopt_long(argc,argv,"%f:o:",long_options,&index))!=-1)
36   { switch(c)
37     { case 2:/* version */show_version("reclass","$Revision: 1.1 $");
38       case '%':verbose=1;break;
39       case 'o':strcpy(outname,default_ext(optarg,".epp"));
40       case 'f':if((input_stream=fopen(optarg,"r"))==NULL) 
41                {fprintf(stderr,"Cannot open reclass file %s\n",optarg);
42                 return 1;
43                } else break;
44       case 1:/*help*/
45       case '?':
46       default:
47              printf("Usage %s [--help] [--version] [-v] [-f reclass_file]\n"
48                     "[-o output_file] file_to_reclass\n",argv[0]);
49              return c==1?0:2; 
50     }
51   }
52   if (argc==optind)
53     { fprintf(stderr,"No input files specified\n");
54       return 2; 
55     }
56   if (argc>=optind+2)
57     { fprintf(stderr,"Too many input files\n");
58       return 2;
59     }
60       
61   infile=open_epp(default_ext(argv[optind],".epp"));    
62   if (!infile) { fprintf(stderr,"Cannot open input file\n");
63               return 1;
64             }
65   Create16bit=1; 
66   outfile=creat_epp_as(outname,infile);
67   if (!outfile){ fprintf(stderr,"Cannot create output file\n");
68                  return 1;
69                }
70   if (input_stream==stdin&&isatty(0))
71   {
72    printf("Enter reclass statements. Press ^D to end.\n");
73    interactive_parser=1;
74   }
75   /* init reclass table */
76   if (!(table=make_reclass_table(infile,reclass_getc)))
77       { unlink(outname);return 1;}
78   if (table[infile->offsite]!=infile->offsite)
79    outfile->offsite=table[infile->offsite];
80    install_progress_indicator(verbose?show_percent:check_int);
81   for_each_cell(outfile,get_cell);
82  
83   close_epp(infile);
84   if (outfile->max<255){
85     fast_convert_to_8bit(outfile,strcat(strcpy(filename,outname),".8bit"));
86     unlink(outname);
87     rename(filename,outname);
88   }
89   else
90   close_epp(outfile);
91   clear_progress(0);  
92  return 0;
93 }