/* Copyright (c) 1993 Association of Universities for Research * in Astronomy. All rights reserved. Produced under National * Aeronautics and Space Administration Contract No. NAS5-26555. */ /* WRITEFITS * * PURPOSE: * Write FITS format data file * * CALLING SEQUENCE: * retval = writefits(h,image,filename) * * INPUTS: * h (* Header) header structure (must have correct image size, * FITS header lines -- use FILLHDR to update) * image (short int) image data * filename (* char) name of FITS file * * OUTPUTS: * returns 0 if successful, -1 if fails * * MODIFICATION HISTORY * Created by R. White, 31 July 1991 * Modified by R. White, 16 June 1992, to make fixed-length records * under VMS. * * * This test disc was produced under U.S. Government grant NAG W-2166 and has * been prepared for data management review only. No license, right, or * interest in any trademark, copyright, or use other than as stated herein is * granted hereby. Further distribution is prohibited. October 1991. * */ #include #include #include "qfile.h" #include "header.h" extern int writefits(h,image,filename) Header *h; short image[]; char *filename; { int i, npix; QFILE *ifile; char blank[80]; /* * Check to see whether file already exists * (Don't bother under VMS, just make a new version) */ #ifndef VMS if (access(filename,0) == 0) { fprintf(stderr, "Error: file %s already exists\n",filename); return(-1); } #endif /* * open file: 2880 byte records, no carriage control */ ifile = qcreat(filename, 2880, 0); /* * write header */ for (i=0; i < h->nhlines; i++) qwrite(ifile, h->hlines[i], 80); /* * write some blank lines if number of header lines is not a * multiple of 36 (2880 bytes) */ for (i = 0; i<80; i++) blank[i] = ' '; for (i = ((h->nhlines-1) % 36) + 1; i<36; i++) qwrite(ifile, blank, 80); /* * write data one byte at a time to ensure proper byte order */ npix = h->section_x_length * h->section_y_length; for (i=0; i>8) & 0xff, ifile); qputc( image[i] & 0xff, ifile); } /* * write pad to bring data up to multiple of 2880 bytes too */ for (i = ((2*npix-1) % 2880) + 1; i<2880; i++) qputc(0,ifile); qclose(ifile); return(0); }