k_clst = n_cnts -1 ; k_clst should always be less than the numnber of points to be clustered. print("n_cnts = " + n_cnts) printVarSummary(n_cnts) if (n_cnts.gt.1)then lat_y := new(n_cnts,float) lon_x := new(n_cnts,float) n_cnts = 0 print("dims_var = " + dims_var) do n = 0,dims_var-1 check = ismissing(var_zoom_1d(n)) if (check.eq.False) if (var_zoom_1d(n).ge.2)then lat_y(n_cnts) = lat_zoom_1d(n) lon_x(n_cnts) = lon_zoom_1d(n) n_cnts = n_cnts + 1 end if end if end do print("n_cnts = " + n_cnts) x := ((/lon_x,lat_y/)) printVarSummary(x) print("i_file = " + i_file) dimx = dimsizes(x) n = dimx(0) ; # variables (2) m = dimx(1) ; # observations (7) ; k = 5 ; # clusters opt = True opt@iter = 40 ; change the default max # iterations clcntr := kmeans_as136(x, k_clst, opt) print("x = " + x) print("clcntr = " + clcntr) k_found = False k_end = k_clst do k_c = 1,k_clst,1 k_end = k_clst-k_c if (k_found.eq.False)then clcntr := kmeans_as136(x, k_end, opt) points := clcntr@npts ; qsort(points) min_p =min(points) print("min_p = " + min_p) if (min_p.gt.0)then k_found = True kk_end =k_end end if end if end do print("points after = " + points) print(k_found) print(kk_end) k_clst_n = kk_end k_found = False min_points = min(clcntr@npts) print("min_points = "+ min_points) do k_c = 1,k_clst_n,1 k_end = k_clst_n-k_c print("k_end = " + k_end) if (k_end.ne.0)then if (k_found.eq.False)then clcntr := kmeans_as136(x, k_end, opt) points := clcntr@npts print("points 2nd = " + points) unique_values := get_unique_values(points) print("num_unique = " + unique_values) num_one = num(points.eq.min_points) print("num_one = " + num_one) ; print(xyz) if (num_one .eq. 1.and.k_found.eq.False)then k_found = True kk_end = k_end end if end if end if end do print("kk_end = " + kk_end) if (kk_end.eq.0)then kk_end = 1 end if k_clst_n = kk_end printVarSummary(clcntr) clcntr := kmeans_as136(x, k_clst_n, opt) print("clcntr@npts= " + clcntr@npts) print("clcntr@ss2 = " + clcntr@ss2) print("clcntr@id " + clcntr@id) print("clcntr before = " + clcntr) print("k_clst_n = " + k_clst_n) print("finished find") ; my adaptation to the clustering program dat := x printVarSummary(x) members := x print(x) print("k_clst_n = " + k_clst_n) m = dimsizes(lon_x); integer M, the number of points. n = 2 ; integer N, the number of spatial dimensions (aka, variables). k = k_clst_n iter = 40 ier = 1 ; not used ic1 := clcntr@id print("ic1 = " + ic1) nc := clcntr@npts print("nc = " + nc) wss := clcntr@ss2 print("wss = " + wss) ; members = new((/n,m/),float) iseed = 1 ; results in the center clusters being set to the first k sets of observations CLUSTER::kmns136_mine (dat, m, n, clcntr, k, ic1, nc ,iter, iseed, wss, members,ier) ; ic1 = ;the cluster to which each point is assigned. ; nc = ; the number of points in each cluster ; wss = ; the within-cluster sum of squares print("ic1 = " + ic1) print("nc = " + nc) print("wss = " + wss) print("clcntr after" + clcntr) print(members)