| |
| |
|
|
| |
| |
| |
|
|
| #include <string.h> |
| #include <stdlib.h> |
| #include <limits.h> |
| #include "fitsio2.h" |
|
|
| |
| int ffppx( fitsfile *fptr, |
| int datatype, |
| long *firstpix, |
| LONGLONG nelem, |
| void *array, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| int naxis, ii; |
| long group = 1; |
| LONGLONG firstelem, dimsize = 1, naxes[9]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| |
| ffgidm(fptr, &naxis, status); |
| ffgiszll(fptr, 9, naxes, status); |
|
|
| firstelem = 0; |
| for (ii=0; ii < naxis; ii++) |
| { |
| firstelem += ((firstpix[ii] - 1) * dimsize); |
| dimsize *= naxes[ii]; |
| } |
| firstelem++; |
|
|
| if (datatype == TBYTE) |
| { |
| ffpprb(fptr, group, firstelem, nelem, (unsigned char *) array, status); |
| } |
| else if (datatype == TSBYTE) |
| { |
| ffpprsb(fptr, group, firstelem, nelem, (signed char *) array, status); |
| } |
| else if (datatype == TUSHORT) |
| { |
| ffpprui(fptr, group, firstelem, nelem, (unsigned short *) array, |
| status); |
| } |
| else if (datatype == TSHORT) |
| { |
| ffppri(fptr, group, firstelem, nelem, (short *) array, status); |
| } |
| else if (datatype == TUINT) |
| { |
| ffppruk(fptr, group, firstelem, nelem, (unsigned int *) array, status); |
| } |
| else if (datatype == TINT) |
| { |
| ffpprk(fptr, group, firstelem, nelem, (int *) array, status); |
| } |
| else if (datatype == TULONG) |
| { |
| ffppruj(fptr, group, firstelem, nelem, (unsigned long *) array, status); |
| } |
| else if (datatype == TLONG) |
| { |
| ffpprj(fptr, group, firstelem, nelem, (long *) array, status); |
| } |
| else if (datatype == TULONGLONG) |
| { |
| ffpprujj(fptr, group, firstelem, nelem, (ULONGLONG *) array, status); |
| } |
| else if (datatype == TLONGLONG) |
| { |
| ffpprjj(fptr, group, firstelem, nelem, (LONGLONG *) array, status); |
| } |
| else if (datatype == TFLOAT) |
| { |
| ffppre(fptr, group, firstelem, nelem, (float *) array, status); |
| } |
| else if (datatype == TDOUBLE) |
| { |
| ffpprd(fptr, group, firstelem, nelem, (double *) array, status); |
| } |
| else |
| *status = BAD_DATATYPE; |
|
|
| return(*status); |
| } |
| |
| int ffppxll( fitsfile *fptr, |
| int datatype, |
| LONGLONG *firstpix, |
| LONGLONG nelem, |
| void *array, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| int naxis, ii; |
| long group = 1; |
| LONGLONG firstelem, dimsize = 1, naxes[9]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| |
| ffgidm(fptr, &naxis, status); |
| ffgiszll(fptr, 9, naxes, status); |
|
|
| firstelem = 0; |
| for (ii=0; ii < naxis; ii++) |
| { |
| firstelem += ((firstpix[ii] - 1) * dimsize); |
| dimsize *= naxes[ii]; |
| } |
| firstelem++; |
|
|
| if (datatype == TBYTE) |
| { |
| ffpprb(fptr, group, firstelem, nelem, (unsigned char *) array, status); |
| } |
| else if (datatype == TSBYTE) |
| { |
| ffpprsb(fptr, group, firstelem, nelem, (signed char *) array, status); |
| } |
| else if (datatype == TUSHORT) |
| { |
| ffpprui(fptr, group, firstelem, nelem, (unsigned short *) array, |
| status); |
| } |
| else if (datatype == TSHORT) |
| { |
| ffppri(fptr, group, firstelem, nelem, (short *) array, status); |
| } |
| else if (datatype == TUINT) |
| { |
| ffppruk(fptr, group, firstelem, nelem, (unsigned int *) array, status); |
| } |
| else if (datatype == TINT) |
| { |
| ffpprk(fptr, group, firstelem, nelem, (int *) array, status); |
| } |
| else if (datatype == TULONG) |
| { |
| ffppruj(fptr, group, firstelem, nelem, (unsigned long *) array, status); |
| } |
| else if (datatype == TLONG) |
| { |
| ffpprj(fptr, group, firstelem, nelem, (long *) array, status); |
| } |
| else if (datatype == TULONGLONG) |
| { |
| ffpprujj(fptr, group, firstelem, nelem, (ULONGLONG *) array, status); |
| } |
| else if (datatype == TLONGLONG) |
| { |
| ffpprjj(fptr, group, firstelem, nelem, (LONGLONG *) array, status); |
| } |
| else if (datatype == TFLOAT) |
| { |
| ffppre(fptr, group, firstelem, nelem, (float *) array, status); |
| } |
| else if (datatype == TDOUBLE) |
| { |
| ffpprd(fptr, group, firstelem, nelem, (double *) array, status); |
| } |
| else |
| *status = BAD_DATATYPE; |
|
|
| return(*status); |
| } |
| |
| int ffppxn( fitsfile *fptr, |
| int datatype, |
| long *firstpix, |
| LONGLONG nelem, |
| void *array, |
| void *nulval, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| int naxis, ii; |
| long group = 1; |
| LONGLONG firstelem, dimsize = 1, naxes[9]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (nulval == NULL) |
| { |
| ffppx(fptr, datatype, firstpix, nelem, array, status); |
| return(*status); |
| } |
|
|
| |
| ffgidm(fptr, &naxis, status); |
| ffgiszll(fptr, 9, naxes, status); |
|
|
| firstelem = 0; |
| for (ii=0; ii < naxis; ii++) |
| { |
| firstelem += ((firstpix[ii] - 1) * dimsize); |
| dimsize *= naxes[ii]; |
| } |
| firstelem++; |
|
|
| if (datatype == TBYTE) |
| { |
| ffppnb(fptr, group, firstelem, nelem, (unsigned char *) array, |
| *(unsigned char *) nulval, status); |
| } |
| else if (datatype == TSBYTE) |
| { |
| ffppnsb(fptr, group, firstelem, nelem, (signed char *) array, |
| *(signed char *) nulval, status); |
| } |
| else if (datatype == TUSHORT) |
| { |
| ffppnui(fptr, group, firstelem, nelem, (unsigned short *) array, |
| *(unsigned short *) nulval,status); |
| } |
| else if (datatype == TSHORT) |
| { |
| ffppni(fptr, group, firstelem, nelem, (short *) array, |
| *(short *) nulval, status); |
| } |
| else if (datatype == TUINT) |
| { |
| ffppnuk(fptr, group, firstelem, nelem, (unsigned int *) array, |
| *(unsigned int *) nulval, status); |
| } |
| else if (datatype == TINT) |
| { |
| ffppnk(fptr, group, firstelem, nelem, (int *) array, |
| *(int *) nulval, status); |
| } |
| else if (datatype == TULONG) |
| { |
| ffppnuj(fptr, group, firstelem, nelem, (unsigned long *) array, |
| *(unsigned long *) nulval,status); |
| } |
| else if (datatype == TLONG) |
| { |
| ffppnj(fptr, group, firstelem, nelem, (long *) array, |
| *(long *) nulval, status); |
| } |
| else if (datatype == TULONGLONG) |
| { |
| ffppnujj(fptr, group, firstelem, nelem, (ULONGLONG *) array, |
| *(ULONGLONG *) nulval, status); |
| } |
| else if (datatype == TLONGLONG) |
| { |
| ffppnjj(fptr, group, firstelem, nelem, (LONGLONG *) array, |
| *(LONGLONG *) nulval, status); |
| } |
| else if (datatype == TFLOAT) |
| { |
| ffppne(fptr, group, firstelem, nelem, (float *) array, |
| *(float *) nulval, status); |
| } |
| else if (datatype == TDOUBLE) |
| { |
| ffppnd(fptr, group, firstelem, nelem, (double *) array, |
| *(double *) nulval, status); |
| } |
| else |
| *status = BAD_DATATYPE; |
|
|
| return(*status); |
| } |
| |
| int ffppxnll( fitsfile *fptr, |
| int datatype, |
| LONGLONG *firstpix, |
| LONGLONG nelem, |
| void *array, |
| void *nulval, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| int naxis, ii; |
| long group = 1; |
| LONGLONG firstelem, dimsize = 1, naxes[9]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (nulval == NULL) |
| { |
| ffppxll(fptr, datatype, firstpix, nelem, array, status); |
| return(*status); |
| } |
|
|
| |
| ffgidm(fptr, &naxis, status); |
| ffgiszll(fptr, 9, naxes, status); |
|
|
| firstelem = 0; |
| for (ii=0; ii < naxis; ii++) |
| { |
| firstelem += ((firstpix[ii] - 1) * dimsize); |
| dimsize *= naxes[ii]; |
| } |
| firstelem++; |
|
|
| if (datatype == TBYTE) |
| { |
| ffppnb(fptr, group, firstelem, nelem, (unsigned char *) array, |
| *(unsigned char *) nulval, status); |
| } |
| else if (datatype == TSBYTE) |
| { |
| ffppnsb(fptr, group, firstelem, nelem, (signed char *) array, |
| *(signed char *) nulval, status); |
| } |
| else if (datatype == TUSHORT) |
| { |
| ffppnui(fptr, group, firstelem, nelem, (unsigned short *) array, |
| *(unsigned short *) nulval,status); |
| } |
| else if (datatype == TSHORT) |
| { |
| ffppni(fptr, group, firstelem, nelem, (short *) array, |
| *(short *) nulval, status); |
| } |
| else if (datatype == TUINT) |
| { |
| ffppnuk(fptr, group, firstelem, nelem, (unsigned int *) array, |
| *(unsigned int *) nulval, status); |
| } |
| else if (datatype == TINT) |
| { |
| ffppnk(fptr, group, firstelem, nelem, (int *) array, |
| *(int *) nulval, status); |
| } |
| else if (datatype == TULONG) |
| { |
| ffppnuj(fptr, group, firstelem, nelem, (unsigned long *) array, |
| *(unsigned long *) nulval,status); |
| } |
| else if (datatype == TLONG) |
| { |
| ffppnj(fptr, group, firstelem, nelem, (long *) array, |
| *(long *) nulval, status); |
| } |
| else if (datatype == TULONGLONG) |
| { |
| ffppnujj(fptr, group, firstelem, nelem, (ULONGLONG *) array, |
| *(ULONGLONG *) nulval, status); |
| } |
| else if (datatype == TLONGLONG) |
| { |
| ffppnjj(fptr, group, firstelem, nelem, (LONGLONG *) array, |
| *(LONGLONG *) nulval, status); |
| } |
| else if (datatype == TFLOAT) |
| { |
| ffppne(fptr, group, firstelem, nelem, (float *) array, |
| *(float *) nulval, status); |
| } |
| else if (datatype == TDOUBLE) |
| { |
| ffppnd(fptr, group, firstelem, nelem, (double *) array, |
| *(double *) nulval, status); |
| } |
| else |
| *status = BAD_DATATYPE; |
|
|
| return(*status); |
| } |
| |
| int ffppr( fitsfile *fptr, |
| int datatype, |
| LONGLONG firstelem, |
| LONGLONG nelem, |
| void *array, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| { |
| long group = 1; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (datatype == TBYTE) |
| { |
| ffpprb(fptr, group, firstelem, nelem, (unsigned char *) array, status); |
| } |
| else if (datatype == TSBYTE) |
| { |
| ffpprsb(fptr, group, firstelem, nelem, (signed char *) array, status); |
| } |
| else if (datatype == TUSHORT) |
| { |
| ffpprui(fptr, group, firstelem, nelem, (unsigned short *) array, |
| status); |
| } |
| else if (datatype == TSHORT) |
| { |
| ffppri(fptr, group, firstelem, nelem, (short *) array, status); |
| } |
| else if (datatype == TUINT) |
| { |
| ffppruk(fptr, group, firstelem, nelem, (unsigned int *) array, status); |
| } |
| else if (datatype == TINT) |
| { |
| ffpprk(fptr, group, firstelem, nelem, (int *) array, status); |
| } |
| else if (datatype == TULONG) |
| { |
| ffppruj(fptr, group, firstelem, nelem, (unsigned long *) array, status); |
| } |
| else if (datatype == TLONG) |
| { |
| ffpprj(fptr, group, firstelem, nelem, (long *) array, status); |
| } |
| else if (datatype == TULONGLONG) |
| { |
| ffpprujj(fptr, group, firstelem, nelem, (ULONGLONG *) array, status); |
| } |
| else if (datatype == TLONGLONG) |
| { |
| ffpprjj(fptr, group, firstelem, nelem, (LONGLONG *) array, status); |
| } |
| else if (datatype == TFLOAT) |
| { |
| ffppre(fptr, group, firstelem, nelem, (float *) array, status); |
| } |
| else if (datatype == TDOUBLE) |
| { |
| ffpprd(fptr, group, firstelem, nelem, (double *) array, status); |
| } |
| else |
| *status = BAD_DATATYPE; |
|
|
| return(*status); |
| } |
| |
| int ffppn( fitsfile *fptr, |
| int datatype, |
| LONGLONG firstelem, |
| LONGLONG nelem, |
| void *array, |
| void *nulval, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| { |
| long group = 1; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (nulval == NULL) |
| { |
| ffppr(fptr, datatype, firstelem, nelem, array, status); |
| return(*status); |
| } |
|
|
| if (datatype == TBYTE) |
| { |
| ffppnb(fptr, group, firstelem, nelem, (unsigned char *) array, |
| *(unsigned char *) nulval, status); |
| } |
| else if (datatype == TSBYTE) |
| { |
| ffppnsb(fptr, group, firstelem, nelem, (signed char *) array, |
| *(signed char *) nulval, status); |
| } |
| else if (datatype == TUSHORT) |
| { |
| ffppnui(fptr, group, firstelem, nelem, (unsigned short *) array, |
| *(unsigned short *) nulval,status); |
| } |
| else if (datatype == TSHORT) |
| { |
| ffppni(fptr, group, firstelem, nelem, (short *) array, |
| *(short *) nulval, status); |
| } |
| else if (datatype == TUINT) |
| { |
| ffppnuk(fptr, group, firstelem, nelem, (unsigned int *) array, |
| *(unsigned int *) nulval, status); |
| } |
| else if (datatype == TINT) |
| { |
| ffppnk(fptr, group, firstelem, nelem, (int *) array, |
| *(int *) nulval, status); |
| } |
| else if (datatype == TULONG) |
| { |
| ffppnuj(fptr, group, firstelem, nelem, (unsigned long *) array, |
| *(unsigned long *) nulval,status); |
| } |
| else if (datatype == TLONG) |
| { |
| ffppnj(fptr, group, firstelem, nelem, (long *) array, |
| *(long *) nulval, status); |
| } |
| else if (datatype == TULONGLONG) |
| { |
| ffppnujj(fptr, group, firstelem, nelem, (ULONGLONG *) array, |
| *(ULONGLONG *) nulval, status); |
| } |
| else if (datatype == TLONGLONG) |
| { |
| ffppnjj(fptr, group, firstelem, nelem, (LONGLONG *) array, |
| *(LONGLONG *) nulval, status); |
| } |
| else if (datatype == TFLOAT) |
| { |
| ffppne(fptr, group, firstelem, nelem, (float *) array, |
| *(float *) nulval, status); |
| } |
| else if (datatype == TDOUBLE) |
| { |
| ffppnd(fptr, group, firstelem, nelem, (double *) array, |
| *(double *) nulval, status); |
| } |
| else |
| *status = BAD_DATATYPE; |
|
|
| return(*status); |
| } |
| |
| int ffpss( fitsfile *fptr, |
| int datatype, |
| long *blc, |
| long *trc , |
| void *array, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| int naxis; |
| long naxes[9]; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| |
| ffgidm(fptr, &naxis, status); |
| ffgisz(fptr, 9, naxes, status); |
|
|
| if (datatype == TBYTE) |
| { |
| ffpssb(fptr, 1, naxis, naxes, blc, trc, |
| (unsigned char *) array, status); |
| } |
| else if (datatype == TSBYTE) |
| { |
| ffpsssb(fptr, 1, naxis, naxes, blc, trc, |
| (signed char *) array, status); |
| } |
| else if (datatype == TUSHORT) |
| { |
| ffpssui(fptr, 1, naxis, naxes, blc, trc, |
| (unsigned short *) array, status); |
| } |
| else if (datatype == TSHORT) |
| { |
| ffpssi(fptr, 1, naxis, naxes, blc, trc, |
| (short *) array, status); |
| } |
| else if (datatype == TUINT) |
| { |
| ffpssuk(fptr, 1, naxis, naxes, blc, trc, |
| (unsigned int *) array, status); |
| } |
| else if (datatype == TINT) |
| { |
| ffpssk(fptr, 1, naxis, naxes, blc, trc, |
| (int *) array, status); |
| } |
| else if (datatype == TULONG) |
| { |
| ffpssuj(fptr, 1, naxis, naxes, blc, trc, |
| (unsigned long *) array, status); |
| } |
| else if (datatype == TLONG) |
| { |
| ffpssj(fptr, 1, naxis, naxes, blc, trc, |
| (long *) array, status); |
| } |
| else if (datatype == TULONGLONG) |
| { |
| ffpssujj(fptr, 1, naxis, naxes, blc, trc, |
| (ULONGLONG *) array, status); |
| } |
| else if (datatype == TLONGLONG) |
| { |
| ffpssjj(fptr, 1, naxis, naxes, blc, trc, |
| (LONGLONG *) array, status); |
| } |
| else if (datatype == TFLOAT) |
| { |
| ffpsse(fptr, 1, naxis, naxes, blc, trc, |
| (float *) array, status); |
| } |
| else if (datatype == TDOUBLE) |
| { |
| ffpssd(fptr, 1, naxis, naxes, blc, trc, |
| (double *) array, status); |
| } |
| else |
| *status = BAD_DATATYPE; |
|
|
| return(*status); |
| } |
| |
| int ffpcl( fitsfile *fptr, |
| int datatype, |
| int colnum, |
| LONGLONG firstrow, |
| LONGLONG firstelem, |
| LONGLONG nelem, |
| void *array, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| { |
| if (*status > 0) |
| return(*status); |
|
|
| if (datatype == TBIT) |
| { |
| ffpclx(fptr, colnum, firstrow, (long) firstelem, (long) nelem, (char *) array, |
| status); |
| } |
| else if (datatype == TBYTE) |
| { |
| ffpclb(fptr, colnum, firstrow, firstelem, nelem, (unsigned char *) array, |
| status); |
| } |
| else if (datatype == TSBYTE) |
| { |
| ffpclsb(fptr, colnum, firstrow, firstelem, nelem, (signed char *) array, |
| status); |
| } |
| else if (datatype == TUSHORT) |
| { |
| ffpclui(fptr, colnum, firstrow, firstelem, nelem, |
| (unsigned short *) array, status); |
| } |
| else if (datatype == TSHORT) |
| { |
| ffpcli(fptr, colnum, firstrow, firstelem, nelem, (short *) array, |
| status); |
| } |
| else if (datatype == TUINT) |
| { |
| ffpcluk(fptr, colnum, firstrow, firstelem, nelem, (unsigned int *) array, |
| status); |
| } |
| else if (datatype == TINT) |
| { |
| ffpclk(fptr, colnum, firstrow, firstelem, nelem, (int *) array, |
| status); |
| } |
| else if (datatype == TULONG) |
| { |
| ffpcluj(fptr, colnum, firstrow, firstelem, nelem, (unsigned long *) array, |
| status); |
| } |
| else if (datatype == TLONG) |
| { |
| ffpclj(fptr, colnum, firstrow, firstelem, nelem, (long *) array, |
| status); |
| } |
| else if (datatype == TULONGLONG) |
| { |
| ffpclujj(fptr, colnum, firstrow, firstelem, nelem, (ULONGLONG *) array, |
| status); |
| } |
| else if (datatype == TLONGLONG) |
| { |
| ffpcljj(fptr, colnum, firstrow, firstelem, nelem, (LONGLONG *) array, |
| status); |
| } |
| else if (datatype == TFLOAT) |
| { |
| ffpcle(fptr, colnum, firstrow, firstelem, nelem, (float *) array, |
| status); |
| } |
| else if (datatype == TDOUBLE) |
| { |
| ffpcld(fptr, colnum, firstrow, firstelem, nelem, (double *) array, |
| status); |
| } |
| else if (datatype == TCOMPLEX) |
| { |
| ffpcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2, |
| (float *) array, status); |
| } |
| else if (datatype == TDBLCOMPLEX) |
| { |
| ffpcld(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2, |
| (double *) array, status); |
| } |
| else if (datatype == TLOGICAL) |
| { |
| ffpcll(fptr, colnum, firstrow, firstelem, nelem, (char *) array, |
| status); |
| } |
| else if (datatype == TSTRING) |
| { |
| ffpcls(fptr, colnum, firstrow, firstelem, nelem, (char **) array, |
| status); |
| } |
| else |
| *status = BAD_DATATYPE; |
|
|
| return(*status); |
| } |
| |
| int ffpcn( fitsfile *fptr, |
| int datatype, |
| int colnum, |
| LONGLONG firstrow, |
| LONGLONG firstelem, |
| LONGLONG nelem, |
| void *array, |
| void *nulval, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| { |
| if (*status > 0) |
| return(*status); |
|
|
| if (nulval == NULL) |
| { |
| ffpcl(fptr, datatype, colnum, firstrow, firstelem, nelem, array, |
| status); |
| return(*status); |
| } |
|
|
| if (datatype == TBYTE) |
| { |
| ffpcnb(fptr, colnum, firstrow, firstelem, nelem, (unsigned char *) array, |
| *(unsigned char *) nulval, status); |
| } |
| else if (datatype == TSBYTE) |
| { |
| ffpcnsb(fptr, colnum, firstrow, firstelem, nelem, (signed char *) array, |
| *(signed char *) nulval, status); |
| } |
| else if (datatype == TUSHORT) |
| { |
| ffpcnui(fptr, colnum, firstrow, firstelem, nelem, (unsigned short *) array, |
| *(unsigned short *) nulval, status); |
| } |
| else if (datatype == TSHORT) |
| { |
| ffpcni(fptr, colnum, firstrow, firstelem, nelem, (short *) array, |
| *(unsigned short *) nulval, status); |
| } |
| else if (datatype == TUINT) |
| { |
| ffpcnuk(fptr, colnum, firstrow, firstelem, nelem, (unsigned int *) array, |
| *(unsigned int *) nulval, status); |
| } |
| else if (datatype == TINT) |
| { |
| ffpcnk(fptr, colnum, firstrow, firstelem, nelem, (int *) array, |
| *(int *) nulval, status); |
| } |
| else if (datatype == TULONG) |
| { |
| ffpcnuj(fptr, colnum, firstrow, firstelem, nelem, (unsigned long *) array, |
| *(unsigned long *) nulval, status); |
| } |
| else if (datatype == TLONG) |
| { |
| ffpcnj(fptr, colnum, firstrow, firstelem, nelem, (long *) array, |
| *(long *) nulval, status); |
| } |
| else if (datatype == TULONGLONG) |
| { |
| ffpcnujj(fptr, colnum, firstrow, firstelem, nelem, (ULONGLONG *) array, |
| *(ULONGLONG *) nulval, status); |
| } |
| else if (datatype == TLONGLONG) |
| { |
| ffpcnjj(fptr, colnum, firstrow, firstelem, nelem, (LONGLONG *) array, |
| *(LONGLONG *) nulval, status); |
| } |
| else if (datatype == TFLOAT) |
| { |
| ffpcne(fptr, colnum, firstrow, firstelem, nelem, (float *) array, |
| *(float *) nulval, status); |
| } |
| else if (datatype == TDOUBLE) |
| { |
| ffpcnd(fptr, colnum, firstrow, firstelem, nelem, (double *) array, |
| *(double *) nulval, status); |
| } |
| else if (datatype == TCOMPLEX) |
| { |
| ffpcne(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2, |
| (float *) array, *(float *) nulval, status); |
| } |
| else if (datatype == TDBLCOMPLEX) |
| { |
| ffpcnd(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2, |
| (double *) array, *(double *) nulval, status); |
| } |
| else if (datatype == TLOGICAL) |
| { |
| ffpcnl(fptr, colnum, firstrow, firstelem, nelem, (char *) array, |
| *(char *) nulval, status); |
| } |
| else if (datatype == TSTRING) |
| { |
| ffpcns(fptr, colnum, firstrow, firstelem, nelem, (char **) array, |
| (char *) nulval, status); |
| } |
| else |
| *status = BAD_DATATYPE; |
|
|
| return(*status); |
| } |
| |
| int fits_iter_set_by_name(iteratorCol *col, |
| fitsfile *fptr, |
| char *colname, |
| int datatype, |
| int iotype) |
| |
| |
| |
| { |
| col->fptr = fptr; |
| strncpy(col->colname, colname,69); |
| col->colname[69]=0; |
| col->colnum = 0; |
| col->datatype = datatype; |
| col->iotype = iotype; |
| return(0); |
| } |
| |
| int fits_iter_set_by_num(iteratorCol *col, |
| fitsfile *fptr, |
| int colnum, |
| int datatype, |
| int iotype) |
| |
| |
| |
| { |
| col->fptr = fptr; |
| col->colnum = colnum; |
| col->datatype = datatype; |
| col->iotype = iotype; |
| return(0); |
| } |
| |
| int fits_iter_set_file(iteratorCol *col, |
| fitsfile *fptr) |
| |
| |
| |
| { |
| col->fptr = fptr; |
| return(0); |
| } |
| |
| int fits_iter_set_colname(iteratorCol *col, |
| char *colname) |
| |
| |
| |
| { |
| strncpy(col->colname, colname,69); |
| col->colname[69]=0; |
| col->colnum = 0; |
| return(0); |
| } |
| |
| int fits_iter_set_colnum(iteratorCol *col, |
| int colnum) |
| |
| |
| |
| { |
| col->colnum = colnum; |
| return(0); |
| } |
| |
| int fits_iter_set_datatype(iteratorCol *col, |
| int datatype) |
| |
| |
| |
| { |
| col->datatype = datatype; |
| return(0); |
| } |
| |
| int fits_iter_set_iotype(iteratorCol *col, |
| int iotype) |
| |
| |
| |
| { |
| col->iotype = iotype; |
| return(0); |
| } |
| |
| fitsfile * fits_iter_get_file(iteratorCol *col) |
| |
| |
| |
| { |
| return(col->fptr); |
| } |
| |
| char * fits_iter_get_colname(iteratorCol *col) |
| |
| |
| |
| { |
| return(col->colname); |
| } |
| |
| int fits_iter_get_colnum(iteratorCol *col) |
| |
| |
| |
| { |
| return(col->colnum); |
| } |
| |
| int fits_iter_get_datatype(iteratorCol *col) |
| |
| |
| |
| { |
| return(col->datatype); |
| } |
| |
| int fits_iter_get_iotype(iteratorCol *col) |
| |
| |
| |
| { |
| return(col->iotype); |
| } |
| |
| void * fits_iter_get_array(iteratorCol *col) |
| |
| |
| |
| { |
| return(col->array); |
| } |
| |
| long fits_iter_get_tlmin(iteratorCol *col) |
| |
| |
| |
| { |
| return(col->tlmin); |
| } |
| |
| long fits_iter_get_tlmax(iteratorCol *col) |
| |
| |
| |
| { |
| return(col->tlmax); |
| } |
| |
| long fits_iter_get_repeat(iteratorCol *col) |
| |
| |
| |
| { |
| return(col->repeat); |
| } |
| |
| char * fits_iter_get_tunit(iteratorCol *col) |
| |
| |
| |
| { |
| return(col->tunit); |
| } |
| |
| char * fits_iter_get_tdisp(iteratorCol *col) |
| |
| |
| |
| { |
| return(col->tdisp); |
| } |
| |
| int ffiter(int n_cols, |
| iteratorCol *cols, |
| long offset, |
| long n_per_loop, |
| int (*work_fn)(long total_n, |
| long offset, |
| long first_n, |
| long n_values, |
| int n_cols, |
| iteratorCol *cols, |
| void *userPointer), |
| void *userPointer, |
| int *status) |
| |
| |
| |
| |
| |
| |
| |
| |
| { |
| typedef struct /* structure to store the column null value */ |
| { |
| int nullsize; |
| union { |
| char *stringnull; |
| unsigned char charnull; |
| signed char scharnull; |
| int intnull; |
| short shortnull; |
| long longnull; |
| unsigned int uintnull; |
| unsigned short ushortnull; |
| unsigned long ulongnull; |
| float floatnull; |
| double doublenull; |
| LONGLONG longlongnull; |
| } null; |
| } colNulls; |
|
|
| void *dataptr, *defaultnull; |
| colNulls *col; |
| int ii, jj, tstatus, naxis, bitpix; |
| int typecode, hdutype, jtype, type, anynul, nfiles, nbytes; |
| long totaln, nleft, frow, felement, n_optimum, i_optimum, ntodo; |
| long rept, rowrept, width, tnull, naxes[9] = {1,1,1,1,1,1,1,1,1}, groups; |
| double zeros = 0.; |
| char message[FLEN_ERRMSG], keyname[FLEN_KEYWORD], nullstr[FLEN_VALUE]; |
| char **stringptr, *nullptr, *cptr; |
|
|
| if (*status > 0) |
| return(*status); |
|
|
| if (n_cols < 0 || n_cols > 999 ) |
| { |
| ffpmsg("Illegal number of columms (ffiter)"); |
| return(*status = BAD_COL_NUM); |
| } |
|
|
| |
| |
| |
| |
| |
|
|
| ffghdt(cols[0].fptr, &hdutype, status); |
|
|
| for (jj = 0; jj < n_cols; jj++) |
| { |
| |
| type = cols[jj].datatype; |
|
|
| |
| |
| |
|
|
| if ((cols[jj].iotype != OutputCol) && (type<0)) { |
| type*=-1; |
| } |
|
|
| if (type != 0 && type != TBYTE && |
| type != TSBYTE && type != TLOGICAL && type != TSTRING && |
| type != TSHORT && type != TINT && type != TLONG && |
| type != TFLOAT && type != TDOUBLE && type != TCOMPLEX && |
| type != TULONG && type != TUSHORT && type != TDBLCOMPLEX && |
| type != TLONGLONG ) |
| { |
| if (type < 0) { |
| snprintf(message,FLEN_ERRMSG, |
| "Variable length array not allowed for output column number %d (ffiter)", |
| jj + 1); |
| } else { |
| snprintf(message,FLEN_ERRMSG, |
| "Illegal datatype for column number %d: %d (ffiter)", |
| jj + 1, cols[jj].datatype); |
| } |
| |
| ffpmsg(message); |
| return(*status = BAD_DATATYPE); |
| } |
|
|
| |
| cols[jj].tlmin = 0; |
| cols[jj].tlmax = 0; |
| cols[jj].tunit[0] = '\0'; |
| cols[jj].tdisp[0] = '\0'; |
|
|
| ffghdt(cols[jj].fptr, &jtype, status); |
|
|
| if (hdutype == IMAGE_HDU) |
| { |
| if (jtype != IMAGE_HDU) |
| { |
| snprintf(message,FLEN_ERRMSG, |
| "File %d not positioned to an image extension (ffiter)", |
| jj + 1); |
| return(*status = NOT_IMAGE); |
| } |
|
|
| |
| cols[jj].colnum = 0; |
| strcpy(cols[jj].colname, "IMAGE"); |
|
|
| tstatus = 0; |
| ffgkys(cols[jj].fptr, "BUNIT", cols[jj].tunit, 0, &tstatus); |
| } |
| else |
| { |
| if (jtype == IMAGE_HDU) |
| { |
| snprintf(message,FLEN_ERRMSG, |
| "File %d not positioned to a table extension (ffiter)", |
| jj + 1); |
| return(*status = NOT_TABLE); |
| } |
|
|
| if (cols[jj].colnum < 1) |
| { |
| |
| if (ffgcno(cols[jj].fptr, CASEINSEN, cols[jj].colname, |
| &cols[jj].colnum, status) ) |
| { |
| snprintf(message,FLEN_ERRMSG, |
| "Column '%s' not found for column number %d (ffiter)", |
| cols[jj].colname, jj + 1); |
| ffpmsg(message); |
| return(*status); |
| } |
| } |
|
|
| |
| if (cols[jj].colnum < 1 || |
| cols[jj].colnum > ((cols[jj].fptr)->Fptr)->tfield) |
| { |
| snprintf(message,FLEN_ERRMSG, |
| "Column %d has illegal table position number: %d (ffiter)", |
| jj + 1, cols[jj].colnum); |
| ffpmsg(message); |
| return(*status = BAD_COL_NUM); |
| } |
|
|
| |
| tstatus = 0; |
| ffkeyn("TLMIN", cols[jj].colnum, keyname, &tstatus); |
| ffgkyj(cols[jj].fptr, keyname, &cols[jj].tlmin, 0, &tstatus); |
|
|
| tstatus = 0; |
| ffkeyn("TLMAX", cols[jj].colnum, keyname, &tstatus); |
| ffgkyj(cols[jj].fptr, keyname, &cols[jj].tlmax, 0, &tstatus); |
|
|
| tstatus = 0; |
| ffkeyn("TTYPE", cols[jj].colnum, keyname, &tstatus); |
| ffgkys(cols[jj].fptr, keyname, cols[jj].colname, 0, &tstatus); |
| if (tstatus) |
| cols[jj].colname[0] = '\0'; |
|
|
| tstatus = 0; |
| ffkeyn("TUNIT", cols[jj].colnum, keyname, &tstatus); |
| ffgkys(cols[jj].fptr, keyname, cols[jj].tunit, 0, &tstatus); |
|
|
| tstatus = 0; |
| ffkeyn("TDISP", cols[jj].colnum, keyname, &tstatus); |
| ffgkys(cols[jj].fptr, keyname, cols[jj].tdisp, 0, &tstatus); |
| } |
| } |
|
|
| |
| |
| |
|
|
| offset = maxvalue(offset, 0L); |
|
|
| if (hdutype == IMAGE_HDU) |
| { |
| fits_get_img_dim(cols[0].fptr, &naxis, status); |
| fits_get_img_size(cols[0].fptr, 9, naxes, status); |
|
|
| tstatus = 0; |
| ffgkyj(cols[0].fptr, "GROUPS", &groups, NULL, &tstatus); |
| if (!tstatus && groups && (naxis > 1) && (naxes[0] == 0) ) |
| { |
| |
| |
| |
| ffgkyj(cols[0].fptr, "GCOUNT", &totaln, NULL, status); |
|
|
| } else { |
| totaln = naxes[0]; |
| } |
|
|
| for (ii = 1; ii < naxis; ii++) |
| totaln *= naxes[ii]; |
|
|
| frow = 1; |
| felement = 1 + offset; |
| } |
| else |
| { |
| ffgkyj(cols[0].fptr, "NAXIS2", &totaln, 0, status); |
| frow = 1 + offset; |
| felement = 1; |
| } |
|
|
| |
| totaln -= offset; |
| totaln = maxvalue(totaln, 0L); |
|
|
| |
| |
| |
|
|
| if (n_per_loop == 0) |
| { |
| |
| |
| |
|
|
| nfiles = 1; |
| ffgrsz(cols[0].fptr, &n_optimum, status); |
|
|
| for (jj = 1; jj < n_cols; jj++) |
| { |
| for (ii = 0; ii < jj; ii++) |
| { |
| if (cols[ii].fptr == cols[jj].fptr) |
| break; |
| } |
|
|
| if (ii == jj) |
| { |
| nfiles++; |
| ffgrsz(cols[jj].fptr, &i_optimum, status); |
| n_optimum = minvalue(n_optimum, i_optimum); |
| } |
| } |
|
|
| |
| n_optimum = n_optimum / nfiles; |
| n_optimum = maxvalue(n_optimum, 1); |
| } |
| else if (n_per_loop < 0) |
| { |
| n_optimum = totaln; |
| } |
| else |
| { |
| n_optimum = minvalue(n_per_loop, totaln); |
| } |
|
|
| |
| |
| |
| |
|
|
| col = calloc(n_cols, sizeof(colNulls) ); |
| if (!col) |
| { |
| ffpmsg("ffiter failed to allocate memory for null values"); |
| *status = MEMORY_ALLOCATION; |
| return(*status); |
| } |
|
|
| for (jj = 0; jj < n_cols; jj++) |
| { |
| |
| if (hdutype == IMAGE_HDU) |
| { |
| fits_get_img_type(cols[jj].fptr, &bitpix, status); |
| switch(bitpix) { |
| case BYTE_IMG: |
| typecode = TBYTE; |
| break; |
| case SHORT_IMG: |
| typecode = TSHORT; |
| break; |
| case LONG_IMG: |
| typecode = TLONG; |
| break; |
| case FLOAT_IMG: |
| typecode = TFLOAT; |
| break; |
| case DOUBLE_IMG: |
| typecode = TDOUBLE; |
| break; |
| case LONGLONG_IMG: |
| typecode = TLONGLONG; |
| break; |
| } |
| } |
| else |
| { |
| if (ffgtcl(cols[jj].fptr, cols[jj].colnum, &typecode, &rept, |
| &width, status) > 0) |
| goto cleanup; |
| |
| if (typecode < 0) { |
| n_optimum = 1; |
| |
| |
| |
| |
|
|
| if (cols[jj].iotype == OutputCol) { |
| snprintf(message,FLEN_ERRMSG, |
| "Variable length array not allowed for output column number %d (ffiter)", |
| jj + 1); |
| ffpmsg(message); |
| return(*status = BAD_DATATYPE); |
| } |
| } |
| } |
|
|
| |
| if (abs(typecode) == TLONG && sizeof(long) == 8 && sizeof(int) == 4) { |
| if(typecode<0) { |
| typecode = -TINT; |
| } else { |
| typecode = TINT; |
| } |
| } |
|
|
| |
| if (abs(typecode) == TBIT) |
| { |
| typecode = typecode / TBIT * TBYTE; |
| rept = (rept + 7) / 8; |
| } |
|
|
| if (cols[jj].datatype == 0) |
| { |
| |
| if (abs(typecode) == TLONG && sizeof(long) == 8 && sizeof(int) == 4) |
| cols[jj].datatype = TINT; |
| else |
| cols[jj].datatype = abs(typecode); |
| } |
|
|
| |
| if (hdutype == IMAGE_HDU || cols[jj].datatype == TSTRING) |
| { |
| ntodo = n_optimum; |
| cols[jj].repeat = 1; |
|
|
| |
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| tstatus = 0; |
| ffgkyj(cols[jj].fptr, "BLANK", &tnull, 0, &tstatus); |
| if (tstatus) |
| { |
| tnull = 0L; |
| } |
| } |
| } |
| else |
| { |
| if (typecode < 0) |
| { |
| |
| |
| rept = 1; |
| for (ii = 0; ii < totaln; ii++) { |
| ffgdes(cols[jj].fptr, cols[jj].colnum, frow + ii, &rowrept, NULL, status); |
| |
| rept = maxvalue(rept, rowrept); |
| } |
| } |
| |
| ntodo = n_optimum * rept; |
| cols[jj].repeat = rept; |
|
|
| |
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| tstatus = 0; |
| if (hdutype == ASCII_TBL) |
| { |
| ffkeyn("TNULL", cols[jj].colnum, keyname, &tstatus); |
| ffgkys(cols[jj].fptr, keyname, nullstr, 0, &tstatus); |
| if (tstatus) |
| { |
| tnull = 0L; |
| } |
| else |
| { |
| cptr = nullstr; |
| while (*cptr == ' ') |
| cptr++; |
|
|
| if (*cptr == '\0') |
| tnull = LONG_MIN; |
| else |
| { |
| |
| ffc2ii(nullstr, &tnull, &tstatus); |
|
|
| if (tstatus) |
| tnull = LONG_MIN; |
| } |
| } |
| } |
| else |
| { |
| ffkeyn("TNULL", cols[jj].colnum, keyname, &tstatus); |
| ffgkyj(cols[jj].fptr, keyname, &tnull, 0, &tstatus); |
| if (tstatus) |
| { |
| tnull = 0L; |
| } |
| else if (tnull == 0) |
| { |
| |
| |
| |
| |
| |
|
|
| tnull = LONG_MIN; |
| } |
| } |
| } |
| } |
|
|
| |
| |
|
|
| switch (cols[jj].datatype) |
| { |
| case TBYTE: |
| cols[jj].array = calloc(ntodo + 1, sizeof(char)); |
| col[jj].nullsize = sizeof(char); |
|
|
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| tnull = minvalue(tnull, 255); |
| tnull = maxvalue(tnull, 0); |
| col[jj].null.charnull = (unsigned char) tnull; |
| } |
| else |
| { |
| col[jj].null.charnull = (unsigned char) 255; |
| } |
| break; |
|
|
| case TSBYTE: |
| cols[jj].array = calloc(ntodo + 1, sizeof(char)); |
| col[jj].nullsize = sizeof(char); |
|
|
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| tnull = minvalue(tnull, 127); |
| tnull = maxvalue(tnull, -128); |
| col[jj].null.scharnull = (signed char) tnull; |
| } |
| else |
| { |
| col[jj].null.scharnull = (signed char) -128; |
| } |
| break; |
|
|
| case TSHORT: |
| cols[jj].array = calloc(ntodo + 1, sizeof(short)); |
| col[jj].nullsize = sizeof(short); |
|
|
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| tnull = minvalue(tnull, SHRT_MAX); |
| tnull = maxvalue(tnull, SHRT_MIN); |
| col[jj].null.shortnull = (short) tnull; |
| } |
| else |
| { |
| col[jj].null.shortnull = SHRT_MIN; |
| } |
| break; |
|
|
| case TUSHORT: |
| cols[jj].array = calloc(ntodo + 1, sizeof(unsigned short)); |
| col[jj].nullsize = sizeof(unsigned short); |
|
|
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| tnull = minvalue(tnull, (long) USHRT_MAX); |
| tnull = maxvalue(tnull, 0); |
| col[jj].null.ushortnull = (unsigned short) tnull; |
| } |
| else |
| { |
| col[jj].null.ushortnull = USHRT_MAX; |
| } |
| break; |
|
|
| case TINT: |
| cols[jj].array = calloc(sizeof(int), ntodo + 1); |
| col[jj].nullsize = sizeof(int); |
|
|
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| tnull = minvalue(tnull, INT_MAX); |
| tnull = maxvalue(tnull, INT_MIN); |
| col[jj].null.intnull = (int) tnull; |
| } |
| else |
| { |
| col[jj].null.intnull = INT_MIN; |
| } |
| break; |
|
|
| case TUINT: |
| cols[jj].array = calloc(ntodo + 1, sizeof(unsigned int)); |
| col[jj].nullsize = sizeof(unsigned int); |
|
|
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| tnull = minvalue(tnull, INT32_MAX); |
| tnull = maxvalue(tnull, 0); |
| col[jj].null.uintnull = (unsigned int) tnull; |
| } |
| else |
| { |
| col[jj].null.uintnull = UINT_MAX; |
| } |
| break; |
|
|
| case TLONG: |
| cols[jj].array = calloc(ntodo + 1, sizeof(long)); |
| col[jj].nullsize = sizeof(long); |
|
|
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| col[jj].null.longnull = tnull; |
| } |
| else |
| { |
| col[jj].null.longnull = LONG_MIN; |
| } |
| break; |
|
|
| case TULONG: |
| cols[jj].array = calloc(ntodo + 1, sizeof(unsigned long)); |
| col[jj].nullsize = sizeof(unsigned long); |
|
|
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| if (tnull < 0) |
| col[jj].null.ulongnull = LONG_MAX; |
| else |
| col[jj].null.ulongnull = (unsigned long) tnull; |
| } |
| else |
| { |
| col[jj].null.ulongnull = LONG_MAX; |
| } |
| break; |
|
|
| case TFLOAT: |
| cols[jj].array = calloc(ntodo + 1, sizeof(float)); |
| col[jj].nullsize = sizeof(float); |
|
|
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| col[jj].null.floatnull = (float) tnull; |
| } |
| else |
| { |
| col[jj].null.floatnull = FLOATNULLVALUE; |
| } |
| break; |
|
|
| case TCOMPLEX: |
| cols[jj].array = calloc((ntodo * 2) + 1, sizeof(float)); |
| col[jj].nullsize = sizeof(float); |
| col[jj].null.floatnull = FLOATNULLVALUE; |
| break; |
|
|
| case TDOUBLE: |
| cols[jj].array = calloc(ntodo + 1, sizeof(double)); |
| col[jj].nullsize = sizeof(double); |
|
|
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG |
| || abs(typecode) == TINT || abs(typecode) == TLONGLONG) |
| { |
| col[jj].null.doublenull = (double) tnull; |
| } |
| else |
| { |
| col[jj].null.doublenull = DOUBLENULLVALUE; |
| } |
| break; |
|
|
| case TDBLCOMPLEX: |
| cols[jj].array = calloc((ntodo * 2) + 1, sizeof(double)); |
| col[jj].nullsize = sizeof(double); |
| col[jj].null.doublenull = DOUBLENULLVALUE; |
| break; |
|
|
| case TSTRING: |
| |
| if( hdutype==ASCII_TBL ) rept = width; |
| stringptr = calloc((ntodo + 1) , sizeof(stringptr)); |
| cols[jj].array = stringptr; |
| col[jj].nullsize = rept + 1; |
|
|
| if (stringptr) |
| { |
| |
| col[jj].null.stringnull = calloc(rept + 1, sizeof(char) ); |
| col[jj].null.stringnull[1] = 1; |
|
|
| |
| stringptr[0] = calloc((ntodo + 1) * (rept + 1), sizeof(char) ); |
|
|
| if (stringptr[0]) |
| { |
| for (ii = 1; ii <= ntodo; ii++) |
| { |
| stringptr[ii] = stringptr[ii - 1] + (rept + 1); |
| } |
|
|
| |
| tstatus = 0; |
| ffkeyn("TNULL", cols[jj].colnum, keyname, &tstatus); |
| ffgkys(cols[jj].fptr, keyname, nullstr, 0, &tstatus); |
| if (!tstatus) |
| strncat(col[jj].null.stringnull, nullstr, rept); |
| } |
| else |
| { |
| ffpmsg("ffiter failed to allocate memory arrays"); |
| *status = MEMORY_ALLOCATION; |
| goto cleanup; |
| } |
| } |
| break; |
|
|
| case TLOGICAL: |
|
|
| cols[jj].array = calloc(ntodo + 1, sizeof(char)); |
| col[jj].nullsize = sizeof(char); |
|
|
| |
| col[jj].null.charnull = 2; |
| break; |
|
|
| case TLONGLONG: |
| cols[jj].array = calloc(ntodo + 1, sizeof(LONGLONG)); |
| col[jj].nullsize = sizeof(LONGLONG); |
|
|
| if (abs(typecode) == TBYTE || abs(typecode) == TSHORT || abs(typecode) == TLONG || |
| abs(typecode) == TLONGLONG || abs(typecode) == TINT) |
| { |
| col[jj].null.longlongnull = tnull; |
| } |
| else |
| { |
| col[jj].null.longlongnull = LONGLONG_MIN; |
| } |
| break; |
|
|
| default: |
| snprintf(message,FLEN_ERRMSG, |
| "Column %d datatype currently not supported: %d: (ffiter)", |
| jj + 1, cols[jj].datatype); |
| ffpmsg(message); |
| *status = BAD_DATATYPE; |
| goto cleanup; |
|
|
| } |
|
|
| |
| if (!cols[jj].array) |
| { |
| ffpmsg("ffiter failed to allocate memory arrays"); |
| *status = MEMORY_ALLOCATION; |
| goto cleanup; |
| } |
| } |
|
|
| |
| |
| |
|
|
| nleft = totaln; |
|
|
| while (nleft) |
| { |
| ntodo = minvalue(nleft, n_optimum); |
|
|
| |
| for (jj = 0; jj < n_cols; jj++) |
| { |
| if (cols[jj].iotype != OutputCol) |
| { |
| if (cols[jj].datatype == TSTRING) |
| { |
| stringptr = cols[jj].array; |
| dataptr = stringptr + 1; |
| defaultnull = col[jj].null.stringnull; |
| } |
| else |
| { |
| dataptr = (char *) cols[jj].array + col[jj].nullsize; |
| defaultnull = &col[jj].null.charnull; |
| } |
|
|
| if (hdutype == IMAGE_HDU) |
| { |
| if (ffgpv(cols[jj].fptr, cols[jj].datatype, |
| felement, cols[jj].repeat * ntodo, defaultnull, |
| dataptr, &anynul, status) > 0) |
| { |
| break; |
| } |
| } |
| else |
| { |
| if (ffgtcl(cols[jj].fptr, cols[jj].colnum, &typecode, &rept,&width, status) > 0) |
| goto cleanup; |
| |
| if (typecode<0) |
| { |
| |
| ffgdes(cols[jj].fptr, cols[jj].colnum, frow,&cols[jj].repeat, NULL,status); |
| } |
| |
| if (ffgcv(cols[jj].fptr, cols[jj].datatype, cols[jj].colnum, |
| frow, felement, cols[jj].repeat * ntodo, defaultnull, |
| dataptr, &anynul, status) > 0) |
| { |
| break; |
| } |
| } |
|
|
| |
|
|
| if (anynul) |
| { |
| if (cols[jj].datatype == TSTRING) |
| { |
| stringptr = cols[jj].array; |
| memcpy(*stringptr, col[jj].null.stringnull, col[jj].nullsize); |
| } |
| else |
| { |
| memcpy(cols[jj].array, defaultnull, col[jj].nullsize); |
| } |
| } |
| else |
| { |
| if (cols[jj].datatype == TSTRING) |
| { |
| stringptr = cols[jj].array; |
| memset(*stringptr, 0, col[jj].nullsize); |
| } |
| else |
| { |
| memset(cols[jj].array, 0, col[jj].nullsize); |
| } |
| } |
| } |
| } |
|
|
| if (*status > 0) |
| break; |
|
|
| |
|
|
| if (hdutype == IMAGE_HDU) |
| *status = work_fn(totaln, offset, felement, ntodo, n_cols, cols, |
| userPointer); |
| else |
| *status = work_fn(totaln, offset, frow, ntodo, n_cols, cols, |
| userPointer); |
|
|
| if (*status > 0 || *status < -1 ) |
| break; |
|
|
| |
| tstatus = 0; |
| for (jj = 0; jj < n_cols; jj++) |
| { |
| if (cols[jj].iotype != InputCol) |
| { |
| if (cols[jj].datatype == TSTRING) |
| { |
| stringptr = cols[jj].array; |
| dataptr = stringptr + 1; |
| nullptr = *stringptr; |
| nbytes = 2; |
| } |
| else |
| { |
| dataptr = (char *) cols[jj].array + col[jj].nullsize; |
| nullptr = (char *) cols[jj].array; |
| nbytes = col[jj].nullsize; |
| } |
|
|
| if (memcmp(nullptr, &zeros, nbytes) ) |
| { |
| |
| if (hdutype == IMAGE_HDU) |
| { |
| if (ffppn(cols[jj].fptr, cols[jj].datatype, |
| felement, cols[jj].repeat * ntodo, dataptr, |
| nullptr, &tstatus) > 0) |
| break; |
| } |
| else |
| { |
| if (ffgtcl(cols[jj].fptr, cols[jj].colnum, &typecode, &rept,&width, status) > 0) |
| goto cleanup; |
| |
| if (typecode<0) |
| { |
| ffgdes(cols[jj].fptr, cols[jj].colnum, frow,&cols[jj].repeat, NULL,status); |
| } |
|
|
| if (ffpcn(cols[jj].fptr, cols[jj].datatype, cols[jj].colnum, frow, |
| felement, cols[jj].repeat * ntodo, dataptr, |
| nullptr, &tstatus) > 0) |
| break; |
| } |
| } |
| else |
| { |
| |
| if (hdutype == IMAGE_HDU) |
| { |
| if (ffppr(cols[jj].fptr, cols[jj].datatype, |
| felement, cols[jj].repeat * ntodo, dataptr, |
| &tstatus) > 0) |
| break; |
| } |
| else |
| { |
| if (ffgtcl(cols[jj].fptr, cols[jj].colnum, &typecode, &rept,&width, status) > 0) |
| goto cleanup; |
| |
| if (typecode<0) |
| { |
| ffgdes(cols[jj].fptr, cols[jj].colnum, frow,&cols[jj].repeat, NULL,status); |
| } |
|
|
| if (ffpcl(cols[jj].fptr, cols[jj].datatype, cols[jj].colnum, frow, |
| felement, cols[jj].repeat * ntodo, dataptr, |
| &tstatus) > 0) |
| break; |
| } |
| } |
| } |
| } |
|
|
| if (*status == 0) |
| *status = tstatus; |
|
|
| if (*status) |
| break; |
|
|
| nleft -= ntodo; |
|
|
| if (hdutype == IMAGE_HDU) |
| felement += ntodo; |
| else |
| frow += ntodo; |
| } |
|
|
| cleanup: |
|
|
| |
| |
| |
|
|
| for (jj = 0; jj < n_cols; jj++) |
| { |
| if (cols[jj].datatype == TSTRING) |
| { |
| if (cols[jj].array) |
| { |
| stringptr = cols[jj].array; |
| free(*stringptr); |
| free(col[jj].null.stringnull); |
| } |
| } |
| if (cols[jj].array) |
| free(cols[jj].array); |
| } |
| free(col); |
| return(*status); |
| } |
|
|
|
|