jcmt2jcm.py

jcmwave.jcmt2jcm(jcmt_file, keys, outputfile=None)

Process template .jcmt file with embedded python blocks to create a .jcm.

Parameters:
  • jcmt_file (filepath) – pathname of the .jcmt file to be processed.
  • keys (dictionary) – contains values for template parameter substitution.
  • outputfile (filepath) –

    sets file path of .jcm output file.

    If not set, the output file has the same basename as the jcmt_file input file, but with extension .jcm (jcmp), and is placed in the same directory

To embed a python into a file use the tag <? to start a script block and use ?> to end a script block.

Outside a script block one refers to the values of a parameter by the following tags:

  • %(parName)i, %(parName)d –> integer values
  • %(parName)f, %(parName)e –> float values
  • %(parName)[3-15]e –> rounded float values, e.g. %(parName)10e truncates floating point number to ten digits.
  • %(parName)s –> string values

Here, parName is the parameter name. The tags are the substituted by the value of the field “parName” if present in the dictionary “keys” (e.g. %(parName)i --> keys['parName']) and if the types are matching (integer, floats, and string). Integer and float vector arguments are also allowed.

Simple Example: Definition of a material block (materials.jcm file). The user provides the refractive index, e.g:

>>> keys['refractive_index'] = 1.5)

The refractive index is converted to the relative permittivity value needed as needed by JCMsolve.

>>> ... # non script block
Material {
  MaterialId = 1
<? # start script block
keys['permittivity'] = keys['refractive_index']**2
?> # end python block
  RelPermittvity = %(permittivity)e # keyword substitution
  RelPermeability = 1.0
}
...

After processing the file the following Material definition is created,

>>> ... # non script block
Material {
  MaterialId = 1
  RelPermittvity = 2.25
  RelPermeability = 1.0
}