/* Copyright (c) 1993 Association of Universities for Research * in Astronomy. All rights reserved. Produced under National * Aeronautics and Space Administration Contract No. NAS5-26555. */ /* imextrxy.c Extract an image at a given pixel position X,Y from a * specified plate. The image can be written either to a * FITS file or to a hhh/hhd file (readable by IRAF.) * * Inputs from terminal (stdin): * plate name of plate (e.g. s840) * X, Y position of source in pixels * nx,ny size of section to extract * object name of object (data is written to object.fits or object.hhh/d) * format output file format ("h" for hhh/hhd, else written in FITS) * * Inputs from command line: * plate_root partial name of directory where plates are located * header_dir directory where headers are located * compression compression factor ("low", "medium", or "high") * -s optional flag to use smoothing when decompressing images * * Programmer: R. White Date: 5 August 1991 * Modified 14 April 1992 to add smoothing parameter. * */ #include #include #include #include #include "header.h" int smooth = 0; extern void pltlist(); extern int gethdr(); extern void position(); extern void conrddms(); extern void getxy(); extern int getradec(); extern int writehhh(); extern int writefits(); main (argc, argv) int argc; char *argv[]; { Header header; int nx, ny; float x, y; int rah,ram,decd,decm; float ras,decs; char decsign; double ra, dec; float mag = 0.0, colour = 0.0; short *image; char filename[80], object[75], format[80]; /* * search for smoothing flag */ if (argc==5 && ( strcmp(argv[4],"-s")==0 || strcmp(argv[4],"-S")==0 )) { smooth = 1; } else if (argc != 4) { fprintf(stderr, "Usage: %s plate-directory header-directory compression-factor [-s]\n", argv[0]); exit(0); } /* * set plate directory, header directory, compression factor, and * plate name in header structure using command line parameters */ strcpy(header.plate_root, argv[1]); strcpy(header.header_dir, argv[2]); strcpy(header.compression, argv[3]); /* * list plates that are available */ pltlist(); /* * get plate name */ fprintf(stderr, "Enter plate name: "); fscanf(stdin, " %s", header.plate_name); /* * read header file for this plate */ if (gethdr(&header)) { fprintf(stderr, "Could not read header for plate %s\n", header.plate_name); exit(0); } /* * get X, Y and convert to RA, Dec */ fprintf(stderr, "Enter target position in pixels (X Y): "); fscanf(stdin, " %f %f", &x, &y); position(&header, x, y, mag, colour, &ra, &dec); conrddms(ra,dec, &rah,&ram,&ras, &decsign,&decd,&decm,&decs); fprintf(stderr, "J2000: %2.2d %2.2d %6.3f %c%2.2d %2.2d %5.2f\n", rah,ram,ras, decsign,decd,decm,decs); /* * get section size */ fprintf(stderr, "Enter desired image size (nx ny): "); fscanf(stdin, " %d %d", &nx, &ny); image = (short *) malloc(sizeof(short)*nx*ny); /* * get object name = output file root */ fprintf(stderr, "Enter object name (use a legal filename root): "); fscanf(stdin, " %s", object); /* * extract image */ getxy(&header,object,x,y,nx,ny,image); /* * write output in FITS or hhh/hhd format */ fprintf(stderr, "Enter format for output image file (h=hhh/hhd, else FITS): "); fscanf(stdin, " %s", format); if (strchr(format,'h') != NULL) { strcpy(filename, object); strcat(filename, ".hhh"); if (writehhh(&header, image, filename)) { fprintf(stderr, "Write to %s/.hhd failed\n", filename); exit(0); } else { fprintf(stderr, "Wrote hhh/hhd image to file %s/.hhd\n", filename); } } else { strcpy(filename, object); strcat(filename, ".fits"); if (writefits(&header, image, filename)) { fprintf(stderr, "Write to file %s failed\n", filename); exit(0); } else { fprintf(stderr, "Wrote FITS image to file %s\n", filename); } } exit(1); }