| |
| |
|
|
| |
| |
| |
|
|
| #include <string.h> |
| #include <stdlib.h> |
| #include "fitsio2.h" |
|
|
| |
| int ffmbyt(fitsfile *fptr, |
| LONGLONG bytepos, |
| int err_mode, |
| int *status) |
| { |
| |
| |
| |
| |
| |
| |
| long record; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (bytepos < 0) |
| return(*status = NEG_FILE_POS); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| record = (long) (bytepos / IOBUFLEN); |
|
|
| |
| if ( ((fptr->Fptr)->curbuf < 0) || |
| (record != (fptr->Fptr)->bufrecnum[(fptr->Fptr)->curbuf])) |
| ffldrc(fptr, record, err_mode, status); |
|
|
| if (*status <= 0) |
| (fptr->Fptr)->bytepos = bytepos; |
|
|
| return(*status); |
| } |
| |
| int ffpbyt(fitsfile *fptr, |
| LONGLONG nbytes, |
| void *buffer, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| int ii, nbuff; |
| LONGLONG filepos; |
| long recstart, recend; |
| long ntodo, bufpos, nspace, nwrite; |
| char *cptr; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| if (nbytes > LONG_MAX) { |
| ffpmsg("Number of bytes to write is greater than LONG_MAX (ffpbyt)."); |
| *status = WRITE_ERROR; |
| return(*status); |
| } |
| |
| ntodo = (long) nbytes; |
| cptr = (char *)buffer; |
|
|
| if ((fptr->Fptr)->curbuf < 0) |
| { |
| ffldrc(fptr, (long) (((fptr->Fptr)->bytepos) / IOBUFLEN), REPORT_EOF, status); |
| } |
|
|
| if (nbytes >= MINDIRECT) |
| { |
| |
| |
|
|
| nbuff = (fptr->Fptr)->curbuf; |
| filepos = (fptr->Fptr)->bytepos; |
| recstart = (fptr->Fptr)->bufrecnum[nbuff]; |
| recend = (long) ((filepos + nbytes - 1) / IOBUFLEN); |
|
|
| |
| bufpos = (long) (filepos - ((LONGLONG)recstart * IOBUFLEN)); |
| nspace = IOBUFLEN - bufpos; |
|
|
| if (nspace) |
| { |
| memcpy((fptr->Fptr)->iobuffer + (nbuff * IOBUFLEN) + bufpos, cptr, nspace); |
| ntodo -= nspace; |
| cptr += nspace; |
| filepos += nspace; |
| (fptr->Fptr)->dirty[nbuff] = TRUE; |
| } |
|
|
| for (ii = 0; ii < NIOBUF; ii++) |
| { |
| if ((fptr->Fptr)->bufrecnum[ii] >= recstart |
| && (fptr->Fptr)->bufrecnum[ii] <= recend ) |
| { |
| if ((fptr->Fptr)->dirty[ii]) |
| ffbfwt(fptr->Fptr, ii, status); |
|
|
| (fptr->Fptr)->bufrecnum[ii] = -1; |
| } |
| } |
|
|
| |
| if ((fptr->Fptr)->io_pos != filepos) |
| ffseek(fptr->Fptr, filepos); |
|
|
| nwrite = ((ntodo - 1) / IOBUFLEN) * IOBUFLEN; |
|
|
| ffwrite(fptr->Fptr, nwrite, cptr, status); |
| ntodo -= nwrite; |
| cptr += nwrite; |
| (fptr->Fptr)->io_pos = filepos + nwrite; |
|
|
| if ((fptr->Fptr)->io_pos >= (fptr->Fptr)->filesize) |
| { |
| (fptr->Fptr)->filesize = (fptr->Fptr)->io_pos; |
|
|
| |
| if ((fptr->Fptr)->hdutype == ASCII_TBL) |
| memset((fptr->Fptr)->iobuffer + (nbuff * IOBUFLEN), 32, IOBUFLEN); |
| else |
| memset((fptr->Fptr)->iobuffer + (nbuff * IOBUFLEN), 0, IOBUFLEN); |
| } |
| else |
| { |
| |
| ffread(fptr->Fptr, IOBUFLEN, (fptr->Fptr)->iobuffer + (nbuff * IOBUFLEN), status); |
| (fptr->Fptr)->io_pos += IOBUFLEN; |
| } |
|
|
| |
| memcpy((fptr->Fptr)->iobuffer + (nbuff * IOBUFLEN), cptr, ntodo); |
| (fptr->Fptr)->dirty[nbuff] = TRUE; |
| (fptr->Fptr)->bufrecnum[nbuff] = recend; |
|
|
| (fptr->Fptr)->logfilesize = maxvalue((fptr->Fptr)->logfilesize, |
| (LONGLONG)(recend + 1) * IOBUFLEN); |
| (fptr->Fptr)->bytepos = filepos + nwrite + ntodo; |
| } |
| else |
| { |
| |
| bufpos = (long) ((fptr->Fptr)->bytepos - ((LONGLONG)(fptr->Fptr)->bufrecnum[(fptr->Fptr)->curbuf] * |
| IOBUFLEN)); |
| nspace = IOBUFLEN - bufpos; |
|
|
| while (ntodo) |
| { |
| nwrite = minvalue(ntodo, nspace); |
|
|
| |
| memcpy((fptr->Fptr)->iobuffer + ((fptr->Fptr)->curbuf * IOBUFLEN) + bufpos, cptr, nwrite); |
| ntodo -= nwrite; |
| cptr += nwrite; |
| (fptr->Fptr)->bytepos += nwrite; |
| (fptr->Fptr)->dirty[(fptr->Fptr)->curbuf] = TRUE; |
|
|
| if (ntodo) |
| { |
| ffldrc(fptr, (long) ((fptr->Fptr)->bytepos / IOBUFLEN), IGNORE_EOF, status); |
| bufpos = 0; |
| nspace = IOBUFLEN; |
| } |
| } |
| } |
| return(*status); |
| } |
| |
| int ffpbytoff(fitsfile *fptr, |
| long gsize, |
| long ngroups, |
| long offset, |
| void *buffer, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| int bcurrent; |
| long ii, bufpos, nspace, nwrite, record; |
| char *cptr, *ioptr; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| if ((fptr->Fptr)->curbuf < 0) |
| { |
| ffldrc(fptr, (long) (((fptr->Fptr)->bytepos) / IOBUFLEN), REPORT_EOF, status); |
| } |
|
|
| cptr = (char *)buffer; |
| bcurrent = (fptr->Fptr)->curbuf; |
| record = (fptr->Fptr)->bufrecnum[bcurrent]; |
| bufpos = (long) ((fptr->Fptr)->bytepos - ((LONGLONG)record * IOBUFLEN)); |
| nspace = IOBUFLEN - bufpos; |
| ioptr = (fptr->Fptr)->iobuffer + (bcurrent * IOBUFLEN) + bufpos; |
|
|
| for (ii = 1; ii < ngroups; ii++) |
| { |
| |
| nwrite = minvalue(gsize, nspace); |
| memcpy(ioptr, cptr, nwrite); |
| cptr += nwrite; |
|
|
| if (nwrite < gsize) |
| { |
| (fptr->Fptr)->dirty[bcurrent] = TRUE; |
| record++; |
| ffldrc(fptr, record, IGNORE_EOF, status); |
| bcurrent = (fptr->Fptr)->curbuf; |
| ioptr = (fptr->Fptr)->iobuffer + (bcurrent * IOBUFLEN); |
|
|
| nwrite = gsize - nwrite; |
| memcpy(ioptr, cptr, nwrite); |
| cptr += nwrite; |
| ioptr += (offset + nwrite); |
| nspace = IOBUFLEN - offset - nwrite; |
| } |
| else |
| { |
| ioptr += (offset + nwrite); |
| nspace -= (offset + nwrite); |
| } |
|
|
| if (nspace <= 0) |
| { |
| (fptr->Fptr)->dirty[bcurrent] = TRUE; |
| record += ((IOBUFLEN - nspace) / IOBUFLEN); |
| ffldrc(fptr, record, IGNORE_EOF, status); |
| bcurrent = (fptr->Fptr)->curbuf; |
|
|
| bufpos = (-nspace) % IOBUFLEN; |
| nspace = IOBUFLEN - bufpos; |
| ioptr = (fptr->Fptr)->iobuffer + (bcurrent * IOBUFLEN) + bufpos; |
| } |
| } |
| |
| |
| nwrite = minvalue(gsize, nspace); |
| memcpy(ioptr, cptr, nwrite); |
| cptr += nwrite; |
|
|
| if (nwrite < gsize) |
| { |
| (fptr->Fptr)->dirty[bcurrent] = TRUE; |
| record++; |
| ffldrc(fptr, record, IGNORE_EOF, status); |
| bcurrent = (fptr->Fptr)->curbuf; |
| ioptr = (fptr->Fptr)->iobuffer + (bcurrent * IOBUFLEN); |
|
|
| nwrite = gsize - nwrite; |
| memcpy(ioptr, cptr, nwrite); |
| } |
|
|
| (fptr->Fptr)->dirty[bcurrent] = TRUE; |
| (fptr->Fptr)->bytepos = (fptr->Fptr)->bytepos + (ngroups * gsize) |
| + (ngroups - 1) * offset; |
| return(*status); |
| } |
| |
| int ffgbyt(fitsfile *fptr, |
| LONGLONG nbytes, |
| void *buffer, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| int ii; |
| LONGLONG filepos; |
| long recstart, recend, ntodo, bufpos, nspace, nread; |
| char *cptr; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
| cptr = (char *)buffer; |
|
|
| if (nbytes >= MINDIRECT) |
| { |
| |
| filepos = (fptr->Fptr)->bytepos; |
|
|
| |
| |
| |
|
|
| recstart = (long) (filepos / IOBUFLEN); |
| recend = (long) ((filepos + nbytes - 1) / IOBUFLEN); |
|
|
| for (ii = 0; ii < NIOBUF; ii++) |
| { |
| if ((fptr->Fptr)->dirty[ii] && |
| (fptr->Fptr)->bufrecnum[ii] >= recstart && (fptr->Fptr)->bufrecnum[ii] <= recend) |
| { |
| ffbfwt(fptr->Fptr, ii, status); |
| } |
| } |
|
|
| |
| if ((fptr->Fptr)->io_pos != filepos) |
| ffseek(fptr->Fptr, filepos); |
|
|
| ffread(fptr->Fptr, (long) nbytes, cptr, status); |
| (fptr->Fptr)->io_pos = filepos + nbytes; |
| } |
| else |
| { |
| |
|
|
| if ((fptr->Fptr)->curbuf < 0) |
| { |
| ffldrc(fptr, (long) (((fptr->Fptr)->bytepos) / IOBUFLEN), REPORT_EOF, status); |
| } |
|
|
| |
| bufpos = (long) ((fptr->Fptr)->bytepos - ((LONGLONG)(fptr->Fptr)->bufrecnum[(fptr->Fptr)->curbuf] * |
| IOBUFLEN)); |
| nspace = IOBUFLEN - bufpos; |
|
|
| ntodo = (long) nbytes; |
| while (ntodo) |
| { |
| nread = minvalue(ntodo, nspace); |
|
|
| |
| memcpy(cptr, (fptr->Fptr)->iobuffer + ((fptr->Fptr)->curbuf * IOBUFLEN) + bufpos, nread); |
| ntodo -= nread; |
| cptr += nread; |
| (fptr->Fptr)->bytepos += nread; |
|
|
| if (ntodo) |
| { |
| ffldrc(fptr, (long) ((fptr->Fptr)->bytepos / IOBUFLEN), REPORT_EOF, status); |
| bufpos = 0; |
| nspace = IOBUFLEN; |
| } |
| } |
| } |
|
|
| return(*status); |
| } |
| |
| int ffgbytoff(fitsfile *fptr, |
| long gsize, |
| long ngroups, |
| long offset, |
| void *buffer, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| int bcurrent; |
| long ii, bufpos, nspace, nread, record; |
| char *cptr, *ioptr; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| if ((fptr->Fptr)->curbuf < 0) |
| { |
| ffldrc(fptr, (long) (((fptr->Fptr)->bytepos) / IOBUFLEN), REPORT_EOF, status); |
| } |
|
|
| cptr = (char *)buffer; |
| bcurrent = (fptr->Fptr)->curbuf; |
| record = (fptr->Fptr)->bufrecnum[bcurrent]; |
| bufpos = (long) ((fptr->Fptr)->bytepos - ((LONGLONG)record * IOBUFLEN)); |
| nspace = IOBUFLEN - bufpos; |
| ioptr = (fptr->Fptr)->iobuffer + (bcurrent * IOBUFLEN) + bufpos; |
|
|
| for (ii = 1; ii < ngroups; ii++) |
| { |
| |
| nread = minvalue(gsize, nspace); |
| memcpy(cptr, ioptr, nread); |
| cptr += nread; |
|
|
| if (nread < gsize) |
| { |
| record++; |
| ffldrc(fptr, record, REPORT_EOF, status); |
| bcurrent = (fptr->Fptr)->curbuf; |
| ioptr = (fptr->Fptr)->iobuffer + (bcurrent * IOBUFLEN); |
|
|
| nread = gsize - nread; |
| memcpy(cptr, ioptr, nread); |
| cptr += nread; |
| ioptr += (offset + nread); |
| nspace = IOBUFLEN - offset - nread; |
| } |
| else |
| { |
| ioptr += (offset + nread); |
| nspace -= (offset + nread); |
| } |
|
|
| if (nspace <= 0 || nspace > IOBUFLEN) |
| { |
| if (nspace <= 0) |
| { |
| record += ((IOBUFLEN - nspace) / IOBUFLEN); |
| bufpos = (-nspace) % IOBUFLEN; |
| } |
| else |
| { |
| record -= ((nspace - 1 ) / IOBUFLEN); |
| bufpos = IOBUFLEN - (nspace % IOBUFLEN); |
| } |
|
|
| ffldrc(fptr, record, REPORT_EOF, status); |
| bcurrent = (fptr->Fptr)->curbuf; |
|
|
| nspace = IOBUFLEN - bufpos; |
| ioptr = (fptr->Fptr)->iobuffer + (bcurrent * IOBUFLEN) + bufpos; |
| } |
| } |
|
|
| |
| nread = minvalue(gsize, nspace); |
| memcpy(cptr, ioptr, nread); |
| cptr += nread; |
|
|
| if (nread < gsize) |
| { |
| record++; |
| ffldrc(fptr, record, REPORT_EOF, status); |
| bcurrent = (fptr->Fptr)->curbuf; |
| ioptr = (fptr->Fptr)->iobuffer + (bcurrent * IOBUFLEN); |
|
|
| nread = gsize - nread; |
| memcpy(cptr, ioptr, nread); |
| } |
|
|
| (fptr->Fptr)->bytepos = (fptr->Fptr)->bytepos + (ngroups * gsize) |
| + (ngroups - 1) * offset; |
| return(*status); |
| } |
| |
| int ffldrc(fitsfile *fptr, |
| long record, |
| int err_mode, |
| int *status) |
| { |
| |
| |
| |
| |
| |
| |
| int ibuff, nbuff; |
| LONGLONG rstart; |
|
|
| |
| |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| for (ibuff = NIOBUF - 1; ibuff >= 0; ibuff--) |
| { |
| nbuff = (fptr->Fptr)->ageindex[ibuff]; |
| if (record == (fptr->Fptr)->bufrecnum[nbuff]) { |
| goto updatebuf; |
| } |
| } |
|
|
| |
| rstart = (LONGLONG)record * IOBUFLEN; |
|
|
| if ( !err_mode && (rstart >= (fptr->Fptr)->logfilesize) ) |
| return(*status = END_OF_FILE); |
|
|
| if (ffwhbf(fptr, &nbuff) < 0) |
| return(*status = TOO_MANY_FILES); |
|
|
| if ((fptr->Fptr)->dirty[nbuff]) |
| ffbfwt(fptr->Fptr, nbuff, status); |
|
|
| if (rstart >= (fptr->Fptr)->filesize) |
| { |
| |
| if ((fptr->Fptr)->hdutype == ASCII_TBL) |
| memset((fptr->Fptr)->iobuffer + (nbuff * IOBUFLEN), 32, IOBUFLEN); |
| else |
| memset((fptr->Fptr)->iobuffer + (nbuff * IOBUFLEN), 0, IOBUFLEN); |
|
|
| (fptr->Fptr)->logfilesize = maxvalue((fptr->Fptr)->logfilesize, |
| rstart + IOBUFLEN); |
|
|
| (fptr->Fptr)->dirty[nbuff] = TRUE; |
| } |
| else |
| { |
| if ((fptr->Fptr)->io_pos != rstart) |
| ffseek(fptr->Fptr, rstart); |
|
|
| ffread(fptr->Fptr, IOBUFLEN, (fptr->Fptr)->iobuffer + (nbuff * IOBUFLEN), status); |
| (fptr->Fptr)->io_pos = rstart + IOBUFLEN; |
| } |
|
|
| (fptr->Fptr)->bufrecnum[nbuff] = record; |
|
|
| updatebuf: |
|
|
| (fptr->Fptr)->curbuf = nbuff; |
|
|
| if (ibuff < 0) |
| { |
| |
| for (ibuff = 0; ibuff < NIOBUF; ibuff++) |
| if ((fptr->Fptr)->ageindex[ibuff] == nbuff) |
| break; |
| } |
|
|
| |
| for (ibuff++; ibuff < NIOBUF; ibuff++) |
| (fptr->Fptr)->ageindex[ibuff - 1] = (fptr->Fptr)->ageindex[ibuff]; |
|
|
| (fptr->Fptr)->ageindex[NIOBUF - 1] = nbuff; |
| return(*status); |
| } |
| |
| int ffwhbf(fitsfile *fptr, |
| int *nbuff) |
| { |
| |
| |
| |
| return(*nbuff = (fptr->Fptr)->ageindex[0]); |
| } |
| |
| int ffflus(fitsfile *fptr, |
| int *status) |
| |
| |
| |
| |
| { |
| int hdunum, hdutype; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffghdn(fptr, &hdunum); |
|
|
| if (ffchdu(fptr,status) > 0) |
| ffpmsg("ffflus could not close the current HDU."); |
|
|
| ffflsh(fptr, FALSE, status); |
|
|
| if (ffgext(fptr, hdunum - 1, &hdutype, status) > 0) |
| ffpmsg("ffflus could not reopen the current HDU."); |
|
|
| return(*status); |
| } |
| |
| int ffflsh(fitsfile *fptr, |
| int clearbuf, |
| int *status) |
| { |
| |
| |
| |
| int ii; |
|
|
| |
| |
| |
| |
| |
| |
| for (ii = 0; ii < NIOBUF; ii++) |
| { |
| |
| if ((fptr->Fptr)->bufrecnum[ii] >= 0 &&(fptr->Fptr)->dirty[ii]) |
| ffbfwt(fptr->Fptr, ii, status); |
|
|
| if (clearbuf) |
| (fptr->Fptr)->bufrecnum[ii] = -1; |
| } |
|
|
| if (*status != READONLY_FILE) |
| ffflushx(fptr->Fptr); |
|
|
| return(*status); |
| } |
| |
| int ffbfeof(fitsfile *fptr, |
| int *status) |
| { |
| |
| |
| |
| int ii; |
|
|
| for (ii = 0; ii < NIOBUF; ii++) |
| { |
| if ( (LONGLONG) (fptr->Fptr)->bufrecnum[ii] * IOBUFLEN >= fptr->Fptr->filesize) |
| { |
| (fptr->Fptr)->bufrecnum[ii] = -1; |
| } |
| } |
|
|
| return(*status); |
| } |
| |
| int ffbfwt(FITSfile *Fptr, |
| int nbuff, |
| int *status) |
| { |
| |
| |
| |
| |
| |
| |
| int ii,ibuff; |
| long jj, irec, minrec, nloop; |
| LONGLONG filepos; |
|
|
| static char zeros[IOBUFLEN]; |
|
|
| if (!(Fptr->writemode) ) |
| { |
| ffpmsg("Error: trying to write to READONLY file."); |
| if (Fptr->driver == 8) { |
| ffpmsg("Cannot write to a GZIP or COMPRESS compressed file."); |
| } |
| Fptr->dirty[nbuff] = FALSE; |
| *status = READONLY_FILE; |
| return(*status); |
| } |
|
|
| filepos = (LONGLONG)Fptr->bufrecnum[nbuff] * IOBUFLEN; |
|
|
| if (filepos <= Fptr->filesize) |
| { |
| |
|
|
| |
| if (Fptr->io_pos != filepos) |
| ffseek(Fptr, filepos); |
|
|
| ffwrite(Fptr, IOBUFLEN, Fptr->iobuffer + (nbuff * IOBUFLEN), status); |
| Fptr->io_pos = filepos + IOBUFLEN; |
|
|
| if (filepos == Fptr->filesize) |
| Fptr->filesize += IOBUFLEN; |
|
|
| Fptr->dirty[nbuff] = FALSE; |
| } |
|
|
| else |
| |
| { |
| |
| if (Fptr->io_pos != Fptr->filesize) |
| ffseek(Fptr, Fptr->filesize); |
|
|
| ibuff = NIOBUF; |
| while(ibuff != nbuff) |
| { |
| minrec = (long) (Fptr->filesize / IOBUFLEN); |
|
|
| |
|
|
| irec = Fptr->bufrecnum[nbuff]; |
| ibuff = nbuff; |
|
|
| for (ii = 0; ii < NIOBUF; ii++) |
| { |
| if (Fptr->bufrecnum[ii] >= minrec && |
| Fptr->bufrecnum[ii] < irec) |
| { |
| irec = Fptr->bufrecnum[ii]; |
| ibuff = ii; |
| } |
| } |
|
|
| filepos = (LONGLONG)irec * IOBUFLEN; |
|
|
| |
| if (filepos > Fptr->filesize) |
| { |
| nloop = (long) ((filepos - (Fptr->filesize)) / IOBUFLEN); |
| for (jj = 0; jj < nloop && !(*status); jj++) |
| ffwrite(Fptr, IOBUFLEN, zeros, status); |
|
|
| |
| |
| |
| Fptr->filesize = filepos; |
| } |
|
|
| |
| ffwrite(Fptr, IOBUFLEN, Fptr->iobuffer + (ibuff * IOBUFLEN), status); |
| Fptr->dirty[ibuff] = FALSE; |
|
|
| Fptr->filesize += IOBUFLEN; |
| } |
|
|
| Fptr->io_pos = Fptr->filesize; |
| } |
|
|
| return(*status); |
| } |
| |
| int ffgrsz( fitsfile *fptr, |
| long *ndata, |
| int *status) |
| |
| |
| |
| |
| |
| |
| { |
| int typecode, bytesperpixel; |
|
|
| |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
| else if ((fptr->Fptr)->datastart == DATA_UNDEFINED) |
| if ( ffrdef(fptr, status) > 0) |
| return(*status); |
|
|
| if ((fptr->Fptr)->hdutype == IMAGE_HDU ) |
| { |
| |
| ffgtcl(fptr, 2, &typecode, NULL, NULL, status); |
| bytesperpixel = typecode / 10; |
| *ndata = ((NIOBUF - 1) * IOBUFLEN) / bytesperpixel; |
| } |
| else |
| { |
| *ndata = (long) (((NIOBUF - 1) * IOBUFLEN) / maxvalue(1, |
| (fptr->Fptr)->rowlength)); |
| *ndata = maxvalue(1, *ndata); |
| } |
|
|
| return(*status); |
| } |
| |
| int ffgtbb(fitsfile *fptr, |
| LONGLONG firstrow, |
| LONGLONG firstchar, |
| LONGLONG nchars, |
| unsigned char *values, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| LONGLONG bytepos, endrow; |
|
|
| if (*status > 0 || nchars <= 0) |
| return(*status); |
|
|
| else if (firstrow < 1) |
| return(*status=BAD_ROW_NUM); |
|
|
| else if (firstchar < 1) |
| return(*status=BAD_ELEM_NUM); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| |
| endrow = ((firstchar + nchars - 2) / (fptr->Fptr)->rowlength) + firstrow; |
| if (endrow > (fptr->Fptr)->numrows) |
| { |
| ffpmsg("attempt to read past end of table (ffgtbb)"); |
| return(*status=BAD_ROW_NUM); |
| } |
|
|
| |
| bytepos = (fptr->Fptr)->datastart + |
| ((fptr->Fptr)->rowlength * (firstrow - 1)) + |
| firstchar - 1; |
|
|
| ffmbyt(fptr, bytepos, REPORT_EOF, status); |
| ffgbyt(fptr, nchars, values, status); |
|
|
| return(*status); |
| } |
| |
| int ffgi1b(fitsfile *fptr, |
| LONGLONG byteloc, |
| long nvals, |
| long incre, |
| unsigned char *values, |
| int *status) |
| |
| |
| |
| |
| { |
| LONGLONG postemp; |
|
|
| if (incre == 1) |
| { |
| if (nvals < MINDIRECT) |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbyt(fptr, nvals, values, status); |
| } |
| else |
| { |
| postemp = (fptr->Fptr)->bytepos; |
| (fptr->Fptr)->bytepos = byteloc; |
| ffgbyt(fptr, nvals, values, status); |
| (fptr->Fptr)->bytepos = postemp; |
| } |
| } |
| else |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbytoff(fptr, 1, nvals, incre - 1, values, status); |
| } |
| return(*status); |
| } |
| |
| int ffgi2b(fitsfile *fptr, |
| LONGLONG byteloc, |
| long nvals, |
| long incre, |
| short *values, |
| int *status) |
| |
| |
| |
| |
| { |
| LONGLONG postemp; |
|
|
| if (incre == 2) |
| { |
| if (nvals * 2 < MINDIRECT) |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbyt(fptr, nvals * 2, values, status); |
| } |
| else |
| { |
| postemp = (fptr->Fptr)->bytepos; |
| (fptr->Fptr)->bytepos = byteloc; |
| ffgbyt(fptr, nvals * 2, values, status); |
| (fptr->Fptr)->bytepos = postemp; |
| } |
| } |
| else |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbytoff(fptr, 2, nvals, incre - 2, values, status); |
| } |
|
|
| #if BYTESWAPPED |
| ffswap2(values, nvals); |
| #endif |
|
|
| return(*status); |
| } |
| |
| int ffgi4b(fitsfile *fptr, |
| LONGLONG byteloc, |
| long nvals, |
| long incre, |
| INT32BIT *values, |
| int *status) |
| |
| |
| |
| |
| { |
| LONGLONG postemp; |
|
|
| if (incre == 4) |
| { |
| if (nvals * 4 < MINDIRECT) |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbyt(fptr, nvals * 4, values, status); |
| } |
| else |
| { |
| postemp = (fptr->Fptr)->bytepos; |
| (fptr->Fptr)->bytepos = byteloc; |
| ffgbyt(fptr, nvals * 4, values, status); |
| (fptr->Fptr)->bytepos = postemp; |
| } |
| } |
| else |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbytoff(fptr, 4, nvals, incre - 4, values, status); |
| } |
|
|
| #if BYTESWAPPED |
| ffswap4(values, nvals); |
| #endif |
|
|
| return(*status); |
| } |
| |
| int ffgi8b(fitsfile *fptr, |
| LONGLONG byteloc, |
| long nvals, |
| long incre, |
| long *values, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| LONGLONG postemp; |
|
|
| if (incre == 8) |
| { |
| if (nvals * 8 < MINDIRECT) |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbyt(fptr, nvals * 8, values, status); |
| } |
| else |
| { |
| postemp = (fptr->Fptr)->bytepos; |
| (fptr->Fptr)->bytepos = byteloc; |
| ffgbyt(fptr, nvals * 8, values, status); |
| (fptr->Fptr)->bytepos = postemp; |
| } |
| } |
| else |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbytoff(fptr, 8, nvals, incre - 8, values, status); |
| } |
|
|
| #if BYTESWAPPED |
| ffswap8((double *) values, nvals); |
| #endif |
|
|
| return(*status); |
| } |
| |
| int ffgr4b(fitsfile *fptr, |
| LONGLONG byteloc, |
| long nvals, |
| long incre, |
| float *values, |
| int *status) |
| |
| |
| |
| |
| { |
| LONGLONG postemp; |
|
|
| #if MACHINE == VAXVMS |
| long ii; |
|
|
| #elif (MACHINE == ALPHAVMS) && (FLOATTYPE == GFLOAT) |
| short *sptr; |
| long ii; |
|
|
| #endif |
|
|
|
|
| if (incre == 4) |
| { |
| if (nvals * 4 < MINDIRECT) |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbyt(fptr, nvals * 4, values, status); |
| } |
| else |
| { |
| postemp = (fptr->Fptr)->bytepos; |
| (fptr->Fptr)->bytepos = byteloc; |
| ffgbyt(fptr, nvals * 4, values, status); |
| (fptr->Fptr)->bytepos = postemp; |
| } |
| } |
| else |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbytoff(fptr, 4, nvals, incre - 4, values, status); |
| } |
|
|
|
|
| #if MACHINE == VAXVMS |
|
|
| ii = nvals; |
| ieevur(values, values, &ii); |
|
|
| #elif (MACHINE == ALPHAVMS) && (FLOATTYPE == GFLOAT) |
|
|
| ffswap2( (short *) values, nvals * 2); |
|
|
| |
| sptr = (short *) values; |
| for (ii = 0; ii < nvals; ii++, sptr += 2) |
| { |
| if (!fnan(*sptr) ) |
| values[ii] *= 4.0; |
| } |
|
|
| #elif BYTESWAPPED |
| ffswap4((INT32BIT *)values, nvals); |
| #endif |
|
|
| return(*status); |
| } |
| |
| int ffgr8b(fitsfile *fptr, |
| LONGLONG byteloc, |
| long nvals, |
| long incre, |
| double *values, |
| int *status) |
| |
| |
| |
| |
| { |
| LONGLONG postemp; |
|
|
| #if MACHINE == VAXVMS |
| long ii; |
|
|
| #elif (MACHINE == ALPHAVMS) && (FLOATTYPE == GFLOAT) |
| short *sptr; |
| long ii; |
|
|
| #endif |
|
|
| if (incre == 8) |
| { |
| if (nvals * 8 < MINDIRECT) |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbyt(fptr, nvals * 8, values, status); |
| } |
| else |
| { |
| postemp = (fptr->Fptr)->bytepos; |
| (fptr->Fptr)->bytepos = byteloc; |
| ffgbyt(fptr, nvals * 8, values, status); |
| (fptr->Fptr)->bytepos = postemp; |
| } |
| } |
| else |
| { |
| ffmbyt(fptr, byteloc, REPORT_EOF, status); |
| ffgbytoff(fptr, 8, nvals, incre - 8, values, status); |
| } |
|
|
| #if MACHINE == VAXVMS |
| ii = nvals; |
| ieevud(values, values, &ii); |
|
|
| #elif (MACHINE == ALPHAVMS) && (FLOATTYPE == GFLOAT) |
| ffswap2( (short *) values, nvals * 4); |
|
|
| |
| sptr = (short *) values; |
| for (ii = 0; ii < nvals; ii++, sptr += 4) |
| { |
| if (!dnan(*sptr) ) |
| values[ii] *= 4.0; |
| } |
|
|
| #elif BYTESWAPPED |
| ffswap8(values, nvals); |
| #endif |
|
|
| return(*status); |
| } |
| |
| int ffptbb(fitsfile *fptr, |
| LONGLONG firstrow, |
| LONGLONG firstchar, |
| LONGLONG nchars, |
| unsigned char *values, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| LONGLONG bytepos, endrow, nrows; |
| char message[FLEN_ERRMSG]; |
|
|
| if (*status > 0 || nchars <= 0) |
| return(*status); |
|
|
| else if (firstrow < 1) |
| return(*status=BAD_ROW_NUM); |
|
|
| else if (firstchar < 1) |
| return(*status=BAD_ELEM_NUM); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
| else if ((fptr->Fptr)->datastart < 0) |
| ffrdef(fptr, status); |
|
|
| endrow = ((firstchar + nchars - 2) / (fptr->Fptr)->rowlength) + firstrow; |
|
|
| |
| if (endrow > (fptr->Fptr)->numrows) |
| { |
| |
| |
| |
| if ( !((fptr->Fptr)->lasthdu) || (fptr->Fptr)->heapsize > 0) |
| { |
| nrows = endrow - ((fptr->Fptr)->numrows); |
|
|
| |
| if (ffirow(fptr, (fptr->Fptr)->numrows, nrows, status) > 0) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "ffptbb failed to add space for %.0f new rows in table.", |
| (double) nrows); |
| ffpmsg(message); |
| return(*status); |
| } |
| } |
| else |
| { |
| |
| (fptr->Fptr)->heapstart += |
| ((LONGLONG)(endrow - (fptr->Fptr)->numrows) * |
| (fptr->Fptr)->rowlength ); |
|
|
| (fptr->Fptr)->numrows = endrow; |
| } |
| } |
|
|
| |
| bytepos = (fptr->Fptr)->datastart + |
| ((fptr->Fptr)->rowlength * (firstrow - 1)) + |
| firstchar - 1; |
|
|
| ffmbyt(fptr, bytepos, IGNORE_EOF, status); |
| ffpbyt(fptr, nchars, values, status); |
|
|
| return(*status); |
| } |
| |
| int ffpi1b(fitsfile *fptr, |
| long nvals, |
| long incre, |
| unsigned char *values, |
| int *status) |
| |
| |
| |
| |
| { |
| if (incre == 1) |
|
|
| ffpbyt(fptr, nvals, values, status); |
|
|
| else |
|
|
| ffpbytoff(fptr, 1, nvals, incre - 1, values, status); |
|
|
| return(*status); |
| } |
| |
| int ffpi2b(fitsfile *fptr, |
| long nvals, |
| long incre, |
| short *values, |
| int *status) |
| |
| |
| |
| |
| { |
| #if BYTESWAPPED |
| ffswap2(values, nvals); |
| #endif |
|
|
| if (incre == 2) |
|
|
| ffpbyt(fptr, nvals * 2, values, status); |
|
|
| else |
|
|
| ffpbytoff(fptr, 2, nvals, incre - 2, values, status); |
|
|
| return(*status); |
| } |
| |
| int ffpi4b(fitsfile *fptr, |
| long nvals, |
| long incre, |
| INT32BIT *values, |
| int *status) |
| |
| |
| |
| |
| { |
| #if BYTESWAPPED |
| ffswap4(values, nvals); |
| #endif |
|
|
| if (incre == 4) |
|
|
| ffpbyt(fptr, nvals * 4, values, status); |
|
|
| else |
|
|
| ffpbytoff(fptr, 4, nvals, incre - 4, values, status); |
|
|
| return(*status); |
| } |
| |
| int ffpi8b(fitsfile *fptr, |
| long nvals, |
| long incre, |
| long *values, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| #if BYTESWAPPED |
| ffswap8((double *) values, nvals); |
| #endif |
|
|
| if (incre == 8) |
|
|
| ffpbyt(fptr, nvals * 8, values, status); |
|
|
| else |
|
|
| ffpbytoff(fptr, 8, nvals, incre - 8, values, status); |
|
|
| return(*status); |
| } |
| |
| int ffpr4b(fitsfile *fptr, |
| long nvals, |
| long incre, |
| float *values, |
| int *status) |
| |
| |
| |
| |
| { |
| #if MACHINE == VAXVMS |
| long ii; |
|
|
| ii = nvals; |
| ieevpr(values, values, &ii); |
|
|
| #elif (MACHINE == ALPHAVMS) && (FLOATTYPE == GFLOAT) |
| long ii; |
|
|
| |
| for (ii = 0; ii < nvals; ii++) |
| values[ii] *= 0.25; |
|
|
| ffswap2( (short *) values, nvals * 2); |
|
|
| #elif BYTESWAPPED |
| ffswap4((INT32BIT *) values, nvals); |
| #endif |
|
|
| if (incre == 4) |
|
|
| ffpbyt(fptr, nvals * 4, values, status); |
|
|
| else |
|
|
| ffpbytoff(fptr, 4, nvals, incre - 4, values, status); |
|
|
| return(*status); |
| } |
| |
| int ffpr8b(fitsfile *fptr, |
| long nvals, |
| long incre, |
| double *values, |
| int *status) |
| |
| |
| |
| |
| { |
| #if MACHINE == VAXVMS |
| long ii; |
|
|
| ii = nvals; |
| ieevpd(values, values, &ii); |
|
|
| #elif (MACHINE == ALPHAVMS) && (FLOATTYPE == GFLOAT) |
| long ii; |
|
|
| |
| for (ii = 0; ii < nvals; ii++) |
| values[ii] *= 0.25; |
|
|
| ffswap2( (short *) values, nvals * 4); |
|
|
| #elif BYTESWAPPED |
| ffswap8(values, nvals); |
| #endif |
|
|
| if (incre == 8) |
|
|
| ffpbyt(fptr, nvals * 8, values, status); |
|
|
| else |
|
|
| ffpbytoff(fptr, 8, nvals, incre - 8, values, status); |
|
|
| return(*status); |
| } |
|
|
|
|