Ejemplo n.º 1
0
void main()
{
  NODE head1,head2,head3;
  MALLOC(head1,1,struct node);
  MALLOC(head2,1,struct node);
  MALLOC(head3,1,struct node);
  head1->link=head1;
  head2->link=head2;
  head3->link=head3;
  printf("enter the first polynomial\n");
  head1=read_polynomial(head1);
  printf("enter the second polynomial\n");
  head2=read_polynomial(head2);
  head3=poly_add(head1,head2,head3);
  printf("polynomial 1:");
  display(head1);
  printf("\npolynomial 2:");
  display(head2);
  printf("\npolynomial 3:");
  display(head3);
  getch();
}
Ejemplo n.º 2
0
sip_t* sip_read_header(const qfits_header* hdr, sip_t* dest) {
	sip_t sip;
	char* str;
	const char* key;
	const char* expect;
	const char* expect2;
	anbool is_sin;
	anbool is_tan;
	anbool skip_linear;
	anbool skip_zero;
    char pretty[FITS_LINESZ];

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

	key = "CTYPE1";
	expect  = "RA---TAN-SIP";
	expect2 = "RA---SIN-SIP";
	str = qfits_header_getstr(hdr, key);
	str = qfits_pretty_string_r(str, pretty);
	if (!str) {
		ERROR("SIP header: no key \"%s\"", key);
		return NULL;
	}
	is_tan = (strncmp(str, expect, strlen(expect)) == 0);
	is_sin = (strncmp(str, expect2, strlen(expect2)) == 0);
	if (!(is_tan || is_sin)) {
		if (!tan_read_header(hdr, &(sip.wcstan))) {
			ERROR("SIP: failed to read TAN header");
			return NULL;
		}
		goto gohome;
	}

	key = "CTYPE2";
	if (is_sin) {
		expect = "DEC--SIN-SIP";
	} else {
		expect = "DEC--TAN-SIP";
	}
	str = qfits_header_getstr(hdr, key);
	str = qfits_pretty_string_r(str, pretty);
	if (!str || strncmp(str, expect, strlen(expect))) {
		ERROR("SIP header: incorrect key \"%s\": expected \"%s\", got \"%s\"", key, expect, str);
		return NULL;
	}

	if (!tan_read_header(hdr, &sip.wcstan)) {
		ERROR("SIP: failed to read TAN header");
		return NULL;
	}

	sip.a_order  = qfits_header_getint(hdr, "A_ORDER", -1);
	sip.b_order  = qfits_header_getint(hdr, "B_ORDER", -1);
	sip.ap_order = qfits_header_getint(hdr, "AP_ORDER", 0);
	sip.bp_order = qfits_header_getint(hdr, "BP_ORDER", 0);

	if ((sip.a_order == -1) || 
		(sip.b_order == -1)) {
		ERROR("SIP: failed to read polynomial orders (A_ORDER=%i, B_ORDER=%i, -1 means absent)\n",
			  sip.a_order, sip.b_order);
		return NULL;
	}
	if ((sip.ap_order == 0) || 
		(sip.bp_order == 0)) {
		logverb("Warning: SIP: failed to read polynomial orders (A_ORDER=%i, B_ORDER=%i (-1 means absent), AP_ORDER=%i, BP_ORDER=%i, (0 means absent)\n",
				sip.a_order, sip.b_order, sip.ap_order, sip.bp_order);
	}

	if ((sip.a_order > SIP_MAXORDER) || 
		(sip.b_order > SIP_MAXORDER) || 
		(sip.ap_order > SIP_MAXORDER) || 
		(sip.bp_order > SIP_MAXORDER)) {
		ERROR("SIP: polynomial orders (A=%i, B=%i, AP=%i, BP=%i) exceeds maximum of %i",
              sip.a_order, sip.b_order, sip.ap_order, sip.bp_order, SIP_MAXORDER);
		return NULL;
	}

	skip_linear = FALSE;
	skip_zero = FALSE;

	if (!read_polynomial(hdr, "A_%i_%i",  sip.a_order,  (double*)sip.a,  SIP_MAXORDER, skip_linear, skip_zero) ||
		!read_polynomial(hdr, "B_%i_%i",  sip.b_order,  (double*)sip.b,  SIP_MAXORDER, skip_linear, skip_zero) ||
		(sip.ap_order > 0 && !read_polynomial(hdr, "AP_%i_%i", sip.ap_order, (double*)sip.ap, SIP_MAXORDER, FALSE, FALSE)) ||
		(sip.bp_order > 0 && !read_polynomial(hdr, "BP_%i_%i", sip.bp_order, (double*)sip.bp, SIP_MAXORDER, FALSE, FALSE))) {
		ERROR("SIP: failed to read polynomial terms");
		return NULL;
	}

 gohome:
	if (!dest)
		dest = malloc(sizeof(sip_t));

	memcpy(dest, &sip, sizeof(sip_t));
	return dest;
}