What's New in Macro Processing |
(January 2018)
What follows are summaries of the more important programming changes in Macro Processing that have appeared in:
Macro Processing - called from 'Equilib > Reactants Window > File > Macro processing > Run macro ...'
FactSage 5.5 (2007)
FactSage 6.3 (2012)
DOCASE
The CASE statements within the DOCASE ... ENDDO commands now include a test for a range
('value1' TO 'value2') and a logical condition test (IS 'operator < > <> >= or <=' 'value').
New $Variable$s
New variables have been introduced into 6.3 macro processing.
SET OUTPUT
New output format commands for the display in the Results Window
SET SELECT
In FactSage 6.2 problems were encoutered with phase and species selection 'SET SELECT' commands of the type:
A new type of variable called a 'macro $function()' has been introduced.
Macro $functions have arguments
contained within the parentheses, (). The arguments are separated by spaces
or commas and may be a %variable, a thermochemical $variable$, but not another
$function. A line in the macro file may have several $functions.
The new functions include:
New SET variables have been added, including:
Examples: $MATH(cos(100)^2 + sin(100)^2) => 1.
$MATH((5!-(2-5)^2)/(sqr(abs(2^4-3^5))) => 7.36732...
Other variables and commands have been added, including:
The Macro Processing Manual has been updated to include the new variables.
New *.mac files have been added to the Macro directory of examples:
- an example of the new $functions is given in 'EquiEx_List_Functions.mac'.
- an example of most thermochemical variables is given in 'EquiEx_List_Thermo.mac'.
- an example of SET SELECT is given in 'EquiEx_Set_Variables.mac'.
DO CASE %1
CASE 0 1 2 // If %1 has the value 0, 1 or 2
(macro lines)
CASE 3 TO 50.5 // If %1 is in the range 3 to 50.5
(macro lines)
CASE IS <= -100 // If %1 is less than or equal to -100
(macro lines)
CASE IS <> 1000 // If %1 is not equal to 1000
(macro lines)
CASE ELSE
(macro lines)
ENDDO
$TEMPDIR\ = temporary directory - environment variable defined by Windows
Extensive Property Changes:
$E_DOK$ = 'OK' when delta values calculated (e.g. initial conditions defined)
$E_DC$ = Delta Cp heat capacity
$E_DF$ = Delta Gibbs Free Energy
$E_DG$ = Delta Gibbs Free Energy
$E_DH$ = Delta Enthalpy
$E_DS$ = Delta Entropy
$E_DV$ = Delta Volume
Input Reactant Values:
$R_SOK$ = 'OK' when states are known (e.g. initial conditions defined)
$R_p*$ = phase state (1=gas, 2=liquid, 3=aqueous, 4=solid, 5=solution) of reactant *
$R_s*$ = short state (g, l, aq, s, s2) of reactant *
$R_S*$ = full state (gas, liquid, aqueous, solid, solid-2) of reactant *
Chemical and Physical Properties of Solution *:
$E_CP*_Evolts$ = aqueous Eh
$E_CP*_pH$ = aqueous pH
$E_CP*_total_molality$ = total solute molality
$E_CP*_ionic_strength$ = ionc strength
$E_CP*_osmotic_coeff$ = osmotic coefficient
$E_CP*_magnetic_moment$ = magnetic moment
$E_CP*_Curie_T$ = Curie temperature
$E_CP*_viscosity$ = viscosity
$E_CP*_surface_tension$ = surface tension
$E_CP*_thermal_cond$ = thermal conductivity
$E_CP*_electrical_cond$ = electrical conductivity
$E_CP*_surface_energy$ = surface energy
$E_CP*_emissivity$ = emissivity
$E_CP*_density$ = density
$E_CP*_thermal_expan$ = thermal_expansivity
$E_CP*_bulk_modulus$ = bulk_modulus
$E_CP*_Grueneisen$ = Grueneisen
$E_CP*_a_lattice$ = lattice parameter a
$E_CP*_c_lattice$ = lattice parameter c
Many of new variables and commands are used in the updated macro file EquiEx_List_Results.mac located in the macros folder.
SET OUTPUT FORMAT FACT CHEMSAGE // FACT and then ChemSage format
SET OUTPUT FORMAT CHEMSAGE FACT // ChemSage and then FACT format
SET OUTPUT FORMAT FACT // FACT format only
SET OUTPUT FORMAT FACT CHEMSAGE // ChemSage format only
SET SELECT COMPOUND + (or - !) [NICK [SPECIES]]
SET SELECT SOLUTION + (or - !) [NICK-Phase [SPECIES]]
SET SELECT GAS (or LIQUID AQUEOUS SOLID) + (or - !) [NICK [SPECIES]]
In FactSage 6.3 these problems have been fixed and the SELECT commands thoroughly tested.
SET SELECT
New data search commands have neen added - SET DATASEARCH GION (NOGION AQUA NOAQUA CXHY MINS1)
SET DATASEARCH GION (NOGION) : include (exclude) gaseous ions (plasmas) SET DATASEARCH AQUA (NOAQUA) : include (exclude) aqueous species SET DATASEARCH CXHY 'value 1-99' : CxHy .. maximum value of x in organic molecules SET DATASEARCH MINS1 (MINS2) : minimum number of solution components is 1 (2)SET ESTIMATE
New commands for redefining the estimatete of final property have been added - SET ESTIMATE T (P V ALPHA)
SET ESTIMATE T 'value' : redefine the estimate of final T SET ESTIMATE P 'value' : redefine the estimate of final P SET ESTIMATE V 'value' : redefine the estimate of final V SET ESTIMATE ALPHA 'value' : redefine the estimate of final ALPHAExamples of the new variables and commands can be found in the updated macro files EquiEx_SET_Variables.mac and EquiEx_List_Results.mac located in the macros folder.
OLE Commands for Excel Worksheets
The number of OLE (Object Linking and Embedding) commands for Excel Worksheets has been expanded. It is now possible to open both *.xlsx type files in addition to *.xls. New CLOSE and QUIT commands enable you to save and close the Excel link. There are new options to dynamically define cell size and text font, color, alignment, etc. in the spreadsheet. Examples of the new commands are presented in EquiEx_Xls_Simple_IO.mac which has been rewritten for FactSage 6.4 and is located in the Macros Directory.
OLEn CLOSE // close the Worksheet; Excel will prompt you to save OLEn CLOSE SAVE // close and save the Worksheet without prompting OLEn CLOSE SAVE 'ExcelFileName' // close and save in a *.xls or *.xlsx file OLEn QUIT // close the Worksheet without saving OLEn CELLS ALL 'options' // apply options to all cells in the Worksheet OLEn COLUMNS 'F:F' 'options' // apply options to column F OLEn ROWS '2:3' 'options' // apply options to rows 2 and 3 OLEn RANGE 'B1:C4' 'options' // apply options to a range OLEn NAME 'NAME' 'options' // apply options to a range name List of 'options' for OLEn CELLS (COLUMNS ROWS RANGE NAME): AUTOFIT // autofit column width // ex: OLE1 CELLS ALL AUTOFIT autofits all cells in the Worksheet BOLD TRUE (FALSE) // Bold text - TRUE is default. BOLD may be replaced by: // ITALIC, SHADOW, STRIKETHROUGH, SUBSCRIPT, SUPERSCRIPT or UNDERLINE // ex: OLE1 ROWS 2:3 BOLD CENTER (LEFT RIGHT) // alignment of contents in each cell CLEAR // clear the contents in each cell COLOR 'color' // text color where 'color' is one of BLACK, MAROON, GREEN, // OLIVE, NAVY, PURPLE, TEAL, GRAY, SILVER, RED, LIME, YELLOW, BLUE, FUSHIA, AQUA or WHITE COLOR RGB(i,j,k) // RGB color where i, j and k in the range 0 - 255 // ex: OLE1 RANGE A1:C:4 COLOR RGB(0,0,255) - same as 'COLOR BLUE' FONTSTYLE 'font style' // font style e.g. 'Bold_Italic' - use _ for spaces HEIGHT 'value' // set rows to a common height SIZE 'value' // set font size to a common value WIDTH 'value' // set columns to a common widthExamples of user-defined functions and procedures are presented in EquiEx_New_in_7.0.mac and EquiEx_Procedures.mac stored in the Macros folder.
FactSage 7.1 (2017)
All the macro files stored in the Macros folder have been checked with FactSage 7.1 and the files updated where necessary.
If you unfamiliar with macro processing go to the Reactants Window, click on 'File > Macro processing > Run macro > Macros Directory ...' and select EquiEx_SET_Variables.mac.
If you want to see the hidden generated information when you load and run one of your saved Equi*.dat files then select EquiEx_List_Results.mac and specify the Equi*.dat file.
For an example of how to open and interact (read and write) with an Excel Worksheet (.Xls and .xlsx files) and a Text Spreadsheet then select EquiEx_Xls_Simple_IO.mac.
For a complete list of examples click on 'Reactants Window > File > Macro processing > Macro Processing - Examples ...'.
The Macro Processing Manual, Summary and Examples have been revised to reflect the changes and additions to the program. |
|
1. %DIR
The macro command %DIR is used to define the user default directory.
If the macro file is reading and writing various files (.dat, .xls, .txt, etc. )
it is recommended that all the files including the .mac file be stored in the same folder,
and it is recommended you should set the value of %DIR to this folder.
For example, if the macro file is stored in c:\FactSage\Private\MyMacro.mac then the following line could
be inserted at the beginning of the .mac file:
%DIR = c:\FactSage\Private\ // Directory of the file c:\FactSage\Private\MyMacro.mac
Alternatively, the following lines are a more general way to define the default location and this does not require you to enter the actual path.
VARIABLE %Macro
%Macro = $MACFILE // Full name of the current macro file - e.g. c:\FactSage\Private\MyMacro.mac
%DIR = $FILE_DIR(%Macro) // Set user default directory to the directory of the macro file - e.g. c:\FactSage\Private\
2. New Plotting Commands
The new SET PLOT commands mirror the options available in the Equilib Post Processor and Plot Species Selection Windows - 'Equilib Results Window > Output > Plot > Plot Results ...'.
Consult these Post Windows for clarification of the following SET PLOT commands.
As an example, load and run the new macro file EquiEx_CH4-O2_Figure.mac that is stored in the Macros folder.
SET PLOT AXIS/CAPTION/LABELS/DISPLAY/SELECT: SET PLOT AXIS Y-AXIS (X-AXIS) a (n etc.) Y (log10(Y) ln(Y) ...) 'minimum' 'maximum' 'step' SET PLOT CAPTION TITLE 'figure title' // Figure title SET PLOT CAPTION SUBTITLE 'figure sub-title' // and subtitle SET PLOT CAPTION Y-TITLE (X-TITLE) 'axis title' // Axes captions SET PLOT CAPTION LABEL 'X coordinate' 'y coordinate' "label #1" // User-defined labels SET PLOT CAPTION LABEL 'X coordinate' 'y coordinate' "label #2" // SET PLOT CAPTION LABEL .... etc. // SET PLOT LABELS SIZE 2 (2 - 24) // size of labels (Post Processor Window) SET PLOT LABELS NO 2 (1 - 9) // number per line SET PLOT LABELS CHEMICAL [INTEGER or NONE) // type of label SET PLOT LABELS OFFSET ON (OFF) // offset labels above the coordinate SET PLOT DISPLAY COLOR ON (OFF) // line color on (or B/W) (Post Processor Window) SET PLOT DISPLAY COLORS 9 12 2 // line colors 0 - 14 (Post Processor Window) SET PLOT DISPLAY COLORS RED BLUE GREEN // line color names BLACK MAROON ... AQUA // 0 = BLACK, 1 = MAROON, 2 = GREEN, 3 = OLIVE, 4 = NAVY, 5 = PURPLE, 6 = TEAL, // 7 = GRAY, 8 = SILVER, 9 = RED, 10 = LIME, 11 = YELLOW, 12 = BLUE, 13 = FUSHIA, 14 = AQUA SET PLOT DISPLAY REACTANTS ON (OFF) // list reactants in the title (if CAPTION TITLE not set) SET PLOT DISPLAY FILE_NAME ON (OFF) // list source file in subtitle (if CAPTION SUBTITLE not set) SET PLOT DISPLAY SOURCE ON (OFF) // include data source in species label (Plot Species Selection Window) SET PLOT DISPLAY PHASE ON (OFF) // include phase name in species label SET PLOT DISPLAY NAME ON (OFF) // include species name in species label SET PLOT DISPLAY PAGE ON (OFF) // include page number in species label SET PLOT SELECT CLEAR // clear current species selection SET PLOT SELECT MASS MOLE (GRAM) // mass units SET PLOT SELECT ORDER INTEGER (MASS FRACTION or ACTIVITY) // order with respect to integer or mass ... SET PLOT SELECT TOP 1 (2 ....) // select top species as defined in ORDER SET PLOT SELECT IGNORE ON (OFF) // ignore species and phase that have no mass SET PLOT SELECT STABLE PHASE (LIQUID SOLID SOLUTION) // select all stable phases (all s table pure liquids ...) SET PLOT SELECT SPECIES 2 5 8 // select species 2 5 and 8
3. Set Activity - EquiEx_CH4-O2_Set-Activity.mac
There is a new macro file, EquiEx_CH4-O2_Set-Activity.mac, that shows how to define the equilibrium P(O2(g)) and a(C(s)) in a system.
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
4. [Streams]
In Macro Processing a [stream] (MIXT*.dat file) is often created and then used (recycled) as input for the next part of the simulation. Sometimes the same EQUI*.dat file containing particular [streams] is repeatedly opened in order update the new [stream] values.
Macros and Recycling [Streams]An example of recycling [streams] is given in the new macro file EquiEx_Streams.mac that is stored in the folder Macros\Ex_Streams. The example shows how to use streams in a simplified steelmaking 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
In R3, the slag products from R1 (including liquid slag and pure compounds) are mixed with the remaining top slag Each phase (i.e. hot metal, liquid slag and pure compounds) is saved in a [stream] and passed to the next Equilib file or to the next time step Reactions R1, R2 and R3 are repeated at each time step, until the total process duration is reached.
FactSage 7.2 (2018)
PhasEx_Superimpose_Figs.mac is a new macro file in FactSage 7.2.
This Phase Diagram macro is particularly useful if you wish to superimpose several calculated phase diagrams into one figure. . Copy PhasEx_Superimpose_Figs.mac to the folder that contains the *.fig files of the type MyName-1.fig, MyName-2.fig, MyName-3.fig ... Run 'Phase Diagram' and then 'Phase Diagram - Components Window > File > Macro Processing > Run .... PhasEx_Superimpose_Figs.mac'. The macro:
The screenshot shows four Ag-Au-Bi isothermal sections superimposed into one figure. |
|
PhasEx_Calc_All_PDs.mac is a new macro file in FactSage 7.2.
This Phase Diagram 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 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:
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. |
|
FactSage 7.3 (2019)