76 pi5 = 3.14159*3.14159*3.14159*3.14159*3.14159
77 lamda4 = lamda_radar*lamda_radar*lamda_radar*lamda_radar
78 m_w_0 = m_complex_water_ray(lamda_radar, 0.0d0)
79 m_i_0 = m_complex_ice_maetzler(lamda_radar, 0.0d0)
80 k_w = (abs( (m_w_0*m_w_0 - 1.0) /(m_w_0*m_w_0 + 2.0) ))**2
86 simpson(n) = simpson(n) + basis(1)
87 simpson(n+1) = simpson(n+1) + basis(2)
88 simpson(n+2) = simpson(n+2) + basis(3)
92 mixingrulestring_s(n:n) = char(0)
93 matrixstring_s(n:n) = char(0)
94 inclusionstring_s(n:n) = char(0)
95 hoststring_s(n:n) = char(0)
96 hostmatrixstring_s(n:n) = char(0)
97 hostinclusionstring_s(n:n) = char(0)
98 mixingrulestring_g(n:n) = char(0)
99 matrixstring_g(n:n) = char(0)
100 inclusionstring_g(n:n) = char(0)
101 hoststring_g(n:n) = char(0)
102 hostmatrixstring_g(n:n) = char(0)
103 hostinclusionstring_g(n:n) = char(0)
106 mixingrulestring_s =
'maxwellgarnett'
108 matrixstring_s =
'water'
109 inclusionstring_s =
'spheroidal'
110 hostmatrixstring_s =
'icewater'
111 hostinclusionstring_s =
'spheroidal'
113 mixingrulestring_g =
'maxwellgarnett'
115 matrixstring_g =
'water'
116 inclusionstring_g =
'spheroidal'
117 hostmatrixstring_g =
'icewater'
118 hostinclusionstring_g =
'spheroidal'
122 xxdx(nrbins+1) = 0.02d0
124 xxdx(n) = dexp(dfloat(n-1)/dfloat(nrbins) &
125 *dlog(xxdx(nrbins+1)/xxdx(1)) +dlog(xxdx(1)))
128 xxds(n) = dsqrt(xxdx(n)*xxdx(n+1))
129 xdts(n) = xxdx(n+1) - xxdx(n)
134 xxdx(nrbins+1) = 0.05d0
136 xxdx(n) = dexp(dfloat(n-1)/dfloat(nrbins) &
137 *dlog(xxdx(nrbins+1)/xxdx(1)) +dlog(xxdx(1)))
140 xxdg(n) = dsqrt(xxdx(n)*xxdx(n+1))
141 xdtg(n) = xxdx(n+1) - xxdx(n)
152 xcre(3) = 1. + xbm_r + xmu_r
153 xcre(4) = 1. + 2.*xbm_r + xmu_r
155 xcrg(n) = wgamma(xcre(n))
161 xcse(3) = 1. + xbm_s + xmu_s
162 xcse(4) = 1. + 2.*xbm_s + xmu_s
164 xcsg(n) = wgamma(xcse(n))
170 xcge(3) = 1. + xbm_g + xmu_g
171 xcge(4) = 1. + 2.*xbm_g + xmu_g
173 xcgg(n) = wgamma(xcge(n))
195 COMPLEX*16 FUNCTION m_complex_water_ray(lambda,T)
198 DOUBLE PRECISION,
INTENT(IN):: t,lambda
199 DOUBLE PRECISION:: epsinf,epss,epsr,epsi
200 DOUBLE PRECISION:: alpha,lambdas,sigma,nenner
201 COMPLEX*16,
PARAMETER:: i = (0d0,1d0)
202 DOUBLE PRECISION,
PARAMETER:: pix=3.1415926535897932384626434d0
204 epsinf = 5.27137d0 + 0.02164740d0 * t - 0.00131198d0 * t*t
205 epss = 78.54d+0 * (1.0 - 4.579d-3 * (t - 25.0) &
206 + 1.190d-5 * (t - 25.0)*(t - 25.0) &
207 - 2.800d-8 * (t - 25.0)*(t - 25.0)*(t - 25.0))
208 alpha = -16.8129d0/(t+273.16) + 0.0609265d0
209 lambdas = 0.00033836d0 * exp(2513.98d0/(t+273.16)) * 1e-2
211 nenner = 1.d0+2.d0*(lambdas/lambda)**(1d0-alpha)*sin(alpha*pix*0.5) &
212 + (lambdas/lambda)**(2d0-2d0*alpha)
213 epsr = epsinf + ((epss-epsinf) * ((lambdas/lambda)**(1d0-alpha) &
214 * sin(alpha*pix*0.5)+1d0)) / nenner
215 epsi = ((epss-epsinf) * ((lambdas/lambda)**(1d0-alpha) &
216 * cos(alpha*pix*0.5)+0d0)) / nenner &
217 + lambda*1.25664/1.88496
219 m_complex_water_ray = sqrt(cmplx(epsr,-epsi))
265 subroutine rayleigh_soak_wetgraupel (x_g, a_geo, b_geo, fmelt, &
266 meltratio_outside, m_w, m_i, lambda, C_back, &
267 mixingrule,matrix,inclusion, &
268 host,hostmatrix,hostinclusion)
272 DOUBLE PRECISION,
INTENT(in):: x_g, a_geo, b_geo, fmelt, lambda, &
274 DOUBLE PRECISION,
INTENT(out):: c_back
275 COMPLEX*16,
INTENT(in):: m_w, m_i
276 CHARACTER(len=*),
INTENT(in):: mixingrule, matrix, inclusion, &
277 host, hostmatrix, hostinclusion
279 COMPLEX*16:: m_core, m_air
280 DOUBLE PRECISION:: d_large, d_g, rhog, x_w, xw_a, fm, fmgrenz, &
281 volg, vg, volair, volice, volwater, &
282 meltratio_outside_grenz, mra
284 DOUBLE PRECISION,
PARAMETER:: pix=3.1415926535897932384626434d0
287 m_air = (1.0d0,0.0d0)
290 fm = dmax1(dmin1(fmelt, 1.0d0), 0.0d0)
292 mra = dmax1(dmin1(meltratio_outside, 1.0d0), 0.0d0)
299 mra = mra + (1.0d0-mra)*fm
303 d_g = a_geo * x_g**b_geo
305 if (d_g .ge. 1d-12)
then
308 rhog = dmax1(dmin1(x_g / vg, 900.0d0), 10.0d0)
311 meltratio_outside_grenz = 1.0d0 - rhog / 1000.
313 if (mra .le. meltratio_outside_grenz)
then
317 volg = vg * (1.0d0 - mra * fm)
322 fmgrenz=(900.0-rhog)/(mra*900.0-rhog+900.0*rhog/1000.)
324 if (fm .le. fmgrenz)
then
326 volg = (1.0 - mra * fm) * vg
330 volg = (x_g - x_w) / 900.0 + x_w / 1000.
335 d_large = (6.0 / pix * volg) ** (1./3.)
336 volice = (x_g - x_w) / (volg * 900.0)
337 volwater = x_w / (1000. * volg)
338 volair = 1.0 - volice - volwater
342 m_core = get_m_mix_nested(m_air, m_i, m_w, volair, volice, &
343 volwater, mixingrule, host, matrix, inclusion, &
344 hostmatrix, hostinclusion,
error)
345 if (
error .ne. 0)
then
351 c_back = (abs((m_core**2-1.0d0)/(m_core**2+2.0d0)))**2 &
352 * pi5 * d_large**6 / lamda4
362 complex*16 function get_m_mix_nested (m_a, m_i, m_w, volair, &
363 volice, volwater, mixingrule, host, matrix, &
364 inclusion, hostmatrix, hostinclusion, cumulerror)
368 DOUBLE PRECISION,
INTENT(in):: volice, volair, volwater
369 COMPLEX*16,
INTENT(in):: m_a, m_i, m_w
370 CHARACTER(len=*),
INTENT(in):: mixingrule, host, matrix, &
371 inclusion, hostmatrix, hostinclusion
372 INTEGER,
INTENT(out):: cumulerror
374 DOUBLE PRECISION:: vol1, vol2
382 get_m_mix_nested = cmplx(1.0d0,0.0d0)
384 if (host .eq.
'air')
then
386 if (matrix .eq.
'air')
then
387 write(*,*)
'GET_M_MIX_NESTED: bad matrix: ', matrix
388 cumulerror = cumulerror + 1
390 vol1 = volice / max(volice+volwater,1d-10)
392 mtmp = get_m_mix(m_a, m_i, m_w, 0.0d0, vol1, vol2, &
393 mixingrule, matrix, inclusion,
error)
394 cumulerror = cumulerror +
error
396 if (hostmatrix .eq.
'air')
then
397 get_m_mix_nested = get_m_mix(m_a, mtmp, 2.0*m_a, &
398 volair, (1.0d0-volair), 0.0d0, mixingrule, &
399 hostmatrix, hostinclusion,
error)
400 cumulerror = cumulerror +
error
401 elseif (hostmatrix .eq.
'icewater')
then
402 get_m_mix_nested = get_m_mix(m_a, mtmp, 2.0*m_a, &
403 volair, (1.0d0-volair), 0.0d0, mixingrule, &
404 'ice', hostinclusion,
error)
405 cumulerror = cumulerror +
error
407 write(*,*)
'GET_M_MIX_NESTED: bad hostmatrix: ', &
409 cumulerror = cumulerror + 1
413 elseif (host .eq.
'ice')
then
415 if (matrix .eq.
'ice')
then
416 write(*,*)
'GET_M_MIX_NESTED: bad matrix: ', matrix
417 cumulerror = cumulerror + 1
419 vol1 = volair / max(volair+volwater,1d-10)
421 mtmp = get_m_mix(m_a, m_i, m_w, vol1, 0.0d0, vol2, &
422 mixingrule, matrix, inclusion,
error)
423 cumulerror = cumulerror +
error
425 if (hostmatrix .eq.
'ice')
then
426 get_m_mix_nested = get_m_mix(mtmp, m_i, 2.0*m_a, &
427 (1.0d0-volice), volice, 0.0d0, mixingrule, &
428 hostmatrix, hostinclusion,
error)
429 cumulerror = cumulerror +
error
430 elseif (hostmatrix .eq.
'airwater')
then
431 get_m_mix_nested = get_m_mix(mtmp, m_i, 2.0*m_a, &
432 (1.0d0-volice), volice, 0.0d0, mixingrule, &
433 'air', hostinclusion,
error)
434 cumulerror = cumulerror +
error
436 write(*,*)
'GET_M_MIX_NESTED: bad hostmatrix: ', &
438 cumulerror = cumulerror + 1
442 elseif (host .eq.
'water')
then
444 if (matrix .eq.
'water')
then
445 write(*,*)
'GET_M_MIX_NESTED: bad matrix: ', matrix
446 cumulerror = cumulerror + 1
448 vol1 = volair / max(volice+volair,1d-10)
450 mtmp = get_m_mix(m_a, m_i, m_w, vol1, vol2, 0.0d0, &
451 mixingrule, matrix, inclusion,
error)
452 cumulerror = cumulerror +
error
454 if (hostmatrix .eq.
'water')
then
455 get_m_mix_nested = get_m_mix(2*m_a, mtmp, m_w, &
456 0.0d0, (1.0d0-volwater), volwater, mixingrule, &
457 hostmatrix, hostinclusion,
error)
458 cumulerror = cumulerror +
error
459 elseif (hostmatrix .eq.
'airice')
then
460 get_m_mix_nested = get_m_mix(2*m_a, mtmp, m_w, &
461 0.0d0, (1.0d0-volwater), volwater, mixingrule, &
462 'ice', hostinclusion,
error)
463 cumulerror = cumulerror +
error
465 write(*,*)
'GET_M_MIX_NESTED: bad hostmatrix: ', &
467 cumulerror = cumulerror + 1
471 elseif (host .eq.
'none')
then
473 get_m_mix_nested = get_m_mix(m_a, m_i, m_w, &
474 volair, volice, volwater, mixingrule, &
475 matrix, inclusion,
error)
476 cumulerror = cumulerror +
error
479 write(*,*)
'GET_M_MIX_NESTED: unknown matrix: ', host
480 cumulerror = cumulerror + 1
483 IF (cumulerror .ne. 0)
THEN
484 write(*,*)
'GET_M_MIX_NESTED: error encountered'
485 get_m_mix_nested = cmplx(1.0d0,0.0d0)
492 COMPLEX*16 FUNCTION get_m_mix (m_a, m_i, m_w, volair, volice, &
493 volwater, mixingrule, matrix, inclusion, error)
497 DOUBLE PRECISION,
INTENT(in):: volice, volair, volwater
498 COMPLEX*16,
INTENT(in):: m_a, m_i, m_w
499 CHARACTER(len=*),
INTENT(in):: mixingrule, matrix, inclusion
500 INTEGER,
INTENT(out)::
error
503 get_m_mix = cmplx(1.0d0,0.0d0)
505 if (mixingrule .eq.
'maxwellgarnett')
then
506 if (matrix .eq.
'ice')
then
507 get_m_mix = m_complex_maxwellgarnett(volice, volair, volwater, &
508 m_i, m_a, m_w, inclusion,
error)
509 elseif (matrix .eq.
'water')
then
510 get_m_mix = m_complex_maxwellgarnett(volwater, volair, volice, &
511 m_w, m_a, m_i, inclusion,
error)
512 elseif (matrix .eq.
'air')
then
513 get_m_mix = m_complex_maxwellgarnett(volair, volwater, volice, &
514 m_a, m_w, m_i, inclusion,
error)
516 write(*,*)
'GET_M_MIX: unknown matrix: ', matrix
521 write(*,*)
'GET_M_MIX: unknown mixingrule: ', mixingrule
525 if (
error .ne. 0)
then
526 write(*,*)
'GET_M_MIX: error encountered'
533 COMPLEX*16 FUNCTION m_complex_maxwellgarnett(vol1, vol2, vol3, &
534 m1, m2, m3, inclusion, error)
538 COMPLEX*16 :: m1, m2, m3
539 DOUBLE PRECISION :: vol1, vol2, vol3
540 CHARACTER(len=*) :: inclusion
542 COMPLEX*16 :: beta2, beta3, m1t, m2t, m3t
543 INTEGER,
INTENT(out) ::
error
547 if (dabs(vol1+vol2+vol3-1.0d0) .gt. 1d-6)
then
548 write(*,*)
'M_COMPLEX_MAXWELLGARNETT: sum of the ', &
549 'partial volume fractions is not 1...ERROR'
550 m_complex_maxwellgarnett=cmplx(-999.99d0,-999.99d0)
559 if (inclusion .eq.
'spherical')
then
560 beta2 = 3.0d0*m1t/(m2t+2.0d0*m1t)
561 beta3 = 3.0d0*m1t/(m3t+2.0d0*m1t)
562 elseif (inclusion .eq.
'spheroidal')
then
563 beta2 = 2.0d0*m1t/(m2t-m1t) * (m2t/(m2t-m1t)*log(m2t/m1t)-1.0d0)
564 beta3 = 2.0d0*m1t/(m3t-m1t) * (m3t/(m3t-m1t)*log(m3t/m1t)-1.0d0)
566 write(*,*)
'M_COMPLEX_MAXWELLGARNETT: ', &
567 'unknown inclusion: ', inclusion
568 m_complex_maxwellgarnett=dcmplx(-999.99d0,-999.99d0)
573 m_complex_maxwellgarnett = &
574 sqrt(((1.0d0-vol2-vol3)*m1t + vol2*beta2*m2t + vol3*beta3*m3t) / &
575 (1.0d0-vol2-vol3+vol2*beta2+vol3*beta3))
subroutine error(parameters, swdown,fsa,fsr,fira,fsh,fcev, fgev,fctr,ssoil,beg_wb,canliq,canice, sneqv,wa,smc,dzsnso,prcp,ecan, etran,edir,runsrf,runsub,dt,nsoil, nsnow,ist,errwat, iloc,jloc,fveg, sav,sag,fsrv,fsrg,zwt,pah, ifdef ccpp
check surface energy balance and water balance.