Exemplo n.º 1
0
void InterPolF(column_type * cnu, int ndepthsnu, double *nu, int k, int knu, column_type * c, int ndepths)
// Fills the full column array c with F values based on interpolation of cnu
{
	int i,s,n;
	double  *ya, *Fa, *yinterp, *Finterp;

	for (s=0; (s<ndepths)?(c[s].y<=cnu[ndepthsnu-1].y):0; s++); // s is index of first depth of c beyond the range of cnu
	n = ndepthsnu + ndepths-s;
	ya = (double *)malloc((n)*sizeof(double));
	Fa = (double *)malloc((n)*sizeof(double));
	for (i=0; i<ndepthsnu; i++) {
		ya[i] = cnu[i].logy;
		Fa[i] = cnu[i].F[knu];
	}
	for (i=s; (i+1)<ndepths; i++) {
		ya[ndepthsnu+i-s] = c[i].logy;
		Fa[ndepthsnu+i-s] = 0.0;
	}
	ya[ndepthsnu+(ndepths-1)-s] = c[ndepths-1].logy;
	Fa[ndepthsnu+(ndepths-1)-s] = Fa[ndepthsnu+(ndepths-1)-s-1];
	yinterp = (double *)malloc((ndepths)*sizeof(double));
	Finterp = (double *)malloc((ndepths)*sizeof(double));
	for (i=0; i<ndepths; i++) { // set y values to interpolate at
		yinterp[i] = c[i].logy;
	}
	InterpolateArray(ya, Fa, n, yinterp, Finterp, ndepths, 0, 0.0, 1, 0.0);
	for (i=0; i<ndepths; i++) {
		c[i].F[k] = Finterp[i];
	}

	free(ya);
	free(Fa);
	free(yinterp);
	free(Finterp);
}
Exemplo n.º 2
0
void InterPolJ(column_type * cnu, int ndepthsnu, double *nu, int k, int knu, column_type * c, int ndepths)
// Fills the full column array c with J values based on BB function and interpolation of cnu
{
	int i,s,n;
	double T;
	double  *ya, *Ja, *yinterp, *Jinterp;

	for (s=0; (s<ndepths)?(c[s].y<=cnu[ndepthsnu-1].y):0; s++); // s is index of first depth of c beyond the range of cnu
	n = ndepthsnu + ndepths-s;
	ya = (double *)malloc((n)*sizeof(double));
	Ja = (double *)malloc((n)*sizeof(double));
	for (i=0; i<ndepthsnu; i++) { // Set y, f, and h values in cnu
		ya[i] = cnu[i].y;
		Ja[i] = cnu[i].J[knu];
	}
	for (i=s; i<ndepths; i++) { // Set y, f, and h values beyond depth s
		ya[ndepthsnu+i-s] = c[i].y;
		T = pow(10.0, c[i].logT);
		Ja[ndepthsnu+i-s] = Bnu(nu[k],T);
	}
	yinterp = (double *)malloc((ndepths)*sizeof(double));
	Jinterp = (double *)malloc((ndepths)*sizeof(double));
	for (i=0; i<ndepths; i++) { // Set y values to interpolate at
		yinterp[i] = c[i].y;
	}
	InterpolateArray(ya, Ja, n, yinterp, Jinterp, ndepths, 0, 0.0, 0, 0.0);
	for (i=0; i<ndepths; i++) { // Set u values in c based on interpolation
		c[i].J[k] = Jinterp[i];
	}

	free(ya);
	free(Ja);
	free(yinterp);
	free(Jinterp);
}
Exemplo n.º 3
0
static void DoInterpolateMap(Widget w, StdForm *sf, XmListCallbackStruct *cb)
{
    int i, j, nX, nY;
    int err, type, order, corners;
    double xspa, yspa;
    string buf;
    MAP *m, *old = (MAP *)sf->any;
    int **L;
    double **A;
    
    int FillHolesInArray(), InterpolateArray();
    void FreeIntArray(), FreeDoubleArray();
    int **AllocIntArray();
    double **AllocDoubleArray();
    void send_line(), wsscanf(), SetWatchCursor();
    void MapDraw(), SetIntpOrder();
    int GetIntpType(), GetIntpOrder(), GetIntpCorners();
    MAP *new_map();
    list *get_maplist();

    if (!old) {
        PostErrorDialog(w, "No map selected to be interpolated.");
        return;
    }
    
    type    = GetIntpType();
    order   = GetIntpOrder();
    corners = GetIntpCorners();
    
    if (order <= 0) {
        PostWarningDialog(w, "Selected interpolation order is zero.");
        return;
    }
    
    nX   = old->i_no;
    nY   = old->j_no;
    xspa = old->xspacing;
    yspa = old->yspacing;
    
    A = AllocDoubleArray(nX, nY);
    if (!A) {
        PostErrorDialog(NULL, "InterpolateMap: Out of memory.");
        return;
    }
    L = AllocIntArray(nX, nY);
    if (!L) {
        FreeDoubleArray(A, nX, nY);
        PostErrorDialog(NULL, "InterpolateMap: Out of memory.");
        return;
    }
    
    SetWatchCursor(True);
    
    for (i=0; i<nX; i++) {
        for (j=0; j<nY; j++) {
            A[i][j] = old->d[i][j];
            if (old->f[i][j] <= BLANK)
                L[i][j] = EMPTY;
            else
                L[i][j] = FILLED;
        }
    }

    if (corners > 0)
        err = FillHolesInArray(A, L, nX, nY, corners);

    if ((i = order)) {
        while (i) {
            err = InterpolateArray(&A, &L, &nX, &nY, type);
            if (err != 0) {
                sprintf(buf, "Couldn't interpolate array. err=%d.", err);
                send_line(buf);
                if (A) FreeDoubleArray(A, nX, nY);
                if (L) FreeIntArray(L, nX, nY);
                SetWatchCursor(False);
                PostErrorDialog(NULL, buf);
                return;
            }
            xspa /= 2.0;
            yspa /= 2.0;
            i--;
            if (corners > 0)
                err = FillHolesInArray(A, L, nX, nY, corners);
        }
    }

    m = new_map(get_maplist(), nX, nY);
    
    m->type     = old->type;
    m->swapped  = old->swapped;
    m->memed    = old->memed;
    m->original = old->original;
    m->x0       = old->x0;
    m->y0       = old->y0;
    m->xleft    = old->xleft;
    m->xright   = old->xright;
    m->ylower   = old->ylower;
    m->yupper   = old->yupper;
    m->date     = old->date;
    strcpy(m->molecule, old->molecule);
    m->interpolated = old->interpolated + 1;
    m->equinox  = old->equinox;
    m->epoch    = old->epoch;
    
    m->ndata    = nX * nY;
    m->i_min    = NINT(m->xleft/xspa);
    m->i_max    = NINT(m->xright/xspa);
    m->j_min    = NINT(m->ylower/yspa);
    m->j_max    = NINT(m->yupper/yspa);
    m->xspacing = xspa;
    m->yspacing = yspa;
    
    for (i=0; i<nX; i++) {
        for (j=0; j<nY; j++) {
            if (L[i][j] == FILLED) {
                m->f[i][j] = UNBLANK;
                m->d[i][j] = A[i][j];
                m->e[i][j] = UNDEF;
            } else {
                m->f[i][j] = BLANK;
                m->d[i][j] = UNDEF;
                m->e[i][j] = UNDEF;
            }
        }
    }
    
    FreeDoubleArray(A, nX, nY);
    FreeIntArray(L, nX, nY);

    SetWatchCursor(False);

    wsscanf(sf->edit[0], m->name);
    sprintf(buf, "Interpolated map stored as '%s': %dx%d\n",  m->name, nX, nY);
    send_line(buf);
    
    XtDestroyWidget(sf->form);
    
    SetIntpOrder(0);
    MapDraw(NULL, m, NULL);
}