Opened 8 years ago

Closed 8 years ago

#210 closed defect (fixed)

nbvmax value changes if interpolation succeeds at slowproc

Reported by: ajornet Owned by: somebody
Priority: major Milestone: orchidee_1_9_6
Component: Driver files Version: trunc
Keywords: nbvmax, slowproc Cc:

Description

nbvmax value changes when interpolation is done. As sub_index and sub_area are defined with this value. The use of nbvmax in loops might introduce some errors.

    ok_interpol = .FALSE.
    DO WHILE ( .NOT. ok_interpol )
       WRITE(numout,*) "Projection arrays for ",callsign," : "
       WRITE(numout,*) "nbvmax = ",nbvmax

       ALLOCATE(sub_index(nbpt, nbvmax,2), STAT=ALLOC_ERR)
       IF (ALLOC_ERR/=0) CALL ipslerr_p(3,'slowproc_update','Error in allocation for sub_index','','')

       sub_index(:,:,:)=0

       ALLOCATE(sub_area(nbpt, nbvmax), STAT=ALLOC_ERR)
       IF (ALLOC_ERR/=0) CALL ipslerr_p(3,'slowproc_update','Error in allocation for sub_area','','')
       sub_area(:,:)=zero

       CALL aggregate_p(nbpt, lalo, neighbours, resolution, contfrac, &
            &                iml, jml, lon_ful, lat_ful, mask, callsign, &
            &                nbvmax, sub_index, sub_area, ok_interpol)
       !
       IF ( .NOT. ok_interpol ) THEN
          DEALLOCATE(sub_area)
          DEALLOCATE(sub_index)
       ENDIF
       !
       nbvmax = nbvmax * 2
    ENDDO
  ...
    DO ib = 1, nbpt
          sumf=zero
          DO idi=1, nbvmax
             ! Leave the do loop if all sub areas are treated, sub_area <= 0
             IF ( sub_area(ib,idi) <= zero ) EXIT
             ip = sub_index(ib,idi,1)
             jp = sub_index(ib,idi,2)
             veget_next(ib,:) = veget_next(ib,:) + vegmap(ip,jp,:,1)*sub_area(ib,idi)
             sumf=sumf + sub_area(ib,idi)
          ENDDO
  ...

Regarding the code:

Interpolation succeeds so sub_area and sub_index are kept with the same size (eg 200). Even though nbvmax updates its value to 400.

The loop below uses nbvmax to read/write sub_index/sub_area. At some point it will start reading non valid positions in the array.
nbvmax

Change History (3)

comment:1 Changed 8 years ago by ajornet

Proposed solution at r3002. Basically move nbvmax inside

IF ( .NOT. ok_interpol ) THEN
    DEALLOCATE(sub_area)
    DEALLOCATE(sub_index)
ENDIF
!
nbvmax = nbvmax * 2

to

IF ( .NOT. ok_interpol ) THEN
    DEALLOCATE(sub_area)
    DEALLOCATE(sub_index)
    !
    nbvmax = nbvmax * 2
ENDIF

comment:2 Changed 8 years ago by maignan

There is also an occurrence in condveg.f90

comment:3 Changed 8 years ago by jgipsl

  • Resolution set to fixed
  • Status changed from new to closed

Done rev [3040]

Note: See TracTickets for help on using tickets.