load "$NCARGTEST/nclscripts/functions.ncl" begin ;---Test with 1D float and int arrays npts = 100 xf = random_uniform(-100,100,npts) xi = toint(xf) cf_out = count_unique_values(xf) ci_out = count_unique_values(xi) cf = dim_count_unique_values_n(xf,0) ci = dim_count_unique_values_n(xi,0) ;---Should all be True print(all(cf.eq.cf_out)) print(all(ci.eq.ci_out)) ;---Test with nD float and int arrays dims = (/5,3,4,npts/) xfm = random_uniform(-100,100,dims) xim = toint(random_uniform(-100,100,dims)) ;---Kludgy way to compute the # of unique values by hand cfm_out = new((/5,3,4/),integer) cim_out = new((/5,3,4/),integer) do i=0,4 do j=0,2 do k=0,3 cfm_out(i,j,k) = count_unique_values(xfm(i,j,k,:)) cim_out(i,j,k) = count_unique_values(xim(i,j,k,:)) end do end do end do cfm = dim_count_unique_values_n(xfm,3) cim = dim_count_unique_values_n(xim,3) ;---Should all be True print(all(cfm.eq.cfm_out)) print(all(cim.eq.cim_out)) ;---Test with nD float and int arrays rearranged dims = (/5,npts,3,4/) xfm := random_uniform(-100,100,dims) xim := toint(random_uniform(-100,100,dims)) ;---Kludgy way to compute the # of unique values by hand cfm_out := new((/5,3,4/),integer) cim_out := new((/5,3,4/),integer) do i=0,4 do j=0,2 do k=0,3 cfm_out(i,j,k) = count_unique_values(xfm(i,:,j,k)) cim_out(i,j,k) = count_unique_values(xim(i,:,j,k)) end do end do end do cfm = dim_count_unique_values_n(xfm,1) cim = dim_count_unique_values_n(xim,1) ;---Should all be True print(all(cfm.eq.cfm_out)) print(all(cim.eq.cim_out)) ;---Test with "npts" as leftmost dimension dims = (/npts,5,3,4/) xfm := random_uniform(-100,100,dims) xim := toint(random_uniform(-100,100,dims)) ;---Kludgy way to compute the # of unique values by hand cfm_out := new((/5,3,4/),integer) cim_out := new((/5,3,4/),integer) do i=0,4 do j=0,2 do k=0,3 cfm_out(i,j,k) = count_unique_values(xfm(:,i,j,k)) cim_out(i,j,k) = count_unique_values(xim(:,i,j,k)) end do end do end do cfm = dim_count_unique_values_n(xfm,0) cim = dim_count_unique_values_n(xim,0) ;---Should all be True print(all(cfm.eq.cfm_out)) print(all(cim.eq.cim_out)) end