| |
| |
|
|
| |
| |
| |
|
|
| #include <string.h> |
| #include <stdlib.h> |
| #include "fitsio2.h" |
| |
| int ffcopy(fitsfile *infptr, |
| fitsfile *outfptr, |
| int morekeys, |
| int *status) |
| |
| |
| |
| |
| { |
| int nspace; |
| |
| if (*status > 0) |
| return(*status); |
|
|
| if (infptr == outfptr) |
| return(*status = SAME_FILE); |
|
|
| if (ffcphd(infptr, outfptr, status) > 0) |
| return(*status); |
|
|
| if (morekeys > 0) { |
| ffhdef(outfptr, morekeys, status); |
|
|
| } else { |
| if (ffghsp(infptr, NULL, &nspace, status) > 0) |
| return(*status); |
|
|
| if (nspace > 0) { |
| ffhdef(outfptr, nspace, status); |
| if (nspace >= 35) { |
|
|
| |
| |
| |
| |
| |
|
|
| ffwend(outfptr, status); |
| } |
| } |
| } |
|
|
| ffcpdt(infptr, outfptr, status); |
|
|
| return(*status); |
| } |
| |
| int ffcpfl(fitsfile *infptr, |
| fitsfile *outfptr, |
| int previous, |
| int current, |
| int following, |
| int *status) |
| |
| |
| |
| { |
| int hdunum, ii; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (infptr == outfptr) |
| return(*status = SAME_FILE); |
|
|
| ffghdn(infptr, &hdunum); |
|
|
| if (previous) { |
| for (ii=1; ii < hdunum; ii++) { |
| ffmahd(infptr, ii, NULL, status); |
| ffcopy(infptr, outfptr, 0, status); |
| } |
| } |
|
|
| if (current && (*status <= 0) ) { |
| ffmahd(infptr, hdunum, NULL, status); |
| ffcopy(infptr, outfptr, 0, status); |
| } |
|
|
| if (following && (*status <= 0) ) { |
| ii = hdunum + 1; |
| while (1) |
| { |
| if (ffmahd(infptr, ii, NULL, status) ) { |
| |
| if (*status == END_OF_FILE) |
| *status = 0; |
| break; |
| } |
|
|
| if (ffcopy(infptr, outfptr, 0, status)) |
| break; |
|
|
| ii++; |
| } |
| } |
|
|
| ffmahd(infptr, hdunum, NULL, status); |
| return(*status); |
| } |
| |
| int ffcphd(fitsfile *infptr, |
| fitsfile *outfptr, |
| int *status) |
| |
| |
| |
| { |
| int nkeys, ii, inPrim = 0, outPrim = 0; |
| long naxis, naxes[1]; |
| char *card, comm[FLEN_COMMENT]; |
| char *tmpbuff; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (infptr == outfptr) |
| return(*status = SAME_FILE); |
|
|
| |
| if (infptr->HDUposition != (infptr->Fptr)->curhdu) |
| ffmahd(infptr, (infptr->HDUposition) + 1, NULL, status); |
|
|
| if (ffghsp(infptr, &nkeys, NULL, status) > 0) |
| return(*status); |
|
|
| |
| tmpbuff = (char*) malloc(nkeys*FLEN_CARD*sizeof(char)); |
| if (!tmpbuff) |
| return(*status = MEMORY_ALLOCATION); |
|
|
| |
| for (ii = 0; ii < nkeys; ii++) |
| ffgrec(infptr, ii+1, tmpbuff + (ii * FLEN_CARD), status); |
|
|
| if (infptr->HDUposition == 0) |
| inPrim = 1; |
|
|
| |
| naxis = -1; |
| if ((infptr->Fptr)->hdutype == IMAGE_HDU) |
| ffgkyj(infptr, "NAXIS", &naxis, NULL, status); |
|
|
| |
| if (outfptr->HDUposition != (outfptr->Fptr)->curhdu) |
| ffmahd(outfptr, (outfptr->HDUposition) + 1, NULL, status); |
|
|
| |
| if ((outfptr->Fptr)->headend != |
| (outfptr->Fptr)->headstart[(outfptr->Fptr)->curhdu] ) |
| ffcrhd(outfptr, status); |
|
|
| if (outfptr->HDUposition == 0) |
| { |
| if (naxis < 0) |
| { |
| |
| |
| ffcrim(outfptr, 8, 0, naxes, status); |
| ffcrhd(outfptr, status); |
| } |
| else |
| { |
| |
| outPrim = 1; |
| } |
| } |
|
|
| if (*status > 0) |
| { |
| free(tmpbuff); |
| return(*status); |
| } |
| if ( inPrim == 1 && outPrim == 0 ) |
| { |
| |
| strcpy(comm, "IMAGE extension"); |
| ffpkys(outfptr, "XTENSION", "IMAGE", comm, status); |
|
|
| |
| for (ii = 1; ii < 3 + naxis; ii++) |
| { |
| card = tmpbuff + (ii * FLEN_CARD); |
| ffprec(outfptr, card, status); |
| } |
|
|
| strcpy(comm, "number of random group parameters"); |
| ffpkyj(outfptr, "PCOUNT", 0, comm, status); |
| |
| strcpy(comm, "number of random groups"); |
| ffpkyj(outfptr, "GCOUNT", 1, comm, status); |
|
|
|
|
| |
| for (ii = 3 + naxis ; ii < nkeys; ii++) |
| { |
| card = tmpbuff+(ii * FLEN_CARD); |
| if (FSTRNCMP(card, "EXTEND ", 8) && |
| FSTRNCMP(card, "COMMENT FITS (Flexible Image Transport System) format is", 58) && |
| FSTRNCMP(card, "COMMENT and Astrophysics', volume 376, page 3", 47) ) |
| { |
| ffprec(outfptr, card, status); |
| } |
| } |
| } |
| else if ( inPrim == 0 && outPrim == 1 ) |
| { |
| |
| strcpy(comm, "file does conform to FITS standard"); |
| ffpkyl(outfptr, "SIMPLE", TRUE, comm, status); |
|
|
| |
| for (ii = 1; ii < 3 + naxis; ii++) |
| { |
| card = tmpbuff + (ii * FLEN_CARD); |
| ffprec(outfptr, card, status); |
| } |
|
|
| |
| strcpy(comm, "FITS dataset may contain extensions"); |
| ffpkyl(outfptr, "EXTEND", TRUE, comm, status); |
|
|
| |
| ffprec(outfptr, |
| "COMMENT FITS (Flexible Image Transport System) format is defined in 'Astronomy", |
| status); |
| ffprec(outfptr, |
| "COMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H", |
| status); |
|
|
| |
| for (ii = 3 + naxis; ii < nkeys; ii++) |
| { |
| card = tmpbuff+(ii * FLEN_CARD); |
| if (FSTRNCMP(card, "PCOUNT ", 8) && FSTRNCMP(card, "GCOUNT ", 8)) |
| { |
| ffprec(outfptr, card, status); |
| } |
| } |
| } |
| else |
| { |
| |
| for (ii = 0; ii < nkeys; ii++) |
| { |
| card = tmpbuff+(ii * FLEN_CARD); |
| ffprec(outfptr, card, status); |
| } |
| } |
|
|
| free(tmpbuff); |
| return(*status); |
| } |
| |
| int ffcpdt(fitsfile *infptr, |
| fitsfile *outfptr, |
| int *status) |
| { |
| |
| |
| |
| |
| 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); |
|
|
| |
| nb = (long) ((indataend - indatastart) / 2880); |
|
|
| if (nb > 0) |
| { |
| if (infptr->Fptr == outfptr->Fptr) |
| { |
| |
| for (ii = 0; ii < nb; ii++) |
| { |
| ffmbyt(infptr, indatastart, REPORT_EOF, status); |
| ffgbyt(infptr, 2880L, buffer, status); |
|
|
| ffmbyt(outfptr, outdatastart, IGNORE_EOF, status); |
| ffpbyt(outfptr, 2880L, buffer, status); |
|
|
| indatastart += 2880; |
| outdatastart += 2880; |
| } |
| } |
| else |
| { |
| |
| |
| ffmbyt(infptr, indatastart, REPORT_EOF, status); |
| ffmbyt(outfptr, outdatastart, IGNORE_EOF, status); |
|
|
| for (ii = 0; ii < nb; ii++) |
| { |
| ffgbyt(infptr, 2880L, buffer, status); |
| ffpbyt(outfptr, 2880L, buffer, status); |
| } |
| } |
| } |
| return(*status); |
| } |
| |
| int ffwrhdu(fitsfile *infptr, |
| FILE *outstream, |
| int *status) |
| { |
| |
| |
| |
| 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); |
|
|
| if (nb > 0) |
| { |
|
|
| |
| ffmbyt(infptr, hdustart, REPORT_EOF, status); |
|
|
| for (ii = 0; ii < nb; ii++) |
| { |
| ffgbyt(infptr, 2880L, buffer, status); |
| fwrite(buffer, 1, 2880, outstream ); |
| } |
| } |
| return(*status); |
| } |
| |
| int ffiimg(fitsfile *fptr, |
| int bitpix, |
| int naxis, |
| long *naxes, |
| int *status) |
| |
| |
| |
| { |
| LONGLONG tnaxes[99]; |
| int ii; |
| |
| if (*status > 0) |
| return(*status); |
|
|
| if (naxis > 99) { |
| ffpmsg("NAXIS value is too large (>99) (ffiimg)"); |
| return(*status = 212); |
| } |
|
|
| for (ii = 0; (ii < naxis); ii++) |
| tnaxes[ii] = naxes[ii]; |
| |
| ffiimgll(fptr, bitpix, naxis, tnaxes, status); |
|
|
| return(*status); |
| } |
| |
| int ffiimgll(fitsfile *fptr, |
| int bitpix, |
| int naxis, |
| LONGLONG *naxes, |
| int *status) |
| |
| |
| |
| { |
| int bytlen, nexthdu, maxhdu, ii, onaxis; |
| long nblocks; |
| LONGLONG npixels, newstart, datasize; |
| char errmsg[FLEN_ERRMSG], card[FLEN_CARD], naxiskey[FLEN_KEYWORD]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| maxhdu = (fptr->Fptr)->maxhdu; |
|
|
| if (*status != PREPEND_PRIMARY) |
| { |
| |
| if (( (fptr->Fptr)->headend == (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu]) |
| |
| || ( (((fptr->Fptr)->curhdu) == maxhdu ) && |
| ((fptr->Fptr)->headstart[maxhdu + 1] >= (fptr->Fptr)->logfilesize ) ) ) |
| { |
| |
| ffcrimll(fptr, bitpix, naxis, naxes, status); |
| return(*status); |
| } |
| } |
|
|
| if (bitpix == 8) |
| bytlen = 1; |
| else if (bitpix == 16) |
| bytlen = 2; |
| else if (bitpix == 32 || bitpix == -32) |
| bytlen = 4; |
| else if (bitpix == 64 || bitpix == -64) |
| bytlen = 8; |
| else |
| { |
| snprintf(errmsg, FLEN_ERRMSG, |
| "Illegal value for BITPIX keyword: %d", bitpix); |
| ffpmsg(errmsg); |
| return(*status = BAD_BITPIX); |
| } |
| if (naxis < 0 || naxis > 999) |
| { |
| snprintf(errmsg, FLEN_ERRMSG, |
| "Illegal value for NAXIS keyword: %d", naxis); |
| ffpmsg(errmsg); |
| return(*status = BAD_NAXIS); |
| } |
|
|
| for (ii = 0; ii < naxis; ii++) |
| { |
| if (naxes[ii] < 0) |
| { |
| snprintf(errmsg, FLEN_ERRMSG, |
| "Illegal value for NAXIS%d keyword: %ld", ii + 1, (long) naxes[ii]); |
| ffpmsg(errmsg); |
| return(*status = BAD_NAXES); |
| } |
| } |
|
|
| |
| if (naxis == 0) |
| npixels = 0; |
| else |
| npixels = naxes[0]; |
|
|
| for (ii = 1; ii < naxis; ii++) |
| npixels = npixels * naxes[ii]; |
|
|
| datasize = npixels * bytlen; |
| nblocks = (long) (((datasize + 2879) / 2880) + 1); |
|
|
| if ((fptr->Fptr)->writemode == READWRITE) |
| { |
| ffrdef(fptr, status); |
| ffpdfl(fptr, status); |
| } |
| else |
| return(*status = READONLY_FILE); |
|
|
| if (*status == PREPEND_PRIMARY) |
| { |
| |
| |
|
|
| *status = 0; |
| ffmahd(fptr, 1, NULL, status); |
|
|
| ffgidm(fptr, &onaxis, status); |
| if (onaxis > 0) |
| ffkeyn("NAXIS",onaxis, naxiskey, status); |
| else |
| strcpy(naxiskey, "NAXIS"); |
|
|
| ffgcrd(fptr, naxiskey, card, status); |
| |
| ffikyj(fptr, "PCOUNT", 0, "required keyword", status); |
| ffikyj(fptr, "GCOUNT", 1, "required keyword", status); |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (ffdkey(fptr, "EXTEND", status) ) |
| *status = 0; |
|
|
| |
| ffrdef(fptr, status); |
|
|
|
|
| |
| if (ffiblk(fptr, nblocks, -1, status) > 0) |
| return(*status); |
|
|
| nexthdu = 0; |
| newstart = 0; |
| } |
| else |
| { |
| nexthdu = ((fptr->Fptr)->curhdu) + 1; |
| newstart = (fptr->Fptr)->headstart[nexthdu]; |
|
|
| (fptr->Fptr)->hdutype = IMAGE_HDU; |
| |
| if (ffiblk(fptr, nblocks, 1, status) > 0) |
| return(*status); |
| } |
|
|
| ((fptr->Fptr)->maxhdu)++; |
| for (ii = (fptr->Fptr)->maxhdu; ii > (fptr->Fptr)->curhdu; ii--) |
| (fptr->Fptr)->headstart[ii + 1] = (fptr->Fptr)->headstart[ii]; |
|
|
| if (nexthdu == 0) |
| (fptr->Fptr)->headstart[1] = nblocks * 2880; |
|
|
| (fptr->Fptr)->headstart[nexthdu] = newstart; |
|
|
| |
| (fptr->Fptr)->curhdu = nexthdu; |
| fptr->HDUposition = nexthdu; |
| (fptr->Fptr)->nextkey = (fptr->Fptr)->headstart[nexthdu]; |
| (fptr->Fptr)->headend = (fptr->Fptr)->headstart[nexthdu]; |
| (fptr->Fptr)->datastart = ((fptr->Fptr)->headstart[nexthdu]) + 2880; |
| (fptr->Fptr)->hdutype = IMAGE_HDU; |
|
|
| |
| ffphprll(fptr, TRUE, bitpix, naxis, naxes, 0, 1, TRUE, status); |
|
|
| |
| ffrdef(fptr, status); |
| return(*status); |
| } |
| |
| int ffitab(fitsfile *fptr, |
| LONGLONG naxis1, |
| LONGLONG naxis2, |
| int tfields, |
| char **ttype, |
| long *tbcol, |
| char **tform, |
| char **tunit, |
| const char *extnmx, |
| int *status) |
| |
| |
| |
| { |
| int nexthdu, maxhdu, ii, nunit, nhead, ncols, gotmem = 0; |
| long nblocks, rowlen; |
| LONGLONG datasize, newstart; |
| char errmsg[FLEN_ERRMSG], extnm[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| extnm[0] = '\0'; |
| if (extnmx) |
| strncat(extnm, extnmx, FLEN_VALUE-1); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| maxhdu = (fptr->Fptr)->maxhdu; |
| |
| if (( (fptr->Fptr)->headend == (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu] ) |
| |
| || ( (((fptr->Fptr)->curhdu) == maxhdu ) && |
| ((fptr->Fptr)->headstart[maxhdu + 1] >= (fptr->Fptr)->logfilesize ) ) ) |
| { |
| |
| ffcrtb(fptr, ASCII_TBL, naxis2, tfields, ttype, tform, tunit, |
| extnm, status); |
| return(*status); |
| } |
|
|
| if (naxis1 < 0) |
| return(*status = NEG_WIDTH); |
| else if (naxis2 < 0) |
| return(*status = NEG_ROWS); |
| else if (tfields < 0 || tfields > 999) |
| { |
| snprintf(errmsg, FLEN_ERRMSG, |
| "Illegal value for TFIELDS keyword: %d", tfields); |
| ffpmsg(errmsg); |
| return(*status = BAD_TFIELDS); |
| } |
|
|
| |
| nunit = 0; |
| for (ii = 0; ii < tfields; ii++) |
| { |
| if (tunit && *tunit && *tunit[ii]) |
| nunit++; |
| } |
|
|
| if (*extnm) |
| nunit++; |
|
|
| rowlen = (long) naxis1; |
|
|
| if (!tbcol || !tbcol[0] || (!naxis1 && tfields)) |
| { |
| |
| |
|
|
| ncols = maxvalue(5, tfields); |
| tbcol = (long *) calloc(ncols, sizeof(long)); |
|
|
| if (tbcol) |
| { |
| gotmem = 1; |
|
|
| |
| |
| ffgabc(tfields, tform, 1, &rowlen, tbcol, status); |
| } |
| } |
|
|
| nhead = (9 + (3 * tfields) + nunit + 35) / 36; |
| datasize = (LONGLONG)rowlen * naxis2; |
| nblocks = (long) (((datasize + 2879) / 2880) + nhead); |
|
|
| if ((fptr->Fptr)->writemode == READWRITE) |
| { |
| ffrdef(fptr, status); |
| ffpdfl(fptr, status); |
| } |
| else |
| return(*status = READONLY_FILE); |
|
|
| nexthdu = ((fptr->Fptr)->curhdu) + 1; |
| newstart = (fptr->Fptr)->headstart[nexthdu]; |
|
|
| (fptr->Fptr)->hdutype = ASCII_TBL; |
| |
| if (ffiblk(fptr, nblocks, 1, status) > 0) |
| { |
| if (gotmem) |
| free(tbcol); |
| return(*status); |
| } |
|
|
| ((fptr->Fptr)->maxhdu)++; |
| for (ii = (fptr->Fptr)->maxhdu; ii > (fptr->Fptr)->curhdu; ii--) |
| (fptr->Fptr)->headstart[ii + 1] = (fptr->Fptr)->headstart[ii]; |
|
|
| (fptr->Fptr)->headstart[nexthdu] = newstart; |
|
|
| |
| (fptr->Fptr)->curhdu = nexthdu; |
| fptr->HDUposition = nexthdu; |
| (fptr->Fptr)->nextkey = (fptr->Fptr)->headstart[nexthdu]; |
| (fptr->Fptr)->headend = (fptr->Fptr)->headstart[nexthdu]; |
| (fptr->Fptr)->datastart = ((fptr->Fptr)->headstart[nexthdu]) + (nhead * 2880); |
| (fptr->Fptr)->hdutype = ASCII_TBL; |
|
|
| |
|
|
| ffphtb(fptr, rowlen, naxis2, tfields, ttype, tbcol, tform, tunit, |
| extnm, status); |
|
|
| if (gotmem) |
| free(tbcol); |
|
|
| |
|
|
| ffrdef(fptr, status); |
| return(*status); |
| } |
| |
| int ffibin(fitsfile *fptr, |
| LONGLONG naxis2, |
| int tfields, |
| char **ttype, |
| char **tform, |
| char **tunit, |
| const char *extnmx, |
| LONGLONG pcount, |
| int *status) |
| |
| |
| |
| { |
| int nexthdu, maxhdu, ii, nunit, nhead, datacode; |
| LONGLONG naxis1; |
| long nblocks, repeat, width; |
| LONGLONG datasize, newstart; |
| char errmsg[FLEN_ERRMSG], extnm[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| extnm[0] = '\0'; |
| if (extnmx) |
| strncat(extnm, extnmx, FLEN_VALUE-1); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| maxhdu = (fptr->Fptr)->maxhdu; |
| |
| if (( (fptr->Fptr)->headend == (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu] ) |
| |
| || ( (((fptr->Fptr)->curhdu) == maxhdu ) && |
| ((fptr->Fptr)->headstart[maxhdu + 1] >= (fptr->Fptr)->logfilesize ) ) ) |
| { |
| |
| ffcrtb(fptr, BINARY_TBL, naxis2, tfields, ttype, tform, tunit, |
| extnm, status); |
| return(*status); |
| } |
|
|
| if (naxis2 < 0) |
| return(*status = NEG_ROWS); |
| else if (tfields < 0 || tfields > 999) |
| { |
| snprintf(errmsg, FLEN_ERRMSG, |
| "Illegal value for TFIELDS keyword: %d", tfields); |
| ffpmsg(errmsg); |
| return(*status = BAD_TFIELDS); |
| } |
|
|
| |
| nunit = 0; |
| for (ii = 0; ii < tfields; ii++) |
| { |
| if (tunit && *tunit && *tunit[ii]) |
| nunit++; |
| } |
|
|
| if (*extnm) |
| nunit++; |
|
|
| nhead = (9 + (2 * tfields) + nunit + 35) / 36; |
|
|
| |
| naxis1 = 0; |
| for (ii = 0; ii < tfields; ii++) |
| { |
| ffbnfm(tform[ii], &datacode, &repeat, &width, status); |
|
|
| if (datacode == TBIT) |
| naxis1 = naxis1 + ((repeat + 7) / 8); |
| else if (datacode == TSTRING) |
| naxis1 += repeat; |
| else |
| naxis1 = naxis1 + (repeat * width); |
| } |
|
|
| datasize = ((LONGLONG)naxis1 * naxis2) + pcount; |
| nblocks = (long) ((datasize + 2879) / 2880) + nhead; |
|
|
| if ((fptr->Fptr)->writemode == READWRITE) |
| { |
| ffrdef(fptr, status); |
| ffpdfl(fptr, status); |
| } |
| else |
| return(*status = READONLY_FILE); |
|
|
| nexthdu = ((fptr->Fptr)->curhdu) + 1; |
| newstart = (fptr->Fptr)->headstart[nexthdu]; |
|
|
| (fptr->Fptr)->hdutype = BINARY_TBL; |
|
|
| |
| if (ffiblk(fptr, nblocks, 1, status) > 0) |
| return(*status); |
|
|
| ((fptr->Fptr)->maxhdu)++; |
| for (ii = (fptr->Fptr)->maxhdu; ii > (fptr->Fptr)->curhdu; ii--) |
| (fptr->Fptr)->headstart[ii + 1] = (fptr->Fptr)->headstart[ii]; |
|
|
| (fptr->Fptr)->headstart[nexthdu] = newstart; |
|
|
| |
| (fptr->Fptr)->curhdu = nexthdu; |
| fptr->HDUposition = nexthdu; |
| (fptr->Fptr)->nextkey = (fptr->Fptr)->headstart[nexthdu]; |
| (fptr->Fptr)->headend = (fptr->Fptr)->headstart[nexthdu]; |
| (fptr->Fptr)->datastart = ((fptr->Fptr)->headstart[nexthdu]) + (nhead * 2880); |
| (fptr->Fptr)->hdutype = BINARY_TBL; |
|
|
| |
| |
| ffphbn(fptr, naxis2, tfields, ttype, tform, tunit, extnm, pcount, |
| status); |
|
|
| |
| ffrdef(fptr, status); |
|
|
| return(*status); |
| } |
| |
| int ffdhdu(fitsfile *fptr, |
| int *hdutype, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| int tmptype = 0; |
| long nblocks, ii, naxes[1]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| if ((fptr->Fptr)->curhdu == 0) |
| { |
| |
| (fptr->Fptr)->headend = 0; |
| (fptr->Fptr)->nextkey = 0; |
|
|
| |
| ffphpr(fptr,1,8,0,naxes,0,1,1,status); |
|
|
| |
| nblocks = (long) (( (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu + 1] - |
| 2880 ) / 2880); |
|
|
| |
| if (nblocks > 0) |
| { |
| if (ffdblk(fptr, nblocks, status) > 0) |
| return(*status); |
| } |
|
|
| |
| (fptr->Fptr)->datastart = DATA_UNDEFINED; |
|
|
| ffrdef(fptr, status); |
| } |
| else |
| { |
|
|
| |
| nblocks = (long) (( (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu + 1] - |
| (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu] ) / 2880); |
|
|
| |
| if (ffdblk(fptr, nblocks, status) > 0) |
| return(*status); |
|
|
| |
| for (ii = (fptr->Fptr)->curhdu + 1; ii <= (fptr->Fptr)->maxhdu; ii++) |
| (fptr->Fptr)->headstart[ii] = (fptr->Fptr)->headstart[ii + 1]; |
|
|
| (fptr->Fptr)->headstart[(fptr->Fptr)->maxhdu + 1] = 0; |
| ((fptr->Fptr)->maxhdu)--; |
|
|
| if (ffrhdu(fptr, &tmptype, status) > 0) |
| { |
| |
| *status = 0; |
| ffcmsg(); |
| ffgext(fptr, ((fptr->Fptr)->curhdu) - 1, &tmptype, status); |
| } |
| } |
|
|
| if (hdutype) |
| *hdutype = tmptype; |
|
|
| return(*status); |
| } |
|
|
|
|