Inter-component transformations
Kristian Nielsen
kristian.nielsen at risoe.dk
Wed Feb 3 14:41:26 CET 1999
Hi Philipp,
> When I use the option --trace, I get, for example, following result:
>
> ENTER:
> COMP: "source"
> STATE: 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
> STATE: -0.00524055, -0.0428509, 0, -2.85016, -2.11707, 1977.96, 0.000270516, 0, 0, 1
> COMP: "fermi"
> STATE: -0.00825353, -0.0428509, -0.1, -4.48881, -2.11707, 1977.96, 0.000270516, 0, 0, 1
> The x and vx value have changed between the component source and fermi
> without any reason (there should only be a translation in the z
Indeed, this looks strange. I tried running your example myself, and I
could not repeat the strange behaviour:
------------------------------------------------------------------------
bash-2.01$ ./instr1 --trace -n1 -s1 WEL=2
ENTER:
[...]
COMP: "source"
STATE: 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
STATE: 0.0340188, -0.0105617, 0, 4.47967, 4.72242, 1977.95, 0.000364659, 0, 0, 1
COMP: "fermi"
STATE: 0.0340188, -0.0105617, -0.1, 4.47967, 4.72242, 1977.95, 0.000364659, 0, 0, 1
[...]
------------------------------------------------------------------------
I have seen something like this before being caused by compiler bugs. I
think the pgcc (pentium-optimized compiler) for one got the coordinate
transformations wrong with aggressive optimization. Could you try
running the example without compiler optimizations, or is there anything
special I should do to repeat the results you got?
> I have another question: Is it possible to use functions in a component
> and how could that be realized?
Hm, I am not completely sure I understand what you are asking here. I
think you mean to write a complex component, where part of the code is
put in a special C function that is part of the component source file?
One way is to put the function definition in the DECLARE section:
------------------------------------------------------------------------
DEFINE COMPONENT My_comp
[...]
DECLARE
%{
double foo(double a) { return a*a; }
%}
[...]
TRACE
%{
... foo(vx*vx+vy*vy) ...
%}
------------------------------------------------------------------------
In the current version of McStas this may not work if the component is
used several times in a single instrument. This will be fixed in a later
version, but for now a workaround is to protect the declaration with
#define:
------------------------------------------------------------------------
DEFINE COMPONENT My_comp
[...]
DECLARE
%{
#ifndef MY_COMP_DECLARE
#define MY_COMP_DECLARE
double foo(double a) { return a*a; }
#endif
%}
------------------------------------------------------------------------
The #ifndef / #endif ensures that the function declaration is only
compiled once.
Hope this helps,
- Kristian.
More information about the mcstas-users
mailing list