00001
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <time.h>
00005 #include <string.h>
00006 #include <math.h>
00007 #include <mkl.h>
00008 #include <sys/param.h>
00009 #include "tinterpolate.h"
00010
00011 #define minval(x,y) (((x) < (y)) ? (x) : (y))
00012 #define maxval(x,y) (((x) > (y)) ? (x) : (y))
00013
00014 #define kInterpDataDir "proj/libs/interpolate/data"
00015
00016 int tinterpolate(
00017 int nsample,
00018 double *tsample,
00019 double tint,
00020 int nconst,
00021 float **images,
00022 unsigned char **masks,
00023 float *image_out,
00024 int nx,
00025 int ny,
00026 int nlead,
00027 int method,
00028 char **filenamep,
00029
00030 float fillval,
00031 const char *path
00032 )
00033 {
00034 const unsigned char maskgood=0;
00035 int malign=32;
00036 int ncor=5000;
00037
00038 int i,j,isample;
00039 FILE *fileptr;
00040 double ti,dt,dtx;
00041 double *acor;
00042 double *a0,*a,*rh0,*coeffd;
00043 double *a1b,bta1b,*a1r,bta1r,c;
00044 int idt;
00045 int info;
00046 char uplo[] = "U";
00047 int ione = 1;
00048 float *coeff;
00049 int nmasks,imask,imask1,ngood;
00050 int *wgood;
00051 int *smasks,*ngoods;
00052 float *coeffs,*cp;
00053 float *sums,*ip;
00054 double t0,t1,t2;
00055 unsigned char *mp;
00056
00057 char *filename;
00058 double sum;
00059 double *xc,*b,*rhc,*bta1b1,*help;
00060 int iconst,jconst;
00061 char fbuf[PATH_MAX];
00062
00063 if ((nsample < 1) || (nsample > 20)) {
00064
00065
00066 printf("tinterpolate: must have 1<=nsample<=20\n");
00067 return 1;
00068 }
00069 t0=dsecnd();
00070 switch (method) {
00071 case 0:
00072 filename=strdup(*filenamep);
00073 break;
00074 case 1:
00075 snprintf(fbuf, sizeof(fbuf), "%s/%s/acort_hr12.txt", path, kInterpDataDir);
00076 filename = strdup(fbuf);
00077 break;
00078 default:
00079 printf("Unknown method in init_fill.\n");
00080 return 1;
00081 break;
00082 }
00083 fileptr = fopen (filename,"r");
00084 if (fileptr==NULL) {
00085 printf("File not found in tinterpolate.\n");
00086 return 1;
00087 }
00088 if (method != 0) {
00089 if (filenamep != NULL) {
00090 *filenamep=strdup(filename);
00091 }
00092 }
00093
00094
00095 acor=(double *)(MKL_malloc(ncor*sizeof(double),malign));
00096
00097 for (i=0;i<ncor;i++) fscanf(fileptr,"%lf",acor+i);
00098 fclose(fileptr);
00099 t0=dsecnd()-t0;
00100
00101 t1=dsecnd();
00102 a0=(double *)(MKL_malloc(nsample*nsample*sizeof(double),malign));
00103 a=(double *)(MKL_malloc(nsample*nsample*sizeof(double),malign));
00104 rh0=(double *)(MKL_malloc(nsample*sizeof(double),malign));
00105 coeffd=(double *)(MKL_malloc(nsample*sizeof(double),malign));
00106 coeff=(float *)(MKL_malloc(nsample*sizeof(float),malign));
00107 a1b=(double *)(MKL_malloc(nconst*nsample*sizeof(double),malign));
00108 a1r=(double *)(MKL_malloc(nsample*sizeof(double),malign));
00109 xc=(double *)(MKL_malloc(nsample*sizeof(double),malign));
00110 b=(double *)(MKL_malloc(nconst*nsample*sizeof(double),malign));
00111 rhc=(double *)(MKL_malloc(nconst*sizeof(double),malign));
00112 help=(double *)(MKL_malloc(nconst*sizeof(double),malign));
00113 bta1b1=(double *)(MKL_malloc(nconst*nconst*sizeof(double),malign));
00114
00115
00116 nmasks=1;
00117 for (i=0;i<nsample;i++) nmasks=2*nmasks;
00118 coeffs=(float *)(MKL_malloc(nsample*nmasks*sizeof(float),malign));
00119 wgood=(int *)(MKL_malloc(nsample*sizeof(int),malign));
00120
00121 for (i=0;i<nsample;i++) {
00122 ti=tsample[i];
00123 for (j=0;j<nsample;j++) {
00124 dt=fabs(tsample[j]-ti);
00125 idt=(float)floor(dt);
00126 dtx=dt-idt;
00127 a0[i*nsample+j]=(1.0-dtx)*acor[idt]+dtx*acor[idt+1];
00128 }
00129 dt=fabs(tint-ti);
00130 idt=(float)floor(dt);
00131 dtx=dt-idt;
00132 rh0[i]=(1.0-dtx)*acor[idt]+dtx*acor[idt+1];
00133 }
00134
00135
00136
00137
00138 for (imask=0;imask<nmasks;imask++) {
00139 cp=coeffs+nsample*imask;
00140 imask1=imask;
00141 ngood=0;
00142
00143 for (i=0;i<nsample;i++) {
00144 if ((imask1&1)==0) {
00145 wgood[ngood]=i;
00146 ngood=ngood+1;
00147 }
00148 imask1=imask1/2;
00149 cp[i]=0.0f;
00150 }
00151 if (ngood>0) {
00152
00153 for (i=0;i<ngood;i++) {
00154 for (j=0;j<ngood;j++) a[ngood*i+j]=a0[nsample*wgood[i]+wgood[j]];
00155 coeffd[i]=rh0[wgood[i]];
00156 }
00157 dpotrf(uplo,&ngood,a,&ngood,&info);
00158 switch (nconst) {
00159 case 0:
00160 dpotrs(uplo,&ngood,&ione,a,&ngood,coeffd,&ngood,&info);
00161 break;
00162 case 1:
00163 for (i=0;i<ngood;i++) a1b[i]=1.;
00164 dpotrs(uplo,&ngood,&ione,a,&ngood,a1b,&ngood,&info);
00165 bta1b=0.;
00166 for (i=0;i<ngood;i++) bta1b=bta1b+a1b[i];
00167 for (i=0;i<ngood;i++) a1r[i]=rh0[wgood[i]];
00168 dpotrs(uplo,&ngood,&ione,a,&ngood,a1r,&ngood,&info);
00169 bta1r=0.0;
00170 for (i=0;i<ngood;i++) bta1r=bta1r+a1r[i];
00171 c=(bta1r-1.)/bta1b;
00172 for (i=0;i<ngood;i++) coeffd[i]=a1r[i]-c*a1b[i];
00173 break;
00174 default:
00175
00176 for (i=0;i<ngood;i++) {
00177 xc[i]=tsample[wgood[i]]-tint;
00178 }
00179
00180
00181 for (i=0;i<ngood;i++) b[i]=1.;
00182 for (i=0;i<ngood;i++) a1b[i]=1.;
00183 rhc[0]=1.0;
00184
00185 for (iconst=1;iconst<nconst;iconst++) {
00186 for (i=0;i<ngood;i++) {
00187 b[iconst*ngood+i]=a1b[(iconst-1)*ngood+i]*xc[i];
00188 a1b[iconst*ngood+i]=a1b[(iconst-1)*ngood+i]*xc[i];
00189 }
00190 rhc[iconst]=0.0;
00191 }
00192
00193 dpotrs(uplo,&ngood,&nconst,a,&ngood,a1b,&ngood,&info);
00194
00195 for (iconst=0;iconst<nconst;iconst++) {
00196 for (jconst=0;jconst<nconst;jconst++) {
00197 sum=0.0;
00198 for (i=0;i<ngood;i++) {
00199 sum=sum+b[iconst*ngood+i]*a1b[jconst*ngood+i];
00200 }
00201 bta1b1[iconst*nconst+jconst]=sum;
00202 }
00203 }
00204 dpotrf(uplo,&nconst,bta1b1,&nconst,&info);
00205 for (iconst=0;iconst<nconst;iconst++) {
00206 sum=0.0;
00207 for (i=0;i<ngood;i++) sum=sum+a1b[iconst*ngood+i]*rh0[wgood[i]];
00208 help[iconst]=sum-rhc[iconst];
00209 }
00210 dpotrs(uplo,&nconst,&ione,bta1b1,&nconst,help,&nconst,&info);
00211 for (i=0;i<ngood;i++) a1r[i]=rh0[wgood[i]];
00212 dpotrs(uplo,&ngood,&ione,a,&ngood,a1r,&ngood,&info);
00213 for (i=0;i<ngood;i++) {
00214 sum=0.0;
00215 for (iconst=0;iconst<nconst;iconst++) {
00216 sum=sum+help[iconst]*a1b[iconst*ngood+i];
00217 }
00218 coeffd[i]=a1r[i]-sum;
00219 }
00220 break;
00221 }
00222 for (i=0;i<ngood;i++) cp[wgood[i]]=(float)coeffd[i];
00223
00224
00225
00226
00227
00228 }
00229 }
00230 t1=dsecnd()-t1;
00231
00232 t2=dsecnd();
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 smasks=(int *)(MKL_malloc(nx*sizeof(int),malign));
00266 ngoods=(int *)(MKL_malloc(nx*sizeof(int),malign));
00267 sums=(float *)(MKL_malloc(nx*sizeof(float),malign));
00268 for (j=0;j<ny;j++) {
00269 for (i=0;i<nx;i++) smasks[i]=0;
00270 for (i=0;i<nx;i++) ngoods[i]=0;
00271 for (isample=nsample-1;isample>=0;isample--) {
00272 mp=masks[isample]+nlead*j;
00273 for (i=0;i<nx;i++) {
00274 if (mp[i]!=maskgood)
00275 smasks[i]=2*smasks[i]+1;
00276 else {
00277 smasks[i]=2*smasks[i];
00278 ngoods[i]=ngoods[i]+1;
00279 }
00280 }
00281 }
00282 for (i=0;i<nx;i++) sums[i]=0.0f;
00283 for (isample=0;isample<nsample;isample++) {
00284 mp=masks[isample]+nlead*j;
00285 cp=coeffs+isample;
00286 ip=images[isample]+nlead*j;
00287 for (i=0;i<nx;i++) {
00288 if (mp[i]==maskgood) {
00289 sums[i]=sums[i]+cp[nsample*smasks[i]]*ip[i];
00290 }
00291 }
00292 }
00293 ip=image_out+nlead*j;
00294 for (i=0;i<nx;i++)
00295 if (ngoods[i] >= nconst)
00296 ip[i]=sums[i];
00297 else
00298 ip[i]=fillval;
00299
00300 }
00301 MKL_free(smasks);
00302 MKL_free(ngoods);
00303 MKL_free(sums);
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341 t2=dsecnd()-t2;
00342 printf("%d %f %f %f\n",nsample,t0,t1,t2);
00343
00344 MKL_free(acor);
00345 MKL_free(a0);
00346 MKL_free(a);
00347 MKL_free(rh0);
00348 MKL_free(coeffd);
00349 MKL_free(coeff);
00350 MKL_free(a1b);
00351 MKL_free(a1r);
00352 MKL_free(coeffs);
00353 MKL_free(wgood);
00354 free (filename);
00355 return 0;
00356 }
00357
00358
00359 int taverage(
00360 int nsample,
00361 double *tsample,
00362 double tint,
00363 int nconst,
00364 float **images,
00365 unsigned char **masks,
00366 float *image_out,
00367 int nx,
00368 int ny,
00369 int nlead,
00370 int method,
00371 char **filenamep,
00372
00373 int avmethod,
00374 int order,
00375 double tspace,
00376 int hwidth,
00377 double par1,
00378 double par2,
00379 float fillval,
00380 const char *path
00381 )
00382 {
00383 const unsigned char maskgood=0;
00384 int malign=32;
00385 int ncor=5000;
00386
00387 int i,j,k,isample,iconst,jconst;
00388 FILE *fileptr;
00389 double ti,dt,dtx,dta;
00390 double *acor;
00391 double *a0,*a,*rh0,*coeffd;
00392 double *b,*a1b,bta1b,*a1r,bta1r,c,*rhc,*xc,*bta1b1,*help;
00393 int idt;
00394 int info;
00395 char uplo[] = "U";
00396 int ione = 1;
00397 float *coeff;
00398 int nmasks,imask,imask1,ngood;
00399 int smask;
00400 int *wgood;
00401 int *smasks;
00402 float *coeffs,*cp;
00403 float sum,*sums,*ip;
00404 double t0,t1,t2;
00405 unsigned char *mp;
00406 int ix;
00407
00408 char *filename;
00409 int ibad;
00410 char fbuf[PATH_MAX];
00411
00412 if ((order < 1) || (order > 20)) {
00413
00414
00415 printf("taverage: must have 1<=order<=20\n");
00416 return 1;
00417 }
00418 t0=dsecnd();
00419 switch (method) {
00420 case 0:
00421 filename=strdup(*filenamep);
00422 break;
00423 case 1:
00424 snprintf(fbuf, sizeof(fbuf), "%s/%s/acort_hr12.txt", path, kInterpDataDir);
00425 filename = strdup(fbuf);
00426 break;
00427 default:
00428 printf("Unknown method in init_fill.\n");
00429 return 1;
00430 break;
00431 }
00432 fileptr = fopen (filename,"r");
00433 if (fileptr==NULL) {
00434 printf("File not found in taverage.\n");
00435 return 1;
00436 }
00437 if (method != 0) {
00438 if (filenamep != NULL) {
00439 *filenamep=strdup(filename);
00440 }
00441 }
00442
00443
00444 acor=(double *)(MKL_malloc(ncor*sizeof(double),malign));
00445
00446 for (i=0;i<ncor;i++) fscanf(fileptr,"%lf",acor+i);
00447 fclose(fileptr);
00448 t0=dsecnd()-t0;
00449
00450 int width,*ix1,*ixi,*ihelp,iwidth,iorder;
00451 double *tw,*tx1,*txi,*thelp,*weights,wsum;
00452 int imin,imin1,minuse,maxuse,nmiss;
00453 double tmin;
00454 float psum;
00455
00456
00457 width=2*hwidth+1;
00458 tw=(double *)(MKL_malloc(width*sizeof(double),malign));
00459 weights=(double *)(MKL_malloc(width*sizeof(double),malign));
00460 wsum=0.0;
00461 for (i=0;i<width;i++) {
00462 dt=i-hwidth+0.0;
00463 dta=fabs(dt);
00464 tw[i]=tint+tspace*dt;
00465 switch (avmethod) {
00466 case tavg_boxcar:
00467 if (dta <= par1) {
00468 weights[i]=1.0;
00469 }
00470 else {
00471 weights[i]=0.0;
00472 }
00473 break;
00474 case tavg_cosine:
00475 if (dta <= (par1-par2)) {
00476 weights[i]=1.0;
00477 }
00478 else if (dta >= (par1+par2)) {
00479 weights[i]=0.0;
00480 }
00481 else {
00482 dtx=(dta-par1)/par2;
00483 weights[i]=0.5*(1-sin(M_PI*dtx/2));
00484 }
00485 break;
00486 case tavg_fourth:
00487 if (dta <= (par1-par2)) {
00488 weights[i]=1.0;
00489 }
00490 else if (dta >= (par1+par2)) {
00491 weights[i]=0.0;
00492 }
00493 else {
00494 dtx=(dta-par1)/par2;
00495 weights[i]=0.5+(-0.75+0.25*dtx*dtx)*dtx;
00496 }
00497 break;
00498 case tavg_hathaway:
00499 weights[i]=(exp(dt*dt/(2*par1*par1))-exp(par2*par2/(2*par1*par1)))*(1+(par2*par2-dt*dt)/(2*par1*par1));
00500 break;
00501 default:
00502 printf("Unimplemented method in taverage\n");
00503 return 1;
00504 }
00505 printf("%d %f %f %f\n",i,dt,dta,weights[i]);
00506 wsum=wsum+weights[i];
00507 }
00508
00509 for (i=0;i<width;i++) weights[i]=weights[i]/wsum;
00510
00511
00512
00513 ix1=(int *)(MKL_malloc(order*width*sizeof(int),malign));
00514 tx1=(double *)(MKL_malloc(order*width*sizeof(double),malign));
00515 thelp=(double *)(MKL_malloc(nsample*sizeof(double),malign));
00516 ihelp=(int *)(MKL_malloc(nsample*sizeof(int),malign));
00517
00518 minuse=nsample;
00519 maxuse=-1;
00520 for (i=0;i<width;i++) {
00521 for (k=0;k<nsample;k++) {
00522 ihelp[k]=k;
00523 thelp[k]=tsample[k];
00524 }
00525 for (j=0;j<order;j++) {
00526 tmin=1e6;
00527 for (k=0;k<nsample-j;k++) {
00528 if (fabs(thelp[k]-tw[i]) < tmin) {
00529 imin=k;
00530 tmin=fabs(thelp[k]-tw[i]);
00531 }
00532 }
00533 imin1=ihelp[imin];
00534 minuse=minval(minuse,imin1);
00535 maxuse=maxval(maxuse,imin1);
00536 ix1[i*order+j]=imin1;
00537 tx1[i*order+j]=tsample[imin1];
00538 for (k=imin;k<nsample-j-1;k++) {
00539 ihelp[k]=ihelp[k+1];
00540 thelp[k]=thelp[k+1];
00541 }
00542 }
00543
00544
00545
00546
00547
00548 }
00549
00550 t1=dsecnd();
00551 a0=(double *)(MKL_malloc(nsample*nsample*sizeof(double),malign));
00552 a=(double *)(MKL_malloc(nsample*nsample*sizeof(double),malign));
00553 rh0=(double *)(MKL_malloc(nsample*sizeof(double),malign));
00554 coeffd=(double *)(MKL_malloc(nsample*sizeof(double),malign));
00555 coeff=(float *)(MKL_malloc(nsample*sizeof(float),malign));
00556 b=(double *)(MKL_malloc(nconst*nsample*sizeof(double),malign));
00557 a1b=(double *)(MKL_malloc(nconst*nsample*sizeof(double),malign));
00558 help=(double *)(MKL_malloc(nconst*sizeof(double),malign));
00559 rhc=(double *)(MKL_malloc(nconst*nsample*sizeof(double),malign));
00560 bta1b1=(double *)(MKL_malloc(nconst*nconst*sizeof(double),malign));
00561 xc=(double *)(MKL_malloc(nsample*sizeof(double),malign));
00562 a1r=(double *)(MKL_malloc(nconst*nsample*sizeof(double),malign));
00563
00564 nmasks=1;
00565 for (i=0;i<order;i++) nmasks=2*nmasks;
00566
00567
00568 coeffs=(float *)(MKL_malloc(width*order*nmasks*sizeof(float),malign));
00569 wgood=(int *)(MKL_malloc(width*sizeof(int),malign));
00570
00571 for (iwidth=0;iwidth<width;iwidth++) {
00572 txi=tx1+iwidth*order;
00573 for (i=0;i<order;i++) {
00574 ti=txi[i];
00575 for (j=0;j<order;j++) {
00576 dt=fabs(txi[j]-ti);
00577 idt=(float)floor(dt);
00578 dtx=dt-idt;
00579 a0[i*order+j]=(1.0-dtx)*acor[idt]+dtx*acor[idt+1];
00580 }
00581 dt=fabs(tw[iwidth]-ti);
00582 idt=(float)floor(dt);
00583 dtx=dt-idt;
00584 rh0[i]=(1.0-dtx)*acor[idt]+dtx*acor[idt+1];
00585 }
00586
00587
00588
00589
00590 for (imask=0;imask<nmasks;imask++) {
00591
00592 cp=coeffs+order*imask+iwidth*order*nmasks;
00593 imask1=imask;
00594 ngood=0;
00595
00596 for (i=0;i<order;i++) {
00597 if ((imask1&1)==0) {
00598 wgood[ngood]=i;
00599 ngood=ngood+1;
00600 }
00601 imask1=imask1/2;
00602 cp[i]=0.0f;
00603 }
00604 if (ngood>0) {
00605
00606 for (i=0;i<ngood;i++) {
00607 for (j=0;j<ngood;j++) a[ngood*i+j]=a0[order*wgood[i]+wgood[j]];
00608 coeffd[i]=rh0[wgood[i]];
00609 }
00610 dpotrf(uplo,&ngood,a,&ngood,&info);
00611 switch (nconst) {
00612 case 0:
00613 dpotrs(uplo,&ngood,&ione,a,&ngood,coeffd,&ngood,&info);
00614 break;
00615 case 1:
00616 for (i=0;i<ngood;i++) a1b[i]=1.;
00617 dpotrs(uplo,&ngood,&ione,a,&ngood,a1b,&ngood,&info);
00618 bta1b=0.;
00619 for (i=0;i<ngood;i++) bta1b=bta1b+a1b[i];
00620 for (i=0;i<ngood;i++) a1r[i]=rh0[wgood[i]];
00621 dpotrs(uplo,&ngood,&ione,a,&ngood,a1r,&ngood,&info);
00622 bta1r=0.0;
00623 for (i=0;i<ngood;i++) bta1r=bta1r+a1r[i];
00624 c=(bta1r-1.)/bta1b;
00625 for (i=0;i<ngood;i++) coeffd[i]=a1r[i]-c*a1b[i];
00626 break;
00627 default:
00628
00629 for (i=0;i<ngood;i++) {
00630 xc[i]=tx1[iwidth*order+wgood[i]]-tw[iwidth];
00631 }
00632
00633
00634 for (i=0;i<ngood;i++) b[i]=1.;
00635 for (i=0;i<ngood;i++) a1b[i]=1.;
00636 rhc[0]=1.0;
00637
00638 for (iconst=1;iconst<nconst;iconst++) {
00639 for (i=0;i<ngood;i++) {
00640 b[iconst*ngood+i]=a1b[(iconst-1)*ngood+i]*xc[i];
00641 a1b[iconst*ngood+i]=a1b[(iconst-1)*ngood+i]*xc[i];
00642 }
00643 rhc[iconst]=0.0;
00644 }
00645
00646 dpotrs(uplo,&ngood,&nconst,a,&ngood,a1b,&ngood,&info);
00647
00648 for (iconst=0;iconst<nconst;iconst++) {
00649 for (jconst=0;jconst<nconst;jconst++) {
00650 sum=0.0;
00651 for (i=0;i<ngood;i++) {
00652 sum=sum+b[iconst*ngood+i]*a1b[jconst*ngood+i];
00653 }
00654 bta1b1[iconst*nconst+jconst]=sum;
00655 }
00656 }
00657 dpotrf(uplo,&nconst,bta1b1,&nconst,&info);
00658 for (iconst=0;iconst<nconst;iconst++) {
00659 sum=0.0;
00660 for (i=0;i<ngood;i++) sum=sum+a1b[iconst*ngood+i]*rh0[wgood[i]];
00661 help[iconst]=sum-rhc[iconst];
00662 }
00663 dpotrs(uplo,&nconst,&ione,bta1b1,&nconst,help,&nconst,&info);
00664 for (i=0;i<ngood;i++) a1r[i]=rh0[wgood[i]];
00665 dpotrs(uplo,&ngood,&ione,a,&ngood,a1r,&ngood,&info);
00666 for (i=0;i<ngood;i++) {
00667 sum=0.0;
00668 for (iconst=0;iconst<nconst;iconst++) {
00669 sum=sum+help[iconst]*a1b[iconst*ngood+i];
00670 }
00671 coeffd[i]=a1r[i]-sum;
00672 }
00673 break;
00674 }
00675 for (i=0;i<ngood;i++) cp[wgood[i]]=(float)coeffd[i];
00676
00677
00678
00679
00680
00681 }
00682 }
00683
00684
00685
00686
00687
00688 }
00689 t1=dsecnd()-t1;
00690
00691 t2=dsecnd();
00692
00693
00694 float *coeff0;
00695 coeff0=(float *)(MKL_malloc(nsample*sizeof(float),malign));
00696 for (isample=0;isample<nsample;isample++) coeff0[isample]=0.0f;
00697 for (iwidth=0;iwidth<width;iwidth++) {
00698 sum=0.0;
00699 txi=tx1+iwidth*order;
00700 for (iorder=0;iorder<order;iorder++) {
00701 sum=sum+txi[iorder]*coeffs[iwidth*order*nmasks+iorder];
00702 isample=ix1[iwidth*order+iorder];
00703 coeff0[isample]=coeff0[isample]+coeffs[iwidth*order*nmasks+iorder]*weights[iwidth];
00704 }
00705 printf("%d %f %f %f\n",iwidth,tw[iwidth],sum,sum-tw[iwidth]);
00706 }
00707
00708 sum=0.0;
00709 for (isample=0;isample<nsample;isample++) {
00710 printf("%d %f %f\n",isample,tsample[isample],coeff0[isample]);
00711 sum=sum+tsample[isample]*coeff0[isample];
00712 }
00713 printf("%f\n",sum);
00714
00715
00716
00717 for (j=0;j<ny;j++) {
00718 for (i=0;i<nx;i++) {
00719 ix=i+nlead*j;
00720 nmiss=0;
00721 for (isample=0;isample<nsample;isample++) {
00722 if (masks[isample][ix]!=maskgood) nmiss=nmiss+1;
00723 }
00724 sum=0.0f;
00725 ibad=0;
00726 if (nmiss==0) {
00727 for (isample=0;isample<nsample;isample++) sum=sum+coeff0[isample]*images[isample][ix];
00728 }
00729 else {
00730
00731 for (iwidth=0;iwidth<width;iwidth++) {
00732
00733 smask=0;
00734 ngood=0;
00735 for (iorder=order-1;iorder>=0;iorder--) {
00736 isample=ix1[iwidth*order+iorder];
00737 if (masks[isample][ix]!=maskgood)
00738 smask=2*smask+1;
00739 else {
00740 smask=2*smask;
00741 ngood=ngood+1;
00742 }
00743 }
00744 if (ngood < nconst) ibad=1;
00745 cp=coeffs+order*smask+iwidth*order*nmasks;
00746 psum=0.0f;
00747 if (smask==0) {
00748 for (iorder=0;iorder<order;iorder++) {
00749 isample=ix1[iwidth*order+iorder];
00750 psum=psum+cp[iorder]*images[isample][ix];
00751 }
00752 }
00753 else {
00754 for (iorder=0;iorder<order;iorder++) {
00755 isample=ix1[iwidth*order+iorder];
00756 if (masks[isample][ix]==maskgood) {
00757 psum=psum+cp[iorder]*images[isample][ix];
00758 }
00759 }
00760 }
00761 sum=sum+psum*weights[iwidth];
00762 }
00763 }
00764 if (ibad == 0) {
00765 image_out[ix]=sum;
00766 }
00767 else {
00768 image_out[ix]=fillval;
00769 }
00770 }
00771 }
00772
00773 t2=dsecnd()-t2;
00774
00775
00776 MKL_free(acor);
00777 MKL_free(a0);
00778 MKL_free(a);
00779 MKL_free(rh0);
00780 MKL_free(coeffd);
00781 MKL_free(coeff);
00782 MKL_free(a1b);
00783 MKL_free(a1r);
00784 MKL_free(coeffs);
00785 MKL_free(wgood);
00786 free (filename);
00787 return 0;
00788 }
00789
00790 char *tinterpolate_version()
00791 {
00792 return strdup("$Id: tinterpolate.c,v 1.9 2011/12/06 18:11:03 arta Exp $");
00793 }
00794
00795