/* function to read basic FITS header data from an array This is like FHEDR0.FOR, but *only* reads information. */ /* Inputs: rbuf unsigned character array containing header. nlines number of 80 byte lines in rbuf. naxes array of long integers, must be equal to or larger than expected number of dimensions. Outputs: *ltype 1 if SIMPLE is TRUE, 0 otherwise. *bitpix number of bits per pixel. *nax number of axes in array. naxes array containing lengths of each axis. *nend contains offset of last line in header. */ #include #include #define TRUE 1 #define FALSE 0 int fhedro(unsigned char *rbuf, int nlines, int *ltype, long *bitpix, short *nax, long *naxes, short *nend) { int ierr, i, j; char fitsline[81]; ierr = 0; for (i = 0; i < 80; i++) { fitsline[i] = rbuf[i]; } fitsline[80] = '\0'; if (!strncmp(fitsline,"SIMPLE ",8)) { /* if the first line of the header is "SIMPLE", check for the T */ if (fitsline[28] == 'T' || fitsline[29] == 'T') { *ltype = TRUE; } else { ierr = -2; *ltype = FALSE; } } else { ierr = -1; } if (ierr == 0) { for (i = 0; i < 80; i++) { fitsline[i] = rbuf[i + 80]; } fitsline[80] = '\0'; if (!strncmp(fitsline,"BITPIX ",8)) { /* get the value of BITPIX */ if (sscanf(&fitsline[16],"%14li",bitpix) != 1) ierr = -2; } else { ierr = -3; } } if (ierr == 0) { for (i = 0; i < 80; i++) { fitsline[i] = rbuf[i + 160]; } fitsline[80] = '\0'; if (!strncmp(fitsline,"NAXIS ",8)) { /* get the number of axes */ if (sscanf(&fitsline[16],"%14hi",nax) != 1) ierr = -2; } else { ierr = -4; } if (*nax < 1 || *nax > 9) { ierr = -5; *nax = 0; } /* find the dimensions of the array */ for (i = 0; i < *nax; i++) { if (ierr == 0) { for (j = 0; j < 80; j++) { fitsline[j] = rbuf[j + 240 + 80*i]; } fitsline[80] = '\0'; if (sscanf(fitsline," ",naxes + i) != 1) ierr = -6; } } /* find the end of the FITS header */ *nend = 0; if (ierr == 0) { for (i = 0; i < nlines; i++) { for (j = 0; j < 80; j++) { fitsline[j] = rbuf[j + 240 + 80*(*nax) + 80*i]; } fitsline[80] = '\0'; if (!strncmp(fitsline,"END",3)) { *nend = i; break; } } } return ierr; } }