function WQUADLEN, x,J
;+
; NAME:
; 	WQUADLEN
;
; PURPOSE:
;	This function finds length and dyadic length of square matrix.
;
; CATEGORY:
;	Wavelets
;
; CALLING SEQUENCE:
;    n = WQUADLEN(x,J)
;
; INPUTS:
;    x:	2-d image; SIZE(n,n), n = 2^J (hopefully)
;
; OUTPUTS:
;    n:	N_ELEMENTS(x) of one of the sides of the image
;    J:	least power of two greater than n
;
; SIDE EFFECTS:
;    A warning is issued if n is not a power of 2,
;	or if x is not a square matrix
;
; EXAMPLE:
;
; SEE ALSO:
;	wdyadlng, wquad2ix
;
; MODIFICATION HISTORY:
; 	Written by:	Amara Graps		November 1994/September 1995
;Translated from MatLab Wavelab routine: quadlength.m
;-

ss = SIZE(x)

IF ss(0) EQ 1 THEN BEGIN
 	PRINT, 'Not a 2D matrix!'
ENDIF ELSE BEGIN
 	s = [ss(2), ss(1)]
 	;#rows = ss(2)
 	;#cols = ss(1)
END
 
n = s(1)

IF ( s(1) NE s(0)) THEN BEGIN
	  PRINT, 'Warning in WQUADLEN:  #rows  is not equal to #cols'
END

k = 1 
J = 0


WHILE ( k LT n ) DO BEGIN
 	 k=2*k
 	J = 1+J 
END 
 
IF ( k NE n ) THEN BEGIN
      PRINT, 'Warning in WQUADLEN:  n is not equal to  2^J'
END

;
; Algorithm Source:  WaveLab Version 0.600
; WaveLab WWW site: http://playfair.stanford.edu/ 
; WaveLab Questions? e-mail wavelab@playfair.stanford.edu
;   
    

RETURN, n 
END 
;***************************************************