;************************************************* ; tdpack_3.ncl ;************************************************ ; ; This file is loaded by default in NCL V6.2.0 and newer load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; ; Function for generating random data. ; function dsrnd1(ifrst,nextn) begin MPLIER = 16807 MODLUS = 2147483647 MOBYMP = 127773 MOMDMP = 2836 JSEED = 123456789 if (ifrst .eq. 0) then nextn = JSEED ifrst = 1 end if hvlue = nextn / MOBYMP lvlue = nextn % MOBYMP testv = MPLIER*lvlue - MOMDMP*hvlue if (testv .gt. 0) then nextn = testv else nextn = testv + MODLUS end if return((1.*nextn)/(1.*MODLUS)) end begin N = 1331 NEAREST = 500 MTRI = 150000 NFARTHER = N - NEAREST ; ; Create our input and work arrays. ; x = new(N,float) y = new(N,float) z = new(N,float) rtri = new((/MTRI,10/),float) rtwk = new((/2,MTRI/),float) ; ; Fill up the dummy input arrays. ; ifrst = 0 nextn = 0 do i = 0,N-1 x(i) = dsrnd1(ifrst,nextn) y(i) = dsrnd1(ifrst,nextn) z(i) = dsrnd1(ifrst,nextn) end do ; ; Specify the reference point from which we want to find the NEAREST ; nearest points. ; px = 0.5 py = 0.5 pz = 0.5 wks = gsn_open_wks("png","tdpack") ; send graphics to PNG file ; ; Set some TDPACK parameters and initialize. These four are viewport ; specifiers. ; tdsetp("VPB", 0.09) tdsetp("VPT", 0.99) tdsetp("VPL", 0.11) tdsetp("VPR", 1.00) tdinit((/4.6, 3.0, 3.3/), (/0.5, 0.5, 0.5/), (/0.5, 0.5, 2.7/), 0.) ; ; Set up some colors using the standard Tdpack entry for that. ; tdclrs(wks, 1, 0., 0.8, 8, 37, 8) ; ; Define style indices for shades of gray, green, and red. ; tdstrs(1, 8, 37, 8, 37, 1, 1, 0, 0.05, 0.05, 0.) tdstrs(3, 8, 37, 68, 97, 1, 1, 0, 0.05, 0.05, 0.) tdstrs(4, 8, 37, 98, 127, 1, 1, 0, 0.05, 0.05, 0.) ; ; Store the indices of the nearest points in npts and the complement ; of that set (with respect to the entire input dataset) in mpts. ; npts = new(NEAREST,integer) mpts = new(NFARTHER,integer) npts(0) = shgetnp(px,py,pz,x,y,z,0) do i=2,N if (i .le. NEAREST) then npts(i-1) = shgetnp(px,py,pz,x,y,z,1) else mpts(i-1-NEAREST) = shgetnp(px,py,pz,x,y,z,1) end if end do ; ; Plot the near points in green. ; ntri = 0 dotsize = 0.02 do i = 0, NEAREST-1 tdmtri(-5, (/x(npts(i)-1), y(npts(i)-1), z(npts(i)-1)/), dotsize, \ rtri, ntri, 4, (/0.,0.,0./),(/1.,1.,1./)) end do ; ; Plot the farther points in gray. ; do i = 0, NFARTHER-1 tdmtri(-5, (/x(mpts(i)), y(mpts(i)), z(mpts(i))/), dotsize, \ rtri, ntri, 1, (/0.,0.,0./),(/1.,1.,1./)) end do ; ; Mark the reference point in red. ; tdmtri(-5,(/px,py,pz/),1.2*dotsize,rtri,ntri,3,(/0.,0.,0./),(/1.,1.,1./)) ; ; Draw ; itwk = tdotri(rtri, ntri, rtwk, 0) tddtri(wks,rtri, ntri, itwk) ; ; Draw a box around the perimeter. ; tdgrds(wks,(/0., 1., 0./), (/1., 0., 1./), (/-1., -1., -1./),11,0) tdgrds(wks,(/0., 1., 0./), (/1., 0., 1./), (/-1., -1., -1./),11,1) frame(wks) end