Component development - mccode-dev/McCode GitHub Wiki
Basic structure
- For instrument/comp/particle parameters and variable scope see table Variables and Scopes
- Basic tips for Writing Components (includes an exercise and a walkthrough of Slit.comp)
Parameter naming and units
Please consult and adhere to our
- McStas NOMENCLATURE and units of SI and neutron standard units (wavelengths in Å, energy in meV, cross-sections in barns).
- McXtrace NOMENCLATURE and units of SI and X-ray standard units (wavelengths in Å, energy in keV, cross-sections in barns or some cases 1/m).
- Inspire from existing components of similar type and choose similar variable names.
In-component documentation
- Writing a parsable mcdoc component header
Component (unit) testing
- Write an example instrument
Run mctest
- The mctest tool can be used to test a set of McStas/McXtrace instruments
Tips and tools for improving quality of your code
- Keep it simple - complexity means a harder time debugging.
- Choose algorithmic simplicity / readability over performance.
- Document (in language that your colleague also understands) what your code is meant to do. You will even not fully remember yourself in a matter of months!
- Please always be mindful and act on / minimise the number warnings from your c-compiler!
- Run the mccode linter
- If you experience weird crashes it is time for Debugging the c-code
Code (indentation) style
- Please use the utiltity (python-)script
McCode/devel/bin/mccode-clangformatto format your new component according to the McCode standard./devel/bin/mccode-clangformat --file mcstas-comps/contrib/My_new.comp
A tip for a good workflow
- We recommend to use the option to Build your own McStas or McXtrace via conda‐forge directly from your personal fork of McCode.