double interpol1d(double x,int n,double *xbuf,double *buf); double interpolAngular(double x,int n,double *xbuf,double *buf); double interpol2d(double x,double y,int nx,int ny,double *xbuf,double *ybuf,double *buf); double interpol1d(double x,int n,double *xbuf,double *buf) /*---------------------------------------------------------------------- * Parabolic blending interpolation of a function of one variable. * * Input parameters: * x abscissa * n number of data points of abscissa and ordinate * xbuf array with pre-defined values of x, ascending * buf array with function values, where buf[i] is function of xbuf[i] * * Terms of use: * You are not allowed to claim that this code is the work of anybody else * than Henning Weede. * The author is not liable for any damage caused by this code. * The author has no duty to waist his time answering questions related * to this code. * The GNU Public License applies. * * Author: Henning Weede *---------------------------------------------------------------------- */{ int ix; double vor,nach,tmp; /* check if ascending order (overflow protection) */ tmp=fabs(xbuf[n-1]-xbuf[0])/10000.; for(ix=1; ixx) break; /* interpolate in pre-parabola, return only this if no post-parabola */ if(ix>1) vor=buf[ix-2]*(x-xbuf[ix-1])*(x-xbuf[ix ])/((xbuf[ix-2]-xbuf[ix-1])*(xbuf[ix-2]-xbuf[ix ])) +buf[ix-1]*(x-xbuf[ix-2])*(x-xbuf[ix ])/((xbuf[ix-1]-xbuf[ix-2])*(xbuf[ix-1]-xbuf[ix ])) +buf[ix ]*(x-xbuf[ix-2])*(x-xbuf[ix-1])/((xbuf[ix ]-xbuf[ix-2])*(xbuf[ix ]-xbuf[ix-1])); if(ix>=n-1) return(vor); /* interpolate in post-parabola, return only this if no pre-parabola */ if(ixPI/2.) { fprintf(stderr,"interpolAngular(): huge gap between beginning and end of angular abscissa.\n"); exit(1); } while(xxbuf[n-1]) x-=2*PI; for(i2=0; i2x) break; if(i2==n) i2=0; i1=i2-1; if(i1<0) i1+=n; i0=i1-1; if(i0<0) i0+=n; i3=i2+1; if(i3>n-1) i3-=n; x0=xbuf[i0]; x1=xbuf[i1]; x2=xbuf[i2]; x3=xbuf[i3]; while(x1>x0+2*PI) x1-=2*PI; while(x1x1+2*PI) x2-=2*PI; while(x2x2+2*PI) x3-=2*PI; while(x3x2) x-=2*PI; y0=buf[i0]; y1=buf[i1]; y2=buf[i2]; y3=buf[i3]; vor=y0*(x-x1)*(x-x2)/((x0-x1)*(x0-x2)) +y1*(x-x0)*(x-x2)/((x1-x0)*(x1-x2)) +y2*(x-x0)*(x-x1)/((x2-x0)*(x2-x1)); nach=y1*(x-x2)*(x-x3)/((x1-x2)*(x1-x3)) +y2*(x-x1)*(x-x3)/((x2-x1)*(x2-x3)) +y3*(x-x1)*(x-x2)/((x3-x1)*(x3-x2)); tmp=(x-x1)/(x2-x1); return(vor*(1.-tmp)+nach*tmp); } /* interpolAngular() */ double interpol2d(double x,double y,int nx,int ny,double *xbuf,double *ybuf,double *buf) /*---------------------------------------------------------------------- * Parabolic blending interpolation of a function of two variables. * * Input parameters: * x,y abscissae * nx,ny number of data points of abscissae * xbuf array with pre-defined values of x, ascending * ybuf array with pre-defined values of y, ascending * buf array with function values, where buf[i+j*nx] is function of xbuf[i] and ybuf[j] * * Return value: function value at x,y * * Terms of use: * You are not allowed to claim that this code is the work of anybody else * than Henning Weede. * The author is not liable for any damage caused by this code. * The author has no duty to waist his time answering questions related * to this code. * The GNU Public License applies. * * Author: Henning Weede *---------------------------------------------------------------------- */{ int i,ix,iy,j; double linDecx,linDecy,linIncx,linIncy, quadAftx1,quadAftx2,quadAftx3,quadAfty1,quadAfty2,quadAfty3, quadPrex0,quadPrex1,quadPrex2,quadPrey0,quadPrey1,quadPrey2, result,tmp, shapFuncx[4],shapFuncy[4]; tmp=fabs(xbuf[nx-1]-xbuf[0])/1000.; for(i=1; ix) break; if(ix>0) { quadPrex0=(x-xbuf[ix ])*(x-xbuf[ix+1])/((xbuf[ix-1]-xbuf[ix ])*(xbuf[ix-1]-xbuf[ix+1])); quadPrex1=(x-xbuf[ix-1])*(x-xbuf[ix+1])/((xbuf[ix ]-xbuf[ix-1])*(xbuf[ix ]-xbuf[ix+1])); quadPrex2=(x-xbuf[ix-1])*(x-xbuf[ix ])/((xbuf[ix+1]-xbuf[ix-1])*(xbuf[ix+1]-xbuf[ix ])); } if(ixy) break; if(iy>0) { quadPrey0=(y-ybuf[iy ])*(y-ybuf[iy+1])/((ybuf[iy-1]-ybuf[iy ])*(ybuf[iy-1]-ybuf[iy+1])); quadPrey1=(y-ybuf[iy-1])*(y-ybuf[iy+1])/((ybuf[iy ]-ybuf[iy-1])*(ybuf[iy ]-ybuf[iy+1])); quadPrey2=(y-ybuf[iy-1])*(y-ybuf[iy ])/((ybuf[iy+1]-ybuf[iy-1])*(ybuf[iy+1]-ybuf[iy ])); } if(iy=0)&&(ix-1+i<=nx-1)&&(iy-1+j>=0)&&(iy-1+j<=ny-1)) result += shapFuncx[i]*shapFuncy[j]*buf[ix-1+i + (iy-1+j)*nx]; return(result); } /* interpol2d() */