#include #include #include extern char *optarg; extern int optind; #ifdef ANSI_FUNC int main (int argc, char **argv) #else main(argc, argv) int argc; char **argv; #endif { int i, j; int c; int args; int ptype; int dim1, dim2, bitpix, skip, bigendian; int tdim; char dims[SZ_LINE]; char *buf=NULL; char *iname=NULL, *oname=NULL; unsigned char *cbuf; short *sbuf; int *ibuf; float *fbuf; double *dbuf; double *dbuf2; Fun ifun=NULL, ofun=NULL; /* exit on gio errors */ setgerror(2); /* we want the args in the same order in which they arrived, and gnu getopt sometimes changes things without this */ putenv("POSIXLY_CORRECT=true"); /* process switch arguments */ while ((c = getopt(argc, argv, "c:l")) != -1){ switch(c){ case 'c': ptype = 'c'; strcpy(dims, optarg); ParseArraySpec(dims, &dim1, &dim2, &bitpix, &skip, &bigendian); break; case 'l': ptype = 'l'; break; } } /* check for required arguments */ args = argc - optind; switch(ptype){ case 'c': if( args < 1 ) gerror(stderr, "usage: %s -c dims fname\n", argv[0]); iname = NULL; oname = argv[optind++]; break; case 'l': if( args < 2 ) gerror(stderr, "usage: %s -l iname oname\n", argv[0]); iname = argv[optind++]; oname = argv[optind++]; break; default: gerror(stderr, "usage: %s requires -c [dims] or -l\n", argv[0]); } /* open the input FITS file */ if( iname ){ if( !(ifun = FunOpen(iname, "r", NULL)) ) gerror(stderr, "could not FunOpen input file: %s\n", argv[optind-1]); } /* open the output FITS file */ if( oname ){ if( !(ofun = FunOpen(oname, "w", NULL)) ) gerror(stderr, "could not FunOpen output file: %s\n", argv[optind-1]); } /* set appropriate data type buffer to point to image buffer */ if( ptype == 'c' ){ /* allocate the buffer */ tdim = dim1*dim2; buf = malloc(tdim*ft_sizeof(bitpix)); switch(bitpix){ case 8: cbuf = (unsigned char *)buf; for(i=0; i