00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <math.h>
00024 #include <complex.h>
00025 #include <jsoc_main.h>
00026 #include <omp.h>
00027
00028 #undef I //I is the complex number (0,1). We un-define it to avoid confusion
00029
00030 struct parameterDoppler {
00031 double FSRNB;
00032 double FSRWB;
00033 double FSRE1;
00034 double FSRE2;
00035 double FSRE3;
00036 double FSRE4;
00037 double FSRE5;
00038 double dlamdv;
00039 int maxVtest;
00040 int maxNx;
00041 int ntest;
00042 double dvtest;
00043 float MISSINGDATA;
00044 float MISSINGRESULT;
00045 double coeff0;
00046 double coeff1;
00047 double coeff2;
00048 double coeff3;
00049 int QuickLook;
00050 };
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 int Dopplergram_largercrop(DRMS_Array_t **arrLev1p,DRMS_Array_t **arrLev15,int framelistSize,DRMS_Array_t *Lookuptable,float Rsun,float X0,float Y0,struct parameterDoppler DopplerParameters,int MISSVALS[5],int *SATVALS,float cdelt1,TIME TargetTime)
00061 {
00062
00063 double FSR[7];
00064 double dlamdv;
00065 int maxVtest;
00066 int maxNx;
00067 int ntest;
00068 double dvtest;
00069 float MISSINGDATA;
00070 float MISSINGRESULT;
00071 int i,j,iii;
00072 int QUICKLOOK;
00073 float ExtraCrop = 90.;
00074
00075 double magnetic = 1.0/(2.0*4.67E-5*0.000061733433*2.5*299792458.0);
00076
00077
00078 double cost[3]={1.0,0.70710678,0.5};
00079 double minimumCoeffs[2]={0.41922611,0.24190794};
00080 double FWHMCoeffs[2]={151.34559,-58.521771};
00081 double FWHM,minimum,angulardistance,minimumR,minimumL;
00082 double coeff[4];
00083
00084 FSR[0]=DopplerParameters.FSRNB;
00085 FSR[1]=DopplerParameters.FSRWB;
00086 FSR[2]=DopplerParameters.FSRE1;
00087 FSR[3]=DopplerParameters.FSRE2;
00088 FSR[4]=DopplerParameters.FSRE3;
00089 FSR[5]=DopplerParameters.FSRE4;
00090 FSR[6]=DopplerParameters.FSRE5;
00091 dlamdv=DopplerParameters.dlamdv;
00092 maxVtest=DopplerParameters.maxVtest;
00093 maxNx=DopplerParameters.maxNx;
00094 ntest=DopplerParameters.ntest;
00095 dvtest=DopplerParameters.dvtest;
00096 MISSINGDATA=DopplerParameters.MISSINGDATA;
00097 MISSINGRESULT=DopplerParameters.MISSINGRESULT;
00098 coeff[0]=DopplerParameters.coeff0;
00099 coeff[1]=DopplerParameters.coeff1;
00100 coeff[2]=DopplerParameters.coeff2;
00101 coeff[3]=DopplerParameters.coeff3;
00102 QUICKLOOK=DopplerParameters.QuickLook;
00103
00104 double vtest[ntest];
00105 float poly[ntest],poly2[ntest];
00106
00107 int status = 0;
00108 int error = 0;
00109 int nRows,nColumns;
00110 DRMS_Type_t type;
00111 float distance;
00112
00113
00114 if(framelistSize != 10 && framelistSize != 12 && framelistSize != 16 && framelistSize != 20)
00115 {
00116 printf("Error in subroutine computing the Dopplergrams: the framelist size is not 10, 12, 16, or 20\n");
00117 error=3;
00118 return error;
00119 }
00120
00121 int N=framelistSize/2;
00122 double *cosi;
00123 double *sini;
00124 double *cos2i;
00125 double *sin2i;
00126 cosi = (double *)malloc(N*sizeof(double));
00127 sini = (double *)malloc(N*sizeof(double));
00128 cos2i= (double *)malloc(N*sizeof(double));
00129 sin2i= (double *)malloc(N*sizeof(double));
00130 if(cosi == NULL || sini == NULL || cos2i == NULL || sin2i == NULL)
00131 {
00132 printf("Error: memory could not be allocated in the Dopplergram() function\n");
00133 exit(EXIT_FAILURE);
00134 }
00135 float L[N],R[N];
00136
00137
00138
00139 for(i=0;i<framelistSize;++i)
00140 {
00141 type = arrLev1p[i]->type;
00142 if (type != DRMS_TYPE_FLOAT)
00143 {
00144 printf("Error in subroutine computing the Dopplergrams: data type of level 1p data is not FLOAT\n");
00145 error = 1;
00146 free(cosi);
00147 free(sini);
00148 free(cos2i);
00149 free(sin2i);
00150 return error;
00151 }
00152 }
00153
00154
00155 nRows = arrLev1p[0]->axis[1];
00156 nColumns = arrLev1p[0]->axis[0];
00157
00158
00159 for(i=1;i<framelistSize;++i)
00160 {
00161 if (arrLev1p[i]->axis[1] != nRows || arrLev1p[i]->axis[0] != nColumns )
00162 {
00163 printf("Error in subroutine computing the Dopplergrams: dimensions of level 1p data are not %d x %d \n",nRows,nColumns);
00164 error = 2;
00165 free(cosi);
00166 free(sini);
00167 free(cos2i);
00168 free(sin2i);
00169 return error;
00170 }
00171 }
00172
00173
00174
00175 double correction=0.0;
00176 double a0,a1,a2,a3,a4;
00177 float *lam0g = arrLev15[0]->data ;
00178 float *B0g = arrLev15[1]->data;
00179 float *Idg = arrLev15[2]->data;
00180 float *widthg = arrLev15[3]->data;
00181 float *I0g = arrLev15[4]->data;
00182 float *rawlam0g = arrLev15[5]->data ;
00183
00184 memset(lam0g, 0.0, drms_array_size(arrLev15[0]));
00185 memset(B0g , 0.0, drms_array_size(arrLev15[1]));
00186 memset(Idg , 0.0, drms_array_size(arrLev15[2]));
00187 memset(widthg, 0.0, drms_array_size(arrLev15[3]));
00188 memset(I0g , 0.0, drms_array_size(arrLev15[4]));
00189 memset(rawlam0g,0.0, drms_array_size(arrLev15[5]));
00190
00191
00192 double FSRNB = FSR[0];
00193 double dtune = FSRNB/2.5;
00194 double dv = 1.0/dlamdv;
00195 double dvtune = dtune*dv;
00196 double *tune = NULL, *angle=NULL;
00197 tune=(double *)malloc(N*sizeof(double));
00198 if(tune == NULL)
00199 {
00200 printf("Error: unable to allocate memory to tune\n");
00201 exit(EXIT_FAILURE);
00202 }
00203 angle=(double *)malloc(N*sizeof(double));
00204 if(angle == NULL)
00205 {
00206 printf("Error: unable to allocate memory to angle\n");
00207 exit(EXIT_FAILURE);
00208 }
00209
00210
00211 if(N == 6)
00212 {
00213 printf("USING 6 WAVELENGTHS\n");
00214 tune[0]=+2.5;
00215 tune[1]=+1.5;
00216 tune[2]=+0.5;
00217 tune[3]=-0.5;
00218 tune[4]=-1.5;
00219 tune[5]=-2.5;
00220 for(i=0;i<N;++i) angle[i]=tune[i];
00221 }
00222 if(N == 5)
00223 {
00224 printf("USING 5 WAVELENGTHS\n");
00225 tune[0]=+2.0;
00226 tune[1]=+1.0;
00227 tune[2]= 0.0;
00228 tune[3]=-1.0;
00229 tune[4]=-2.0;
00230 for(i=0;i<N;++i) angle[i]=tune[i];
00231 }
00232 if(N == 8)
00233 {
00234 printf("USING 8 WAVELENGTHS\n");
00235 tune[7]=+3.5;
00236 tune[0]=+2.5;
00237 tune[1]=+1.5;
00238 tune[2]=+0.5;
00239 tune[3]=-0.5;
00240 tune[4]=-1.5;
00241 tune[5]=-2.5;
00242 tune[6]=-3.5;
00243 for(i=0;i<N;++i) angle[i]=tune[i];
00244 }
00245 if(N == 10)
00246 {
00247 printf("USING 10 WAVELENGTHS\n");
00248 tune[9]=+4.5;
00249 tune[7]=+3.5;
00250 tune[0]=+2.5;
00251 tune[1]=+1.5;
00252 tune[2]=+0.5;
00253 tune[3]=-0.5;
00254 tune[4]=-1.5;
00255 tune[5]=-2.5;
00256 tune[6]=-3.5;
00257 tune[8]=-4.5;
00258 for(i=0;i<N;++i) angle[i]=tune[i];
00259 }
00260
00261 double period = (double)(N-1)*dtune;
00262 double pv1,pv2;
00263 double f1LCPc,f1RCPc,f1LCPs,f1RCPs,f2LCPc,f2RCPc,f2LCPs,f2RCPs;
00264 double vLCP,vRCP,v2LCP,v2RCP;
00265 double temp,temp2,temp3,tempbis,temp2bis,temp3bis;
00266 double meanL=0.0,meanR=0.0;
00267
00268 pv1 = dvtune*(double)(N-1);
00269 pv2 = pv1/2.;
00270
00271 for(i=0;i<N;++i)
00272 {
00273 tune[i] = tune[i]*dtune;
00274 angle[i]= angle[i]*2.0*M_PI/(double)N;
00275 cosi[i] = cos(angle[i]);
00276 sini[i] = sin(angle[i]);
00277 cos2i[i]= cos(2.0*angle[i]);
00278 sin2i[i]= sin(2.0*angle[i]);
00279 }
00280
00281
00282
00283 float *lookupt = Lookuptable->data ;
00284 int axist[3];
00285 axist[0]=Lookuptable->axis[0];
00286 axist[1]=Lookuptable->axis[1];
00287 axist[2]=Lookuptable->axis[2];
00288 printf("Dimensions of the look-up tables: %d %d %d\n",axist[0],axist[1],axist[2]);
00289
00290 if(axist[0] > maxVtest || axist[1] > maxNx || axist[2] > maxNx)
00291 {
00292 printf("Error in subroutine computing the Dopplergrams: dimensions of the look-up tables exceed what is allowed: %d %d %d\n",maxVtest,maxNx,maxNx);
00293 error = 4;
00294 free(cosi);
00295 free(sini);
00296 free(cos2i);
00297 free(sin2i);
00298 free(tune);
00299 free(angle);
00300 return error;
00301 }
00302
00303
00304
00305 for(i=0;i<ntest;++i) vtest[i] = dvtest*((double)i-((double)ntest-1.0)/2.0);
00306
00307 int index_lo=0;
00308 int index_hi=ntest-1;
00309 float RR1,RR2;
00310 int x0,y0,x1,y1;
00311 float xa,xb,ya,yb;
00312 int ratio,indexL,indexR,indexL2,indexR2,row,column,step=10;
00313 long loc1,loc2,loc3,loc4;
00314 double Kfourier;
00315 float *tempvec=NULL;
00316 Kfourier = dtune/period*2.0;
00317 ratio = nRows/axist[2];
00318 float minlookupt1=0.0,maxlookupt1=0.0,minlookupt2=0.0,maxlookupt2=0.0;
00319
00320 int MISSVALS20=0;
00321 int MISSVALS21=0;
00322 int MISSVALS22=0;
00323 int MISSVALS23=0;
00324 int MISSVALS24=0;
00325
00326 int SATVALS2 =0;
00327 float offset=((float)ratio-1.0)/2.0;
00328
00329
00330
00331
00332
00333
00334 #pragma omp parallel default(none) reduction(+:MISSVALS20,MISSVALS21,MISSVALS22,MISSVALS23,MISSVALS24,SATVALS2) shared(step,arrLev1p,cosi,sini,cos2i,sin2i,pv1,pv2,index_lo,index_hi,vtest,period,dtune,dv,I0g,B0g,Idg,lam0g,rawlam0g,widthg,magnetic,axist,ratio,lookupt,nRows,nColumns,MISSINGDATA,MISSINGRESULT,Kfourier,Rsun,X0,Y0,ntest,tune,N,cost,minimumCoeffs,FWHMCoeffs,offset,ExtraCrop,cdelt1,TargetTime,QUICKLOOK,coeff) private(tempvec,iii,L,R,f1LCPc,f1RCPc,f1LCPs,f1RCPs,vLCP,vRCP,f2LCPc,f2RCPc,f2LCPs,f2RCPs,temp,tempbis,temp2,temp2bis,temp3,temp3bis,meanL,meanR,v2LCP,v2RCP,x0,y0,x1,y1,RR1,RR2,i,loc1,loc2,loc3,loc4,xa,xb,ya,yb,indexL,indexR,indexL2,indexR2,poly,poly2,row,column,distance,j,minlookupt1,maxlookupt1,minlookupt2,maxlookupt2,FWHM,minimum,angulardistance,minimumR,minimumL,correction,a0,a1,a2,a3,a4)
00335 {
00336
00337 #pragma omp for
00338 for(iii=0;iii<nRows*nColumns;++iii)
00339 {
00340
00341 row =iii / nColumns;
00342 column=iii % nColumns;
00343
00344 distance = sqrt(((float)row-Y0)*((float)row-Y0)+((float)column-X0)*((float)column-X0));
00345
00346
00347 if(distance <= (Rsun+ExtraCrop))
00348 {
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 distance=distance*cdelt1;
00360 FWHM=100.67102+0.015037016*distance-0.00010128197*distance*distance+3.1548385E-7*distance*distance*distance-3.7298102E-10*distance*distance*distance*distance+1.7275788E-13*distance*distance*distance*distance*distance;
00361 FWHM=FWHM/2.0/sqrt(log(2.0))/1000.;
00362
00363
00364
00365
00366
00367 for(i=0;i<N;++i)
00368 {
00369 tempvec=(float *)arrLev1p[i*2]->data;
00370 L[i]= tempvec[iii] ;
00371 tempvec=(float *)arrLev1p[i*2+1]->data;
00372 R[i]= tempvec[iii] ;
00373 }
00374
00375
00376 f1LCPc=0.0;
00377 f1RCPc=0.0;
00378 f1LCPs=0.0;
00379 f1RCPs=0.0;
00380 f2LCPc=0.0;
00381 f2RCPc=0.0;
00382 f2LCPs=0.0;
00383 f2RCPs=0.0;
00384 for(i=0;i<N;++i)
00385 {
00386 f1LCPc += cosi[i] *(double)L[i];
00387 f1RCPc += cosi[i] *(double)R[i];
00388 f1LCPs += sini[i] *(double)L[i];
00389 f1RCPs += sini[i] *(double)R[i];
00390 f2LCPc += cos2i[i]*(double)L[i];
00391 f2RCPc += cos2i[i]*(double)R[i];
00392 f2LCPs += sin2i[i]*(double)L[i];
00393 f2RCPs += sin2i[i]*(double)R[i];
00394 }
00395
00396 vLCP = atan2(-f1LCPs,-f1LCPc)*pv1/2.0/M_PI;
00397 vRCP = atan2(-f1RCPs,-f1RCPc)*pv1/2.0/M_PI;
00398 v2LCP = atan2(-f2LCPs,-f2LCPc)*pv2/2.0/M_PI;
00399 v2RCP = atan2(-f2RCPs,-f2RCPc)*pv2/2.0/M_PI;
00400 v2LCP = fmod((v2LCP-vLCP+10.5*pv2),pv2)-pv2/2.0+vLCP;
00401 v2RCP = fmod((v2RCP-vRCP+10.5*pv2),pv2)-pv2/2.0+vRCP;
00402
00403 if(isnan(f1LCPc) || isnan(f1RCPc) || isnan(f1LCPs) || isnan(f1RCPs))
00404 {
00405 MISSVALS20 +=1;
00406 MISSVALS21 +=1;
00407 MISSVALS22 +=1;
00408 MISSVALS23 +=1;
00409 MISSVALS24 +=1;
00410 lam0g[iii] = MISSINGRESULT;
00411 B0g[iii] = MISSINGRESULT;
00412 widthg[iii] = MISSINGRESULT;
00413 Idg[iii] = MISSINGRESULT;
00414 I0g[iii] = MISSINGRESULT;
00415 rawlam0g[iii] = MISSINGRESULT;
00416 continue;
00417 }
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430 x0 = floor( ((float)column-offset)/(float)ratio);
00431 y0 = floor( ((float)row-offset)/(float)ratio);
00432 x1 = x0+1;
00433 y1 = y0+1;
00434
00435 if(x1 >= axist[1])
00436 {
00437 x0 = x0-1;
00438 x1 = x1-1;
00439 }
00440 if(y1 >= axist[2])
00441 {
00442 y0 = y0-1;
00443 y1 = y1-1;
00444 }
00445
00446
00447
00448
00449
00450
00451 xb = (((float)column-offset)-(float)x0*(float)ratio)/(float)ratio;
00452 yb = (((float)row-offset)-(float)y0*(float)ratio)/(float)ratio;
00453 xa = 1.0-xb;
00454 ya = 1.0-yb;
00455
00456
00457
00458
00459 loc1=x0*axist[0]+y0*axist[0]*axist[1];
00460 loc2=x1*axist[0]+y0*axist[0]*axist[1];
00461 loc3=x0*axist[0]+y1*axist[0]*axist[1];
00462 loc4=x1*axist[0]+y1*axist[0]*axist[1];
00463
00464 indexL =ntest+1;
00465 indexR =ntest+1;
00466 indexL2=ntest+1;
00467 indexR2=ntest+1;
00468
00469
00470 memset(poly,0.0,sizeof(poly));
00471 memset(poly2,0.0,sizeof(poly2));
00472
00473 poly[0] =ya*(lookupt[loc1]*xa+lookupt[loc2]*xb)+yb*(lookupt[loc3]*xa+lookupt[loc4]*xb);
00474 poly2[0] =ya*(lookupt[loc1+ntest]*xa+lookupt[loc2+ntest]*xb)+yb*(lookupt[loc3+ntest]*xa+lookupt[loc4+ntest]*xb);
00475 minlookupt1 = poly[0];
00476 minlookupt2 = poly2[0];
00477
00478 poly[ntest-1]=ya*(lookupt[loc1+ntest-1]*xa+lookupt[loc2+ntest-1]*xb)+yb*(lookupt[loc3+ntest-1]*xa+lookupt[loc4+ntest-1]*xb);
00479 poly2[ntest-1]=ya*(lookupt[loc1+2*ntest-1]*xa+lookupt[loc2+2*ntest-1]*xb)+yb*(lookupt[loc3+2*ntest-1]*xa+lookupt[loc4+2*ntest-1]*xb);
00480 maxlookupt1 = poly[ntest-1];
00481 maxlookupt2 = poly2[ntest-1];
00482
00483 for(i=step;i<ntest;i=i+step)
00484 {
00485 poly[i] =ya*(lookupt[loc1+i]*xa+lookupt[loc2+i]*xb)+yb*(lookupt[loc3+i]*xa+lookupt[loc4+i]*xb);
00486 poly2[i] =ya*(lookupt[loc1+i+ntest]*xa+lookupt[loc2+i+ntest]*xb)+yb*(lookupt[loc3+i+ntest]*xa+lookupt[loc4+i+ntest]*xb);
00487 if(poly[i] > vLCP && poly[i-step] <= vLCP)
00488 {
00489 for(j=i-step+1;j<=i;j++)
00490 {
00491 poly[j] =ya*(lookupt[loc1+j]*xa+lookupt[loc2+j]*xb)+yb*(lookupt[loc3+j]*xa+lookupt[loc4+j]*xb);
00492 if(poly[j] > vLCP && poly[j-1] <= vLCP) indexL = j-1;
00493 }
00494 }
00495 if(poly[i] > vRCP && poly[i-step] <= vRCP)
00496 {
00497 for(j=i-step+1;j<=i;j++)
00498 {
00499 poly[j] =ya*(lookupt[loc1+j]*xa+lookupt[loc2+j]*xb)+yb*(lookupt[loc3+j]*xa+lookupt[loc4+j]*xb);
00500 if(poly[j] > vRCP && poly[j-1] <= vRCP) indexR = j-1;
00501 }
00502 }
00503 if(poly2[i]> v2LCP && poly2[i-step] <= v2LCP)
00504 {
00505 for(j=i-step+1;j<=i;j++)
00506 {
00507 poly2[j] =ya*(lookupt[loc1+j+ntest]*xa+lookupt[loc2+j+ntest]*xb)+yb*(lookupt[loc3+j+ntest]*xa+lookupt[loc4+j+ntest]*xb);
00508 if(poly2[j] > v2LCP && poly2[j-1] <= v2LCP) indexL2 = j-1;
00509 }
00510 }
00511 if(poly2[i]> v2RCP && poly2[i-step] <= v2RCP)
00512 {
00513 for(j=i-step+1;j<=i;j++)
00514 {
00515 poly2[j] =ya*(lookupt[loc1+j+ntest]*xa+lookupt[loc2+j+ntest]*xb)+yb*(lookupt[loc3+j+ntest]*xa+lookupt[loc4+j+ntest]*xb);
00516 if(poly2[j] > v2RCP && poly2[j-1] <= v2RCP) indexR2 = j-1;
00517 }
00518 }
00519 }
00520
00521
00522
00523 if(vLCP < minlookupt1)
00524 {
00525 vLCP=vtest[0];
00526 indexL=ntest+1;
00527
00528 }
00529 if(vLCP > maxlookupt1)
00530 {
00531 vLCP=vtest[ntest-1];
00532 indexL=ntest+1;
00533
00534 }
00535 if(vRCP < minlookupt1)
00536 {
00537 vRCP=vtest[0];
00538 indexR=ntest+1;
00539
00540 }
00541 if(vRCP > maxlookupt1)
00542 {
00543 vRCP=vtest[ntest-1];
00544 indexR=ntest+1;
00545
00546 }
00547 if(v2LCP < minlookupt2)
00548 {
00549 v2LCP=vtest[0];
00550 indexL2=ntest+1;
00551 }
00552 if(v2LCP > maxlookupt2)
00553 {
00554 v2LCP=vtest[ntest-1];
00555 indexL2=ntest+1;
00556 }
00557 if(v2RCP < minlookupt2)
00558 {
00559 v2RCP=vtest[0];
00560 indexR2=ntest+1;
00561 }
00562 if(v2RCP > maxlookupt2)
00563 {
00564 v2RCP=vtest[ntest-1];
00565 indexR2=ntest+1;
00566 }
00567
00568 if(indexL == ntest+1 || indexR == ntest+1 || indexL2 == ntest+1 || indexR2 == ntest+1)
00569 {
00570
00571
00572
00573
00574
00575
00576 SATVALS2 += 1;
00577 }
00578
00579
00580
00581
00582 if(indexL != ntest+1) vLCP = vtest[indexL] +(vLCP-(double)poly[indexL]) *(vtest[indexL+1] -vtest[indexL]) /((double)poly[indexL+1] -(double)poly[indexL] );
00583 if(indexR != ntest+1) vRCP = vtest[indexR] +(vRCP-(double)poly[indexR]) *(vtest[indexR+1] -vtest[indexR]) /((double)poly[indexR+1] -(double)poly[indexR] );
00584
00585 if(indexL2 != ntest+1) v2LCP = vtest[indexL2]+(v2LCP-(double)poly2[indexL2])*(vtest[indexL2+1]-vtest[indexL2])/((double)poly2[indexL2+1]-(double)poly2[indexL2]);
00586 if(indexR2 != ntest+1) v2RCP = vtest[indexR2]+(v2RCP-(double)poly2[indexR2])*(vtest[indexR2+1]-vtest[indexR2])/((double)poly2[indexR2+1]-(double)poly2[indexR2]);
00587
00588
00589
00590
00591
00592 f1LCPc = f1LCPc*Kfourier;
00593 f1RCPc = f1RCPc*Kfourier;
00594 f1LCPs = f1LCPs*Kfourier;
00595 f1RCPs = f1RCPs*Kfourier;
00596 f2LCPc = f2LCPc*Kfourier;
00597 f2RCPc = f2RCPc*Kfourier;
00598 f2LCPs = f2LCPs*Kfourier;
00599 f2RCPs = f2RCPs*Kfourier;
00600
00601
00602
00603 rawlam0g[iii] = (float)((vLCP+vRCP)/2.);
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653 correction=coeff[0]+coeff[1]*vLCP+coeff[2]*vLCP*vLCP+coeff[3]*vLCP*vLCP*vLCP;
00654 vLCP-=(float)correction;
00655 correction=coeff[0]+coeff[1]*vRCP+coeff[2]*vRCP*vRCP+coeff[3]*vRCP*vRCP*vRCP;
00656 vRCP-=(float)correction;
00657
00658
00659
00660
00661 lam0g[iii] = (float)((vLCP+vRCP)/2.);
00662 if(isnan(lam0g[iii])) MISSVALS20 += 1;
00663
00664
00665
00666
00667 B0g[iii] = (float)((vLCP-vRCP)*magnetic);
00668 if(isnan(B0g[iii])) MISSVALS21 += 1;
00669
00670
00671 temp = period/M_PI*sqrt(1.0/6.0*log((f1LCPc*f1LCPc+f1LCPs*f1LCPs)/(f2LCPc*f2LCPc+f2LCPs*f2LCPs)));
00672 tempbis = period/M_PI*sqrt(1.0/6.0*log((f1RCPc*f1RCPc+f1RCPs*f1RCPs)/(f2RCPc*f2RCPc+f2RCPs*f2RCPs)));
00673 widthg[iii] = (float)((temp+tempbis)*sqrt(log(2.0)))*1000.;
00674 if(isnan(widthg[iii])) MISSVALS23 += 1;
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684 temp2 = period/2.0*sqrt(f1LCPc*f1LCPc+f1LCPs*f1LCPs)/sqrt(M_PI)/FWHM*exp(M_PI*M_PI*FWHM*FWHM/period/period);
00685 temp2bis = period/2.0*sqrt(f1RCPc*f1RCPc+f1RCPs*f1RCPs)/sqrt(M_PI)/FWHM*exp(M_PI*M_PI*FWHM*FWHM/period/period);
00686 Idg[iii] = (float)((temp2+temp2bis)/2.0);
00687 if(isnan(Idg[iii])) MISSVALS22 += 1;
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709 temp3 = vLCP/dv;
00710 temp3bis = vRCP/dv;
00711 meanL=0.0;
00712 meanR=0.0;
00713 for(i=0;i<N;++i)
00714 {
00715 meanL += L[i];
00716 meanR += R[i];
00717 }
00718 meanL=meanL/(double)N;
00719 meanR=meanR/(double)N;
00720
00721
00722 for(i=0;i<N;++i)
00723 {
00724
00725
00726 meanL += (temp2 /(double)N*exp(-(tune[i]-temp3) *(tune[i]-temp3) /FWHM/FWHM));
00727 meanR += (temp2bis/(double)N*exp(-(tune[i]-temp3bis)*(tune[i]-temp3bis)/FWHM/FWHM));
00728 }
00729
00730 I0g[iii] = (float)((meanL+meanR)/2.0);
00731 if(isnan(I0g[iii])) MISSVALS24 += 1;
00732
00733
00734
00735 }
00736 else
00737 {
00738 lam0g[iii] = MISSINGRESULT;
00739 B0g[iii] = MISSINGRESULT;
00740 widthg[iii] = MISSINGRESULT;
00741 Idg[iii] = MISSINGRESULT;
00742 I0g[iii] = MISSINGRESULT;
00743 rawlam0g[iii] = MISSINGRESULT;
00744 }
00745
00746 }
00747 }
00748
00749
00750 free(cosi);
00751 free(sini);
00752 free(cos2i);
00753 free(sin2i);
00754 free(tune);
00755 free(angle);
00756
00757
00758
00759 MISSVALS[0]=MISSVALS20;
00760 MISSVALS[1]=MISSVALS21;
00761 MISSVALS[2]=MISSVALS22;
00762 MISSVALS[3]=MISSVALS23;
00763 MISSVALS[4]=MISSVALS24;
00764 *SATVALS=SATVALS2;
00765 return error;
00766
00767 }