Summary of Macro Processing Examples in FactSage 8.0

The macro example files are stored in the \MACROS folder.

Equilib Macros - EquiEx*.mac

EquiExample_1.mac

This is a simple example for getting started.

It loads Equilib file Ex_CH4-O2, calculates and displays results as Equilib.txt, Equilib.tab and Equilib.xml

EquiExample_2.mac

This is a simple example for getting started.

It prompts (ASK) the user to enter the Equilib Equi*.dat file number (* = 1 to 9999) or 'Cancel' to quit.

It calculates the Equi*.TXT, Equi*.RES, Equi*.FIG, Equi*.TAB, Equi*.XML files and recycles to ASK again.

EquiExample_3.mac
This is a simple example for getting started.

It prompts (ASK) the user to enter Equilib Equi*.dat file numbers %First and %Last (* is within the range 1 to 9999.

It processes all EQUI*.dat files where * = %First to %Last and calculates the Equi*.TXT and Equi*.RES files.

EquiEx_CH4-O2-a.mac
This is the first (a) of three (a, b & c) Equilib macros where the system is (1-alpha) CH4 (25C,gas) + (alpha) O2 (25C,gas) => Adiabatic flame temperature.

This example demonstrates the three basic macro commands OPEN, CALC, SHOW.

EquiEx_CH4-O2-b.mac
Example (b) illustrates user variables and demonstrates how a macro can prompt the user to specify which type of output he wants - simple calculation or save calculation or show results in various formats.

This is a good example of :

  • Excel Worksheets
  • text spreadsheets
  • DOCASE ... CASE 1 ... CASE 2 ... ENDDO
  • EquiEx_CH4-O2-c.mac
    Example (c) is an advanced macro where the user interacts with an Excel Worksheet and text spreadsheet.

    The macro :

  • opens the the Worksheet Ex_CH4-O2.xls or the text spreadsheet Ex_CH4-O2.txt.
  • creates a new spreadsheet if one does not exist and fills it with values of Alpha and Delta(H)
  • loads the Equilib file Ex_CH4-O2, reads Alpha and Delta(H) values from the file, calculates the flame temperature and writes this value back to the spreadsheet.
  • by an iterative procedure it determines the value of (alpha) that maximizes T. This value is posted on the screen and highlighted in the spreadsheet.

    Note: if you want an efficient way to calculate the maximum adiabatic flame temperature of a gas use module FactOptimal.

  • EquiEx_CH4-O2_Figure.mac
    This example is for advanced users. It shows how to plot equilibrium results and save figures.

    Figure 1 - EX_CH4-O2_Figure-1.fig - is a plot of the adiabatic temperature versus the page (1- 21).

  • defines the variables of the axes and their limits
  • plots the results
  • saves the figure.

    Figure 2 - EX_CH4-O2_Figure-2.fig - is a plot activity versus page for the 8 most prominent species.

  • defines the variables of the axes and their limits
  • identifies the 4 most prominent species with respect to activity
  • plots the results
  • saves the figure.

    Both figures are then displayed via the VIEWFIG command.

  • EquiEx_CH4-O2_Set-Activity.mac
    This example is for advanced users. It shows how to define the equilibrium P(O2(g)) and a(C(s)).

    The macro :

  • opens the stored example Ex_CH4-O2.dat - CH4 (25C,gas) + (alpha) O2 (25C,gas) => Adiabatic
  • identifies O2(g) as an 'ACTIVITY species' and sets P(O2) equilibrium = 1e-5
  • redefines the amounts of reactant CH4 and O2, defines the final temperature 1600, and defines Delta H (Z) = 'blank' (i.e. the reaction is no longer adiabatic)
  • calculates the equilibrium and displays the results where P(O2) = 1e-5
  • drops P(O2) from the ACTIVITY calculation
  • identifies C(s) as a new 'ACTIVITY species' and defines equilibrium range of values of log(a(C)) = -5 -4 -3 and -2
  • calculates the equilibrium and displays the results where a(C) = 1e-5, 1e-4, 1e-3 and 1e-2
  • EquiEx_CMD.mac
    This macro shows how to execute Command Prompt Windows commands via the macro processing command CMD.

    The Command Prompt (or command shell) is a feature of Windows that provides an entry point for typing Windows commands including former MS-DOS commands and is typically only used by advanced users.

    Run this macro and the Command Prompt Windows commands will :

    • display a list of the Command Prompt commands available on your computer
    • display detailed help on the COPY command
    • copy all .fig files from the FactSage \FIGURE folder to the Windows temporary folder
    • list the copied .fig files stored in the Windows temporary folder
    • delete the .fig files stored in the Windows temporary folder
    EquiEx_Functions_and_Procedures.mac
    This macro shows user-defined $Functions (FUNCTIONS ... END FUNCTIONS) and subroutines (PROCEDURES ... END PROCEDURES).

    In the example we scan the figures and macros folders and return number (%Scan_number) of *.fig and *.mac files.

    In addition the size (%Scan_big_size) and name (%Scan_big_name) of the largest file in the folder are determined.

    Functions and subroutines perform identical operations except that the $Function also returns a value.
    In this example function $My_Total_Files() and subroutine Sub_SCAN_Files() perform the same tasks and $My_Total_Files also returns the total number of files.

    EquiEx_List_Files.mac
    Example of scanning a directory and listing the files.

    Here we scan for '*.fig' files in the figures directory.

    %1 = $SCAN_DIR(c:\FactSage\Figures\*.fig)

  • This initiates a scan of all c:\FactSage\Figures\*.fig file names.
  • Value of %1 is the number of files (or '0' if nothing found)

    %1 = $SCAN_DIR()

  • Subsequent calls without the mask return the name of each file.
  • %1 is the short name of each file or '0' when done.
  • EquiEx_List_Functions.mac
    Examples of the functions :

  • $FILEDIR(): file directory

  • $CONSTANT(): constants and conversions

  • $Functions(): $Abs, $Exp, $Ln, $Log10, $Int, $Fix, $Mod, $Sgn, $Rnd, $RndInt, $Min, $Max, $Mean, $MinI, $MaxI

  • $MATH(): mathematical expression that includes the operators, + - / * ^, as well the common functions abs(), ln(), log10(), exp(), cos(), sin(), tan(), acos(), asin(), atan(), fix(), int(), sqr(), cbr() and fact().

  • $ELEMENT_NAME(), $ELEMENT_MASS(), $ELEMENT_NUMBER(), $MOLWT(): chemical functions
  • EquiEx_List_Results.mac
    Simple example of common thermochemical $variables$ to list the input and calculated values
    - note $variables$ are case sensitive.
    EquiEx_List_Thermo.mac
    An advanced example of thermochemical $variables$ including thermochemical, chemical and physical properties for compounds and solutions.
    EquiEx_List_Thermo_Functions.mac
    An advanced example of thermochemical $variables$ including solution properties and components.
    This is the same as EquiEx_List_Thermo.mac except here the $function codes are also displayed.
    EquiEx_New_in_7.0.mac
    This macro uses variables and commands that are new in FactSage 7.0 :

  • $STRING() function for WRITE and APPEND commands
  • 2-dimensional arrays e.g. %A1(2,3) %B2(0:2,4:6)
  • dynamic allocation (DIM) and reallocation (REDIM) of %variables
  • array functions $ARRAY_DIM() $ARRAY_COUNT() $ARRAY_LBOUND() $ARRAY_UBOUND()
  • $ENUM() function to enumerate the members of an array
  • user-defined subroutines (PROCEDURES)
  • user-defined $Functions (FUNCTIONS)
  • DEBUG /ON to activate 'DEBUG Macro Window', DEBUG 'caption' etc.
  • TAB_LINE(=) etc tabular commands used in conjunction with APPEND and text files.
  • EquiEx_New_in_7.1.mac
    This macro lists the .mac files that are new in FactSage 7.1.
    EquiEx_Set_Page.mac
    After loading an Equi*.dat file and calculating multiple pages of results (for example EquiEx_CH4-O2.DAT has 21 pages of results) this example shows how to accessing each page after multiple pages of results have been calculated.

  • SET PAGE N // to access a page where N lies between 1 and the total number of pages $PAGES
  • PROCEDURES // PROCEDURE Sub_AccessPage(%Page) access page %Page
  • PAUSE // Wait for the user to click 'Go' to resume processing
  • EquiEx_SET_Variables.mac
    This example first calculates the adiabatic temperatures for the reaction (1-A) CH4 + (A) O2 and then uses the SET command to change the databases, reactants, species selection and type of calculation. For example:

  • SET REACTANT DEL CH4 // Delete Reactant CH4
  • SET REACTANT ADD SO3 liquid #2 // Add new reactant SO3(l) as steam #2
  • SET REACTANT C2H6 MASS <1-A> // Redefine Reactant masses
  • SET UNITS TK BAR // Redefine units T(K) and P(bar)
  • SET FINAL A 0.1 // = 0.5
  • SET SELECT COMPOUND - // remove all compounds
  • SET SELECT SOLUTION - // remove all solutions
  • SET SELECT SOLID + FTdemo C // select FTdemo C solids
  • EquiEx_Sort_Functions.mac
    Example of the sort Functions :

  • SORT_INCI(), SORT_INC() - Sort Increasing
  • SORT_DECI(), SORT_DEC() - Sort Decreasing
  • $RND(0,100)- random real (floating point) number used in the sorting.
  • EquiEx_Xls_Simple_IO.mac
    Example of simple interactive Input and Output with Excel Worksheets and Text Spreadsheets.
    The Excel files must be *.xls or *.xlsx
    The Text files must be *.txt or *.tab.

    Note this example works with any saved Equi*.dat file.

    Ex_Streams\EquiEx_Streams.mac
    This macro is for advanced users and shows how to use streams in a simplified process. The process consists of the desulfurisation of hot metal by the top slag.

    The process is broken down into 3 reactions:

  • A fraction of the hot metal is equilibrated with a fraction of the slag in R1
  • In R2, the hot metal product from R1 is mixed back with the remaining hot metal (hot metal homogenisation)V
  • In R3, the slag products from R1 (including liquid slag and pure compounds) are mixed with the remaining top slag (slag homogenisation)

    Reactions R1, R2 and R3 are repeated at each time step, until the total process duration is reached

    The simulation i/o is stored in the Excel file Ex_Streams_inoutput.xls and includes a chart that plots the process in real time. The Excel file can be manually edited and inital conditions changed.

    As a backup all the original files are stored in the folder Ex_Streams\Original_Files\.


  • Phase Diagram Macros - PhasEx*.mac

    PhasExample_1.mac

    This is a simple example for getting started.

    The macro shows how to :
  • load a saved Phas*.dat
  • calculate the Phase Diagram
  • save the calculated figure in a (*.fig) file
  • display the *.fig file using the Figure module.
  • PhasExample_3.mac

    This macro processes all the PHAS*.dat files where * = %1 to %LAST (in the range 1 to 9999).

    The macro shows how to :

  • prompt the user to enter the default directory (%DIR)
  • prompt the user to enter the first (%1) and last (%LAST) file numbers.
  • calculate the Phase Diagram
  • save the figure output in phas*.fig file that can be displayed by Figure & Viewer.
  • save the figure output in phas*.bmp bitmap file that can be imported into Word and Power Point.
  • PhasEx_Calc_All_PDs.MAC - new in FactSage 7.2

    This macro is particularly useful for database developers who wish to recalculate phase diagrams using revised databases. The macro loads each Phas*.dat that is stored in a folder, calculates the phase diagram and then displays the calculated figures in a web browser (htm) format. If the PHAS*.dat also contains a stored diagram it is displayed as well. In this manner the developer can compare the newly calculated diagram with the old one.

    Copy PhasEx_Calc_All_PDs.MAC to the folder where the Phas*.dat files are stored. Run 'Phase Diagram' and then 'Phase Diagram - Components Window > File > Macro Processing > Run .... PhasEx_Calc_All_PDs.MAC'.

    The macro :

  • loads each Phas*.dat file and calculates the phase diagram
  • the calculated Phase Diagram is stored in the \BMPs\ folder as a bmp file
  • both the calculated figure and the previously saved figure are displayed side by side in an htm file (Phas_Calc_All_PDS.htm)

    In order to permanently save a record of all calculated and saved figures use 'Word' to open Phas_Calc_All_PDS.htm and save as a *.pdf file - for example Phas_Calc_All_PDS.pdf



  • Christopher W. Bale
    CRCT, 2020