示例#1
0
int main(int argc, char** args) {
	char* outfn = NULL;
	char* infn = NULL;
    int ext;
	int c;
    int loglvl = LOG_MSG;
    qfits_header* hdr;
    sip_t sip;

    while ((c = getopt(argc, args, OPTIONS)) != -1) {
        switch (c) {
		case '?':
        case 'h':
			print_help(args[0]);
			exit(0);
        case 'v':
            loglvl++;
            break;
        }
    }

    log_init(loglvl);

    if (optind != argc-3) {
        print_help(args[0]);
        exit(-1);
    }

    infn = args[optind+0];
    ext = atoi(args[optind+1]);
    outfn = args[optind+2];

    logmsg("Reading extension %i from file \"%s\"\n", ext, infn);
    hdr = anqfits_get_header2(infn, ext);
    if (!hdr) {
        ERROR("Failed to read header from extension %i of file \"%s\"\n", ext, infn);
        exit(-1);
    }

    if (!sip_read_header(hdr, &sip)) {
        ERROR("Failed to read SIP header.\n");
        exit(-1);
    }

    if (sip.a_order > 0) {
        logmsg("Got SIP header.\n");
    } else {
        logmsg("Got TAN header.\n");
    }

    logmsg("Writing to file \"%s\"\n", outfn);
    if (sip_write_to_file(&sip, outfn)) {
        ERROR("Failed to write SIP header to file \"%s\".\n", outfn);
        exit(-1);
    }

    qfits_header_destroy(hdr);

    return 0;
}
示例#2
0
sip_t* sip_from_string(const char* str, int slen, sip_t* dest) {
	qfits_header* hdr;
	sip_t* rtn;
	if (slen == 0) {
		slen = strlen(str);
	}
	hdr = qfits_header_read_hdr_string((const unsigned char*)str, slen);
	if (!hdr) {
		ERROR("Failed to parse a FITS header from the given string");
		return NULL;
	}
	rtn = sip_read_header(hdr, dest);
	qfits_header_destroy(hdr);
	return rtn;
}
void fits_guess_scale_hdr(const qfits_header* hdr,
                          sl** p_methods, dl** p_scales) {
	sip_t sip;
	double val;
	anbool gotsip = FALSE;
    char* errstr;

    sl* methods = NULL;
    dl* scales = NULL;

    if (p_methods) {
        if (!*p_methods)
            *p_methods = sl_new(4);
        methods = *p_methods;
    }
    if (p_scales) {
        if (!*p_scales)
            *p_scales = dl_new(4);
        scales = *p_scales;
    }

	memset(&sip, 0, sizeof(sip_t));

    errors_start_logging_to_string();

	if (sip_read_header(hdr, &sip)) {
        val = sip_pixel_scale(&sip);
        if (val != 0.0) {
            addscale(methods, scales, "sip", val);
            gotsip = TRUE;
		}
	}
    errstr = errors_stop_logging_to_string("\n  ");
    logverb("fits-guess-scale: failed to read SIP/TAN header:\n  %s\n", errstr);
    free(errstr);

	if (!gotsip) {
		// it might have a correct CD matrix but be missing other parts (eg CRVAL)
		double cd11, cd12, cd21, cd22;
		double errval = -HUGE_VAL;
		cd11 = qfits_header_getdouble(hdr, "CD1_1", errval);
		cd12 = qfits_header_getdouble(hdr, "CD1_2", errval);
		cd21 = qfits_header_getdouble(hdr, "CD2_1", errval);
		cd22 = qfits_header_getdouble(hdr, "CD2_2", errval);
		if ((cd11 != errval) && (cd12 != errval) && (cd21 != errval) && (cd22 != errval)) {
			val = cd11 * cd22 - cd12 * cd21;
			if (val != 0.0)
                addscale(methods, scales, "cd", sqrt(fabs(val)));
		}
	}

	val = qfits_header_getdouble(hdr, "PIXSCALE", -1.0);
	if (val != -1.0)
        addscale(methods, scales, "pixscale", val);

    /* Why all this?
     val = qfits_header_getdouble(hdr, "PIXSCAL1", -1.0);
     if (val != -1.0) {
     if (val != 0.0) {
     printf("scale pixscal1 %g\n", val);
     } else {
     val = atof(qfits_pretty_string(qfits_header_getstr(hdr, "PIXSCAL1")));
     if (val != 0.0) {
     printf("scale pixscal1 %g\n", val);
     }
     }
     }
     */

     val = qfits_header_getdouble(hdr, "PIXSCAL1", 0.0);
     if (val != 0.0)
         addscale(methods, scales, "pixscal1", val);

     val = qfits_header_getdouble(hdr, "PIXSCAL2", 0.0);
     if (val != 0.0)
         addscale(methods, scales, "pixscal2", val);

     val = qfits_header_getdouble(hdr, "PLATESC", 0.0);
     if (val != 0.0)
         addscale(methods, scales, "platesc", val);

	val = qfits_header_getdouble(hdr, "CCDSCALE", 0.0);
     if (val != 0.0)
         addscale(methods, scales, "ccdscale", val);

	val = qfits_header_getdouble(hdr, "CDELT1", 0.0);
     if (val != 0.0)
         addscale(methods, scales, "cdelt1", 3600.0 * fabs(val));
}
示例#4
0
// silly little dispatch function to avoid casting - I like a modicum of type safety
static void* call_sip_read_header(const qfits_header* hdr, void* dest) {
	return sip_read_header(hdr, dest);
}