TUgridReGrid TCL UTILITIES USER MANUAL TUgridReGrid
SYNOPSIS
Regrid or crop a grid
PACKAGE
TCLUTILS
NAME
TUgridReGrid
USAGE
set rV  [TUgridReGrid  Action iGrid igInfo oGrid ogInfo ogNorm {EndCmd}]
INPUT DEFINITIONS
Action - The action that the procedure should take
CUT - Cut a rectangular region from the input grid. The region by the X and Y grid extent given in ogInfo.
REGRID - Regrid the input grid int the grid defined by ogInfo.
iGrid - The input 2D data grid generated by a call to TUdataGrid.
igInfo - The grid information array for the input data grid.
oGrid - The CUT or REGRIDDED data grid
ogInfo - The grid information array for the CUT or REGRIDDED data grid.
ogNorm - The normalization grid associated with the CUT or REGRIDDED data grid.
EndCmd - Optional input. If set to the default value END then the regrid of the data is terminated with the END command which normalizes the grid according to ogNorm. Any other value and the output grid is not normalized.
RETURN DEFINITION
Returns 1 if no errors and -1 if Action was to CUT the grid and the region to cut defined in ogInfo is not contained in the input grid.
DESCRIPTION
TUgridReGrid regrids a 2D data grid. This can be accomplished in two ways; either by unpacking the input grid and then regridding it to the new specifications in ogInfo (REGRID) or building the new grid directly from the cells being regridded (CUT). While both methods can accomplish the same regridding there are subtle differences in the way that they work.
CUT is the more restrictive of the two methods. It uses the first four elements in ogInfo to define region in the input grid being regridded. (The remaining elements it either copies from the input gird discription array or recomputes internally.) The entire defined region must be contained in the input grid otherwise and error is generated. The procedure cuts the region out of the input grid and returns it as a new grid setting the both ogInfo(4) (the number of cells along the X direction) and ogInfo(5) (the number of cells along the Y direction) to reflect the size of the cut region.
REGRID disassembles the input grid and then reassembles it according to the gird information found in ogInfo. This allows the new grid to extend beyond the limits of the input grid. In addition if the new grid has a smaller cell size in the X and/or the Y directions than the parent grid then the new grid be undersampled meaning that there will be rows and/or columns in the new grid which are not filled. In this case it will be necessary to use a routine such as TUgridFill12 to fill the gaps.
ERRORS
None Generated
C BACKING
No
EXAMPLE(S)
EXAMPLE 1:Regrid examples.
# REGRID a grid containing a set of three Gaussians 

# SET up the grid information array for base grid.  

set gInfo(0) -6.0
set gInfo(1) 6.0
set gInfo(2) -6.0
set gInfo(3) 6.0
set gInfo(4) 100
set gInfo(5) 100
set gInfo(6) POINT
set gInfo(7) POINT
set gInfo(8) COLUMN
set gInfo(9) IGNORE
set gInfo(10) NEW:ADD:END
set gInfo(11) -1
set gInfo(12) -5
set gInfo(13) -1.0e30
set gInfo(14)  1.0e30
set gInfo(15)  NO
set gInfo(16)  NO

# GRID information for a CUT.  Only need the cut coordinates

set cgInfo(0) -6.0
set cgInfo(1) 0.0
set cgInfo(2) -3.0
set cgInfo(3) 3.0

# GRID information for a REGRID.  Change the initialization value for the
#   grid to -50.0

set rgInfo(0) -5.0
set rgInfo(1) 5.0
set rgInfo(2) -5.0
set rgInfo(3) 5.0
set rgInfo(4) 100
set rgInfo(5) 100
set rgInfo(6) POINT
set rgInfo(7) POINT
set rgInfo(8) COLUMN
set rgInfo(9) IGNORE
set rgInfo(10) NEW:ADD:END
set rgInfo(11) -50.0
set rgInfo(12) -5
set rgInfo(13) -1.0e30
set rgInfo(14)  1.0e30
set rgInfo(15)  NO
set rgInfo(16)  NO

# SET up a data set consisting of three Gaussians centered at (-3,-3),
#  (-3, 3) and at (3, 0).  Each has a different intensity.

set nP 0
set nG [expr $gInfo(4) * $gInfo(5)]
for { set I 0 } { $I < $nG } { incr I } {
   TUgridInfo 20 gInfo rV $I
   set X($nP) $rV(2)
   set Y($nP) $rV(3)
   set R [expr ($X($nP)-3.0) * ($X($nP)-3.0) + ($Y($nP)-3.0) * ($Y($nP)-3.0)]
   set A [expr exp(-$R / 6.0)]
   set R [expr ($X($nP)-3.0) * ($X($nP)-3.0) + ($Y($nP)+3.0) * ($Y($nP)+3.0)]
   set B [expr 3.0 * exp(-$R / 6.0)]
   set R [expr ($X($nP)+3.0) * ($X($nP)+3.0) + $Y($nP)*$Y($nP)]
   set C [expr 4.0 * exp(-$R / 6.0)]
   set V($nP) [expr $A + $B - $C ]
   incr nP
}

# GRID the base data set

TUdataGrid $nP 1 X X 1 Y Y V gV Norm gInfo

# CUT the data set from (-6, -3) to (0, 3)

TUgridReGrid CUT gV gInfo gCG cgInfo rNorM

# REGRID the data set from to run from (-5, -5) to (5, 5) keeping the
#   same number of cells

TUgridReGrid REGRID gV gInfo gRG rgInfo rNorM

# SET up the plot basics.  There are a total of 3 plots defined here.

set GphInfo(xScrL) 580
set GphInfo(yScrL) 600
GraphicsOn TK ETones SWAP

GenWindow 1 0.0 0.0 0.0 1.0 1.0 0.0  0. 0. 0. 1. 1. 0. XY
set WinInfo(2,corFmt) 1
RelWindow 2 1 217.0 350.0 0. 417. 550. 0. -6. -6. 0. 6. 6. 0.
DefinePlot 2 2 $gInfo(4) $gInfo(5)
set WinInfo(6,corFmt) 1
RelWindow 6 1 75.0 65.0 0. 275. 265. 0. -6. -3. 0. 0. 3. 0.
DefinePlot 6 6 $cgInfo(4) $cgInfo(5)
set WinInfo(7,corFmt) 1
RelWindow 7 1 350.0 65.0 0. 550. 265. 0. -5. -5. 0. 5. 5. 0.
DefinePlot 7 7 $rgInfo(4) $rgInfo(5)

# SET up the color map to run from -4.5 to 4.5

PLTcolorMap -4.1 4.1 LINEAR 0 cA

# PLOT the base grid on top

Plot3D 2 Xb Yb Dummy Dummy gV AUTO Dummy cA

# PLOT the grid cut in the lower left-hand plot

Plot3D 6 Xb Yb Dummy Dummy gCG AUTO Dummy cA

# PLOT the regrid in the lower right-hand plot

Plot3D 7 Xb Yb Dummy Dummy gRG AUTO Dummy cA

# THROW up the axis.  Annotate all plots since they have different ranges

PlotOutlines 2 [list "" 1.0 "" 1.0] [list BOT BOT BOTH BOTH]
PlotOutlines 6 [list "X" 1.0 "Y" 1.0] [list BOT BOT BOTH BOTH]
PlotOutlines 7 [list "" 1.0 "" 1.0] [list BOT BOT BOTH BOTH]

# LABEL the plots 

TextProp 12 HOLD HOLD
WinClip 2 0
TexT 2 0.0 6.50 0.0 center "ORIGINAL" $GphInfo(White)
WinClip 6 0
TexT 6 -3.0 3.40 0.0 center "CUT" $GphInfo(White)
WinClip 7 0
TexT 7 0.0 5.50 0.0 center "REGRID" $GphInfo(White)

update
      
Sept 22, 2006