version 1.9, 2013/05/20 23:55:32
|
version 1.13, 2013/05/31 22:47:15
|
Line 222 int computeBtotalderivative(float *bt, i |
|
Line 222 int computeBtotalderivative(float *bt, i |
|
| |
| |
/* brute force method of calculating the derivative (no consideration for edges) */ | /* brute force method of calculating the derivative (no consideration for edges) */ |
for (i = 3; i <= nx-4; i++) |
for (i = 1; i <= nx-2; i++) |
{ | { |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
derx_bt[j * nx + i] = (-bt[j * nx + (i-3)] + 9.0*bt[j * nx + (i-2)] - 45.0*bt[j * nx + (i-1)] + 45*bt[j * nx + (i+1)] - 9.0*bt[j * nx + (i+2)] + bt[j * nx + (i+3)])*(1.0/60.0); |
derx_bt[j * nx + i] = (bt[j * nx + i+1] - bt[j * nx + i-1])*0.5; |
} | } |
} | } |
| |
/* brute force method of calculating the derivative (no consideration for edges) */ | /* brute force method of calculating the derivative (no consideration for edges) */ |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
for (j = 3; j <= ny-4; j++) |
for (j = 1; j <= ny-2; j++) |
{ | { |
dery_bt[j * nx + i] = (-bt[(j-3) * nx + i] + 9.0*bt[(j-2) * nx + i] - 45.0*bt[(j-1) * nx + i] + 45*bt[(j+1) * nx + i] - 9.0*bt[(j+2) * nx + i] + bt[(j+3) * nx + i])*(1.0/60.0); |
dery_bt[j * nx + i] = (bt[(j+1) * nx + i] - bt[(j-1) * nx + i])*0.5; |
} | } |
} | } |
| |
| |
/* consider the edges: 3 pixels on each edge, for a total of 12 edge formulae below */ |
/* consider the edges */ |
i=0; | i=0; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
derx_bt[j * nx + i] = (-147.0*bt[j * nx + i] + 360.0*bt[j * nx + (i+1)] - 450.0*bt[j * nx + (i+2)] + 400.0*bt[j * nx + (i+3)] - 225.0*bt[j * nx + (i+4)] + 72.0*bt[j * nx + (i+5)] - 10.0*bt[j * nx + (i+6)])*(1.0/60.0); |
derx_bt[j * nx + i] = ( (-3*bt[j * nx + i]) + (4*bt[j * nx + (i+1)]) - (bt[j * nx + (i+2)]) )*0.5; |
} | } |
| |
i=nx-1; | i=nx-1; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
derx_bt[j * nx + i] = ( 147.0*bt[j * nx + i] - 360.0*bt[j * nx + (i-1)] + 450.0*bt[j * nx + (i-2)] - 400.0*bt[j * nx + (i-3)] + 225.0*bt[j * nx + (i-4)] - 72.0*bt[j * nx + (i-5)] + 10.0*bt[j * nx + (i-6)])*(1.0/60.0); |
derx_bt[j * nx + i] = ( (3*bt[j * nx + i]) + (-4*bt[j * nx + (i-1)]) - (-bt[j * nx + (i-2)]) )*0.5; |
} | } |
| |
|
|
i=1; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
derx_bt[j * nx + i] = (-10.0*bt[j * nx + i] - 77.0*bt[j * nx + (i+1)] + 150.0*bt[j * nx + (i+2)] - 100.0*bt[j * nx + (i+3)] + 50.0*bt[j * nx + (i+4)] - 15.0*bt[j * nx + (i+5)] + 2.0*bt[j * nx + (i+6)])*(1.0/60.0); |
|
} |
|
|
|
i=nx-2; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
derx_bt[j * nx + i] = ( 10.0*bt[j * nx + i] + 77.0*bt[j * nx + (i-1)] - 150.0*bt[j * nx + (i-2)] + 100.0*bt[j * nx + (i-3)] - 50.0*bt[j * nx + (i-4)] + 15.0*bt[j * nx + (i-5)] - 2.0*bt[j * nx + (i-6)])*(1.0/60.0); |
|
} |
|
|
|
|
|
i=2; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
derx_bt[j * nx + i] = ( 2.0*bt[j * nx + i] - 24.0*bt[j * nx + (i+1)] - 35.0*bt[j * nx + (i+2)] + 80.0*bt[j * nx + (i+3)] - 30.0*bt[j * nx + (i+4)] + 8.0*bt[j * nx + (i+5)] - bt[j * nx + (i+6)])*(1.0/60.0); |
|
} |
|
|
|
i=nx-3; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
derx_bt[j * nx + i] = (-2.0*bt[j * nx + i] + 24.0*bt[j * nx + (i-1)] + 35.0*bt[j * nx + (i-2)] - 80.0*bt[j * nx + (i-3)] + 30.0*bt[j * nx + (i-4)] - 8.0*bt[j * nx + (i-5)] + bt[j * nx + (i-6)])*(1.0/60.0); |
|
} |
|
|
|
|
|
j=0; | j=0; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
dery_bt[j * nx + i] = (-147.0*bt[j * nx + i] + 360.0*bt[(j+1) * nx + i] - 450.0*bt[(j+2) * nx + i] + 400.0*bt[(j+3) * nx + i] - 225.0*bt[(j+4) * nx + i] + 72.0*bt[(j+5) * nx + i] - 10.0*bt[(j+6) * nx + i])*(1.0/60.0); |
dery_bt[j * nx + i] = ( (-3*bt[j*nx + i]) + (4*bt[(j+1) * nx + i]) - (bt[(j+2) * nx + i]) )*0.5; |
} | } |
| |
j=ny-1; | j=ny-1; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
dery_bt[j * nx + i] = ( 147.0*bt[j * nx + i] - 360.0*bt[(j-1) * nx + i] + 450.0*bt[(j-2) * nx + i] - 400.0*bt[(j-3) * nx + i] + 225.0*bt[(j-4) * nx + i] - 72.0*bt[(j-5) * nx + i] + 10.0*bt[(j-6) * nx + i])*(1.0/60.0); |
dery_bt[j * nx + i] = ( (3*bt[j * nx + i]) + (-4*bt[(j-1) * nx + i]) - (-bt[(j-2) * nx + i]) )*0.5; |
} |
|
|
|
j=1; |
|
for (i = 0; i <= nx-2; i++) |
|
{ |
|
dery_bt[j * nx + i] = (-10.0*bt[j * nx + i] - 77.0*bt[(j+1) * nx + i] + 150.0*bt[(j+2) * nx + i] - 100.0*bt[(j+3) * nx + i] + 50.0*bt[(j+4) * nx + i] - 15.0*bt[(j+5) * nx + i] + 2.0*bt[(j+6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=ny-2; |
|
for (i = 0; i <= nx-2; i++) |
|
{ |
|
dery_bt[j * nx + i] = ( 10.0*bt[j * nx + i] + 77.0*bt[(j-1) * nx + i] - 150.0*bt[(j-2) * nx + i] + 100.0*bt[(j-3) * nx + i] - 50.0*bt[(j-4) * nx + i] + 15.0*bt[(j-5) * nx + i] - 2.0*bt[(j-6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=2; |
|
for (i = 0; i <= nx-3; i++) |
|
{ |
|
dery_bt[j * nx + i] = ( 2.0*bt[j * nx + i] - 24.0*bt[(j+1) * nx + i] - 35.0*bt[(j+2) * nx + i] + 80.0*bt[(j+3) * nx + i] - 30.0*bt[(j+4) * nx + i] + 8.0*bt[(j+5) * nx + i] - bt[(j+6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=ny-3; |
|
for (i = 0; i <= nx-3; i++) |
|
{ |
|
dery_bt[j * nx + i] = (-2.0*bt[j * nx + i] + 24.0*bt[(j-1) * nx + i] + 35.0*bt[(j-2) * nx + i] - 80.0*bt[(j-3) * nx + i] + 30.0*bt[(j-4) * nx + i] - 8.0*bt[(j-5) * nx + i] + bt[(j-6) * nx + i])*(1.0/60.0); |
|
} | } |
| |
| |
Line 353 int computeBhderivative(float *bh, float |
|
Line 302 int computeBhderivative(float *bh, float |
|
float sum,err = 0.0; | float sum,err = 0.0; |
| |
/* brute force method of calculating the derivative (no consideration for edges) */ | /* brute force method of calculating the derivative (no consideration for edges) */ |
for (i = 3; i <= nx-4; i++) |
for (i = 1; i <= nx-2; i++) |
{ | { |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
derx_bh[j * nx + i] = (-bh[j * nx + (i-3)] + 9.0*bh[j * nx + (i-2)] - 45.0*bh[j * nx + (i-1)] + 45*bh[j * nx + (i+1)] - 9.0*bh[j * nx + (i+2)] + bh[j * nx + (i+3)])*(1.0/60.0); |
derx_bh[j * nx + i] = (bh[j * nx + i+1] - bh[j * nx + i-1])*0.5; |
} | } |
} | } |
| |
/* brute force method of calculating the derivative (no consideration for edges) */ | /* brute force method of calculating the derivative (no consideration for edges) */ |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
for (j = 3; j <= ny-4; j++) |
for (j = 1; j <= ny-2; j++) |
{ | { |
dery_bh[j * nx + i] = (-bh[(j-3) * nx + i] + 9.0*bh[(j-2) * nx + i] - 45.0*bh[(j-1) * nx + i] + 45*bh[(j+1) * nx + i] - 9.0*bh[(j+2) * nx + i] + bh[(j+3) * nx + i])*(1.0/60.0); |
dery_bh[j * nx + i] = (bh[(j+1) * nx + i] - bh[(j-1) * nx + i])*0.5; |
} | } |
} | } |
| |
| |
/* consider the edges: 3 pixels on each edge, for a total of 12 edge formulae below */ |
/* consider the edges */ |
i=0; | i=0; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
derx_bh[j * nx + i] = (-147.0*bh[j * nx + i] + 360.0*bh[j * nx + (i+1)] - 450.0*bh[j * nx + (i+2)] + 400.0*bh[j * nx + (i+3)] - 225.0*bh[j * nx + (i+4)] + 72.0*bh[j * nx + (i+5)] - 10.0*bh[j * nx + (i+6)])*(1.0/60.0); |
derx_bh[j * nx + i] = ( (-3*bh[j * nx + i]) + (4*bh[j * nx + (i+1)]) - (bh[j * nx + (i+2)]) )*0.5; |
} | } |
| |
i=nx-1; | i=nx-1; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
derx_bh[j * nx + i] = ( 147.0*bh[j * nx + i] - 360.0*bh[j * nx + (i-1)] + 450.0*bh[j * nx + (i-2)] - 400.0*bh[j * nx + (i-3)] + 225.0*bh[j * nx + (i-4)] - 72.0*bh[j * nx + (i-5)] + 10.0*bh[j * nx + (i-6)])*(1.0/60.0); |
derx_bh[j * nx + i] = ( (3*bh[j * nx + i]) + (-4*bh[j * nx + (i-1)]) - (-bh[j * nx + (i-2)]) )*0.5; |
} |
|
|
|
|
|
i=1; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
derx_bh[j * nx + i] = (-10.0*bh[j * nx + i] - 77.0*bh[j * nx + (i+1)] + 150.0*bh[j * nx + (i+2)] - 100.0*bh[j * nx + (i+3)] + 50.0*bh[j * nx + (i+4)] - 15.0*bh[j * nx + (i+5)] + 2.0*bh[j * nx + (i+6)])*(1.0/60.0); |
|
} |
|
|
|
i=nx-2; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
derx_bh[j * nx + i] = ( 10.0*bh[j * nx + i] + 77.0*bh[j * nx + (i-1)] - 150.0*bh[j * nx + (i-2)] + 100.0*bh[j * nx + (i-3)] - 50.0*bh[j * nx + (i-4)] + 15.0*bh[j * nx + (i-5)] - 2.0*bh[j * nx + (i-6)])*(1.0/60.0); |
|
} |
|
|
|
|
|
i=2; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
derx_bh[j * nx + i] = ( 2.0*bh[j * nx + i] - 24.0*bh[j * nx + (i+1)] - 35.0*bh[j * nx + (i+2)] + 80.0*bh[j * nx + (i+3)] - 30.0*bh[j * nx + (i+4)] + 8.0*bh[j * nx + (i+5)] - bh[j * nx + (i+6)])*(1.0/60.0); |
|
} | } |
| |
i=nx-3; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
derx_bh[j * nx + i] = (-2.0*bh[j * nx + i] + 24.0*bh[j * nx + (i-1)] + 35.0*bh[j * nx + (i-2)] - 80.0*bh[j * nx + (i-3)] + 30.0*bh[j * nx + (i-4)] - 8.0*bh[j * nx + (i-5)] + bh[j * nx + (i-6)])*(1.0/60.0); |
|
} |
|
|
|
|
|
j=0; | j=0; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
dery_bh[j * nx + i] = (-147.0*bh[j * nx + i] + 360.0*bh[(j+1) * nx + i] - 450.0*bh[(j+2) * nx + i] + 400.0*bh[(j+3) * nx + i] - 225.0*bh[(j+4) * nx + i] + 72.0*bh[(j+5) * nx + i] - 10.0*bh[(j+6) * nx + i])*(1.0/60.0); |
dery_bh[j * nx + i] = ( (-3*bh[j*nx + i]) + (4*bh[(j+1) * nx + i]) - (bh[(j+2) * nx + i]) )*0.5; |
} | } |
| |
j=ny-1; | j=ny-1; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
dery_bh[j * nx + i] = ( 147.0*bh[j * nx + i] - 360.0*bh[(j-1) * nx + i] + 450.0*bh[(j-2) * nx + i] - 400.0*bh[(j-3) * nx + i] + 225.0*bh[(j-4) * nx + i] - 72.0*bh[(j-5) * nx + i] + 10.0*bh[(j-6) * nx + i])*(1.0/60.0); |
dery_bh[j * nx + i] = ( (3*bh[j * nx + i]) + (-4*bh[(j-1) * nx + i]) - (-bh[(j-2) * nx + i]) )*0.5; |
} |
|
|
|
j=1; |
|
for (i = 0; i <= nx-2; i++) |
|
{ |
|
dery_bh[j * nx + i] = (-10.0*bh[j * nx + i] - 77.0*bh[(j+1) * nx + i] + 150.0*bh[(j+2) * nx + i] - 100.0*bh[(j+3) * nx + i] + 50.0*bh[(j+4) * nx + i] - 15.0*bh[(j+5) * nx + i] + 2.0*bh[(j+6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=ny-2; |
|
for (i = 0; i <= nx-2; i++) |
|
{ |
|
dery_bh[j * nx + i] = ( 10.0*bh[j * nx + i] + 77.0*bh[(j-1) * nx + i] - 150.0*bh[(j-2) * nx + i] + 100.0*bh[(j-3) * nx + i] - 50.0*bh[(j-4) * nx + i] + 15.0*bh[(j-5) * nx + i] - 2.0*bh[(j-6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=2; |
|
for (i = 0; i <= nx-3; i++) |
|
{ |
|
dery_bh[j * nx + i] = ( 2.0*bh[j * nx + i] - 24.0*bh[(j+1) * nx + i] - 35.0*bh[(j+2) * nx + i] + 80.0*bh[(j+3) * nx + i] - 30.0*bh[(j+4) * nx + i] + 8.0*bh[(j+5) * nx + i] - bh[(j+6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=ny-3; |
|
for (i = 0; i <= nx-3; i++) |
|
{ |
|
dery_bh[j * nx + i] = (-2.0*bh[j * nx + i] + 24.0*bh[(j-1) * nx + i] + 35.0*bh[(j-2) * nx + i] - 80.0*bh[(j-3) * nx + i] + 30.0*bh[(j-4) * nx + i] - 8.0*bh[(j-5) * nx + i] + bh[(j-6) * nx + i])*(1.0/60.0); |
|
} | } |
| |
| |
Line 483 int computeBzderivative(float *bz, float |
|
Line 381 int computeBzderivative(float *bz, float |
|
*mean_derivative_bz_ptr = 0.0; | *mean_derivative_bz_ptr = 0.0; |
float sum,err = 0.0; | float sum,err = 0.0; |
| |
|
|
/* brute force method of calculating the derivative (no consideration for edges) */ | /* brute force method of calculating the derivative (no consideration for edges) */ |
for (i = 3; i <= nx-4; i++) |
for (i = 1; i <= nx-2; i++) |
{ | { |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(bz[j * nx + i]) continue; | if isnan(bz[j * nx + i]) continue; |
derx_bz[j * nx + i] = (-bz[j * nx + (i-3)] + 9.0*bz[j * nx + (i-2)] - 45.0*bz[j * nx + (i-1)] + 45*bz[j * nx + (i+1)] - 9.0*bz[j * nx + (i+2)] + bz[j * nx + (i+3)])*(1.0/60.0); |
derx_bz[j * nx + i] = (bz[j * nx + i+1] - bz[j * nx + i-1])*0.5; |
} | } |
} | } |
| |
/* brute force method of calculating the derivative (no consideration for edges) */ | /* brute force method of calculating the derivative (no consideration for edges) */ |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
for (j = 3; j <= ny-4; j++) |
for (j = 1; j <= ny-2; j++) |
{ | { |
if isnan(bz[j * nx + i]) continue; | if isnan(bz[j * nx + i]) continue; |
dery_bz[j * nx + i] = (-bz[(j-3) * nx + i] + 9.0*bz[(j-2) * nx + i] - 45.0*bz[(j-1) * nx + i] + 45*bz[(j+1) * nx + i] - 9.0*bz[(j+2) * nx + i] + bz[(j+3) * nx + i])*(1.0/60.0); |
dery_bz[j * nx + i] = (bz[(j+1) * nx + i] - bz[(j-1) * nx + i])*0.5; |
} | } |
} | } |
| |
| |
/* consider the edges: 3 pixels on each edge, for a total of 12 edge formulae below */ |
/* consider the edges */ |
i=0; | i=0; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(bz[j * nx + i]) continue; | if isnan(bz[j * nx + i]) continue; |
derx_bz[j * nx + i] = (-147.0*bz[j * nx + i] + 360.0*bz[j * nx + (i+1)] - 450.0*bz[j * nx + (i+2)] + 400.0*bz[j * nx + (i+3)] - 225.0*bz[j * nx + (i+4)] + 72.0*bz[j * nx + (i+5)] - 10.0*bz[j * nx + (i+6)])*(1.0/60.0); |
derx_bz[j * nx + i] = ( (-3*bz[j * nx + i]) + (4*bz[j * nx + (i+1)]) - (bz[j * nx + (i+2)]) )*0.5; |
} | } |
| |
i=nx-1; | i=nx-1; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(bz[j * nx + i]) continue; | if isnan(bz[j * nx + i]) continue; |
derx_bz[j * nx + i] = ( 147.0*bz[j * nx + i] - 360.0*bz[j * nx + (i-1)] + 450.0*bz[j * nx + (i-2)] - 400.0*bz[j * nx + (i-3)] + 225.0*bz[j * nx + (i-4)] - 72.0*bz[j * nx + (i-5)] + 10.0*bz[j * nx + (i-6)])*(1.0/60.0); |
derx_bz[j * nx + i] = ( (3*bz[j * nx + i]) + (-4*bz[j * nx + (i-1)]) - (-bz[j * nx + (i-2)]) )*0.5; |
} |
|
|
|
|
|
i=1; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
if isnan(bz[j * nx + i]) continue; |
|
derx_bz[j * nx + i] = (-10.0*bz[j * nx + i] - 77.0*bz[j * nx + (i+1)] + 150.0*bz[j * nx + (i+2)] - 100.0*bz[j * nx + (i+3)] + 50.0*bz[j * nx + (i+4)] - 15.0*bz[j * nx + (i+5)] + 2.0*bz[j * nx + (i+6)])*(1.0/60.0); |
|
} |
|
|
|
i=nx-2; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
if isnan(bz[j * nx + i]) continue; |
|
derx_bz[j * nx + i] = ( 10.0*bz[j * nx + i] + 77.0*bz[j * nx + (i-1)] - 150.0*bz[j * nx + (i-2)] + 100.0*bz[j * nx + (i-3)] - 50.0*bz[j * nx + (i-4)] + 15.0*bz[j * nx + (i-5)] - 2.0*bz[j * nx + (i-6)])*(1.0/60.0); |
|
} |
|
|
|
|
|
i=2; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
if isnan(bz[j * nx + i]) continue; |
|
derx_bz[j * nx + i] = ( 2.0*bz[j * nx + i] - 24.0*bz[j * nx + (i+1)] - 35.0*bz[j * nx + (i+2)] + 80.0*bz[j * nx + (i+3)] - 30.0*bz[j * nx + (i+4)] + 8.0*bz[j * nx + (i+5)] - bz[j * nx + (i+6)])*(1.0/60.0); |
|
} |
|
|
|
i=nx-3; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
if isnan(bz[j * nx + i]) continue; |
|
derx_bz[j * nx + i] = (-2.0*bz[j * nx + i] + 24.0*bz[j * nx + (i-1)] + 35.0*bz[j * nx + (i-2)] - 80.0*bz[j * nx + (i-3)] + 30.0*bz[j * nx + (i-4)] - 8.0*bz[j * nx + (i-5)] + bz[j * nx + (i-6)])*(1.0/60.0); |
|
} | } |
| |
|
|
j=0; | j=0; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
if isnan(bz[j * nx + i]) continue; | if isnan(bz[j * nx + i]) continue; |
dery_bz[j * nx + i] = (-147.0*bz[j * nx + i] + 360.0*bz[(j+1) * nx + i] - 450.0*bz[(j+2) * nx + i] + 400.0*bz[(j+3) * nx + i] - 225.0*bz[(j+4) * nx + i] + 72.0*bz[(j+5) * nx + i] - 10.0*bz[(j+6) * nx + i])*(1.0/60.0); |
dery_bz[j * nx + i] = ( (-3*bz[j*nx + i]) + (4*bz[(j+1) * nx + i]) - (bz[(j+2) * nx + i]) )*0.5; |
} | } |
| |
j=ny-1; | j=ny-1; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
if isnan(bz[j * nx + i]) continue; | if isnan(bz[j * nx + i]) continue; |
dery_bz[j * nx + i] = ( 147.0*bz[j * nx + i] - 360.0*bz[(j-1) * nx + i] + 450.0*bz[(j-2) * nx + i] - 400.0*bz[(j-3) * nx + i] + 225.0*bz[(j-4) * nx + i] - 72.0*bz[(j-5) * nx + i] + 10.0*bz[(j-6) * nx + i])*(1.0/60.0); |
dery_bz[j * nx + i] = ( (3*bz[j * nx + i]) + (-4*bz[(j-1) * nx + i]) - (-bz[(j-2) * nx + i]) )*0.5; |
} |
|
|
|
j=1; |
|
for (i = 0; i <= nx-2; i++) |
|
{ |
|
if isnan(bz[j * nx + i]) continue; |
|
dery_bz[j * nx + i] = (-10.0*bz[j * nx + i] - 77.0*bz[(j+1) * nx + i] + 150.0*bz[(j+2) * nx + i] - 100.0*bz[(j+3) * nx + i] + 50.0*bz[(j+4) * nx + i] - 15.0*bz[(j+5) * nx + i] + 2.0*bz[(j+6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=ny-2; |
|
for (i = 0; i <= nx-2; i++) |
|
{ |
|
if isnan(bz[j * nx + i]) continue; |
|
dery_bz[j * nx + i] = ( 10.0*bz[j * nx + i] + 77.0*bz[(j-1) * nx + i] - 150.0*bz[(j-2) * nx + i] + 100.0*bz[(j-3) * nx + i] - 50.0*bz[(j-4) * nx + i] + 15.0*bz[(j-5) * nx + i] - 2.0*bz[(j-6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=2; |
|
for (i = 0; i <= nx-3; i++) |
|
{ |
|
if isnan(bz[j * nx + i]) continue; |
|
dery_bz[j * nx + i] = ( 2.0*bz[j * nx + i] - 24.0*bz[(j+1) * nx + i] - 35.0*bz[(j+2) * nx + i] + 80.0*bz[(j+3) * nx + i] - 30.0*bz[(j+4) * nx + i] + 8.0*bz[(j+5) * nx + i] - bz[(j+6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=ny-3; |
|
for (i = 0; i <= nx-3; i++) |
|
{ |
|
if isnan(bz[j * nx + i]) continue; |
|
dery_bz[j * nx + i] = (-2.0*bz[j * nx + i] + 24.0*bz[(j-1) * nx + i] + 35.0*bz[(j-2) * nx + i] - 80.0*bz[(j-3) * nx + i] + 30.0*bz[(j-4) * nx + i] - 8.0*bz[(j-5) * nx + i] + bz[(j-6) * nx + i])*(1.0/60.0); |
|
} | } |
| |
| |
Line 619 int computeBzderivative(float *bz, float |
|
Line 457 int computeBzderivative(float *bz, float |
|
} | } |
| |
/*===========================================*/ | /*===========================================*/ |
|
|
/* Example function 8: Current Jz = (dBy/dx) - (dBx/dy) */ | /* Example function 8: Current Jz = (dBy/dx) - (dBx/dy) */ |
| |
// In discretized space like data pixels, | // In discretized space like data pixels, |
Line 627 int computeBzderivative(float *bz, float |
|
Line 464 int computeBzderivative(float *bz, float |
|
// the integration of the field Bx and By along | // the integration of the field Bx and By along |
// the circumference of the data pixel divided by the area of the pixel. | // the circumference of the data pixel divided by the area of the pixel. |
// One form of differencing (a word for the differential operator | // One form of differencing (a word for the differential operator |
// in the discretized space) of the curl is expressed as the following, |
// in the discretized space) of the curl is expressed as |
// which utilizes a second-order finite difference method: |
|
|
|
// (dx * (Bx(i,j-1)+Bx(i,j)) / 2 | // (dx * (Bx(i,j-1)+Bx(i,j)) / 2 |
// +dy * (By(i+1,j)+By(i,j)) / 2 | // +dy * (By(i+1,j)+By(i,j)) / 2 |
// -dx * (Bx(i,j+1)+Bx(i,j)) / 2 | // -dx * (Bx(i,j+1)+Bx(i,j)) / 2 |
// -dy * (By(i-1,j)+By(i,j)) / 2) / (dx * dy) | // -dy * (By(i-1,j)+By(i,j)) / 2) / (dx * dy) |
// | // |
// | // |
// However, for the purposes of this calculation, we will use a sixth-order finite difference |
|
// method taken from the pencil code: |
|
// |
|
// dBy/dx = ( -By*(i-3,j) + 9By(i-2,j) - 45By(i-1,j) + 45By(i+1,j) - 9By(i+2,j) + By(i+3,j) )/ 60 |
|
// and similarly for dBx/dy. |
|
// |
|
// To change units from Gauss/pixel to mA/m^2 (the units for Jz in Leka and Barnes, 2003), | // To change units from Gauss/pixel to mA/m^2 (the units for Jz in Leka and Barnes, 2003), |
// one must perform the following unit conversions: | // one must perform the following unit conversions: |
// (Gauss)(1/arcsec)(arcsec/meter)(Newton/Gauss*Ampere*meter)(Ampere^2/Newton)(milliAmpere/Ampere), or | // (Gauss)(1/arcsec)(arcsec/meter)(Newton/Gauss*Ampere*meter)(Ampere^2/Newton)(milliAmpere/Ampere), or |
Line 664 int computeBzderivative(float *bz, float |
|
Line 493 int computeBzderivative(float *bz, float |
|
// int *mask, int *bitmask, float cdelt1, double rsun_ref, double rsun_obs,float *derx, float *dery, float *noisebx, | // int *mask, int *bitmask, float cdelt1, double rsun_ref, double rsun_obs,float *derx, float *dery, float *noisebx, |
// float *noiseby, float *noisebz) | // float *noiseby, float *noisebz) |
| |
|
|
int computeJz(float *bx_err, float *by_err, float *bx, float *by, int *dims, float *jz, float *jz_err, float *jz_err_squared, | int computeJz(float *bx_err, float *by_err, float *bx, float *by, int *dims, float *jz, float *jz_err, float *jz_err_squared, |
int *mask, int *bitmask, float cdelt1, double rsun_ref, double rsun_obs,float *derx, float *dery) | int *mask, int *bitmask, float cdelt1, double rsun_ref, double rsun_obs,float *derx, float *dery) |
| |
Line 672 int computeJz(float *bx_err, float *by_e |
|
Line 500 int computeJz(float *bx_err, float *by_e |
|
{ | { |
int nx = dims[0], ny = dims[1]; | int nx = dims[0], ny = dims[1]; |
int i, j, count_mask=0; | int i, j, count_mask=0; |
printf("nx=%d\n",nx); |
|
printf("ny=%d\n",ny); |
|
if (nx <= 0 || ny <= 0) return 1; | if (nx <= 0 || ny <= 0) return 1; |
float curl=0.0, us_i=0.0,test_perimeter=0.0,mean_curl=0.0; | float curl=0.0, us_i=0.0,test_perimeter=0.0,mean_curl=0.0; |
| |
|
|
/* Calculate the derivative*/ | /* Calculate the derivative*/ |
/* brute force method of calculating the derivative (no consideration for edges) */ | /* brute force method of calculating the derivative (no consideration for edges) */ |
for (i = 3; i <= nx-4; i++) |
|
|
|
|
for (i = 1; i <= nx-2; i++) |
{ | { |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(by[j * nx + i]) continue; | if isnan(by[j * nx + i]) continue; |
derx[j * nx + i] = (-by[j * nx + (i-3)] + 9.0*by[j * nx + (i-2)] - 45.0*by[j * nx + (i-1)] + 45*by[j * nx + (i+1)] - 9.0*by[j * nx + (i+2)] + by[j * nx + (i+3)])*(1.0/60.0); |
derx[j * nx + i] = (by[j * nx + i+1] - by[j * nx + i-1])*0.5; |
} | } |
} | } |
| |
/* brute force method of calculating the derivative (no consideration for edges) */ |
|
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
for (j = 3; j <= ny-4; j++) |
for (j = 1; j <= ny-2; j++) |
{ | { |
if isnan(bx[j * nx + i]) continue; | if isnan(bx[j * nx + i]) continue; |
dery[j * nx + i] = (-bx[(j-3) * nx + i] + 9.0*bx[(j-2) * nx + i] - 45.0*bx[(j-1) * nx + i] + 45*bx[(j+1) * nx + i] - 9.0*bx[(j+2) * nx + i] + bx[(j+3) * nx + i])*(1.0/60.0); |
dery[j * nx + i] = (bx[(j+1) * nx + i] - bx[(j-1) * nx + i])*0.5; |
} | } |
} | } |
| |
/* consider the edges: 3 pixels on each edge, for a total of 12 edge formulae below */ |
// consider the edges |
i=0; | i=0; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(by[j * nx + i]) continue; | if isnan(by[j * nx + i]) continue; |
derx[j * nx + i] = (-147.0*by[j * nx + i] + 360.0*by[j * nx + (i+1)] - 450.0*by[j * nx + (i+2)] + 400.0*by[j * nx + (i+3)] - 225.0*by[j * nx + (i+4)] + 72.0*by[j * nx + (i+5)] - 10.0*by[j * nx + (i+6)])*(1.0/60.0); |
derx[j * nx + i] = ( (-3*by[j * nx + i]) + (4*by[j * nx + (i+1)]) - (by[j * nx + (i+2)]) )*0.5; |
} | } |
| |
i=nx-1; | i=nx-1; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(by[j * nx + i]) continue; | if isnan(by[j * nx + i]) continue; |
derx[j * nx + i] = ( 147.0*by[j * nx + i] - 360.0*by[j * nx + (i-1)] + 450.0*by[j * nx + (i-2)] - 400.0*by[j * nx + (i-3)] + 225.0*by[j * nx + (i-4)] - 72.0*by[j * nx + (i-5)] + 10.0*by[j * nx + (i-6)])*(1.0/60.0); |
derx[j * nx + i] = ( (3*by[j * nx + i]) + (-4*by[j * nx + (i-1)]) - (-by[j * nx + (i-2)]) )*0.5; |
} |
|
|
|
|
|
i=1; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
if isnan(by[j * nx + i]) continue; |
|
derx[j * nx + i] = (-10.0*by[j * nx + i] - 77.0*by[j * nx + (i+1)] + 150.0*by[j * nx + (i+2)] - 100.0*by[j * nx + (i+3)] + 50.0*by[j * nx + (i+4)] - 15.0*by[j * nx + (i+5)] + 2.0*by[j * nx + (i+6)])*(1.0/60.0); |
|
} | } |
| |
i=nx-2; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
if isnan(by[j * nx + i]) continue; |
|
derx[j * nx + i] = ( 10.0*by[j * nx + i] + 77.0*by[j * nx + (i-1)] - 150.0*by[j * nx + (i-2)] + 100.0*by[j * nx + (i-3)] - 50.0*by[j * nx + (i-4)] + 15.0*by[j * nx + (i-5)] - 2.0*by[j * nx + (i-6)])*(1.0/60.0); |
|
} |
|
|
|
|
|
i=2; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
if isnan(by[j * nx + i]) continue; |
|
derx[j * nx + i] = ( 2.0*by[j * nx + i] - 24.0*by[j * nx + (i+1)] - 35.0*by[j * nx + (i+2)] + 80.0*by[j * nx + (i+3)] - 30.0*by[j * nx + (i+4)] + 8.0*by[j * nx + (i+5)] - by[j * nx + (i+6)])*(1.0/60.0); |
|
} |
|
|
|
i=nx-3; |
|
for (j = 0; j <= ny-2; j++) |
|
{ |
|
if isnan(by[j * nx + i]) continue; |
|
derx[j * nx + i] = (-2.0*by[j * nx + i] + 24.0*by[j * nx + (i-1)] + 35.0*by[j * nx + (i-2)] - 80.0*by[j * nx + (i-3)] + 30.0*by[j * nx + (i-4)] - 8.0*by[j * nx + (i-5)] + by[j * nx + (i-6)])*(1.0/60.0); |
|
} |
|
|
|
|
|
j=0; | j=0; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
if isnan(bx[j * nx + i]) continue; | if isnan(bx[j * nx + i]) continue; |
dery[j * nx + i] = (-147.0*bx[j * nx + i] + 360.0*bx[(j+1) * nx + i] - 450.0*bx[(j+2) * nx + i] + 400.0*bx[(j+3) * nx + i] - 225.0*bx[(j+4) * nx + i] + 72.0*bx[(j+5) * nx + i] - 10.0*bx[(j+6) * nx + i])*(1.0/60.0); |
dery[j * nx + i] = ( (-3*bx[j*nx + i]) + (4*bx[(j+1) * nx + i]) - (bx[(j+2) * nx + i]) )*0.5; |
} | } |
| |
j=ny-1; | j=ny-1; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
if isnan(bx[j * nx + i]) continue; | if isnan(bx[j * nx + i]) continue; |
dery[j * nx + i] = ( 147.0*bx[j * nx + i] - 360.0*bx[(j-1) * nx + i] + 450.0*bx[(j-2) * nx + i] - 400.0*bx[(j-3) * nx + i] + 225.0*bx[(j-4) * nx + i] - 72.0*bx[(j-5) * nx + i] + 10.0*bx[(j-6) * nx + i])*(1.0/60.0); |
dery[j * nx + i] = ( (3*bx[j * nx + i]) + (-4*bx[(j-1) * nx + i]) - (-bx[(j-2) * nx + i]) )*0.5; |
} | } |
| |
j=1; |
|
for (i = 0; i <= nx-2; i++) |
|
{ |
|
if isnan(bx[j * nx + i]) continue; |
|
dery[j * nx + i] = (-10.0*bx[j * nx + i] - 77.0*bx[(j+1) * nx + i] + 150.0*bx[(j+2) * nx + i] - 100.0*bx[(j+3) * nx + i] + 50.0*bx[(j+4) * nx + i] - 15.0*bx[(j+5) * nx + i] + 2.0*bx[(j+6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=ny-2; |
|
for (i = 0; i <= nx-2; i++) |
|
{ |
|
if isnan(bx[j * nx + i]) continue; |
|
dery[j * nx + i] = ( 10.0*bx[j * nx + i] + 77.0*bx[(j-1) * nx + i] - 150.0*bx[(j-2) * nx + i] + 100.0*bx[(j-3) * nx + i] - 50.0*bx[(j-4) * nx + i] + 15.0*bx[(j-5) * nx + i] - 2.0*bx[(j-6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=2; |
|
for (i = 0; i <= nx-3; i++) |
|
{ |
|
if isnan(bx[j * nx + i]) continue; |
|
dery[j * nx + i] = ( 2.0*bx[j * nx + i] - 24.0*bx[(j+1) * nx + i] - 35.0*bx[(j+2) * nx + i] + 80.0*bx[(j+3) * nx + i] - 30.0*bx[(j+4) * nx + i] + 8.0*bx[(j+5) * nx + i] - bx[(j+6) * nx + i])*(1.0/60.0); |
|
} |
|
|
|
j=ny-3; |
|
for (i = 0; i <= nx-3; i++) |
|
{ |
|
if isnan(bx[j * nx + i]) continue; |
|
dery[j * nx + i] = (-2.0*bx[j * nx + i] + 24.0*bx[(j-1) * nx + i] + 35.0*bx[(j-2) * nx + i] - 80.0*bx[(j-3) * nx + i] + 30.0*bx[(j-4) * nx + i] - 8.0*bx[(j-5) * nx + i] + bx[(j-6) * nx + i])*(1.0/60.0); |
|
} |
|
| |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
/* calculate jz at all points */ |
// calculate jz at all points |
jz[j * nx + i] = (derx[j * nx + i]-dery[j * nx + i]); /* jz is in units of Gauss/pix */ |
jz[j * nx + i] = (derx[j * nx + i]-dery[j * nx + i]); // jz is in units of Gauss/pix |
|
jz_err[j * nx + i]=0.5*sqrt( (bx_err[(j+1) * nx + i]*bx_err[(j+1) * nx + i]) + (bx_err[(j-1) * nx + i]*bx_err[(j-1) * 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)]) ) ; |
/* calculate the error in jz at all points */ |
|
jz_err[j * nx + i]=sqrt( (1.0/60.0)*bx_err[(j-3) * nx + i]*(1.0/60.0)*bx_err[(j-3) * nx + i] + (9.0/60.0)*bx_err[(j-2) * nx + i]*(9.0/60.0)*bx_err[(j-2) * nx + i] + (45.0/60.0)*bx_err[(j-1) * nx + i]*(45.0/60.0)*bx_err[(j-1) * nx + i] + |
|
(1.0/60.0)*bx_err[(j+3) * nx + i]*(1.0/60.0)*bx_err[(j+3) * nx + i] + (9.0/60.0)*bx_err[(j+2) * nx + i]*(9.0/60.0)*bx_err[(j+2) * nx + i] + (45.0/60.0)*bx_err[(j+1) * nx + i]*(45.0/60.0)*bx_err[(j+1) * nx + i] + |
|
(1.0/60.0)*by_err[j * nx + (i-3)]*(1.0/60.0)*by_err[j * nx + (i-3)] + (9.0/60.0)*by_err[j * nx + (i-2)]*(9.0/60.0)*by_err[j * nx + (i-2)] + (45.0/60.0)*by_err[j * nx + (i-1)]*(45.0/60.0)*by_err[j * nx + (i-1)] + |
|
(1.0/60.0)*by_err[j * nx + (i+3)]*(1.0/60.0)*by_err[j * nx + (i+3)] + (9.0/60.0)*by_err[j * nx + (i+2)]*(9.0/60.0)*by_err[j * nx + (i+2)] + (45.0/60.0)*by_err[j * nx + (i+1)]*(45.0/60.0)*by_err[j * nx + (i+1)] ); |
|
|
|
jz_err_squared[j * nx + i]=(jz_err[j * nx + i]*jz_err[j * nx + i]); | jz_err_squared[j * nx + i]=(jz_err[j * nx + i]*jz_err[j * nx + i]); |
count_mask++; | count_mask++; |
} | } |
//printf("\n"); |
|
} | } |
| |
return 0; | return 0; |
Line 812 int computeJz(float *bx_err, float *by_e |
|
Line 576 int computeJz(float *bx_err, float *by_e |
|
/*===========================================*/ | /*===========================================*/ |
| |
| |
/* Example function 9: Compute quantities on smoothed Jz array */ |
/* Example function 9: Compute quantities on Jz array */ |
|
// Compute mean and total current on Jz array. |
// All of the subsequent functions, including this one, use a smoothed Jz array. The smoothing is performed by Jesper's |
|
// fresize routines. These routines are located at /cvs/JSOC/proj/libs/interpolate. A Gaussian with a FWHM of 4 pixels |
|
// and truncation width of 12 pixels is used to smooth the array; however, a quick analysis shows that the mean values |
|
// of qualities like Jz and helicity do not change much as a result of smoothing. The smoothed array will, of course, |
|
// give a lower total Jz as the stron field pixels have been smoothed out to neighboring weaker field pixels. |
|
| |
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, | 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, |
float *mean_jz_ptr, float *mean_jz_err_ptr, float *us_i_ptr, float *us_i_err_ptr, int *mask, int *bitmask, | float *mean_jz_ptr, float *mean_jz_err_ptr, float *us_i_ptr, float *us_i_err_ptr, int *mask, int *bitmask, |
Line 839 int computeJzsmooth(float *bx, float *by |
|
Line 598 int computeJzsmooth(float *bx, float *by |
|
{ | { |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
//printf("%f ",jz_smooth[j * nx + i]); |
|
if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue; | if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue; |
if isnan(derx[j * nx + i]) continue; | if isnan(derx[j * nx + i]) continue; |
if isnan(dery[j * nx + i]) continue; | if isnan(dery[j * nx + i]) continue; |
//if isnan(jz_smooth[j * nx + i]) continue; |
|
//curl += (jz_smooth[j * nx + i])*(1/cdelt1)*(rsun_obs/rsun_ref)*(0.00010)*(1/MUNAUGHT)*(1000.); /* curl is in units of mA / m^2 */ |
|
//us_i += fabs(jz_smooth[j * nx + i])*(cdelt1/1)*(rsun_ref/rsun_obs)*(0.00010)*(1/MUNAUGHT); /* us_i is in units of A */ |
|
//jz_rms_err[j * nx + i] = sqrt(jz_err_squared_smooth[j * nx + i]); |
|
//err += (jz_rms_err[j * nx + i]*jz_rms_err[j * nx + i]); |
|
if isnan(jz[j * nx + i]) continue; | if isnan(jz[j * nx + i]) continue; |
curl += (jz[j * nx + i])*(1/cdelt1)*(rsun_obs/rsun_ref)*(0.00010)*(1/MUNAUGHT)*(1000.); /* curl is in units of mA / m^2 */ | curl += (jz[j * nx + i])*(1/cdelt1)*(rsun_obs/rsun_ref)*(0.00010)*(1/MUNAUGHT)*(1000.); /* curl is in units of mA / m^2 */ |
us_i += fabs(jz[j * nx + i])*(cdelt1/1)*(rsun_ref/rsun_obs)*(0.00010)*(1/MUNAUGHT); /* us_i is in units of A */ | us_i += fabs(jz[j * nx + i])*(cdelt1/1)*(rsun_ref/rsun_obs)*(0.00010)*(1/MUNAUGHT); /* us_i is in units of A */ |
err += (jz_err[j * nx + i]*jz_err[j * nx + i]); | err += (jz_err[j * nx + i]*jz_err[j * nx + i]); |
count_mask++; | count_mask++; |
} | } |
//printf("\n"); |
|
} | } |
| |
/* Calculate mean vertical current density (mean_curl) and total unsigned vertical current (us_i) using smoothed Jz array and continue conditions above */ | /* Calculate mean vertical current density (mean_curl) and total unsigned vertical current (us_i) using smoothed Jz array and continue conditions above */ |
Line 1063 int computeSumAbsPerPolarity(float *jz_e |
|
Line 815 int computeSumAbsPerPolarity(float *jz_e |
|
/*===========================================*/ | /*===========================================*/ |
/* Example function 13: Mean photospheric excess magnetic energy and total photospheric excess magnetic energy density */ | /* Example function 13: Mean photospheric excess magnetic energy and total photospheric excess magnetic energy density */ |
// The units for magnetic energy density in cgs are ergs per cubic centimeter. The formula B^2/8*PI integrated over all space, dV | // The units for magnetic energy density in cgs are ergs per cubic centimeter. The formula B^2/8*PI integrated over all space, dV |
// automatically yields erg per cubic centimeter for an input B in Gauss. |
// automatically yields erg per cubic centimeter for an input B in Gauss. Note that the 8*PI can come out of the integral; thus, |
|
// the integral is over B^2 dV and the 8*PI is divided at the end. |
// | // |
// Total magnetic energy is the magnetic energy density times dA, or the area, and the units are thus ergs/cm. To convert | // Total magnetic energy is the magnetic energy density times dA, or the area, and the units are thus ergs/cm. To convert |
// ergs per centimeter cubed to ergs per centimeter, simply multiply by the area per pixel in cm: | // ergs per centimeter cubed to ergs per centimeter, simply multiply by the area per pixel in cm: |
Line 1084 int computeFreeEnergy(float *bx_err, flo |
|
Line 837 int computeFreeEnergy(float *bx_err, flo |
|
| |
*totpotptr=0.0; | *totpotptr=0.0; |
*meanpotptr=0.0; | *meanpotptr=0.0; |
float sum,err=0.0; |
float sum,sum1,err=0.0; |
| |
for (i = 0; i < nx; i++) | for (i = 0; i < nx; i++) |
{ | { |
Line 1093 int computeFreeEnergy(float *bx_err, flo |
|
Line 846 int computeFreeEnergy(float *bx_err, flo |
|
if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue; | if ( mask[j * nx + i] < 70 || bitmask[j * nx + i] < 30 ) continue; |
if isnan(bx[j * nx + i]) continue; | if isnan(bx[j * nx + i]) continue; |
if isnan(by[j * nx + i]) continue; | if isnan(by[j * nx + i]) continue; |
sum += ( ((bpx[j * nx + i] - bx[j * nx + i])*(bpx[j * nx + i] - bx[j * nx + i])) + ((bpy[j * nx + i] - by[j * nx + i])*(bpy[j * nx + i] - by[j * nx + i])) ) / 8.*PI; |
sum += ( ((bpx[j * nx + i] - bx[j * nx + i])*(bpx[j * nx + i] - bx[j * nx + i])) + ((bpy[j * nx + i] - by[j * nx + i])*(bpy[j * nx + i] - by[j * nx + i])) )*(cdelt1*cdelt1*(rsun_ref/rsun_obs)*(rsun_ref/rsun_obs)*100.0*100.0); |
|
sum1 += ( ((bpx[j * nx + i] - bx[j * nx + i])*(bpx[j * nx + i] - bx[j * nx + i])) + ((bpy[j * nx + i] - by[j * nx + i])*(bpy[j * nx + i] - by[j * nx + i])) ); |
err += (4.0*bx[j * nx + i]*bx[j * nx + i]*bx_err[j * nx + i]*bx_err[j * nx + i]) + (4.0*by[j * nx + i]*by[j * nx + i]*by_err[j * nx + i]*by_err[j * nx + i]); | err += (4.0*bx[j * nx + i]*bx[j * nx + i]*bx_err[j * nx + i]*bx_err[j * nx + i]) + (4.0*by[j * nx + i]*by[j * nx + i]*by_err[j * nx + i]*by_err[j * nx + i]); |
//err += 2.0*bz_err[j * nx + i]*bz_err[j * nx + i]; |
|
count_mask++; | count_mask++; |
} | } |
} | } |
| |
*meanpotptr = (sum) / (count_mask); /* Units are ergs per cubic centimeter */ |
*meanpotptr = (sum1/(8.*PI)) / (count_mask); /* Units are ergs per cubic centimeter */ |
*meanpot_err_ptr = (sqrt(err)) / (count_mask*8.*PI); // error in the quantity (sum)/(count_mask) |
*meanpot_err_ptr = (sqrt(err))*fabs(cdelt1*cdelt1*(rsun_ref/rsun_obs)*(rsun_ref/rsun_obs)*100.0*100.0) / (count_mask*8.*PI); // error in the quantity (sum)/(count_mask) |
//*mean_derivative_bz_err_ptr = (sqrt(err))/(count_mask); // error in the quantity (sum)/(count_mask) |
|
| |
/* Units of sum are ergs/cm^3, units of factor are cm^2/pix^2; therefore, units of totpotptr are ergs per centimeter */ | /* Units of sum are ergs/cm^3, units of factor are cm^2/pix^2; therefore, units of totpotptr are ergs per centimeter */ |
*totpotptr = sum*(cdelt1*cdelt1*(rsun_ref/rsun_obs)*(rsun_ref/rsun_obs)*100.0*100.0*(1/8.*PI)) ; |
*totpotptr = (sum)/(8.*PI); |
*totpot_err_ptr = (sqrt(err))*fabs(cdelt1*cdelt1*(rsun_ref/rsun_obs)*(rsun_ref/rsun_obs)*100.0*100.0*(1/8.*PI)); |
*totpot_err_ptr = (sqrt(err))*fabs(cdelt1*cdelt1*(rsun_ref/rsun_obs)*(rsun_ref/rsun_obs)*100.0*100.0*(1/(8.*PI))); |
| |
printf("MEANPOT=%g\n",*meanpotptr); | printf("MEANPOT=%g\n",*meanpotptr); |
printf("MEANPOT_err=%g\n",*meanpot_err_ptr); | printf("MEANPOT_err=%g\n",*meanpot_err_ptr); |