Macro

Da ArcoWiki.

Macro are sub-routines that allow to compact a sequence of instructions in a single command.
The macro command can be in the main program or in an external file.

If the macro description is inside the DMIS program, it should be written at the beginning of it but, in any case, prior to the execution of the Macro command itself.

$$ Example of a MACRO declaration

M(foro)=MACRO/off_x,off_y,'nome_ci'
DECL/LOCAL,DOUBLE,r_foro,z_mis
r_foro=ASSIGN/6.25
z_mis=ASSIGN/-2.5
F(@nome_ci) = FEAT/CIRCLE, INNER, CART, off_x, off_y, z_mis, 0, 0, 1, r_foro*2
MEAS/CIRCLE, F(@nome_ci), 4
GOTO/off_x, off_y, 7
PTMEAS/CART, off_x+r_foro, off_y, z_mis, -1, 0, 0
PTMEAS/CART, off_x, off_y+r_foro, z_mis, 0, -1, 0
PTMEAS/CART, off_x-r_foro, off_y, z_mis, 1, 0, 0
PTMEAS/CART, off_x, off_y-r_foro, z_mis, 0, 1, 0
GOTO/off_x, off_y, 7
ENDMES
$$ End of Macro Declaration
ENDMAC
$$ instructions
$$ instructions

$$ Recall to execute the macro

CALL/M(foro),12.5,12.5,foro1
$$ instructions
$$ instructions


If the macro is located in an external file (for example to make sure that the macro can be shared between more programs), then the macro file shall be inserted in the program using the procedure to Include an External Macro File at the beginning of the program using an ‘EXTFIL’ command. In this case the macros are recalled from the specified external file.

$$ Use of an external file containing macro declaration

EXTFIL/DMIS,'c:\cim\MACRO.dmi'


The external macro file has “.DML” extension, begins with DMISMD/ and ends with ENDFIL/.
Inside of the file, the syntax is the same as a regular DMIS program.


$$ Declaration of different Macro in an external file
DMISMD/'module_name'

$$ First Macro declaration
M(macro_1)=MACRO/passedtext
TEXT/OPER,CONCAT('You passed the following text to the macro: ',passedtext)
ENDMAC
$$ Second Macro declaration
M(macro_2)=MACRO/num1,num2
DECL/DOUBLE,sumres
sumres=ASSIGN/num1+num2
EXT/OPER,CONCAT('The sum of the 2 numbers is: ',STR(sumres))
ENDMAC

ENDFIL