Grid File Utilities

This command is used to modify and create grid files. The modifications can be done manually on a single grid, on multiple grids in a batch mode or saved and rerun using the grid macros created with the macro editor. To modify manually, start by picking the Select Grid(s) button. There is an option to use inclusion and exclusion polylines to only modify the grid within/outside these perimeters. With this option active, the program will prompt for inclusion and exclusion polylines when a function is selected. Only grid cells inside the inclusion polylines will be modified. Grid cells inside the exclusion polylines will not be modified. If no inclusion and exclusion polylines are selected, then the entire grid will be modified. Each function is described below.

-------------------------

            If GridA < compare_value then GridA =assign_value, otherwise no change
            If GridA < compare_GridB then GridA = GridC, otherwise no change
            If GridA > compare_value then GridA =assign_value, otherwise no change
            If GridA > compare_GridB then GridA = GridC, otherwise no change
Export to DTM writes the current grid file to a DTM format text file. The format of this file is the following:

DTM 1.0         Header Line
test.dtm             Name of file
51                     Number of cells in X direction
51                     Number of cells in Y direction
79442.4697      Lower left grid corner Y coordinate
14899.0326       Lower left grid corner X coordinate
0.0                    Lower left grid corner Z coordinate
11.5618             Dimension of cell in X direction
7.0639               Dimension of cell in Y direction
1581.2612         Grid cell values starting from lower left, moving from left to right
1580.8879
1580.3257
etc...
Import from Text File (X, Y, Z) creates a grid file from X Y Z data in any text file. There does not need to be a current grid file loaded since this routine will create a grid file. The text file should consist of one X Y Z coordinate per row with the first coordinate being the lower left grid corner and the last coordinate as the upper right grid corner. There are options for space or comma separated coordinates and for the order of the coordinates as either row (left to right) or column (bottom to top). The prompting will be as follows:
Separation type [<Space>/Comma/FixedWidth]?
Column number for X coordinate <1>:
Column number for Y coordinate <2>:
Column number for Z value <3>:

Import from Triangulation prompts user to select a tin or flt file and allows user to adjust grid position and resolution. The grid file is created with the same name in the same directory as selected tin/flt file.Import DEM/ESRI prompts user to select a dem, adf or ASCII ESRI grid file to be imported. The ESRI grid files can be created from ArcMap using the Raster To ASCII tool. If the file format is recognized program reads and displays the information about source projection and allows user to define target projection for transforming the grid to local coordinate system. Skip every # rows/cols allows user to reduce the size of the imported grid file. The grid file is created with the same name in the same directory as selected dem file.
Import Mintec
allows user to import Mintec GSM Model Dump as grd files. User is prompted to select GSM Model Dump (txt) file, which is then processed to determine minimum northing, easting (lower left corner), resolution and size of the grid. First three columns of the GSM model dump must represent the X, Y and SEAM LEVEL respectively, a base name for the grid files is specified along with name of the quality that each column represents. User can define up to 17 qualities. When the import button is pressed all the imported grids are created with the name "BASE NAME-SEAM LEVEL-BASE ITEM.grd" in the same directory as source dump file.Import Surfer prompts to select a grd file from Surfer program and creates a grd file.

Macro Editor: The Macro Command Recorder allows you to store the grid modification steps to a (.GFU) file. The new or existing GFU file needs to be selected at the beginning of the command.

When adding a step that involves another grid file, there are three options for storing this grid into the script. Use Grid Variable will use the grid assigned to the Grid Variable Name. Prompt for Grid File Name will bring up a grid file selection dialog each time the macro is run. Store the Grid File Name will save the specific grid file name into the macro. Each function added will appear in the macro text window. Additional explanation of the proper syntax is shown below in the GFU Macro File Details section.

Surface Macro Launcher Details
The Surface Macro Launcher displays the GFU in the upper menu bar. This is an editor, and you can use basic functions like CTRL-X, CTRL-C & CTRL-V for cut, copy & paste. If there are any errors in the GFU during its execution, they will be displayed in the error log section. The Values Drilldown is a good method for error checking on the macro. Use the Pick button to select a spot in plan view to fill in the Northing and Easting boxes. Then when the GFU is executed, the results of each line will be displayed. The Verbose Output will show the value of each line L1, L2, etc., instead of overwriting the variable each time it is encountered. GFU files also can be edited easily in any text editor, such as Notepad, WordPad or K-Edit.







Submacro in the same macro that calls it. There are two submacros defined at the top, and then they are both called at the bottom, THICK2 and THICK.

SUBMACRO THICK()
A1=LOADFROM($PROJECTPATH\one.grd)
B1=LOADFROM($PROJECTPATH\two.grd)
C1=A1+B1;
SAVEAS(C1,$PROJECTPATH\three.grd)
END SUBMACRO
;---------------------------------------------
SUBMACRO THICK2(A,B,D)
C=A+B;
SAVEAS(C,D);
END SUBMACRO
;---------------------------------------------
A1=LOADFROM($PROJECTPATH\one.grd);
B1=LOADFROM($PROJECTPATH\two.grd);
THICK2(a1,B1,$PROJECTPATH\three_b.grd);
THICK()
---------------------------------------------------------------------------------

Submacro in a different macro that calls it. The first step is to define the submacros in their own gfu, this one contains THICK and THICK2 and is saved as mymacros.gfu.
SUBMACRO THICK()
A1=LOADFROM(C:\downloads\one.grd);
B1=LOADFROM(C:\downloads\two.grd);
C1=A1+B1;
SAVEAS(C1,C:\downloads\three.grd);
END SUBMACRO;
;--------------------------------------
SUBMACRO THICK2(A,B,D)
C=A+B;
SAVEAS(C,D);
END SUBMACRO;
---------------------------------------------------------------------------------

INCLUDE: To include a previously defined macro in another macro, the INCLUDE function is used. Once mymacros.gfu is created, then it can be loaded (with INCLUDE) and referenced in another, separate GFU macro.

INCLUDE($PROJECTPATH\mymacros.gfu);

A1=LOADFROM($PROJECTPATH\one.grd);
B1=LOADFROM($PROJECTPATH\two.grd);
THICK2(a1,B1,$PROJECTPATH\three_b.grd);
THICK();

Here is an example, with comments, where the bottom elevation and the thickness are added together to get the roof, for 6 seams. The Submacro is defined by the equation just once. Then it is called and used 6 times at the bottom of the macro.
;Add the Floor and Thickness to get the seam Roof.
;Coal seams to apply this to are: C1,C2,C3,C4,C5,C6
;------------------------------------------------------
;LOAD THE GRIDS INTO MEMORY
;
C1_KEY_ELV=LOADFROM(C:\Carlson Projects\C1_KEY_ELV.GRD)
C1_KEY_THK=LOADFROM(C:\Carlson Projects\C1_KEY_THK.GRD)
C2_KEY_ELV=LOADFROM(C:\Carlson Projects\C2_KEY_ELV.GRD)
C2_KEY_THK=LOADFROM(C:\Carlson Projects\C2_KEY_THK.GRD)
C3_KEY_ELV=LOADFROM(C:\Carlson Projects\C3_KEY_ELV.GRD)
C3_KEY_THK=LOADFROM(C:\Carlson Projects\C3_KEY_THK.GRD)
C4_KEY_ELV=LOADFROM(C:\Carlson Projects\C4_KEY_ELV.GRD)
C4_KEY_THK=LOADFROM(C:\Carlson Projects\C4_KEY_THK.GRD)
C5_KEY_ELV=LOADFROM(C:\Carlson Projects\C5_KEY_ELV.GRD)
C5_KEY_THK=LOADFROM(C:\Carlson Projects\C5_KEY_THK.GRD)
C6_KEY_ELV=LOADFROM(C:\Carlson Projects\C6_KEY_ELV.GRD)
C6_KEY_THK=LOADFROM(C:\Carlson Projects\C6_KEY_THK.GRD)
;------------------------------------------------------
;DEFINE THE SUBMACRO EQUATION
;
SUBMACRO ROOF(X,Y,Z)
TOP=X+Y
SAVEAS(TOP,Z)
END SUBMACRO
;
;------------------------------------------------------
ROOF(C1_KEY_ELV,C1_KEY_THK,C:\Carlson Projects\C1_KEY_TOP.grd)
ROOF(C2_KEY_ELV,C2_KEY_THK,C:\Carlson Projects\C2_KEY_TOP.grd)
ROOF(C3_KEY_ELV,C3_KEY_THK,C:\Carlson Projects\C3_KEY_TOP.grd)
ROOF(C4_KEY_ELV,C4_KEY_THK,C:\Carlson Projects\C4_KEY_TOP.grd)
ROOF(C5_KEY_ELV,C5_KEY_THK,C:\Carlson Projects\C5_KEY_TOP.grd)
ROOF(C6_KEY_ELV,C6_KEY_THK,C:\Carlson Projects\C6_KEY_TOP.grd)


Variables
Variables in the GFU can be any keywords providing meaningful identification of the data loaded. A variable can be either just a value or constant; or most commonly a surface (Grid or TIN). Individual macro lines typically have one of the following forms:
    Variable1=Variable2
    Variable1=Expression
    Variable1=Function(Expression1,Expression2)

Whenever new variable name is encountered on the left side of the equation, the new variable will be created. The program will use its knowledge of the right side of equation to define a type of the new variable. For example:
    A=1.0                  Variable A will be just a value
    A=LoadFrom(abc.grd)        Variable A is a grid loaded from file
    B=A                               Variable B is same variable type as A
    B=(1+C+A)/D                  Variable B will be 1+C+A, all divided by D. C and D will need to be defined somewhere before this line in the GFU.

Important!: Once a variable is defined, its type (like grid location and resolution) does not change. Therefore, for the existing variable A, the following expression:
    A=Min(B,C)

is interpreted in the following way: for every point of the existing surface A calculate values of surface B and C and use the smaller of the two values to set new value of point elevation on surface A.

The following operators may be used in the expressions:
+, -, *, / - regular arithmetic operators
<, >, =, ! (not) - logic operators
| (or), & (and) - binary operators

Changing the scope of the equation
The scope of any line of the script can be modified by adding one of the following inclusion/exclusion operators:
    A=Min(B,C);INCLU()       - will prompt for inclusion at run-time
    A=Min(B,C);INCLU(handle_here)   - will use AutoCAD entity with specified handle for the inclusion
    A=Min(B,C);EXCLU()   - will prompt for exclusion at run-time
    A=Min(B,C);EXCLU(handle_here)   - will use AutoCAD entity with specified handle for the exclusion
    A=Min(B,C);PERIM()   - will prompt for polyline file with inclusions/exclusions
    A=Min(B,C);PERIM(file_name)   - will use specified file with inclusions/exclusions
Multiple inclusions or exclusions can be appended in this manner. Only points of target surface (A) passing inclusion/exclusion filter will be evaluated.

For custom, user define prompting, the following text should be used:
    PERIM(,Prompt goes here) for user defined interactive inclusion and exclusion selection in CAD
    PERIM(*,Prompt goes here) for file selection dialog with user defined prompts to select a PLN file.

The following script functions are currently defined:


Macro functions (performing operations on the entire surface at once)

LOAD() Prompt user for the file to load. Returns a variable.
LOAD(,Prompt goes here) for user defined prompting
LOADFROM(string) Load surface from file. Grids (GRD) and TINs (FLT, TIN) are supported. Returns a variable.
SAVE(Variable) Saves surface back to original file.
SAVEAS(Variable,FileName) Saves surface into a file with given name.
RELEASE(Variable)  Releases  memory used by a surface and undefines it for further use.
EXTRAP(Variable[,Type])

Micro functions (taking effect on point by point basis as controlled by left side of the equation) Expressions can be complex ones with variables, value and functions

MAX(Expresson1,Expression2) Sets value to larger of two expressions evaluated.
MIN(Expresson1,Expression2) Sets value to smaller of two expressions evaluated.
LESS(Expression1,Expression2,Expression3) If result of Expression1 is less than Expression2 then result is Expression3. Otherwise the source point is not changed. If Expression3 is not specified value is set to NULL.
GREATER(Expression1,Expression2,Expression3) If result of Expression1 is greater than Expression2 then result is Expression3. Otherwise the source point is not changed. If Expression3 is not specified value is set to NULL.
IF(Expression1,Expression2,Expression3) If Expression1 (can be logic expression like (A+B)>C or A=B or A!B 'not equal') not 0 then result is Expression2, otherwise it is Expression3.
POW(Expression1,Expression2) Result is value of Expression1 in power of Expression2
MERGE(Expression1,Expression2) If Expression2 is valid at a point, then result is that value, otherwise it is value of Expression1
SET_NULL(Expression1,Expression2) If Expression1 is valid at a point, then result is that value, otherwise it is value of Expression2
CHANGE_RANGE_VALUE(Expression1, Range1, Range2, Expression2) If Expression1 is a valid point and its value is greater than equal to Range1 and less than equal to Range2, then result is Expression2. If Expression2 is not specified value is set to NULL.

Here is an example of a complex IF statement used for coal recovery based on thickness of the seam:

COALTHK=LoadFrom(C:\Carlson Projects\Grids\C40_THK.GRD);
ROM_COAL=COALTHK
ROM_COAL=if((COALTHK<2)|(COALTHK=2),COALTHK - (COALTHK * 0.50),ROM_COAL)
ROM_COAL=if(((COALTHK<4)|(COALTHK=4))&(COALTHK>2),COALTHK - (COALTHK * 0.10),ROM_COAL)
ROM_COAL=if((COALTHK<7)&(COALTHK>4),COALTHK - (COALTHK * 0.075),COALTHK - (COALTHK * 0.05))
SaveAs(ROM_COAL, C:\Carlson Projects\Grids\C40_ROM_THK.GRD)

Pulldown Menu Location: Surface and Grids
Keyboard Command: GFU
Prerequisite: Make a grid (.GRD) file with the Make 3D Grid File command.