Ejemplo n.º 1
0
/*--------------------------------------------------------------------------*/
int ffcpdt(fitsfile *infptr,    /* I - FITS file pointer to input file  */
           fitsfile *outfptr,   /* I - FITS file pointer to output file */
           int *status)         /* IO - error status     */
{
/*
  copy the data unit from the CHDU of infptr to the CHDU of outfptr. 
  This will overwrite any data already in the outfptr CHDU.
*/
    long nb, ii;
    LONGLONG indatastart, indataend, outdatastart;
    char buffer[2880];

    if (*status > 0)
        return(*status);

    if (infptr == outfptr)
        return(*status = SAME_FILE);

    ffghadll(infptr,  NULL, &indatastart, &indataend, status);
    ffghadll(outfptr, NULL, &outdatastart, NULL, status);

    /* Calculate the number of blocks to be copied  */
    nb = (long) ((indataend - indatastart) / 2880);

    if (nb > 0)
    {
      if (infptr->Fptr == outfptr->Fptr)
      {
        /* copying between 2 HDUs in the SAME file */
        for (ii = 0; ii < nb; ii++)
        {
            ffmbyt(infptr,  indatastart,  REPORT_EOF, status);
            ffgbyt(infptr,  2880L, buffer, status); /* read input block */

            ffmbyt(outfptr, outdatastart, IGNORE_EOF, status);
            ffpbyt(outfptr, 2880L, buffer, status); /* write output block */

            indatastart  += 2880; /* move address */
            outdatastart += 2880; /* move address */
        }
      }
      else
      {
        /* copying between HDUs in separate files */
        /* move to the initial copy position in each of the files */
        ffmbyt(infptr,  indatastart,  REPORT_EOF, status);
        ffmbyt(outfptr, outdatastart, IGNORE_EOF, status);

        for (ii = 0; ii < nb; ii++)
        {
            ffgbyt(infptr,  2880L, buffer, status); /* read input block */
            ffpbyt(outfptr, 2880L, buffer, status); /* write output block */
        }
      }
    }
    return(*status);
}
Ejemplo n.º 2
0
/*--------------------------------------------------------------------------*/
int ffwrhdu(fitsfile *infptr,    /* I - FITS file pointer to input file  */
            FILE *outstream,     /* I - stream to write HDU to */
            int *status)         /* IO - error status     */
{
/*
  write the data unit from the CHDU of infptr to the output file stream
*/
    long nb, ii;
    LONGLONG hdustart, hduend;
    char buffer[2880];

    if (*status > 0)
        return(*status);

    ffghadll(infptr, &hdustart,  NULL, &hduend, status);

    nb = (long) ((hduend - hdustart) / 2880);  /* number of blocks to copy */

    if (nb > 0)
    {

        /* move to the start of the HDU */
        ffmbyt(infptr,  hdustart,  REPORT_EOF, status);

        for (ii = 0; ii < nb; ii++)
        {
            ffgbyt(infptr,  2880L, buffer, status); /* read input block */
            fwrite(buffer, 1, 2880, outstream ); /* write to output stream */
        }
    }
    return(*status);
}
Ejemplo n.º 3
0
/* Routine to test the extra bytes at the end of file */ 
   void  test_end(fitsfile *infits, 
		  FILE *out) 

{   
   int status = 0; 
   LONGLONG headstart, datastart, dataend;
   int hdutype;

   /* check whether there are any HDU left */ 
   fits_movrel_hdu(infits,1, &hdutype, &status);
   if (!status) {
       wrtout(out,"< End-of-File >");
       sprintf(errmes, 
    "There are extraneous HDU(s) beyond the end of last HDU.");
       wrterr(out,errmes,2);
       wrtout(out," ");
       return;
   }

   if (status != END_OF_FILE) { 
      wrtserr(out,"Bad HDU? ",&status,2);
      return;
   } 

   status = 0;  
   fits_clear_errmsg();
   if(ffghadll(infits, &headstart, &datastart, &dataend, &status)) 
       wrtferr(out, "",&status,1);

   /* try to move to the last byte of this extension.  */
   if (ffmbyt(infits, dataend - 1,0,&status))
   {
       sprintf(errmes, 
   "Error trying to read last byte of the file at byte %ld.", (long) dataend);
       wrterr(out,errmes,2);
       wrtout(out,"< End-of-File >");
       wrtout(out," ");
       return;
   } 

   /* try to move to what would be the first byte of the next extension. 
     If successfull, we have a problem... */

   ffmbyt(infits, dataend,0,&status);
   if(status == 0) { 
       wrtout(out,"< End-of-File >");
       sprintf(errmes, 
     "File has extra byte(s) after last HDU at byte %ld.", (long) dataend);
       wrterr(out,errmes,2);
       wrtout(out," ");
   } 

   return;
}