function wfgeneration, dim, length, L0, r0, lambda, SEED=seed 
;
; wave-front (wf) generation following von Karman model
; (infinite L0 -Kolmogorov model- not allowed here).
;
; dim    = wf linear dimension [px],
; length = wf physical length [m],
; L0     = wf outer-scale [m],
; seed   = random generation seed (OPTIONAL),
; r0     = Fried parameter at wavelength 'lambda' [m],
; lambda = wavelength at which r0 is defined.
;
; Marcel Carbillet [marcel.carbillet@unice.fr],
; lab. Lagrange (UCA, OCA, CNRS), Feb. 2013.
;
; Last modification: Feb. 2018.
;
phase = (randomu(seed,dim,dim)-.5) * 2*!PI   ; rnd uniformly distributed phase
                                             ; (between -PI and +PI)
rr = dist(dim)
modul = (rr^2+(length/L0)^2)^(-11/12.)       ; von Karman model

screen = fft(modul*exp(complex(0,1)*phase), /INVERSE)
                                             ; compute wf
screen *= sqrt(2)*sqrt(.0228)*(length/r0)^(5/6.)*lambda/(2*!PI)
                                             ; proper normalization of wf
screen -= mean(screen)						 ; force mean to zero

return, screen                               ; deliver 2 independent wf:
                                             ; float(screen) & imaginary(screen)
end