anchor.diff:    real(8), allocatable :: zlocmaster_(:,:),zvalmaster_(:,:)!temporary arrays for above when enlarging
     integer, allocatable :: zlocsizes(:) !size of zloc(:) held in zlocmaster(:,#)
     real(8), allocatable :: KLzeros(:) !zeros of realization
  -  real(8), allocatable :: KLzerosabs_(:,:),KLzerosscat_(:,:) !temporary arrays for increasing size
  +  real(8), allocatable :: KLzerosabs_(:,:),KLzerosscat_(:,:),KLzerostotn_(:,:) !temporary arrays for increasing size
   
     integer :: i, exi, imax, izer, exsize, izero
     logical, allocatable :: flextremamax(:), flextremapos(:)
  
positive.code:   deallocate(zloc)
    deallocate(zval)
  
  !print *,"zlocsizes:",zlocsizes
  !print *,"zlocmaster(1:zlocsizes(1),1):",zlocmaster(1:zlocsizes(1),1)
  !print *,"zvalmaster(1:zlocsizes(1),1):",zvalmaster(1:zlocsizes(1),1)
  !print *,"flfindzeros:",flfindzeros
    if(flfindzeros) then
      !search in each cell which contains a zero and find the zero
      allocate(KLzeros(KLrmaxnumzeros))
      izero = 1
  !print *,"KLrmaxnumzeros:",KLrmaxnumzeros
      do isec = 1,numslabsecs
        do ipt = 1,zlocsizes(isec)-1
          if(zvalmaster(ipt,isec)*zvalmaster(ipt+1,isec)<0) then
            !call zero finder and store
            !print *,"zvalmaster(ipt,isec),zvalmaster(ipt+1,isec):",zvalmaster(ipt,isec),zvalmaster(ipt+1,isec)
            !print *,"zlocmaster(ipt,isec),zlocmaster(ipt+1,isec):",zlocmaster(ipt,isec),zlocmaster(ipt+1,isec)
            KLzeros(izero) = KLr_findzeros(j,zlocmaster(ipt,isec),zlocmaster(ipt+1,isec), &
                                               zvalmaster(ipt,isec),zvalmaster(ipt+1,isec),chxstype,order=0) 
            izero = izero + 1
          endif
        enddo
      enddo
  !print *,"KLzeros(:):",KLzeros(:)
  !read *
      !store zeros in absorb module array
      if(chxstype .eq. 'absorb') then
        if(.not.allocated(KLzerosabs)) allocate(KLzerosabs(KLrmaxnumzeros,numRealz))
  
negative.code:     tsigscatave     = sigscatave
      tsigabsave      = sigabsave
    else
      tmeanadjust     = 0.0d0
      tsigsmeanadjust = 0.0d0
      tsigameanadjust = 0.0d0
      tsigave         = 0.0d0
      tsigscatave     = 0.0d0
      tsigabsave      = 0.0d0
    endif
  
    end subroutine KLr_setmeans
  