/* Copyright (c) 1993 Association of Universities for Research * in Astronomy. All rights reserved. Produced under National * Aeronautics and Space Administration Contract No. NAS5-26555. */ /* imextrct.c Extract an image at a given RA,Dec 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) * RA, Dec position of source in J2000 or B1950 coordinates * equinox equinox of position * 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 condmsrd(); extern void conrddms(); extern void b1950_j2000(); extern int getradec(); extern int writehhh(); extern int writefits(); main (argc, argv) int argc; char *argv[]; { Header header; int nx, ny; int equinox,rah,ram,decd,decm; float ras,decs; char decsign; double in_ra, in_dec, ra, dec; 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(); 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 RA, Dec and convert to radians */ fprintf(stderr, "Enter target RA & Dec (hh mm ss.sss +dd mm ss.sss): "); fscanf(stdin, " %d %d %f %c%d %d %f", &rah,&ram,&ras, &decsign,&decd,&decm,&decs); if (decsign != '-') decsign = '+'; condmsrd(rah,ram,ras,decsign,decd,decm,decs, &in_ra, &in_dec); /* * precess position to 2000 if necessary */ fprintf(stderr, "Enter equinox for coordinates (1950 or 2000): "); fscanf(stdin, " %d", &equinox); if (equinox == 1950) { b1950_j2000(in_ra,in_dec,&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); } else if (equinox == 2000) { ra = in_ra; dec = in_dec; } else { fprintf(stderr, "Equinox must be 1950 or 2000\n"); exit(0); } /* * 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 */ if (getradec(&header,object,ra,dec,nx,ny,image)) { fprintf(stderr, "Image file not written\n"); exit(0); } /* * 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); }