The Grid Calc Transform function applies user-defined programs to perform grid-to-grid operations. The grid calc models are text files that contain the programming logic to perform complicated, multi-line equation and conditional operations on grids. The model is executed one time through for each grid node. One or more grids can be produced as output from a grid calc model. The model list is pre loaded with all model files found in the GRIDS sub directory under the project directory. All models must end with a .TXT extension. Select a model file from the drop-down model list then click the "Compile Model" button.
To open the Grid Calc Transform tool, select Contours>Grids>Grid Calc Transform from the menu bar at the top of the Map Module.
Compiling The Model
Grid calc models are stored in text form and must be "compiled" into an executable form prior to execution. Compiling the model loads the the input and output variables into the assignment list boxes.
Assigning Model Variables
MAXIMUM VARIABLE NAME LENGTH IS 40 CHARACTERS
Input Variables
Input variables may be grids, constant values, or NULL values. Each input variable should be assigned to the appropriate identifier.
To assign a model variable, click once on the variable name listed in the "Input Variable Assignments" list. Then choose a "Grid File", "Constant" value, or ""Null" item. After making the choice, click on the Apply button to set the assignment. The new assignment will appear in the input variable list.
Note: All input grids must have matching data limits, rows and columns, and grid sizes.
Output Grids
The result of the model is one or more grid files. These grids can be selectively assigned to one of the existing grid files or can be assigned a new grid name. Output variables are assigned using the same technique described in the input variable section. Output grids should have a title specified.
Temporary output grids computed in the model but not stored back to the disk can be specified as "UNASSIGNED".
Model Execution
Once the model is compiled and all input and output variables are assigned, press the "Execute Model" button to start the user model transformation process.
Grid Calc Model Programming Syntax
Grid calc models are text files that contain the programming logic to perform complicated, multi-line equation and conditional operations on grids. The model is executed one time through for each grid node value including Null nodes.
Users should be familiar with programming languages such as FORTRAN before attempting to create or modify a user model file.
Statements
Each statement in the model consists of variables, operators, and key words. Each statement in the model is terminated with a semicolon (;). Statements may be continued over more then one line. An operator or delimiter, such as, a space or parenthesis separates constants, variables, and numbers. Statements which control the flow of the program logic contain key words "GOTO", "IF...THEN...ELSE", or "BEGIN...END". Branching is done using statement LABELS placed on a line prior to the point of continued processing. Each label consists of a character string terminated by a colon (:). Examples of labels are LABEL1:, L999: and DONE:.
Model Comments
An exclamation mark (!) defines the beginning of a comment. Entire lines may be commented by placing an ! in column one. In-line comments may be placed on executable statements by placing the ! and comment following the semicolon (;) line terminator. Blank lines in the model are ignored.
Comment examples:
!thisisacommentedline.
A= B + C; ! this is an in-line comment.
Symbols and Keywords
(;) End of statement terminator
(!) Comment indicator (start comment)
(:) Label terminator
space Delimiter
IF Test control word
THEN statement Continuation of test
THEN BEGIN Starts "TRUE" condition of test
ELSE BEGIN Starts "FALSE" condition of test
GOTO Branch to a label
CONSTANT Declare constant
GRID Declare grid variable
IN Declare GRID as input variable
OUT Declare GRID as output variable
DO Do loop
END End THEN BEGIN or ELSE BEGIN section
ENDDO End Do Loop
ENDMOD Terminates the model
Functions
Function Keyword Example
------------ ------------ -------------
add + A+B
subtract - A-B
multiply * A*B
divide / A/B
exponential ** A**2 (A squared)
assign = A = 1.0
compare equal = or .EQ. IF(A=B) THEN... or IF(A.EQ.B) THEN...
logical AND .AND. IF((A=B).AND.(C=D))...
logical OR .OR. IF((A=B).OR.(C=D))...
greater than > or .GT. IF(A.GT.B)...
less than < or .LT. IF(A<B)...
greater or equal >= or .GE. IF(A.GE.B)...
less or equal <= or .LE. IF(A.LE.B)...
E to power of X EXP(x)
log (natural) LN(x)
log (base 10) LOG10(x)
absolute value ABS(x)
square root SQRT(x)
negative (-x) NEG(x)
truncate to integer TRUNC(x)
sign of number times 1 SIGN(x) IF(SIGN(x)=-1)...
round to 2 dec places ROUND(x)
maximum of x and y MAX(x,y)
minimum of x and y MIN(x,y)
remainder of x / y MOD(x,y)
Parenthesis
Binary operators are defined as an expression enclosed within parentheses, such as, (x+y) or (x*y). Statements require parentheses only when more than one binary operation is used or when one wishes to force the evaluation precedence. The normal operator precedence from lowest to highest is:
+ and -
* and /
**
unary - (minus sign)
The expression,
A+B*C**D/E-F is equivalent to (A+((B*(C**D))/E))-F
and would be evaluated in the following steps. Intermediate expressions are shown in braces.
K = C**D [A+B*K/E-F]
L = B*K [A+L/E-F]
M = L/E [A+M-F]
N = A+M [N-F]
O = N-F
Parenthesis force the sub-expression enclosed to be evaluated first, as illustrated below.
(A+B)*C**D/(E-F)
K = A+B [K*C**D/(E-F)]
L = C**D [K*L/(E-F)]
M = K*L [M/(E-F)]
N = E-F [M/N]
O = M/N
Declaration Section
The declaration section is the first part of a model program in which the input and output logs and constants are defined. Each declare statement consists of a "type" keyword, a variable name, and a "use" keyword. It is not necessary to declare temporary variables, Temporary variables are defined for the first time as the result of an assignment statement.
Examples:
GRID UPPER IN;
GRID LOWER IN;
GRID ISOPACH OUT;
CONSTANT SAND 2.5; ! value is optional
CONSTANT NULL; ! assumed to represent NULL grid value
Executable Statement
An executable statement is any statement in which an equation type calculation is performed or an assignment is made. The general form is:
ASSIGNMENT_VARIABLE = executable_statement;
Examples x = a * b;
x = (a*(b+c))/(x-y);
Note that each line is terminated with a semi-colon (;) and the equal sign (=) is required. Variables appearing on the right side of the equation must either be declared as constants or grids or be temporary variables defined as the result of an earlier assignment statement.
GOTO and LABEL Statement
The "GOTO" keyword and following label is use to branch to another part of the program.
Example
IF ( x > 0.0 ) THEN GOTO DIVIDE;
y = 0.0;
GOTO MORE;
DIVIDE:
y = y / x;
MORE:
statement;
statement;
etc.
IF-THEN STATEMENT
The IF-THEN statement conditionally executes a single assignment statement, GOTO, or BEGIN-END group based on the results of a logical comparison.
Example
IF( SW > 0.75 ) THEN BEGIN;
SW3 = (1-SW)**3;
SW = 1-(16/3)*SW3*(5-128*SW3);
END;
IF-THEN-ELSE STATEMENT
The IF-THEN-ELSE compound statement provides conditional processing in a clear and efficient manner without the use of a GOTO.
Examples:
IF ( logical expression ) THEN BEGIN;
statement;
statement;
etc.
END;
ELSE BEGIN;
statement;
statement;
etc.
END;
DO-LOOP STATEMENT
The DO loop statement is used to repeat a section of the model a set number of times.
The general format of the DO loop is:
DO counter = first TO last;
statement;
statement;
etc.
ENDDO;
The following example sums values from 1 to 10. "A" is summed when K is even and "B" is summed when K is odd.
SUM = 0.0;
N = 10;
DO K = 1 TO N;
IF( MOD(K,2)=0) THEN BEGIN;
SUM = SUM + A;
END;
ELSE BEGIN;
SUM = SUM + B;
END;
ENDDO;
EXAMPLE GRID CALC MODEL
! ISOPACH.TXT - GRID CALC MODEL TRANSFORM
!
! COMPUTES ISOPACH BETWEEN TWO STRUCTURE GRIDS
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! INPUT GRIDS USED IN THE MODEL
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
GRID UPPER IN; ! UPPER STRUCTURE GRID
GRID LOWER IN; ! LOWER STRUCTURE GRID
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! OUTPUT GRIDS USED IN THE MODEL
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
GRID ISO OUT; ! OUTPUT ISOPACH GRID
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! CONSTANTS USED IN THE MODEL
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
CONST NULL; ! USED TO TEST FOR NULL GRID VALUES
CONST ISOMIN 0.0; ! USED TO CLIP ISOPACH TO ZERO THICKNESS
IF ( (UPPER .NE. NULL) .AND. (LOWER .NE. NULL) ) THEN BEGIN;
ISO = UPPER - LOWER;
ISO = MAX(ISO,ISOMIN); ! CLIP AT ZERO THICKNESS
END;
ELSE BEGIN;
ISO = NULL;
END;
DONE:
ENDMOD;
|