00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #include <math.h>
00050 #include <mkl.h>
00051
00052 #define PI (M_PI)
00053 #define MUNAUGHT (0.0000012566370614)
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 int computeAbsFlux(float *bz_err, float *bz, int *dims, float *absFlux,
00071 float *mean_vf_ptr, float *mean_vf_err_ptr, float *count_mask_ptr, int *mask,
00072 int *bitmask, float cdelt1, double rsun_ref, double rsun_obs)
00073
00074 {
00075
00076 int nx = dims[0];
00077 int ny = dims[1];
00078 int i = 0;
00079 int j = 0;
00080 int count_mask = 0;
00081 double sum = 0.0;
00082 double err = 0.0;
00083 *absFlux = 0.0;
00084 *mean_vf_ptr = 0.0;
00085
00086
00087 if (nx <= 0 || ny <= 0) return 1;
00088
00089 for (i = 0; i < nx; i++)
00090 {
00091 for (j = 0; j < ny; j++)
00092 {
00093 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00094 if isnan(bz[j * nx + i]) continue;
00095 sum += (fabs(bz[j * nx + i]));
00096 err += bz_err[j * nx + i]*bz_err[j * nx + i];
00097 count_mask++;
00098 }
00099 }
00100
00101 *mean_vf_ptr = sum*cdelt1*cdelt1*(rsun_ref/rsun_obs)*(rsun_ref/rsun_obs)*100.0*100.0;
00102 *mean_vf_err_ptr = (sqrt(err))*fabs(cdelt1*cdelt1*(rsun_ref/rsun_obs)*(rsun_ref/rsun_obs)*100.0*100.0);
00103 *count_mask_ptr = count_mask;
00104 return 0;
00105 }
00106
00107
00108
00109
00110
00111 int computeBh(float *bx_err, float *by_err, float *bh_err, float *bx, float *by, float *bz, float *bh, int *dims,
00112 float *mean_hf_ptr, int *mask, int *bitmask)
00113
00114 {
00115
00116 int nx = dims[0];
00117 int ny = dims[1];
00118 int i = 0;
00119 int j = 0;
00120 int count_mask = 0;
00121 double sum = 0.0;
00122 *mean_hf_ptr = 0.0;
00123
00124 if (nx <= 0 || ny <= 0) return 1;
00125
00126 for (i = 0; i < nx; i++)
00127 {
00128 for (j = 0; j < ny; j++)
00129 {
00130 if isnan(bx[j * nx + i])
00131 {
00132 bh[j * nx + i] = NAN;
00133 bh_err[j * nx + i] = NAN;
00134 continue;
00135 }
00136 if isnan(by[j * nx + i])
00137 {
00138 bh[j * nx + i] = NAN;
00139 bh_err[j * nx + i] = NAN;
00140 continue;
00141 }
00142 bh[j * nx + i] = sqrt( bx[j * nx + i]*bx[j * nx + i] + by[j * nx + i]*by[j * nx + i] );
00143 sum += bh[j * nx + i];
00144 bh_err[j * nx + i]=sqrt( bx[j * nx + i]*bx[j * nx + i]*bx_err[j * nx + i]*bx_err[j * nx + i] + by[j * nx + i]*by[j * nx + i]*by_err[j * nx + i]*by_err[j * nx + i])/ bh[j * nx + i];
00145 count_mask++;
00146 }
00147 }
00148
00149 *mean_hf_ptr = sum/(count_mask);
00150
00151 return 0;
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161 int computeGamma(float *bz_err, float *bh_err, float *bx, float *by, float *bz, float *bh, int *dims,
00162 float *mean_gamma_ptr, float *mean_gamma_err_ptr, int *mask, int *bitmask)
00163 {
00164 int nx = dims[0];
00165 int ny = dims[1];
00166 int i = 0;
00167 int j = 0;
00168 int count_mask = 0;
00169 double sum = 0.0;
00170 double err = 0.0;
00171 *mean_gamma_ptr = 0.0;
00172
00173 if (nx <= 0 || ny <= 0) return 1;
00174
00175 for (i = 0; i < nx; i++)
00176 {
00177 for (j = 0; j < ny; j++)
00178 {
00179 if (bh[j * nx + i] > 100)
00180 {
00181 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00182 if isnan(bz[j * nx + i]) continue;
00183 if isnan(bz_err[j * nx + i]) continue;
00184 if isnan(bh_err[j * nx + i]) continue;
00185 if isnan(bh[j * nx + i]) continue;
00186 if (bz[j * nx + i] == 0) continue;
00187 sum += fabs(atan(bh[j * nx + i]/fabs(bz[j * nx + i])))*(180./PI);
00188 err += (1/(1+((bh[j * nx + i]*bh[j * nx + i])/(bz[j * nx + i]*bz[j * nx + i]))))*(1/(1+((bh[j * nx + i]*bh[j * nx + i])/(bz[j * nx + i]*bz[j * nx + i])))) *
00189 ( ((bh_err[j * nx + i]*bh_err[j * nx + i])/(bz[j * nx + i]*bz[j * nx + i])) +
00190 ((bh[j * nx + i]*bh[j * nx + i]*bz_err[j * nx + i]*bz_err[j * nx + i])/(bz[j * nx + i]*bz[j * nx + i]*bz[j * nx + i]*bz[j * nx + i])) );
00191 count_mask++;
00192 }
00193 }
00194 }
00195
00196 *mean_gamma_ptr = sum/count_mask;
00197 *mean_gamma_err_ptr = (sqrt(err)/(count_mask))*(180./PI);
00198
00199
00200 return 0;
00201 }
00202
00203
00204
00205
00206
00207 int computeB_total(float *bx_err, float *by_err, float *bz_err, float *bt_err, float *bx, float *by, float *bz, float *bt, int *dims, int *mask, int *bitmask)
00208 {
00209
00210 int nx = dims[0];
00211 int ny = dims[1];
00212 int i = 0;
00213 int j = 0;
00214 int count_mask = 0;
00215
00216 if (nx <= 0 || ny <= 0) return 1;
00217
00218 for (i = 0; i < nx; i++)
00219 {
00220 for (j = 0; j < ny; j++)
00221 {
00222 if isnan(bx[j * nx + i])
00223 {
00224 bt[j * nx + i] = NAN;
00225 bt_err[j * nx + i] = NAN;
00226 continue;
00227 }
00228 if isnan(by[j * nx + i])
00229 {
00230 bt[j * nx + i] = NAN;
00231 bt_err[j * nx + i] = NAN;
00232 continue;
00233 }
00234 if isnan(bz[j * nx + i])
00235 {
00236 bt[j * nx + i] = NAN;
00237 bt_err[j * nx + i] = NAN;
00238 continue;
00239 }
00240 bt[j * nx + i] = sqrt( bx[j * nx + i]*bx[j * nx + i] + by[j * nx + i]*by[j * nx + i] + bz[j * nx + i]*bz[j * nx + i]);
00241 bt_err[j * nx + i]=sqrt(bx[j * nx + i]*bx[j * nx + i]*bx_err[j * nx + i]*bx_err[j * nx + i] + by[j * nx + i]*by[j * nx + i]*by_err[j * nx + i]*by_err[j * nx + i] + bz[j * nx + i]*bz[j * nx + i]*bz_err[j * nx + i]*bz_err[j * nx + i] ) / bt[j * nx + i];
00242 }
00243 }
00244 return 0;
00245 }
00246
00247
00248
00249
00250 int computeBtotalderivative(float *bt, int *dims, float *mean_derivative_btotal_ptr, int *mask, int *bitmask, float *derx_bt, float *dery_bt, float *bt_err, float *mean_derivative_btotal_err_ptr, float *err_termAt, float *err_termBt)
00251 {
00252
00253 int nx = dims[0];
00254 int ny = dims[1];
00255 int i = 0;
00256 int j = 0;
00257 int count_mask = 0;
00258 double sum = 0.0;
00259 double err = 0.0;
00260 *mean_derivative_btotal_ptr = 0.0;
00261
00262 if (nx <= 0 || ny <= 0) return 1;
00263
00264
00265 for (i = 1; i <= nx-2; i++)
00266 {
00267 for (j = 0; j <= ny-1; j++)
00268 {
00269 derx_bt[j * nx + i] = (bt[j * nx + i+1] - bt[j * nx + i-1])*0.5;
00270 err_termAt[j * nx + i] = (((bt[j * nx + (i+1)]-bt[j * nx + (i-1)])*(bt[j * nx + (i+1)]-bt[j * nx + (i-1)])) * (bt_err[j * nx + (i+1)]*bt_err[j * nx + (i+1)] + bt_err[j * nx + (i-1)]*bt_err[j * nx + (i-1)])) ;
00271 }
00272 }
00273
00274
00275 for (i = 0; i <= nx-1; i++)
00276 {
00277 for (j = 1; j <= ny-2; j++)
00278 {
00279 dery_bt[j * nx + i] = (bt[(j+1) * nx + i] - bt[(j-1) * nx + i])*0.5;
00280 err_termBt[j * nx + i] = (((bt[(j+1) * nx + i]-bt[(j-1) * nx + i])*(bt[(j+1) * nx + i]-bt[(j-1) * nx + i])) * (bt_err[(j+1) * nx + i]*bt_err[(j+1) * nx + i] + bt_err[(j-1) * nx + i]*bt_err[(j-1) * nx + i])) ;
00281 }
00282 }
00283
00284
00285
00286
00287 i=0;
00288 for (j = 0; j <= ny-1; j++)
00289 {
00290 derx_bt[j * nx + i] = ( (-3*bt[j * nx + i]) + (4*bt[j * nx + (i+1)]) - (bt[j * nx + (i+2)]) )*0.5;
00291 }
00292
00293 i=nx-1;
00294 for (j = 0; j <= ny-1; j++)
00295 {
00296 derx_bt[j * nx + i] = ( (3*bt[j * nx + i]) + (-4*bt[j * nx + (i-1)]) - (-bt[j * nx + (i-2)]) )*0.5;
00297 }
00298
00299 j=0;
00300 for (i = 0; i <= nx-1; i++)
00301 {
00302 dery_bt[j * nx + i] = ( (-3*bt[j*nx + i]) + (4*bt[(j+1) * nx + i]) - (bt[(j+2) * nx + i]) )*0.5;
00303 }
00304
00305 j=ny-1;
00306 for (i = 0; i <= nx-1; i++)
00307 {
00308 dery_bt[j * nx + i] = ( (3*bt[j * nx + i]) + (-4*bt[(j-1) * nx + i]) - (-bt[(j-2) * nx + i]) )*0.5;
00309 }
00310
00311
00312 for (i = 1; i <= nx-2; i++)
00313 {
00314 for (j = 1; j <= ny-2; j++)
00315 {
00316 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00317 if ( (derx_bt[j * nx + i] + dery_bt[j * nx + i]) == 0) continue;
00318 if isnan(bt[j * nx + i]) continue;
00319 if isnan(bt[(j+1) * nx + i]) continue;
00320 if isnan(bt[(j-1) * nx + i]) continue;
00321 if isnan(bt[j * nx + i-1]) continue;
00322 if isnan(bt[j * nx + i+1]) continue;
00323 if isnan(bt_err[j * nx + i]) continue;
00324 if isnan(derx_bt[j * nx + i]) continue;
00325 if isnan(dery_bt[j * nx + i]) continue;
00326 sum += sqrt( derx_bt[j * nx + i]*derx_bt[j * nx + i] + dery_bt[j * nx + i]*dery_bt[j * nx + i] );
00327 err += err_termBt[j * nx + i] / (16.0*( derx_bt[j * nx + i]*derx_bt[j * nx + i] + dery_bt[j * nx + i]*dery_bt[j * nx + i] ))+
00328 err_termAt[j * nx + i] / (16.0*( derx_bt[j * nx + i]*derx_bt[j * nx + i] + dery_bt[j * nx + i]*dery_bt[j * nx + i] )) ;
00329 count_mask++;
00330 }
00331 }
00332
00333 *mean_derivative_btotal_ptr = (sum)/(count_mask);
00334 *mean_derivative_btotal_err_ptr = (sqrt(err))/(count_mask);
00335
00336
00337
00338 return 0;
00339 }
00340
00341
00342
00343
00344
00345 int computeBhderivative(float *bh, float *bh_err, int *dims, float *mean_derivative_bh_ptr, float *mean_derivative_bh_err_ptr, int *mask, int *bitmask, float *derx_bh, float *dery_bh, float *err_termAh, float *err_termBh)
00346 {
00347
00348 int nx = dims[0];
00349 int ny = dims[1];
00350 int i = 0;
00351 int j = 0;
00352 int count_mask = 0;
00353 double sum= 0.0;
00354 double err =0.0;
00355 *mean_derivative_bh_ptr = 0.0;
00356
00357 if (nx <= 0 || ny <= 0) return 1;
00358
00359
00360 for (i = 1; i <= nx-2; i++)
00361 {
00362 for (j = 0; j <= ny-1; j++)
00363 {
00364 derx_bh[j * nx + i] = (bh[j * nx + i+1] - bh[j * nx + i-1])*0.5;
00365 err_termAh[j * nx + i] = (((bh[j * nx + (i+1)]-bh[j * nx + (i-1)])*(bh[j * nx + (i+1)]-bh[j * nx + (i-1)])) * (bh_err[j * nx + (i+1)]*bh_err[j * nx + (i+1)] + bh_err[j * nx + (i-1)]*bh_err[j * nx + (i-1)]));
00366 }
00367 }
00368
00369
00370 for (i = 0; i <= nx-1; i++)
00371 {
00372 for (j = 1; j <= ny-2; j++)
00373 {
00374 dery_bh[j * nx + i] = (bh[(j+1) * nx + i] - bh[(j-1) * nx + i])*0.5;
00375 err_termBh[j * nx + i] = (((bh[ (j+1) * nx + i]-bh[(j-1) * nx + i])*(bh[(j+1) * nx + i]-bh[(j-1) * nx + i])) * (bh_err[(j+1) * nx + i]*bh_err[(j+1) * nx + i] + bh_err[(j-1) * nx + i]*bh_err[(j-1) * nx + i]));
00376 }
00377 }
00378
00379
00380
00381
00382 i=0;
00383 for (j = 0; j <= ny-1; j++)
00384 {
00385 derx_bh[j * nx + i] = ( (-3*bh[j * nx + i]) + (4*bh[j * nx + (i+1)]) - (bh[j * nx + (i+2)]) )*0.5;
00386 }
00387
00388 i=nx-1;
00389 for (j = 0; j <= ny-1; j++)
00390 {
00391 derx_bh[j * nx + i] = ( (3*bh[j * nx + i]) + (-4*bh[j * nx + (i-1)]) - (-bh[j * nx + (i-2)]) )*0.5;
00392 }
00393
00394 j=0;
00395 for (i = 0; i <= nx-1; i++)
00396 {
00397 dery_bh[j * nx + i] = ( (-3*bh[j*nx + i]) + (4*bh[(j+1) * nx + i]) - (bh[(j+2) * nx + i]) )*0.5;
00398 }
00399
00400 j=ny-1;
00401 for (i = 0; i <= nx-1; i++)
00402 {
00403 dery_bh[j * nx + i] = ( (3*bh[j * nx + i]) + (-4*bh[(j-1) * nx + i]) - (-bh[(j-2) * nx + i]) )*0.5;
00404 }
00405
00406
00407 for (i = 0; i <= nx-1; i++)
00408 {
00409 for (j = 0; j <= ny-1; j++)
00410 {
00411 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00412 if ( (derx_bh[j * nx + i] + dery_bh[j * nx + i]) == 0) continue;
00413 if isnan(bh[j * nx + i]) continue;
00414 if isnan(bh[(j+1) * nx + i]) continue;
00415 if isnan(bh[(j-1) * nx + i]) continue;
00416 if isnan(bh[j * nx + i-1]) continue;
00417 if isnan(bh[j * nx + i+1]) continue;
00418 if isnan(bh_err[j * nx + i]) continue;
00419 if isnan(derx_bh[j * nx + i]) continue;
00420 if isnan(dery_bh[j * nx + i]) continue;
00421 sum += sqrt( derx_bh[j * nx + i]*derx_bh[j * nx + i] + dery_bh[j * nx + i]*dery_bh[j * nx + i] );
00422 err += err_termBh[j * nx + i] / (16.0*( derx_bh[j * nx + i]*derx_bh[j * nx + i] + dery_bh[j * nx + i]*dery_bh[j * nx + i] ))+
00423 err_termAh[j * nx + i] / (16.0*( derx_bh[j * nx + i]*derx_bh[j * nx + i] + dery_bh[j * nx + i]*dery_bh[j * nx + i] )) ;
00424 count_mask++;
00425 }
00426 }
00427
00428 *mean_derivative_bh_ptr = (sum)/(count_mask);
00429 *mean_derivative_bh_err_ptr = (sqrt(err))/(count_mask);
00430
00431
00432
00433 return 0;
00434 }
00435
00436
00437
00438
00439 int computeBzderivative(float *bz, float *bz_err, int *dims, float *mean_derivative_bz_ptr, float *mean_derivative_bz_err_ptr, int *mask, int *bitmask, float *derx_bz, float *dery_bz, float *err_termA, float *err_termB)
00440 {
00441
00442 int nx = dims[0];
00443 int ny = dims[1];
00444 int i = 0;
00445 int j = 0;
00446 int count_mask = 0;
00447 double sum = 0.0;
00448 double err = 0.0;
00449 *mean_derivative_bz_ptr = 0.0;
00450
00451 if (nx <= 0 || ny <= 0) return 1;
00452
00453
00454 for (i = 1; i <= nx-2; i++)
00455 {
00456 for (j = 0; j <= ny-1; j++)
00457 {
00458 derx_bz[j * nx + i] = (bz[j * nx + i+1] - bz[j * nx + i-1])*0.5;
00459 err_termA[j * nx + i] = (((bz[j * nx + (i+1)]-bz[j * nx + (i-1)])*(bz[j * nx + (i+1)]-bz[j * nx + (i-1)])) * (bz_err[j * nx + (i+1)]*bz_err[j * nx + (i+1)] + bz_err[j * nx + (i-1)]*bz_err[j * nx + (i-1)]));
00460 }
00461 }
00462
00463
00464 for (i = 0; i <= nx-1; i++)
00465 {
00466 for (j = 1; j <= ny-2; j++)
00467 {
00468 dery_bz[j * nx + i] = (bz[(j+1) * nx + i] - bz[(j-1) * nx + i])*0.5;
00469 err_termB[j * nx + i] = (((bz[(j+1) * nx + i]-bz[(j-1) * nx + i])*(bz[(j+1) * nx + i]-bz[(j-1) * nx + i])) * (bz_err[(j+1) * nx + i]*bz_err[(j+1) * nx + i] + bz_err[(j-1) * nx + i]*bz_err[(j-1) * nx + i]));
00470 }
00471 }
00472
00473
00474
00475
00476 i=0;
00477 for (j = 0; j <= ny-1; j++)
00478 {
00479 derx_bz[j * nx + i] = ( (-3*bz[j * nx + i]) + (4*bz[j * nx + (i+1)]) - (bz[j * nx + (i+2)]) )*0.5;
00480 }
00481
00482 i=nx-1;
00483 for (j = 0; j <= ny-1; j++)
00484 {
00485 derx_bz[j * nx + i] = ( (3*bz[j * nx + i]) + (-4*bz[j * nx + (i-1)]) - (-bz[j * nx + (i-2)]) )*0.5;
00486 }
00487
00488 j=0;
00489 for (i = 0; i <= nx-1; i++)
00490 {
00491 dery_bz[j * nx + i] = ( (-3*bz[j*nx + i]) + (4*bz[(j+1) * nx + i]) - (bz[(j+2) * nx + i]) )*0.5;
00492 }
00493
00494 j=ny-1;
00495 for (i = 0; i <= nx-1; i++)
00496 {
00497 dery_bz[j * nx + i] = ( (3*bz[j * nx + i]) + (-4*bz[(j-1) * nx + i]) - (-bz[(j-2) * nx + i]) )*0.5;
00498 }
00499
00500
00501 for (i = 0; i <= nx-1; i++)
00502 {
00503 for (j = 0; j <= ny-1; j++)
00504 {
00505 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00506 if ( (derx_bz[j * nx + i] + dery_bz[j * nx + i]) == 0) continue;
00507 if isnan(bz[j * nx + i]) continue;
00508 if isnan(bz[(j+1) * nx + i]) continue;
00509 if isnan(bz[(j-1) * nx + i]) continue;
00510 if isnan(bz[j * nx + i-1]) continue;
00511 if isnan(bz[j * nx + i+1]) continue;
00512 if isnan(bz_err[j * nx + i]) continue;
00513 if isnan(derx_bz[j * nx + i]) continue;
00514 if isnan(dery_bz[j * nx + i]) continue;
00515 sum += sqrt( derx_bz[j * nx + i]*derx_bz[j * nx + i] + dery_bz[j * nx + i]*dery_bz[j * nx + i] );
00516 err += err_termB[j * nx + i] / (16.0*( derx_bz[j * nx + i]*derx_bz[j * nx + i] + dery_bz[j * nx + i]*dery_bz[j * nx + i] )) +
00517 err_termA[j * nx + i] / (16.0*( derx_bz[j * nx + i]*derx_bz[j * nx + i] + dery_bz[j * nx + i]*dery_bz[j * nx + i] )) ;
00518 count_mask++;
00519 }
00520 }
00521
00522 *mean_derivative_bz_ptr = (sum)/(count_mask);
00523 *mean_derivative_bz_err_ptr = (sqrt(err))/(count_mask);
00524
00525
00526
00527 return 0;
00528 }
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567 int computeJz(float *bx_err, float *by_err, float *bx, float *by, int *dims, float *jz, float *jz_err, float *jz_err_squared,
00568 int *mask, int *bitmask, float cdelt1, double rsun_ref, double rsun_obs,float *derx, float *dery, float *err_term1, float *err_term2)
00569
00570
00571 {
00572 int nx = dims[0];
00573 int ny = dims[1];
00574 int i = 0;
00575 int j = 0;
00576 int count_mask = 0;
00577
00578 if (nx <= 0 || ny <= 0) return 1;
00579
00580
00581
00582
00583 for (i = 1; i <= nx-2; i++)
00584 {
00585 for (j = 0; j <= ny-1; j++)
00586 {
00587 derx[j * nx + i] = (by[j * nx + i+1] - by[j * nx + i-1])*0.5;
00588 err_term1[j * nx + i] = (by_err[j * nx + i+1])*(by_err[j * nx + i+1]) + (by_err[j * nx + i-1])*(by_err[j * nx + i-1]);
00589 }
00590 }
00591
00592 for (i = 0; i <= nx-1; i++)
00593 {
00594 for (j = 1; j <= ny-2; j++)
00595 {
00596 dery[j * nx + i] = (bx[(j+1) * nx + i] - bx[(j-1) * nx + i])*0.5;
00597 err_term2[j * nx + i] = (bx_err[(j+1) * nx + i])*(bx_err[(j+1) * nx + i]) + (bx_err[(j-1) * nx + i])*(bx_err[(j-1) * nx + i]);
00598 }
00599 }
00600
00601
00602
00603
00604
00605 i=0;
00606 for (j = 0; j <= ny-1; j++)
00607 {
00608 derx[j * nx + i] = ( (-3*by[j * nx + i]) + (4*by[j * nx + (i+1)]) - (by[j * nx + (i+2)]) )*0.5;
00609 }
00610
00611 i=nx-1;
00612 for (j = 0; j <= ny-1; j++)
00613 {
00614 derx[j * nx + i] = ( (3*by[j * nx + i]) + (-4*by[j * nx + (i-1)]) - (-by[j * nx + (i-2)]) )*0.5;
00615 }
00616
00617 j=0;
00618 for (i = 0; i <= nx-1; i++)
00619 {
00620 dery[j * nx + i] = ( (-3*bx[j*nx + i]) + (4*bx[(j+1) * nx + i]) - (bx[(j+2) * nx + i]) )*0.5;
00621 }
00622
00623 j=ny-1;
00624 for (i = 0; i <= nx-1; i++)
00625 {
00626 dery[j * nx + i] = ( (3*bx[j * nx + i]) + (-4*bx[(j-1) * nx + i]) - (-bx[(j-2) * nx + i]) )*0.5;
00627 }
00628
00629
00630 for (i = 0; i <= nx-1; i++)
00631 {
00632 for (j = 0; j <= ny-1; j++)
00633 {
00634
00635 jz[j * nx + i] = (derx[j * nx + i]-dery[j * nx + i]);
00636 jz_err[j * nx + i] = 0.5*sqrt( err_term1[j * nx + i] + err_term2[j * nx + i] ) ;
00637 jz_err_squared[j * nx + i]= (jz_err[j * nx + i]*jz_err[j * nx + i]);
00638 count_mask++;
00639 }
00640 }
00641 return 0;
00642 }
00643
00644
00645
00646
00647
00648
00649 int computeJzsmooth(float *bx, float *by, int *dims, float *jz, float *jz_smooth, float *jz_err, float *jz_rms_err, float *jz_err_squared_smooth,
00650 float *mean_jz_ptr, float *mean_jz_err_ptr, float *us_i_ptr, float *us_i_err_ptr, int *mask, int *bitmask,
00651 float cdelt1, double rsun_ref, double rsun_obs,float *derx, float *dery)
00652
00653 {
00654
00655 int nx = dims[0];
00656 int ny = dims[1];
00657 int i = 0;
00658 int j = 0;
00659 int count_mask = 0;
00660 double curl = 0.0;
00661 double us_i = 0.0;
00662 double err = 0.0;
00663
00664 if (nx <= 0 || ny <= 0) return 1;
00665
00666
00667 for (i = 0; i <= nx-1; i++)
00668 {
00669 for (j = 0; j <= ny-1; j++)
00670 {
00671 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00672 if isnan(derx[j * nx + i]) continue;
00673 if isnan(dery[j * nx + i]) continue;
00674 if isnan(jz[j * nx + i]) continue;
00675 curl += (jz[j * nx + i])*(1/cdelt1)*(rsun_obs/rsun_ref)*(0.00010)*(1/MUNAUGHT)*(1000.);
00676 us_i += fabs(jz[j * nx + i])*(cdelt1/1)*(rsun_ref/rsun_obs)*(0.00010)*(1/MUNAUGHT);
00677 err += (jz_err[j * nx + i]*jz_err[j * nx + i]);
00678 count_mask++;
00679 }
00680 }
00681
00682
00683 *mean_jz_ptr = curl/(count_mask);
00684 *mean_jz_err_ptr = (sqrt(err)/count_mask)*((1/cdelt1)*(rsun_obs/rsun_ref)*(0.00010)*(1/MUNAUGHT)*(1000.));
00685
00686 *us_i_ptr = (us_i);
00687 *us_i_err_ptr = (sqrt(err))*((cdelt1/1)*(rsun_ref/rsun_obs)*(0.00010)*(1/MUNAUGHT));
00688
00689
00690
00691
00692
00693
00694
00695 return 0;
00696
00697 }
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717 int computeAlpha(float *jz_err, float *bz_err, float *bz, int *dims, float *jz, float *jz_smooth, float *mean_alpha_ptr, float *mean_alpha_err_ptr, int *mask, int *bitmask, float cdelt1, double rsun_ref, double rsun_obs)
00718
00719 {
00720 int nx = dims[0];
00721 int ny = dims[1];
00722 int i = 0;
00723 int j = 0;
00724 double alpha_total = 0.0;
00725 double C = ((1/cdelt1)*(rsun_obs/rsun_ref)*(1000000.));
00726 double total = 0.0;
00727 double A = 0.0;
00728 double B = 0.0;
00729
00730 if (nx <= 0 || ny <= 0) return 1;
00731 for (i = 1; i < nx-1; i++)
00732 {
00733 for (j = 1; j < ny-1; j++)
00734 {
00735 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00736 if isnan(jz[j * nx + i]) continue;
00737 if isnan(bz[j * nx + i]) continue;
00738 if (jz[j * nx + i] == 0.0) continue;
00739 if (bz[j * nx + i] == 0.0) continue;
00740 A += jz[j*nx+i]*bz[j*nx+i];
00741 B += bz[j*nx+i]*bz[j*nx+i];
00742 }
00743 }
00744
00745 for (i = 1; i < nx-1; i++)
00746 {
00747 for (j = 1; j < ny-1; j++)
00748 {
00749 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00750 if isnan(jz[j * nx + i]) continue;
00751 if isnan(bz[j * nx + i]) continue;
00752 if (jz[j * nx + i] == 0.0) continue;
00753 if (bz[j * nx + i] == 0.0) continue;
00754 total += bz[j*nx+i]*bz[j*nx+i]*jz_err[j*nx+i]*jz_err[j*nx+i] + (jz[j*nx+i]-2*bz[j*nx+i]*A/B)*(jz[j*nx+i]-2*bz[j*nx+i]*A/B)*bz_err[j*nx+i]*bz_err[j*nx+i];
00755 }
00756 }
00757
00758
00759 alpha_total = ((A/B)*C);
00760 *mean_alpha_ptr = alpha_total;
00761 *mean_alpha_err_ptr = (C/B)*(sqrt(total));
00762
00763 return 0;
00764 }
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775 int computeHelicity(float *jz_err, float *jz_rms_err, float *bz_err, float *bz, int *dims, float *jz, float *mean_ih_ptr,
00776 float *mean_ih_err_ptr, float *total_us_ih_ptr, float *total_abs_ih_ptr,
00777 float *total_us_ih_err_ptr, float *total_abs_ih_err_ptr, int *mask, int *bitmask, float cdelt1, double rsun_ref, double rsun_obs)
00778
00779 {
00780
00781 int nx = dims[0];
00782 int ny = dims[1];
00783 int i = 0;
00784 int j = 0;
00785 int count_mask = 0;
00786 double sum = 0.0;
00787 double sum2 = 0.0;
00788 double err = 0.0;
00789
00790 if (nx <= 0 || ny <= 0) return 1;
00791
00792 for (i = 0; i < nx; i++)
00793 {
00794 for (j = 0; j < ny; j++)
00795 {
00796 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00797 if isnan(jz[j * nx + i]) continue;
00798 if isnan(bz[j * nx + i]) continue;
00799 if isnan(jz_err[j * nx + i]) continue;
00800 if isnan(bz_err[j * nx + i]) continue;
00801 if (bz[j * nx + i] == 0.0) continue;
00802 if (jz[j * nx + i] == 0.0) continue;
00803 sum += (jz[j * nx + i]*bz[j * nx + i])*(1/cdelt1)*(rsun_obs/rsun_ref);
00804 sum2 += fabs(jz[j * nx + i]*bz[j * nx + i])*(1/cdelt1)*(rsun_obs/rsun_ref);
00805 err += (jz_err[j * nx + i]*jz_err[j * nx + i]*bz[j * nx + i]*bz[j * nx + i]) + (bz_err[j * nx + i]*bz_err[j * nx + i]*jz[j * nx + i]*jz[j * nx + i]);
00806 count_mask++;
00807 }
00808 }
00809
00810 *mean_ih_ptr = sum/count_mask ;
00811 *total_us_ih_ptr = sum2 ;
00812 *total_abs_ih_ptr = fabs(sum) ;
00813
00814 *mean_ih_err_ptr = (sqrt(err)/count_mask)*(1/cdelt1)*(rsun_obs/rsun_ref) ;
00815 *total_us_ih_err_ptr = (sqrt(err))*(1/cdelt1)*(rsun_obs/rsun_ref) ;
00816 *total_abs_ih_err_ptr = (sqrt(err))*(1/cdelt1)*(rsun_obs/rsun_ref) ;
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827 return 0;
00828 }
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841 int computeSumAbsPerPolarity(float *jz_err, float *bz_err, float *bz, float *jz, int *dims, float *totaljzptr, float *totaljz_err_ptr,
00842 int *mask, int *bitmask, float cdelt1, double rsun_ref, double rsun_obs)
00843
00844 {
00845 int nx = dims[0];
00846 int ny = dims[1];
00847 int i=0;
00848 int j=0;
00849 int count_mask=0;
00850 double sum1=0.0;
00851 double sum2=0.0;
00852 double err=0.0;
00853 *totaljzptr=0.0;
00854
00855 if (nx <= 0 || ny <= 0) return 1;
00856
00857 for (i = 0; i < nx; i++)
00858 {
00859 for (j = 0; j < ny; j++)
00860 {
00861 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00862 if isnan(bz[j * nx + i]) continue;
00863 if isnan(jz[j * nx + i]) continue;
00864 if (bz[j * nx + i] > 0) sum1 += ( jz[j * nx + i])*(1/cdelt1)*(0.00010)*(1/MUNAUGHT)*(rsun_ref/rsun_obs);
00865 if (bz[j * nx + i] <= 0) sum2 += ( jz[j * nx + i])*(1/cdelt1)*(0.00010)*(1/MUNAUGHT)*(rsun_ref/rsun_obs);
00866 err += (jz_err[j * nx + i]*jz_err[j * nx + i]);
00867 count_mask++;
00868 }
00869 }
00870
00871 *totaljzptr = fabs(sum1) + fabs(sum2);
00872 *totaljz_err_ptr = sqrt(err)*(1/cdelt1)*fabs((0.00010)*(1/MUNAUGHT)*(rsun_ref/rsun_obs));
00873
00874
00875
00876 return 0;
00877 }
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892 int computeFreeEnergy(float *bx_err, float *by_err, float *bx, float *by, float *bpx, float *bpy, int *dims,
00893 float *meanpotptr, float *meanpot_err_ptr, float *totpotptr, float *totpot_err_ptr, int *mask, int *bitmask,
00894 float cdelt1, double rsun_ref, double rsun_obs)
00895
00896 {
00897 int nx = dims[0];
00898 int ny = dims[1];
00899 int i = 0;
00900 int j = 0;
00901 int count_mask = 0;
00902 double sum = 0.0;
00903 double sum1 = 0.0;
00904 double err = 0.0;
00905 *totpotptr = 0.0;
00906 *meanpotptr = 0.0;
00907
00908 if (nx <= 0 || ny <= 0) return 1;
00909
00910 for (i = 0; i < nx; i++)
00911 {
00912 for (j = 0; j < ny; j++)
00913 {
00914 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00915 if isnan(bx[j * nx + i]) continue;
00916 if isnan(by[j * nx + i]) continue;
00917 sum += ( ((bx[j * nx + i] - bpx[j * nx + i])*(bx[j * nx + i] - bpx[j * nx + i])) + ((by[j * nx + i] - bpy[j * nx + i])*(by[j * nx + i] - bpy[j * nx + i])) )*(cdelt1*cdelt1*(rsun_ref/rsun_obs)*(rsun_ref/rsun_obs)*100.0*100.0);
00918 sum1 += ( ((bx[j * nx + i] - bpx[j * nx + i])*(bx[j * nx + i] - bpx[j * nx + i])) + ((by[j * nx + i] - bpy[j * nx + i])*(by[j * nx + i] - bpy[j * nx + i])) );
00919 err += 4.0*(bx[j * nx + i] - bpx[j * nx + i])*(bx[j * nx + i] - bpx[j * nx + i])*(bx_err[j * nx + i]*bx_err[j * nx + i]) +
00920 4.0*(by[j * nx + i] - bpy[j * nx + i])*(by[j * nx + i] - bpy[j * nx + i])*(by_err[j * nx + i]*by_err[j * nx + i]);
00921 count_mask++;
00922 }
00923 }
00924
00925
00926 *meanpotptr = (sum1) / (count_mask*8.*PI) ;
00927 *meanpot_err_ptr = (sqrt(err)) / (count_mask*8.*PI);
00928
00929
00930 *totpotptr = (sum)/(8.*PI);
00931 *totpot_err_ptr = (sqrt(err))*fabs(cdelt1*cdelt1*(rsun_ref/rsun_obs)*(rsun_ref/rsun_obs)*100.0*100.0*(1/(8.*PI)));
00932
00933
00934
00935
00936
00937
00938
00939 return 0;
00940 }
00941
00942
00943
00944
00945 int computeShearAngle(float *bx_err, float *by_err, float *bz_err, float *bx, float *by, float *bz, float *bpx, float *bpy, float *bpz, int *dims,
00946 float *meanshear_angleptr, float *meanshear_angle_err_ptr, float *area_w_shear_gt_45ptr, int *mask, int *bitmask)
00947
00948
00949 {
00950 int nx = dims[0];
00951 int ny = dims[1];
00952 int i = 0;
00953 int j = 0;
00954 float count_mask = 0;
00955 float count = 0;
00956 double dotproduct = 0.0;
00957 double magnitude_potential = 0.0;
00958 double magnitude_vector = 0.0;
00959 double shear_angle = 0.0;
00960 double denominator = 0.0;
00961 double term1 = 0.0;
00962 double term2 = 0.0;
00963 double term3 = 0.0;
00964 double sumsum = 0.0;
00965 double err = 0.0;
00966 double part1 = 0.0;
00967 double part2 = 0.0;
00968 double part3 = 0.0;
00969 *area_w_shear_gt_45ptr = 0.0;
00970 *meanshear_angleptr = 0.0;
00971
00972 if (nx <= 0 || ny <= 0) return 1;
00973
00974 for (i = 0; i < nx; i++)
00975 {
00976 for (j = 0; j < ny; j++)
00977 {
00978 if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue;
00979 if isnan(bpx[j * nx + i]) continue;
00980 if isnan(bpy[j * nx + i]) continue;
00981 if isnan(bpz[j * nx + i]) continue;
00982 if isnan(bz[j * nx + i]) continue;
00983 if isnan(bx[j * nx + i]) continue;
00984 if isnan(by[j * nx + i]) continue;
00985 if isnan(bx_err[j * nx + i]) continue;
00986 if isnan(by_err[j * nx + i]) continue;
00987 if isnan(bz_err[j * nx + i]) continue;
00988
00989
00990 dotproduct = (bpx[j * nx + i])*(bx[j * nx + i]) + (bpy[j * nx + i])*(by[j * nx + i]) + (bpz[j * nx + i])*(bz[j * nx + i]);
00991 magnitude_potential = sqrt( (bpx[j * nx + i]*bpx[j * nx + i]) + (bpy[j * nx + i]*bpy[j * nx + i]) + (bpz[j * nx + i]*bpz[j * nx + i]));
00992 magnitude_vector = sqrt( (bx[j * nx + i]*bx[j * nx + i]) + (by[j * nx + i]*by[j * nx + i]) + (bz[j * nx + i]*bz[j * nx + i]) );
00993
00994
00995
00996
00997 shear_angle = acos(dotproduct/(magnitude_potential*magnitude_vector))*(180./PI);
00998 sumsum += shear_angle;
00999
01000 count ++;
01001
01002 if (shear_angle > 45) count_mask ++;
01003
01004
01005
01006 term1 = bx[j * nx + i]*by[j * nx + i]*bpy[j * nx + i] - by[j * nx + i]*by[j * nx + i]*bpx[j * nx + i] + bz[j * nx + i]*bx[j * nx + i]*bpz[j * nx + i] - bz[j * nx + i]*bz[j * nx + i]*bpx[j * nx + i];
01007 term2 = bx[j * nx + i]*bx[j * nx + i]*bpy[j * nx + i] - bx[j * nx + i]*by[j * nx + i]*bpx[j * nx + i] + bx[j * nx + i]*bz[j * nx + i]*bpy[j * nx + i] - bz[j * nx + i]*by[j * nx + i]*bpz[j * nx + i];
01008 term3 = bx[j * nx + i]*bx[j * nx + i]*bpz[j * nx + i] - bx[j * nx + i]*bz[j * nx + i]*bpx[j * nx + i] + by[j * nx + i]*by[j * nx + i]*bpz[j * nx + i] - by[j * nx + i]*bz[j * nx + i]*bpy[j * nx + i];
01009
01010 part1 = bx[j * nx + i]*bx[j * nx + i] + by[j * nx + i]*by[j * nx + i] + bz[j * nx + i]*bz[j * nx + i];
01011 part2 = bpx[j * nx + i]*bpx[j * nx + i] + bpy[j * nx + i]*bpy[j * nx + i] + bpz[j * nx + i]*bpz[j * nx + i];
01012 part3 = bx[j * nx + i]*bpx[j * nx + i] + by[j * nx + i]*bpy[j * nx + i] + bz[j * nx + i]*bpz[j * nx + i];
01013
01014
01015 denominator = part1*part1*part1*part2*(1.0-((part3*part3)/(part1*part2)));
01016
01017 err = (term1*term1*bx_err[j * nx + i]*bx_err[j * nx + i])/(denominator) +
01018 (term1*term1*bx_err[j * nx + i]*bx_err[j * nx + i])/(denominator) +
01019 (term1*term1*bx_err[j * nx + i]*bx_err[j * nx + i])/(denominator) ;
01020
01021 }
01022 }
01023
01024 *meanshear_angleptr = (sumsum)/(count);
01025 *meanshear_angle_err_ptr = (sqrt(err)/count_mask)*(180./PI);
01026
01027
01028 *area_w_shear_gt_45ptr = (count_mask/(count))*(100.0);
01029
01030
01031
01032
01033
01034 return 0;
01035 }
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048 int computeR(float *bz_err, float *los, int *dims, float *Rparam, float cdelt1,
01049 float *rim, float *p1p0, float *p1n0, float *p1p, float *p1n, float *p1,
01050 float *pmap, int nx1, int ny1,
01051 int scale, float *p1pad, int nxp, int nyp, float *pmapn)
01052
01053 {
01054 int nx = dims[0];
01055 int ny = dims[1];
01056 int i = 0;
01057 int j = 0;
01058 int index, index1;
01059 double sum = 0.0;
01060 double err = 0.0;
01061 *Rparam = 0.0;
01062 struct fresize_struct fresboxcar, fresgauss;
01063 struct fint_struct fints;
01064 float sigma = 10.0/2.3548;
01065
01066
01067 init_fresize_boxcar(&fresboxcar,1,1);
01068 init_fresize_gaussian(&fresgauss,sigma,20,1);
01069
01070
01071
01072 fsample(los, rim, nx, ny, nx, nx1, ny1, nx1, scale, 0, 0, 0.0);
01073
01074
01075
01076
01077 for (i = 0; i < nx1; i++)
01078 {
01079 for (j = 0; j < ny1; j++)
01080 {
01081 index = j * nx1 + i;
01082 if (rim[index] > 150)
01083 p1p0[index]=1.0;
01084 else
01085 p1p0[index]=0.0;
01086 if (rim[index] < -150)
01087 p1n0[index]=1.0;
01088 else
01089 p1n0[index]=0.0;
01090 }
01091 }
01092
01093
01094
01095 fresize(&fresboxcar, p1p0, p1p, nx1, ny1, nx1, nx1, ny1, nx1, 0, 0, 0.0);
01096 fresize(&fresboxcar, p1n0, p1n, nx1, ny1, nx1, nx1, ny1, nx1, 0, 0, 0.0);
01097
01098
01099
01100
01101 for (i = 0; i < nx1; i++)
01102 {
01103 for (j = 0; j < ny1; j++)
01104 {
01105 index = j * nx1 + i;
01106 if ((p1p[index] > 0.0) && (p1n[index] > 0.0))
01107 p1[index]=1.0;
01108 else
01109 p1[index]=0.0;
01110 }
01111 }
01112
01113
01114
01115
01116
01117 for (i = 0; i < nxp; i++)
01118 {
01119 for (j = 0; j < nyp; j++)
01120 {
01121 index = j * nxp + i;
01122 p1pad[index]=0.0;
01123 }
01124 }
01125
01126
01127 for (i = 0; i < nx1; i++)
01128 {
01129 for (j = 0; j < ny1; j++)
01130 {
01131 index = j * nx1 + i;
01132 index1 = (j+20) * nxp + (i+20);
01133 p1pad[index1]=p1[index];
01134 }
01135 }
01136
01137
01138
01139
01140
01141 fresize(&fresgauss, p1pad, pmap, nxp, nyp, nxp, nxp, nyp, nxp, 0, 0, 0.0);
01142
01143
01144
01145 for (i = 0; i < nx1; i++)
01146 {
01147 for (j = 0; j < ny1; j++)
01148 {
01149 index = j * nx1 + i;
01150 index1 = (j+20) * nxp + (i+20);
01151 pmapn[index]=pmap[index1];
01152 }
01153 }
01154
01155
01156
01157 for (i = 0; i < nx1; i++)
01158 {
01159 for (j = 0; j < ny1; j++)
01160 {
01161 index = j * nx1 + i;
01162 if isnan(pmapn[index]) continue;
01163 if isnan(rim[index]) continue;
01164 sum += pmapn[index]*abs(rim[index]);
01165 }
01166 }
01167
01168 if (sum < 1.0)
01169 *Rparam = 0.0;
01170 else
01171 *Rparam = log10(sum);
01172
01173
01174
01175 free_fresize(&fresboxcar);
01176 free_fresize(&fresgauss);
01177
01178 return 0;
01179
01180 }
01181
01182
01183
01184
01185
01186
01187
01188 int computeLorentz(float *bx, float *by, float *bz, float *fx, float *fy, float *fz, int *dims,
01189 float *totfx_ptr, float *totfy_ptr, float *totfz_ptr, float *totbsq_ptr,
01190 float *epsx_ptr, float *epsy_ptr, float *epsz_ptr, int *mask, int *bitmask,
01191 float cdelt1, double rsun_ref, double rsun_obs)
01192
01193 {
01194
01195 int nx = dims[0];
01196 int ny = dims[1];
01197 int nxny = nx*ny;
01198 int j = 0;
01199 int index;
01200 double totfx = 0, totfy = 0, totfz = 0;
01201 double bsq = 0, totbsq = 0;
01202 double epsx = 0, epsy = 0, epsz = 0;
01203 double area = cdelt1*cdelt1*(rsun_ref/rsun_obs)*(rsun_ref/rsun_obs)*100.0*100.0;
01204 double k_h = -1.0 * area / (4. * PI) / 1.0e20;
01205 double k_z = area / (8. * PI) / 1.0e20;
01206
01207 if (nx <= 0 || ny <= 0) return 1;
01208
01209 for (int i = 0; i < nxny; i++)
01210 {
01211 if ( mask[i] < 70 || bitmask[i] < 30 ) continue;
01212 if isnan(bx[i]) continue;
01213 if isnan(by[i]) continue;
01214 if isnan(bz[i]) continue;
01215 fx[i] = bx[i] * bz[i] * k_h;
01216 fy[i] = by[i] * bz[i] * k_h;
01217 fz[i] = (bx[i] * bx[i] + by[i] * by[i] - bz[i] * bz[i]) * k_z;
01218 bsq = bx[i] * bx[i] + by[i] * by[i] + bz[i] * bz[i];
01219 totfx += fx[i]; totfy += fy[i]; totfz += fz[i];
01220 totbsq += bsq;
01221 }
01222
01223 *totfx_ptr = totfx;
01224 *totfy_ptr = totfy;
01225 *totfz_ptr = totfz;
01226 *totbsq_ptr = totbsq;
01227 *epsx_ptr = (totfx / k_h) / totbsq;
01228 *epsy_ptr = (totfy / k_h) / totbsq;
01229 *epsz_ptr = (totfz / k_z) / totbsq;
01230
01231
01232
01233 return 0;
01234
01235 }
01236
01237
01238
01239
01240 #include <math.h>
01241
01242 void greenpot(float *bx, float *by, float *bz, int nnx, int nny)
01243 {
01244
01245 int inx, iny, i, j, n;
01246
01247 float *pfpot, *rdist;
01248 pfpot=(float *)malloc(sizeof(float) *nnx*nny);
01249 rdist=(float *)malloc(sizeof(float) *nnx*nny);
01250 float *bztmp;
01251 bztmp=(float *)malloc(sizeof(float) *nnx*nny);
01252
01253
01254
01255
01256
01257 for (iny=0; iny < nny; iny++){for (inx=0; inx < nnx; inx++){pfpot[nnx*iny+inx] = 0.0;}}
01258
01259 for (iny=0; iny < nny; iny++){for (inx=0; inx < nnx; inx++){rdist[nnx*iny+inx] = 0.0;}}
01260
01261 for (iny=0; iny < nny; iny++){for (inx=0; inx < nnx; inx++){bx[nnx*iny+inx] = 0.0;}}
01262
01263 for (iny=0; iny < nny; iny++){for (inx=0; inx < nnx; inx++){by[nnx*iny+inx] = 0.0;}}
01264
01265 for (iny=0; iny < nny; iny++){for (inx=0; inx < nnx; inx++)
01266 {
01267 float val0 = bz[nnx*iny + inx];
01268 if (isnan(val0)){bztmp[nnx*iny + inx] = 0.0;}else{bztmp[nnx*iny + inx] = val0;}
01269 }}
01270
01271
01272 float dz = 0.001;
01273
01274
01275 for (iny=0; iny < nny; iny++){for (inx=0; inx < nnx; inx++)
01276 {
01277 float rdd, rdd1, rdd2;
01278 float r;
01279 rdd1 = (float)(inx);
01280 rdd2 = (float)(iny);
01281 rdd = rdd1 * rdd1 + rdd2 * rdd2 + dz * dz;
01282 rdist[nnx*iny+inx] = 1.0/sqrt(rdd);
01283 }}
01284
01285 int iwindow;
01286 if (nnx > nny) {iwindow = nnx;} else {iwindow = nny;}
01287 float rwindow;
01288 rwindow = (float)(iwindow);
01289 rwindow = rwindow * rwindow + 0.01;
01290
01291 rwindow = 1.0e2;
01292
01293 rwindow = sqrt(rwindow);
01294 iwindow = (int)(rwindow);
01295
01296
01297 for (iny=0;iny<nny;iny++){for (inx=0;inx<nnx;inx++)
01298 {
01299 float val0 = bz[nnx*iny + inx];
01300 if (isnan(val0))
01301 {
01302 pfpot[nnx*iny + inx] = 0.0;
01303 }
01304 else
01305 {
01306 float sum;
01307 sum = 0.0;
01308 int j2, i2;
01309 int j2s, j2e, i2s, i2e;
01310 j2s = iny - iwindow;
01311 j2e = iny + iwindow;
01312 if (j2s < 0){j2s = 0;}
01313 if (j2e > nny){j2e = nny;}
01314 i2s = inx - iwindow;
01315 i2e = inx + iwindow;
01316 if (i2s < 0){i2s = 0;}
01317 if (i2e > nnx){i2e = nnx;}
01318
01319 for (j2=j2s;j2<j2e;j2++){for (i2=i2s;i2<i2e;i2++)
01320 {
01321 float val1 = bztmp[nnx*j2 + i2];
01322 float rr, r1, r2;
01323
01324
01325
01326
01327
01328 int di, dj;
01329 di = abs(i2 - inx);
01330 dj = abs(j2 - iny);
01331 sum = sum + val1 * rdist[nnx * dj + di] * dz;
01332
01333 } }
01334 pfpot[nnx*iny + inx] = sum;
01335 }
01336 } }
01337
01338
01339 for (iny=1; iny < nny - 1; iny++){for (inx=1; inx < nnx - 1; inx++)
01340 {
01341 bx[nnx*iny + inx] = -(pfpot[nnx*iny + (inx+1)]-pfpot[nnx*iny + (inx-1)]) * 0.5;
01342 by[nnx*iny + inx] = -(pfpot[nnx*(iny+1) + inx]-pfpot[nnx*(iny-1) + inx]) * 0.5;
01343 } }
01344
01345 free(rdist);
01346 free(pfpot);
01347 free(bztmp);
01348 }
01349
01350
01351
01352
01353 char *sw_functions_version()
01354 {
01355 return strdup("$Id");
01356 }
01357
01358