function WTREEHGT, stree,D,cost ;+ ;NAME: ; WTREEHGT ; ;PURPOSE: ; To measure the total height of a stat-tree. ; ;CATEGORY: ; Wavelets. ; ;CALLING SEQUENCE: ; maxheight = WTREEHGT(stree,D, cost) ; ;INPUTS: ; stree = stat tree (e.g. generated by WSTATREE) ; D = maximum depth of search ; ;OUTPUTS: ; maxheight = Height of the tree, assigning each branch ; a length equal to the entropy drop between parent and child ; cost = Tree of entropy drops associated with various splits ; ; ;NOTES: ; This is a utility used by WPLBTREE to set scale for plotting ; It is not intended for other use. ; ;EXAMPLE: ; ;SEE ALSO: ; wstatree, wplbtree ; ;MODIFICATION HISTORY: ; Written by: Amara Graps December 1994 ;Translated from MatLab Wavelab routine: calctreeheight.pro ;- cost = FLTARR(N_ELEMENTS(stree)) value = stree ; prune, bottom-up, left-right scan FOR dd=D-1, 0, -1 DO BEGIN FOR b=0, (2^dd-1) DO BEGIN vparent = stree(WNODE(dd,b)-1) vchild = value(WNODE(dd+1,2*b)-1) + value(WNODE(dd+1,2*b+1)-1) IF ((vparent LT vchild)) THEN BEGIN value(WNODE(dd,b)-1) = vparent cost(WNODE(dd,b)-1) = 0. END ELSE BEGIN value(WNODE(dd,b)-1) = vchild cost(WNODE(dd,b)-1) = vparent - vchild END ;else END ;b END ;dd height = cost * 0 ; prune, bottom-up, left-right scan FOR dd=D-1, 0, -1 DO BEGIN FOR b=0,(2^dd-1) DO BEGIN delta = cost(WNODE(dd,b)-1) IF (delta EQ 0) THEN BEGIN height(WNODE(dd,b)-1) = 0 END ELSE BEGIN height(WNODE(dd,b)-1) = delta + $ MAX([height(WNODE(dd+1,2*b)-1),height(WNODE(dd+1,2*b+1)-1)]) END ;else END ;b END ;dd maxheight = height(0) ; ; Algorithm Source: WaveLab Version 0.600 ; WaveLab WWW site: http://playfair.stanford.edu/ ; WaveLab Questions? e-mail wavelab@playfair.stanford.edu ; RETURN, maxheight END ;***************************************************