Subscript out of range for array a (extract_obs.f90)

Bug reports, work arounds and fixes

Moderators: arango, robertson

Post Reply
Message
Author
jpm
Posts: 21
Joined: Thu Aug 27, 2009 4:37 pm
Location: UCSC

Subscript out of range for array a (extract_obs.f90)

#1 Unread post by jpm »

There is a bug in the 4DVAR code when dealing with observations that have an obs_depth in between 0 and 1. I kept running into problems (negative Ritz values) with a particular model run until I switched on the debug mode which told me about an out of range subscript.

The problem occurs in extract_obs.F and ad_extract_obs.F:
line 358 in extract_obs.F and following (some comments added by me):

Code: Select all

          IF (Zobs(iobs).gt.0.0_r8) THEN
            k1=INT(Zobs(iobs))     ! k1 can become 0
            k2=MIN(k1+1,N(ng))                
            r2=REAL(k2-k1,r8)*(Zobs(iobs)-REAL(k1,r8))
            r1=1.0_r8-r2
          ELSE
            !...
          END IF
          ! ... no changes to k1
          IF ((r1+r2).gt.0.0_r8) THEN
            ! ... no changes to k1
            Aobs(iobs)=Hmat(1)*A(i1,j1,k1)+                             & ! k1 is used as an index here and A's 3rd dimension starts at 1
     &                 Hmat(2)*A(i2,j1,k1)+                             &
     &                 Hmat(3)*A(i2,j2,k1)+                             &
     &                 Hmat(4)*A(i1,j2,k1)+                             &
     &                 Hmat(5)*A(i1,j1,k2)+                             &
     &                 Hmat(6)*A(i2,j1,k2)+                             &
     &                 Hmat(7)*A(i2,j2,k2)+                             &
     &                 Hmat(8)*A(i1,j2,k2)
Accessing A(i1,j1,k1) with k1=0 was the problem for me. To quote the error message:
0: Subscript out of range for array a (extract_obs.f90: 362)
subscript=0, lower bound=1, upper bound=42, dimension=3
I fixed it replacing lines 359 and 360 by:

Code: Select all

            k1=MAX(INT(Zobs(iobs)),1)          ! Positions in fractional
            k2=MIN(INT(Zobs(iobs))+1,N(ng))    ! levels
Which causes an extrapolation analogous to obs_depth > N.

The same patch needs to be applied to ad_extract_obs.F.
Jann Paul Mattern, Ocean Sciences Department, UCSC

User avatar
arango
Site Admin
Posts: 1367
Joined: Wed Feb 26, 2003 4:41 pm
Location: DMCS, Rutgers University
Contact:

Re: Subscript out of range for array a (extract_obs.f90)

#2 Unread post by arango »

This is usually a problem of how the observations are processed. However, it is wise to add this constraint to extract_obs.F and ad_extract_obs.F. Thank you for bringing this to my attention.

Post Reply