`
restore,filename = 'one_mg.sav', /ver
psd = psd_iso(mg, /arc) ;these two command lines generate a random array of magnetic flux to calculate what the noise should be
z = findgen(5000)/100. ;this is the height above the photosphere
n = n_elements(psd.k)
binsize = psd.k[2]-psd.k[1] ; since all bins are the same size, this is the dk used in intgeration
noise =0 ;this is a noise subtraction, where the last 10% of the elements of psd.psd is assumed to have tailed off to become noise.
for i = n_elements(psd.psd)-(n_elements(psd.psd)/10),n_elements(psd.psd)-1 do begin $
noise = noise + psd.psd[i] & $
endfor
noise = noise/((n_elements(psd.psd))/(10))
psd.psd = psd.psd - noise
A = 0
for i = 0,n-1 do begin $
A = A + binsize*psd.k[i]*psd.psd[i]*exp(-2.*psd.k[i]*z) & $
endfor
A = A*2.*pi
B = 0
for i = 0,n-1 do begin $
B = B + binsize*(psd.k[i])^3.*psd.psd[i]*exp(-2.*psd.k[i]*z) & $
endfor
B = B*2.*pi
D = 0
for i = 0,n-1 do begin $
D = D + binsize*(psd.k[i])^2.*psd.psd[i]*exp(-2.*psd.k[i]*z) & $
endfor
D = D*2.*pi
q = (b/a)^0.5
sigma = (a)^0.5
c = D/((a*b))^0.5
; these are all the spectral integrals evaluated and then re-arranged to find out the parameters of the field required
end