edoddridge / aronnax

An idealised isopycnal model that can be run either with n+1/2 layers, or with n layers and variable bathymetry.
http://aronnax.readthedocs.io/en/latest/
MIT License
24 stars 6 forks source link

Compiling MIM with -fcheck=all detects an array bounds error #50

Closed axch closed 7 years ago

axch commented 7 years ago

To wit:

At line 588 of file MIM.f90
Fortran runtime error: Index '0' of dimension 1 of array 'dvdt_bt' below lower bound of 1

Widening the lower bound to 0 removes the warning (and has no visible effect on output), but now I am confused: dvdt_bt and dudt_bt seem to have asymmetric sizes, and also seem to be bigger than needed. To wit, looking at that the do loops where they are used, I would think that declaring them as dudt_bt(nx, 0:ny) and dvdt_bt(0:nx, ny) would suffice. (Running the test suite with -fcheck=all agrees.)

@edoddridge Is this just a typo or paste-o in the bounds? Or is something more subtle going on here?

General comments, in case this seems like a triviality:

edoddridge commented 7 years ago

I understand the issues with accessing memory that is out of the allocated region.

This is actually an issue with the loop bounds. The domain that the model actually solves goes from:

If you look at the wrap_fields subroutines you'll see that the value at i = 0 is set to the value at i = nx, and the value at i = nx+1 is set to the value at i = 1. This means there's no point wasting cycles having the loops start at 0.

I'll merge your pull requests and then deal with this.

axch commented 7 years ago

Actually, can you hold off on rearranging that for now? I have a half-done PR for #12, which will introduce conflicts with any changes to array bounds.

edoddridge commented 7 years ago

Sure thing. I'll wait for that to come through.