int linini_(const int *naxis, int *lin) { return linini(1, *naxis, (struct linprm *)lin); }
int lincpy(int alloc, const struct linprm *linsrc, struct linprm *lindst) { static const char *function = "lincpy"; int i, j, naxis, status; const double *srcp; double *dstp; struct wcserr **err; if (linsrc == 0x0) return LINERR_NULL_POINTER; if (lindst == 0x0) return LINERR_NULL_POINTER; err = &(lindst->err); naxis = linsrc->naxis; if (naxis < 1) { return wcserr_set(WCSERR_SET(LINERR_MEMORY), "naxis must be positive (got %d)", naxis); } if ((status = linini(alloc, naxis, lindst))) { return status; } srcp = linsrc->crpix; dstp = lindst->crpix; for (j = 0; j < naxis; j++) { *(dstp++) = *(srcp++); } srcp = linsrc->pc; dstp = lindst->pc; for (i = 0; i < naxis; i++) { for (j = 0; j < naxis; j++) { *(dstp++) = *(srcp++); } } srcp = linsrc->cdelt; dstp = lindst->cdelt; for (i = 0; i < naxis; i++) { *(dstp++) = *(srcp++); } if (linsrc->dispre) { if (!lindst->dispre) { if ((lindst->dispre = calloc(1, sizeof(struct disprm))) == 0x0) { return wcserr_set(LIN_ERRMSG(LINERR_MEMORY)); } lindst->m_dispre = lindst->dispre; } if ((status = discpy(alloc, linsrc->dispre, lindst->dispre))) { status = wcserr_set(LIN_ERRMSG(lin_diserr[status])); goto cleanup; } } if (linsrc->disseq) { if (!lindst->disseq) { if ((lindst->disseq = calloc(1, sizeof(struct disprm))) == 0x0) { return wcserr_set(LIN_ERRMSG(LINERR_MEMORY)); } lindst->m_disseq = lindst->disseq; } if ((status = discpy(alloc, linsrc->disseq, lindst->disseq))) { status = wcserr_set(LIN_ERRMSG(lin_diserr[status])); goto cleanup; } } cleanup: if (status && (lindst->m_dispre || lindst->m_disseq)) { if (lindst->dispre) free(lindst->dispre); if (lindst->disseq) free(lindst->disseq); lindst->dispre = 0x0; lindst->disseq = 0x0; } return status; }
int main() { int i, j, k, nFail, status; double img[2][9], *pcij, pix[2][9], resid, residmax; struct linprm lin; printf("Testing WCSLIB linear transformation routines (tlin.c)\n" "------------------------------------------------------\n"); /* List status return messages. */ printf("\nList of lin status return values:\n"); for (status = 1; status <= 3; status++) { printf("%4d: %s.\n", status, lin_errmsg[status]); } lin.flag = -1; linini(1, NAXIS, &lin); pcij = lin.pc; for (i = 0; i < lin.naxis; i++) { lin.crpix[i] = CRPIX[i]; for (j = 0; j < lin.naxis; j++) { *(pcij++) = PC[i][j]; } lin.cdelt[i] = CDELT[i]; } for (k = 0; k < NCOORD; k++) { printf("\nPIX %d:", k+1); for (j = 0; j < NAXIS; j++) { printf("%14.8f", pix0[k][j]); } } printf("\n"); if ((status = linp2x(&lin, NCOORD, NELEM, pix0[0], img[0]))) { printf("linp2x ERROR %d\n", status); return 1; } for (k = 0; k < NCOORD; k++) { printf("\nIMG %d:", k+1); for (j = 0; j < NAXIS; j++) { printf("%14.8f", img[k][j]); } } printf("\n"); if ((status = linx2p(&lin, NCOORD, NELEM, img[0], pix[0]))) { printf("linx2p ERROR %d\n", status); return 1; } for (k = 0; k < NCOORD; k++) { printf("\nPIX %d:", k+1); for (j = 0; j < NAXIS; j++) { printf("%14.8f", pix[k][j]); } } printf("\n"); /* Check closure. */ nFail = 0; residmax = 0.0; for (k = 0; k < NCOORD; k++) { for (j = 0; j < NAXIS; j++) { resid = fabs(pix[k][j] - pix0[k][j]); if (residmax < resid) residmax = resid; if (resid > tol) nFail++; } } printf("\nlinp2x/linx2p: Maximum closure residual = %.1e pixel.\n", residmax); linfree(&lin); if (nFail) { printf("\nFAIL: %d closure residuals exceed reporting tolerance.\n", nFail); } else { printf("\nPASS: All closure residuals are within reporting tolerance.\n"); } return nFail; }