00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <time.h>
00004 #include <string.h>
00005 #include <math.h>
00006 #include <mkl_blas.h>
00007 #include <mkl_service.h>
00008 #include <mkl_lapack.h>
00009 #include <mkl_vml_functions.h>
00010 #include <omp.h>
00011 #include "polcal.h"
00012 #include "fresize.h"
00013 #include "localization.h"
00014 #define minval(x,y) (((x) < (y)) ? (x) : (y))
00015 #define maxval(x,y) (((x) > (y)) ? (x) : (y))
00016
00017
00018 char polcalParamFile[] = "/home/jsoc/hmi/tables/lev15/polcal-param-fit.bin";
00019
00020 static void printm(double *m)
00021 {
00022 int i;
00023
00024 for (i=0;i<16;i++) {
00025 printf(" %f",m[i]);
00026 if ((i%4)==3) printf("\n");
00027 }
00028 }
00029
00030 static void mat4mm(
00031 double *a,
00032 double *b,
00033 double *c
00034 )
00035 {
00036 int i,j,k;
00037 double sum;
00038
00039 for (i=0;i<4;i++) {
00040 for (j=0;j<4;j++) {
00041 sum=0.0;
00042 for (k=0;k<4;k++) sum=sum+a[i+4*k]*b[k+4*j];
00043 c[i+4*j]=sum;
00044 }
00045 }
00046 }
00047
00048 static void polarizer(
00049 double phi,
00050 double *m
00051 )
00052 {
00053 double c,s;
00054
00055 c=cos(2*phi);
00056 s=sin(2*phi);
00057
00058 m[0]=0.5;
00059 m[1]=0.5*c;
00060 m[2]=0.5*s;
00061 m[3]=0.0;
00062 m[4]=0.5*c;
00063 m[5]=0.5*c*c;
00064 m[6]=0.5*s*c;
00065 m[7]=0.0;
00066 m[8]=0.5*s;
00067 m[9]=0.5*s*c;
00068 m[10]=0.5*s*s;
00069 m[11]=0.0;
00070 m[12]=0.0;
00071 m[13]=0.0;
00072 m[14]=0.0;
00073 m[15]=0.0;
00074
00075 }
00076
00077 static void retarder(
00078 double delta,
00079 double phi,
00080 double *m
00081 )
00082 {
00083 double cd,sd,c,s;
00084 int i;
00085 double pi=M_PI;
00086
00087 for (i=1;i<4;i++) m[i]=0.0;
00088 for (i=1;i<4;i++) m[4*i]=0.0;
00089
00090 m[0]=1.0;
00091 cd=cos(2*pi*delta);
00092 sd=sin(2*pi*delta);
00093 c=cos(2*phi);
00094 s=sin(2*phi);
00095 m[5]=c*c+s*s*cd;
00096 m[6]=c*s*(1-cd);
00097 m[7]=s*sd;
00098 m[9]=c*s*(1-cd);
00099 m[10]=s*s+c*c*cd;
00100 m[11]=-c*sd;
00101 m[13]=-s*sd;
00102 m[14]=c*sd;
00103 m[15]=cd;
00104
00105 }
00106
00107 int init_polcal(struct polcal_struct *pars, int method)
00108 {
00109 int nin=32;
00110 int malign=32;
00111 int i,j;
00112 double d;
00113 FILE *fileptr = NULL;
00114
00115 if (method!=1) {
00116 printf("Unimplemented method in init_polcal\n");
00117 return 1;
00118 }
00119 pars->method=method;
00120 pars->nin=nin;
00121 pars->xin=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00122 pars->yin=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00123 pars->fqq_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00124 pars->fqq_1=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00125 pars->fqq_2=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00126 pars->fqu_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00127 pars->fqv_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00128 pars->fuu_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00129 pars->fuu_1=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00130 pars->fuu_2=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00131 pars->fuv_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00132 pars->fvv_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00133 pars->fvv_1=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00134 pars->fvv_2=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00135 pars->ret1_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00136 pars->ret1_1=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00137 pars->ret2_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00138 pars->ret2_1=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00139 pars->ret3_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00140 pars->ret3_1=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00141 pars->phi1_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00142 pars->phi2_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00143 pars->phi3_0=(double *)(MKL_malloc(nin*nin*sizeof(double),malign));
00144
00145
00146
00147
00148
00149
00150
00151 if (polcalParamFile)
00152 {
00153 fileptr = fopen(polcalParamFile, "r");
00154 }
00155
00156 if (fileptr == NULL)
00157 {
00158 fileptr = fopen(POLCAL_PARAMS, "r");
00159 }
00160
00161 if (fileptr==NULL) {
00162 printf("File not found in init_polcal.\n");
00163 return 1;
00164 }
00165
00166 fread (&pars->tsela,sizeof(double),1,fileptr);
00167 fread (&pars->tfronta,sizeof(double),1,fileptr);
00168 fread (pars->fqq_0,sizeof(double),nin*nin,fileptr);
00169 fread (pars->fqq_1,sizeof(double),nin*nin,fileptr);
00170 fread (pars->fqq_2,sizeof(double),nin*nin,fileptr);
00171 fread (pars->fqu_0,sizeof(double),nin*nin,fileptr);
00172 fread (pars->fqv_0,sizeof(double),nin*nin,fileptr);
00173 fread (pars->fuu_0,sizeof(double),nin*nin,fileptr);
00174 fread (pars->fuu_1,sizeof(double),nin*nin,fileptr);
00175 fread (pars->fuu_2,sizeof(double),nin*nin,fileptr);
00176 fread (pars->fuv_0,sizeof(double),nin*nin,fileptr);
00177 fread (pars->fvv_0,sizeof(double),nin*nin,fileptr);
00178 fread (pars->fvv_1,sizeof(double),nin*nin,fileptr);
00179 fread (pars->fvv_2,sizeof(double),nin*nin,fileptr);
00180 fread (pars->ret1_0,sizeof(double),nin*nin,fileptr);
00181 fread (pars->ret1_1,sizeof(double),nin*nin,fileptr);
00182 fread (pars->ret2_0,sizeof(double),nin*nin,fileptr);
00183 fread (pars->ret2_1,sizeof(double),nin*nin,fileptr);
00184 fread (pars->ret3_0,sizeof(double),nin*nin,fileptr);
00185 fread (pars->ret3_1,sizeof(double),nin*nin,fileptr);
00186 fread (pars->phi1_0,sizeof(double),nin*nin,fileptr);
00187 fread (pars->phi2_0,sizeof(double),nin*nin,fileptr);
00188 fread (pars->phi3_0,sizeof(double),nin*nin,fileptr);
00189 fclose(fileptr);
00190
00191 for (i=0;i<nin;i++) {
00192 d=(i-(nin/2-0.5))/(nin/2);
00193 for (j=0;j<nin;j++) {
00194 pars->xin[j*nin+i]=d;
00195 pars->yin[i*nin+j]=d;
00196 }
00197 }
00198
00199 return 0;
00200 }
00201
00202 int free_polcal(
00203 struct polcal_struct *pars
00204 )
00205 {
00206 MKL_free(pars->xin);
00207 MKL_free(pars->yin);
00208 MKL_free(pars->fqq_0);
00209 MKL_free(pars->fqq_1);
00210 MKL_free(pars->fqq_2);
00211 MKL_free(pars->fqu_0);
00212 MKL_free(pars->fqv_0);
00213 MKL_free(pars->fuu_0);
00214 MKL_free(pars->fuu_1);
00215 MKL_free(pars->fuu_2);
00216 MKL_free(pars->fuv_0);
00217 MKL_free(pars->fvv_0);
00218 MKL_free(pars->fvv_1);
00219 MKL_free(pars->fvv_2);
00220 MKL_free(pars->ret1_0);
00221 MKL_free(pars->ret1_1);
00222 MKL_free(pars->ret2_0);
00223 MKL_free(pars->ret2_1);
00224 MKL_free(pars->ret3_0);
00225 MKL_free(pars->ret3_1);
00226 MKL_free(pars->phi1_0);
00227 MKL_free(pars->phi2_0);
00228 MKL_free(pars->phi3_0);
00229
00230 return 0;
00231 }
00232
00233 int polcal(
00234 struct polcal_struct *pars,
00235 int nframe,
00236 int mode,
00237 float **input,
00238 float **output,
00239 int *ps1,
00240 int *ps2,
00241 int *ps3,
00242 float tsel,
00243 float tfront,
00244 int nx,
00245 int ny,
00246 int nlead
00247 )
00248 {
00249 int malign=32;
00250 int nin,polsol,polout;
00251 int i,j,k,ix,iy,iz,iframe,ipol;
00252 float *demod_in;
00253 double ts,tf;
00254 double dqq,duu,dvv,dqu,dqv,duv,dret1,dret2,dret3,dphi1,dphi2,dphi3;
00255 double *mtel,*mhelp,*m,*m1,*m2,*m3,*dmat;
00256 double *pl1angle,*pl2angle,*pl3angle;
00257 const double dir[]={-1,-1,1};
00258 const double pi=M_PI;
00259 const double pmax=0.938508*2048./1924.*pi/180;
00260 const double splitmax=0.01837;
00261 double x0,y0,dist0,phi0,phi,delta;
00262 double sum;
00263 char uplo[] = "U";
00264 int ifour=4;
00265 int info1,info2;
00266 float xscale,yscale,xzero,yzero;
00267 float xi,yi,*cx0,*cx1,cy0,cy1;
00268 int *ix0,iy0;
00269 float c00,c01,c10,c11,demod_out;
00270 int iz00,iz01,iz10,iz11;
00271 double pscale;
00272 const float tscale=0.0f;
00273 float fiq,fiu,fiv;
00274 int minps2,maxps2;
00275 int leakcor;
00276 int psfcor;
00277 struct fresize_struct psf_q;
00278 struct fresize_struct psf_u;
00279 float *helpq,*helpu;
00280 float xx,yy,yy2,rr2x,*xx2s;
00281 float fiq0,fiq1,fiq2,fiq3,fiq4;
00282 float fiu0,fiu1,fiu2,fiu3,fiu4;
00283 float fiv0,fiv1,fiv2,fiv3,fiv4;
00284 float int0,int1,int2,int3,int4,int5;
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 const float kerq_new[5][5] =
00310 {{0.0025540328,0.0014054127,-0.0068338746,-0.0036082337,0.0030879086},
00311 {-0.0021203885,0.0024757898,-0.00038367994,0.0033062588,-0.00040921161},
00312 {-0.0072601518,-0.0025927805,0.026828298,0.0042583267,-0.0095492689},
00313 {-0.0018917886,0.0010262981,-0.0091327691,0.0010989052,-0.0036920641},
00314 {0.0015600444,0.00071167337,-0.0033762701,0.0011738308,0.0013651198}};
00315
00316 const float keru_new[5][5] =
00317 {{-0.00049870912,0.0027657090,0.0021755355,-0.0048088858,-0.0017044651},
00318 {-0.0037942851,-0.0036754557,-0.00044049794,-0.0025652278,0.0055248008},
00319 {0.00069222959,-0.0033606194,0.018997891,-0.0026897083,0.0019509337},
00320 {0.0031935224,-0.0020587455,-0.00015615637,-0.0033495235,-0.0048827137},
00321 {-7.6658680e-05,-0.0034658817,0.0010824736,0.0022102219,-0.0010668119}};
00322
00323
00324
00325 const float kerq_old[5][5] =
00326 {{0.0037206091,-0.0019643126,-0.016193939,-0.0076218857,0.0043843131},
00327 {0.00049905806,0.0040439727,-0.017494203,0.0024333910,0.0030044689},
00328 {-0.0067546715,0.0080826366,0.062275348,0.010767046,-0.0089655220},
00329 {-0.0024383606,0.00057499661,-0.023057758,0.00071254324,-0.0036152480},
00330 {0.0026420443,-0.0017713332,-0.013929130,-0.0018103380,0.0024885890}};
00331
00332 const float keru_old[5][5] =
00333 {{0.0018666587,0.0075391244,0.00049939188,-0.0097649409,-0.0032506137},
00334 {-0.0033866379,0.0057003782,-0.0046985594,-0.012012604,0.0052348375},
00335 {-0.00060864512,-0.0028413328,0.023487552,-0.0011891184,0.0022289085},
00336 {0.0029176405,-0.013011020,-0.0013825372,0.0083993347,-0.0044858224},
00337 {0.00094548694,-0.0086396909,-0.00012516038,0.0078249956,-0.0012269566}};
00338
00339
00340
00341
00342
00343
00344 leakcor=0;
00345 psfcor=0;
00346 fiq=0.0f;
00347 fiu=0.0f;
00348 fiv=0.0f;
00349 minps2=300;
00350 maxps2=-10;
00351 for (i=0;i<nframe;i++) {
00352 minps2=minval(minps2,ps2[i]);
00353 maxps2=maxval(maxps2,ps2[i]);
00354 }
00355 if ((minps2 == 91) && (maxps2 == 91)) {
00356
00357 leakcor=1;
00358 fiq= 2.15e-4;
00359 fiu= 1.10e-4;
00360 fiv= 0.00e-4;
00361 psfcor=1;
00362 init_fresize_user(&psf_q,2,1,(float *)kerq_old);
00363 init_fresize_user(&psf_u,2,1,(float *)keru_old);
00364 }
00365 if ((minps2 == 53) && (maxps2 == 53)) {
00366
00367
00368
00369
00370
00371
00372 leakcor=2;
00373
00374 fiq0= 2.0411683e-06;
00375 fiq1= 0.00012040193;
00376 fiq2= 0.00026537064;
00377 fiq3= -0.00059574417;
00378 fiq4= -0.0026085394;
00379
00380 fiu0= -0.00011803840;
00381 fiu1= 0.00011883301;
00382 fiu2= 0.00023335908;
00383 fiu3= -0.0011413839;
00384 fiu4= -0.0034897879;
00385
00386
00387 fiv0= 4.2255156e-06;
00388 fiv1= 1.7374540e-05;
00389 fiv2= 1.3426406e-05;
00390 fiv3= 0.00012586214;
00391 fiv4= 0.00045829690;
00392 fiv0=sqrt(-1.0);
00393
00394 psfcor=1;
00395 init_fresize_user(&psf_q,2,1,(float *)kerq_new);
00396 init_fresize_user(&psf_u,2,1,(float *)keru_new);
00397 }
00398 if (minps2 != maxps2) {
00399 printf("Variable PS2 positions. Not correcting for instrumental polarization.\n");
00400 }
00401 if ((minps2 != 53) && (minps2 !=91)) {
00402 printf("Non-standard PS2 positions. Not correcting for instrumental polarization.\n");
00403 }
00404
00405 pscale=0.5;
00406 if ((mode<1) || (mode>3)) {
00407 printf("Bad output polarization in polcal: %d.\n",mode);
00408 return 1;
00409 }
00410 if (mode == 1) {
00411
00412 polsol=4;
00413 polout=4;
00414 }
00415 if (mode == 2) {
00416
00417 polsol=4;
00418 polout=2;
00419 }
00420 if (mode == 3) {
00421
00422 polsol=2;
00423 polout=2;
00424 }
00425 nin=pars->nin;
00426 ts=tsel-pars->tsela;
00427 tf=tscale*(tfront-pars->tfronta);
00428
00429 demod_in=(float *)MKL_malloc(nin*nin*nframe*polsol*sizeof(double),malign);
00430 mtel=(double *)MKL_malloc(16*sizeof(double),malign);
00431 mhelp=(double *)MKL_malloc(16*sizeof(double),malign);
00432 m=(double *)MKL_malloc(16*sizeof(double),malign);
00433 m1=(double *)MKL_malloc(16*sizeof(double),malign);
00434 m2=(double *)MKL_malloc(16*sizeof(double),malign);
00435 m3=(double *)MKL_malloc(16*sizeof(double),malign);
00436 dmat=(double *)MKL_malloc(4*nframe*sizeof(double),malign);
00437 pl1angle=(double *)MKL_malloc(nframe*sizeof(double),malign);
00438 pl2angle=(double *)MKL_malloc(nframe*sizeof(double),malign);
00439 pl3angle=(double *)MKL_malloc(nframe*sizeof(double),malign);
00440
00441 for (i=0;i<nframe;i++) {
00442 pl1angle[i]=ps1[i]*1.5*pi/180*dir[0];
00443 pl2angle[i]=ps2[i]*1.5*pi/180*dir[1];
00444 pl3angle[i]=ps3[i]*1.5*pi/180*dir[2];
00445 }
00446
00447
00448 mtel[0]=1;mtel[1]=0;mtel[2]=0;mtel[3]=0;
00449 mtel[4]=0;mtel[8]=0;mtel[12]=0;
00450 for (iy=0;iy<nin;iy++) {
00451 for (ix=0;ix<nin;ix++) {
00452 iz=nin*iy+ix;
00453 x0=(ix-(nin/2-0.5))/(nin/2);
00454 y0=(iy-(nin/2-0.5))/(nin/2);
00455 dist0=sqrt(x0*x0+y0*y0)*pmax;
00456 phi0=atan2(y0,x0);
00457
00458 dqq=pars->fqq_0[iz]+pars->fqq_1[iz]*tf+pars->fqq_2[iz]*tf*tf;
00459 duu=pars->fuu_0[iz]+pars->fuu_1[iz]*tf+pars->fuu_2[iz]*tf*tf;
00460 dvv=pars->fvv_0[iz]+pars->fvv_1[iz]*tf+pars->fvv_2[iz]*tf*tf;
00461 dqu=pars->fqu_0[iz];
00462 dqv=pars->fqv_0[iz];
00463 duv=pars->fuv_0[iz];
00464
00465 dret1=pars->ret1_0[iz]+pars->ret1_1[iz]*ts;
00466 dret2=pars->ret2_0[iz]+pars->ret2_1[iz]*ts;
00467 dret3=pars->ret3_0[iz]+pars->ret3_1[iz]*ts;
00468 dphi1=pars->phi1_0[iz];
00469 dphi2=pars->phi2_0[iz];
00470 dphi3=pars->phi3_0[iz];
00471
00472
00473 mtel[5]=dqq;mtel[6]=dqu;mtel[7]=dqv;
00474 mtel[9]=dqu;mtel[10]=duu;mtel[11]=duv;
00475 mtel[13]=-dqv;mtel[14]=-duv;mtel[15]=dvv;
00476
00477 for (iframe=0;iframe<nframe;iframe++) {
00478 phi=pl1angle[iframe]-dphi1;
00479 delta=dret1*(1+0.5*dist0*dist0*cos(2*(phi0-phi)));
00480 retarder(delta,phi,mhelp);
00481 mat4mm(mhelp,mtel,m1);
00482
00483 phi=pl2angle[iframe]-dphi2;
00484 delta=dret2*(1+0.5*dist0*dist0*cos(2*(phi0-phi)));
00485 retarder(delta,phi,mhelp);
00486 mat4mm(mhelp,m1,m2);
00487
00488 phi=pl3angle[iframe]-dphi3;
00489 delta=dret3*(1+0.5*dist0*dist0*cos(2*(phi0-phi)));
00490 retarder(delta,phi,mhelp);
00491 mat4mm(mhelp,m2,m3);
00492
00493 phi=pi/2 + y0*splitmax;
00494 polarizer(phi,mhelp);
00495 mat4mm(mhelp,m3,m);
00496
00497
00498 for (ipol=0;ipol<4;ipol++) dmat[4*iframe+ipol]=m[4*ipol];
00499
00500 }
00501
00502 if (polsol==4) {
00503
00504 for (i=0;i<4;i++) {
00505 for (j=0;j<4;j++) {
00506 sum=0.0;
00507 for (iframe=0;iframe<nframe;iframe++) sum=sum+dmat[i+4*iframe]*dmat[j+4*iframe];
00508 mhelp[4*i+j]=sum;
00509 }
00510 }
00511 }
00512
00513
00514 if (polsol==2) {
00515
00516 for (i=0;i<nframe;i++) dmat[4*i+1]=dmat[4*i+3];
00517 for (i=0;i<2;i++) {
00518 for (j=0;j<2;j++) {
00519 sum=0.0;
00520 for (iframe=0;iframe<nframe;iframe++) sum=sum+dmat[i+4*iframe]*dmat[j+4*iframe];
00521 mhelp[4*i+j]=sum;
00522 }
00523 }
00524 }
00525
00526 dpotrf(uplo,&polsol,mhelp,&ifour,&info1);
00527 dpotrs(uplo,&polsol,&nframe,mhelp,&ifour,dmat,&ifour,&info2);
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 if (mode==1) {
00546 for (iframe=0;iframe<nframe;iframe++) {
00547 for (ipol=0;ipol<4;ipol++)
00548 demod_in[iframe+nframe*ipol+nframe*4*iz]=dmat[ipol+4*iframe];
00549 }
00550 }
00551
00552 if (mode==2) {
00553 for (iframe=0;iframe<nframe;iframe++) {
00554 demod_in[iframe+nframe*0+nframe*2*iz]=dmat[4*iframe]+dmat[3+4*iframe];
00555 demod_in[iframe+nframe*1+nframe*2*iz]=dmat[4*iframe]-dmat[3+4*iframe];
00556 }
00557 }
00558
00559 if (mode==3) {
00560 for (iframe=0;iframe<nframe;iframe++) {
00561 demod_in[iframe+nframe*0+nframe*2*iz]=dmat[4*iframe]+dmat[1+4*iframe];
00562 demod_in[iframe+nframe*1+nframe*2*iz]=dmat[4*iframe]-dmat[1+4*iframe];
00563 }
00564 }
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576 }
00577 }
00578
00579 xscale=(nin+0.0)/nx;
00580 xzero=-xscale*(nx-1)/2+(nin-1.)/2;
00581 yscale=(nin+0.0)/ny;
00582 yzero=-yscale*(ny-1)/2+(nin-1.)/2;
00583
00584 i=floor(xzero);
00585 j=floor(xscale);
00586
00587 ix0=(int *)MKL_malloc(nx*sizeof(int),malign);
00588 cx0=(float *)MKL_malloc(nx*sizeof(float),malign);
00589 cx1=(float *)MKL_malloc(nx*sizeof(float),malign);
00590 for (ix=0;ix<nx;ix++) {
00591
00592 xi=xzero+ix*xscale;
00593 ix0[ix]=minval(maxval(0,floor(xi)),(nin-2));
00594 cx1[ix]=xi-ix0[ix];
00595 cx0[ix]=1.0-cx1[ix];
00596 }
00597
00598 #pragma omp parallel for default(none) \
00599 private(ix,iy,iz,yi,iy0,cy0,cy1,iz00,iz01,iz10,iz11,c00,c01,c10,c11,ipol,sum,iframe,demod_out) \
00600 shared(nlead,output,nx,ny,yzero,yscale,nin,ix0,cx0,cx1,nframe,polout,demod_in,pscale,fiq,fiu,fiv,mode,input)
00601 for (iy=0;iy<ny;iy++) {
00602 yi=yzero+iy*yscale;
00603 iy0=minval(maxval(0,floor(yi)),(nin-2));
00604 cy1=yi-iy0;
00605 cy0=1.0-cy1;
00606 for (ix=0;ix<nx;ix++) {
00607 iz=nlead*iy+ix;
00608 iz00=nin*iy0+ix0[ix];
00609 iz01=nin*iy0+ix0[ix]+1;
00610 iz10=nin*(iy0+1)+ix0[ix];
00611 iz11=nin*(iy0+1)+ix0[ix]+1;
00612 c00=cy0*cx0[ix];
00613 c01=cy0*cx1[ix];
00614 c10=cy1*cx0[ix];
00615 c11=cy1*cx1[ix];
00616 for (ipol=0;ipol<polout;ipol++) {
00617 sum=0.0;
00618 for (iframe=0;iframe<nframe;iframe++) {
00619
00620 demod_out=c00*demod_in[iframe+nframe*ipol+nframe*polout*iz00]+
00621 c01*demod_in[iframe+nframe*ipol+nframe*polout*iz01]+
00622 c10*demod_in[iframe+nframe*ipol+nframe*polout*iz10]+
00623 c11*demod_in[iframe+nframe*ipol+nframe*polout*iz11];
00624
00625 sum=sum+demod_out*input[iframe][iz];
00626 }
00627 output[ipol][iz]=pscale*sum;
00628 }
00629
00630
00631
00632
00633
00634
00635
00636 }
00637 }
00638
00639 if ((mode == 1) && (leakcor == 1)) {
00640 #pragma omp parallel for default(none) \
00641 private(ix,iy,iz) \
00642 shared(nlead,output,helpq,helpu,nx,ny,fiq,fiu,fiv)
00643 for (iy=0;iy<ny;iy++) {
00644 for (ix=0;ix<nx;ix++) {
00645 iz=nlead*iy+ix;
00646 output[1][iz]=output[1][iz]-fiq*output[0][iz];
00647 output[2][iz]=output[2][iz]-fiu*output[0][iz];
00648 output[3][iz]=output[3][iz]-fiv*output[0][iz];
00649 }
00650 }
00651 }
00652
00653 if ((mode == 1) && (leakcor == 2)) {
00654 xx2s=(float *)MKL_malloc(nx*sizeof(float),malign);
00655 for (ix=0;ix<nx;ix++) {
00656 xx=(ix-nx/2+0.5f)/(nx/2);
00657 xx2s[ix]=xx*xx;
00658 }
00659 #pragma omp parallel for default(none) \
00660 private(ix,iy,iz,yy,yy2,rr2x) \
00661 shared(int0,int1,int2,int3,int4) \
00662 shared(fiq0,fiq1,fiq2,fiq3,fiq4) \
00663 shared(fiu0,fiu1,fiu2,fiu3,fiu4) \
00664 shared(fiv0,fiv1,fiv2,fiv3,fiv4) \
00665 shared(nlead,output,helpq,helpu,nx,ny,fiq,fiu,fiv,xx2s)
00666 for (iy=0;iy<ny;iy++) {
00667 yy=(iy-ny/2+0.5f)/(ny/2);
00668 yy2=yy*yy;
00669 for (ix=0;ix<nx;ix++) {
00670 iz=nlead*iy+ix;
00671 rr2x=xx2s[ix]+yy2-0.5f;
00672
00673 int0=output[0][iz];
00674 int1=rr2x*int0;
00675 int2=rr2x*int1;
00676 int3=rr2x*int2;
00677 int4=rr2x*int3;
00678 output[1][iz]=output[1][iz]-fiq0*int0-fiq1*int1-fiq2*int2-fiq3*int3-fiq4*int4;
00679 output[2][iz]=output[2][iz]-fiu0*int0-fiu1*int1-fiu2*int2-fiu3*int3-fiu4*int4;
00680
00681
00682 }
00683 }
00684 MKL_free(xx2s);
00685 }
00686
00687 if ((mode == 1) && (psfcor == 1)) {
00688 helpq=(float *)MKL_malloc(ny*nlead*sizeof(float),malign);
00689 helpu=(float *)MKL_malloc(ny*nlead*sizeof(float),malign);
00690 fresize(&psf_q,output[0],helpq,nx,ny,nlead,nx,ny,nlead,0,0,0.0f);
00691 fresize(&psf_u,output[0],helpu,nx,ny,nlead,nx,ny,nlead,0,0,0.0f);
00692 #pragma omp parallel for default(none) \
00693 private(ix,iy,iz) \
00694 shared(nlead,output,helpq,helpu,nx,ny)
00695 for (iy=0;iy<ny;iy++) {
00696 for (ix=0;ix<nx;ix++) {
00697 iz=nlead*iy+ix;
00698 output[1][iz]=output[1][iz]-helpq[iz];
00699 output[2][iz]=output[2][iz]-helpu[iz];
00700 }
00701 }
00702 MKL_free(helpq);
00703 MKL_free(helpu);
00704 }
00705
00706 MKL_free(ix0);
00707 MKL_free(cx0);
00708 MKL_free(cx1);
00709 MKL_free(demod_in);
00710 MKL_free(mtel);
00711 MKL_free(mhelp);
00712 MKL_free(m);
00713 MKL_free(m1);
00714 MKL_free(m2);
00715 MKL_free(m3);
00716 MKL_free(dmat);
00717 MKL_free(pl1angle);
00718 MKL_free(pl2angle);
00719 MKL_free(pl3angle);
00720
00721 return 0;
00722 }
00723
00724 char *polcal_version()
00725 {
00726 return strdup("$Id: polcal.c,v 1.8 2016/10/03 19:11:21 arta Exp $");
00727 }
00728