void rc1_fft(REAL *data, complex *cdata, int n, int sign) { int j; double *datft; if (NINT(pow(2.0, (double)NINT(log((double)n)/log(2.0)))) != n) { if (npfar(n) == n) pfarc(sign,n,data,cdata); else rcdft(data,cdata,n,sign); } else { datft = (double *)malloc(n*sizeof(double)); if (datft == NULL) fprintf(stderr,"rc1_fft: memory allocation error\n"); for (j = 0; j < n; j++) datft[j] = (double)data[j]; realfft(n, datft); cdata[0].i = 0.0; for (j = 0; j < n/2; j++) { cdata[j].r = (REAL)datft[j]; cdata[j+1].i = sign*(REAL)datft[n-j-1]; } cdata[n/2].r = datft[n/2]; cdata[n/2].i = 0.0; free(datft); } return; }
void cr1_fft(complex *cdata, REAL *data, int n, int sign) { int j; double *datft; if (NINT(pow(2.0, (double)NINT(log((double)n)/log(2.0)))) != n) { if (npfar(n) == n) pfacr(sign,n,cdata,data); else crdft(cdata,data,n,sign); } else { datft = (double *)malloc(n*sizeof(double)); if (datft == NULL) fprintf(stderr,"cr1_fft: memory allocation error\n"); for (j = 0; j < n/2; j++) { datft[j] = (double)cdata[j].r; datft[n-1-j] = (double)cdata[j+1].i; } datft[n/2] = (double)cdata[n/2].r; realifft(n, datft); if (sign == -1) { for (j = 0; j < n; j++) data[j] = (REAL)datft[j]; } else if (sign == 1) { for (j = 1; j < n; j++) data[j] = (REAL)datft[n-j]; data[0] = (REAL)datft[0]; } free(datft); } return; }
int FromLT (int rsize, double *ltm, double *ltv, int *bin, int *corner) { /* arguments: int rsize i: reference pixel size double ltm[2] i: diagonal elements of MWCS matrix double ltv[2] i: MWCS linear transformation vector int bin[2] o: pixel size in X and Y int corner[2] o: corner of subarray in X and Y */ extern int status; double dbinx, dbiny, dxcorner, dycorner; dbinx = (double)rsize / ltm[0]; dbiny = (double)rsize / ltm[1]; dxcorner = (dbinx - rsize) - dbinx * ltv[0]; dycorner = (dbiny - rsize) - dbiny * ltv[1]; /* Round off to the nearest integer. */ corner[0] = NINT (dxcorner); corner[1] = NINT (dycorner); bin[0] = NINT (dbinx); bin[1] = NINT (dbiny); return (status); }
asynStatus MCB4BAxis::sendAccelAndVelocity(double acceleration, double velocity) { asynStatus status; int ival; // static const char *functionName = "MCB4B::sendAccelAndVelocity"; // Send the velocity ival = NINT(fabs(115200./velocity)); if (ival < 2) ival=2; if (ival > 255) ival = 255; sprintf(pC_->outString_, "#%02dV=%d", axisNo_, ival); status = pC_->writeReadController(); // Send the acceleration // acceleration is in steps/sec/sec // MCB is programmed with Ramp Index (R) where: // dval (steps/sec/sec) = 720,000/(256-R) */ // or R=256-(720,000/dval) */ ival = NINT(256-(720000./acceleration)); if (ival < 1) ival=1; if (ival > 255) ival=255; sprintf(pC_->outString_, "#%02dR=%d", axisNo_, ival); status = pC_->writeReadController(); return status; }
void cc1_fft(complex *cdata, int n, int sign) { int j; double *real, *imag; if (NINT(pow(2.0, (double)NINT(log((double)n)/log(2.0)))) != n) { if (npfa(n) == n) pfacc(sign, n, cdata); else ccdft(cdata,n,sign); } else { real = (double *)malloc(n*sizeof(double)); if (real == NULL) fprintf(stderr,"cc1_fft: memory allocation error\n"); imag = (double *)malloc(n*sizeof(double)); if (imag == NULL) fprintf(stderr,"cc1_fft: memory allocation error\n"); for (j = 0; j < n; j++) { real[j] = (double)cdata[j].r; imag[j] = (double)cdata[j].i; } if (sign < 0) fft(n, real, imag); else ifft(n, real, imag); for (j = 0; j < n; j++) { cdata[j].r = (REAL)real[j]; cdata[j].i = (REAL)imag[j]; } free(real); free(imag); } return; }
void smooth (float **in, float **out, long naxes[], float sigma, float radius) { int i, j, k, l, xmin, ymin, xmax, ymax; float sumwt, sumflux, wt, rad; for (j=1; j <= naxes[2]; j++) { for (i=1; i <= naxes[1]; i++) { xmin = IMAX (1, i - NINT(radius)); xmax = IMIN (i+NINT(radius), naxes[1]); ymin = IMAX (1, j - NINT(radius)); ymax = IMIN (j+NINT(radius), naxes[2]); sumwt = 0.; sumflux = 0.; for (l=ymin; l <= ymax; l++) { for (k=xmin; k <= xmax; k++) { rad = sqrt((k-i)*(k-i)+(l-j)*(l-j)); if (rad <= radius) { wt = exp (-rad*rad/2/sigma/sigma); sumwt += wt; sumflux += in[l][k] * wt; }; }; }; out[j][i] = sumflux / sumwt; }; }; }
void makefilter(float *f, int nfft, int nfreq, float dt, float *filter) { float onfft = 1.0 / nfft; float df = onfft / dt; int nfreqm1 = nfreq - 1; int if1 = NINT(f[0]/df); int if2 = NINT(f[1]/df); int if3 = MIN(NINT(f[2]/df), nfreqm1); int if4 = MIN(NINT(f[3]/df), nfreqm1); { register int i; register float c = PIBY2 / (if2 - if1 + 2); for (i = if1; i <= if2; ++i) { register float s = sin(c*(i - if1 + 1)); filter[i] = s * s * onfft; } } { register int i; register float c = PIBY2 / (if4 - if3 + 2); for (i = if3; i <= if4; ++i) { register float s = sin(c*(if4 - i + 1)); filter[i] = s * s * onfft; } } { register int i; for (i = if2 + 1; i < if3; ++i) filter[i] = onfft; for (i = 0; i < if1; ++i) filter[i] = 0.0; for (i = if4 + 1; i < nfreq; ++i) filter[i] = 0.0; } }
/*==========================================================================*/ void lnk_cell_dis(int ia, int ib, int ic, int ncell_a, int ncell_b, int ncell_c, double *rcell, double hmat_lnk[], int iperd) /*==========================================================================*/ {/*Begin Routine */ /*==========================================================================*/ /* Local variables */ double acelli, bcelli, ccelli, dx, dy, dz, dsx, dsy, dsz; double dsxt, dsyt, dszt; /*==========================================================================*/ /* ia,ib,ic are the shifts along a,b,c */ /* ncell_a,ncell_b,ncell_c are the number of divisions along a,b,c */ /* hmat matrix of cell parameters */ /* rcell is return with cartesian distance associated with shifts */ /* scalar temp */ /* get inverse number of divisions along cell axis */ /*==========================================================================*/ acelli = 1. / (double) ncell_a; bcelli = 1. / (double) ncell_b; ccelli = 1. / (double) ncell_c; /* convert shifts to a displacement along fractional coord. (the s) */ dsx = (double) ia * acelli; dsy = (double) ib * bcelli; dsz = (double) ic * ccelli; /* periodic image */ /* if (iperd >= 1) { dsx -= NINT(dsx);}*/ /* if (iperd >= 2) { dsy -= NINT(dsy);}*/ /* if (iperd >= 3) { dsz -= NINT(dsz);}*/ dsx -= NINT(dsx); dsy -= NINT(dsy); dsz -= NINT(dsz); /* subtract out one cell to account that cell that share edges can have */ /* particles separteded by one less cell distances */ /* dsxt = copysign(acelli,dsx); */ /* dsyt = copysign(bcelli,dsy); */ /* dszt = copysign(ccelli,dsz); */ if(dsx>=0){dsxt=acelli;}else{dsxt=-acelli;} if(dsy>=0){dsyt=bcelli;}else{dsyt=-bcelli;} if(dsz>=0){dszt=ccelli;}else{dszt=-ccelli;} if (dsx != 0.) {dsx -= dsxt;} if (dsy != 0.) {dsy -= dsyt;} if (dsz != 0.) {dsz -= dszt;} /* convert to cartesian displacements */ dx = dsx * hmat_lnk[1] + dsy * hmat_lnk[4] + dsz * hmat_lnk[7]; dy = dsx * hmat_lnk[2] + dsy * hmat_lnk[5] + dsz * hmat_lnk[8]; dz = dsx * hmat_lnk[3] + dsy * hmat_lnk[6] + dsz * hmat_lnk[9]; /* get distance */ *rcell = sqrt(dx * dx + dy * dy + dz * dz); } /* lnk_cell_dis */
int main(int argc, char **argv) { int i, j, n; float *f, max, step, rstep; float fhist[1024], dev, rdev, ent, error; int hist[1024]; initargs(argc, argv); requestdoc(1); MUSTGETPARINT("n",&n); f = alloc1float(n); fread(f,sizeof(float),n,stdin); for(i=0;i<1024;i++) hist[i] = 0; for(i=0,rdev=0.;i<n;i++) rdev += f[i]*f[i]; rdev = rdev/n; rdev = sqrt(rdev); if(!getparfloat("dev",&dev)) dev = rdev; fprintf(stderr,"dev=%f\n", dev); step = dev*3.464*.01; rstep = 1./step; error = 0.; for(i=0;i<n;i++){ max = f[i]*rstep; error += (NINT(max)*step - f[i])*(NINT(max)*step - f[i]); hist[NINT(max)+512] ++; } error = error/n; error = sqrt(error); error = error/rdev; ent = 0.; for(j=0;j<1024;j++){ fhist[j] = ((float) hist[j])/((float) n); if(hist[j]) ent += fhist[j]*log(fhist[j])/log(2.); } ent = -ent; fprintf(stderr,"entropy of the signal is=%f, average error=%f\n",ent, error); fwrite(fhist,sizeof(float),1024,stdout); return EXIT_SUCCESS; }
void remove_fb(float *yp,float *ym,int n,short *scaler,short *shft) /* Find Scale and timeshift Yp = data trace Ym = wavelet F=min(Yp(x) - Ym(x)*a)^2 is a function to minimize for scaler find shift first with xcorrelation then solve for a - scaler */ { #define RAMPR 5 void find_p(float *ym,float *yp,float *a,int *b,int n); int it,ir; float a=1.0; int b=0; int ramps; float *a_ramp; ramps=NINT(n-n/RAMPR); find_p(ym,yp,&a,&b,n); a_ramp = ealloc1float(n); for(it=0;it<ramps;it++) a_ramp[it]=1.0; for(it=ramps,ir=0;it<n;it++,ir++) { a_ramp[it]=1.0-(float)ir/(float)(n-ramps-1); } if (b<0) { for(it=0;it<n+b;it++) yp[it-b] -=ym[it]*a*a_ramp[it-b]; } else { for(it=0;it<n-b;it++) yp[it] -=ym[it-b]*a*a_ramp[it+b]; } *scaler = NINT((1.0-a)*100.0); *shft = b; free1float(a_ramp); }
/*------------------------------------------------------------*/ lint2d lint2d_make( int na, pt2d *aa, fdm2d fdm) /*< init 2D linear interpolation >*/ { lint2d ca; int ia; float f1,f2; ca = (lint2d) sf_alloc(1,sizeof(*ca)); ca->n = na; ca->w00 = sf_floatalloc(na); ca->w01 = sf_floatalloc(na); ca->w10 = sf_floatalloc(na); ca->w11 = sf_floatalloc(na); ca->jz = sf_intalloc(na); ca->jx = sf_intalloc(na); for (ia=0; ia<na; ia++) { if(aa[ia].z >= fdm->ozpad && aa[ia].z < fdm->ozpad + (fdm->nzpad-1)*fdm->dz && aa[ia].x >= fdm->oxpad && aa[ia].x < fdm->oxpad + (fdm->nxpad-1)*fdm->dx ) { ca->jz[ia] = NINT((aa[ia].z-fdm->ozpad)/fdm->dz); ca->jx[ia] = NINT((aa[ia].x-fdm->oxpad)/fdm->dx); f1 = (aa[ia].z-fdm->ozpad)/fdm->dz - ca->jz[ia]; f2 = (aa[ia].x-fdm->oxpad)/fdm->dx - ca->jx[ia]; } else { ca->jz[ia] = 0; ca->jx[ia] = 0; f1 = 1; f2 = 0; } ca->w00[ia] = (1-f1)*(1-f2); ca->w01[ia] = ( f1)*(1-f2); ca->w10[ia] = (1-f1)*( f2); ca->w11[ia] = ( f1)*( f2); } return ca; }
static void FirstLast (double *ltm, double *ltv, int *snpix, int *npix, int *rbin, int *first, int *last, int *sfirst) { /* arguments: double ltm[2], ltv[2] i: linear transformation from scratch to image coords (adjusted for use with zero indexed coords) int snpix[2] i: size of scratch image int npix[2] i: size of actual image int rbin[2] o: number of pixels in scratch for one image pixel int first[2], last[2] o: corners of overlap region, in image coords int sfirst[2] o: lower left corner of overlap, in scratch array */ double scr; /* pixel coordinate in scratch array */ int i, k; rbin[0] = NINT (1. / ltm[0]); rbin[1] = NINT (1. / ltm[1]); for (k = 0; k < 2; k++) { /* axis number */ /* Search for the first pixel in the image array that maps to a point that is completely within the scratch array. The left (lower) edge of pixel i is (i - 0.5). Map (i - 0.5) to the scratch array, and if that point is within the scratch array, i is the first fully illuminated pixel. */ for (i = 0; i < npix[k]; i++) { scr = (i - 0.5 - ltv[k]) / ltm[k]; /* -0.5 is left (lower) edge of first pixel in scratch */ if (scr+TOLERANCE >= -0.5) { first[k] = i; sfirst[k] = NINT (scr+0.5); break; } } /* Now look for the last fully illuminated pixel, using the right (upper) edge of the image pixels. */ for (i = npix[k]-1; i > 0; i--) { scr = (i + 0.5 - ltv[k]) / ltm[k]; /* compare scr with right (upper) edge of last pixel in the scratch array */ if (scr-TOLERANCE <= snpix[k]-1. + 0.5) { last[k] = i; break; } } } }
void crm_fft(complex *cdata, REAL *data, int n1, int n2, int ldc, int ldr, int sign) { int j, i; double *datft; if (NINT(pow(2.0, (double)NINT(log((double)n1)/log(2.0)))) != n1) { if (npfar(n1) == n1) { if (ldr == n1 && ldc == n2) { pfa2cr(sign, 1, n1, n2, cdata, data); } else { for (i = 0; i < n2; i++) { pfacr(sign, n1, &cdata[i*ldc], &data[i*ldr]); } } } else { for (i = 0; i < n2; i++) { crdft(&cdata[i*ldc], &data[i*ldr], n1, sign); } } } else { datft = (double *)malloc(n1*sizeof(double)); if (datft == NULL) fprintf(stderr,"crm_fft: memory allocation error\n"); for (i = 0; i < n2; i++) { for (j = 0; j < n1/2; j++) { datft[j] = (double)cdata[i*ldc+j].r; datft[n1-1-j] = (double)cdata[i*ldc+j+1].i; } datft[n1/2] = (double)cdata[i*ldc+n1/2].r; realifft(n1, datft); if (sign == -1) { for (j = 0; j < n1; j++) data[i*ldr+j] = (REAL)datft[j]; } else if (sign == 1) { for (j = 1; j < n1; j++) data[i*ldr+j] = (REAL)datft[n1-j]; data[i*ldr] = (REAL)datft[0]; } } free(datft); } return; }
asynStatus MCB4BAxis::move(double position, int relative, double minVelocity, double maxVelocity, double acceleration) { asynStatus status; // static const char *functionName = "MCB4BAxis::move"; status = sendAccelAndVelocity(acceleration, maxVelocity); if (relative) { sprintf(pC_->outString_, "#%02dI%+d", axisNo_, NINT(position)); } else { sprintf(pC_->outString_, "#%02dG%+d", axisNo_, NINT(position)); } status = pC_->writeReadController(); return status; }
static void adjustAxesValues (int n1, float d1, float f1, int n2, float d2, float f2, float *x1beg, float *x1end, float *x2beg, float *x2end) /***************************************************************************** Adjust axes values to nearest samples; ensure at least 2 by 2 samples. *****************************************************************************/ { int ix1beg,ix1end,ix2beg,ix2end; ix1beg = NINT((*x1beg-f1)/d1); ix1end = NINT((*x1end-f1)/d1); ix1beg = MAX(0,MIN(n1-1,ix1beg)); ix1end = MAX(0,MIN(n1-1,ix1end)); if (ix1beg==ix1end) { if (*x1beg<*x1end) { if (ix1beg>0) ix1beg--; else ix1end++; } else { if (ix1beg<n1-1) ix1beg++; else ix1end--; } } *x1beg = f1+ix1beg*d1; *x1end = f1+ix1end*d1; ix2beg = NINT((*x2beg-f2)/d2); ix2end = NINT((*x2end-f2)/d2); ix2beg = MAX(0,MIN(n2-1,ix2beg)); ix2end = MAX(0,MIN(n2-1,ix2end)); if (ix2beg==ix2end) { if (*x2beg<*x2end) { if (ix2beg>0) ix2beg--; else ix2end++; } else { if (ix2beg<n2-1) ix2beg++; else ix2end--; } } *x2beg = f2+ix2beg*d2; *x2end = f2+ix2end*d2; }
float alpha_trim_w(float *a,float *w,int n,float p) /****************************************************************** alpha_trim_w - Weighted Alpha trim of array ****************************************************************** Notes: the value a[irp] is replaced by the mean of the a values, but the largers and smallest p% of a values are left out fo mean computation,array a is destroyed ****************************************************************** Author: Balasz Nemeth, given to CWP in 2008 by Potash Corporation ******************************************************************/ { float mean=0; unsigned int ist=NINT(n*(p/100.0)); unsigned int i,ic; int *ind=NULL; ind = ealloc1(n,sizeof(unsigned int)); for(i=0;i<n;++i) ind[i]=i; qkisort(n,a,ind); for(i=ist,ic=0;i<n-ist;i++,ic++) mean += a[ind[i]]*w[ind[i]]; free1(ind); return(mean/(float)ic); }
void randdf(float *x, float *z, int nxp, float dx, float dz, float **gridcp, float **gridcs, float **gridro, float **cp, float **cs, float **ro, float *interface, int *zp, int nx, float sizex, float sizez, int ndiff, int diffrwidth, int type) { float x0, z0, dsx, dsz; int i, rtype; long lseed; rtype=type; lseed = (long)ndiff; srand48(lseed); x0 = x[0]; z0 = z[0]; if (nxp==2) { /* an area is defined, do not fill until end of x and z coordinate */ dsx = x[1]-x0; dsz = z[1]-z0; } else { /* no area: fill until end of x and z range */ dsx = sizex-x0; dsz = sizez-z0; } for (i=0; i<ndiff; i++) { nxp=1; if (rtype<0) type=NINT(2*drand48()); else type = rtype; x[0] = x0 + diffrwidth*dx+drand48()*(dsx-2*diffrwidth*dx); z[0] = z0 + diffrwidth*dz+drand48()*(dsz-2*diffrwidth*dz); diffraction(x, z, nxp, dx, dz, gridcp, gridcs, gridro, cp, cs, ro, interface, zp, nx, diffrwidth, type); } return; }
void wipvfield(float x[], float y[], float r[], float phi[], int npts, float angle, float vent) { register int i; int fill; float x1, y1, x2, y2; double darg; LOGICAL error; darg = wipgetvar("fill", &error); fill = (error == TRUE) ? 1 : NINT(darg); cpgbbuf(); cpgsah(fill, angle, vent); for (i = 0; i < npts; i++) { x1 = x[i]; y1 = y[i]; x2 = x1 + (r[i] * COS(phi[i] * RPDEG)); y2 = y1 + (r[i] * SIN(phi[i] * RPDEG)); cpgarro(x1, y1, x2, y2); } cpgebuf(); return; }
void wipdecode(const char *string, char *outstr, size_t maxout) { char *ptr, *tmptr, *savptr; char ch; char tempstr[BUFSIZ], variable[BUFSIZ]; int nsig, nopen; double arg; LOGICAL error; ptr = (char *)string; if (Strchr(string, ESC) != (char *)NULL) { arg = wipgetvar("nsig", &error); nsig = NINT(arg); /* Tells how to format a user variable. */ tmptr = tempstr; while (*ptr) { if (*ptr != ESC) { *tmptr++ = *ptr++; /* Just copy the character. */ continue; /* Get the next character. */ } /* At this point an ESC character has been found. */ ch = *ptr++; /* save the ESC character. */ if (*ptr != '[') { /* No user variable here, so just store... */ *tmptr++ = ch; /* ...the two characters and continue. */ *tmptr++ = *ptr++; /* This is so "\\" gets passed. */ continue; /* Get the next character. */ } /* At this point a user variable flag has been found. */ ptr++; /* Increment ptr past the '['. */ savptr = variable; /* Set up user variable name pointer. */ nopen = 1; /* Initialize the number of open '['s. */ while ((*ptr) && (nopen)) { /* Get user variable name. */ if (*ptr == '[') nopen++; if (*ptr == ']') nopen--; if (nopen) *savptr++ = *ptr++; } if (*ptr != Null) ptr++; /* Skip over last ']' */ *savptr = Null; /* Skip last ']'; add terminating Null. */ if (wipisstring(variable)) { /* User string variable. */ savptr = wipgetstring(variable); /* Find string variable. */ if (savptr == (char *)NULL) savptr = ""; /* Error check. */ } else { /* Standard user variable. */ arg = wipevaluate(variable, &error); /* Find user variable. */ savptr = wipfpfmt(arg, nsig); /* Format the value. */ } while ((*savptr != Null) && (isspace(*savptr))) savptr++; /* Strip off leading blanks. */ while (*savptr) *tmptr++ = *savptr++; /* Include the value. */ } /* End of "while (*ptr)" loop. */ *tmptr = Null; /* Terminate the string with a Null. */ ptr = tempstr; /* Assign the work pointer to this string. */ } /* End of "(domacs == TRUE)" if block. */ if (Strlen(ptr) >= maxout) wipoutput(stderr, "Decoded string overflows output string size.\n"); (void)Strncpy(outstr, ptr, maxout); outstr[maxout-1] = Null; /* Make sure it is Null terminated. */ return; }
asynStatus MCB4BAxis::setPosition(double position) { asynStatus status; //static const char *functionName = "MCB4BAxis::setPosition"; sprintf(pC_->outString_, "#%02dP=%+d", axisNo_, NINT(position)); status = pC_->writeReadController(); return status; }
NV_INT32 pseudo_dist_from_viewer (MISC *misc, NV_FLOAT64 x, NV_FLOAT64 y) { NV_FLOAT64 xyz_y = ((y - misc->abe_share->edit_area.min_y) / edit_y_range) * misc->draw_area_height; NV_FLOAT64 xyz_x = ((x - misc->abe_share->edit_area.min_x) / edit_x_range) * misc->draw_area_width; xyz_x = xyz_x * misc->cos_array[misc->ortho_angle] - xyz_y * misc->sin_array[misc->ortho_angle]; return (NINT (xyz_x * (NV_FLOAT64) misc->ortho_scale)); }
void rcm_fft(REAL *data, complex *cdata, int n1, int n2, int ldr, int ldc, int sign) { int j, i; double *datft; if (NINT(pow(2.0, (double)NINT(log((double)n1)/log(2.0)))) != n1) { if (npfar(n1) == n1) { if (ldr == n1 && ldc == n2) { pfa2rc(sign, 1, n1, n2, data, cdata); } else { for (i = 0; i < n2; i++) { pfarc(sign, n1, &data[i*ldr], &cdata[i*ldc]); } } } else { for (i = 0; i < n2; i++) { rcdft(&data[i*ldr], &cdata[i*ldc], n1, sign); } } } else { datft = (double *)malloc(n1*sizeof(double)); if (datft == NULL) fprintf(stderr,"rcm_fft: memory allocation error\n"); for (i = 0; i < n2; i++) { for (j = 0; j < n1; j++) datft[j] = (double)data[i*ldr+j]; realfft(n1, datft); cdata[i*ldc].i = 0.0; for (j = 0; j < n1/2; j++) { cdata[i*ldc+j].r = (REAL)datft[j]; cdata[i*ldc+j+1].i = sign*(REAL)datft[n1-j-1]; } cdata[i*ldc+n1/2].r = (REAL)datft[n1/2]; cdata[i*ldc+n1/2].i = 0.0; } free(datft); } return; }
float setzsrc(int nb, int *boundary, float *inter, int nx, int ni, float zsrc1, float dzsrc, float h, float oz, int nz, float xsrc, float ox, int id, int verbose) { int k; float zsrc; if (nb) { k = boundary[id]-1; if (inter[k*nx+NINT(xsrc/h)] == 0) { if (verbose >= 2) { fprintf(stderr," setzsrc: boundary %d not defined at x=%f\n",boundary[id],xsrc+ox); fprintf(stderr," setzsrc: trying next boundary\n"); } k++; while (k < ni) { if (inter[k*nx+NINT(xsrc/h)] != 0) { if (verbose >= 2) fprintf(stderr," setzsrc: deeper boundary found\n"); break; } k++; } if (k == ni) { fprintf(stderr," setzsrc: no boundary found; source put at bottom of model\n"); zsrc = (nz-1)*h - oz; } else { if (verbose>=2) fprintf(stderr," setzsrc: source at boundary %d\n", k+1); zsrc = inter[k*nx+NINT(xsrc/h)] - oz; } } else { if (verbose>=2) fprintf(stderr," setzsrc: source at boundary %d\n", k+1); zsrc = inter[k*nx+NINT(xsrc/h)] - oz; } } else { zsrc = zsrc1 + id*dzsrc - oz; } return zsrc; }
void makecircle(int ix, int iz, int diffrwidth, float **med, float value) { int j,k, id, ir; id=diffrwidth/2; for (j=-id; j<=id; j++){ for (k=-id; k<=id; k++){ ir = NINT(sqrt(j*j+k*k)); if (ir <= id) med[ix+j][iz+k] = value; } } return; }
QRect CropFrame::_photoToScreenRect(const QRect& r) const { // r is given in photo coordinates, and we want to convert that // to screen coordinates double xRatio = 0.0; double yRatio = 0.0; // flip the photo dimensions if rotated int photoW; int photoH; if (m_photo->rotation == 0 || m_photo->rotation == 180) { photoW = m_photo->width(); photoH = m_photo->height(); } else { photoW = m_photo->height(); photoH = m_photo->width(); } if (m_photo->width() > 0) xRatio = (double) m_pixmap->width() / (double) photoW; if (m_photo->height() > 0) yRatio = (double)m_pixmap->height() / (double)photoH; int x1 = NINT(r.left() * xRatio + m_pixmapX); int y1 = NINT(r.top() * yRatio + m_pixmapY); int w = NINT(r.width() * xRatio); int h = NINT(r.height() * yRatio); QRect result; result.setRect(x1, y1, w, h); return result; }
void ccm_fft(complex *cdata, int n1, int n2, int ld1, int sign) { int i, j; double *real, *imag; if (NINT(pow(2.0, (double)NINT(log((double)n1)/log(2.0)))) != n1) { if (npfa(n1) == n1) pfamcc(sign, n1, n2, 1, ld1, cdata); else { for (i = 0; i < n2; i++) ccdft(&cdata[i*ld1],n1,sign); } } else { real = (double *)malloc(n1*sizeof(double)); if (real == NULL) fprintf(stderr,"ccm_fft: memory allocation error\n"); imag = (double *)malloc(n1*sizeof(double)); if (imag == NULL) fprintf(stderr,"ccm_fft: memory allocation error\n"); for (i = 0; i < n2; i++) { for (j = 0; j < n1; j++) { real[j] = (double)cdata[i*ld1+j].r; imag[j] = (double)cdata[i*ld1+j].i; } if (sign < 0) fft(n1, real, imag); else ifft(n1, real, imag); for (j = 0; j < n1; j++) { cdata[i*ld1+j].r = (REAL)real[j]; cdata[i*ld1+j].i = (REAL)imag[j]; } } free(real); free(imag); } return; }
static void prp1d (FILE *fp, char *label, int n, float d, float f, float x[]) { int i,ibase,icx,ic; float xmin,xmax,xscale,xbase; /* print title */ fprintf(fp,"\n"); fprintf(fp,"%s\n",label); /* minimum and maximum x */ xmin = x[0]; xmax = x[0]; for (i=1; i<n; i++) { xmin = MIN(xmin,x[i]); xmax = MAX(xmax,x[i]); } fprintf(fp,"minimum = %g\n",xmin); fprintf(fp,"maximum = %g\n",xmax); /* determine scale factors and shifts for converting x values to *s */ if (xmin==xmax) xscale = 1.0; else xscale = (ILC-IFC)/(xmax-xmin); if (xmin<0.0 && xmax<0.0) { ibase = ILC; xbase = xmax; } else if (xmin<0.0 && xmax>=0.0) { ibase = IFC+(0.0-xmin)*xscale; xbase = 0.0; } else { ibase = IFC; xbase = xmin; } /* loop over x values */ for (i=0; i<n; i++) { /* determine column corresponding to x value */ icx = ibase+NINT((x[i]-xbase)*xscale); icx = MAX(IFC,MIN(ILC,icx)); /* print the index, x value, and row of *s */ fprintf(fp,"%10.3e %13.6e ",f+i*d,x[i]); for (ic=IFC; ic<MIN(ibase,icx); ic++) fprintf(fp," "); for (ic=MIN(ibase,icx); ic<=MAX(ibase,icx); ic++) fprintf(fp,"*"); fprintf(fp,"\n"); } }
/*==========================================================================*/ void period_lnk(int intact,double dxs[],double dys[],double dzs[], double hmat[], double hmati[], int iperd) {/*begin routine*/ /*=======================================================================*/ /* Begin subprogram: */ /*=======================================================================*/ /* Local variable declarations */ int jpart; double sx,sy,sz; /*=======================================================================*/ /* One dimensions */ if((iperd) == 1) { for(jpart=1;jpart <= intact; ++jpart) { sx =dxs[jpart]*(hmati)[1]; sx -= NINT(sx); dxs[jpart] = sx*(hmat)[1]; }/*endfor*/ }/* endif */ /*=======================================================================*/ /* Two dimensions */ if((iperd) == 2) { for(jpart=1;jpart <= intact; ++jpart) { sx =dxs[jpart]*(hmati)[1]+dys[jpart]*(hmati)[2]; sy =dxs[jpart]*(hmati)[3]+dys[jpart]*(hmati)[4]; sx -= NINT(sx); sy -= NINT(sy); dxs[jpart] = sx*(hmat)[1]+sy*(hmat)[2]; dys[jpart] = sx*(hmat)[3]+sy*(hmat)[4]; }/* endfor */ }/* endif */ /*======================================================================*/ /* Three dimensions */ if((iperd) == 3) { for(jpart=1;jpart <= intact; ++jpart) { sx =dxs[jpart]*(hmati)[1] +dys[jpart]*(hmati)[4] +dzs[jpart]*(hmati)[7]; sy =dxs[jpart]*(hmati)[2] +dys[jpart]*(hmati)[5] +dzs[jpart]*(hmati)[8]; sz =dxs[jpart]*(hmati)[3] +dys[jpart]*(hmati)[6] +dzs[jpart]*(hmati)[9]; sx -= NINT(sx); sy -= NINT(sy); sz -= NINT(sz); dxs[jpart] =sx*(hmat)[1]+sy*(hmat)[4]+sz*(hmat)[7]; dys[jpart] =sx*(hmat)[2]+sy*(hmat)[5]+sz*(hmat)[8]; dzs[jpart] =sx*(hmat)[3]+sy*(hmat)[6]+sz*(hmat)[9]; }/* endfor */ }/* endif */ /*========================================================================*/ }/* end routine */
void sinusint(int *zp, int minx, int maxx, float dz, float *interface, float dx, float ampl, float wavel) { int j, i; j = 0; for (i = minx; i < maxx; i++) { zp[i] = NINT((interface[i] + ampl*sin(2*M_PI*j*dx/(wavel)))/dz); j++; if (SGN(zp[i]) < 0) zp[i] = 0; } return; }
void setup_fops(complex *Fop, float *Top, int nxys, int Nfoc, int nw, int npos, int ntfft, int *ixpos, int *first, float dxs, float dys, int nshots, int nxy, int nw_low, int *ircv, float *yrcv, float *xrcv, float fxsb, float fysb){ int ix, idxs, idys, iloop, iw, k, i, l; complex *ctrace; ctrace = (complex *)calloc(ntfft,sizeof(complex)); iloop = (*first ? npos : nxys) memset(&Fop[Nfoc*nxys*nw].r, 0, nxys*nw*2*sizeof(float)); /* transform muted Ni (Top) to frequency domain, input for next iteration */ //TODO: create a FFT kernel for (i = 0; i < iloop; i++) { /* set Fop to zero, so new operator can be defined within ixpos points */ for (l = 0; l < Nfoc; l++) { rc1fft(&Top[l*size+i*nts],ctrace,ntfft,-1); ix = (*first ? i : ixpos[i]); for (iw=0; iw<nw; iw++) { Fop[l*nxys*nw+iw*nxys+ix].r = ctrace[nw_low+iw].r; Fop[l*nxys*nw+iw*nxys+ix].i = mode*ctrace[nw_low+iw].i; } } } if (*first) { idxs = 1.0/dxs; idys = 1.0/dys; ircv = (int *)malloc(nshots*nxy*sizeof(int)); for (i = 0; i < nxy; i++) { for (k=0; k<nshots; k++) { ircv[k*nxy+i] = NINT((yrcv[k*nxy+i]-fysb)*idys)*nx+NINT((xrcv[k*nxy+i]-fxsb)*idxs); } } *first = 0; } free(ctrace); }