; ---------------------------------------------------------------------- ; Centroid to dip in the ppsum[] array to find more accurate offset value. ; function nsx_wpcent, pp, npp, ppsum ; Limits. ii1=pp-3 if (ii1 lt 0 ) then ii1=0 if (ii1 gt npp-1) then ii1=npp-1 ii2=pp+3 if (ii2 lt 0 ) then ii2=0 if (ii2 gt npp-1) then ii2=npp-1 ; Find base level (lower of two sides. hi1=0. for ii=long(ii1),pp do begin if (ppsum[ii] gt hi1) then hi1=ppsum[ii] endfor hi2=0. for ii=long(pp),ii2 do begin if (ppsum[ii] gt hi2) then hi2=ppsum[ii] endfor if (hi1 lt hi2) then base=hi1 else base=hi2 ; Limits. ii1=pp-1 if (ii1 lt 0 ) then ii1=0 if (ii1 gt npp-1) then ii1=npp-1 ii2=pp+1 if (ii2 lt 0 ) then ii2=0 if (ii2 gt npp-1) then ii2=npp-1 ; Centroid. */ sum=0. wsum=0. for ii=long(ii1),ii2 do begin wgt = base - ppsum[ii] if (wgt ge 0.) then begin sum = sum + ( wgt * double(ii) ) wsum= wsum+ wgt endif endfor if (wsum ge 0.) then cent = sum / wsum else cent=double(pp) return,cent end