static int UpdateHdr (char *output) { extern int status; Hdr phdr; /* primary header */ IODescPtr im; /* descriptor for output image */ int PutKeyBool (Hdr *, char *, Bool, char *); sprintf(MsgText, "Trying to open %s...",output); trlmessage (MsgText); initHdr (&phdr); /* Open input image in order to read its primary header. */ im = openUpdateImage (output, "", 0, &phdr); if (hstio_err()) { trlopenerr (output); closeImage(im); return (status = OPEN_FAILED); } if (PutKeyBool (&phdr, "ASN_PROD", True, "") ) { freeHdr (&phdr); trlerror ("Couldn't update ASN_PROD keyword in ASN table header"); return(status = KEYWORD_MISSING); } /* write out primary header */ if (putHeader (im)) status = HEADER_PROBLEM; if (hstio_err() || status) { trlreaderr (output); closeImage (im); return (status = OPEN_FAILED); } closeImage (im); /* Close the ASN table's primary header. */ freeHdr (&phdr); sprintf(MsgText, "Updated Global Header for %s...",output); trlmessage (MsgText); return (status); }
/* This routine copies a FITS file. */ static int CopyFFile (char *infile, char *outfile) { /* arguments: infile i: name of input file outfile i: name of output file */ extern int status; FILE *ifp, *ofp; /* for input and output files */ void *buf; /* buffer for copying blocks */ int nin, nout; /* number read and written */ int done; IODescPtr im; Hdr phdr; /* function from lib */ void UFilename (char *, Hdr *); if ((buf = calloc (FITS_BUFSIZE, sizeof(char))) == NULL) return (status = OUT_OF_MEMORY); if ((ofp = fopen (outfile, "wb")) == NULL) { sprintf (MsgText,"Can't create temporary file %s.", outfile); trlerror(MsgText); free (buf); return (status = INVALID_TEMP_FILE); } if ((ifp = fopen (infile, "rb")) == NULL) { sprintf (MsgText, "Can't open %s.", infile); trlerror (MsgText); (void)fcloseWithStatus(&ofp); remove (outfile); free (buf); return (status = OPEN_FAILED); } done = 0; while (!done) { nin = fread (buf, sizeof(char), FITS_BUFSIZE, ifp); if (ferror (ifp)) { sprintf (MsgText, "Can't read from %s (copying to %s).", infile, outfile); trlerror (MsgText); (void)fcloseWithStatus(&ofp); (void)fcloseWithStatus(&ifp); free (buf); return (status = FILE_NOT_READABLE); } if (feof (ifp)) done = 1; nout = fwrite (buf, sizeof(char), nin, ofp); if (nout < nin) { sprintf (MsgText, "Can't copy %s to %s.", infile, outfile); trlerror (MsgText); (void)fcloseWithStatus(&ofp); (void)fcloseWithStatus(&ifp); free (buf); return (status = COPY_NOT_POSSIBLE); } } (void)fcloseWithStatus(&ofp); (void)fcloseWithStatus(&ifp); free (buf); /* Update the FILENAME keyword in the primary header of the output file. */ initHdr (&phdr); im = openUpdateImage (outfile, "", 0, &phdr); UFilename (outfile, &phdr); putHeader (im); closeImage (im); freeHdr (&phdr); return (status); }
int TargPos (StisInfo12 *sci, int extver, double shift1, double shift2) { /* arguments: StisInfo12 *sci i: info about science data file int extver i: EXTVER number of extensions to update double shift1, shift2 i: shift to be assigned to SHIFTAi keywords */ int status; IODescPtr im; /* descriptor for an image */ Hdr hdr; /* header for an extension */ /* Update SCI extension. */ initHdr (&hdr); im = openUpdateImage (sci->input, "SCI", extver, &hdr); if (hstio_err()) return (OPEN_FAILED); /* Update SHIFTAi. */ if ((status = UpdateShift (&hdr, shift1, shift2))) return (status); putHeader (im); if (hstio_err()) return (OPEN_FAILED); closeImage (im); freeHdr (&hdr); /* Update ERR extension. */ im = openUpdateImage (sci->input, "ERR", extver, &hdr); if (hstio_err()) return (OPEN_FAILED); if ((status = UpdateShift (&hdr, shift1, shift2))) return (status); putHeader (im); if (hstio_err()) return (OPEN_FAILED); closeImage (im); freeHdr (&hdr); /* Update DQ extension. */ im = openUpdateImage (sci->input, "DQ", extver, &hdr); if (hstio_err()) return (OPEN_FAILED); if ((status = UpdateShift (&hdr, shift1, shift2))) return (status); putHeader (im); if (hstio_err()) return (OPEN_FAILED); closeImage (im); freeHdr (&hdr); /* write to trailer */ if (fabs (shift1) < MUCH_TOO_BIG) /* shift is OK */ printf (" SHIFTA1 set to %.6g\n", shift1); if (fabs (shift2) < MUCH_TOO_BIG) printf (" SHIFTA2 set to %.6g\n", shift2); return (0); }