10 void error(const char * message)
12 fprintf(stderr,"%s\n",message);
15 void swab(const void *from,void *to,size_t size);
16 void dcopy(const void *from,void *to,size_t size)
21 int convert(EPP *epp,FILE *in,void (*copyrow)(const void *,void*,size_t),
24 int bytes=(epp->lc-epp->fc)*2,row,col,i,rows=epp->lr-epp->fr;
25 short int *buf,*buf2,*p;
28 for (row=epp->fr,i=1;row<epp->lr;row++,i++) {
29 fread(buf,bytes,1,in);
30 copyrow(buf,buf2,bytes);
31 for (col=epp->fc,p=buf2;col<epp->lc;col++,p++) {
32 epp_put(epp,col,row,(unsigned short)(*p+shift));
34 if (EndLineProc(row,i,rows)) return -1;
40 EPP *read_header(char *filename,int *swapbytes,int shift)
42 int rows=0,cols=0,nodata=32768;
43 FILE *f=fopen(filename,"r");
44 double X1=0,Y1=0,X2=0,Y2=0,DX=0,DY=0;
50 while(isalpha(*p)) p++;
52 if (!strcmp(buf,"BYTEORDER")) {
53 while(isspace(*p)) p++;
54 *swapbytes=toupper(*p)=='M';
55 } else if (!strcmp(buf,"NROWS")) {
57 } else if (!strcmp(buf,"NCOLS")) {
59 } else if (!strcmp(buf,"NBITS")) {
61 fprintf(stderr,"Data size in %s is not 16 bit\n",filename);
64 } else if (!strcmp(buf,"NODATA")) {
66 if (nodata<0) nodata+=65536;
67 } else if (!strcmp(buf,"ULXMAP")) {
69 } else if (!strcmp(buf,"ULYMAP")) {
71 } else if (!strcmp(buf,"XDIM")) {
73 } else if (!strcmp(buf,"YDIM")) {
83 return creat_epp(force_ext(filename,".epp"),1,1,cols,
84 rows,X1,Y1,X2,Y2,100,0,nodata);
86 int main(int argc, char **argv)
88 char headersuffix[100]=".hdr",headername[1024];
90 while ((c=getopt(argc,argv,"s:h:%"))!=EOF) {
92 case 's': {char *erptr;
93 shift = strtol(optarg,&erptr,0);
95 error("Invalid shift value");
99 case 'h': strcpy(headersuffix, optarg);
103 default: error("Invalid option.\n Usage bil2epp [-h header_suffix]"
104 " [-s shift_value] [-%] files\n");
108 install_progress_indicator(verbose?show_percent:check_int);
109 if (optind==argc) error("No files specified");
111 for (i=optind;i<argc;i++) {
113 FILE *f=fopen(argv[i],"r");
117 fprintf(stderr,"Cannot open %s, skipping\n",argv[i]);
120 strcpy(headername,force_ext(argv[i],headersuffix));
121 if (!(epp=read_header(headername,&swapbytes,shift))) {
122 fprintf(stderr,"Cannot open %s, skipping %s\n",headername,argv[i]);
126 fprintf(stderr,"\r%s\n",argv[i]);
128 if (convert (epp,f,swapbytes?swab:dcopy,shift)) {