| |
| |
|
|
| |
| |
| |
|
|
| #include <string.h> |
| #include <limits.h> |
| #include <stdlib.h> |
| #include <ctype.h> |
| |
| #include <stddef.h> |
| #include "fitsio2.h" |
|
|
| |
| int ffghsp(fitsfile *fptr, |
| int *nexist, |
| int *nmore, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| if (nexist) |
| *nexist = (int) (( ((fptr->Fptr)->headend) - |
| ((fptr->Fptr)->headstart[(fptr->Fptr)->curhdu]) ) / 80); |
|
|
| if ((fptr->Fptr)->datastart == DATA_UNDEFINED) |
| { |
| if (nmore) |
| *nmore = -1; |
| } |
| else |
| { |
| |
| if (nmore) |
| *nmore = (int) (((fptr->Fptr)->datastart - (fptr->Fptr)->headend) / 80 - 1); |
| } |
|
|
| return(*status); |
| } |
| |
| int ffghps(fitsfile *fptr, |
| int *nexist, |
| int *position, |
| int *status) |
| |
| |
| |
| |
| { |
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| if (nexist) |
| *nexist = (int) (( ((fptr->Fptr)->headend) - ((fptr->Fptr)->headstart[(fptr->Fptr)->curhdu]) ) / 80); |
|
|
| if (position) |
| *position = (int) (( ((fptr->Fptr)->nextkey) - ((fptr->Fptr)->headstart[(fptr->Fptr)->curhdu]) ) / 80 + 1); |
|
|
| return(*status); |
| } |
| |
| int ffnchk(fitsfile *fptr, |
| int *status) |
| |
| |
| |
| |
| |
| |
| { |
| long ii, nblock; |
| LONGLONG bytepos; |
| int length, nullpos; |
| char block[2881]; |
| |
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| if ((fptr->Fptr)->datastart == DATA_UNDEFINED) |
| { |
| return(0); |
| |
| } |
| else |
| { |
| |
| nblock = (long) (( (fptr->Fptr)->datastart - |
| (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu] ) / 2880); |
| } |
|
|
| bytepos = (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu]; |
| ffmbyt(fptr, bytepos, REPORT_EOF, status); |
|
|
| block[2880] = '\0'; |
| for (ii = 0; ii < nblock; ii++) |
| { |
| if (ffgbyt(fptr, 2880, block, status) > 0) |
| return(0); |
|
|
| length = strlen(block); |
| if (length != 2880) |
| { |
| nullpos = (ii * 2880) + length + 1; |
| return(nullpos); |
| } |
| } |
|
|
| return(0); |
| } |
| |
| int ffmaky(fitsfile *fptr, |
| int nrec, |
| int *status) |
| { |
| |
| |
| |
| |
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| (fptr->Fptr)->nextkey = (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu] + ( (nrec - 1) * 80); |
|
|
| return(*status); |
| } |
| |
| int ffmrky(fitsfile *fptr, |
| int nmove, |
| int *status) |
| { |
| |
| |
| |
| |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| (fptr->Fptr)->nextkey += (nmove * 80); |
|
|
| return(*status); |
| } |
| |
| int ffgnky(fitsfile *fptr, |
| char *card, |
| int *status) |
| |
| |
| |
| { |
| int jj, nrec; |
| LONGLONG bytepos, endhead; |
| char message[FLEN_ERRMSG]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| card[0] = '\0'; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| bytepos = (fptr->Fptr)->nextkey; |
| endhead = maxvalue( ((fptr->Fptr)->headend), ((fptr->Fptr)->datastart - 2880) ); |
|
|
| |
| if (bytepos > endhead || |
| bytepos < (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu] ) |
| { |
| nrec= (int) ((bytepos - (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu]) / 80 + 1); |
| snprintf(message, FLEN_ERRMSG,"Cannot get keyword number %d. It does not exist.", |
| nrec); |
| ffpmsg(message); |
| return(*status = KEY_OUT_BOUNDS); |
| } |
| |
| ffmbyt(fptr, bytepos, REPORT_EOF, status); |
|
|
| card[80] = '\0'; |
|
|
| if (ffgbyt(fptr, 80, card, status) <= 0) |
| { |
| (fptr->Fptr)->nextkey += 80; |
|
|
| |
| jj = 79; |
| while (jj >= 0 && card[jj] == ' ') |
| jj--; |
|
|
| card[jj + 1] = '\0'; |
| } |
| return(*status); |
| } |
| |
| int ffgnxk( fitsfile *fptr, |
| char **inclist, |
| int ninc, |
| char **exclist, |
| int nexc, |
| char *card, |
| int *status) |
| |
| |
| |
| |
| |
| |
| { |
| int casesn, match, exact, namelen; |
| long ii, jj; |
| char keybuf[FLEN_CARD], keyname[FLEN_KEYWORD]; |
|
|
| card[0] = '\0'; |
| if (*status > 0) |
| return(*status); |
|
|
| casesn = FALSE; |
|
|
| |
| while( ffgcrd(fptr, "*", keybuf, status) <= 0) |
| { |
| ffgknm(keybuf, keyname, &namelen, status); |
| |
| |
| for (ii = 0; ii < ninc; ii++) |
| { |
| ffcmps(inclist[ii], keyname, casesn, &match, &exact); |
| if (match) |
| { |
| |
| jj = -1; |
| while ( ++jj < nexc ) |
| { |
| ffcmps(exclist[jj], keyname, casesn, &match, &exact); |
| if (match) |
| break; |
| } |
|
|
| if (jj >= nexc) |
| { |
| |
| strcat(card, keybuf); |
| return(*status); |
| } |
| } |
| } |
| } |
| return(*status); |
| } |
| |
| int ffgky( fitsfile *fptr, |
| int datatype, |
| const char *keyname, |
| void *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| { |
| LONGLONG longval; |
| double doubleval; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (datatype == TSTRING) |
| { |
| ffgkys(fptr, keyname, (char *) value, comm, status); |
| } |
| else if (datatype == TBYTE) |
| { |
| if (ffgkyjj(fptr, keyname, &longval, comm, status) <= 0) |
| { |
| if (longval > UCHAR_MAX || longval < 0) |
| *status = NUM_OVERFLOW; |
| else |
| *(unsigned char *) value = (unsigned char) longval; |
| } |
| } |
| else if (datatype == TSBYTE) |
| { |
| if (ffgkyjj(fptr, keyname, &longval, comm, status) <= 0) |
| { |
| if (longval > 127 || longval < -128) |
| *status = NUM_OVERFLOW; |
| else |
| *(signed char *) value = (signed char) longval; |
| } |
| } |
| else if (datatype == TUSHORT) |
| { |
| if (ffgkyjj(fptr, keyname, &longval, comm, status) <= 0) |
| { |
| if (longval > (long) USHRT_MAX || longval < 0) |
| *status = NUM_OVERFLOW; |
| else |
| *(unsigned short *) value = (unsigned short) longval; |
| } |
| } |
| else if (datatype == TSHORT) |
| { |
| if (ffgkyjj(fptr, keyname, &longval, comm, status) <= 0) |
| { |
| if (longval > SHRT_MAX || longval < SHRT_MIN) |
| *status = NUM_OVERFLOW; |
| else |
| *(short *) value = (short) longval; |
| } |
| } |
| else if (datatype == TUINT) |
| { |
| if (ffgkyjj(fptr, keyname, &longval, comm, status) <= 0) |
| { |
| if (longval > (long) UINT_MAX || longval < 0) |
| *status = NUM_OVERFLOW; |
| else |
| *(unsigned int *) value = longval; |
| } |
| } |
| else if (datatype == TINT) |
| { |
| if (ffgkyjj(fptr, keyname, &longval, comm, status) <= 0) |
| { |
| if (longval > INT_MAX || longval < INT_MIN) |
| *status = NUM_OVERFLOW; |
| else |
| *(int *) value = longval; |
| } |
| } |
| else if (datatype == TLOGICAL) |
| { |
| ffgkyl(fptr, keyname, (int *) value, comm, status); |
| } |
| else if (datatype == TULONG) |
| { |
| if (ffgkyjj(fptr, keyname, &longval, comm, status) <= 0) |
| { |
| if (longval > ULONG_MAX || longval < 0) |
| *status = NUM_OVERFLOW; |
| else |
| *(unsigned long *) value = longval; |
| } |
| } |
| else if (datatype == TLONG) |
| { |
| if (ffgkyjj(fptr, keyname, &longval, comm, status) <= 0) |
| { |
| if (longval > LONG_MAX || longval < LONG_MIN) |
| *status = NUM_OVERFLOW; |
| else |
| *(int *) value = longval; |
| } |
| ffgkyj(fptr, keyname, (long *) value, comm, status); |
| } |
| else if (datatype == TULONGLONG) |
| { |
| ffgkyujj(fptr, keyname, (ULONGLONG *) value, comm, status); |
| } |
| else if (datatype == TLONGLONG) |
| { |
| ffgkyjj(fptr, keyname, (LONGLONG *) value, comm, status); |
| } |
| else if (datatype == TFLOAT) |
| { |
| ffgkye(fptr, keyname, (float *) value, comm, status); |
| } |
| else if (datatype == TDOUBLE) |
| { |
| ffgkyd(fptr, keyname, (double *) value, comm, status); |
| } |
| else if (datatype == TCOMPLEX) |
| { |
| ffgkyc(fptr, keyname, (float *) value, comm, status); |
| } |
| else if (datatype == TDBLCOMPLEX) |
| { |
| ffgkym(fptr, keyname, (double *) value, comm, status); |
| } |
| else |
| *status = BAD_DATATYPE; |
|
|
| return(*status); |
| } |
| |
| int ffgkey( fitsfile *fptr, |
| const char *keyname, |
| char *keyval, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| char card[FLEN_CARD]; |
|
|
| keyval[0] = '\0'; |
| if (comm) |
| comm[0] = '\0'; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (ffgcrd(fptr, keyname, card, status) > 0) |
| return(*status); |
|
|
| ffpsvc(card, keyval, comm, status); |
|
|
| return(*status); |
| } |
| |
| int ffgrec( fitsfile *fptr, |
| int nrec, |
| char *card, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| { |
| if (*status > 0) |
| return(*status); |
|
|
| if (nrec == 0) |
| { |
| ffmaky(fptr, 1, status); |
| if (card) |
| card[0] = '\0'; |
| } |
| else if (nrec > 0) |
| { |
| ffmaky(fptr, nrec, status); |
| ffgnky(fptr, card, status); |
| } |
|
|
| return(*status); |
| } |
| |
| int ffgcrd( fitsfile *fptr, |
| const char *name, |
| char *card, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| int nkeys, nextkey, ntodo, namelen, namelen_limit, namelenminus1, cardlen; |
| int ii = 0, jj, kk, wild, match, exact, hier = 0; |
| char keyname[FLEN_KEYWORD], cardname[FLEN_KEYWORD]; |
| char *ptr1, *ptr2, *gotstar; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| *keyname = '\0'; |
| |
| while (name[ii] == ' ') |
| ii++; |
|
|
| strncat(keyname, &name[ii], FLEN_KEYWORD - 1); |
|
|
| namelen = strlen(keyname); |
|
|
| while (namelen > 0 && keyname[namelen - 1] == ' ') |
| namelen--; |
|
|
| keyname[namelen] = '\0'; |
|
|
| for (ii=0; ii < namelen; ii++) |
| keyname[ii] = toupper(keyname[ii]); |
|
|
| if (FSTRNCMP("HIERARCH", keyname, 8) == 0) |
| { |
| if (namelen == 8) |
| { |
| |
| hier = 1; |
| } |
| else |
| { |
| |
| |
| ptr1 = keyname; |
| ptr2 = &keyname[8]; |
|
|
| while(*ptr2 == ' ') |
| ptr2++; |
|
|
| namelen = 0; |
| while(*ptr2) |
| { |
| *ptr1 = *ptr2; |
| ptr1++; |
| ptr2++; |
| namelen++; |
| } |
| *ptr1 = '\0'; |
| } |
| } |
|
|
| |
| |
|
|
| namelen_limit = namelen; |
| gotstar = 0; |
| if (namelen < 9 && |
| (strchr(keyname,'?') || (gotstar = strchr(keyname,'*')) || |
| strchr(keyname,'#')) ) |
| { |
| wild = 1; |
|
|
| |
| |
| |
| |
| if (gotstar) |
| namelen_limit -= 2; |
| } |
| else |
| wild = 0; |
|
|
| ffghps(fptr, &nkeys, &nextkey, status); |
|
|
| namelenminus1 = maxvalue(namelen - 1, 1); |
| ntodo = nkeys - nextkey + 1; |
| for (jj=0; jj < 2; jj++) |
| { |
| for (kk = 0; kk < ntodo; kk++) |
| { |
| ffgnky(fptr, card, status); |
|
|
| if (hier) |
| { |
| if (FSTRNCMP("HIERARCH", card, 8) == 0) |
| return(*status); |
| } |
| else |
| { |
| ffgknm(card, cardname, &cardlen, status); |
|
|
| if (cardlen >= namelen_limit) |
| { |
| |
| if (!( !wild && cardlen != namelen) ) |
| { |
| for (ii=0; ii < cardlen; ii++) |
| { |
| |
| if (cardname[ii] > 96) |
| { |
| |
| |
| |
| |
|
|
| cardname[ii] = toupper(cardname[ii]); |
| } |
| } |
|
|
| if (wild) |
| { |
| ffcmps(keyname, cardname, 1, &match, &exact); |
| if (match) |
| return(*status); |
| } |
| else if (keyname[namelenminus1] == cardname[namelenminus1]) |
| { |
| |
| |
| |
|
|
| if (FSTRNCMP(keyname, cardname, namelenminus1) == 0) |
| { |
| return(*status); |
| } |
| } |
| else if (namelen == 0 && cardlen == 0) |
| { |
| |
| return(*status); |
| } |
| } |
| } |
| } |
| } |
|
|
| if (wild || jj == 1) |
| break; |
|
|
| ffmaky(fptr, 1, status); |
| ntodo = nextkey - 1; |
| } |
|
|
| return(*status = KEY_NO_EXIST); |
| } |
| |
| int ffgstr( fitsfile *fptr, |
| const char *string, |
| char *card, |
| int *status) |
| |
| |
| |
| |
| |
| |
| { |
| int nkeys, nextkey, ntodo, stringlen; |
| int jj, kk; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| stringlen = strlen(string); |
| if (stringlen > 80) { |
| return(*status = KEY_NO_EXIST); |
| } |
|
|
| ffghps(fptr, &nkeys, &nextkey, status); |
| ntodo = nkeys - nextkey + 1; |
|
|
| for (jj=0; jj < 2; jj++) |
| { |
| for (kk = 0; kk < ntodo; kk++) |
| { |
| ffgnky(fptr, card, status); |
| if (strstr(card, string) != 0) { |
| return(*status); |
| } |
| } |
|
|
| ffmaky(fptr, 1, status); |
| ntodo = nextkey - 1; |
| } |
|
|
| return(*status = KEY_NO_EXIST); |
| } |
| |
| int ffgknm( char *card, |
| char *name, |
| int *length, |
| int *status) |
|
|
| |
| |
| |
| |
| { |
| char *ptr1, *ptr2; |
| int ii, namelength; |
|
|
| namelength = FLEN_KEYWORD - 1; |
| *name = '\0'; |
| *length = 0; |
|
|
| |
| if (FSTRNCMP(card, "HIERARCH ", 9) == 0) |
| { |
| ptr2 = strchr(card, '='); |
|
|
| if (!ptr2) |
| { |
| |
| strcat(name, "HIERARCH"); |
| *length = 8; |
| return(*status); |
| } |
|
|
| |
| ptr1 = &card[9]; |
| while (*ptr1 == ' ') |
| ptr1++; |
|
|
| strncat(name, ptr1, ptr2 - ptr1); |
| ii = ptr2 - ptr1; |
|
|
| while (ii > 0 && name[ii - 1] == ' ') |
| ii--; |
|
|
| name[ii] = '\0'; |
| *length = ii; |
| } |
| else |
| { |
| for (ii = 0; ii < namelength; ii++) |
| { |
| |
| if (*(card+ii) != ' ' && *(card+ii) != '=' && *(card+ii) !='\0') |
| { |
| *(name+ii) = *(card+ii); |
| } |
| else |
| { |
| name[ii] = '\0'; |
| *length = ii; |
| return(*status); |
| } |
| } |
|
|
| |
| name[namelength] = '\0'; |
| *length = namelength; |
| } |
|
|
| return(*status); |
| } |
| |
| int ffgunt( fitsfile *fptr, |
| const char *keyname, |
| char *unit, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE]; |
| char comm[FLEN_COMMENT]; |
| char *loc; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
|
|
| if (comm[0] == '[') |
| { |
| loc = strchr(comm, ']'); |
| if (loc) |
| *loc = '\0'; |
|
|
| strcpy(unit, &comm[1]); |
| } |
| else |
| unit[0] = '\0'; |
| |
| return(*status); |
| } |
| |
| int ffgkys( fitsfile *fptr, |
| const char *keyname, |
| char *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
| value[0] = '\0'; |
| ffc2s(valstring, value, status); |
| |
| return(*status); |
| } |
| |
| int ffgksl( fitsfile *fptr, |
| const char *keyname, |
| int *length, |
| int *status) |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE], value[FLEN_VALUE]; |
| int position, contin, len; |
| |
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, NULL, status); |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffghps(fptr, NULL, &position, status); |
| |
| if (!valstring[0]) { |
| *length = 0; |
| } else { |
| ffc2s(valstring, value, status); |
| *length = strlen(value); |
|
|
| |
| contin = 1; |
| while (contin) |
| { |
| len = strlen(value); |
|
|
| if (len && *(value+len-1) == '&') |
| { |
| ffgcnt(fptr, value, NULL, status); |
| if (*value) |
| { |
| *length += strlen(value) - 1; |
| } |
| else |
| { |
| contin = 0; |
| } |
| } |
| else |
| { |
| contin = 0; |
| } |
| } |
| } |
|
|
| ffmaky(fptr, position - 1, status); |
| |
| |
| |
| return(*status); |
| } |
| |
| int ffgkls( fitsfile *fptr, |
| const char *keyname, |
| char **value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE], nextcomm[FLEN_COMMENT]; |
| int contin, commspace = 0; |
| size_t len; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| *value = NULL; |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (comm) |
| { |
| |
| commspace = FLEN_COMMENT - strlen(comm) - 2; |
| } |
| |
| if (!valstring[0]) |
| { |
| *value = (char *) malloc(1); |
| **value = '\0'; |
| } |
| else |
| { |
| |
| *value = (char *) malloc(strlen(valstring) + 1); |
|
|
| ffc2s(valstring, *value, status); |
| len = strlen(*value); |
|
|
| |
| contin = 1; |
| while (contin) |
| { |
| if (len && *(*value+len-1) == '&') |
| { |
| ffgcnt(fptr, valstring, nextcomm, status); |
| if (*valstring) |
| { |
| *(*value+len-1) = '\0'; |
| len += strlen(valstring) - 1; |
| *value = (char *) realloc(*value, len + 1); |
| strcat(*value, valstring); |
| } |
| else |
| { |
| contin = 0; |
| } |
|
|
| |
| if ((commspace > 0) && (*nextcomm != 0)) |
| { |
| strncat(comm, " ", 1); |
| strncat(comm, nextcomm, commspace); |
| commspace = FLEN_COMMENT - strlen(comm) - 2; |
| } |
| } |
| else |
| { |
| contin = 0; |
| } |
| } |
| } |
| return(*status); |
| } |
| |
| int ffgsky( fitsfile *fptr, |
| const char *keyname, |
| int firstchar, |
| int maxchar, |
| |
| char *value, |
| int *valuelen, |
| |
| |
| |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE], nextcomm[FLEN_COMMENT]; |
| char *tempstring; |
| int contin, commspace = 0; |
| size_t len; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| tempstring = NULL; |
| *value = '\0'; |
| if (valuelen) *valuelen = 0; |
| |
| ffgkey(fptr, keyname, valstring, comm, status); |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (comm) |
| { |
| |
| commspace = FLEN_COMMENT - strlen(comm) - 2; |
| } |
| |
| if (!valstring[0]) |
| { |
| tempstring = (char *) malloc(1); |
| *tempstring = '\0'; |
| } |
| else |
| { |
| |
| tempstring = (char *) malloc(strlen(valstring) + 1); |
|
|
| ffc2s(valstring, tempstring, status); |
| len = strlen(tempstring); |
|
|
| |
| contin = 1; |
| while (contin && *status <= 0) |
| { |
| if (len && *(tempstring+len-1) == '&') |
| { |
| ffgcnt(fptr, valstring, nextcomm, status); |
| if (*valstring) |
| { |
| *(tempstring+len-1) = '\0'; |
| len += strlen(valstring) - 1; |
| tempstring = (char *) realloc(tempstring, len + 1); |
| strcat(tempstring, valstring); |
| } |
| else |
| { |
| contin = 0; |
| } |
|
|
| |
| if ((commspace > 0) && (*nextcomm != 0)) |
| { |
| strncat(comm, " ", 1); |
| strncat(comm, nextcomm, commspace); |
| commspace = FLEN_COMMENT - strlen(comm) - 2; |
| } |
| } |
| else |
| { |
| contin = 0; |
| } |
| } |
| } |
| |
| if (tempstring) |
| { |
| len = strlen(tempstring); |
| if (firstchar <= len) |
| strncat(value, tempstring + (firstchar - 1), maxchar); |
| free(tempstring); |
| if (valuelen) *valuelen = len; |
| } |
| |
| return(*status); |
| } |
| |
| int fffree( void *value, |
| int *status) |
| |
| |
| |
| |
| { |
| if (*status > 0) |
| return(*status); |
|
|
| if (value) |
| free(value); |
|
|
| return(*status); |
| } |
| |
| int ffgcnt( fitsfile *fptr, |
| char *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| int tstatus; |
| char card[FLEN_CARD], strval[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| tstatus = 0; |
| value[0] = '\0'; |
|
|
| if (ffgnky(fptr, card, &tstatus) > 0) |
| return(*status); |
|
|
| if (strncmp(card, "CONTINUE ", 10) == 0) |
| { |
| strncpy(card, "D2345678= ", 10); |
| ffpsvc(card, strval, comm, &tstatus); |
| ffc2s(strval, value, &tstatus); |
|
|
| if (tstatus) |
| value[0] = '\0'; |
| } |
| else |
| ffmrky(fptr, -1, status); |
|
|
| return(*status); |
| } |
| |
| int ffgkyl( fitsfile *fptr, |
| const char *keyname, |
| int *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
| ffc2l(valstring, value, status); |
|
|
| return(*status); |
| } |
| |
| int ffgkyj( fitsfile *fptr, |
| const char *keyname, |
| long *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
| ffc2i(valstring, value, status); |
|
|
| return(*status); |
| } |
| |
| int ffgkyjj( fitsfile *fptr, |
| const char *keyname, |
| LONGLONG *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
| ffc2j(valstring, value, status); |
|
|
| return(*status); |
| } |
| |
| int ffgkyujj( fitsfile *fptr, |
| const char *keyname, |
| ULONGLONG *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
| ffc2uj(valstring, value, status); |
|
|
| return(*status); |
| } |
| |
| int ffgkye( fitsfile *fptr, |
| const char *keyname, |
| float *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
| ffc2r(valstring, value, status); |
|
|
| return(*status); |
| } |
| |
| int ffgkyd( fitsfile *fptr, |
| const char *keyname, |
| double *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
| ffc2d(valstring, value, status); |
|
|
| return(*status); |
| } |
| |
| int ffgkyc( fitsfile *fptr, |
| const char *keyname, |
| float *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE], message[FLEN_ERRMSG]; |
| int len; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
|
|
| if (valstring[0] != '(' ) |
| { |
| snprintf(message, FLEN_ERRMSG, "keyword %s does not have a complex value (ffgkyc):", |
| keyname); |
| ffpmsg(message); |
| ffpmsg(valstring); |
| return(*status = BAD_C2F); |
| } |
|
|
| valstring[0] = ' '; |
| len = strcspn(valstring, ")" ); |
| valstring[len] = '\0'; |
|
|
| len = strcspn(valstring, ","); |
| valstring[len] = '\0'; |
|
|
| ffc2r(valstring, &value[0], status); |
| ffc2r(&valstring[len + 1], &value[1], status); |
| return(*status); |
| } |
| |
| int ffgkym( fitsfile *fptr, |
| const char *keyname, |
| double *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE], message[FLEN_ERRMSG]; |
| int len; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
|
|
| if (valstring[0] != '(' ) |
| { |
| snprintf(message, FLEN_ERRMSG, "keyword %s does not have a complex value (ffgkym):", |
| keyname); |
| ffpmsg(message); |
| ffpmsg(valstring); |
| return(*status = BAD_C2D); |
| } |
|
|
| valstring[0] = ' '; |
| len = strcspn(valstring, ")" ); |
| valstring[len] = '\0'; |
|
|
| len = strcspn(valstring, ","); |
| valstring[len] = '\0'; |
|
|
| ffc2d(valstring, &value[0], status); |
| ffc2d(&valstring[len + 1], &value[1], status); |
|
|
| return(*status); |
| } |
| |
| int ffgkyt( fitsfile *fptr, |
| const char *keyname, |
| long *ivalue, |
| double *fraction, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| { |
| char valstring[FLEN_VALUE]; |
| char *loc; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffgkey(fptr, keyname, valstring, comm, status); |
|
|
| |
| ffc2d(valstring, fraction, status); |
|
|
| *ivalue = (long) *fraction; |
|
|
| *fraction = *fraction - *ivalue; |
|
|
| |
| |
|
|
| loc = strchr(valstring, '.'); |
| if (loc) |
| { |
| if (!strchr(valstring, 'E') && !strchr(valstring, 'D')) |
| ffc2d(loc, fraction, status); |
| } |
|
|
| return(*status); |
| } |
| |
| int ffgkyn( fitsfile *fptr, |
| int nkey, |
| char *keyname, |
| char *value, |
| char *comm, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| char card[FLEN_CARD], sbuff[FLEN_CARD]; |
| int namelen; |
|
|
| keyname[0] = '\0'; |
| value[0] = '\0'; |
| if (comm) |
| comm[0] = '\0'; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (ffgrec(fptr, nkey, card, status) > 0 ) |
| return(*status); |
|
|
| ffgknm(card, keyname, &namelen, status); |
|
|
| if (ffpsvc(card, value, comm, status) > 0) |
| return(*status); |
|
|
| if (fftrec(keyname, status) > 0) |
| { |
| snprintf(sbuff, FLEN_CARD, "Name of keyword no. %d contains illegal character(s): %s", |
| nkey, keyname); |
| ffpmsg(sbuff); |
|
|
| if (nkey % 36 == 0) |
| ffpmsg(" (This may indicate a missing END keyword)."); |
| } |
| return(*status); |
| } |
| |
| int ffgkns( fitsfile *fptr, |
| const char *keyname, |
| int nstart, |
| int nmax, |
| char *value[], |
| int *nfound, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| int nend, lenroot, ii, nkeys, mkeys, tstatus, undefinedval; |
| long ival; |
| char keyroot[FLEN_KEYWORD], keyindex[8], card[FLEN_CARD]; |
| char svalue[FLEN_VALUE], comm[FLEN_COMMENT], *equalssign; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| *nfound = 0; |
| nend = nstart + nmax - 1; |
|
|
| keyroot[0] = '\0'; |
| strncat(keyroot, keyname, FLEN_KEYWORD - 1); |
| |
| lenroot = strlen(keyroot); |
| |
| if (lenroot == 0) |
| return(*status); |
|
|
| for (ii=0; ii < lenroot; ii++) |
| keyroot[ii] = toupper(keyroot[ii]); |
|
|
| ffghps(fptr, &nkeys, &mkeys, status); |
|
|
| undefinedval = FALSE; |
| for (ii=3; ii <= nkeys; ii++) |
| { |
| if (ffgrec(fptr, ii, card, status) > 0) |
| return(*status); |
|
|
| if (strncmp(keyroot, card, lenroot) == 0) |
| { |
| keyindex[0] = '\0'; |
| equalssign = strchr(card, '='); |
| if (equalssign == 0) continue; |
|
|
| if (equalssign - card - lenroot > 7) |
| { |
| return (*status=BAD_KEYCHAR); |
| } |
| strncat(keyindex, &card[lenroot], equalssign - card - lenroot); |
| tstatus = 0; |
| if (ffc2ii(keyindex, &ival, &tstatus) <= 0) |
| { |
| if (ival <= nend && ival >= nstart) |
| { |
| ffpsvc(card, svalue, comm, status); |
| ffc2s(svalue, value[ival-nstart], status); |
| if (ival - nstart + 1 > *nfound) |
| *nfound = ival - nstart + 1; |
|
|
| if (*status == VALUE_UNDEFINED) |
| { |
| undefinedval = TRUE; |
| *status = 0; |
| } |
| } |
| } |
| } |
| } |
| if (undefinedval && (*status <= 0) ) |
| *status = VALUE_UNDEFINED; |
|
|
| return(*status); |
| } |
| |
| int ffgknl( fitsfile *fptr, |
| const char *keyname, |
| int nstart, |
| int nmax, |
| int *value, |
| int *nfound, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| int nend, lenroot, ii, nkeys, mkeys, tstatus, undefinedval; |
| long ival; |
| char keyroot[FLEN_KEYWORD], keyindex[8], card[FLEN_CARD]; |
| char svalue[FLEN_VALUE], comm[FLEN_COMMENT], *equalssign; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| *nfound = 0; |
| nend = nstart + nmax - 1; |
|
|
| keyroot[0] = '\0'; |
| strncat(keyroot, keyname, FLEN_KEYWORD - 1); |
|
|
| lenroot = strlen(keyroot); |
| |
| if (lenroot == 0) |
| return(*status); |
| |
| for (ii=0; ii < lenroot; ii++) |
| keyroot[ii] = toupper(keyroot[ii]); |
|
|
| ffghps(fptr, &nkeys, &mkeys, status); |
|
|
| ffmaky(fptr, 3, status); |
|
|
| undefinedval = FALSE; |
| for (ii=3; ii <= nkeys; ii++) |
| { |
| if (ffgnky(fptr, card, status) > 0) |
| return(*status); |
|
|
| if (strncmp(keyroot, card, lenroot) == 0) |
| { |
| keyindex[0] = '\0'; |
| equalssign = strchr(card, '='); |
| if (equalssign == 0) continue; |
|
|
| if (equalssign - card - lenroot > 7) |
| { |
| return (*status=BAD_KEYCHAR); |
| } |
| strncat(keyindex, &card[lenroot], equalssign - card - lenroot); |
|
|
| tstatus = 0; |
| if (ffc2ii(keyindex, &ival, &tstatus) <= 0) |
| { |
| if (ival <= nend && ival >= nstart) |
| { |
| ffpsvc(card, svalue, comm, status); |
| ffc2l(svalue, &value[ival-nstart], status); |
| if (ival - nstart + 1 > *nfound) |
| *nfound = ival - nstart + 1; |
|
|
| if (*status == VALUE_UNDEFINED) |
| { |
| undefinedval = TRUE; |
| *status = 0; |
| } |
| } |
| } |
| } |
| } |
| if (undefinedval && (*status <= 0) ) |
| *status = VALUE_UNDEFINED; |
|
|
| return(*status); |
| } |
| |
| int ffgknj( fitsfile *fptr, |
| const char *keyname, |
| int nstart, |
| int nmax, |
| long *value, |
| int *nfound, |
| int *status) |
| |
| |
| |
| |
| { |
| int nend, lenroot, ii, nkeys, mkeys, tstatus, undefinedval; |
| long ival; |
| char keyroot[FLEN_KEYWORD], keyindex[8], card[FLEN_CARD]; |
| char svalue[FLEN_VALUE], comm[FLEN_COMMENT], *equalssign; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| *nfound = 0; |
| nend = nstart + nmax - 1; |
|
|
| keyroot[0] = '\0'; |
| strncat(keyroot, keyname, FLEN_KEYWORD - 1); |
|
|
| lenroot = strlen(keyroot); |
| |
| if (lenroot == 0) |
| return(*status); |
| |
| for (ii=0; ii < lenroot; ii++) |
| keyroot[ii] = toupper(keyroot[ii]); |
|
|
| ffghps(fptr, &nkeys, &mkeys, status); |
|
|
| ffmaky(fptr, 3, status); |
|
|
| undefinedval = FALSE; |
| for (ii=3; ii <= nkeys; ii++) |
| { |
| if (ffgnky(fptr, card, status) > 0) |
| return(*status); |
|
|
| if (strncmp(keyroot, card, lenroot) == 0) |
| { |
| keyindex[0] = '\0'; |
| equalssign = strchr(card, '='); |
| if (equalssign == 0) continue; |
|
|
| if (equalssign - card - lenroot > 7) |
| { |
| return (*status=BAD_KEYCHAR); |
| } |
| strncat(keyindex, &card[lenroot], equalssign - card - lenroot); |
|
|
| tstatus = 0; |
| if (ffc2ii(keyindex, &ival, &tstatus) <= 0) |
| { |
| if (ival <= nend && ival >= nstart) |
| { |
| ffpsvc(card, svalue, comm, status); |
| ffc2i(svalue, &value[ival-nstart], status); |
| if (ival - nstart + 1 > *nfound) |
| *nfound = ival - nstart + 1; |
|
|
| if (*status == VALUE_UNDEFINED) |
| { |
| undefinedval = TRUE; |
| *status = 0; |
| } |
| } |
| } |
| } |
| } |
| if (undefinedval && (*status <= 0) ) |
| *status = VALUE_UNDEFINED; |
|
|
| return(*status); |
| } |
| |
| int ffgknjj( fitsfile *fptr, |
| const char *keyname, |
| int nstart, |
| int nmax, |
| LONGLONG *value, |
| int *nfound, |
| int *status) |
| |
| |
| |
| |
| { |
| int nend, lenroot, ii, nkeys, mkeys, tstatus, undefinedval; |
| long ival; |
| char keyroot[FLEN_KEYWORD], keyindex[8], card[FLEN_CARD]; |
| char svalue[FLEN_VALUE], comm[FLEN_COMMENT], *equalssign; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| *nfound = 0; |
| nend = nstart + nmax - 1; |
|
|
| keyroot[0] = '\0'; |
| strncat(keyroot, keyname, FLEN_KEYWORD - 1); |
|
|
| lenroot = strlen(keyroot); |
| |
| if (lenroot == 0) |
| return(*status); |
|
|
| for (ii=0; ii < lenroot; ii++) |
| keyroot[ii] = toupper(keyroot[ii]); |
|
|
| ffghps(fptr, &nkeys, &mkeys, status); |
|
|
| ffmaky(fptr, 3, status); |
|
|
| undefinedval = FALSE; |
| for (ii=3; ii <= nkeys; ii++) |
| { |
| if (ffgnky(fptr, card, status) > 0) |
| return(*status); |
|
|
| if (strncmp(keyroot, card, lenroot) == 0) |
| { |
| keyindex[0] = '\0'; |
| equalssign = strchr(card, '='); |
| if (equalssign == 0) continue; |
|
|
| if (equalssign - card - lenroot > 7) |
| { |
| return (*status=BAD_KEYCHAR); |
| } |
| strncat(keyindex, &card[lenroot], equalssign - card - lenroot); |
|
|
| tstatus = 0; |
| if (ffc2ii(keyindex, &ival, &tstatus) <= 0) |
| { |
| if (ival <= nend && ival >= nstart) |
| { |
| ffpsvc(card, svalue, comm, status); |
| ffc2j(svalue, &value[ival-nstart], status); |
| if (ival - nstart + 1 > *nfound) |
| *nfound = ival - nstart + 1; |
|
|
| if (*status == VALUE_UNDEFINED) |
| { |
| undefinedval = TRUE; |
| *status = 0; |
| } |
| } |
| } |
| } |
| } |
| if (undefinedval && (*status <= 0) ) |
| *status = VALUE_UNDEFINED; |
|
|
| return(*status); |
| } |
| |
| int ffgkne( fitsfile *fptr, |
| const char *keyname, |
| int nstart, |
| int nmax, |
| float *value, |
| int *nfound, |
| int *status) |
| |
| |
| |
| |
| { |
| int nend, lenroot, ii, nkeys, mkeys, tstatus, undefinedval; |
| long ival; |
| char keyroot[FLEN_KEYWORD], keyindex[8], card[FLEN_CARD]; |
| char svalue[FLEN_VALUE], comm[FLEN_COMMENT], *equalssign; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| *nfound = 0; |
| nend = nstart + nmax - 1; |
|
|
| keyroot[0] = '\0'; |
| strncat(keyroot, keyname, FLEN_KEYWORD - 1); |
|
|
| lenroot = strlen(keyroot); |
| |
| if (lenroot == 0) |
| return(*status); |
|
|
| for (ii=0; ii < lenroot; ii++) |
| keyroot[ii] = toupper(keyroot[ii]); |
|
|
| ffghps(fptr, &nkeys, &mkeys, status); |
|
|
| ffmaky(fptr, 3, status); |
|
|
| undefinedval = FALSE; |
| for (ii=3; ii <= nkeys; ii++) |
| { |
| if (ffgnky(fptr, card, status) > 0) |
| return(*status); |
|
|
| if (strncmp(keyroot, card, lenroot) == 0) |
| { |
| keyindex[0] = '\0'; |
| equalssign = strchr(card, '='); |
| if (equalssign == 0) continue; |
|
|
| if (equalssign - card - lenroot > 7) |
| { |
| return (*status=BAD_KEYCHAR); |
| } |
| strncat(keyindex, &card[lenroot], equalssign - card - lenroot); |
|
|
| tstatus = 0; |
| if (ffc2ii(keyindex, &ival, &tstatus) <= 0) |
| { |
| if (ival <= nend && ival >= nstart) |
| { |
| ffpsvc(card, svalue, comm, status); |
| ffc2r(svalue, &value[ival-nstart], status); |
| if (ival - nstart + 1 > *nfound) |
| *nfound = ival - nstart + 1; |
|
|
| if (*status == VALUE_UNDEFINED) |
| { |
| undefinedval = TRUE; |
| *status = 0; |
| } |
| } |
| } |
| } |
| } |
| if (undefinedval && (*status <= 0) ) |
| *status = VALUE_UNDEFINED; |
|
|
| return(*status); |
| } |
| |
| int ffgknd( fitsfile *fptr, |
| const char *keyname, |
| int nstart, |
| int nmax, |
| double *value, |
| int *nfound, |
| int *status) |
| |
| |
| |
| |
| { |
| int nend, lenroot, ii, nkeys, mkeys, tstatus, undefinedval; |
| long ival; |
| char keyroot[FLEN_KEYWORD], keyindex[8], card[FLEN_CARD]; |
| char svalue[FLEN_VALUE], comm[FLEN_COMMENT], *equalssign; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| *nfound = 0; |
| nend = nstart + nmax - 1; |
|
|
| keyroot[0] = '\0'; |
| strncat(keyroot, keyname, FLEN_KEYWORD - 1); |
|
|
| lenroot = strlen(keyroot); |
|
|
| if (lenroot == 0) |
| return(*status); |
|
|
| for (ii=0; ii < lenroot; ii++) |
| keyroot[ii] = toupper(keyroot[ii]); |
|
|
| ffghps(fptr, &nkeys, &mkeys, status); |
|
|
| ffmaky(fptr, 3, status); |
|
|
| undefinedval = FALSE; |
| for (ii=3; ii <= nkeys; ii++) |
| { |
| if (ffgnky(fptr, card, status) > 0) |
| return(*status); |
| if (strncmp(keyroot, card, lenroot) == 0) |
| { |
| keyindex[0] = '\0'; |
| equalssign = strchr(card, '='); |
| if (equalssign == 0) continue; |
|
|
| if (equalssign - card - lenroot > 7) |
| { |
| return (*status=BAD_KEYCHAR); |
| } |
| strncat(keyindex, &card[lenroot], equalssign - card - lenroot); |
| tstatus = 0; |
| if (ffc2ii(keyindex, &ival, &tstatus) <= 0) |
| { |
| if (ival <= nend && ival >= nstart) |
| { |
| ffpsvc(card, svalue, comm, status); |
| ffc2d(svalue, &value[ival-nstart], status); |
| if (ival - nstart + 1 > *nfound) |
| *nfound = ival - nstart + 1; |
|
|
| if (*status == VALUE_UNDEFINED) |
| { |
| undefinedval = TRUE; |
| *status = 0; |
| } |
| } |
| } |
| } |
| } |
| if (undefinedval && (*status <= 0) ) |
| *status = VALUE_UNDEFINED; |
|
|
| return(*status); |
| } |
| |
| int ffgtdm(fitsfile *fptr, |
| int colnum, |
| int maxdim, |
| int *naxis, |
| long naxes[], |
| int *status) |
| |
| |
| |
| { |
| int tstatus = 0; |
| char keyname[FLEN_KEYWORD], tdimstr[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffkeyn("TDIM", colnum, keyname, status); |
|
|
| ffgkys(fptr, keyname, tdimstr, NULL, &tstatus); |
|
|
| ffdtdm(fptr, tdimstr, colnum, maxdim,naxis, naxes, status); |
|
|
| return(*status); |
| } |
| |
| int ffgtdmll(fitsfile *fptr, |
| int colnum, |
| int maxdim, |
| int *naxis, |
| LONGLONG naxes[], |
| int *status) |
| |
| |
| |
| { |
| int tstatus = 0; |
| char keyname[FLEN_KEYWORD], tdimstr[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| ffkeyn("TDIM", colnum, keyname, status); |
|
|
| ffgkys(fptr, keyname, tdimstr, NULL, &tstatus); |
|
|
| ffdtdmll(fptr, tdimstr, colnum, maxdim,naxis, naxes, status); |
|
|
| return(*status); |
| } |
| |
| int ffdtdm(fitsfile *fptr, |
| char *tdimstr, |
| int colnum, |
| int maxdim, |
| int *naxis, |
| long naxes[], |
| int *status) |
| |
| |
| |
| |
| |
| { |
| long dimsize, totalpix = 1; |
| char *loc, *lastloc, message[FLEN_ERRMSG]; |
| tcolumn *colptr = 0; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (colnum != 0) { |
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| if (colnum < 1 || colnum > (fptr->Fptr)->tfield) |
| return(*status = BAD_COL_NUM); |
|
|
| colptr = (fptr->Fptr)->tableptr; |
| colptr += (colnum - 1); |
|
|
| if (!tdimstr[0]) |
| { |
| *naxis = 1; |
| if (maxdim > 0) |
| naxes[0] = (long) colptr->trepeat; |
|
|
| return(*status); |
| } |
| } |
|
|
| *naxis = 0; |
|
|
| loc = strchr(tdimstr, '(' ); |
| if (!loc) |
| { |
| snprintf(message, FLEN_ERRMSG, "Illegal dimensions format: %s", tdimstr); |
| return(*status = BAD_TDIM); |
| } |
|
|
| while (loc) |
| { |
| loc++; |
| dimsize = strtol(loc, &loc, 10); |
| if (*naxis < maxdim) |
| naxes[*naxis] = dimsize; |
|
|
| if (dimsize < 0) |
| { |
| ffpmsg("one or more dimension are less than 0 (ffdtdm)"); |
| ffpmsg(tdimstr); |
| return(*status = BAD_TDIM); |
| } |
|
|
| totalpix *= dimsize; |
| (*naxis)++; |
| lastloc = loc; |
| loc = strchr(loc, ','); |
| } |
|
|
| loc = strchr(lastloc, ')' ); |
| if (!loc) |
| { |
| snprintf(message, FLEN_ERRMSG, "Illegal dimensions format: %s", tdimstr); |
| return(*status = BAD_TDIM); |
| } |
|
|
| if (colnum != 0) { |
| if ((colptr->tdatatype > 0) && ((long) colptr->trepeat != totalpix)) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "column vector length, %ld, does not equal TDIMn array size, %ld", |
| (long) colptr->trepeat, totalpix); |
| ffpmsg(message); |
| ffpmsg(tdimstr); |
| return(*status = BAD_TDIM); |
| } |
| } |
| return(*status); |
| } |
| |
| int ffdtdmll(fitsfile *fptr, |
| char *tdimstr, |
| int colnum, |
| int maxdim, |
| int *naxis, |
| LONGLONG naxes[], |
| int *status) |
| |
| |
| |
| |
| { |
| LONGLONG dimsize; |
| LONGLONG totalpix = 1; |
| char *loc, *lastloc, message[FLEN_ERRMSG]; |
| tcolumn *colptr; |
| double doublesize; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| if (colnum < 1 || colnum > (fptr->Fptr)->tfield) |
| return(*status = BAD_COL_NUM); |
|
|
| colptr = (fptr->Fptr)->tableptr; |
| colptr += (colnum - 1); |
|
|
| if (!tdimstr[0]) |
| { |
| *naxis = 1; |
| if (maxdim > 0) |
| naxes[0] = colptr->trepeat; |
| } |
| else |
| { |
| *naxis = 0; |
|
|
| loc = strchr(tdimstr, '(' ); |
| if (!loc) |
| { |
| snprintf(message, FLEN_ERRMSG, "Illegal TDIM keyword value: %s", tdimstr); |
| return(*status = BAD_TDIM); |
| } |
|
|
| while (loc) |
| { |
| loc++; |
|
|
| |
| |
| |
|
|
| doublesize = strtod(loc, &loc); |
| dimsize = (LONGLONG) (doublesize + 0.1); |
|
|
| if (*naxis < maxdim) |
| naxes[*naxis] = dimsize; |
|
|
| if (dimsize < 0) |
| { |
| ffpmsg("one or more TDIM values are less than 0 (ffdtdm)"); |
| ffpmsg(tdimstr); |
| return(*status = BAD_TDIM); |
| } |
|
|
| totalpix *= dimsize; |
| (*naxis)++; |
| lastloc = loc; |
| loc = strchr(loc, ','); |
| } |
|
|
| loc = strchr(lastloc, ')' ); |
| if (!loc) |
| { |
| snprintf(message, FLEN_ERRMSG, "Illegal TDIM keyword value: %s", tdimstr); |
| return(*status = BAD_TDIM); |
| } |
|
|
| if ((colptr->tdatatype > 0) && (colptr->trepeat != totalpix)) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "column vector length, %.0f, does not equal TDIMn array size, %.0f", |
| (double) (colptr->trepeat), (double) totalpix); |
| ffpmsg(message); |
| ffpmsg(tdimstr); |
| return(*status = BAD_TDIM); |
| } |
| } |
| return(*status); |
| } |
| |
| int ffghpr(fitsfile *fptr, |
| int maxdim, |
| int *simple, |
| int *bitpix, |
| int *naxis, |
| long naxes[], |
| long *pcount, |
| long *gcount, |
| int *extend, |
| int *status) |
| |
| |
| |
| |
| |
| |
| { |
| int idummy, ii; |
| LONGLONG lldummy; |
| double ddummy; |
| LONGLONG tnaxes[99]; |
|
|
| ffgphd(fptr, maxdim, simple, bitpix, naxis, tnaxes, pcount, gcount, extend, |
| &ddummy, &ddummy, &lldummy, &idummy, status); |
| |
| if (naxis && naxes) { |
| for (ii = 0; (ii < *naxis) && (ii < maxdim); ii++) |
| naxes[ii] = (long) tnaxes[ii]; |
| } else if (naxes) { |
| for (ii = 0; ii < maxdim; ii++) |
| naxes[ii] = (long) tnaxes[ii]; |
| } |
|
|
| return(*status); |
| } |
| |
| int ffghprll(fitsfile *fptr, |
| int maxdim, |
| int *simple, |
| int *bitpix, |
| int *naxis, |
| LONGLONG naxes[], |
| long *pcount, |
| long *gcount, |
| int *extend, |
| int *status) |
| |
| |
| |
| |
| |
| |
| { |
| int idummy; |
| LONGLONG lldummy; |
| double ddummy; |
|
|
| ffgphd(fptr, maxdim, simple, bitpix, naxis, naxes, pcount, gcount, extend, |
| &ddummy, &ddummy, &lldummy, &idummy, status); |
|
|
| return(*status); |
| } |
| |
| int ffghtb(fitsfile *fptr, |
| int maxfield, |
| long *naxis1, |
| long *naxis2, |
| int *tfields, |
| char **ttype, |
| long *tbcol, |
| char **tform, |
| char **tunit, |
| char *extnm, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| int ii, maxf, nfound, tstatus; |
| long fields; |
| char name[FLEN_KEYWORD], value[FLEN_VALUE], comm[FLEN_COMMENT]; |
| char xtension[FLEN_VALUE], message[FLEN_ERRMSG]; |
| LONGLONG llnaxis1, llnaxis2, pcount; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| |
| ffgkyn(fptr, 1, name, value, comm, status); |
|
|
| if (!strcmp(name, "XTENSION")) |
| { |
| if (ffc2s(value, xtension, status) > 0) |
| { |
| ffpmsg("Bad value string for XTENSION keyword:"); |
| ffpmsg(value); |
| return(*status); |
| } |
|
|
| |
| |
| if ( (value[0] != '\'') || |
| ( strcmp(xtension, "TABLE") ) ) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "This is not a TABLE extension: %s", value); |
| ffpmsg(message); |
| return(*status = NOT_ATABLE); |
| } |
| } |
|
|
| else |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "First keyword of the extension is not XTENSION: %s", name); |
| ffpmsg(message); |
| return(*status = NO_XTENSION); |
| } |
|
|
| if (ffgttb(fptr, &llnaxis1, &llnaxis2, &pcount, &fields, status) > 0) |
| return(*status); |
|
|
| if (naxis1) |
| *naxis1 = (long) llnaxis1; |
|
|
| if (naxis2) |
| *naxis2 = (long) llnaxis2; |
|
|
| if (pcount != 0) |
| { |
| snprintf(message, FLEN_ERRMSG, "PCOUNT = %.0f is illegal in ASCII table; must = 0", |
| (double) pcount); |
| ffpmsg(message); |
| return(*status = BAD_PCOUNT); |
| } |
|
|
| if (tfields) |
| *tfields = fields; |
|
|
| if (maxfield < 0) |
| maxf = fields; |
| else |
| maxf = minvalue(maxfield, fields); |
|
|
| if (maxf > 0) |
| { |
| for (ii = 0; ii < maxf; ii++) |
| { |
| if (ttype) |
| *ttype[ii] = '\0'; |
|
|
| if (tunit) |
| *tunit[ii] = '\0'; |
| } |
|
|
| |
| if (ttype) |
| ffgkns(fptr, "TTYPE", 1, maxf, ttype, &nfound, status); |
|
|
| if (tunit) |
| ffgkns(fptr, "TUNIT", 1, maxf, tunit, &nfound, status); |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (tbcol) |
| { |
| ffgknj(fptr, "TBCOL", 1, maxf, tbcol, &nfound, status); |
|
|
| if (*status > 0 || nfound != maxf) |
| { |
| ffpmsg( |
| "Required TBCOL keyword(s) not found in ASCII table header (ffghtb)."); |
| return(*status = NO_TBCOL); |
| } |
| } |
|
|
| if (tform) |
| { |
| ffgkns(fptr, "TFORM", 1, maxf, tform, &nfound, status); |
|
|
| if (*status > 0 || nfound != maxf) |
| { |
| ffpmsg( |
| "Required TFORM keyword(s) not found in ASCII table header (ffghtb)."); |
| return(*status = NO_TFORM); |
| } |
| } |
| } |
|
|
| if (extnm) |
| { |
| extnm[0] = '\0'; |
|
|
| tstatus = *status; |
| ffgkys(fptr, "EXTNAME", extnm, comm, status); |
|
|
| if (*status == KEY_NO_EXIST) |
| *status = tstatus; |
| } |
|
|
| return(*status); |
| } |
| |
| int ffghtbll(fitsfile *fptr, |
| int maxfield, |
| LONGLONG *naxis1, |
| LONGLONG *naxis2, |
| int *tfields, |
| char **ttype, |
| LONGLONG *tbcol, |
| char **tform, |
| char **tunit, |
| char *extnm, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| int ii, maxf, nfound, tstatus; |
| long fields; |
| char name[FLEN_KEYWORD], value[FLEN_VALUE], comm[FLEN_COMMENT]; |
| char xtension[FLEN_VALUE], message[FLEN_ERRMSG]; |
| LONGLONG llnaxis1, llnaxis2, pcount; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| |
| ffgkyn(fptr, 1, name, value, comm, status); |
|
|
| if (!strcmp(name, "XTENSION")) |
| { |
| if (ffc2s(value, xtension, status) > 0) |
| { |
| ffpmsg("Bad value string for XTENSION keyword:"); |
| ffpmsg(value); |
| return(*status); |
| } |
|
|
| |
| |
| if ( (value[0] != '\'') || |
| ( strcmp(xtension, "TABLE") ) ) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "This is not a TABLE extension: %s", value); |
| ffpmsg(message); |
| return(*status = NOT_ATABLE); |
| } |
| } |
|
|
| else |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "First keyword of the extension is not XTENSION: %s", name); |
| ffpmsg(message); |
| return(*status = NO_XTENSION); |
| } |
|
|
| if (ffgttb(fptr, &llnaxis1, &llnaxis2, &pcount, &fields, status) > 0) |
| return(*status); |
|
|
| if (naxis1) |
| *naxis1 = llnaxis1; |
|
|
| if (naxis2) |
| *naxis2 = llnaxis2; |
|
|
| if (pcount != 0) |
| { |
| snprintf(message, FLEN_ERRMSG, "PCOUNT = %.0f is illegal in ASCII table; must = 0", |
| (double) pcount); |
| ffpmsg(message); |
| return(*status = BAD_PCOUNT); |
| } |
|
|
| if (tfields) |
| *tfields = fields; |
|
|
| if (maxfield < 0) |
| maxf = fields; |
| else |
| maxf = minvalue(maxfield, fields); |
|
|
| if (maxf > 0) |
| { |
| for (ii = 0; ii < maxf; ii++) |
| { |
| if (ttype) |
| *ttype[ii] = '\0'; |
|
|
| if (tunit) |
| *tunit[ii] = '\0'; |
| } |
|
|
| |
| if (ttype) |
| ffgkns(fptr, "TTYPE", 1, maxf, ttype, &nfound, status); |
|
|
| if (tunit) |
| ffgkns(fptr, "TUNIT", 1, maxf, tunit, &nfound, status); |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (tbcol) |
| { |
| ffgknjj(fptr, "TBCOL", 1, maxf, tbcol, &nfound, status); |
|
|
| if (*status > 0 || nfound != maxf) |
| { |
| ffpmsg( |
| "Required TBCOL keyword(s) not found in ASCII table header (ffghtbll)."); |
| return(*status = NO_TBCOL); |
| } |
| } |
|
|
| if (tform) |
| { |
| ffgkns(fptr, "TFORM", 1, maxf, tform, &nfound, status); |
|
|
| if (*status > 0 || nfound != maxf) |
| { |
| ffpmsg( |
| "Required TFORM keyword(s) not found in ASCII table header (ffghtbll)."); |
| return(*status = NO_TFORM); |
| } |
| } |
| } |
|
|
| if (extnm) |
| { |
| extnm[0] = '\0'; |
|
|
| tstatus = *status; |
| ffgkys(fptr, "EXTNAME", extnm, comm, status); |
|
|
| if (*status == KEY_NO_EXIST) |
| *status = tstatus; |
| } |
|
|
| return(*status); |
| } |
| |
| int ffghbn(fitsfile *fptr, |
| int maxfield, |
| long *naxis2, |
| int *tfields, |
| char **ttype, |
| char **tform, |
| char **tunit, |
| char *extnm, |
| long *pcount, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| int ii, maxf, nfound, tstatus; |
| long fields; |
| char name[FLEN_KEYWORD], value[FLEN_VALUE], comm[FLEN_COMMENT]; |
| char xtension[FLEN_VALUE], message[FLEN_ERRMSG]; |
| LONGLONG naxis1ll, naxis2ll, pcountll; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| |
| ffgkyn(fptr, 1, name, value, comm, status); |
|
|
| if (!strcmp(name, "XTENSION")) |
| { |
| if (ffc2s(value, xtension, status) > 0) |
| { |
| ffpmsg("Bad value string for XTENSION keyword:"); |
| ffpmsg(value); |
| return(*status); |
| } |
|
|
| |
| |
| if ( (value[0] != '\'') || |
| ( strcmp(xtension, "BINTABLE") && |
| strcmp(xtension, "A3DTABLE") && |
| strcmp(xtension, "3DTABLE") |
| ) ) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "This is not a BINTABLE extension: %s", value); |
| ffpmsg(message); |
| return(*status = NOT_BTABLE); |
| } |
| } |
|
|
| else |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "First keyword of the extension is not XTENSION: %s", name); |
| ffpmsg(message); |
| return(*status = NO_XTENSION); |
| } |
|
|
| if (ffgttb(fptr, &naxis1ll, &naxis2ll, &pcountll, &fields, status) > 0) |
| return(*status); |
|
|
| if (naxis2) |
| *naxis2 = (long) naxis2ll; |
|
|
| if (pcount) |
| *pcount = (long) pcountll; |
|
|
| if (tfields) |
| *tfields = fields; |
|
|
| if (maxfield < 0) |
| maxf = fields; |
| else |
| maxf = minvalue(maxfield, fields); |
|
|
| if (maxf > 0) |
| { |
| for (ii = 0; ii < maxf; ii++) |
| { |
| if (ttype) |
| *ttype[ii] = '\0'; |
|
|
| if (tunit) |
| *tunit[ii] = '\0'; |
| } |
|
|
| if (ttype) |
| ffgkns(fptr, "TTYPE", 1, maxf, ttype, &nfound, status); |
|
|
| if (tunit) |
| ffgkns(fptr, "TUNIT", 1, maxf, tunit, &nfound, status); |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (tform) |
| { |
| ffgkns(fptr, "TFORM", 1, maxf, tform, &nfound, status); |
|
|
| if (*status > 0 || nfound != maxf) |
| { |
| ffpmsg( |
| "Required TFORM keyword(s) not found in binary table header (ffghbn)."); |
| return(*status = NO_TFORM); |
| } |
| } |
| } |
|
|
| if (extnm) |
| { |
| extnm[0] = '\0'; |
|
|
| tstatus = *status; |
| ffgkys(fptr, "EXTNAME", extnm, comm, status); |
|
|
| if (*status == KEY_NO_EXIST) |
| *status = tstatus; |
| } |
| return(*status); |
| } |
| |
| int ffghbnll(fitsfile *fptr, |
| int maxfield, |
| LONGLONG *naxis2, |
| int *tfields, |
| char **ttype, |
| char **tform, |
| char **tunit, |
| char *extnm, |
| LONGLONG *pcount, |
| int *status) |
| |
| |
| |
| |
| |
| { |
| int ii, maxf, nfound, tstatus; |
| long fields; |
| char name[FLEN_KEYWORD], value[FLEN_VALUE], comm[FLEN_COMMENT]; |
| char xtension[FLEN_VALUE], message[FLEN_ERRMSG]; |
| LONGLONG naxis1ll, naxis2ll, pcountll; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| |
| ffgkyn(fptr, 1, name, value, comm, status); |
|
|
| if (!strcmp(name, "XTENSION")) |
| { |
| if (ffc2s(value, xtension, status) > 0) |
| { |
| ffpmsg("Bad value string for XTENSION keyword:"); |
| ffpmsg(value); |
| return(*status); |
| } |
|
|
| |
| |
| if ( (value[0] != '\'') || |
| ( strcmp(xtension, "BINTABLE") && |
| strcmp(xtension, "A3DTABLE") && |
| strcmp(xtension, "3DTABLE") |
| ) ) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "This is not a BINTABLE extension: %s", value); |
| ffpmsg(message); |
| return(*status = NOT_BTABLE); |
| } |
| } |
|
|
| else |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "First keyword of the extension is not XTENSION: %s", name); |
| ffpmsg(message); |
| return(*status = NO_XTENSION); |
| } |
|
|
| if (ffgttb(fptr, &naxis1ll, &naxis2ll, &pcountll, &fields, status) > 0) |
| return(*status); |
|
|
| if (naxis2) |
| *naxis2 = naxis2ll; |
|
|
| if (pcount) |
| *pcount = pcountll; |
|
|
| if (tfields) |
| *tfields = fields; |
|
|
| if (maxfield < 0) |
| maxf = fields; |
| else |
| maxf = minvalue(maxfield, fields); |
|
|
| if (maxf > 0) |
| { |
| for (ii = 0; ii < maxf; ii++) |
| { |
| if (ttype) |
| *ttype[ii] = '\0'; |
|
|
| if (tunit) |
| *tunit[ii] = '\0'; |
| } |
|
|
| if (ttype) |
| ffgkns(fptr, "TTYPE", 1, maxf, ttype, &nfound, status); |
|
|
| if (tunit) |
| ffgkns(fptr, "TUNIT", 1, maxf, tunit, &nfound, status); |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (tform) |
| { |
| ffgkns(fptr, "TFORM", 1, maxf, tform, &nfound, status); |
|
|
| if (*status > 0 || nfound != maxf) |
| { |
| ffpmsg( |
| "Required TFORM keyword(s) not found in binary table header (ffghbn)."); |
| return(*status = NO_TFORM); |
| } |
| } |
| } |
|
|
| if (extnm) |
| { |
| extnm[0] = '\0'; |
|
|
| tstatus = *status; |
| ffgkys(fptr, "EXTNAME", extnm, comm, status); |
|
|
| if (*status == KEY_NO_EXIST) |
| *status = tstatus; |
| } |
| return(*status); |
| } |
| |
| int ffgphd(fitsfile *fptr, |
| int maxdim, |
| int *simple, |
| int *bitpix, |
| int *naxis, |
| LONGLONG naxes[], |
| long *pcount, |
| long *gcount, |
| int *extend, |
| double *bscale, |
| double *bzero, |
| LONGLONG *blank, |
| int *nspace, |
| int *status) |
| { |
| |
| |
| |
| |
| |
| int unknown, found_end, tstatus, ii, nextkey, namelen; |
| long longbitpix, longnaxis; |
| LONGLONG axislen; |
| char message[FLEN_ERRMSG], keyword[FLEN_KEYWORD]; |
| char card[FLEN_CARD]; |
| char name[FLEN_KEYWORD], value[FLEN_VALUE], comm[FLEN_COMMENT]; |
| char xtension[FLEN_VALUE]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (fptr->HDUposition != (fptr->Fptr)->curhdu) |
| ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status); |
|
|
| if (simple) |
| *simple = 1; |
|
|
| unknown = 0; |
|
|
| |
| |
| |
| ffgkyn(fptr, 1, name, value, comm, status); |
|
|
| if ((fptr->Fptr)->curhdu == 0) |
| { |
| if (!strcmp(name, "SIMPLE")) |
| { |
| if (value[0] == 'F') |
| { |
| if (simple) |
| *simple=0; |
| } |
| else if (value[0] != 'T') |
| return(*status = BAD_SIMPLE); |
| } |
|
|
| else |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "First keyword of the file is not SIMPLE: %s", name); |
| ffpmsg(message); |
| return(*status = NO_SIMPLE); |
| } |
| } |
|
|
| else |
| { |
|
|
| if (!strcmp(name, "XTENSION")) |
| { |
| if (ffc2s(value, xtension, status) > 0) |
| { |
| ffpmsg("Bad value string for XTENSION keyword:"); |
| ffpmsg(value); |
| return(*status); |
| } |
|
|
| |
| |
| if ( (value[0] != '\'') || |
| ( strcmp(xtension, "IMAGE") && |
| strcmp(xtension, "IUEIMAGE") ) ) |
| { |
| unknown = 1; |
| snprintf(message, FLEN_ERRMSG, |
| "This is not an IMAGE extension: %s", value); |
| ffpmsg(message); |
| } |
| } |
|
|
| else |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "First keyword of the extension is not XTENSION: %s", name); |
| ffpmsg(message); |
| return(*status = NO_XTENSION); |
| } |
| } |
|
|
| if (unknown && (fptr->Fptr)->compressimg) |
| { |
| |
| unknown = 0; |
| ffxmsg(3, message); |
|
|
| if (bitpix) |
| { |
| ffgidt(fptr, bitpix, status); |
|
|
| if (*status > 0) |
| { |
| ffpmsg("Error reading BITPIX value of compressed image"); |
| return(*status); |
| } |
| } |
|
|
| if (naxis) |
| { |
| ffgidm(fptr, naxis, status); |
|
|
| if (*status > 0) |
| { |
| ffpmsg("Error reading NAXIS value of compressed image"); |
| return(*status); |
| } |
| } |
|
|
| if (naxes) |
| { |
| ffgiszll(fptr, maxdim, naxes, status); |
|
|
| if (*status > 0) |
| { |
| ffpmsg("Error reading NAXISn values of compressed image"); |
| return(*status); |
| } |
| } |
|
|
| nextkey = 9; |
| } |
| else |
| { |
|
|
| |
| |
| |
| ffgkyn(fptr, 2, name, value, comm, status); |
|
|
| if (strcmp(name, "BITPIX")) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "Second keyword of the extension is not BITPIX: %s", name); |
| ffpmsg(message); |
| return(*status = NO_BITPIX); |
| } |
|
|
| if (ffc2ii(value, &longbitpix, status) > 0) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "Value of BITPIX keyword is not an integer: %s", value); |
| ffpmsg(message); |
| return(*status = BAD_BITPIX); |
| } |
| else if (longbitpix != BYTE_IMG && longbitpix != SHORT_IMG && |
| longbitpix != LONG_IMG && longbitpix != LONGLONG_IMG && |
| longbitpix != FLOAT_IMG && longbitpix != DOUBLE_IMG) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "Illegal value for BITPIX keyword: %s", value); |
| ffpmsg(message); |
| return(*status = BAD_BITPIX); |
| } |
| if (bitpix) |
| *bitpix = longbitpix; |
|
|
| |
| |
| |
| ffgtkn(fptr, 3, "NAXIS", &longnaxis, status); |
|
|
| if (*status == BAD_ORDER) |
| return(*status = NO_NAXIS); |
| else if (*status == NOT_POS_INT || longnaxis > 999) |
| { |
| snprintf(message,FLEN_ERRMSG,"NAXIS = %ld is illegal", longnaxis); |
| ffpmsg(message); |
| return(*status = BAD_NAXIS); |
| } |
| else |
| if (naxis) |
| *naxis = longnaxis; |
|
|
| |
| |
| |
| for (ii=0, nextkey=4; ii < longnaxis; ii++, nextkey++) |
| { |
| ffkeyn("NAXIS", ii+1, keyword, status); |
| ffgtknjj(fptr, 4+ii, keyword, &axislen, status); |
|
|
| if (*status == BAD_ORDER) |
| return(*status = NO_NAXES); |
| else if (*status == NOT_POS_INT) |
| return(*status = BAD_NAXES); |
| else if (ii < maxdim) |
| if (naxes) |
| naxes[ii] = axislen; |
| } |
| } |
|
|
| |
| |
| |
| |
|
|
| |
| if (bscale) |
| *bscale = 1.0; |
| if (bzero) |
| *bzero = 0.0; |
| if (pcount) |
| *pcount = 0; |
| if (gcount) |
| *gcount = 1; |
| if (extend) |
| *extend = 0; |
| if (blank) |
| *blank = NULL_UNDEFINED; |
|
|
| *nspace = 0; |
| found_end = 0; |
| tstatus = *status; |
|
|
| for (; !found_end; nextkey++) |
| { |
| |
| |
| |
| |
|
|
| if (ffgrec(fptr, nextkey, card, status) > 0 ) |
| { |
| if (*status == KEY_OUT_BOUNDS) |
| { |
| found_end = 1; |
| *status = tstatus; |
| } |
| else |
| { |
| ffpmsg("Failed to find the END keyword in header (ffgphd)."); |
| } |
| } |
| else |
| { |
| ffgknm(card, name, &namelen, status); |
|
|
| if (fftrec(name, status) > 0) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "Name of keyword no. %d contains illegal character(s): %s", |
| nextkey, name); |
| ffpmsg(message); |
|
|
| if (nextkey % 36 == 0) |
| ffpmsg(" (This may indicate a missing END keyword)."); |
| } |
|
|
| if (!strcmp(name, "BSCALE") && bscale) |
| { |
| *nspace = 0; |
| ffpsvc(card, value, comm, status); |
|
|
| if (ffc2dd(value, bscale, status) > 0) |
| { |
| |
| *status = tstatus; |
| *bscale = 1.0; |
|
|
| snprintf(message, FLEN_ERRMSG, |
| "Error reading BSCALE keyword value as a double: %s", value); |
| ffpmsg(message); |
| } |
| } |
|
|
| else if (!strcmp(name, "BZERO") && bzero) |
| { |
| *nspace = 0; |
| ffpsvc(card, value, comm, status); |
|
|
| if (ffc2dd(value, bzero, status) > 0) |
| { |
| |
| *status = tstatus; |
| *bzero = 0.0; |
|
|
| snprintf(message, FLEN_ERRMSG, |
| "Error reading BZERO keyword value as a double: %s", value); |
| ffpmsg(message); |
| } |
| } |
|
|
| else if (!strcmp(name, "BLANK") && blank) |
| { |
| *nspace = 0; |
| ffpsvc(card, value, comm, status); |
|
|
| if (ffc2jj(value, blank, status) > 0) |
| { |
| |
| *status = tstatus; |
| *blank = NULL_UNDEFINED; |
|
|
| snprintf(message, FLEN_ERRMSG, |
| "Error reading BLANK keyword value as an integer: %s", value); |
| ffpmsg(message); |
| } |
| } |
|
|
| else if (!strcmp(name, "PCOUNT") && pcount) |
| { |
| *nspace = 0; |
| ffpsvc(card, value, comm, status); |
|
|
| if (ffc2ii(value, pcount, status) > 0) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "Error reading PCOUNT keyword value as an integer: %s", value); |
| ffpmsg(message); |
| } |
| } |
|
|
| else if (!strcmp(name, "GCOUNT") && gcount) |
| { |
| *nspace = 0; |
| ffpsvc(card, value, comm, status); |
|
|
| if (ffc2ii(value, gcount, status) > 0) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "Error reading GCOUNT keyword value as an integer: %s", value); |
| ffpmsg(message); |
| } |
| } |
|
|
| else if (!strcmp(name, "EXTEND") && extend) |
| { |
| *nspace = 0; |
| ffpsvc(card, value, comm, status); |
|
|
| if (ffc2ll(value, extend, status) > 0) |
| { |
| |
| *status = tstatus; |
| *extend = 0; |
|
|
| snprintf(message, FLEN_ERRMSG, |
| "Error reading EXTEND keyword value as a logical: %s", value); |
| ffpmsg(message); |
| } |
| } |
|
|
| else if (!strcmp(name, "END")) |
| found_end = 1; |
|
|
| else if (!card[0] ) |
| *nspace = *nspace + 1; |
|
|
| else |
| *nspace = 0; |
| |
| } |
|
|
| if (*status > 0) |
| { |
| if ((fptr->Fptr)->curhdu == 0) |
| ffpmsg( |
| "Failed to read the required primary array header keywords."); |
| else |
| ffpmsg( |
| "Failed to read the required image extension header keywords."); |
|
|
| return(*status); |
| } |
| } |
|
|
| if (unknown) |
| *status = NOT_IMAGE; |
|
|
| return(*status); |
| } |
| |
| int ffgttb(fitsfile *fptr, |
| LONGLONG *rowlen, |
| LONGLONG *nrows, |
| LONGLONG *pcount, |
| long *tfields, |
| int *status) |
| { |
| |
| |
| |
| |
| |
| |
| if (*status > 0) |
| return(*status); |
|
|
| if (fftkyn(fptr, 2, "BITPIX", "8", status) == BAD_ORDER) |
| return(*status = NO_BITPIX); |
| else if (*status == NOT_POS_INT) |
| return(*status = BAD_BITPIX); |
|
|
| if (fftkyn(fptr, 3, "NAXIS", "2", status) == BAD_ORDER) |
| return(*status = NO_NAXIS); |
| else if (*status == NOT_POS_INT) |
| return(*status = BAD_NAXIS); |
|
|
| if (ffgtknjj(fptr, 4, "NAXIS1", rowlen, status) == BAD_ORDER) |
| return(*status = NO_NAXES); |
| else if (*status == NOT_POS_INT) |
| return(*status == BAD_NAXES); |
|
|
| if (ffgtknjj(fptr, 5, "NAXIS2", nrows, status) == BAD_ORDER) |
| return(*status = NO_NAXES); |
| else if (*status == NOT_POS_INT) |
| return(*status == BAD_NAXES); |
|
|
| if (ffgtknjj(fptr, 6, "PCOUNT", pcount, status) == BAD_ORDER) |
| return(*status = NO_PCOUNT); |
| else if (*status == NOT_POS_INT) |
| return(*status = BAD_PCOUNT); |
|
|
| if (fftkyn(fptr, 7, "GCOUNT", "1", status) == BAD_ORDER) |
| return(*status = NO_GCOUNT); |
| else if (*status == NOT_POS_INT) |
| return(*status = BAD_GCOUNT); |
|
|
| if (ffgtkn(fptr, 8, "TFIELDS", tfields, status) == BAD_ORDER) |
| return(*status = NO_TFIELDS); |
| else if (*status == NOT_POS_INT || *tfields > 999) |
| return(*status == BAD_TFIELDS); |
|
|
|
|
| if (*status > 0) |
| ffpmsg( |
| "Error reading required keywords in the table header (FTGTTB)."); |
|
|
| return(*status); |
| } |
| |
| int ffgtkn(fitsfile *fptr, |
| int numkey, |
| char *name, |
| long *value, |
| int *status) |
| { |
| |
| |
| |
| |
| |
| |
| char keyname[FLEN_KEYWORD], valuestring[FLEN_VALUE]; |
| char comm[FLEN_COMMENT], message[FLEN_ERRMSG]; |
| |
| if (*status > 0) |
| return(*status); |
| |
| keyname[0] = '\0'; |
| valuestring[0] = '\0'; |
|
|
| if (ffgkyn(fptr, numkey, keyname, valuestring, comm, status) <= 0) |
| { |
| if (strcmp(keyname, name) ) |
| *status = BAD_ORDER; |
|
|
| else |
| { |
| ffc2ii(valuestring, value, status); |
|
|
| if (*status > 0 || *value < 0 ) |
| *status = NOT_POS_INT; |
| } |
|
|
| if (*status > 0) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "ffgtkn found unexpected keyword or value for keyword no. %d.", |
| numkey); |
| ffpmsg(message); |
|
|
| snprintf(message, FLEN_ERRMSG, |
| " Expected positive integer keyword %s, but instead", name); |
| ffpmsg(message); |
|
|
| snprintf(message, FLEN_ERRMSG, |
| " found keyword %s with value %s", keyname, valuestring); |
| ffpmsg(message); |
| } |
| } |
|
|
| return(*status); |
| } |
| |
| int ffgtknjj(fitsfile *fptr, |
| int numkey, |
| char *name, |
| LONGLONG *value, |
| int *status) |
| { |
| |
| |
| |
| |
| |
| |
| char keyname[FLEN_KEYWORD], valuestring[FLEN_VALUE]; |
| char comm[FLEN_COMMENT], message[FLEN_ERRMSG]; |
| |
| if (*status > 0) |
| return(*status); |
| |
| keyname[0] = '\0'; |
| valuestring[0] = '\0'; |
|
|
| if (ffgkyn(fptr, numkey, keyname, valuestring, comm, status) <= 0) |
| { |
| if (strcmp(keyname, name) ) |
| *status = BAD_ORDER; |
|
|
| else |
| { |
| ffc2jj(valuestring, value, status); |
|
|
| if (*status > 0 || *value < 0 ) |
| *status = NOT_POS_INT; |
| } |
|
|
| if (*status > 0) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "ffgtknjj found unexpected keyword or value for keyword no. %d.", |
| numkey); |
| ffpmsg(message); |
|
|
| snprintf(message, FLEN_ERRMSG, |
| " Expected positive integer keyword %s, but instead", name); |
| ffpmsg(message); |
|
|
| snprintf(message, FLEN_ERRMSG, |
| " found keyword %s with value %s", keyname, valuestring); |
| ffpmsg(message); |
| } |
| } |
|
|
| return(*status); |
| } |
| |
| int fftkyn(fitsfile *fptr, |
| int numkey, |
| char *name, |
| char *value, |
| int *status) |
| { |
| |
| |
| |
| |
| char keyname[FLEN_KEYWORD], valuestring[FLEN_VALUE]; |
| char comm[FLEN_COMMENT], message[FLEN_ERRMSG]; |
| |
| if (*status > 0) |
| return(*status); |
| |
| keyname[0] = '\0'; |
| valuestring[0] = '\0'; |
|
|
| if (ffgkyn(fptr, numkey, keyname, valuestring, comm, status) <= 0) |
| { |
| if (strcmp(keyname, name) ) |
| *status = BAD_ORDER; |
|
|
| if (strcmp(value, valuestring) ) |
| *status = NOT_POS_INT; |
| } |
|
|
| if (*status > 0) |
| { |
| snprintf(message, FLEN_ERRMSG, |
| "fftkyn found unexpected keyword or value for keyword no. %d.", |
| numkey); |
| ffpmsg(message); |
|
|
| snprintf(message, FLEN_ERRMSG, |
| " Expected keyword %s with value %s, but", name, value); |
| ffpmsg(message); |
|
|
| snprintf(message, FLEN_ERRMSG, |
| " found keyword %s with value %s", keyname, valuestring); |
| ffpmsg(message); |
| } |
|
|
| return(*status); |
| } |
| |
| int ffh2st(fitsfile *fptr, |
| char **header, |
| int *status) |
|
|
| |
| |
| |
| |
| |
| { |
| int nkeys; |
| long nrec; |
| LONGLONG headstart; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| |
| if (ffghsp(fptr, &nkeys, NULL, status) > 0) |
| return(*status); |
|
|
| nrec = (nkeys / 36 + 1); |
|
|
| |
| *header = (char *) calloc ( nrec * 2880 + 1, 1); |
| if (!(*header)) |
| { |
| *status = MEMORY_ALLOCATION; |
| ffpmsg("failed to allocate memory to hold all the header keywords"); |
| return(*status); |
| } |
|
|
| ffghadll(fptr, &headstart, NULL, NULL, status); |
| ffmbyt(fptr, headstart, REPORT_EOF, status); |
| ffgbyt(fptr, nrec * 2880, *header, status); |
| *(*header + (nrec * 2880)) = '\0'; |
|
|
| return(*status); |
| } |
| |
| int ffhdr2str( fitsfile *fptr, |
| int exclude_comm, |
| char **exclist, |
| int nexc, |
| char **header, |
| int *nkeys, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| int casesn, match, exact, totkeys; |
| long ii, jj; |
| char keybuf[162], keyname[FLEN_KEYWORD], *headptr; |
|
|
| *nkeys = 0; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| |
| if (ffghsp(fptr, &totkeys, NULL, status) > 0) |
| return(*status); |
|
|
| |
| |
| |
| *header = (char *) calloc ( (totkeys + 1) * 80 + 1, 1); |
| if (!(*header)) |
| { |
| *status = MEMORY_ALLOCATION; |
| ffpmsg("failed to allocate memory to hold all the header keywords"); |
| return(*status); |
| } |
|
|
| headptr = *header; |
| casesn = FALSE; |
|
|
| |
| for (ii = 1; ii <= totkeys; ii++) |
| { |
| ffgrec(fptr, ii, keybuf, status); |
| |
| strcat(keybuf, |
| " "); |
|
|
| keyname[0] = '\0'; |
| strncat(keyname, keybuf, 8); |
| |
| if (exclude_comm) |
| { |
| if (!FSTRCMP("COMMENT ", keyname) || |
| !FSTRCMP("HISTORY ", keyname) || |
| !FSTRCMP(" ", keyname) ) |
| continue; |
| } |
|
|
| |
| for (jj = 0; jj < nexc; jj++ ) |
| { |
| ffcmps(exclist[jj], keyname, casesn, &match, &exact); |
| if (match) |
| break; |
| } |
|
|
| if (jj == nexc) |
| { |
| |
| strcpy(headptr, keybuf); |
| headptr += 80; |
| (*nkeys)++; |
| } |
| } |
|
|
| |
| strcpy(headptr, |
| "END "); |
| headptr += 80; |
| (*nkeys)++; |
|
|
| *headptr = '\0'; |
| |
| *header = (char *) realloc(*header, (*nkeys *80) + 1); |
|
|
| return(*status); |
| } |
| |
| int ffcnvthdr2str( fitsfile *fptr, |
| int exclude_comm, |
| char **exclist, |
| int nexc, |
| char **header, |
| int *nkeys, |
| int *status) |
| |
| |
| |
| |
| |
| |
| { |
| fitsfile *tempfptr; |
| |
| if (*status > 0) |
| return(*status); |
|
|
| if (fits_is_compressed_image(fptr, status) ) |
| { |
| |
| |
| if (fits_create_file(&tempfptr, "mem://", status) > 0) { |
| return(*status); |
| } |
|
|
| if (fits_img_decompress_header(fptr, tempfptr, status) > 0) { |
| fits_delete_file(tempfptr, status); |
| return(*status); |
| } |
|
|
| ffhdr2str(tempfptr, exclude_comm, exclist, nexc, header, nkeys, status); |
| fits_close_file(tempfptr, status); |
|
|
| } else { |
| ffhdr2str(fptr, exclude_comm, exclist, nexc, header, nkeys, status); |
| } |
|
|
| return(*status); |
| } |
|
|