Date post: | 08-Nov-2014 |
Category: |
Documents |
Upload: | yair-galindo-vega |
View: | 148 times |
Download: | 19 times |
SQL Manual Minex V5.3 April 2008
Minex SQL Manual i
Table of Contents
Introduction ............................................................................................................................ 1 Example SQL .............................................................................................................................................. 1 Nulls ........................................................................................................................................................... 3
SQL Editor ................................................................................................................................ 4 Types of SQL .............................................................................................................................................. 4 SQL Editor .................................................................................................................................................. 5
Borehole SQL ........................................................................................................................... 7 Status SQL .................................................................................................................................................. 7 Executing a Borehole SQL ........................................................................................................................ 10 Borehole SQL Variables ........................................................................................................................... 16
Seam Pick SQL ....................................................................................................................... 18
Grid or Seam Model SQL ........................................................................................................ 24
Mine Reserves Database SQL ................................................................................................. 32
SQL Syntax ............................................................................................................................. 36 Sequential Order of Statements .............................................................................................................. 36 Input/Output ........................................................................................................................................... 39 Control Constructs ................................................................................................................................... 39 Comments ............................................................................................................................................... 41
Minex SQL Manual 1
Introduction Minex 5 uses a subset of Structured Query Language (SQL) to manipulate data with user defined logic. SQL provides the user with flexibility to make their own “what if” decisions. SQL has been used in Minex 5 to work on various data sets, including
• Borehole data • Grids • Mine Reserves databases
An SQL is written in a text file (saved with the extension .SQL). Users can use the internal Minex 5 SQL editor or use Notepad, Ultraedit or other ASCII text editors. Once written the SQL is run by:
a. Compiling into binary. Compiling will also find and note errors. But if compiling is successful the SQL is then,
b. Executed on the data.
The Minex SQL is best understood by using an example.
Example SQL In coal mining poor quality coal is assigned a zero seam thickness. For example saleable coal may have the following characteristics:
ASH < 14%
Energy > 26
Moisture < 10%
Mining equipment may necessitate coal less than 0.1 metres be wasted.
Minex 5 models coal seams using 2D grids. The grid-to-grid arithmetic necessary to set these conditions is not complex, but is tedious. A SQL macro can easily complete such a task. Listed below is an example SQL macro. In this case comment lines prefixed with a ! are present to describe the macro. Comment lines are not compiled or executed.
Minex SQL Manual 2
This SQL contains three parts.
1. Data definitions. Variable names are defined such THICK, ASH, SE, MO. The SQL is compiled from top to bottom so this declaration is near the top of the SQL.
2. Conditions. Conditions can either be true or false. The condition is labeled X. Here checks are made on thickness, ash, moisture and specific energy. Because of the OR logic X is true if one condition is true.
3. Action. Actions take place only if the condition X is true. As this SQL is written for a 2D grid it will cycle through each mesh point, test the conditions then take the action if the conditions are met. The following flow sheet illustrates the process.
Minex SQL Manual 3
Nulls Minex uses the null value 99999.000 where data is missing or undefined. Thus a borehole sample or a grid cell that is not known is filled with this special value. When Minex finds a null value it ignores the values in functions such as volumes, contouring and compositing. In SQLs however the user must allow for nulls. In the examples that follow you will see reference to NULL. In the example the “AND ASH # NULL” is critical as NULL is greater than 10.
Minex SQL Manual 4
SQL Editor SQLs should be created using the File > New menu path. This process creates the SQL file and automatically opens the Minex SQL editor. The process uses a wizard to create an SQL. The steps are shown in Figure 1.
Figure 1: Minex SQL Wizard
Key points in this wizard are:
1. All SQLs have a file extension SQL. 2. When naming the SQL in step 2, don’t input the extension (.SQL) Minex will manage this
file extension. Entering the extension will result in files named XXX.SQL.SQL 3. The SQL is an ASCII file and can be edited in any ASCII editor. 4. The first line of the SQL should have a line such as “!Borehole-SQLMacro”. This tells
Minex what type of SQL it is working with. 5. Minex will enter this first line.
Types of SQL Minex has four types of SQL. The type of SQL is defined via the first step in the wizard (Figure 2).
1. Borehole SQL. This type of SQL is used to change or define variable values in the Minex borehole database. For example a Borehole SQL could define density as RD = 1.21 + 0.1*ASH.
2. ReservesSQL. This type of SQL works with the pit reserves database. For example we could say a variable TIME = 10 if STRIP = 2.
3. SeammodelSQL. This SQL works on Minex grids. For example we could say grid XXX = TOPS – 100.
4. SeamPickSQL. This SQL works with the seam pick or B33 file. This allows the seam picks to be moved up or down. This could be done to allow incorporation of dilution.
Figure 2: SQL Types
1. Select type of SQL
2. Name the SQL
3. Minex opens SQL editor
1. Select type of SQL
2. Name the SQL
3. Minex opens SQL editor
Minex SQL Manual 5
SQL Editor The Minex SQL editor has two main buttons:
1. The save button writes the SQL to disk in the active project area. The save button is hidden but available on the lower left TAB (Figure 3).
2. The compile button converts the ASCII SQL to binary (Figure 4). Any errors are reported in the output window. The SQL is NOT compiled from the editor buffer. The SQL is compiled from the version on disk. So always save the SQL before compiling.
Figure 3: Save SQL on lower left Tab
Minex SQL Manual 6
Line number
Line number : character position of cursor
Compile button
Line number
Line number : character position of cursor
Compile button
Figure 4: SQL editor
Minex SQL Manual 7
Borehole SQL The following chapters discuss the five types of SQL;
1. Borehole SQL 2. Borehole SQL Variable 3. Seam pick (Chapter 5) 4. Grid SQL (Chapter 6) 5. Mine Reserves database (Chapter 7)
These chapters have a common layout.
1. A STATUS SQL is discussed. 2. The method of executing the SQL is shown. 3. One or more examples are presented.
This chapter discusses the borehole SQL. Borehole SQLs are used to set values to variables in a Minex borehole database. For example density could be calculated from ash as RD = 1.2 + ASH * .01
Status SQL A STATUS borehole SQL has the following lines.
• !Borehole-SQLMacro • STATUS • EXIT
Note: Line 1 tells Minex the type of SQL. Line 2 contains the command STATUS. Status is a command that lists all variables and options available. The
output of the STATUS line will vary depending on the type of SQL. Line 3 reads EXIT. This line is recommended but not essential.
When compiled this SQL sends a report to the output window. This report has two parts.
1. The variables of the database are read and printed, all these variables can be used in the SQL as either read or write variables.
2. The status information is reported.
The part 1 information reads as follows:
============================
SQL Macro compilation report
============================
Current list of 62 variables..
Variable 1 is TOSURVEY (numeric)
Variable 2 is AZIMUTH (numeric)
Variable 3 is DIP (numeric)
Variable 4 is X (numeric)
Minex SQL Manual 8
Variable 5 is Y (numeric)
Variable 6 is Z (numeric)
Variable 7 is TODOMAIN (numeric)
Variable 8 is DOMAIN (numeric)
Variable 9 is TOLITH (numeric)
Variable 10 is TOQUAL (numeric)
Variable 11 is TOGEOPH (numeric)
Variable 12 is TOSEAM (numeric)
Variable 13 is ROCKTYPE (4 char alpha)
Variable 14 is INTERREL (4 char alpha)
Variable 15 is INTERPER (4 char alpha)
Variable 16 is SHADE (4 char alpha)
Variable 17 is COLOUR1 (4 char alpha)
Variable 18 is COLOUR2 (4 char alpha)
Variable 19 is GRAINSZE (4 char alpha)
Variable 20 is LITHADJ1 (4 char alpha)
Variable 21 is LITHADJ2 (4 char alpha)
Variable 22 is WEATHER (4 char alpha)
Variable 23 is TEXTURE (4 char alpha)
Variable 24 is COMMENT (4 char alpha)
Variable 25 is YIELD (numeric)
Variable 26 is MOIST (numeric)
Variable 27 is ASH (numeric)
Variable 28 is VM (numeric)
Variable 29 is FC (numeric)
Variable 30 is ARD (numeric)
Variable 31 is CSN (numeric)
Variable 32 is SE (numeric)
Variable 33 is SU (numeric)
Variable 34 is GAMMA (numeric)
Variable 35 is LSD (numeric)
Variable 36 is BRD (numeric)
Variable 37 is CALIPER (numeric)
Variable 38 is DENSITY (numeric)
Variable 39 is O_ASH_T (SQL Computed)
Variable 40 is O_ASH_T2 (SQL Computed)
Variable 41 is ASH_T (SQL Computed)
Variable 42 is ASH_T2 (SQL Computed)
Minex SQL Manual 9
Variable 43 is WASHASH (numeric)
Additional variables added by the database system follow..
Variable 44 is BD3HOLE : First 8 characters of hole name
Variable 45 is BD3INT : Interval number ranging from 1..BD3LEN
Variable 46 is BD3LEN : No. of intervals in hole
Variable 47 is BD3FROM : FROM depth down hole
Variable 48 is BD3TO : TO depth down hole
Variable 49 is BD3THICK : Thickness of interval (TO-FROM)
Variable 50 is BD3COLX : World X coordinate of hole collar
Variable 51 is BD3COLY : World Y coordinate of hole collar
Variable 52 is BD3COLZ : World Z coordinate of hole collar
Variable 53 is BD3DEPTH : Final depth of hole
Variable 54 is BD3FROMX : World X coordinate at top of interval
Variable 55 is BD3FROMY : World Y coordinate at top of interval
Variable 56 is BD3FROMZ : World Z coordinate at top of interval
Variable 57 is BD3MIDX : World X coordinate at middle of interval
Variable 58 is BD3MIDY : World Y coordinate at middle of interval
Variable 59 is BD3MIDZ : World Z coordinate at middle of interval
Variable 60 is BD3TOX : World X coordinate at bottom of interval
Variable 61 is BD3TOY : World Y coordinate at bottom of interval
Variable 62 is BD3TOZ : World Z coordinate at bottom of interval
In this case the first 43 variables are user defined variables present in the database. The variables 44 to 62 are innate to the database. These variables between 44 and 62 can’t be changed with an SQL. They can however be used to change other variables.
For example an SQL to report “bad” ash would read:
!Borehole-SQLMacro
SELECT X
WHERE ASH # NULL
AND ASH > 88
AND BD3THICK > 0.01
IF SELECT X
PRINT "BD3HOLE" BD3HOLE
PRINT "BD3FROM" BD3FROM
ENDIF
Minex SQL Manual 10
EXIT
Running this SQL will report those “bad” points.
Processing with a SQL MACRO current
ASH 89.300
BD3HOLE "3000 "
BD3FROM 28.930
ASH 88.500
BD3HOLE "3000 "
BD3FROM 42.040
Part 2 of the STATUS SQL report shows the available functions and limits. These limits may change with new versions of Minex.
Internal SQL/MACRO status
-------------------------
Maximum of 4,096 lines per macro
Maximum no. variables/macro is as follows
DATABASE 544, LOCAL 128, GLOBAL 32, EXTERNAL 512
Maximum length of variable names is as follows
DATABASE 16, LOCAL 16, GLOBAL 16, EXTERNAL 8
Maximum of 16 characters for a SELECT label
Maximum of 128 SELECT clauses per macro
Maximum of 256 "IF..ENDIF" groups
Maximum of 32 "..ELSE.." alternatives within each "IF"
Maximum of 8 comma separated arguments per line
Maximum of 40 characters for "..." strings
Executing a Borehole SQL To execute a borehole SQL right click on the SQL in the explorer window. This will bring up a new window which allows the SQL to be run or executed (Figure 5).
Warning: It is useful when running a borehole SQL to set the Borehole selection menu to ALL. The borehole SQL will only act on the holes active within the borehole selection menu. If the selection enables only a few holes, it is easy to run the SQL on some holes and not correct all holes.
Minex SQL Manual 11
Figure 5: Executing a boreholeSQL
Example 1 Calculate sum of proximate data
In coal proximate analysis the sum of all variables should add to 100 (plus or minus a small error). The following SQL writes out a new variable called SUMPROX which stores the accumulation. SUMPROX is then reported in a second SQL.
!Borehole-SQLMacro
SELECT SUMM
WHERE ASH # NULL
AND FC # NULL
AND MOIST # NULL
AND VM # NULL
AND SU # NULL
IF SELECT SUMM
PROXSUM = ASH + MOIST
PROXSUM = PROXSUM + FC
PROXSUM = PROXSUM + VM
PROXSUM = PROXSUM + SU
ELSE
PROXSUM = NULL
ENDIF
EXIT
Example 2 Report sum of proximate data
Minex SQL Manual 12
This reports data that is more than 101% or less than 99%. Note the “OR” statement must be in character position 1.
!Borehole-SQLMacro
SELECT REPORT
WHERE PROXSUM # NULL
AND PROXSUM > 101
OR
WHERE PROXSUM # NULL
AND PROXSUM < 99
IF SELECT REPORT
PRINT "PROXSUM" PROXSUM
PRINT "BD3HOLE " BD3HOLE
ENDIF
EXIT
When executed the SQL reports as follows:
Processing with a SQL MACRO current
PROXSUM 101.200
BD3HOLE "1067 "
PROXSUM 101.180
BD3HOLE "1068 "
PROXSUM 101.070
BD3HOLE "1077 "
PROXSUM 101.490
BD3HOLE "1078 "
PROXSUM 101.090
BD3HOLE "1080 "
PROXSUM 101.040
BD3HOLE "1080 "
PROXSUM 102.260
BD3HOLE "1125 "
Minex SQL Manual 13
PROXSUM 102.400
BD3HOLE "1125 "
PROXSUM 101.160
BD3HOLE "1125 "
Etc
Minex SQL Manual 14
Example 3. Calculate density from ASH
In this case the input variable is ASH, so a simple IF statement is adequate.
!Borehole-SQLMacro
IF ASH # NULL
RD_CALC = ASH * 0.01
RD_CALC = RD_CALC + 1.21
ELSE
RD_CALC = NULL
ENDIF
EXIT
Example 4. Calculate UHV from ASH and moisture.
In India the ultimate heating value UHV is calculated from the ash and the moisture values. In this example the select statement is used as the logic is only applied if both ash and moist are valid.
!Borehole-SQLMacro
SELECT A
WHERE ASH # NULL
AND MOIST # NULL
AND ASH # 0.00
AND MOIST # 0.00
IF SELECT A
UHV = ASH + MOIST
UHV = UHV * 138
UHV = 8900 - UHV
ELSE
UHV = NULL
ENDIF
EXIT
Minex SQL Manual 15
Minex SQL Manual 16
Borehole SQL Variables In Minex a borehole variable can be created as an SQL variable. An SQL variable is stored as a name or header in the borehole database but is not populated with values. When the SQL variable is reported, plotted, or modeled its value is determined by running an SQL over the database. An SQL variable is recomputed every time it is needed. Thus if new data is loaded or old data is changed it is not necessary to remember to run the SQL. To use an SQL variable:
1. The variable must be initialized as an SQL variable (Figure 6) and 2. An SQL must be nominated by name in the properties tab of the borehole database
(Figure 7).
Figure 6: Creating an SQL variable
1 set as true
2 enter name of SQL
1 set as true
2 enter name of SQL
Figure 7: Enable the SQL by turning it on and entering a valid SQL name
Minex SQL Manual 17
An example SQL file is shown below. Typically a borehole database can have many variables. However the borehole database can only access and run one SQL file. Thus all SQL variables must be defined in the one SQL file.
!Borehole-SQLMacro
SELECT A
WHERE ASH # NULL
AND MOIST # NULL
AND ASH # 0.00
AND MOIST # 0.00
IF SELECT A
UHV_SQL = ASH + MOIST
UHV_SQL = UHV_SQL * 138
UHV_SQL = 8900 - UHV_SQL
ELSE
UHV_SQL = NULL
ENDIF
Note it is not appropriate (nor necessary) to use the STATUS command in this type of SQL.
Minex SQL Manual 18
Seam Pick SQL A seam pick SQL allows the seam pick to be moved up or down (thickened or thinned) based on some logic. The STATUS output for a Seam Pick SQL is shown below:
============================
SQL Macro compilation report
============================
Variable 1 is BD3HOLE : First 8 characters of hole name
Variable 2 is BD3COLX : World X coordinate of hole collar
Variable 3 is BD3COLY : World Y coordinate of hole collar
Variable 4 is BD3COLZ : World Z coordinate of hole collar
Variable 5 is BD3DEPTH : Final depth of hole
Variable 6 is E : ROCK TYPE
Variable 7 is EAS : RAW ASH
Variable 8 is EMO : RAW MOIST
Variable 9 is EVM : VOLATILE MATTER
Variable 10 is ERD : RELATIVE DENSITY
Variable 11 is ESE : SPECIFIC ENERGY
Variable 12 is ESU : TOTAL SULPHUR
Variable 13 is EFC
Variable 14 is EFR : FROM depth down hole
Variable 15 is ETO : TO depth down hole
Variable 16 is ESR : Top of Seam RL
Variable 17 is ESF : Base of Seam RL
Variable 18 is EST : Thickness of seam (TO-FROM)
Variable 19 is EIB : Seam interburden (stratigraphic - to next seam stratigraphically above)
Variable 20 is EGAP : Seam overburden (non stratigraphic - to next seam above
Variable 21 is ESST : Stratigraphic thickness
Variable 22 is EFRX : World X coordinate at top of seam
Variable 23 is EFRY : World Y coordinate at top of seam
Variable 24 is EFRZ : World Z coordinate at top of seam
Variable 25 is ETOX : World X coordinate at base of seam
Variable 26 is ETOY : World Y coordinate at base of seam
Variable 27 is ETOZ : World Z coordinate at base of seam
Variable 28 is EXXX : Seam update flag 0=keep 1=delete 2=update
Variable 29 is C : ROCK TYPE
Variable 30 is CAS : RAW ASH
Minex SQL Manual 19
Variable 31 is CMO : RAW MOIST
Variable 32 is CVM : VOLATILE MATTER
Variable 33 is CRD : RELATIVE DENSITY
Variable 34 is CSE : SPECIFIC ENERGY
Variable 35 is CSU : TOTAL SULPHUR
Variable 36 is CFC
Variable 37 is CFR : FROM depth down hole
Variable 38 is CTO : TO depth down hole
Variable 39 is CSR : Top of Seam RL
Variable 40 is CSF : Base of Seam RL
Variable 41 is CST : Thickness of seam (TO-FROM)
Variable 42 is CIB : Seam interburden (stratigraphic - to next seam stratigraphically above)
Variable 43 is CGAP : Seam overrburden (non stratigraphic - to next seam above
Variable 44 is CSST : Stratigraphic thickness
Variable 45 is CFRX : World X coordinate at top of seam
Variable 46 is CFRY : World Y coordinate at top of seam
Variable 47 is CFRZ : World Z coordinate at top of seam
Variable 48 is CTOX : World X coordinate at base of seam
Variable 49 is CTOY : World Y coordinate at base of seam
Variable 50 is CTOZ : World Z coordinate at base of seam
Variable 51 is CXXX : Seam update flag 0=keep 1=delete 2=update
Variable 52 is B : ROCK TYPE
Variable 53 is BAS : RAW ASH
Variable 54 is BMO : RAW MOIST
Variable 55 is BVM : VOLATILE MATTER
Variable 56 is BRD : RELATIVE DENSITY
Variable 57 is BSE : SPECIFIC ENERGY
Variable 58 is BSU : TOTAL SULPHUR
Variable 59 is BFC
Variable 60 is BFR : FROM depth down hole
Variable 61 is BTO : TO depth down hole
Variable 62 is BSR : Top of Seam RL
Variable 63 is BSF : Base of Seam RL
Variable 64 is BST : Thickness of seam (TO-FROM)
Variable 65 is BIB : Seam interburden (stratigraphic - to next seam stratigraphically above)
Variable 66 is BGAP : Seam overrburden (non stratigraphic - to next seam above
Minex SQL Manual 20
Variable 67 is BSST : Stratigraphic thickness
Variable 68 is BFRX : World X coordinate at top of seam
Variable 69 is BFRY : World Y coordinate at top of seam
Variable 70 is BFRZ : World Z coordinate at top of seam
Variable 71 is BTOX : World X coordinate at base of seam
Variable 72 is BTOY : World Y coordinate at base of seam
Variable 73 is BTOZ : World Z coordinate at base of seam
Variable 74 is BXXX : Seam update flag 0=keep 1=delete 2=update
Variable 75 is A : ROCK TYPE
Variable 76 is AAS : RAW ASH
Variable 77 is AMO : RAW MOIST
Variable 78 is AVM : VOLATILE MATTER
Variable 79 is ARD : RELATIVE DENSITY
Variable 80 is ASE : SPECIFIC ENERGY
Variable 81 is ASU : TOTAL SULPHUR
Variable 82 is AFC
Variable 83 is AFR : FROM depth down hole
Variable 84 is ATO : TO depth down hole
Variable 85 is ASR : Top of Seam RL
Variable 86 is ASF : Base of Seam RL
Variable 87 is AST : Thickness of seam (TO-FROM)
Variable 88 is AIB : Seam interburden (stratigraphic - to next seam stratigraphically above)
Variable 89 is AGAP : Seam overrburden (non stratigraphic - to next seam above
Variable 90 is ASST : Stratigraphic thickness
Variable 91 is AFRX : World X coordinate at top of seam
Variable 92 is AFRY : World Y coordinate at top of seam
Variable 93 is AFRZ : World Z coordinate at top of seam
Variable 94 is ATOX : World X coordinate at base of seam
Variable 95 is ATOY : World Y coordinate at base of seam
Variable 96 is ATOZ : World Z coordinate at base of seam
Variable 97 is AXXX : Seam update flag 0=keep 1=delete 2=update
Internal SQL/MACRO status
-------------------------
Maximum of 4,096 lines per macro
Maximum no. variables/macro is as follows
DATABASE 544, LOCAL 128, GLOBAL 32, EXTERNAL 512
Minex SQL Manual 21
Maximum length of variable names is as follows
DATABASE 16, LOCAL 16, GLOBAL 16, EXTERNAL 8
Maximum of 16 characters for a SELECT label
Maximum of 128 SELECT clauses per macro
Maximum of 256 "IF..ENDIF" groups
Maximum of 32 "..ELSE.." alternatives within each "IF"
Maximum of 8 comma separated arguments per line
Maximum of 40 characters for "..." strings
The key things of note here are:
1. The seams in this database are E C B A. 2. Each seam is assigned 23 variables with a suffix prefix system such as AAS, AIB or ASF. 3. The special variable with suffix XXX is used to indicate if a seam will be changed. This
variable can be set to 0, 1 or 2 to flag an action. The actions are 0=keep 1=delete 2=update
In the example below seams E and C are combined into C if the waste between the seams is less than 20% of the coal material.
!SeamPick-SQLMacro
! A local variable is used within the sql
! To do mathematics
! This variable is not written back to the database.
LOCAL RATIO
SELECT X
WHERE EST # NULL
AND CST # NULL
AND CIB # NULL
IF SELECT X
RATIO = EST + CST
RATIO = CIB / RATIO
ELSE
RATIO = 100
ENDIF
Minex SQL Manual 22
! If Ratio is less than 25% then the C seam is thickened and the E seam is thinned.
IF RATIO <= 0.25
CXXX = 2
EXXX = 2
CFR =EFR
ETO = EFR
ENDIF
EXIT
.
CST
CIB
EST
CST
EST
AFTER
BEFORE
CST
CIB
EST
CST
EST
AFTER
BEFORE
Figure 8 shows the results of this SQL
Note:
Figure 8 is an example from a seam pick SQL process. Here the third hole has the C seam thickened and the E seam set to 0 thickness.
Minex SQL Manual 23
When running a seam pick SQL the menu is as shown in Figure 9. The most critical part of this menu is the lower section. Here the user should save the new pick file as a new name and not overwrite the existing seam pick file.
Figure 9: Seam pick menu
Minex SQL Manual 24
Grid or Seam Model SQL Grid or seam model SQL allows arithmetic functions to be done on grids. The STATUS output for a grid SQL is simpler than the earlier SQLs as seen below.
============================
SQL Macro compilation report
============================
Internal SQL/MACRO status
-------------------------
Maximum of 4,096 lines per macro
Maximum no. variables/macro is as follows
DATABASE 544, LOCAL 128, GLOBAL 32, EXTERNAL 512
Maximum length of variable names is as follows
DATABASE 16, LOCAL 16, GLOBAL 16, EXTERNAL 8
Maximum of 16 characters for a SELECT label
Maximum of 128 SELECT clauses per macro
Maximum of 256 "IF..ENDIF" groups
Maximum of 32 "..ELSE.." alternatives within each "IF"
Maximum of 8 comma separated arguments per line
Maximum of 40 characters for "..." strings
In this list there are no variables defined. Recall the earlier SQLs (borehole and seam pick) used a defined and rigid database. A grid or seam model SQL works on a very flexible and undefined set of grids. While the suffix system of SF SR ST etc is fixed the seams A B C D or JOE FRED MARY TOM names are totally user defined. Thus the names of the grids are unknown to the SQL application.
As such the grid SQL system has no predefined list of variables. The EXTERNAL verb is used to define the grids required. EXTERNAL grids are either read or written (or both) to the disk.
Example 1 Compute total seam thickness.
The following example calculates total seam thickness for a set of seams E C B A.
!SeamModel-SQLMacro
! DECLARE INPUT VARIABLES
EXTERNAL EST,CST,BST,AST
! Declare output variables
EXTERNAL TOTST
Minex SQL Manual 25
! GET RID OF NULLS
IF EST = NULL
EST = 0
ELSE
EST = EST
ENDIF
! GET RID OF NULLS
IF EST = NULL
CST = 0
ELSE
CST = CST
ENDIF
! GET RID OF NULLS
IF BST = NULL
BST = 0
ELSE
BST = BST
ENDIF
! GET RID OF NULLS
IF AST = NULL
EST = 0
ELSE
AST = AST
ENDIF
Minex SQL Manual 26
! NOW ADD THEM UP AS NULL ALL REMOVED NO CONDITIONS
TOTST = AST + BST
TOTST = TOTST + CST
TOTST = TOTST + EST
EXIT
To run this menu the user can either:
1. Right click on the SQL in the Minex explorer and select Execute or
2. Access the Seam SQL via the path Seam Model > Seam Model Operations > SQL
In either case the menu in Figure 10 is displayed. Starting at the top of the menu the steps to follow are:
1. Nominate an input reference grid. All SQL operations will be done at the mesh size and extents of this reference grid.
2. Nominate the input and output grid files. 3. Compile the SQL. This will fill column 1 with the names of the all the EXTERNAL
variables. These variables are displayed in order. By grouping the input variables before the output variables, the outputs appear at the bottom.
4. Set the grids to be input or output (Yes or No). See Figure 11. 5. Run the SQL (use OK button).
Minex SQL Manual 27
1
2
3
4
1
2
3
4
Figure 10: Seam model SQL
In this SQL the four thickness grids are input (Yes) and the TOTST is an output (Yes) as shown in Figure 11.
Minex SQL Manual 28
Figure 11: Set grids to be input or output
When run the grid max and min values are displayed. The statistics of this run are shown below.
Grid - Cells - Maximum - Minimum - Average
TOTST 38400 199998.0 11.99 63364.91
Here the null values are a problem. The SQL contains the incorrect segment:
IF EST = NULL
CST = 0
ELSE
CST = CST
ENDIF
Changing this to
IF CST = NULL
CST = 0
ELSE
CST = CST
ENDIF
On the second run the prompt shown in Figure 12 is given. Accepting this prompt leaves the input and output settings (Yes or No) as defined in Figure 11 unchanged.
Minex SQL Manual 29
Figure 12: Compilation prompt.
The new result is shown below.
Grid - Cells - Maximum - Minimum - Average
TOTST 38400 16.13 0.00 8.82
Example 2: Grid SQL with a suffix.
Grids can be defined explicitly ASF, ASR, AST etc or assigned a generic name where an SQL is to be run over a set of seams (a seam list). Generic variable names like FLOOR, ROOF, THICK require the user to associate the variable with the grid suffix in question.
An example of this is provided below
EXTERNAL ROOF, FLOOR, THICK
SELECT MICHELLE
WHERE ROOF = NULL
AND FLOOR # NULL
IF SELECT MICHELLE
ROOF = FLOOR
THICK = 0
ENDIF
Here the variables are associated to the relevant grid suffix. Thus the SQL variable ROOF is equates to the Minex suffix SR. FLOOR is associated with SF and THICK is associated with ST. When the SQL is complied the second column is mapped with the appropriate suffixes (Figure 13).
Minex SQL Manual 30
Figure 13: Example of mapping SQL names to suffix
Example 3: Grid SQL with a suffix.
The grid SQL in example 1 would be tedious and error prone with 100 or 200 seams. A more elegant SQL uses a grid suffix system and runs the same logic over all (or a selected group of seams).
!SeamModel-SQLMacro
EXTERNAL THICK
EXTERNAL TOTST
IF THICK = NULL
THICK = 0
ELSE
THICK = THICK
ENDIF
TOTST = TOTST + THICK
EXIT
Here the variable THICK will be translated to SEAM+SUFFIX for the seam selected. The key to this SQL is to read the value of TOTST in from disk and write it out to disk. Thus a grid of zeros is required as the first input. This grid can be generated using a separate SQL or using a scale function. Here a grid is scaled using manipulate (Figure 14).
Minex SQL Manual 31
Figure 14: Manipulate a grid.
When the SQL is loaded and compiled only two variables are listed, THICK and TOTST (Figure 15). THICK is mapped in column 2 to ST (the standard Minex suffix for thickness). Thus for each seam E C B A the grids EST CST BST and AST are read. These are added to TOTST which for the first seam E is read in as a zero value grid and is written out with the values of EST. Subsequent reads and writes accumulate seams C, B and A respectively.
Figure 15: Using suffixes with seam model SQL
When run; the output appears four times for the four seams. As a quick check the values of TOTST should increase for each run.
Grid - Cells - Maximum - Minimum - Average
TOTST 38400 3.87 0.00 2.25
TOTST 38400 6.70 0.00 4.38
TOTST 38400 10.07 0.00 5.91
TOTST 38400 16.13 0.00 8.82
Minex SQL Manual 32
Mine Reserves Database SQL The final type of SQL relates to the reserves database. Like the other database this type of SQL has a defined set of variables and does not use EXTERNAL variables. The STATUS command shows the defined variables.
Database SQL variable names are :- (A) Alpha (N) Numeric (R) Read (W) Write
| (NR) PIT Pit number | (NR) BENCH Bench number |
| (NR) STRIP Strip number | (NR) BLOCK Block number |
| (AR) TYPE "ORE" or "WASTE" | (AR) SEAM Seam name |
| (AR) LAYER Layer name | (ARW) SUBCODE Material subcode |
| (ARW) SCODE Surface code | (ARW) PCODE Premining code |
| (ARW) MCODE Mining code | (NRW) VOLUME Volume |
| (NRW) AREA Area | (NRW) UWEDGE % Upper Wedge |
| (NRW) LWEDGE % Lower Wedge | (NRW) REHANDLE % Rehandle |
| (NRW) RECOVERY % Recovery | (NRW) BULK Bulking factor |
| (NRW) EPERCENT % Exposed | (NRW) SPERCENT % Surface preparation |
| (NRW) DPERCENT % Drilled | (NRW) CPERCENT % Charged |
| (NRW) PPERCENT % Premined | (NRW) MPERCENT % Mined |
| (NRW) VPERCENT % Vertically mined |
| (NR) XTOP,YTOP,ZTOP Top Coord | (NR) XBASE,YBASE,ZBASE Base Coord |
| (NR) LEVNO Level number | (ARW) LAYCLASS Class name for layer|
| (ARW) NAME1 General name for block | (ARW) NAME2 General name for block|
| (NRW) 'qname' Quality Variable name |
| (NR) _SEAM Seam name | (NR) _LAYER Layer name |
| (NRW) _SUBCODE Material subcode | (NRW) _SCODE Surface code |
| (NRW) _PCODE Premining code | (NRW) _MCODE Mining code |
| (NRW) _LAYCLAS Class name for layer| (NRW) _NAME1 General name for block |
Some variables are protected. Thus the PIT Bench Strip etc are database keys and cannot be changed. These are shown above as NR (Numeric Read). Other variables are W or Write variables and can be changed.
Example 1
In the example below the hardwired database variable LAYCLASS is used for a coal classing exercise. Coal is classed into one of three classes, EXPORT, THERMAL or DOMEST. These classes can then be used for reporting and in the case of the scheduler for tracking coal tonnage within a particular class during scheduling.
SELECT A
WHERE RAWCV >= 25
Minex SQL Manual 33
AND TYPE = "ORE"
IF SELECT A
LAYCLASS = "EXPORT"
ENDIF
SELECT B
AND RAWCV < 25
AND RAWCV >= 22.5
AND TYPE = "ORE"
IF SELECT B
LAYCLASS = "THERMAL"
ENDIF
SELECT C
AND RAWCV < 22.5
AND RAWCV >= 0
AND TYPE = "ORE"
IF SELECT C
LAYCLASS = "DOMEST"
ENDIF
Example 2 Calculate distance to dump
LOCAL X,Y,Z
LOCAL A,B,C
! DUMP COORDINATES
X = 288223.929
Y =1417524.394
Z = 350
A = XBASE - X
Minex SQL Manual 34
B = YBASE - Y
C = ZBASE - Z
! ASSUME A 10% GRADIENT
C = C * 10
A = A * A
B = B * B
A = A + B
A = A **0.5
! CHECK IF HORIZONTIAL DISTANCE IS GREATER THAN RAMP LENGTH
IF A < C
A = C
ELSE
A = A
ENDIF
DUMP = A
EXIT
When this SQL is executed the menu shown in Figure 16 is displayed.
Minex SQL Manual 35
Figure 16: Reserves SQL menu
Note in the above menu there is no compile. The OK complies and runs the SQL. The SQL will automatically run on ALL pits in the database (Unless the SQL is coded to prevent this).
Minex SQL Manual 36
SQL Syntax This portion of the manual discusses the valid variable types, conditions and operands (e.g.+,-.).
Sequential Order of Statements SQL's should have their statements ordered to optimise their running. The following order is recommended:
c. Declarations d. Selections e. Arguments or actions
For example here we calculate the grid of overburden thickness by subtracting the roof grid XXXSR from TOPS.
EXTERNAL TOPS, XXXSR, XXXOB (1. Declare variable)
SELECT X (2. Make Selection)
WHERE TOPS # NULL
AND XXXSR # NULL
IF SELECT X (3. Take action)
XXXOB = TOPS – XXXSR
ELSE
XXXOB = NULL
ENDIF Data types
Data is either numeric or string. String comparisons (such as IF LITH = "SAND") are limited to four characters and the alpha numeric string must be contained within double quotes (" ").
Data declarations
Three types of variables can be declared. These are LOCAL, GLOBAL and EXTERNAL variables. The LOCAL and GLOBAL variables are temporary variables used within a macro. The EXTERNAL variables are real data variables. EXTERNAL variables are written to disk or read from disk and are EXTERNAL to the logic in the SQL. LOCAL and GLOBAL variables are declared in the SQL and can’t be written to disk. As discussed earlier in Sections 2, 3 and 4 databases such as the borehole database have known defined variables. For database SQLs there is no need to use EXTERNAL variables. For grids however the flexibility of the grid system means that users define the grids to be accessed.
LOCAL VARIABLES
Minex SQL Manual 37
LOCAL variables are internal to macros and cannot be accessed from, or written to, a database or file. Local variables are zero after computation of an interval or a grid cell. Local variables are useful for calculation purposes.
LOCAL A,B,C,D,E,F GLOBAL VARIABLES
Global variables are similar to LOCAL variables but can accumulate down a hole from interval to interval or from grid point to grid point.
GLOBAL A,B,C
EXTERNAL VARIABLES
External variables are accessed from outside the SQL (e.g. from disk) and can be written back to disk. EXTERNAL variables are only required when using SQL on 2D grids. In 2D grid SQL's external variables can be modified at runtime to take suffix names. For example, the trivial computation of roof grids as floor plus thickness, would read:
EXTERNAL FLOOR, ROOF, THICK
SELECT X
WHERE FLOOR # NULL
AND THICK # NULL
IF SELECT X
ROOF = FLOOR + THICK
ENDIF
At runtime the variable FLOOR would be changed to SF, ROOF to SR and THICK to ST. This would then compute roof grids for all seams.
Minex SQL Manual 38
Operators
SQL supports the following mathematical and logical operators as below:
= equals + addition - subtraction * multiplication / division * exponentiation
For example:
A = 5.3 A = B + C A = B - C A = B * C A = B/C A = B ** 3
SQL allows only one operation per line thus A = B + C + D is not valid. This restriction is done for compilation reasons. Writing and maintaining complex compilers doesn’t benefit Gemcom clients as it doesn’t add additional functionality. The one operation per line is simpler to compile. The example above would thus be coded as two lines:
A= B + C A = A + D
Similarly A = 15 x 10 (0.5 x B)
Could be coded as: A = 0.5 * B A = 10 ** A
A = 15 * A
SQL supports the standard logical expressions such as
> greater than < less than = equals # not equals = greater or equal to <= less or equal to
For example the following constructions are all valid:
IF A >2
Minex SQL Manual 39
IF A = 2
IF A < 2
IF A < = B
IF A # NULL
IF A B
All such logical expressions would in full appear like this:
IF A > 2
B = 4
ENDIF
Input/Output SQL's may be used to output data to the dialogue window, and input responses from users during their running. PRINT allows a variable to be written to the screen. Thus
PRINT "This is thickness" THICK. PRINT LAST "string" varname. This only works with databases such as the drillhole or reserves database. PRINT LAST allows a value to be printed at the end of a job. For example the last hole name could be printed. PRINT LAST is not valid for a grid operation. INQUIRE "string" varname. This allows user to input a variable constant at runtime. Thus
INQUIRE "what is metal price" AUVALUE
Control Constructs SQLs may be used to perform according to selection criteria.
IF
ELSE (optional)
ENDIF
The IF and ENDIF statement allow a simple condition. The ELSE statement is optional. For example:
Minex SQL Manual 40
IF GOLD > 2.0
DOMAIN = 1
ENDIF
Another example
IF GOLD < 0.02
LITH = "WASTE"
ELSE
LITH = "ORE"
ENDIF The SELECT statement allows several conditions to be grouped under a label. The label must be less than 16 characters. The AND, AND_NOT and OR statements are optional.
SELECT label
WHERE
AND (optional)
AND_NOT (optional)
OR (optional)
Example:
SELECT X
WHERE THICK # NULL
AND THICK < = 0.5
OR
WHERE ASH # NULL
AND ASH = 30
Selections are invoked through the IF SELECT statement following;
IF SELECT label
ELSE (optional)
ENDIF
Minex SQL Manual 41
The IF SELECT statement uses the group of selections in a similar way to the simple IF statement.
Example:
IF SELECT X
THICK = 0.0
ELSE
THICK = 1.0
ENDIF
Note: Several conditions may be put in the line of separators by:
Example:
WHERE A = 1 ; AND B = 2
Predefined Mathematical Functions The following functions are available.
Function Description Example
ABS(variable) Absolute value A = ABS(GOLD)
CHS(variable) Change sign A = CHS(COST)
LOG(variable) Logarithm to base 10 A = LOG(ARSENIC)
LN(variable) Logarithm to base e A = LN(ARSENIC)
SQRT(variable) Square root A = SQRT(TOTAL)
INT(variable) Take integer component A = INT(SUM)
Comments SQL's should be commented, the ! is used as the leading characters of a line for a comment.
Minex SQL Manual 42
! THIS LINE IS A COMMENT
IF GOLD < 0.02
LITH = "FOOT"
ELSE
LITH = "HANG"
ENDIF
Comment lines are not compiled.
Limitations
The SQL editor and compiler does have some limits. These are listed below. A list of limits can be produced by running a single line SQL with the term STATUS. The current Minex 5 limits (2007) are:
• Maximum of 4,096 lines per macro • Maximum no. variables/macro is as follows • DATABASE 544, LOCAL 128, GLOBAL 32, EXTERNAL 512 • Maximum length of variable names is as follows • DATABASE 16, LOCAL 16, GLOBAL 16, EXTERNAL 8 • Maximum of 16 characters for a SELECT label • Maximum of 128 SELECT clauses per macro • Maximum of 256 "IF..ENDIF" groups • Maximum of 32 "..ELSE.." alternatives within each "IF" • Maximum of 8 comma separated arguments per line • Maximum of 40 characters for "..." strings
These limits will differ on earlier software versions. Using SQL on 2D grids the users have a limit of 6 grids with 256,000 points per grid. However, if the grids used only have 128,000 points, then 12 grids can be accessed. This effectively means that for grids of 10,000 to l20,000 points (a typical coal grid), and as many as 50 grids could be accessed.