Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base profile initialization fails with ibas_prf=3 and zf(k) = 11000 #41

Closed
fjansson opened this issue May 7, 2019 · 1 comment
Closed

Comments

@fjansson
Copy link
Contributor

fjansson commented May 7, 2019

Running DALES with ibas_prf=3 (the default) causes undefined behaviour (often a thermo crash) if the model has a vertical level at exactly 11000 m.

modstartup.f90, line 1305, initializing the rhobf profile when ibas_prf = 3

 real,dimension(4) :: zmat=(/11000.,20000.,32000.,47000./)
 real,dimension(4) :: lapserate=(/-6.5/1000.,0.,1./1000,2.8/1000/)

...

 do k=1,k1
          if(zf(k)<zmat(1)) then
            pb(k)=exp((log(ps)*lapserate(1)*rd+log(tsurf+zsurf*lapserate(1))*grav-&
              log(tsurf+zf(k)*lapserate(1))*grav)/(lapserate(1)*rd))
            tb(k)=tsurf+lapserate(1)*(zf(k)-zsurf)
          else
            j=1
            do while(zf(k)>zmat(j))   !! bug here, ">" should be ">="
              j=j+1
            end do
            tb(k)=tmat(j-1)+lapserate(j)*(zf(k)-zmat(j-1))

This code uses a table of temperature lapse rates lapserate(j) in different height intervals given by zmat(j) The problem occurs if any height level zf(k) equals zmat(1), which is defined as 11000. Then the else clause is run, the while loop is not executed, and j=1, which makes the final line access tmat(0) and zmat(0), which are undefined.

Fix: change the > sign in while() to >= , this ensures that after the while loop j is at least 2.

fjansson added a commit that referenced this issue Jun 13, 2019
@fjansson
Copy link
Contributor Author

Fixed in branch to4.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant