コード例 #1
0
int main(int argc, char *argv[]) {
    float *x=NULL,*y=NULL,minx,maxx,miny,maxy,cx, *oparams=NULL,*nparams=NULL;
    float *rx=NULL,*ry=NULL,*w=NULL,*wparams=NULL,*wx=NULL,*wy=NULL,*ww=NULL;
    float *y_sault_fit=NULL, *x_fit=NULL, *y_new_fit=NULL, *y_reynolds_fit=NULL;
    float *y_stevens_fit=NULL,*y_whole_fit=NULL,*y_old_fit=NULL;
    int i,j,n=0,n_fit=100,new_fit_order=2,whole_fit_order=5,nr=0,nw=0;
    /* float extra_x[NEXTRA]={ 93, 95 }, extra_y[NEXTRA] = { 0.1223, 0.1168 }; */
    float extra_x[NEXTRA]= { 93, 95 }, extra_y[NEXTRA] = { 0.1116, 0.1056 };
    float extra_u[NEXTRA]= { 0.01356, 0.01399 };
    float fitp_sault[NFIT_SAULT]= { -202.6259, 149.7321, -36.4943, 2.9372 };
    float fitp_reynolds[NFIT_REYNOLDS]= { -30.7667, 26.4908, -7.0977, 0.605334 };
    float fitp_stevens[NFIT_STEVENS]= { -1.237160, 2.005317, -0.400622 };
    float fitp_old[NFIT_OLD]= { -23.839, 19.569, -4.8168, 0.35836 };
    float *ratio_reynolds_fit=NULL,*ratio_stevens_fit=NULL,*ratio_sault_fit=NULL;
    float *ratio_new_fit=NULL;
    float vpx1, vpx2, vpy1, vpy2, vpy3, lx, ly, dly;
    char fitlabel[BUFSIZE];

    /* Generate the cm fit points. */
    for (cx=1.0; cx<10.0; cx+=0.1) {
        nr++;
        rx = realloc(rx, nr * sizeof(float));
        ry = realloc(ry, nr * sizeof(float));
        rx[nr-1] = log10f(cx * 1000);
        ry[nr-1] = 0.0;
        for (i=0; i<NFIT_REYNOLDS; i++) {
            ry[nr-1] += fitp_reynolds[i] * powf(rx[n-1], (float)i);
        }
    }

    /* Generate the 15mm fit points. */
    for (cx=10.0; cx<=24.0; cx+=0.128) {
        n++;
        x = realloc(x, n * sizeof(float));
        y = realloc(y, n * sizeof(float));
        w = realloc(w, n * sizeof(float));
        x[n-1] = log10f(cx * 1000);
        y[n-1] = 0.0;
        for (i=0; i<NFIT_REYNOLDS; i++) {
            y[n-1] += fitp_sault[i] * powf(x[n-1], (float)i);
        }
        w[n-1] = 1.0/0.1;
    }

    /* Do the fit. */
    linfit_order(NFIT_SAULT, n, x, y, w, &oparams);
    for (i=0; i<NFIT_SAULT; i++) {
        printf("i = %d c[i] = %.4f\n", i, oparams[i]);
    }

    /* Add the 3mm flux points. */
    for (i=0; i<NEXTRA; i++) {
        n++;
        x = realloc(x, n * sizeof(float));
        y = realloc(y, n * sizeof(float));
        w = realloc(w, n * sizeof(float));
        x[n-1] = log10f(extra_x[i] * 1000);
        y[n-1] = log10f(extra_y[i]);
        w[n-1] = 1/extra_u[i];
    }

    /* Do another fit. */
    linfit_order(new_fit_order, n, x, y, w, &nparams);
    for (i=0; i<new_fit_order; i++) {
        printf("i = %d nc[i] = %.4f\n", i, nparams[i]);
    }

    /* Generate the whole range fit points. */
    minx=log10f(900);
    maxx=log10f(100000);
    miny=-2;
    maxy=log10f(20);
    x_fit = malloc(n_fit * sizeof(float));
    for (i=0; i<n_fit; i++) {
        x_fit[i] = minx + i * ((maxx - minx)/(float)n_fit);
        nw++;
        wx = realloc(wx, nw * sizeof(float));
        wy = realloc(wy, nw * sizeof(float));
        ww = realloc(ww, nw * sizeof(float));
        wx[nw-1] = x_fit[i];
        wy[nw-1] = 0.0;
        ww[nw-1] = 1;
        if (x_fit[i] < log10f(11143)) {
            /* Use the Reynolds fit. */
            for (j=0; j<NFIT_REYNOLDS; j++) {
                wy[nw-1] += fitp_reynolds[j] * powf(x_fit[i], (float)j);
            }
        } else {
            /* Use the new fit. */
            for (j=0; j<new_fit_order; j++) {
                wy[nw-1] += nparams[j] * powf(x_fit[i], (float)j);
            }
        }
    }

    /* Do a whole-range fit. */
    linfit_order(whole_fit_order, nw, wx, wy, ww, &wparams);
    for (i=0; i<whole_fit_order; i++) {
        printf("i = %d wc[i] = %.4f\n", i, wparams[i]);
    }

    // minmax(n, x, &minx, &maxx);
    // minmax(n, y, &miny, &maxy);

    y_sault_fit = malloc(n_fit * sizeof(float));
    y_reynolds_fit = malloc(n_fit * sizeof(float));
    y_stevens_fit = malloc(n_fit * sizeof(float));
    y_new_fit = malloc(n_fit * sizeof(float));
    y_whole_fit = malloc(n_fit * sizeof(float));
    y_old_fit = malloc(n_fit * sizeof(float));
    ratio_reynolds_fit = malloc(n_fit * sizeof(float));
    ratio_stevens_fit = malloc(n_fit * sizeof(float));
    ratio_sault_fit = malloc(n_fit * sizeof(float));
    ratio_new_fit = malloc(n_fit * sizeof(float));
    /* minx=log10f(50); */
    minx=log10f(1000);
    /* maxx=log10f(500000); */
    maxx=log10f(110000);
    for (i=0; i<n_fit; i++) {
        x_fit[i] = minx + i * ((maxx - minx)/(float)n_fit);
        y_sault_fit[i] = 0.0;
        y_reynolds_fit[i] = 0.0;
        y_new_fit[i] = 0.0;
        y_stevens_fit[i] = 0.0;
        y_whole_fit[i] = 0.0;
        y_old_fit[i] = 0.0;
        for (j=0; j<NFIT_SAULT; j++) {
            y_sault_fit[i] += fitp_sault[j] * powf(x_fit[i], (float)j);
        }
        for (j=0; j<NFIT_REYNOLDS; j++) {
            y_reynolds_fit[i] += fitp_reynolds[j] * powf(x_fit[i], (float)j);
        }
        for (j=0; j<NFIT_STEVENS; j++) {
            y_stevens_fit[i] += fitp_stevens[j] * powf(x_fit[i], (float)j);
        }
        for (j=0; j<new_fit_order; j++) {
            y_new_fit[i] += nparams[j] * powf(x_fit[i], (float)j);
        }
        for (j=0; j<whole_fit_order; j++) {
            y_whole_fit[i] += wparams[j] * powf(x_fit[i], (float)j);
        }
        for (j=0; j<NFIT_OLD; j++) {
            y_old_fit[i] += fitp_old[j] * powf(x_fit[i], (float)j);
        }
        ratio_reynolds_fit[i] = powf(10, (y_reynolds_fit[i] - y_whole_fit[i]));
        ratio_stevens_fit[i] = powf(10, (y_stevens_fit[i] - y_whole_fit[i]));
        ratio_sault_fit[i] = powf(10, (y_sault_fit[i] - y_whole_fit[i]));
        ratio_new_fit[i] = powf(10, (y_new_fit[i] - y_whole_fit[i]));
    }

    /* cpgopen("11/xs"); */
    cpgopen("1934-638_models.ps/cps");
    /* cpgopen("1934-638_models.png/png"); */
    cpgqvp(0, &vpx1, &vpx2, &vpy1, &vpy2);
    vpy3 = vpy1 + (vpy2 - vpy1) / 5.0;
    /* cpgsvp(vpx1, vpx2, vpy3, vpy2); */
    cpgswin(minx, maxx, miny, maxy);
    lx = minx + (maxx - minx) / 9.0;
    ly = miny + (maxy - miny) / 3.0;
    dly = (maxy - miny) / 20.0;
    cpgsch(1.0);
    cpgbox("BCLNTS",0,0,"BCLNTS",0,0);
    cpglab("Frequency (MHz)", "Flux Density (Jy)", "1934-638 Model Comparison");
    cpgsch(0.8);
    cpgpt(n, x, y, 4);
    /* cpgpt(nw, wx, wy, 4); */
    cpgsci(2);
    /* cpgpt(nr, rx, ry, 4); */
    cpgline(n_fit, x_fit, y_sault_fit);
    strcpy(fitlabel, "Sault: ");
    fitstring(fitp_sault, NFIT_SAULT, fitlabel);
    cpgtext(lx, ly, fitlabel);
    cpgsci(3);
    cpgline(n_fit, x_fit, y_new_fit);
    strcpy(fitlabel, "Stevens (linear): ");
    fitstring(nparams, new_fit_order, fitlabel);
    ly -= dly;
    cpgtext(lx, ly, fitlabel);
    cpgsci(4);
    cpgline(n_fit, x_fit, y_reynolds_fit);
    strcpy(fitlabel, "Reynolds: ");
    fitstring(fitp_reynolds, NFIT_REYNOLDS, fitlabel);
    ly -= dly;
    cpgtext(lx, ly, fitlabel);
    cpgsci(5);
    cpgline(n_fit, x_fit, y_stevens_fit);
    strcpy(fitlabel, "Stevens (Miriad): ");
    fitstring(fitp_stevens, NFIT_STEVENS, fitlabel);
    ly -= dly;
    cpgtext(lx, ly, fitlabel);
    cpgsci(6);
    cpgline(n_fit, x_fit, y_old_fit);
    strcpy(fitlabel, "Pre-1994: ");
    fitstring(fitp_old, NFIT_OLD, fitlabel);
    ly -= dly;
    cpgtext(lx, ly, fitlabel);
    /* cpgsci(6); */
    /* cpgline(n_fit, x_fit, y_whole_fit); */
    /* strcpy(fitlabel, "Stevens (New): "); */
    /* fitstring(wparams, whole_fit_order, fitlabel); */
    /* ly -= dly; */
    /* cpgtext(lx, ly, fitlabel); */
    /* cpgsvp(vpx1, vpx2, vpy1, vpy3); */
    /* cpgsci(1); */
    /* cpgswin(minx, maxx, 0.9, 1.1); */
    /* cpgsch(1.0); */
    /* cpgbox("BCLNTS",0,0,"BCMTS",0,0); */
    /* cpglab("Frequency (MHz)", "Model Ratio", ""); */
    /* cpgsci(2); */
    /* cpgline(n_fit, x_fit, ratio_sault_fit); */
    /* cpgsci(3); */
    /* cpgline(n_fit, x_fit, ratio_new_fit); */
    /* cpgsci(4); */
    /* cpgline(n_fit, x_fit, ratio_reynolds_fit); */
    /* cpgsci(5); */
    /* cpgline(n_fit, x_fit, ratio_stevens_fit); */
    cpgclos();

    exit(0);
}
コード例 #2
0
ファイル: symbol.c プロジェクト: galaxysd/GalaxyCodeBases
S_FUNC void
printtype(VALUE *vp)
{
	int	type;
	char	*s;

	type = vp->v_type;
	if (type < 0) {
		printf("Error %d", -type);
		return;
	}
	switch (type) {
	case V_NUM:
		printf("real = ");
		fitprint(vp->v_num, 32);
		return;
	case V_COM:
		printf("complex = ");
		fitprint(vp->v_com->real, 8);
		if (!vp->v_com->imag->num.sign)
			printf("+");
		fitprint(vp->v_com->imag, 8);
		printf("i");
		return;
	case V_STR:
		printf("string = \"");
		fitstring(vp->v_str->s_str, vp->v_str->s_len, 50);
		printf("\"");
		return;
	case V_NULL:
		s = "null";
		break;
	case V_MAT:
		s = "matrix";
		break;
	case V_LIST:
		s = "list";
		break;
	case V_ASSOC:
		s = "association";
		break;
	case V_OBJ:
		printf("%s ", objtypename(
			vp->v_obj->o_actions->oa_index));
		s = "object";
		break;
	case V_FILE:
		s = "file id";
		break;
	case V_RAND:
		s = "additive 55 random state";
		break;
	case V_RANDOM:
		s = "Blum random state";
		break;
	case V_CONFIG:
		s = "config state";
		break;
	case V_HASH:
		s = "hash state";
		break;
	case V_BLOCK:
		s = "unnamed block";
		break;
	case V_NBLOCK:
		s = "named block";
		break;
	case V_VPTR:
		s = "value pointer";
		break;
	case V_OPTR:
		s = "octet pointer";
		break;
	case V_SPTR:
		s = "string pointer";
		break;
	case V_NPTR:
		s = "number pointer";
		break;
	default:
		s = "???";
		break;
	}
	printf("%s", s);
}