/* Copyright (c) 1993 Association of Universities for Research * in Astronomy. All rights reserved. Produced under National * Aeronautics and Space Administration Contract No. NAS5-26555. */ /* WRITEHHH * * PURPOSE: * Write hhh/hhd format data files * * CALLING SEQUENCE: * retval = writehhh(h,image,headfile) * * INPUTS: * h (* Header) header structure (must have correct image size, * FITS header lines -- use FILLHDR to update) * image (short int) image data * headfile (* char) name of header file (with .xxh extension); data * will be written to file with final 'h' changed to 'd'. * * 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 write VMS fixed-length records * */ #include #include #include #include "qfile.h" #include "header.h" extern int writehhh(h,image,headfile) Header *h; short image[]; char *headfile; { char *datafile, *p; int i, npix; QFILE *ihead, *idata; /* * construct filename for data (hhd) file */ datafile = malloc(strlen(headfile)+1); strcpy(datafile, headfile); p = strrchr(datafile, 'h'); *p++ = 'd'; /* * the 'h' must either be the last character or be followed by * a semicolon (to be compatible with VMS) */ if (*p != '\0' && *p != ';') { fprintf(stderr, "Error: header filename must end with 'h'\n"); free(datafile); return(-1); } /* * check to see whether header or data files already exist * (Don't bother under VMS, just make a new version) */ #ifndef VMS if (access(headfile,0) == 0) { fprintf(stderr, "Error: header file %s already exists\n",headfile); free(datafile); return(-1); } if (access(datafile,0) == 0) { fprintf(stderr, "Error: data file %s already exists\n",datafile); free(datafile); return(-1); } #endif /* * write header file: 80 byte records, CR carriage control */ ihead = qcreat(headfile,80,1); for (i=0; i < h->nhlines; i++) qwrite(ihead,h->hlines[i],80); qclose(ihead); /* * write data file: 512 byte records, no carriage control */ idata = qcreat(datafile,512,0); npix = h->section_x_length * h->section_y_length; qwrite(idata, image, sizeof(short)*npix); qclose(idata); free(datafile); return(0); }