Segmentation fault on logical variable in Fortran -
i'm trying run subroutine 'condensation' found here (http://mesonh.aero.obs-mip.fr/chaboureau/pub/ncl/), wrote 'main' program in order initialize arrays , call subroutine.
i did 'print' statements in 'condensation' subroutine find wrong, , found problem (segmentation fault error) occurs on every mention of logical variable 'luseri'.
but, don't know why.
in main program, wrote:
program main logical :: luseri ... luseri = .true. ... call condensation(...,luseri) end program main
('luseri' last argument in subroutine)
everything seems ok: variable declaration , assignment in main program, declaration in subroutine 'condensation' , mention.
here 'main' program (main_cst.f90) wrote:
program main_cst implicit none integer, parameter :: klon = 8 ! horizontal dimension integer, parameter :: klev = 28 ! vertical dimension integer, parameter :: kidia = 1 ! value of first point in x; default=1 integer, parameter :: kfdia = 8 ! value of last point in x; default=klon integer, parameter :: kbdia = 1 ! vert. comp. start @ kbdia @ least 1 integer, parameter :: ktdia = 1 ! vert. comp. can limited klev + 1 - ktdia ! default=1 logical :: luseri ! logical switch compute both liquid ! , solid condensate (luseri=.true.) ! or liquid condensate (luseri=.false.) real, dimension(klon,klev) :: ppabs ! pressure (pa) real, dimension(klon,klev) :: pzz ! height of model levels (m) real, dimension(klon,klev) :: pt ! grid scale t (k) real, dimension(klon,klev) :: prv ! grid scale water vapor mixing ratio (kg/kg) real, dimension(klon,klev) :: pmflx ! convective mass flux (kg/(s m^2)) real, dimension(klon,klev) :: prc ! grid scale r_c mixing ratio (kg/kg) real, dimension(klon,klev) :: pri ! grid scale r_i (kg/kg) integer :: kx ! horizontal loop counter kx = kidia, kfdia ppabs(kx,:)=(/1000, 975, 950, 925, 900, 875, 850, 825, 800, 775, 750, 725, 700, & 675, 650, 600, 500, 300, 250, 200, 150, 100, 70, 50, 30, 20, 10, 3/) pzz(kx,:)=(/111.31, 333.80, 561.25, 794.10, 1032.35, 1276.02, 1525.42, & 1780.62, 2041.78, 2309.21, 2583.33, 2864.61, 3153.70, 3451.53, & 3758.06, 4397.20, 5770.03, 9485.69, 10710.62, 12141.42, 13897.52, & 16283.89, 18361.25, 20367.34, 23523.77, 26158.47, 30748.48, 38877.28/) pt(kx,:)=(/300.81, 299.97, 299.63, 298.31, 296.93, 295.81, 294.07, 292.04, & 290.02, 287.85, 285.50, 283.34, 281.39, 279.55, 278.16, 275.40, & 267.42, 239.07, 229.57, 219.98, 208.53, 197.10, 193.60, 200.84, & 213.77, 221.35, 230.21, 231.10/) prv(kx,:)=(/0.012570000, 0.012460000, 0.011830000, 0.011390000, 0.010560000, & 0.009922000, 0.009529000, 0.009226000, 0.009008000, 0.008739000, & 0.008411000, 0.007836000, 0.007077000, 0.006153000, 0.004703000, & 0.002451000, 0.000774100, 0.000107400, 0.000056510, 0.000031610, & 0.000008088, 0.000004136, 0.000002686, 0.000002901, 0.000003876, & 0.000004562, 0.000004388, 0.000007886/) end pmflx(:,:) = 0.0 prc(:,:) = 0.0 pri(:,:) = 0.0 luseri = .true. call condensation(klon, klev, kidia, kfdia, kbdia, ktdia, ppabs, pzz, pt, prv, & pmflx, prc, pri, luseri) end program main_cst
the condensation subroutine (condensation.f90) can found @ http://mesonh.aero.obs-mip.fr/chaboureau/pub/ncl/:
! ######spl subroutine condensation( klon, klev, kidia, kfdia, kbdia, ktdia, & ppabs, pzz, pt, prv, prc, pri, pmflx, pcldfr, luseri ) ! ############################################################################ ! !! !! purpose !! ------- !!** routine diagnose cloud fraction , liquid , ice condensate mixing ratios !! !! !!** method !! ------ !! based on large-scale fields of temperature, water vapor, , possibly !! liquid , solid condensate, conserved quantities r_t , h_l constructed !! , fractional cloudiness, liquid , solid condensate diagnosed. !! !! total variance parameterized sum of stratiform/turbulent variance !! , convective variance. !! turbulent variance parameterized function of first-order moments, , !! convective variance modelled function of convective mass flux (units kg/s m^2) !! provided mass flux convection scheme. !! !! nota: if host model not use prognostic values liquid , solid condensate !! or not provide convective mass flux, put these values zero. !! also, supposed vertical model levels numbered !! 1 klev, 1 first model level above surface !! !! !! !! external !! -------- !! ini_cst !! !! implicit arguments !! ------------------ !! module modd_cst : contains physical constants !! !! reference !! --------- !! chaboureau j.p. , p. bechtold (j. atmos. sci. 2002) !! !! author !! ------ !! p. bechtold * laboratoire d'aerologie * !! !! modifications !! ------------- !! original 13/06/2001 !! modified 20/03/2002 : add convective sigma_s , improve turbulent !! length-scale in boundary-layer , near tropopause !! !------------------------------------------------------------------------------- ! !* 0. declarations ! ------------ ! use modd_cst ! implicit none ! !* 0.1 declarations of dummy arguments : ! ! integer, intent(in) :: klon ! horizontal dimension integer, intent(in) :: klev ! vertical dimension integer, intent(in) :: kidia ! value of first point in x ! default=1 integer, intent(in) :: kfdia ! value of last point in x ! default=klon integer, intent(in) :: kbdia ! vertical computations start @ ! ! kbdia @ least 1 integer, intent(in) :: ktdia ! vertical computations can ! limited klev + 1 - ktdia ! default=1 real, dimension(klon,klev), intent(in) :: ppabs ! pressure (pa) real, dimension(klon,klev), intent(in) :: pzz ! height of model levels (m) real, dimension(klon,klev), intent(in) :: pt ! grid scale t (k) real, dimension(klon,klev), intent(in) :: prv ! grid scale water vapor mixing ratio (kg/kg) logical :: luseri ! logical switch compute both ! liquid , solid condensate (luseri=.true.) ! or liquid condensate (luseri=.false.) real, dimension(klon,klev), intent(in) :: pmflx ! convective mass flux (kg/(s m^2)) real, dimension(klon,klev), intent(inout) :: prc ! grid scale r_c mixing ratio (kg/kg) real, dimension(klon,klev), intent(inout) :: pri ! grid scale r_i (kg/kg) real, dimension(klon,klev), intent(out) :: pcldfr ! fractional cloudiness (between 0 , 1) ! ! !* 0.2 declarations of local variables : ! integer :: ji, jk, jkt, jkp, jkm ! loop index real, dimension(klon,klev) :: ztlk, zrt ! work arrays t_l, r_t real, dimension(klon,klev) :: zl ! length-scale integer, dimension(klon) :: itpl ! top levels of tropopause/highest inversion real, dimension(klon) :: ztmin ! min temp. related itpl ! real :: ztemp, zlv, zls, ztl, zpv, zqsl, zpiv, zqsi, zfrac, zcond, zcpd ! thermodynamics real :: zll, dzz, zzz ! length scales real :: zah, za, zb, zsbar, zq1, zsigma, zdrw, zdtl ! related computation of sig_s real :: zsig_conv ! convective part of sig_s ! !* 0.3 definition of constants : ! !------------------------------------------------------------------------------- ! real :: zl0 = 600. ! tropospheric length scale ! changed 600 m instead of 900 m give consistent ! value (linear increase) in general 500 m deep oceanic ! mixed layer - put 900 m if wished real :: zcsigma = 0.2 ! constant in sigma_s parameterization real :: zcsig_conv = 0.30e-2 ! scaling factor zsig_conv function of mass flux ! !------------------------------------------------------------------------------- ! call ini_cst ! initialize thermodynamic constants in module modd_cst pcldfr(:,:) = 0. ! initialize values jkt = klev+1-ktdia jk=kbdia,jkt ji=kidia,kfdia ztemp = pt(ji,jk) !latent heat of vaporisation/sublimation zlv = xlvtt + ( xcpv - xcl ) * ( ztemp - xtt ) zls = xlstt + ( xcpv - xci ) * ( ztemp - xtt ) !store temperature @ saturation , total water mixing ratio zrt(ji,jk) = prv(ji,jk) + prc(ji,jk) + pri(ji,jk) zcpd = xcpd + zrt(ji,jk) * xcpv ztlk(ji,jk) = ztemp - zlv*prc(ji,jk)/zcpd - zls*pri(ji,jk)/zcpd end end !------------------------------------------------------------------------------- ! determine tropopause/inversion height minimum temperature itpl(:) = kbdia+1 ztmin(:) = 400. jk = kbdia+1,jkt-1 ji=kidia,kfdia if ( pt(ji,jk) < ztmin(ji) ) ztmin(ji) = pt(ji,jk) itpl(ji) = jk end if end end ! set mixing length scale - used computing "turbulent part" of sigma_s zl(:,kbdia) = 20. jk = kbdia+1,jkt ji=kidia,kfdia ! free troposphere zl(ji,jk) = zl0 jkp = itpl(ji) zzz = pzz(ji,jk) - pzz(ji,kbdia) ! approximate length boundary-layer : linear increase if ( zl0 > zzz ) zl(ji,jk) = zzz ! gradual decrease of length-scale near , above tropopause/top inversion if ( zzz > 0.9*(pzz(ji,jkp)-pzz(ji,kbdia)) ) & zl(ji,jk) = .6 * zl(ji,jk-1) end end !------------------------------------------------------------------------------- jk=kbdia+1,jkt-1 jkp=jk+1 jkm=jk-1 ji=kidia,kfdia ztemp = pt(ji,jk) !latent heat of vaporisation/sublimation zlv = xlvtt + ( xcpv - xcl ) * ( ztemp - xtt ) zls = xlstt + ( xcpv - xci ) * ( ztemp - xtt ) zcpd = xcpd + zrt(ji,jk) * xcpv !temperature @ saturation ztl = ztemp - zlv*prc(ji,jk)/zcpd - zls*pri(ji,jk)/zcpd !saturated water vapor mixing ratio on liquid water zpv = exp( xalpw - xbetaw / ztl - xgamw * log( ztl ) ) zqsl = xrd / xrv * zpv / ( ppabs(ji,jk) - zpv ) !saturated water vapor mixing ratio on ice zpiv = exp( xalpi - xbetai / ztl - xgami * log( ztl ) ) zqsi = xrd / xrv * zpiv / ( ppabs(ji,jk) - zpiv ) !interpolate between liquid , solid function of temperature ! glaciation interval specified here 20 k zfrac = ( ztl - 250.16 ) / ( xtt - 250.16 ) ! liquid/solid fraction zfrac = max( 0., min(1., zfrac ) ) zfrac = zfrac * zfrac if(.not. luseri) zfrac=1. zqsl = ( 1. - zfrac ) * zqsi + zfrac * zqsl zlv = ( 1. - zfrac ) * zls + zfrac * zlv !coefficients , b zah = zlv * zqsl / ( xrv * ztl**2 ) za = 1. / ( 1. + zlv/zcpd * zah ) zb = zah * za !parameterize sigma_s first_order closure dzz = pzz(ji,jkp) - pzz(ji,jkm) zdrw = zrt(ji,jkp) - zrt(ji,jkm) zdtl = ztlk(ji,jkp) - ztlk(ji,jkm) + xg/zcpd * dzz zll = zl(ji,jk) zsig_conv = zcsig_conv * pmflx(ji,jk) / za ! standard deviation due convection zsigma = sqrt( max( 1.e-25, zcsigma*zcsigma* zll*zll/(dzz*dzz) * ( & za*za*zdrw*zdrw - 2.*za*zb*zdrw*zdtl + zb*zb*zdtl*zdtl ) & + zsig_conv * zsig_conv ) ) !zsigma should of order 4.e-4 in lowest 5 km of atmosphere zsigma = max( zsigma, 1.e-12 ) !normalized saturation deficit zsbar = za * ( zrt(ji,jk) - zqsl ) zq1 = zsbar / zsigma !cloud fraction pcldfr(ji,jk) = max( 0., min(1.,0.5+0.36*atan(1.55*zq1)) ) !total condensate if (zq1 > 0. .and. zq1 <= 2. ) zcond = exp(-1.)+.66*zq1+.086*zq1*zq1 else if (zq1 > 2.) zcond = zq1 else zcond = exp( 1.2*zq1-1 ) end if zcond = zcond * zsigma if ( zcond<1.e-6) zcond = 0. pcldfr(ji,jk) = 0. end if prc(ji,jk) = zfrac * zcond ! liquid condensate if (luseri) pri(ji,jk) = (1.-zfrac) * zcond ! solid condensate end if ! compute s'rl'/sigs^2 ! used in w'rl'= w's' * s'rl'/sigs^2 ! psigrc(ji,jk) = pcldfr(ji,jk) ! gaussian relation end end ! end subroutine condensation
there 2 more files, found @ http://mesonh.aero.obs-mip.fr/chaboureau/pub/ncl/.
ini_cst.f90:
! ######spl subroutine ini_cst ! ################## ! !!**** *ini_cst * - routine initialize constants modules !! !! purpose !! ------- ! purpose of routine initialize constants ! stored in modules modd_cst ! ! !!** method !! ------ !! thermodynamic constants set numerical values !! !! !! external !! -------- !! !! implicit arguments !! ------------------ !! module modd_cst : contains physical constants !! !! reference !! --------- !! chaboureau j.p. , p. bechtold (j. atmos. sci. 2002) !! !! !! author !! ------ !! p. bechtold * laboratoire d'aerologie * !! !! modifications !! ------------- !! original 13/06/2001 !! modified 20/03/2002 : add convective sigma_s , improve turbulent !! length-scale in boundary-layer , near tropopause !------------------------------------------------------------------------------- ! !* 0. declarations ! ------------ ! use modd_cst ! implicit none ! !------------------------------------------------------------------------------- ! !* 1. set fundamental thermodynamical constants ! these have same values (not names) in arpege ifs ! ------------------------------------------------------- ! ! xp00 = 1.e5 ! reference pressure xpi = 3.141592654 ! pi xg = 9.80665 ! gravity constant xmd = 28.9644e-3 ! molecular weight of dry air xmv = 18.0153e-3 ! molecular weight of water vapor xrd = 287.05967 ! gaz constant dry air xrv = 461.524993 ! gaz constant water vapor xcpd = 1004.708845 ! specific heat of dry air xcpv = 1846.1 ! specific heat of water vapor xrholw = 1000. ! density of liquid water xcl = 4218. ! specific heat of liquid water xci = 2106. ! specific heat of ice xtt = 273.16 ! triple point temperature xlvtt = 2.5008e6 ! latent heat of vaporisation @ xtt xlstt = 2.8345e6 ! latent heat of sublimation @ xtt xlmtt = 0.3337e6 ! latent heat of melting @ xtt xestt = 611.14 ! saturation pressure @ xtt xalpw = 60.22416 ! constants in saturation pressure on liquid water xbetaw = 6822.459384 xgamw = 5.13948 xalpi = 32.62116 ! constants in saturation pressure on ice xbetai = 6295.421 xgami = 0.56313 ! ! end subroutine ini_cst ! ######spl module modd_cst ! ############### ! implicit none ! real, save :: xp00 ! reference pressure real, save :: xpi ! pi real, save :: xg ! gravity constant real, save :: xmd ! molecular weight of dry air real, save :: xmv ! molecular weight of water vapor real, save :: xrd ! gaz constant dry air real, save :: xrv ! gaz constant water vapor real, save :: xcpd ! specific heat of dry air real, save :: xcpv ! specific heat of water vapor real, save :: xrholw ! density of liquid water real, save :: xcl ! specific heat of liquid water real, save :: xci ! specific heat of ice real, save :: xtt ! triple point temperature real, save :: xlvtt ! latent heat of vaporisation @ xtt real, save :: xlstt ! latent heat of sublimation @ xtt real, save :: xlmtt ! latent heat of melting @ xtt real, save :: xestt ! saturation pressure @ xtt real, save :: xalpw ! constants in saturation pressure on liquid water real, save :: xbetaw real, save :: xgamw real, save :: xalpi ! constants in saturation pressure on ice real, save :: xbetai real, save :: xgami ! end module modd_cst
modd_cst.f90:
! ######spl module modd_cst ! ############### ! implicit none ! real, save :: xp00 ! reference pressure real, save :: xpi ! pi real, save :: xg ! gravity constant real, save :: xmd ! molecular weight of dry air real, save :: xmv ! molecular weight of water vapor real, save :: xrd ! gaz constant dry air real, save :: xrv ! gaz constant water vapor real, save :: xcpd ! specific heat of dry air real, save :: xcpv ! specific heat of water vapor real, save :: xrholw ! density of liquid water real, save :: xcl ! specific heat of liquid water real, save :: xci ! specific heat of ice real, save :: xtt ! triple point temperature real, save :: xlvtt ! latent heat of vaporisation @ xtt real, save :: xlstt ! latent heat of sublimation @ xtt real, save :: xlmtt ! latent heat of melting @ xtt real, save :: xestt ! saturation pressure @ xtt real, save :: xalpw ! constants in saturation pressure on liquid water real, save :: xbetaw real, save :: xgamw real, save :: xalpi ! constants in saturation pressure on ice real, save :: xbetai real, save :: xgami ! end module modd_cst
this code i'm working with.
i use command compile:
g95 modd_cst.f90 ini_cst.f90 condensation.f90 main_cst.f90 -o cst.g95
you seem have mismatch between put in call , subroutine gets
call condensation(klon, klev, kidia, kfdia, kbdia, ktdia, ppabs, pzz, pt, prv, pmflx, prc, pri, luseri)
and subroutine wants
subroutine condensation( klon, klev, kidia, kfdia, kbdia, ktdia, & ppabs, pzz, pt, prv, prc, pri, pmflx, pcldfr, luseri )
so in call prv pmflx prc pri in subroutine prv prc pri pmflx. furthermore missing 1 variable pass subroutine. fortran sensitive order of variables pass on. without checking rest of code assume should solve problem.
Comments
Post a Comment