# Keyword Substitution Use {term}`project keys` to parameterize the fixed project from [Project Setup](project_setup.md). The rod radius changes between solves. The other project inputs remain unchanged. Later pages use the same mechanism for parameter scans and more complex template calculations. ## Create A Template Rename `layout.jcm` to `layout.jcmt` to create a template {term}`project support file`. Replace the fixed rod radius with a printf-style placeholder: ```{literalinclude} ../../demos/documentation_tutorials/getting_started/keyword_substitution/layout.jcmt :language: jcm :lines: 23-30 ``` The name inside the placeholder is the project key name. The `e` and `f` format codes accept numeric values. When {func}`solve ` receives project keys, JCMsuite renders `layout.jcmt` as `layout.jcm`. JCMsuite then runs the project. The source template remains unchanged for the next solve. The template renderer supports these replacement formats: | Value type | Placeholder | Format Code | Output format | | -------------- | ---------------------------- | ----------- | ------------------------------------------ | | Integer | `%(count)d` or `%(count)i` | `d` or `i` | Decimal integer | | Floating-point | `%(radius)e` or `%(radius)f` | `e` or `f` | Floating-point value | | Complex | `%(permittivity)g` | `g` | JCMsuite complex value `(real, imaginary)` | | String | `%(name)s` | `s` | String value | The `g` format code formats complex values. For a complex scalar, it renders the real and imaginary parts as a JCMsuite complex pair. For example, `1.967 + 4.443j` renders as `(1.967, 4.443)`. Numeric vectors and matrices can also contain complex values. Each complex element uses the same pair representation. Numeric placeholders can include an optional one- or two-digit precision modifier before the format code. The modifier controls the precision used by the `e`, `f`, and `g` formats: ```jcm Wavelength = %(wavelength)6e Radius = %(radius)3f Permittivity = %(permittivity)8g ``` Without a modifier, the renderer uses its default numeric precision. The modifier is a precision value, not a project key name or a field width. ## Use Arrays Numeric project keys accept Python lists, tuples, and NumPy arrays. A one-dimensional value renders as a JCM vector. A two-dimensional value renders as a JCM matrix. For integer placeholders, every element must be an integer. For example, use these template placeholders: ```jcm GlobalPosition = %(position)e RelPermittivity = %(permittivity)e ``` Then provide a vector and a matrix in the project keys: ```python keys = { "position": [0.0, 1.0, 0.0], "permittivity": [[1.0, 0.0], [0.0, 1.0]], } ``` ## Use Nested Project Keys Project keys can contain nested values. Use a colon-separated path in the placeholder to select a nested project key. See [Templating](../project_tools/templating.md) for path resolution rules and multi-level examples. ```jcm RelPermittivity = %(material:permittivity)e ``` Provide the nested project keys in `keys`: ```python keys = { "material": { "permittivity": 2.3104, }, } ``` See [Templating](../project_tools/templating.md) for the complete template workflow. ## Run The Project ```{literalinclude} ../../demos/documentation_tutorials/getting_started/keyword_substitution/run.py :language: python ``` The project keys supply the rod radius as $r = 0.3\,\mathrm{\mu m}$. {func}`solve ` renders the layout template with the radius value and returns a {class}`SolveResult `. The script prints the exterior energy flux. The script also displays the intensity of the exported electric field. ## Inspect The Geometry Use {func}`geo ` with the same project keys to inspect the rendered mesh before you run the electromagnetic solve: ```{literalinclude} ../../demos/documentation_tutorials/getting_started/keyword_substitution/run_geo.py :language: python ``` The call renders `layout.jcmt`, generates `grid.jcm`, and opens the grid in JCMview. ## Project Files
run.py ```{literalinclude} ../../demos/documentation_tutorials/getting_started/keyword_substitution/run.py :language: python ```
run_geo.py ```{literalinclude} ../../demos/documentation_tutorials/getting_started/keyword_substitution/run_geo.py :language: python ```
layout.jcmt ```{literalinclude} ../../demos/documentation_tutorials/getting_started/keyword_substitution/layout.jcmt :language: jcm ```
materials.jcm ```{literalinclude} ../../demos/documentation_tutorials/getting_started/keyword_substitution/materials.jcm :language: jcm ```
mie2D.jcmp ```{literalinclude} ../../demos/documentation_tutorials/getting_started/keyword_substitution/mie2D.jcmp :language: jcm ```
sources.jcm ```{literalinclude} ../../demos/documentation_tutorials/getting_started/keyword_substitution/sources.jcm :language: jcm ```
## Next Step Continue to [Parameter Scan](parameter_scan.md) to solve the project for many radius values.